return value of 'OrderModify' should be checked

 

Hi everyone,

Anyhow please, how is correct way for:


void TrailingAlls(int pType,int stop,double AvgPrice) 
  {
   int profits;
   double stoptrade;
   double stopcal;
   if(stop!=0) 
     {
      for(int trade= OrdersTotal()-1; trade>= 0; trade--) 
        {
         if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) 
           {
            if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
            if(OrderSymbol()==Symbol() || OrderMagicNumber()==MagicNumber) 
              {
               if(OrderType()==OP_BUY) 
                 {
                  profits=NormalizeDouble((Bid-AvgPrice)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Bid-stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal>stoptrade)) (OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Aqua));
                 }
               if(OrderType()==OP_SELL) 
                 {
                  profits=NormalizeDouble((AvgPrice-Ask)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Ask+stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal<stoptrade)) OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
                 }
              }
            Sleep(1000);
           }
        }
     }
  }
 
void TrailingAlls(int pType,int stop,double AvgPrice) 
  {
   int profits;
   double stoptrade;
   double stopcal;
   if(stop!=0) 
     {
      for(int trade= OrdersTotal()-1; trade>= 0; trade--) 
        {
         if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) 
           {
            if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
            if(OrderSymbol()==Symbol() || OrderMagicNumber()==MagicNumber) 
              {
               if(OrderType()==OP_BUY) 
                 {
                  profits=NormalizeDouble((Bid-AvgPrice)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Bid-stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal>stoptrade)) (something = OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Aqua));
                 }
               if(OrderType()==OP_SELL) 
                 {
                  profits=NormalizeDouble((AvgPrice-Ask)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Ask+stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal<stoptrade)) something = OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
                 }
              }
            Sleep(1000);
           }
        }
     }
  }
Look up what it returns and process the results, did the modification succeed or not and if not what additional action should be taken ?
 

Thanks Marco, I got it...and work properly.


void TrailingAlls(int pType,int stop,double AvgPrice)
  {
   int profits;
   double stoptrade;
   double stopcal;
   if(stop!=0)
     {
      for(int trade= OrdersTotal()-1; trade>= 0; trade--)
        {
         if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
            if(OrderSymbol()==Symbol() || OrderMagicNumber()==MagicNumber)
              {
               if(OrderType()==OP_BUY)
                 {
                  profits=NormalizeDouble((Bid-AvgPrice)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Bid-stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal>stoptrade)) (trade = OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Aqua));
                 }
               if(OrderType()==OP_SELL)
                 {
                  profits=NormalizeDouble((AvgPrice-Ask)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Ask+stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal<stoptrade)) trade = OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
                 }
              }
            Sleep(1000);
           }
        }
     }
  }
//+----------------------------------------------------------

 

Don't use "trade" variable, because it is used for calculating order total, please use this :

void TrailingAlls(int pType,int stop,double AvgPrice) 
  {
   int profits;
   double stoptrade;
   double stopcal;
   bool result = false;
   if(stop!=0) 
     {
      for(int trade= OrdersTotal()-1; trade>= 0; trade--) 
        {
         if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) 
           {
            if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
            if(OrderSymbol()==Symbol() || OrderMagicNumber()==MagicNumber) 
              {
               if(OrderType()==OP_BUY) 
                 {
                  profits=NormalizeDouble((Bid-AvgPrice)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Bid-stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal>stoptrade)) (result = OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Aqua));
                 }
               if(OrderType()==OP_SELL) 
                 {
                  profits=NormalizeDouble((AvgPrice-Ask)/Point,0);
                  if(profits<pType) continue;
                  stoptrade=OrderStopLoss();
                  stopcal=Ask+stop*Point;
                  if(stoptrade==0.0 || (stoptrade!=0.0 && stopcal<stoptrade)) result = OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
                 }
              }
            Sleep(1000);
           }
        }
     }
  }


  

 
This way it will only get rid of the warning and the return value still isn't checked so it's still no good.
Reason: