OrderModify Error 1

 

It kept on producing OrderModify Error 1 when running the ea on strategy tester, everything is working just like expected tho but im concern with this error.

This is the code: 

void OnTick()
  {
   
   if ( OrdersTotal() == 0  )
   {
   int ticket = OrderSend(_Symbol,OP_BUY,0.1,Ask,5,Ask-500*_Point,Ask+1000*_Point,NULL,0,0,clrGreen);
   }
   breakEvenStopLoss();
  }
void breakEvenStopLoss() {
      for (int i = 0; i < OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) 
         
            if (OrderSymbol() == Symbol())
            
               if ((OrderType() == OP_BUY)) 
                  
                     if (Ask>OrderOpenPrice()+510*_Point)
                     {
                        OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+50*_Point),OrderTakeProfit(),0,clrNONE);
                     }
                     
}
}
 
You don't check to see if the SL has already been moved.
 
if (Ask>OrderOpenPrice()+510*_Point)
   OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+50*_Point),OrderTakeProfit(),0,clrNONE);

Constant

ERR_NO_RESULT
You Server
Change the SL to X It is at X!
Change the SL to X It is at X!
Change the SL to X You are insane
Insanity: doing the same thing over and over again and expecting different results.
          Unknown
 
Renz Carillo:

It kept on producing OrderModify Error 1 when running the ea on strategy tester, everything is working just like expected tho but im concern with this error.

This is the code: 

Keith Watford:
You don't check to see if the SL has already been moved.
void breakEvenStopLoss() {
      for (int i = 0; i < OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) 
         
            if (OrderSymbol() == Symbol())
            
               if ((OrderType() == OP_BUY)) 
                  
                     if (Ask>OrderOpenPrice()+510*_Point && OrderOpenPrice()+50*_Point!=OrderStopLOst())
                     {
                        OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+50*_Point),OrderTakeProfit(),0,clrNONE);
                     }
                     
}
}
 

After spending the whole day, i've managed to fix the error, it now works without any error. What it now does is stoploss moves to breakeven when price reached 1:1 risk reward ratio

Here is the code: 

void breakEvenStopLoss() {
      for (int i = 0; i < OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) 
         {
            //SYMBOL MUST BE THE SAME
            if (OrderSymbol() == Symbol())
            {
               //ORDER TYPE MUST BE THE SAME
               if ((OrderType() == OP_BUY)) 
               {  
                  // PRICE REACHED 1:1 MOVE SL TO BREAKEVEN     
                  if (Ask>(OrderOpenPrice()-OrderStopLoss()+OrderOpenPrice()) && 
                  //SINCE WE MOVE THE SL TO BREAKEVEN + ADD HALF PIP TO ACCOUNT FOR SPREAD,
                  //MEANING THIS COULD ONLY TRIGGER IF PRICE WASN'T MODIFIED YET,
                  //THUS PREVENTING ORDERMODIFY ERROR 1
                  //ORDERMODIFY ERROR 1: DOING THE SAME THING OVER & OVER AGAIN WITHOUT CHANGING ANYTHING
                  (OrderStopLoss()<OrderOpenPrice()))
                  {
                     OrderModify(OrderTicket() //CHOOSE THE CORRECT TICKET
                     ,OrderOpenPrice() //ORDER ENTRY PRICE NOT CHANGED, ONLY THE STOPLOSS
                     ,(OrderOpenPrice()+5*_Point) // SL HAS BEEN CHANGED
                     ,OrderTakeProfit() // TAKE PROFIT NOT CHANGED, ONLY THE STOPLOSS
                     ,0 //NO EXPIRATION
                     ,clrNONE); // NO COLOR
                     }
                   }
                 }
               }                     
            }
      for (int i = 0; i < OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) 
         {
            if (OrderSymbol() == Symbol())
            {
               if ((OrderType() == OP_SELL)) 
               {
                  // PRICE REACHED 1:1 MOVE SL TO BREAKEVEN
                  if (Bid < (((OrderStopLoss()-OrderOpenPrice())-OrderOpenPrice())*(-1))
                  //SINCE WE MOVE THE SL TO BREAKEVEN + ADD HALF PIP TO ACCOUNT FOR SPREAD,
                  //MEANING THIS COULD ONLY TRIGGER IF PRICE WASN'T MODIFIED YET,
                  //THUS PREVENTING ORDERMODIFY ERROR 1
                  //ORDERMODIFY ERROR 1: DOING THE SAME THING OVER & OVER AGAIN WITHOUT CHANGING ANYTHING
                  && (OrderStopLoss()>OrderOpenPrice()))
                  {
                     OrderModify(OrderTicket() //CHOOSE THE CORRECT TICKET
                     ,OrderOpenPrice() //ORDER ENTRY PRICE NOT CHANGED, ONLY THE STOPLOSS
                     ,(OrderOpenPrice()-5*_Point) // SL HAS BEEN CHANGED
                     ,OrderTakeProfit() // TAKE PROFIT NOT CHANGED, ONLY THE STOPLOSS
                     ,0 //NO EXPIRATION
                     ,clrNONE); // NO COLOR
                     }
                   }
                 }
               }                     
             }
           }
 
Renz Carillo: After spending the whole day, i've managed to fix the error, it now works without any error. What it now does is stoploss moves to breakeven when price reached 1:1 risk reward ratio
               if ((OrderType() == OP_BUY)) 
               {  
                  // PRICE REACHED 1:1 MOVE SL TO BREAKEVEN     
                  if (Ask>(OrderOpenPrice()

  1. "Whole day" - poor baby.
  2. It moves the stop loss to breakeven before you reach 1:1
  3. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

Reason: