Advertisement IC Markets

Higher timeframe moving averages on lower charts: the stair step problem

Optimize MetaTrader 4, MetaTrader 5, cTrader, and TradingView for speed. Discuss Level II Market Depth (DOM), custom hotkeys, and volume indicators.
Post Reply
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Higher timeframe moving averages on lower charts: the stair step problem

Post by Fairman »

Higher timeframe moving averages on lower charts: the stair step problem

A common setup is plotting, say, the H1 50 EMA on an M5 chart, so you can see the bigger trend without switching charts. TradingView and MT5 both let you do it, either through the indicator settings or a custom indicator.

The catch is how it's drawn. Each H1 value only exists once the hour closes. So on the M5 chart, the line stays flat for twelve candles, then jumps to the next value. It looks like stairs. Some versions smooth that out by drawing a line between the steps, which looks nicer but uses future data for the candles in between. On historical charts that line is a little better than what you'd have seen in real time.

There's also the question of the current hour. Some indicators show the still forming H1 value, which moves around until the hour closes. Others only show closed values, which lag but don't change.

Neither is wrong. You just need to know which one you're looking at, especially if you backtest by eye. A smooth higher timeframe MA can make pullback entries look cleaner in hindsight than they were.

I use the stepped version with closed values only. It's uglier but what I see in replay is what I'd have seen live.
It’s Fairman :geek:
Recommended broker for automated trading & scalping IC Markets
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Higher timeframe moving averages on lower charts: the stair step problem

Post by Fairman »

An alternative some people use is to scale the period instead, for example a 600 EMA on M5 to approximate an H1 50 EMA. It's not identical, since the EMA weights are applied to M5 closes rather than H1 closes, but it updates every M5 bar with no steps and no lookahead. The two will drift apart a bit, especially after sharp moves within the hour. For a rough trend filter that's often close enough, and it avoids the repaint question entirely. I'd pick one approach and stick to it in both analysis and backtesting, so the two match.
It’s Fairman :geek:
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Higher timeframe moving averages on lower charts: the stair step problem

Post by Fairman »

If you code this in an EA, be careful with which bar index you use from the higher timeframe. Reading bar zero gives the forming value, bar one the last closed one. Mixing them up is one of the most common reasons an EA backtests better than it trades. In MT5 the tester can also behave oddly with multi timeframe data at the start of a test, so I'd skip the first few days of results while the higher timeframe history loads in properly. Printing both bar zero and bar one values to the log for a few hours is a fast way to confirm the EA is reading what you think it's reading.
It’s Fairman :geek:
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Higher timeframe moving averages on lower charts: the stair step problem

Post by Fairman »

Another approach is to draw the higher timeframe average as a horizontal line at its last closed value rather than plotting it continuously. That makes it clear that the value only changes once per higher timeframe bar. It's less pretty but more honest about what the level is. Some custom indicators do this automatically, extending the last value forward until the next bar closes. It's a small visual change, but it stops the eye from reading the line as a smooth, constantly updating level. It also makes entries near the line easier to judge, since you know exactly which value you're comparing against.
It’s Fairman :geek:
FXS Prop Desk
Posts: 1689
Joined: Wed Oct 07, 2026 9:52 am

Re: Higher timeframe moving averages on lower charts: the stair step problem

Post by FXS Prop Desk »

A side effect of the stepped line that catches people out is alerts. If you set a "price crosses the H1 EMA" alert on the M5 chart, it can fire at the top of the hour simply because the line jumped through price, even though price itself barely moved. I'd filter those by requiring the M5 close to stay on the other side of the line for two bars after the step.

The step timing also depends on the server clock once you go above H1. An H4 average on a GMT+2 broker and one on a UTC chart close at different hours, so the same trend filter can disagree for a couple of hours after each step. Which clock is your backtest data on?
FXS Official Team | The Idea Lab & Strategy
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Higher timeframe moving averages on lower charts: the stair step problem

Post by Fairman »

In backtests, the stair step effect is easy to get wrong in a way that helps the results. If the code reads the higher timeframe value at the current lower bar, it might use the value of an H1 bar that hasn't closed yet, which includes future data relative to the M5 bar. That makes signals look better than they could ever be live. I'd check which H1 bar the code reads at, say, 10:05, and make sure it's the 09:00 bar. A simple test is to print the H1 bar time the code reads at a few M5 bars and check it against the chart.
It’s Fairman :geek:
Post Reply