OrderModify Errors 1, 130

 

Hi,


I keep getting ordermodify errors 1 and 130 when executing this code:

Please note that the "Lot" variable is predefined, and the call to the LOT() function is not being used right now.

 //Zero Stop
      bool StopMoved;
      for(int z = 0;z<=OrdersTotal();z++){
   OrderSelect(z,SELECT_BY_POS,MODE_TRADES);
   if(OrderType() == OP_BUY && OrderMagicNumber() == dailyMagic && OrderSymbol() == Symbol() && StopMoved == false){
   if(Bid < OrderOpenPrice() + 10*Point){
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+0.0003,OrderTakeProfit(),0,MediumSeaGreen);
    StopMoved = true;
    }
   }
   if(OrderType() == OP_SELL && OrderMagicNumber() == dailyMagic && OrderSymbol() == Symbol() && StopMoved == false){
   if(Ask < OrderOpenPrice() - 10*Point){
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-0.0003,OrderTakeProfit(),0,MediumSeaGreen);
   StopMoved = true;
   }
   }
   }  
    
   //Check Dailypivot and Place Trade
   
   double ADXval = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);
   if(dailypivot) {

      //Check Time
      if(Hour() >= starttime  && Hour() <= endtime && noofdailytrade == 0){
          //Check Daily Pivot for buy
          if( ( (Close[1] <= (dpivot+10*Point) && Close[1] >= (dpivot-10*Point)) || (Low[0] <= (dpivot+5*Point) && Low[0] >= (dpivot-5*Point))) && iOpen(Symbol(),0,1) > dpivot && iOpen(Symbol(),0,2) > dpivot && ADXval < 30 ) {
             RefreshRates();
             error=OrderSend(Symbol(),OP_BUY, Lot,Ask,MarketInfo(Symbol(),MODE_SPREAD),Ask-dailystoploss*Point,Ask+dailyprofit *Point,"Gulzaar",dailyMagic,3);
             StopMoved = false;
             if (error==-1)   ShowERROR(error,0,0);
          
          }

          //Check Daily Pivot for sell          
          if( ( (Close[1] >= (dpivot-10*Point) && Close[1] <= (dpivot+10*Point)) || (High[0] >= (dpivot-5*Point) && High[0] <= (dpivot+5*Point)))  && iOpen(Symbol(),0,1) < dpivot && iOpen(Symbol(),0,2) < dpivot && ADXval < 30) {
             RefreshRates();      
             error=OrderSend(Symbol(),OP_SELL,Lot,Bid,MarketInfo(Symbol(),MODE_SPREAD),Bid+dailystoploss*Point,Bid-dailyprofit *Point,"Gulzaar",dailyMagic,3);
             StopMoved = false;
             if (error==-1)   ShowERROR(error,0,0);
          
          }
      }

   }
   
   //check dM1
   if(dailyM1) { 
          //Check M1 for daily Pivot
          if(Hour() >= starttime  && Hour() <= endtime && noofdailytrade == 0){
          if( ( (Close[1] <= (dM1+10*Point) && Close[1] >= (dM1-10*Point)) || (Low[0] <= (dM1+5*Point) && Low[0] >= (dM1-5*Point))) && iOpen(Symbol(),0,1) > dM1 && iOpen(Symbol(),0,2) > dM1 && noofdailytrade == 0 && ADXval < 30){
             
             LOT = LOT(risk,1);
             RefreshRates();
             //First trade 20 pip Stoploss/Profit
             error=OrderSend(Symbol(),OP_BUY, Lot,Ask,MarketInfo(Symbol(),MODE_SPREAD),Ask-dailystoploss*Point,Ask+dailyprofit *Point,"Gulzaar",dailyMagic,3);            
             StopMoved = false;
             if (error==-1)   ShowERROR(error,0,0);
             }
             //End
      
             /*/Second Trade Target is S1
             RefreshRates();
             error = OrderSend(Symbol(),OP_BUY, LOT,Ask,MarketInfo(Symbol(),MODE_SPREAD),0,0,"Gulzaar",dailyMagic,3);
             OrderModify(error,OrderOpenPrice(),Ask-dailystoploss*Point,dS1,0, MediumSeaGreen);
             if (error==-1)   ShowERROR(error,0,0);
      */
          }
   }
   
   //check dM4 
   if(dailyM4){         
          //Check M4 for daily Pivot
          if(Hour() >= starttime  && Hour() <= endtime && noofdailytrade == 0){
          if( ( (Close[1] >= (dM4-10*Point) && Close[1] <= (dM4+10*Point)) || (High[0] >= (dM4-5*Point) && High[0] <= (dM4+10*Point)))  && iOpen(Symbol(),0,1) < dM4 && iOpen(Symbol(),0,2) < dM4 && noofdailytrade == 0 && ADXval < 30) {
   
             LOT = LOT(risk,1);
             RefreshRates();
             //First trade 20 pip Stoploss/Profit
             error=OrderSend(Symbol(),OP_SELL,Lot,Bid,MarketInfo(Symbol(),MODE_SPREAD),Bid+dailystoploss*Point,Bid-dailyprofit *Point,"Gulzaar",dailyMagic,3);
             StopMoved = false;
             if (error==-1)   ShowERROR(error,0,0);
             }
             //End
      
             /*/Second Trade Target is R1
             RefreshRates();
             error=OrderSend(Symbol(),OP_SELL,LOT,Bid,MarketInfo(Symbol(),MODE_SPREAD),0,0,"Gulzaar",dailyMagic,3);
             OrderModify(error,OrderOpenPrice(),Bid+dailystoploss*Point,dR1,0, MediumSeaGreen);
             if (error==-1)   ShowERROR(error,0,0);
   */
          }

   }
 
