My Indicator Only works on live data but not on history

 

Hi all,

The code below is my onCalculate Method, it works in Strategy tester and in live data but if I put indicator on a chart I got a straight line for past candles


int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[])
  {
   if(rates_total < MAPeriod - 1)
      return(0);

   int first, bar, iii;
   double  MyResult;

   if(prev_calculated == 0)
      first = MAPeriod - 1 + begin;
   else
      first = prev_calculated - 1;

   for(bar = first; bar < rates_total; bar++)
     {
    
         MyResult=MyFormula(_Symbol,_Period,MAPeriod,bar);

   

      ExtLineBuffer[bar] = MyResult;
     }

   return(rates_total);
  }