Download MetaTrader 5

OrderModify error 1 during back testing

To add comments, please log in or register
mop0
197
mop0  

I have some code to break even when price reaches a particular point but I keep getting OrderModify Error 1 in the journal. The code works absolutely fine and does its job of break even at the correct point, I just keep getting the error clogging up the journal after that happens.

      for (int counter = OrdersTotal() - 1; counter >= 0; counter--)
         {
            OrderSelect(counter,SELECT_BY_POS,MODE_TRADES);
            
            if (OrderType() == OP_BUY && iClose(NULL,0,0) >= LongBreakEvenPrice && OrderOpenPrice() != OrderStopLoss())
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0,Yellow);
               }

            if (OrderType() == OP_SELL && iClose(NULL,0,0) <= ShortBreakEvenPrice && OrderOpenPrice() != OrderStopLoss())
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0,Yellow);
               }
         }

I also tried the following but it doesn't make a difference:

OrderModify(OrderTicket(),0,OrderOpenPrice(),0,0,Yellow);

Any ideas?

Edit: additional info: I only use one timeframe and one symbol, and Open Prices only for the Strategy Tester.

Edit2: Is is possible to suppress the error message?

whroeder1
14781
whroeder1  
eempc: but I keep getting OrderModify Error 1 in the journal.
  1. You
    Server
    Change the SL to X
    It is at X!
    Change the SL to XIt is at X!
    Change the SL to XYou are insane
  2. OrderOpenPrice() != OrderStopLoss()
    The == operand. - MQL4 forum
mop0
197
mop0  
Better rethink this...
qjol
3243
qjol  
WHRoeder:
  1. You
    Server
    Change the SL to X
    It is at X!
    Change the SL to XIt is at X!
    Change the SL to XYou are insane
  2. The == operand. - MQL4 forum

Not quite true

first time he checks if the SL is @ break even

OrderOpenPrice() != OrderStopLoss()

so he is modifying the OrderStopLoss() to OrderOpenPrice()

the Second time is OrderStopLoss() == OrderOpenPrice()

mop0
197
mop0  

It looks a bit awkward but I seem to have fixed the issue using MathRound (after multiplying by mx, which = 10000). Many thanks!

MathRound(OrderOpenPrice()*mx) != MathRound(OrderStopLoss()*mx)
mop0
197
mop0  
qjol:

Not quite true

first time he checks if the SL is @ break even

so he is modifying the OrderStopLoss() to OrderOpenPrice()

the Second time is OrderStopLoss() == OrderOpenPrice()

Yeah, that's what I though so too with my code. But WHRoeder links to an interesting thing about how prices don't quite = another price, it seems to be a quirk of MQL4.
whroeder1
14781
whroeder1  
the Second time is OrderStopLoss() == OrderOpenPrice()

Do not compare doubles for equality. It has to do which EVERY computer because the way floating point is implementated. Nothing unusual with MQL4.

Print your variables

Print("OSL="+PriceToStr(OrderStopLoss()),
      " OOP="+PriceToStr(OrderOpenPrice()),
      " Equ="+( OrderStopLoss() == OrderOpenPrice() )
      );
/////////////
string   PriceToStr(double p){   return( DoubleToStr(p, Digits) );            }
Daniel Petrovai
440
Daniel Petrovai  
eempc:

I have some code to break even when price reaches a particular point but I keep getting OrderModify Error 1 in the journal. The code works absolutely fine and does its job of break even at the correct point, I just keep getting the error clogging up the journal after that happens.

I also tried the following but it doesn't make a difference:

Any ideas?

Edit: additional info: I only use one timeframe and one symbol, and Open Prices only for the Strategy Tester.

Edit2: Is is possible to suppress the error message?

Hi,

I'm trying to replicate the error you get . Can you post how do you calculate the LongBreakEvenPrice and ShortBreakEvenPrice ?

Do you have only 1 order open at the time and you store the open price somewhere else?

Because if you have more than 1 order, say buy orders, the LongBreakEvenPrice won't be the same for the two of them, right ?

Keith Watford
Moderator
9641
Keith Watford  
thrdel:

Hi,

I'm trying to replicate the error you get . Can you post how do you calculate the LongBreakEvenPrice and ShortBreakEvenPrice ?

Do you have only 1 order open at the time and you store the open price somewhere else?

Because if you have more than 1 order, say buy orders, the LongBreakEvenPrice won't be the same for the two of them, right ?




That doesn't matter, the important condition here is

OrderOpenPrice() != OrderStopLoss()

The problem can usually be resolved by substituting

MathAbs(OrderOpenPrice() - OrderStopLoss() ) > Point()
Daniel Petrovai
440
Daniel Petrovai  
GumRai:


That doesn't matter, the important condition here is

The problem can usually be resolved by substituting


I understand your point but if you cannot test the code and get the same error, how can you be sure?

Unless you use to get the ERROR 1 message in your other code or EA's and you solved it as you mentioned.

I would give your answer a thumb up any way, if I could.

Keith Watford
Moderator
9641
Keith Watford  
thrdel:


I understand your point but if you cannot test the code and get the same error, how can you be sure?

Unless you use to get the ERROR 1 message in your other code or EA's and you solved it as you mentioned.

I would give your answer a thumb up any way, if I could.


In the OP's code

            
            if (OrderType() == OP_BUY && iClose(NULL,0,0) >= LongBreakEvenPrice && OrderOpenPrice() != OrderStopLoss())
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0,Yellow);
               }

you could simply change it to something like

            
            if (OrderType() == OP_BUY && Bid-OrderOpenPrice()>Point()*100 && OrderOpenPrice() != OrderStopLoss())
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0,Yellow);
               }

if you are trying to replicate the error

123
To add comments, please log in or register