an error in a simple code made me crazy!!

To add comments, please log in or register
Seyed Mohammad Tabadkani
114
Seyed Mohammad Tabadkani  

Hey guys,

Please look at this code:

void ModifyM1()
{
 double price;
 double stoploss;
 double takeprofit;
 string TradeSymbol;
 
 
 if(OrderSelect(M1BTicket,SELECT_BY_TICKET))
         {
         if(OrderType() == OP_BUYSTOP)
                  {
                  TradeSymbol = OrderSymbol();
                  price = SymbolInfoDouble(TradeSymbol,SYMBOL_ASK)+(M1Distance*SymbolInfoDouble(TradeSymbol,SYMBOL_POINT)) ;
                  stoploss = 0;
                  takeprofit = 0;
                  if((OrderOpenPrice()>price) || (OrderOpenPrice()<price))
                                                {
                                                Print("Modifying BuyStop from ",OrderOpenPrice()," to " ,price);
                                                if(OrderModify(M1BTicket,price,stoploss,takeprofit,0,Red)) Print("Buy Stop Modified!");
                                                }
                  }                       
                                       
         }
}

How this code can has this result?? 


Print order should not be processed when OrderOpenPrice() == price but it does!!. I can't understand it please help me.

Seyed Mohammad Tabadkani
114
Seyed Mohammad Tabadkani  

I got the same result when I write the if order in this way:

if(OrderOpenPrice() != price)
                                                {
                                                Print("Modifying BuyStop from ",OrderOpenPrice()," to " ,price);
                                                if(OrderModify(M1BTicket,price,stoploss,takeprofit,0,Red)) Print("Buy Stop Modified!");
                                                }
William Roeder
20233
William Roeder  
  1. if(OrderModify(M1BTicket,price,stoploss,takeprofit,0,Red)) Print("Buy Stop Modified!");
    Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  2. if((OrderOpenPrice()>price) || (OrderOpenPrice()<price))
    
    This is almost always true. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. if(OrderOpenPrice() != price)
    See № 1

  4. What does the open price have to do with your SL? Why don't you test the current SL against the new SL? ERR_NO_RESULT
    You Server
    Change the SL to XIt is at X!
    Change the SL to X It is at X!
    Change the SL to XYou are insane
To add comments, please log in or register