Download MetaTrader 5

OrderModify Error1

To add comments, please log in or register
Ngo Yung Lau
312
Ngo Yung Lau  

Hi,

Please help on below that I keep seeing Error1 when the EA tried to modify the stop loss level?

I already added the OrderModifyCheck  function provided by below link, but Error 1 still keep exist.

https://www.mql5.com/en/articles/2555#no_changes_in_modification_request


void MoveTP()

  {

   for(int i=0; i<OrdersTotal();i++)

     {


      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;


      if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())

        {

         if(OrderType()==OP_BUY)

           {

            if(Bid-OrderOpenPrice()>point*TrailingStop)

              {

               if(OrderStopLoss()<Bid-point*TrailingStop)

                 {

                  double ssl=NormalizeDouble(Bid-TrailingStop*point,Digits);

                  if(OrderModifyCheck(OrderTicket(),OrderOpenPrice(),ssl,OrderTakeProfit()))

                    {

                     mot=OrderModify(OrderTicket(),OrderOpenPrice(),ssl,OrderTakeProfit(),0,Red);


                    }

                 }

              }

           }

         else if(OrderType()==OP_SELL)

           {

            if((OrderOpenPrice()-Ask)>(point*TrailingStop))

              {

               if(OrderStopLoss()>Ask+point*TrailingStop)

                 {

                  double ppl=NormalizeDouble(Ask+point*TrailingStop,Digits);

                  if(OrderModifyCheck(OrderTicket(),OrderOpenPrice(),ppl,OrderTakeProfit()))

                    {

                    mot= OrderModify(OrderTicket(),OrderOpenPrice(),ppl,OrderTakeProfit(),0,Red);

                    }


                 }

              }

           }

        }

     }

  }


bool OrderModifyCheck(int ticket,double price,double csl,double ctp)

  {

//--- select order by ticket

   if(OrderSelect(ticket,SELECT_BY_TICKET))

     {

      //--- point size and name of the symbol, for which a pending order was placed

      string symbol=OrderSymbol();

      //double point=SymbolInfoDouble(symbol,SYMBOL_POINT);

      //--- check if there are changes in the Open price

      bool PriceOpenChanged=true;

      int type=OrderType();

      if(!(type==OP_BUY || type==OP_SELL))

        {

         PriceOpenChanged=(MathAbs(OrderOpenPrice()-price)>point);

        }

      //--- check if there are changes in the StopLoss level

      bool StopLossChanged=(MathAbs(OrderStopLoss()-csl)>point);

      //--- check if there are changes in the Takeprofit level

      bool TakeProfitChanged=(MathAbs(OrderTakeProfit()-csl)>ctp);

      //--- if there are any changes in levels

      if(PriceOpenChanged || StopLossChanged || TakeProfitChanged)

         return(true);  // order can be modified      

      //--- there are no changes in the Open, StopLoss and Takeprofit levels

      else

      //--- notify about the error

         PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",

                     ticket,OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit());

     }

//--- came to the end, no changes for the order

   return(false);

  }      // no point in modifying


The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • 2016.08.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
Ngo Yung Lau
312
Ngo Yung Lau  

Problem solved.

Thanks 

To add comments, please log in or register