Total Bars(iBars) of a Pair is not Updating when running a script

 

Hi, I'm trying create a script that loads data from all pairs from certain timeframes.

The logic is :

Attach script to Window A

Script Tells Window B --> 

  Load Pair X

  Load Time Frame Y

 ChartNavigate to shift -99999 

  if Time of First bar after ChartNavigate is still after 26 March 2018 00:00 then do ChartNavigate again

 When done, shift to next time frame, when done, shift to the next pair. untill all pairs in market watch is completed

The issue is after each loop, the time (using either iBars or CHART_FIRST_VISIBLE_BAR value) value is when the data of Window,Pair & Timeframe is loaded, looping does not udpates the value of this.

Attach is the script (it works because a trick, that if I've hit the most left bar, i skip to next pair. but that means the pair loads way more data than I requested)

and below is snippet of  the code

should be something like

/* curTime : current time frame, in ENUM*/

do {
   ChartNavigate(cChartID,CHART_END,-99999);
   Sleep(50); 
} while( iTime(curPair,curTime,iBars(curPair,curTime) ) > StrToTime(date)) );


but I'm using something like this instead

         do {
            ChartNavigate(cChartID,CHART_END,-99999);
            Sleep(50); 
            if (pos==ChartGetInteger(cChartID,CHART_FIRST_VISIBLE_BAR,0)) {
                   samePos += 1;
            } else { 
               pos = ChartGetInteger(cChartID,CHART_FIRST_VISIBLE_BAR,0);
               samePos = 0;
            }
            
            Comment(TimeToStr(iTime(curPair,curTime,pos),TIME_DATE) + " " + samePos);
         } while( ((samePos <20) && (TimeToStr(iTime(curPair,curTime,pos),TIME_DATE) == "1970.01.01")) || ( iTime(curPair,curTime,pos) > StrToTime(date)) );
    

I hope someone can give me an explantion. is this an MQL4 bug? that prevents new iBars value to be loaded during a running script? Anyone have any workarounds?

Files:
Reason: