Hello all,
I have an indicator which draws some 'permanent' objects (i.e. they aren't subsequently deleted by the indicator).
The problem I have is when I switch time frames - during the lag between the new timeframe opening and the candles updating, the indicator paints objects based on the old info.
Is there some way I can create a pause in init() when switching time frames, in order to allow all the tick data to catch up before the indicator starts working?
Many thanks in advance for any assistance.
What about using UninitializeReason() and Sleep().
For example:
init() { if (UninitializeReason() == REASON_CHARTCHANGE) // Pause for 2 seconds in half second intervals for (int i = 0; i <= 3; i++) sleep(500); }
Hello all,
I have an indicator which draws some 'permanent' objects (i.e. they aren't subsequently deleted by the indicator).
The problem I have is when I switch time frames - during the lag between the new timeframe opening and the candles updating, the indicator paints objects based on the old info.
Is there some way I can create a pause in init() when switching time frames, in order to allow all the tick data to catch up before the indicator starts working?
Many thanks in advance for any assistance.
No, don't pause in init() it has to return within, approx., 2 seconds, ...
Hmmm...I know that deinit() must complete within 2.5 seconds (or be forcibly terminated by Terminal) and start() must complete within 2.5 seconds if a termination call is made (or be forcibly terminated by Terminal). See Special Functions. But I'm unaware that init() is constrained by that same timing rule.
The code below seems to show that init() does not have to return within 2.5 seconds:
int init() { for (int i = 1; i <= 10; i++) { Sleep(500); Print (i, " - Just completed a half-second sleep."); } }
That code produced the following output:
EDIT: The above code is for an EA, not an indicator.
I have an indicator which draws some 'permanent' objects (i.e. they aren't subsequently deleted by the indicator).
The problem I have is when I switch time frames - during the lag between the new timeframe opening and the candles updating, the indicator paints objects based on the old info.
Is there some way I can create a pause in init() when switching time frames, in order to allow all the tick data to catch up before the indicator starts working?
Your indicator shouldn't be drawing anything except in start(). There may be no bars, market info, etc yet. Just fix your indicator, don't try to band aid it.
Indicators can not sleep. EAs may now be able to since there are multiple (8) trading threads in the latest versions. Just because it can, doesn't mean it should.
Hmmm...I know that deinit() must complete within 2.5 seconds (or be forcibly terminated by Terminal) and start() must complete within 2.5 seconds if a termination call is made (or be forcibly terminated by Terminal). See Special Functions. But I'm unaware that init() is constrained by that same timing rule.
The code below seems to show that init() does not have to return within 2.5 seconds: That code produced the following output:
Many thanks for the comments.
This is how I (think) I've fixed it:
bool FirstRun; int WaitTime; int init() { FirstRun = true; WaitTime = TimeLocal() + 5; return(0); } int start() { if(FirstRun == true) { if(TimeLocal()<WaitTime) { return(0); } else { FirstRun = false; } } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I have an indicator which draws some 'permanent' objects (i.e. they aren't subsequently deleted by the indicator).
The problem I have is when I switch time frames - during the lag between the new timeframe opening and the candles updating, the indicator paints objects based on the old info.
Is there some way I can create a pause in init() when switching time frames, in order to allow all the tick data to catch up before the indicator starts working?
Many thanks in advance for any assistance.