Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The Heikin Ashi Trend Shift is a trend-following continuation strategy built on Heikin-Ashi candles — a smoothed version of the standard Japanese candlestick chart. Where raw price candles flip colour from one bar to the next and produce a great deal of visual noise, Heikin-Ashi averages each candle into its neighbours, turning choppy price action into cleaner, more persistent runs of a single colour. This makes it easier to read who is in control of the market. The strategy is designed to trade the exact moment the smoothed candle colour shifts back in the direction of an established trend, treating that shift as a continuation signal rather than a guess at a market top or bottom.
The approach is built for trending markets. It pairs the Heikin-Ashi colour shift with an Exponential Moving Average (EMA) trend filter — a moving average that weights recent prices more heavily — so that it only looks for long entries while price trades above the EMA, and short entries while price trades below it. In the sideways chop around the average, the two filters effectively cancel each other and the strategy tends to stand aside. This regime-gate design is what keeps the system aligned with the prevailing direction instead of fighting it.
As a learning tool, this strategy suits traders who want to study how smoothing techniques, trend filters, and volatility-based risk management fit together in a single objective, rule-based system. Every condition is measured on closed bars only, so there is nothing subjective to interpret. It is best treated as a structured example of continuation-trade logic — a way to understand how a mechanical trend-follower is assembled — not as a shortcut to results.
How It Works
The strategy evaluates its rules once per newly-closed bar on the primary timeframe. It uses three ingredients: the Heikin-Ashi candle colour, an EMA trend filter, and the Average True Range (ATR), a common measure of market volatility. Here is how the pieces fit together.
Heikin-Ashi calculation (never repaints):
- Each smoothed close is the average of the raw open, high, low, and close.
- Each smoothed open is the average of the previous smoothed open and previous smoothed close.
- A candle is considered bullish when its Heikin-Ashi close is above its Heikin-Ashi open, and bearish when the close is below the open. Because these values are computed only on closed bars, the signal does not change after the fact.
Entry conditions — the colour shift:
- The strategy signals a long when the market is in an uptrend (raw close above the EMA) and the just-closed Heikin-Ashi candle flips bullish after the prior candle was not bullish — a resumed up-shift after a counter-trend pause.
- The strategy signals a short when the market is in a downtrend (raw close below the EMA) and the just-closed candle flips bearish after the prior candle was not bearish.
- A noise gate filters out weak, indecisive candles: the shift candle's body must be at least
BodyAtrFrac× ATR. This is the primary false-signal filter, and it prevents the strategy from acting on tiny "doji-like" candles that carry little conviction.
Exit conditions:
- Stop-loss: placed
AtrStopMult× ATR away from the entry price. Because the stop is scaled to ATR, it automatically widens in volatile conditions and tightens in calm ones. - Take-profit: set at
RewardRatiomultiplied by the stop distance. With the default settings, the target sits at twice the risk, which is intended to let trend winners help offset the trades that are filtered out or stopped early. - Opposite colour shift: if the smoothed candle flips against an open position, the strategy closes the trade early rather than waiting for the full stop — the smoothed trend read has turned against it.
- Trailing stop: a one-directional ATR trailing stop ratchets the stop behind price by
TrailAtrMult× ATR as a run extends. It only ever moves in the favourable direction, locking in open profit without capping the upside.
The system holds only one position at a time per Magic number, and it never stacks entries. Each signal acts once, on the close of a new bar.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| EmaPeriod | 50 | 20 | 200 | Lookback period of the EMA trend filter on raw closes. Longs are only considered above it, shorts only below it. |
| AtrPeriod | 14 | 7 | 30 | Lookback for the ATR volatility measure used by the noise gate, the stop, and the trailing stop. |
| BodyAtrFrac | 0.15 | 0.00 | 1.50 | Minimum Heikin-Ashi shift-candle body size, as a fraction of ATR. Higher values demand stronger candles and reject more noise. |
| AtrStopMult | 1.50 | 0.50 | 5.00 | Initial stop-loss distance from entry, expressed in ATR multiples. |
| RewardRatio | 2.00 | 1.00 | 6.00 | Take-profit distance as a multiple of the stop distance (the reward-to-risk ratio). |
| TrailAtrMult | 1.50 | 0.00 | 5.00 | ATR trailing-stop distance. Set to 0 to disable trailing entirely. |
| Lots | 0.10 | 0.01 | 1.00 | Order volume in lots. |
| Magic | 5731 | 0 | 9,999,999 | Unique identifier so the EA manages only its own positions. |

