Help with code issue?

 

The second if statment "if(OrdersTotal() == 0 && LoMidBuf1 > LoMidBuf && SellOrder == 1)" is running even though the OrdersTotal() equals one (set by the first if statement). The print statment shows that OrdersTotal is zero but the code still runs. I don't understand. Thanks for the help.

2012.08.24 16:00:09 2012.08.23 01:00 HLxSMA_EA_V2 EURUSD,H1: open #2 buy 0.01 EURUSD at 1.25424 ok
2012.08.24 16:00:09 2012.08.23 01:00 HLxSMA_EA_V2 EURUSD,H1: 1, 1 (print output)
2012.08.24 16:00:09 2012.08.23 01:00 HLxSMA_EA_V2 EURUSD,H1: OrderModify error 130

if(OrdersTotal() == 0 && HiMidBuf1 < HiMidBuf && BuyOrder == 1)
{
int TicketNumber = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,0,0,"Buy Order",MagicNumber,0,Green);

OrderSelect(TicketNumber,SELECT_BY_TICKET);

double OpenPriceB = OrderOpenPrice();
double BuyStopLossB = OpenPriceB - (StopLoss * UsePoint);
double BuyTakeProfitB = OpenPriceB + (TakeProfit * UsePoint);
Print(OrdersTotal(),", ",BuyOrder);
OrderModify(TicketNumber,OrderOpenPrice(),BuyStopLossB,BuyTakeProfitB,0);
}

if(OrdersTotal() == 0 && LoMidBuf1 > LoMidBuf && SellOrder == 1)
{
TicketNumber = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,0,0,"Buy Order",MagicNumber,0,Green);

OrderSelect(TicketNumber,SELECT_BY_TICKET);
double OpenPriceS = OrderOpenPrice();
double BuyStopLossS = OpenPriceS + (StopLoss * UsePoint);
double BuyTakeProfitS = OpenPriceS - (TakeProfit * UsePoint);
Print(OrdersTotal(),", ",SellOrder);
OrderModify(TicketNumber,OrderOpenPrice(),BuyStopLossS,BuyTakeProfitS,0);
NewDay++;
}

 
Ickyrus:

First

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

Second

ERR_INVALID_STOPS 130 Invalid stops.


Well Ickyrus I fully understand the error message. Had you read my comments you would have seen the problem is not the error code created but why is the second if statement running. If the second statement did not run the error would be seen. Thanks for the suggestion anyway.
 
if(OrdersTotal() == 0 && LoMidBuf1 > LoMidBuf && SellOrder == 1)
{
TicketNumber = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,0,0,"Buy Order",MagicNumber,0,Green);   // BUY  ??  NOT  SELL ??
                                                               //check if(TicketNumber > 0)   before you gonna modifie
OrderSelect(TicketNumber,SELECT_BY_TICKET);
double OpenPriceS = OrderOpenPrice();
double BuyStopLossS = OpenPriceS + (StopLoss * UsePoint);        //  if BUY wrong stoploss
double BuyTakeProfitS = OpenPriceS - (TakeProfit * UsePoint);    //   ...  and wrong TakeProfit
Print(OrdersTotal(),", ",SellOrder);
OrderModify(TicketNumber,OrderOpenPrice(),BuyStopLossS,BuyTakeProfitS,0);
NewDay++;
}
Read my points in the code
 
deVries:
Read my points in the code

Thank you! Been looking at this code for hours and missed the forest for the trees.
 

deVries:

Brilliantly deducted just love the way you went from the error to the why it did not work.
Reason: