Why OnCalculate does not update in real time??? - page 2

 
ironhak #: I'll achieve the desired outcome without altering the proper structure of the loop? 
for(int iBar =Bars-MathMax(lookback, prev_calculated); iBar >= 0; --iBar) //I removed -1
Wrong. If your lookback is zero (you only look at Close[iBar]), your loop start at Bars. Close[Bars] does not exist.
          How to do your lookbacks correctly #9#14 & #19 (2016)
 
William Roeder #:
Wrong. If your lookback is zero (you only look at Close[iBar]), your loop start at Bars. Close[Bars] does not exist.
          How to do your lookbacks correctly #9#14 & #19 (2016)

Than's. So apparently I forgot to add -1 on 

return rates_total-1

This caused indicator not to update in real time. Thank's. 

So correct solution would be: 

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[])
  {
   int lookback = 1000;
   for(int iBar =Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar)
     {
      double price = (MarketInfo(Symbol(),MODE_BID) + MarketInfo(Symbol(),MODE_ASK)) /2;
      ObjectSetText(prefix+"close",DoubleToString(price,5),24,"Arial",clrWhite);
      
      if(mkt_time == TimeHour(Time[iBar]) && TimeMinute(Time[iBar]) == 0)
        {
         mkt_open = Open[iBar];
        }
      ObjectSetText(prefix+"mkt_open",DoubleToString(mkt_open,5),24,"Arial",clrWhite);

     }
   return(rates_total-1);
  }

This way the indicator updates with every new tick. Am I right now? Thank's.