1
votes

I have an order modification code for my open market orders which comes up with Error 130 in the MT4 Journal, I know this is an age-old issue & there are several sources I have looked at, both here & throughout the web - however, nothing seems to work.

1) I have NormalizeDouble()-cured everything that has double functions on MQL4 i.e prices etc - this is to ensure that the number of digits after the decimal points are consistent with the pair its trading; some are 3 digits, others are 5 digits.

2) The pnlPoints & stopPoints are calculated using the _Period so the number of points are consistent regardless of the number of digits after the decimal point of the chart the EA is dropped on

3) I'm aware of the presence of the MarketInfo( Symbol(), MODE_STOPLEVEL ) & haved added this to the MarketInfo( Symbol(), MODE_SPREAD ) to some to the stoplevel calculation.

4) I want 100 points "In the money" before the order is modified to breakeven.

5) I'm using a five digit broker but as you will know, some pairs like the EURJPY will have three digits. This is corrected by the _Period & the NormalizeDouble() funtions.

                 /*Breakeven Order Modification*/
                 for(int b = OrdersTotal()-1;b>=0;b--)
                 {
                 if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==true)
                    {
                    double   aBidPrice   =  MarketInfo(Symbol(),MODE_BID);
                    double   anOpenPrice =  OrderOpenPrice();
                    double   aNewTpPrice =  OrderTakeProfit();
                    double   aCurrentSL  =  OrderStopLoss();
                    double   aNewSLPrice =  anOpenPrice;
                    double   pnlPoints   =  NormalizeDouble(aBidPrice - anOpenPrice/_Point,Digits);
                    double   stopPoints  =  NormalizeDouble(aBidPrice - aNewSLPrice/_Point,Digits);
                    int      stopLevel   =  int(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD));
                    int      aTicket     =  OrderTicket();
                    if(OrderType() == OP_BUY)
                    if(stopPoints > stopLevel)
                    if(aTicket > 0)
                    if(pnlPoints > breakeven)
                    if(aNewSLPrice == aCurrentSL)continue;
                       {
                       BuyMod = OrderModify(OrderTicket(),NormalizeDouble(anOpenPrice,Digits),NormalizeDouble(aNewSLPrice,Digits),NormalizeDouble(aNewTpPrice,Digits),0,buycolor);
                       SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
                       if(BuyMod = false || aTicket == 0)
                          {
                          Print("Order modification for ticket #"+IntegerToString(aTicket,10)+"Error code",GetLastError());
                          }
                       }
                    }
                 }
                 for(int s = OrdersTotal()-1; s>=0; s--)
                    {
                    if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)==true)
                       {
                       double   anAskPrice  =  MarketInfo(Symbol(),MODE_ASK);
                       double   anOpenPrice =  OrderOpenPrice();
                       double   aNewTpPrice =  OrderTakeProfit();
                       double   aCurrentSL  =  OrderStopLoss();
                       double   aNewSLPrice =  anOpenPrice;
                       double   pnlPoints   =  NormalizeDouble(anOpenPrice - anAskPrice/_Point,Digits);
                       double   stopPoints  =  NormalizeDouble(aNewSLPrice - anAskPrice/_Point,Digits);
                       int      stopLevel   =  int(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD));
                       int      aTicket     =  OrderTicket();
                       if(OrderType()== OP_SELL)
                       if(stopPoints > stopLevel)
                       if(aTicket > 0)
                       if(pnlPoints > breakeven)
                       if(aNewSLPrice == aCurrentSL)continue;
                          {
                          SellMod = OrderModify(OrderTicket(),NormalizeDouble(anOpenPrice,Digits),NormalizeDouble(aNewSLPrice,Digits),NormalizeDouble(aNewTpPrice,Digits),0,sellcolor);
                          SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
                          if(SellMod = false || aTicket == 0)
                             {
                             Print("Order modification for ticket #"+IntegerToString(aTicket,10)+"Error code",GetLastError());
                             }
                          }
                       }
                    }

Many thanks & regards.

1

1 Answers

0
votes

MQL4 Error 130 stands for ERR_INVALID_STOPS

So the next best step is to review your OrderModify() calls, adding a self-journalling of the actual values, that are to be put inside the Server-side sent instruction.

Design a wrapper function, with an exactly the same calling-signature as standard OrderModify() has:

int LogAndSendOrderModify( int      const aTicketNUMBER,
                           double   const anOrderOpenPRICE,
                           double   const aStopLossPRICE,
                           double   const aTakeProfitPRICE,
                           datetime const anExpirationTIME,
                           color    const aMarkerArrowCOLOR
                           ){ ... }

... and include a piece of code, right before the OrderModify(), which exactly logs each value into a journal.

PrintFormat( "[%s]: TKT:[%d]OP:[%15.8f]SL:[%15.8f]TP:[%15.8f]SL_STOPZONE:[%d]TP_STOPZONE:[%d]SL_FREEZEZONE:[T.B.D.]TP_FREEZEZONE:[T.B.D.]",
              __FUNCTION__,
              aTicketNUMBER,
              anOrderOpenPRICE,
              aStopLossPRICE,
              aTakeProfitPRICE,
              (int) ( MathPow( 10, _Digits ) * ( Bid - aStopLossPRICE ) ),
              (int) ( MathPow( 10, _Digits ) * ( aTakeProfitPRICE - Bid ) )
              );

For ??_FREEZEZONE you need to provide values similarly, but with a need to call an OrderSelect( aTicketNUMBER, ... ) accordingly, before making any request into a current state of the db.Pool records with { OrderTakeProfit() | OrderStopLoss() }, but the principle is obvious.

Facts matter and if self-reported values are compliant with Broker Terms& Condition and still keep getting ERR_INVALID_STOPS, ask your Broker for a due explanation of any non-compliance observed.