ERR_INVALID_TRADE_PARAMETERS

 

Why do I often get OrderModify Error 3 (ERR_INVALID_TRADE_PARAMETERS) in such cases?

2013.02.11 01:39:53 - StopLevel = 0.00020000
2013.02.11 01:39:53 - FreezeLevel = 0.00000000
2013.02.11 01:39:53 - Error Modifying Sell Stop: 3
2013.02.11 01:39:53 - FROM: Entry = 1.33226 SL = 1.33684 TP = 1.32695 -> TO: Entry = 1.33226000 SL = 1.33685000 TP = 1.32696000 Bid = 1.33639

2013.02.11 01:57:33 - StopLevel = 0.00020000
2013.02.11 01:57:33 - FreezeLevel = 0.00000000
2013.02.11 01:57:33 - Error Modifying Sell Stop: 3
2013.02.11 01:57:33 - FROM: Entry = 1.33216 SL = 1.33698 TP = 1.32687 -> TO: Entry = 1.33216000 SL = 1.33699000 TP = 1.32688000 Bid = 1.33663

 
enivid:

Why do I often get OrderModify Error 3 (ERR_INVALID_TRADE_PARAMETERS) in such cases?

2013.02.11 01:39:53 - StopLevel = 0.00020000
2013.02.11 01:39:53 - FreezeLevel = 0.00000000
2013.02.11 01:39:53 - Error Modifying Sell Stop: 3
2013.02.11 01:39:53 - FROM: Entry = 1.33226 SL = 1.33684 TP = 1.32695 -> TO: Entry = 1.33226000 SL = 1.33685000 TP = 1.32696000 Bid = 1.33639

2013.02.11 01:57:33 - StopLevel = 0.00020000
2013.02.11 01:57:33 - FreezeLevel = 0.00000000
2013.02.11 01:57:33 - Error Modifying Sell Stop: 3
2013.02.11 01:57:33 - FROM: Entry = 1.33216 SL = 1.33698 TP = 1.32687 -> TO: Entry = 1.33216000 SL = 1.33699000 TP = 1.32688000 Bid = 1.33663

Something seems wrong in your OrderModify call.

Check your calls and the documentation.
https://docs.mql4.com/trading/errors 

ERR_INVALID_TRADE_PARAMETERS3Invalid parameters were passed to the trading function, for example, wrong symbol, unknown trade operation, negative slippage, non-existing ticket number, etc. The program logic must be changed.
 
enivid:

Why do I often get OrderModify Error 3 (ERR_INVALID_TRADE_PARAMETERS) in such cases?

2013.02.11 01:39:53 - StopLevel = 0.00020000
2013.02.11 01:39:53 - FROM: Entry = 1.33226 SL = 1.33684 TP = 1.32695 -> TO: Entry = 1.33226000 SL = 1.33685000 TP = 1.32696000 Bid = 1.33639

  1. SL = (1.33685000) - (Bid = 1.33639) = 0.00046 Stop level = 0.00020. So if the spread is greater than 46-20=2.6 pips you will have 130. For a Sell, the stops are relative to the ASK.
  2. On ECN brokers you must open first and THEN set stops. You are modifying a stop, not an open order. Maybe.
  3. I never could get stops to work with pending orders. I thought it was because it was comparing the stop to the CURRENT Bid/Ask not the orderOpenPrice. There is no reason to use a pending order (except perhaps a news scalping). They are useful since the human can't watch the screen continuously and press the button quickly. The EA can. Just wait for the price to reach your level and open.
 
kronin:

Something seems wrong in your OrderModify call.

Check your calls and the documentation.
https://docs.mql4.com/trading/errors 

ERR_INVALID_TRADE_PARAMETERS3Invalid parameters were passed to the trading function, for example, wrong symbol, unknown trade operation, negative slippage, non-existing ticket number, etc. The program logic must be changed.

 

No other parameters of the order except for those listed (entry, SL, TP) are changed:

if (!OrderModify(OrderTicket(), LowerEntry, LowerSL, LowerTP, OrderExpiration()))

WHRoeder:
  1. SL = (1.33685000) - (Bid = 1.33639) = 0.00046 Stop level = 0.00020. So if the spread is greater than 46-20=2.6 pips you will have 130. For a Sell, the stops are relative to the ASK.
  2. On ECN brokers you must open first and THEN set stops. You are modifying a stop, not an open order. Maybe.
  3. I never could get stops to work with pending orders. I thought it was because it was comparing the stop to the CURRENT Bid/Ask not the orderOpenPrice. There is no reason to use a pending order (except perhaps a news scalping). They are useful since the human can't watch the screen continuously and press the button quickly. The EA can. Just wait for the price to reach your level and open.

