help error code

 

How can i fix this?

98        for(cnt=OrdersTotal()-1;cnt>=0;cnt--){                                                
99 "error"      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
100           if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)continue;
101           if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
102                if(OrderType()==OP_BUY)
103              {
104               LongTrade=true;
105               ShortTrade=false;
106               LastBuyLots=OrderLots();
107               break;
108              }
   total=CountTrades();
   AveragePrice=0;
   double Count=0;
   for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {
240 "error"      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
         continue;
      if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            AveragePrice=AveragePrice+OrderOpenPrice()*OrderLots();
            Count=Count + OrderLots();
           }
     }
   if(total > 0)
      AveragePrice=NormalizeDouble(AveragePrice/Count, Digits);
256 "error"         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
285 "error"            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if(NewOrdersPlaced)
      if(flag==1)// check if average has really changed
        {
         for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
           {
            //     PriceTarget=total;
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
               continue;
            if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
               //      OrderModify(OrderTicket(),0,Stopper,PriceTarget,0,Yellow);// set all positions to averaged levels
290 "error"               OrderModify(OrderTicket(),AveragePrice,OrderStopLoss(),PriceTarget,0,Yellow);// set all positions to averaged levels
            NewOrdersPlaced=false;
           }
        }
  }
   if(NewOrdersPlaced)
      if(flag==1)// check if average has really changed
        {
         for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
           {
            //     PriceTarget=total;
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
               continue;
            if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
               //      OrderModify(OrderTicket(),0,Stopper,PriceTarget,0,Yellow);// set all positions to averaged levels
               OrderModify(OrderTicket(),AveragePrice,OrderStopLoss(),PriceTarget,0,Yellow);// set all positions to averaged levels
            NewOrdersPlaced=false;
           }
        }
294 "error"  }

423 "error"               OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
440 "error"               OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
446 "error"                     OrderClose(OrderTicket(),OrderLots(),Bid,slip,Blue);
448 "error"                     OrderClose(OrderTicket(),OrderLots(),Ask,slip,Red);
458 "error"            int ticket=0;
655 "error"               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
694 "error"                        OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Aqua);
705 "error"                        OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
729 "error"            int cnt, oldticketnumber=0, ticketnumber;
732 "error"               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
754 "error"            int cnt, oldticketnumber=0, ticketnumber;
757 "error"               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
Files:
boterrores.jpg  190 kb
 
javiervillagran96:

How can i fix this?

It means just that - return values should be checked.

So you should have something like:

if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{ // Do what you usually do }
else
{ Print ("Failed to select order - Error: ", GetLastError()); }

for example.

 
Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
          What are Function return values ? How do I use them ? - MQL4 programming forum
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.