0bps

Strategy vault / Trend following

Multi Timeframe Heiken Ashi Crossover Strategy

This strategy uses Heiken Ashi candles across three timeframes to generate signals when all timeframes align bullish or bearish. It aims to confirm trend using multiple timeframes to reduce false signals.

Author
ChaoZhang
Complexity
Starter · 51 lines
Parameters
5
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

Overview

This strategy uses Heiken Ashi candles across three timeframes to generate signals when all timeframes align bullish or bearish. It aims to confirm trend using multiple timeframes to reduce false signals.

Principles

Heiken Ashi candles differ from regular candles by smoothing price action for easier trend identification.

The strategy employs daily, weekly and monthly Heiken Ashi candles. When all three align bullish, with green candles, long signal is generated. When all red candles, short signal is generated.

Exits when any timeframe flips direction after entry.

Advantages

  1. Multi-timeframe confirmation reduces false signals and enhances robustness.

  2. Heiken Ashi smooths noise to identify trend.

  3. Simple straightforward rules easy to implement.

  4. Flexible timeframes adaptable to different products.

  5. No parameter optimization required, very easy to use.

Risks and Mitigations

  1. Strict conditions may miss opportunities. Can relax condition requirements.

  2. Heiken Ashi lag remains, potentially delaying signals. Can optimize with additional indicators.

  3. No stop loss inability to control risk. Can add moving stop loss.

  4. Fixed risk-reward lacks flexibility. Can implement dynamic stops.

  5. Indicator-only prone to false signals. Can add price-volume confirmation.

Enhancement Opportunities

  1. Test additional timeframes like 15m or 60m.

  2. Optimize Heiken Ashi parameters for sensitivity.

  3. Add moving stop loss for risk control.

  4. Incorporate market structure indicators to avoid ranges.

  5. Develop re-entry conditions to extend holding period.

Summary

The strategy taps into Heiken Ashi across timeframes for trend following, but indicator-only design prone to false signals. Improvements can be made via additional indicators, stops, parameter optimization to make it more reliable. Overall the multi-timeframe confirmation is a useful concept.

Parameters

NameDefaultWhat it controls
v_input_1DTM 1
v_input_2WTM 2
v_input_3MTM 3
v_input_4truelongA
v_input_5falseshortA

Source Pine Script

/*backtest
start: 2023-01-01 00:00:00
end: 2023-03-23 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
args: [["v_input_5",true]]
*/

//@version=4
strategy("Heiken Ashi MTF Strategy")
ha_t = heikinashi(syminfo.tickerid)

res = input('D', title="TM 1")
ha_open = security(ha_t, res, open)
ha_close = security(ha_t, res, close)
ha_dif = ha_open-ha_close
ha_diff=iff(ha_dif > 0, 1, iff(ha_dif<0, 2, 3))

res2 = input('W', title="TM 2")
ha_open2 = security(ha_t, res2, open)
ha_close2 = security(ha_t, res2, close)
ha_dif2 = ha_open2-ha_close2
ha_diff2=iff(ha_dif2 > 0, 1, iff(ha_dif2<0, 2, 3))

res3 = input('M', title="TM 3")
ha_open3 = security(ha_t, res3, open)
ha_close3 = security(ha_t, res3, close)
ha_dif3 = ha_open3-ha_close3
ha_diff3=iff(ha_dif3 > 0, 1, iff(ha_dif3<0, 2, 3))

plot(15, title="TF1", color=iff(ha_diff==1, color.red, iff(ha_diff==2, color.green, color.white)), style=plot.style_circles, linewidth=5, join=true)
plot(14, title="TF2", color=iff(ha_diff2==1, color.red, iff(ha_diff2==2, color.green, color.white)), style=plot.style_circles, linewidth=5, join=true)
plot(13, title="TF3", color=iff(ha_diff3==1, color.red, iff(ha_diff3==2, color.green, color.white)), style=plot.style_circles, linewidth=5, join=true)


short = ha_diff ==1 and ha_diff2==1 and ha_diff3 ==1
long = ha_diff ==2 and ha_diff2==2 and ha_diff3 ==2

exitlong = ha_diff ==1 or ha_diff2==1 or ha_diff3 ==1
exitshort = ha_diff ==2 or ha_diff2==2 or ha_diff3 ==2

longA = input(true)
shortA = input(false)

if(longA)
    strategy.entry("long",1,when=long)
    strategy.close("long",when=exitlong)
if(shortA)
    strategy.entry("short",0,when=short)
    strategy.close("short",when=exitshort)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-18. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Multi-Timeframe-Heiken-Ashi-Crossover-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open