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_PARAMETERS | 3 | Invalid 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. |
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
- 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.
- On ECN brokers you must open first and THEN set stops. You are modifying a stop, not an open order. Maybe.
- 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.
Something seems wrong in your OrderModify call.
Check your calls and the documentation.
https://docs.mql4.com/trading/errors
ERR_INVALID_TRADE_PARAMETERS | 3 | Invalid 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()))
- 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.
- On ECN brokers you must open first and THEN set stops. You are modifying a stop, not an open order. Maybe.
- 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?
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()
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.
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.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.
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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