Have a read of this post and reply: https://www.mql5.com/en/forum/135049
 
RaptorUK:
Have a read of this post and reply: https://www.mql5.com/en/forum/135049

HI, went through your post. It works sometimes - in fact, when I first added the code to move stops to zero, it worked fine, and even when I moved them to 3 pips more than my entry. But once I changed some of the other criteria(aside from entry/modify) it would stop working.


This same modifying script works fine in my other experts.


thanks

 
What are your Broker's MODE_FREEZELEVEL & MODE_STOPLEVEL ?
 

Mr RaptorUK,

You are the expert here. Could you help me with the codes? Really not sure what went wrong about the Ordermodify Error 1.

void DoModify1()
{
   int atr=ATR(1);
   for(int i=0;i<OrdersTotal(); i++)  
   {
      RefreshRates();
      bool b=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);     
      if (!b) continue;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderMagicNumber()!=Magic) continue;     
          if (OrderType()==OP_BUY)
            {  
               if(OrderStopLoss()==0)
               {
                  double sl= OrderOpenPrice()-atr*myPoint*AtrPecSL;
                     OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Red); 
               }
               else if(OrderTakeProfit()==0 && ! IsClosePer)
               {
                  double tp= OrderOpenPrice()+atr*myPoint*AtrPecTP;
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tp,0,Green); 
               }
               else if(IsClosePer && OrderTakeProfit()!=0)
               {
                   OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),0,0,White); 
               }
            }     
          else if (OrderType()==OP_SELL)
            {               
               if(OrderStopLoss()==0)
               {
                  sl= OrderOpenPrice()+atr*myPoint*AtrPecSL;
                     OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Red); 
               }
               else if(OrderTakeProfit()==0 && ! IsClosePer)
               {
                  tp= OrderOpenPrice()-atr*myPoint*AtrPecTP;
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tp,0,Green); 
               }
               else if(IsClosePer && OrderTakeProfit()!=0)
               {
                   OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),0,0,White); 
               }
            }  
  } 
}
 
Spawn1980:

Mr RaptorUK,

You are the expert here. Could you help me with the codes? Really not sure what went wrong about the Ordermodify Error 1.

You need to read the return values from the OrderModify() to know which one(s) fails and report the error . . . then you will have a better idea of which value you are not changing. Error 1 happens when you do an OrdrModify without changing the SL or TP . . . to avoid this check that the new SL is different to the current SL and that the new TP is different to the current TP . . . bear in mind that comparing doubles can be troublesome . . . read this thread for more info about comparing doubles: Can price != price ?
Reason: