Strategy vault / Trend following
Heiken Ashi Crossover Strategy
The Heiken Ashi Crossover Strategy is a quantitative trading strategy that applies both the Heiken Ashi crossover principle and smoothing techniques. By calculating the average price over 4 periods to generate the…

Overview
The Heiken Ashi Crossover Strategy is a quantitative trading strategy that applies both the Heiken Ashi crossover principle and smoothing techniques. By calculating the average price over 4 periods to generate the smoothed price, and then computing the Heiken Ashi crossover based on the smoothed prices, it can issue reliable trading signals. Compared with the original Heiken Ashi crossover, this strategy can filter out short-term market noise and avoid wrong signals by using smoothing techniques.
Strategy Logic
The core logic behind this strategy includes:
Heiken Ashi Crossover Principle
Heiken Ashi crossover refers to the buy or sell signals generated when the short-term moving average crosses over or below the long-term moving average. In this strategy, the short-term MA is the smoothed closing price (haclose), while the long-term MA is the smoothed opening price (haopen).
Smoothing Techniques
To filter out noise, this strategy adopts the average price over 4 periods to calculate the smoothed price:
haclose = (open + high + low + close) / 4
haopen = (previous haopen + current haclose) / 2
The Heiken Ashi crossover signals based on the smoothed prices above can provide more reliable trading signals. A buy signal is generated when haclose crosses over haopen, while a sell signal is triggered when haclose crosses below haopen.
Advantage Analysis
Compared with the original Heiken Ashi crossover strategy, the Smoothed Heiken Ashi Crossover Strategy has the following edges:
The smoothing techniques filter out short-term market noises and avoid wrong signals, thus improving the quality of trading signals.
By adopting the 4-period average price to calculate the smoothed price, it can better reflect the medium-to-long term trend and generate more reliable trading signals.
Combined with the fast-crossover feature of Heiken Ashi, this strategy can timely capture the turning points of medium-to-long term trends.
Risk Analysis
There are also some risks associated with this strategy:
In periods of violent market fluctuation, the smoothing techniques may filter out some effective signals, thus missing potential trading opportunities.
The 4-period moving average calculation also introduces a certain degree of lag, which may result in missing short-term opportunities.
This strategy has some requirements on trading frequency and holding period. It is not suitable for overly frequent or long-term trading.
To tackle the risks above, parameters tuning of the smoothing techniques and incorporating other technical indicators can be helpful solutions.
Optimization Directions
This strategy can be optimized in the following aspects:
Parameter tuning for the smoothing techniques, like adjusting the moving average period, to find the optimal parameter combination.
Incorporating other indicators like volume, Bollinger Bands etc. to improve the accuracy of trading signals.
Adding stop loss strategies like trailing stop loss, pyramiding stop loss to control risks.
Optimizing money management by setting proper position sizing and stop loss levels to limit the loss of single trades.
Conclusion
The Heiken Ashi Crossover Strategy combines the Heiken Ashi crossover principle and smoothing techniques, which can effectively detect trend turning points in the medium-to-long term without being interfered by short-term market noises. Compared with the original Heiken Ashi crossover, this strategy filters out some noise by smoothing techniques and thus can generate higher quality trading signals. With proper stop loss and money management, this strategy can earn relatively steady returns from the market. However, traders should also be aware of the risks like lag and missing signals, and optimize the strategy accordingly.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | From Month |
| v_input_2 | true | From Day |
| v_input_3 | 2017 | From Year |
| v_input_4 | true | To Month |
| v_input_5 | true | To Day |
| v_input_6 | 9999 | To Year |
Source Pine Script
/*backtest
start: 2022-12-06 00:00:00
end: 2023-12-12 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("Heikin-Ashi Strategy", overlay=true)
// Plots Color Of Heikin-Ashi Bars while Viewing Candlestics or Bars
//Works on Candlesticks and OHLC Bars - Does now work on Heikin-Ashi bars - But I have verified its accuracy
// Created By User ChrisMoody 1-30-2014 with help from Alex in Tech Support
// === BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1)
FromDay = input(defval = 1, title = "From Day", minval = 1)
FromYear = input(defval = 2017, title = "From Year", minval = 1998)
ToMonth = input(defval = 1, title = "To Month", minval = 1)
ToDay = input(defval = 1, title = "To Day", minval = 1)
ToYear = input(defval = 9999, title = "To Year", minval = 1998)
haclose = ((open + high + low + close)/4)//[smoothing]
haopen = na(haopen[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2
heikUpColor() => haclose > haopen
heikDownColor() => haclose <= haopen
barcolor(heikUpColor() ? aqua: heikDownColor() ? red : na)
if (heikUpColor() )
strategy.entry("LONG", strategy.long, comment="LONG")
if (heikDownColor())
strategy.entry("SHORT", strategy.short, comment="SHORT")
//plot(pos, title="pos", style=line, linewidth=1, color=red )Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-13. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Heiken-Ashi-Crossover-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- Dual EMA Filtered ATR Adaptive Trend Following StrategyPine Script · Trend following · 1h
- Dual Hull Moving Average Trading StrategyPine Script · Trend following · 1d
- Full Crypto Swing ALMA Cross MACD Quantitative StrategyPine Script · Trend following · 1h
- Heiken Ashi and Super Trend Combination StrategyPine Script · Trend following · 1d
- Incremental Order Size Fibonacci Retracement Trend Following StrategyPine Script · Trend following · 1d