OrderModify() error 1

 

hi, I keep getting this error, and not sure why? 

i know in the book it states "Open price and expiration time can be changed only for pending orders. If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated." But what is this referring to?  

 Below is my code; please help.

 

for(int b=OrdersTotal()-1; b >= 0; b--)
      {
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNumber)      
            if(OrderSymbol()==Symbol())           
               if(OrderType()==OP_BUY)                          
                  if(Bid-OrderOpenPrice()>WhenToMoveToBE*Point) 
                   if(OrderOpenPrice()>OrderStopLoss())
                   buymod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(PipsToLockIn*Point),OrderTakeProfit(),0,clrBlue);
       }
 
DeanDeV: If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated." But what is this referring to?
You
Server
Change the SL to X
It is at X!
Change the SL to XIt is at X!
Change the SL to XYou are insane
  1. You would know what it is referring to had you tested your your return codes (OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. I suspect that WhenToMoveToBE is smaller than PipsToLockIn.
  3. A point is not a pip. PipsToLockIn*Point is wrong on 5 digit broker's Problems with a calculation - MQL4 forum or your variable should be renamed to PointsToLockIn
  4. Put Print statements including variable values, before and inside if statements and find out why.
 
WHRoeder:
DeanDeV: If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated." But what is this referring to?
You
Server
Change the SL to X
It is at X!
Change the SL to XIt is at X!
Change the SL to XYou are insane
  1. You would know what it is referring to had you tested your your return codes (OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. I suspect that WhenToMoveToBE is smaller than PipsToLockIn.
  3. A point is not a pip. PipsToLockIn*Point is wrong on 5 digit broker's Problems with a calculation - MQL4 forum or your variable should be renamed to PointsToLockIn
  4. Put Print statements including variable values, before and inside if statements and find out why.

Thank you. I always appreciate your responses! WhenToMoveToBE > PipsToLockIn; however I have changed the function, however I still get this error.

if(Hour()==X && Minute()==Y) MoveToBreakEven();

void MoveToBreakEven()
  {
   for(int z=OrdersTotal()-1; z>=0; z--)
    {
     if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_BUY)
          int buymodify=OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-(PointsToLockIn*Point),OrderTakeProfit(),0,clrBlue);
           if(buymodify>0) Print("Buy order OrderModify() success.");
            if(buymodify<0) Print("Buy order OrderModify() failed.", GetLastError());
    }
   for(int y=OrdersTotal()-1; y>=0; y--)
    {
     if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_SELL)
          int sellmodify=OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]+(PointsToLockIn*Point),OrderTakeProfit(),0,clrRed);
           if(sellmodify>0) Print("Sell order OrderModify() success.");
            if(sellmodify<0) Print("Sell order OrderModify() failed.", GetLastError());
    }
  }

 I have also tried NormalizeDouble() on the new stop loss without success. It modifies the order but it still gives this error and it modifies it every tick at the specified time ie. continuosly thus giving OrderModify() error 1. Any ideas for an additional filter to prevent this? I thought of sleep, but we know that that doesn't work in back testing...?

void MoveToBreakEven()
  {
   for(int z=OrdersTotal()-1; z>=0; z--)
    {
     if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_BUY)
         if(Ask-OrderOpenPrice()>PointsToLockIn*Point)
           int buymodify=OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-(PointsToLockIn*Point),OrderTakeProfit(),0,clrBlue);
            if(buymodify>0) 
             {
              Print("Buy order OrderModify() success."); //break;
              Sleep();
             }
            if(buymodify<0) Print("Buy order OrderModify() failed.", GetLastError());
    }
   for(int y=OrdersTotal()-1; y>=0; y--)
    {
     if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_SELL)
         if(OrderOpenPrice()-Bid>PointsToLockIn*Point)
           int sellmodify=OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]+(PointsToLock*Point),OrderTakeProfit(),0,clrRed);
            if(sellmodify>0)
             {
              Print("Sell order OrderModify() success."); //break;
              Sleep();
             }
             if(sellmodify<0) Print("Sell order OrderModify() failed.", GetLastError());
    }
  }
 
   for(int z=OrdersTotal()-1; z>=0; z--)
    {
     if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_BUY)
         if(Ask-OrderOpenPrice()>PointsToLockIn*Point) //A Buy trade is closed at Bid, so why use Ask?
           int buymodify=OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-(PointsToLockIn*Point),OrderTakeProfit(),0,clrBlue);
            if(buymodify>0) 
             {
              Print("Buy order OrderModify() success."); //break;
              Sleep();
             }
            if(buymodify<0) Print("Buy order OrderModify() failed.", GetLastError());
    }

When checking a Buy, don't use Ask, use Bid or OrderClosePrice()

OrderModify() returns a boolean value not an integer

You are checking against current price, what does Open[0] have to do with it? 

 

Maybe you can try something like this

input double MoveToBreakEvenPoints=200;
input double PointsToLockIn=10;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void MoveToBreakEven()
  {
   bool buymodify;
   for(int z=OrdersTotal()-1; z>=0; z--)
     {
      if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
         if(OrderType()==OP_BUY && OrderOpenPrice()>OrderStopLoss())
            if(OrderClosePrice()-OrderOpenPrice()>=MoveToBreakEvenPoints*Point)
              {
               buymodify=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+PointsToLockIn*Point,OrderTakeProfit(),0,clrBlue);
               if(buymodify)
                 {
                  Print("Buy order OrderModify() success."); //break;
                 }
               else
                  Print("Buy order OrderModify() failed.",GetLastError());
              }
     }
  }

That uses Points as that is what you have been using

Not tested, so I may have made a mistake when modifying your code 

 
int buymodify=OrderModify(...
if(buymodify>0) Print("Buy order OrderModify() success.");
if(buymodify<0) Never Occurs
RTM OrderModify - MQL4 Documentation returns a bool.
 
GumRai:

When checking a Buy, don't use Ask, use Bid or OrderClosePrice()

OrderModify() returns a boolean value not an integer

You are checking against current price, what does Open[0] have to do with it? 

Thank you so much for your assistance. It is greatly appreciated. Redid the whole function, and seems to run smoothly. Thanks again!