You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Mladen, do I understand you correct that you don't recommend using a timer? Do you think my code is the most efficient way to make sure that no candle is missing?
If I loop all symbols and all timeframes constantly with every tick I can be pretty sure that I don't miss any new candle.
For the job you want to do the best way is to use the timer (as @Marco vd Heijden has already told in his post)
Timer eliminates the need for a tick and makes sure that you check data for symbols different from current chart symbol even is there is not incoming tick
Would this be the correct way to use the timer-event?
Now the OnTimer function is called every minute and the function itself does the work.
So now it's not executed with every tick anymore.
Would this be the correct way to use the timer-event?
Now the OnTimer function is called every minute and the function itself does the work.
So now it's not executed with every tick anymore.
Yes, that is OK
Bare in mind though that with a timer set to 1 minute. you can have potential maximal lag of 59 seconds between the new bar forming for some time frame + symbol and testing that time frame + symbol.
Yes and if you want it to be faster you can use:
Then it checks twice a second but make sure that the entire calculation fits otherwise it will start to cause problems due to calculations not being finished before the next timer cycle set's in it may become unstable.
So it depends on how fast you want / need it to be.
If you lowest time frame is M5 then a check every minute is fine.
Yes, that is OK
Bare in mind though that with a timer set to 1 minute. you can have potential maximal lag of 59 seconds between the new bar forming for some time frame + symbol and testing that time frame + symbol.
Yes, 59 seconds is fine. I think I will adjust the timer interval to my needs. I am not sure which timeframes I need at the end.
Yes and if you want it to be faster you can use:
Then it checks twice a second but make sure that the entire calculation fits otherwise it will start to cause problems due to calculations not being finished before the next timer cycle set's in it may become unstable.
So it depends on how fast you want / need it to be.
If you lowest time frame is M5 then a check every minute is fine.
Thanks a lot!
I think at the end I might use M30-H4. So I will use a higher interval and I will make sure that I start the MT4 at a full or half hour.
I am not really sure what you mean with working with TimeCurrent() in this case. In my opinion the time is not so important because I have to make sure that a new candle started and that is not always with XX:XX:00. More often that not the first tick of a new candle comes (in quiet times) 10 seconds late.
I'm saying that, since you asked about optimisations, it's possible to do far less work per tick/timer than processing all of 28x5 = 140 different combinations and calling iTime() on all of them.
But the following approach contains two relatively subtle assumptions about undocumented aspects of the way MT4 works internally:
I'm saying that, since you asked about optimisations [...]
... but it then becomes a question of what's a meaningful optimisation. On the average tick/timer/test when no new bar has formed, the code above is about 300 times faster than doing all the checks on iTime(). But the iTime-based version still only consumes about 1 millisecond per check. So, my version would only be a meaningful improvement if you wanted to use something like this in backtesting. It's not going to make any material difference in real-life use.
I'm saying that, since you asked about optimisations, it's possible to do far less work per tick/timer than processing all of 28x5 = 140 different combinations and calling iTime() on all of them.
But the following approach contains two relatively subtle assumptions about undocumented aspects of the way MT4 works internally:
Very interesting approach using a very different coding-style compared to mine. It's definitely something I can learn a lot from. Thank you for that!