What's the best practice for handling repeated true if conditions due to multiple ticks during one period?
- Trading Principles - Trade - MetaTrader 5 for iPhone
- Trading Principles - Trade - MetaTrader 5 for Android
- Real and Generated Ticks - Algorithmic Trading, Trading Robots
-
There is no onPeriodClose because you can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.
What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles 20 June 2006
No candle if open = close ? - MQL4 programming forum 2010.06.06For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum 2014.04.04 - Don't look at a signal. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12 - Both
Suppose you want to do some action where if on the previous candle of some period indicator a == some value and indicator b<c then open a long position.
use global variable, change when condition is met, set it back when you are done with the outcome of your expected condition
This is exactly what I was describing, albeit less succinct. But you still have the situation where your condition tests true, so you have to include your global variable in the test condition. Which works for a simple situation, but it just seems that you could end up with a lot of global variables, and "did it get set at the right time and set back at the right time". All to overcome this problem of testing the same criteria on every tick, when you are really looking for it one time at each period of a time frame. But I suppose that's how you do it.
There is no onPeriodClose because you can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.
Not really meaning a candle as much as the time of a peroid. i.e. M1 has a peroid of one minute, so at 12:01:00 the period of 12:00:00 closed. Possibly you mean the same thing by Always use time? But how do you use time? I read the paragraph description for OnTimer previously because I thought that would be the trick to testing a condition every minute, but it lead me to believe that it was for notification event. However, further investigation seems like maybe OnTimer could work for such a situation. Is that what you meant by Always use time?
This is exactly what I was describing, albeit less succinct. But you still have the situation where your condition tests true, so you have to include your global variable in the test condition. Which works for a simple situation, but it just seems that you could end up with a lot of global variables, and "did it get set at the right time and set back at the right time". All to overcome this problem of testing the same criteria on every tick, when you are really looking for it one time at each period of a time frame. But I suppose that's how you do it.
There is no onPeriodClose because you can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.
Not really meaning a candle as much as the time of a peroid. i.e. M1 has a peroid of one minute, so at 12:01:00 the period of 12:00:00 closed. Possibly you mean the same thing by Always use time? But how do you use time? I read the paragraph description for OnTimer previously because I thought that would be the trick to testing a condition every minute, but it lead me to believe that it was for notification event. However, further investigation seems like maybe OnTimer could work for such a situation. Is that what you meant by Always use time?
darkenedforest: Always use time? But how do you use time?
I read the paragraph description for OnTimer previously because I thought that would be the trick to testing a condition every minute, but it lead me to believe that it was for notification event. However, further investigation seems like maybe OnTimer could work for such a situation. Is that what you meant by Always use time?
- Do you see those lines that are blue and underlined? They are links. Click on them and they take you to more information. (#1.1 last link)
- It is a notification event, for equal times. Timing of new bars are not. (#1.1 second paragraph)
- Do you see those lines that are blue and underlined? They are links. Click on them and they take you to more information. (#1.1 last link)
- It is a notification event, for equal times. Timing of new bars are not. (#1.1 second paragraph)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use