EA doesn't close order during backtest?

 
void OnTick()
  {
   if(OrdersTotal() == 0)
   {
      if(iCustom(Symbol(),PERIOD_CURRENT,"mt",0,0) > 1 && iCustom(Symbol(),PERIOD_CURRENT,"mta",0,0) > 0)
      {
         OrderSend (_Symbol,OP_BUY,lots,Ask,1,0,0,NULL,0,0,Green);
      }
   
      if(iCustom(Symbol(),PERIOD_CURRENT,"mt",0,0) > 1 && iCustom(Symbol(),PERIOD_CURRENT,"mta",0,0) < 0)
      {
         OrderSend (_Symbol,OP_SELL,lots,Bid,1,0,0,NULL,0,0,Red);
      }
   
   }
   

      if(iCustom(Symbol(),PERIOD_CURRENT,"mt",0,0) < 0)
      {
         CloseAllPositions();
         
      } 
  }//Ontick

void CloseAllPositions(){

   for(int i = OrdersTotal()-1; i >=0;i--)
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   string CurrencyPair = OrderSymbol();
   if(_Symbol==CurrencyPair)
   if(OrderType()==OP_SELL)
   {
      OrderClose(OrderTicket(),OrderLots(),Ask,3,NULL);
      
   }
   if(OrderType()==OP_BUY)
   {
      OrderClose(OrderTicket(),OrderLots(),Bid,3,NULL);
   }
   }//END FOR
}//CLOSE FUNCTION

Please help? I used two indicators for opening position and when one of the indicators go from positive to negative it is supposed to close all orders. But during backtest the order never closes.


Update: turns out the iCustom(Symbol(),PERIOD_CURRENT,"mt",0,0) < 0 never is true. But when I look at the stopped strategy tester, the indicators seem fine and it becomes <0 at some point.

(Even the send order condtion is not working properly.)

I have three indicators "mta", "mtb" and "mt". mt calls for mta and mtb via the iCustom function also.

It says "array out of range in "mt"(or mta)" in the journal. I don't know if that has something to do with it.

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 
This is actually MT4 code, I didn't know there was another section for MT4. But anyway, please help.
 

Changing the draw limit of all indicators from 1000 to 99 seems to solve the problem.

Otherwise the iCustom function always give crazy numbers

Edit: Just found out it was because of tickdatasuite setting that only shows 100 bars before.