Indicator stops calculating

 
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- check for bars count
   if(rates_total<InpMAPeriod-1 || InpMAPeriod<2)
      return(0);
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
      ArrayInitialize(ExtLineBuffer,0);
//--- calculation
   int counted_bar=IndicatorCounted();
   int limit=Bars-counted_bar-InpMAPeriod;
   for(int x=0; x<limit; x++)
     {
         y = InpMAPeriod-1;
         z = (InpMAPeriod-1)+x;
         HH[x] = iHigh(Symbol(),PERIOD_CURRENT,iHighest(NULL,0, MODE_HIGH,y,x));                                           //---InpMAPeriod's high calculation

         LL[x] = iLow(Symbol(),PERIOD_CURRENT,iLowest(NULL,0, MODE_LOW,y,x));                                              //---InpMAPeriod's low calculation

         if ((Close[x] >= Close[z] && Close[x] >= Open[z]) || (Close[x] <= Close[z] && Close[x] <= Open[z]))               //---InpMAPeriod's close calculation
         tClose[x] = Close[x];
         else
         tClose[x] = Close[z];
         hlc3[x]=(HH[x]+LL[x]+tClose[x])/3;                                                                                //---InpMAPeriod's hlc3 calculation
     }
   CalculateEMA(rates_total,prev_calculated,hlc3);                                                                         //---Set calculated hlc3 as EMA input price
//--- return value of prev_calculated for next call
   return(rates_total);
  }

Hi

I coded a custom indicator, it work on the chart without any problem, EA gives its values by iCustome, everything's ok until EA opens first trade, after first trade opening Indicator stops calculating therefore EA can't modify or close the position

what's wrong with it???

 
Ashomid7: what's wrong with it???
 int limit=Bars-counted_bar-InpMAPeriod;

After the first run counted equals bars and your loop does nothing.
          How to do your lookbacks correctly #9 - #14 & #19

 
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- check for bars count
   if(rates_total<InpMAPeriod-1 || InpMAPeriod<2)
      return(0);
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
      ArrayInitialize(ExtLineBuffer,0);
//--- calculation
   limit=rates_total-prev_calculated;
   for(i=0; i<limit; i++)
     {
         datetime now  = Time[i],
                  bod  = now - now % 86400;                                                                                //---Beginning of the day
         int      iBod = iBarShift(NULL,0, bod);
     
         HH[i] = iHigh(Symbol(),PERIOD_CURRENT,iHighest(NULL,0, MODE_HIGH,iBod-i,i));                                      //---InpMAPeriod's high calculation

         LL[i] = iLow(Symbol(),PERIOD_CURRENT,iLowest(NULL,0, MODE_LOW,iBod-i,i));                                         //---InpMAPeriod's low calculation

         if ((Close[i] >= Close[iBod] && Close[i] >= Open[iBod]) || (Close[i] <= Close[iBod] && Close[i] <= Open[iBod]))   //---InpMAPeriod's close calculation
         tClose[i] = Close[i];
         else
         tClose[i] = Close[iBod];
         hlc3[i]=(HH[i]+LL[i]+tClose[i])/3;                                                                                //---InpMAPeriod's hlc3 calculation
     }
   CalculateEMA(rates_total,prev_calculated,hlc3);                                                                         //---Set calculated hlc3 as EMA input price
//--- return value of prev_calculated for next call
   return(rates_total);
  }
William Roeder:

After the first run counted equals bars and your loop does nothing.
          How to do your lookbacks correctly #9 - #14 & #19

 it doesn't work, I changed calculation method and loop method for all of the code :((
Reason: