I get error OrderModify error 1 in Strategy Tester mt4. Can someone help me fix this?

 

So, I get this error in strategy tester mt4:

Beside of the error, the strategy tester works really fine. But I'm afraid if I using this code in real account, this error would disrupt the trading. 

Can someone help me to fix this?

This is the code I write:

extern int    Magic1 = 100;
extern int    Magic2 = 200;
extern int    min_gapsize = 1;
extern double lotsize_gap = 0.01;
extern double StopLoss = 1000;
extern ENUM_TIMEFRAMES    TF = PERIOD_CURRENT;
double ot;
//----
datetime order_time = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

// Defining the variables to decide.
   double current_openprice = iOpen(Symbol(), TF, 0);
   double previous_highprice = iHigh(Symbol(), TF, 1);
   double previous_lowprice = iLow(Symbol(), TF, 1);
   double point_gap = MarketInfo(Symbol(), MODE_POINT);
   int spread_gap = MarketInfo(Symbol(), MODE_SPREAD);
   datetime current_time = iTime(Symbol(), TF, 0);
// catching the gap on sell upper gap
   if(current_openprice > previous_highprice + (min_gapsize + spread_gap)*point_gap &&
      current_time != order_time)
     {
       int ticket = OrderSend(Symbol(), OP_SELL, lotsize_gap, Bid, 0, 0, 
                              previous_highprice + spread_gap*point_gap, 
                              "", Magic1, 0, Red);
       order_time = iTime(Symbol(), PERIOD_CURRENT, 0);
       //----
       if(ticket < 0)
         {
           Print("OrderSend failed with error #", GetLastError());
         }
     }
//catching the gap on buy down gap
   if(current_openprice < previous_lowprice - (min_gapsize + spread_gap)*point_gap &&
      current_time != order_time)
     {
       ticket = OrderSend(Symbol(), OP_BUY, lotsize_gap, Ask, 0, 0, 
                          previous_lowprice - spread_gap*point_gap,
                          "", Magic2, 0, Green);
                          
       order_time = iTime(Symbol(), PERIOD_CURRENT, 0);
       if(ticket < 0)
         {
           Print("OrderSend failed with error #", GetLastError());
         }
     }
//----
   ot=OrdersTotal();
   for(int cnt=ot-1;cnt>=0;cnt--) 
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
         {
             ModifyStopLoss(OrderOpenPrice() - StopLoss*Point);
         } 
            
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)

         {    
            ModifyStopLoss(OrderOpenPrice() + StopLoss*Point);
         } 
                
   }
//------------------------------------------------------------------+
   return(0);
  }


//----------------------ModifyStopLoss---------------------+  
void ModifyStopLoss(double xStopLoss) 
{
   bool modSL;
   modSL=OrderModify(OrderTicket(),OrderOpenPrice(),xStopLoss,OrderTakeProfit(),0,CLR_NONE);
}  
//+------------------------------------------------------------------+
 

Don't keep trying to modify the SL over and over again. Just do it once.


In future please post in the correct section

I will move your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:

Don't keep trying to modify the SL over and over again. Just do it once.


In future please post in the correct section

I will move your topic to the MQL4 and Metatrader 4 section.

Thank you, sorry for being in wrong section, I'm still newbie here.

Anyway, can you point out where is the error in the code, and how to fixed it? 

 
Daniel Sastraamidjaja:

Anyway, can you point out where is the error in the code, and how to fixed it? 

Keith Watford:

Don't keep trying to modify the SL over and over again. Just do it once.

       if(ticket < 0)
         {
           Print("OrderSend failed with error #", GetLastError());
         }
       else
         {
           //Modify SL
         }
 
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

Compute the new value, then check that you are moving the existing value at least a tick.

PIP, Point, or Tick are all different in general.
          What is a TICK? - MQL4 programming forum