I need help before I tear the last hair out, please.
I have several error messages along the lines of "return value of Order Select (Order Modify, Order Close) should be checked". I'm dying here and need someone smarter that I to find the error. This is MetaTrader 4. Thanks!
//Check position
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//+------------------------------------------------+
//| CLOSE BUY CONDITIONS: |
//+------------------------------------------------+
if (CloseBuy) Order = SIGNAL_CLOSEBUY;
//+-------------------------------------------------+
//| Place Close Buy Order |
//+-------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && (( !TickCheck) || ( (Bars != BarCount))))
{
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
// if (SignalMail) SendMail(" >", "" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " A_H4 No Lag: CLOSED THE LONG ");
if (NotifyON) SendNotification("Close Buy " + Symbol() + " " + DoubleToStr(Ask, Digits) );
if (SoundON) Alert("BUY CLOSED " + Symbol() + " M=" + Period() +" " + DoubleToStr(Ask, Digits) );
IsTrade = False;
continue;
}
//Trailing stop
if(TrailingStopMode && (TrailingStop > 0) ) {
if(Bid - OrderOpenPrice() > PT * TrailingStop) {
if(OrderStopLoss() < Bid - PT * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - PT * TrailingStop, OrderTakeProfit(), 0, MediumSpringGreen);
if (!TickModeOn) BarCount = Bars;
continue;
}
}
}
} else {
//+---------------------------------------------------+
//| CLOSE SELL CONDITIONS |
//+---------------------------------------------------+
if ( CloseSell )Order = SIGNAL_CLOSESELL;
//+---------------------------------------------------+
//| Place Close Sell Order |
//+---------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && (( !TickCheck) || ( (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
//if (SignalMail) SendMail(" >", "" + Symbol() + " " + DoubleToStr(Ask, Digits) + " A_H4 No Lag: CLOSED THE SHORT ");
if (NotifyON) SendNotification("CloseSELL " + Symbol() + " " + DoubleToStr(Ask, Digits) );
if (SoundON) Alert("SELL CLOSED " + Symbol() + " M=" + Period() +" " + DoubleToStr(Ask, Digits) );
IsTrade = False;
continue;
}
//Trailing stop
if(TrailingStopMode && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (PT * TrailingStop)) {
if((OrderStopLoss() > (Ask + PT * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + PT * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!TickModeOn) BarCount = Bars;
continue;
}
}
}
}
}
}
I have several error messages along the lines of "return value of Order Select (Order Modify, Order Close) should be checked". I'm dying here and need someone smarter that I to find the error. This is MetaTrader 4. Thanks!
//Check position
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//+------------------------------------------------+
//| CLOSE BUY CONDITIONS: |
//+------------------------------------------------+
if (CloseBuy) Order = SIGNAL_CLOSEBUY;
//+-------------------------------------------------+
//| Place Close Buy Order |
//+-------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && (( !TickCheck) || ( (Bars != BarCount))))
{
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
// if (SignalMail) SendMail(" >", "" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " A_H4 No Lag: CLOSED THE LONG ");
if (NotifyON) SendNotification("Close Buy " + Symbol() + " " + DoubleToStr(Ask, Digits) );
if (SoundON) Alert("BUY CLOSED " + Symbol() + " M=" + Period() +" " + DoubleToStr(Ask, Digits) );
IsTrade = False;
continue;
}
//Trailing stop
if(TrailingStopMode && (TrailingStop > 0) ) {
if(Bid - OrderOpenPrice() > PT * TrailingStop) {
if(OrderStopLoss() < Bid - PT * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - PT * TrailingStop, OrderTakeProfit(), 0, MediumSpringGreen);
if (!TickModeOn) BarCount = Bars;
continue;
}
}
}
} else {
//+---------------------------------------------------+
//| CLOSE SELL CONDITIONS |
//+---------------------------------------------------+
if ( CloseSell )Order = SIGNAL_CLOSESELL;
//+---------------------------------------------------+
//| Place Close Sell Order |
//+---------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && (( !TickCheck) || ( (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
//if (SignalMail) SendMail(" >", "" + Symbol() + " " + DoubleToStr(Ask, Digits) + " A_H4 No Lag: CLOSED THE SHORT ");
if (NotifyON) SendNotification("CloseSELL " + Symbol() + " " + DoubleToStr(Ask, Digits) );
if (SoundON) Alert("SELL CLOSED " + Symbol() + " M=" + Period() +" " + DoubleToStr(Ask, Digits) );
IsTrade = False;
continue;
}
//Trailing stop
if(TrailingStopMode && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (PT * TrailingStop)) {
if((OrderStopLoss() > (Ask + PT * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + PT * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!TickModeOn) BarCount = Bars;
continue;
}
}
}
}
}
}