The major automated trading platforms such as MetaTrader 4, NinjaTrader and TradeStation all count time in the same way. This makes it quite convenient for ordering trading strategies and expert advisors; you don’t have to do any mental gymnastics to describe the strategy in different platforms. The consistent arrangement of time makes it easy for us to translate trading strategies across multiple platforms.
We tend to think of time as moving in the same direction as when we read. English speakers, who read from left to right, think of time as moving the same direction. If you speak a language like Arabic that reads right to left, you tend to think of time as marching to the left.
All of these charting platforms are written by speakers of left to right languages. The past is anything that’s not on the far right side. The present is the square on the far right. Each square represents an equal time interval. Traders know these as bars.
What tends to confuse everyone ordering expert advisors is that even though time marches to the right, trading programmers count the bars to the left. What makes things more confusing is that programmers always start counting from 0 instead of 1.
If you want to trade a moving average cross strategy that waits for the bars to close, what you’re looking at is “bar 2” and “bar 1”. The way I describe this in the scope of work is the value at two closed bars ago and the value at the last closed bar, respectively.
An expert advisor that uses closed bars ignores bar 0 because it is still open, which causes the moving average values to fluctuate. The only way to know for certain a moving average value at a particular bar is to wait for the bar to close, which means it is no longer bar 0. When a client requests an expert advisor that trades intrabar, they intend to compare the moving averages at “bar 1” with “bar 0”. In plain language, that means to compare the value at the last closed bar with the currently open bar.
Hopefully, this description makes sense when you open a chart and see the bars already loaded. The final confusing element is when a new bar pops onto the screen. The previous examples showed 5 bars on the chart (bars 0-4). When a sixth bar pops up, the count is reset to the new time period on every update.
Say that we’re looking at an H1 chart in MetaTrader and that the current time is 06:00. When the new hour strikes, the chart loads a new candle to represent 07:00. It’s at this time that the count resets.