Very odd problem from indicator buffer

 
Hello,

My indicator draws multiple pair's daily percetage change as line in the indicator window. 
However I noticed a very weird problem, that the value are sometimes wrong as the ticks goes by on chart, but if I refresh or reload the indicator,
the value goes back to the correct value. But this does not happen in the strategy tester using everytick mode, everything is correct there when I ran the indicator.
Have anyone ever encounter such problem? Any help would be appreciated. Thanks in Advance.

Below are the codes:
#property strict
#property indicator_separate_window
#property indicator_buffers 7

extern string NNN = "---------------Color Settings----------------"; //-
extern color Line1 = clrDodgerBlue; //Line 1 Color
extern color Line2 = clrLime;       //Line 2 Color
extern color Line3 = clrRed;        //Line 3 Color
extern color Line4 = clrWheat;      //Line 4 Color
extern color Line5 = clrGold;       //Line 5 Color
extern color Line6 = clrDeepPink;   //Line 6 Color
extern color Line7 = clrPurple;     //Line 7 Color

double DP1[], DP2[], DP3[], DP4[], DP5[], DP6[], DP7[];
string Pair1, Pair2, Pair3, Pair4, Pair5, Pair6, Pair7;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
   IndicatorBuffers(7);
   IndicatorDigits(5);
   Pair1 = "EURUSD"; Pair2 = "EURGBP"; Pair3 = "EURJPY"; Pair4 = "EURCAD"; Pair5 = "EURAUD"; Pair6 = "EURNZD"; Pair7 = "EURCHF";
   
    SetIndexBuffer(0, DP1);   
    SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, Line1);    
    SetIndexLabel(0, Pair1);
    
    SetIndexBuffer(1, DP2);  
    SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1, Line2);    
    SetIndexLabel(1, Pair2);
    
    SetIndexBuffer(2, DP3); 
    SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1, Line3);    
    SetIndexLabel(2, Pair3);
    
    SetIndexBuffer(3, DP4); 
    SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1, Line4);    
    SetIndexLabel(3, Pair4);  
    
    SetIndexBuffer(4, DP5);    
    SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 1, Line5);    
    SetIndexLabel(4, Pair5);
    
    SetIndexBuffer(5, DP6);     
    SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 1, Line6);    
    SetIndexLabel(5, Pair6);
    
    SetIndexBuffer(6, DP7);    
    SetIndexStyle(6, DRAW_LINE, STYLE_SOLID, 1, Line7);    
    SetIndexLabel(6, Pair7);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 ExtCountedBars=IndicatorCounted();
 if (ExtCountedBars<0) return(-1);
 int pos;
 int limit=1000; //Past 1000 Bar only
 if(ExtCountedBars>2) limit=Bars-ExtCountedBars-1;
 pos=limit;  
   
   for(int t=0; t<=limit; t++)
   { 
         int mtfBar = iBarShift(_Symbol, PERIOD_D1, Time[t]);
         double Open1 = iOpen(Pair1, PERIOD_D1, mtfBar); double Close1 = iClose(Pair1, _Period, t);
         double Open2 = iOpen(Pair2, PERIOD_D1, mtfBar); double Close2 = iClose(Pair2, _Period, t);
         double Open3 = iOpen(Pair3, PERIOD_D1, mtfBar); double Close3 = iClose(Pair3, _Period, t);
         double Open4 = iOpen(Pair4, PERIOD_D1, mtfBar); double Close4 = iClose(Pair4, _Period, t);
         double Open5 = iOpen(Pair5, PERIOD_D1, mtfBar); double Close5 = iClose(Pair5, _Period, t);
         double Open6 = iOpen(Pair6, PERIOD_D1, mtfBar); double Close6 = iClose(Pair6, _Period, t);
         double Open7 = iOpen(Pair7, PERIOD_D1, mtfBar); double Close7 = iClose(Pair7, _Period, t);
         DP1[t] = ((Close1-Open1)/Open1*100);
         DP2[t] = ((Close2-Open2)/Open2*100);
         DP3[t] = ((Close3-Open3)/Open3*100);
         DP4[t] = ((Close4-Open4)/Open4*100);
         DP5[t] = ((Close5-Open5)/Open5*100);
         DP6[t] = ((Close6-Open6)/Open6*100);
         DP7[t] = ((Close7-Open7)/Open7*100);
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

Sorry will double check next time.
Anyway I've found the problem, because a tick in a single pair is independent to other pair's tick, so the data from other pairs only gets updated according to the chart symbol's tick instead of the real tick from the pair requested.
Not sure if there is a work around this?

 
I Kai Wu #:

Sorry will double check next time.
Anyway I've found the problem, because a tick in a single pair is independent to other pair's tick, so the data from other pairs only gets updated according to the chart symbol's tick instead of the real tick from the pair requested.
Not sure if there is a work around this?

SymbolInfoTick() 

 
Thank-god Avwerosuoghene Odukudu #:

SymbolInfoTick() 

I have to put it in OnTimer right? else the function only excutes when chart symbol ticks?

 
         double Open7 = iOpen(Pair7, PERIOD_D1, mtfBar); double Close7 = iClose(Pair7, _Period, t);
         DP1[t] = ((Close1-Open1)/Open1*100);

You are mixing apples and oranges. Code fails an all charts but the daily.