OrderModify() error 3

 

I am completely stumped and would welcome any ideas.  The below code is part of a larger and fairly complex logical sequence, but because of the printing I can see that the logical structure is functioning properly.  However the OrderModify function is generating error 3.  Is it not correct to use zeroes for values you don't want changed?  These are pending orders (OP_SELLSTOP) and in this example I don't want to change the entry price (the 0 before "shortSL) and the EA doesn't use take profit values.

In effect the below if-else sequence is choosing between a predetermined stop price ("shortSL") or a freeze value ("upperFreeze" based on MarketInfo(_Symbol,MODE_STOPLEVEL)).

Any ideas would be very much appreciated.


                        //stop price needs to be changed
                        else if(OrderStopLoss() != shortSL)
                        {
                           //use normal values
                           if(freezeUpper <= shortSL)
                           {
                              modify = OrderModify(OrderTicket(),0,shortSL,0,0);
                              Print("Sell SL: normal");
                              Print("OrderTicket(): ",OrderTicket());
                              Print("OrderType(): ",OrderType());
                              Print("OrderOpenPrice(): ",OrderOpenPrice());
                              Print("ShortEntry: ",shortEntry);
                              Print("freezeLower: ",freezeLower);
                              Print("OrderStopLoss(): ",OrderStopLoss());
                              Print("ShortSL: ",shortSL);
                              Print("freezeUpper: ",freezeUpper);
                           }   
                           //use freeze values
                           else if(freezeUpper >= shortSL)
                           {
                              modify = OrderModify(OrderTicket(),0,freezeUpper,0,0);
                              Print("Sell SL: freeze");
                              Print("OrderTicket(): ",OrderTicket());
                              Print("OrderType(): ",OrderType());
                              Print("OrderOpenPrice(): ",OrderOpenPrice());
                              Print("ShortEntry: ",shortEntry);
                              Print("freezeLower: ",freezeLower);
                              Print("OrderStopLoss(): ",OrderStopLoss());
                              Print("ShortSL: ",shortSL);
                              Print("freezeUpper: ",freezeUpper);
                           }   



Below is an example where I am trying to change the entry price while leaving the stop level alone, but it is also generating error 3.  In all cases these are pending orders - either OP_SELLSTOP in these examples or in other places OP_BUYSTOP.


                        //entry price needs to be changed
                        else if(OrderOpenPrice() != shortEntry)
                        {
                           //use normal values
                           if(freezeLower >= shortEntry)
                           {
                              modify = OrderModify(OrderTicket(),shortEntry,0,0,0);
                              Print("Sell entry: normal");
                              Print("OrderTicket(): ",OrderTicket());
                              Print("OrderType(): ",OrderType());
                              Print("OrderOpenPrice(): ",OrderOpenPrice());
                              Print("ShortEntry: ",shortEntry);
                              Print("freezeLower: ",freezeLower);
                              Print("OrderStopLoss(): ",OrderStopLoss());
                              Print("ShortSL: ",shortSL);
                              Print("freezeUpper: ",freezeUpper);
                           }   
                           //use freeze values
                           else if(freezeLower <= shortEntry)
                           {
                              modify = OrderModify(OrderTicket(),freezeLower,0,0,0);
                              Print("Sell entry:  freeze");
                              Print("OrderTicket(): ",OrderTicket());
                              Print("OrderType(): ",OrderType());
                              Print("OrderOpenPrice(): ",OrderOpenPrice());
                              Print("ShortEntry: ",shortEntry);
                              Print("freezeLower: ",freezeLower);
                              Print("OrderStopLoss(): ",OrderStopLoss());
                              Print("ShortSL: ",shortSL);
                              Print("freezeUpper: ",freezeUpper);
                           }   
                        }
 
jeffkotnik:

I am completely stumped and would welcome any ideas.  The below code is part of a larger and fairly complex logical sequence, but because of the printing I can see that the logical structure is functioning properly.  However the OrderModify function is generating error 3.  Is it not correct to use zeroes for values you don't want changed?  These are pending orders (OP_SELLSTOP) and in this example I don't want to change the entry price (the 0 before "shortSL) and the EA doesn't use take profit values.

In effect the below if-else sequence is choosing between a predetermined stop price ("shortSL") or a freeze value ("upperFreeze" based on MarketInfo(_Symbol,MODE_STOPLEVEL)).

Any ideas would be very much appreciated.

Below is an example where I am trying to change the entry price while leaving the stop level alone, but it is also generating error 3.  In all cases these are pending orders - either OP_SELLSTOP in these examples or in other places OP_BUYSTOP.

Step 1: Find the significance of the error code: Trade Server Return Codes
In this case Error 3, ERR_INVALID_TRADE_PARAMETERS, signifies "Invalid trade parameters".

Step 2: Read-up on the function in question: OrderModify()
In this case, we can see that for pending orders you have to supply an Opening price (not 0). If you do not wish to change it then use the original price with OrderOpenPrice(). The same goes for the stops — if you don't plan to change or disable them, then use the original prices with OrderStopLoss() and OrderTakeProfit(). Do the same for expiration as well. See the example code in the documentation.

Other observations:
It is not possible from your code to see if you are properly selecting the order before executing the modification. So show that part too if the issue is not resolved with these suggestions. Also look into both the Stops Level and Freeze Level. They are not the same thing. Requirements and Limitations in Making Trades

Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL4 Reference
 
Fernando, I am grateful, thank you so much.  I haven't tested it completely but Step 2 alone seems to have eliminated the problem entirely.