Recommended Chart Settings
The Heikin Ashi Trend Shift was designed with a liquid instrument and an intraday-to-swing timeframe in mind — for example a forex major such as EURUSD or a metal such as XAUUSD (gold) on the H1 (1-hour) chart. That said, every calculation reads the chart's own timeframe and every risk level is ATR-scaled, so the logic ports to other symbols and timeframes without hard-coded values.
Because market behaviour changes over time and differs between instruments, results will vary considerably across different symbols, sessions, and market conditions. Any timeframe or symbol you choose should be studied on its own before it is relied upon, ideally by observing how the colour-shift and EMA-filter interaction behaves on that specific chart.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
Like any mechanical system, the Heikin Ashi Trend Shift has clear strengths and equally clear limitations that are worth understanding before committing to it.
Strengths of the approach:
- Noise reduction. Heikin-Ashi smoothing filters out much of the bar-to-bar flicker that causes raw-candle systems to churn, which can help produce more patient, persistent signals.
- Trend alignment. The EMA regime gate keeps entries on the same side as the broader move, historically a sensible bias for continuation trading.
- Volatility-aware risk. Because stops, targets, and trailing all scale with ATR, the system adapts its risk footprint to current conditions rather than using fixed distances.
Known limitations:
- Range-bound whipsaws. In a sideways market, price crosses back and forth over the EMA and Heikin-Ashi candles flip repeatedly. This is the environment where trend-following logic historically struggles most, and the noise gate only partially mitigates it.
- Lag. Smoothing and moving averages are, by nature, lagging tools. A colour shift confirms a move that has already begun, so entries occur after the initial thrust, and sharp reversals can be caught late.
- Parameter sensitivity. Different
EmaPeriod,BodyAtrFrac, andRewardRatiocombinations can behave very differently. Over-tuning parameters to fit past data (curve-fitting) may produce a system that looks strong historically but does not generalise.
The honest summary is that this is a competent illustration of continuation-trade construction that may indicate trend resumption under favourable conditions, but it is not a solution for all markets and will experience losing streaks during choppy or news-driven phases.
Risk Management Tips
Sound risk management matters far more to long-term outcomes than any single entry rule. Whatever strategy you study, these general principles are worth internalising:
- Size positions deliberately. A common educational guideline is to risk no more than 1–2% of account equity on any single trade. Adjust the
Lotsinput so that the ATR-based stop distance corresponds to that fraction of your account, rather than trading a fixed lot size blindly. - Test on a demo account first. Run the EA on a demo or paper account across a range of market conditions before considering any live capital. This lets you observe its behaviour without financial consequences.
- Understand drawdown. Every strategy endures losing streaks. Know the maximum peak-to-trough decline you are willing to tolerate, and understand that a string of losses is a normal part of any trend-following system, not necessarily a sign that something is broken.
- Avoid over-leverage. Leverage magnifies losses just as much as gains. Conservative use of leverage gives a strategy room to survive the inevitable rough patches.
- Keep expectations grounded. Backtests and historical behaviour describe the past, not the future. Treat all analysis as a learning exercise rather than a prediction.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: HeikinAshiTrendShift.ex5 (5 downloads)
- Source Code: HeikinAshiTrendShift.mq5 (3 downloads)
- Documentation: HeikinAshiTrendShift.pdf (4 downloads)