MQL4 Wait Until All Bars Have Loaded .

 

Hello Mql.

I am developing an indicator on MQL4 , what i am doing is utilizing a while loop -blocking further operations- (placed in OnInit function) until

all the bars have loaded from the broker in a chart.

I Check if the current time - last candle time is <= one bar time for this period.

heres the segment that ... makes MT4 freeze . :)

Enlighten if you can . :)


   //check bars loaded state
      datetime time_now=TimeCurrent();
      int minute_now=time_now;   
      int minute_need=Period()*60;
   while(Bars_Loaded==0)
    {
      int minute_last_bar=Time[0];
      if(minute_now-minute_last_bar<=minute_need)
      {
      Bars_Loaded=1;
      }   
      Alert("State :"+Bars_Loaded);
      Sleep(1000);     
    } 



 

 
LoRio:

Hello Mql.

I am developing an indicator on MQL4 , what i am doing is utilizing a while loop -blocking further operations- (placed in OnInit function) until

all the bars have loaded from the broker in a chart.

I Check if the current time - last candle time is <= one bar time for this period.

heres the segment that ... makes MT4 freeze . :)

Enlighten if you can . :)




 

You have answered your own question: it is blocking further operations.

https://docs.mql4.com/runtime/running

"All indicators share the resources of graphic interface thread of the terminal"

When you change the timeframe then the indicator blocks the terminal so it can not load the candles. If it can not load the candles, Bars_Loaded will be always 0...

 
lost89:

You have answered your own question: it is blocking further operations.

https://docs.mql4.com/runtime/running

"All indicators share the resources of graphic interface thread of the terminal"

When you change the timeframe then the indicator blocks the terminal so it can not load the candles. If it can not load the candles, Bars_Loaded will be always 0...

I see my error . Thank you .
I'll transform this to monitor if the candles have loaded through OnTimer and act accordingly