1. Please see another case with both Bid and Ask logged:

2013.02.11 22:52:03 - StopLevel = 0.00020000
2013.02.11 22:52:03 - FreezeLevel = 0.00000000
2013.02.11 22:52:03 - Error Modifying Sell Stop: 3
2013.02.11 22:52:03 - FROM: Entry = 1.33468 SL = 1.34041 TP = 1.32882 -> TO: Entry = 1.33468000 SL = 1.34040000 TP = 1.32881000 Bid/Ask = 1.33989/1.34001 OrderTicket = 299588027

The difference is about 40 pips, while the stop level is 20 pips.

2. The broker is not ECN. Those are pending orders. Those errors happen not on every modification attempt, though I fail to see any dependencies.

3. OK, let's assume it is comparing the stops to current price instead of the entry price, but what should be the minimum distance? Apparently it is not MODE_STOPLEVEL. Then what?

 
enivid:

No other parameters of the order except for those listed (entry, SL, TP) are changed:


1. Please see another case with both Bid and Ask logged:

2013.02.11 22:52:03 - StopLevel = 0.00020000
2013.02.11 22:52:03 - FreezeLevel = 0.00000000
2013.02.11 22:52:03 - Error Modifying Sell Stop: 3
2013.02.11 22:52:03 - FROM: Entry = 1.33468 SL = 1.34041 TP = 1.32882 -> TO: Entry = 1.33468000 SL = 1.34040000 TP = 1.32881000 Bid/Ask = 1.33989/1.34001 OrderTicket = 299588027

The difference is about 40 pips, while the stop level is 20 pips.

2. The broker is not ECN. Those are pending orders. Those errors happen not on every modification attempt, though I fail to see any dependencies.

3. OK, let's assume it is comparing the stops to current price instead of the entry price, but what should be the minimum distance? Apparently it is not MODE_STOPLEVEL. Then what?

Please show your code,  especially the code for the OrderSelect() the calculations for LowerEntry, LowerSL, LowerTP  and also please add a print to print the OrderExpiration() and TimeCurrent()
 
RaptorUK:
Please show your code,  especially the code for the OrderSelect() the calculations for LowerEntry, LowerSL, LowerTP  and also please add a print to print the OrderExpiration() and TimeCurrent()


Thanks to RaptorUK for hinting me on how to solve the problem (again!), which was in order's expiration. The error is generated whenever an EA tries to modify an order, which has expiration < 11 minutes, and not moving its expiration at least to +11 minutes from TimeCurrent(). So this simple fix did the job:

int expiration = OrderExpiration();
if (expiration - TimeCurrent() < 660) expiration = TimeCurrent() + 660;
Of course, I would say that such behavior is not normal. It is either a bug or at least a poorly documented feature of MetaTrader 4. If it has been mentioned in OrderModify() help file, there would be no need for this topic.
 
enivid:

Thanks to RaptorUK for hinting me on how to solve the problem (again!), which was in order's expiration. The error is generated whenever an EA tries to modify an order, which has expiration < 11 minutes, and not moving its expiration at least to +11 minutes from TimeCurrent(). So this simple fix did the job:

Of course, I would say that such behavior is not normal. It is either a bug or at least a poorly documented feature of MetaTrader 4. If it has been mentioned in OrderModify() help file, there would be no need for this topic.
You are welcome, it is an infrequently mentioned feature,  but I do remember it being mentioned before.  Some Brokers don't even support it at all as far as I recall . . .
 
I've found an old forum discussion that mentions that new orders should use expiry time >= 11 minutes, but found nothing on OrderModify() failing to modify SL/TP on orders that are to expire during next 11 minutes unless expiration time is moved too.
 
enivid:
I've found an old forum discussion that mentions that new orders should use expiry time >= 11 minutes, but found nothing on OrderModify() failing to modify SL/TP on orders that are to expire during next 11 minutes unless expiration time is moved too.
Yep,  it was the 11 minute thing that I was thinking of,  it did occur to me that from initial Send to Modify the Expiry time may become too close.  I never use Expiration though so it's not something I've ever come across . . . will bear it in mind for the future though ;-)
 
enivid:
2013.02.11 22:52:03 - StopLevel = 0.00020000

2013.02.11 22:52:03 - FROM: Entry = 1.33468 SL = 1.34041 TP = 1.32882 -> TO: Entry = 1.33468000 SL = 1.34040000 TP = 1.32881000 Bid/Ask = 1.33989/1.34001 OrderTicket = 299588027

The difference is about 40 pips, while the stop level is 20 pips.

1.34040000 - 1.34001 = 0.00039 Thats 3.9 pips (39 points) NOT 40. pips. On a 5 digit broker a pip is NOT a point
Reason: