Just can't fix this OrderModify error......

 

Hi Guys

Having trouble with this OrderModify error 1. The most basic error in the book and one I haven't been able to fix as yet. I downloaded an EA and have it compiled but can't get past this error:


if(Bid - OrderOpenPrice() > Point*TurnSourLimit && Bid - OrderOpenPrice() < Point*TrailingStop)
{
Print("C OrderTicket()="+OrderTicket()+" Point="+Point+" Digits="+Digits);
Print("Ask: " +Ask);
Print("OrderOpenPrice() ", OrderOpenPrice(), " OrderOpenPrice() ", NormalizeDouble(OrderOpenPrice()-Point, Digits)," OrderTakeProfit() ", OrderTakeProfit());
OrderModify(OrderTicket(), NormalizeDouble(OrderOpenPrice(),5), NormalizeDouble(OrderOpenPrice()-Point, Digits), NormalizeDouble(OrderTakeProfit(),5), 0, Green);
Print("done");
}


extern double TurnSourLimit = 50;

extern double TrailingStop = 80;


2010.09.11 22:03:08 2010.01.05 00:14 candlesticks EURUSD,Daily: done
2010.09.11 22:03:08 2010.01.05 00:14 candlesticks EURUSD,Daily: OrderModify error 1
2010.09.11 22:03:08 2010.01.05 00:14 candlesticks EURUSD,Daily: OrderOpenPrice() 1.4427 OrderOpenPrice() 1.4427 OrderTakeProfit() 1.4527
2010.09.11 22:03:08 2010.01.05 00:14 candlesticks EURUSD,Daily: Ask: 1.44347000
2010.09.11 22:03:08 2010.01.05 00:14 candlesticks EURUSD,Daily: C OrderTicket()=1 Point=0.00001000 Digits=5


I have tried a few things, and added logging but can't seem to figure out why it keeps failing.

It seems that OrderOpenPrice() returns only a 4 digits price 1.4427 but the actual buy price was 1.44268 5 digits. My broker is 5 digits.


The trade is:

1 2010.01.05 00:00 buy 1 1.50 1.44268 1.44168 1.45268 0.00 10000.00


I had tried to NormalizeDouble, but I still get a 4 digit price come out?


Any pointers?


Thanks

 

Print defaults to 4 digits.

Turn the double into a string with the appropriate number of digits before printing.

Print("OrderOpenPrice() ", DoubleToStr(OrderOpenPrice(), Digits), ... ... );

 

OK, I did that and here is the newly print lines:

2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: OrderModify error 1
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: OrderOpenPrice() 1.44268 OrderOpenPrice() 1.44268 OrderTakeProfit() 1.45268
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: Bid: 1.44338000
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: Ask: 1.44364000
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: C OrderTicket()=1 Point=0.00001000 Digits=5


Just noticed that for some modifies it actually works. Here is an example of one that works:


2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: done
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: modify #1 buy 1.50 EURUSD at 1.44268 sl: 1.44268 tp: 1.45268 ok
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: OrderOpenPrice() 1.44268 OrderOpenPrice() 1.44268 OrderTakeProfit() 1.45268
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: Bid: 1.44343000
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: Ask: 1.44369000
2010.09.12 16:05:21 2010.01.05 00:14 candlesticks EURUSD,Daily: C OrderTicket()=1 Point=0.00001000 Digits=5


What gives?

 
could it be that the current price and the stoploss don't have enough pips between them, say of the broker has a minimum pip size for a stoploss?
 

Hi,
You need to control new stoploss level more thoroughly.
See for example link
https://www.mql5.com/en/forum/124153, "Error 1 and I don't know why".
Also please pay special attention to your normalization method.
Precision of the normalization must be the same for entire expression.

Also use in conditional statement the same normalized values as for OrderModify function.
See for example link https://www.mql5.com/en/forum/123816.

Best regards

 

Here is my thread on ordermodify error 1. Maybe you'll find something useful in there.

https://www.mql5.com/en/forum/128449 

 
johnfilo

could it be that the current price and the stoploss don't have enough pips between them, say of the broker has a minimum pip size for a stoploss?

That would be ERR_TRADE_MODIFY_DENIED 145 Modification denied because order too close to market. No code for that either.

ERR_NO_RESULT 1 No error returned, but the result is unknown: make sure the new stop is greater (buy) than the old by at least one Point. Normalization is irrelevant.

/* A TP or SL can be not closer to the order price (open, limit, or
 * stop) or closing price (filled order) than this amount. A pending
 * order price can be no closer to the current price than this
 * amount. On IBFX it's equal to 30 (3.0 pips.) */                      double
minGapStop = MarketInfo(Symbol(), MODE_STOPLEVEL)*Point),
SLmax      = Bid - minGapStop,
SLnew      = ...;
if ((Bid - oo.SL) < minGapStop) return; // Too close to change
if ((SLnew-SLmax) > 0)          SLnew = SLmax; // No closer
if ((SLnew - oo.SL) < Point)    return; // No change
 

WHRoeder - You were spot on, the current stoploss was the same as OrderOpenPrice. So I added this check before executing the OrderModify and it has removed this error.


if(Bid - OrderOpenPrice() > Point*TurnSourLimit && Bid - OrderOpenPrice() < Point*TrailingStop)
{
if (OrderStopLoss() != OrderOpenPrice())
OrderModify(OrderTicket(), NormalizeDouble(OrderOpenPrice(),5), NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(OrderTakeProfit(),5), 0, Green);

}


Thanks to all that commented. On with the profit :)

Reason: