Strategy vault / Trend following
Heikin Ashi and Kaufman Adaptive Moving Average Trading Strategy
The Heikin Ashi and Kaufman Adaptive Moving Average Trading Strategy (HLC3/Kaufman Strategy) is a quantitative trading strategy that combines Heikin Ashi candles and Kaufman Adaptive Moving Average (KAMA). It uses…

Overview
The Heikin Ashi and Kaufman Adaptive Moving Average Trading Strategy (HLC3/Kaufman Strategy) is a quantitative trading strategy that combines Heikin Ashi candles and Kaufman Adaptive Moving Average (KAMA). It uses Heikin Ashi candles to determine trading direction and KAMA as an auxiliary indicator for trade signal filtering.
Strategy Logic
The main components of this strategy are:
Calculate Heikin Ashi open and close prices. These prices reflect the middle price of candle bodies and can filter out some noise.
Calculate Kaufman Adaptive Moving Average (KAMA). KAMA can dynamically adjust its smoothness and will not lag too much during sharp market fluctuations.
Compare the relationship between Heikin Ashi close and KAMA to determine buy and sell signals. When Heikin Ashi close crosses over KAMA, a buy signal is generated. When Heikin Ashi close crosses below KAMA, a sell signal is generated.
Add ADX indicator to judge the strength of the trend to avoid wrong signals in range-bound markets.
Advantage Analysis
The biggest advantage of this strategy is the dual filter of Heikin Ashi candles and KAMA, which can greatly reduce noisy trades and wrong signals. The specific advantages are:
- Heikin Ashi candles themselves have noise reduction capabilities to filter out some short-term fluctuations.
- KAMA is more sensitive than SMA and EMA and can effectively track trend changes at major levels.
- The combination of Heikin Ashi and KAMA dual filters can reduce errors.
- ADX indicator can be configured to determine the strength of the trend to avoid wrong signals.
- Trading signals are direct and easy to operate flexibly.
Risk Analysis
- Wrong signals may occur in some ranging markets. Parameters should be adjusted accordingly to avoid this risk.
- Overly sensitive parameters can easily chase peaks and kill bottoms. KAMA parameters should be relaxed properly.
- In long-term trending markets, KAMA may lag behind price changes to some extent. ADX should be combined to determine the stability of the trend.
Optimization Directions
- Optimize Heikin Ashi close and KAMA parameters to find the best filtering conditions.
- Add trend judging indicators such as ADX to ensure trading signals are generated only when the trend is stable.
- Combine other auxiliary indicators such as Bollinger Bands to set stop loss standards.
- Test the stability of parameters on different products to find the optimal parameter combinations.
Summary
The Heikin Ashi and Kaufman Adaptive Moving Average Trading Strategy is a dual filter trend tracking strategy. It combines the noise reduction capability of Heikin Ashi candles and KAMA's fast tracking of trend changes to effectively filter out noise trades and reduce wrong signals. It is suitable for tracking medium and long term trends. The strategy can be further enhanced in terms of stability and profitability through parameter optimization, confirmation by auxiliary indicators, etc.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | D | Hlc3 Time Frame |
| v_input_2 | true | Hlc3 Shift |
| v_input_3 | 20 | Slow EMA Period |
| v_input_4 | 5 | Length |
| v_input_5_hlc3 | 0 | xPrice: hlc3 | high | low | open | hl2 | close | hlcc4 | ohlc4 |
| v_input_6 | 2.5 | Fastend |
| v_input_7 | 20 | Slowend |
Source Pine Script
/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//Heikin/Kaufman by Marco
strategy("HLC3/Kaufman Strategy ",shorttitle="HLC3/KAU",overlay=true)
res1 = input(title="Hlc3 Time Frame", defval="D")
test = input(1,"Hlc3 Shift")
sloma = input(20,"Slow EMA Period")
//Kaufman MA
Length = input(5, minval=1)
xPrice = input(hlc3)
xvnoise = abs(xPrice - xPrice[1])
Fastend = input(2.5,step=.5)
Slowend = input(20)
nfastend = 2/(Fastend + 1)
nslowend = 2/(Slowend + 1)
nsignal = abs(xPrice - xPrice[Length])
nnoise = sum(xvnoise, Length)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMA = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
//Heikin Ashi Open/Close Price
//ha_t = heikinashi(tickerid)
//ha_close = request.security(ha_t, period, nAMA)
//mha_close = request.security(ha_t, res1, hlc3)
bha_close = request.security(syminfo.ticker, timeframe.period, nAMA)
bmha_close = request.security(syminfo.ticker, res1, hlc3)
//Moving Average
//fma = ema(mha_close[test],1)
//sma = ema(ha_close,sloma)
//plot(fma,title="MA",color=black,linewidth=2,style=line)
//plot(sma,title="SMA",color=red,linewidth=2,style=line)
bfma = ema(bmha_close[test],1)
bsma = ema(bha_close,sloma)
plot(bfma,title="MA",color=black,linewidth=2,style=line)
plot(bsma,title="SMA",color=red,linewidth=2,style=line)
//Strategy
//golong = crossover(fma,sma)
//goshort = crossunder(fma,sma)
golong = crossover(bfma,bsma)
goshort = crossunder(bfma,bsma)
strategy.entry("Buy",strategy.long,when = golong)
strategy.entry("Sell",strategy.short,when = goshort)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-19. 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/Heikin-Ashi-and-Kaufman-Adaptive-Moving-Average-Trading-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
- Quantitative Trend Tracking StrategyPine Script · Trend following · 5h
- DPO EMA Trend Crossover Quantitative Strategy ResearchPine Script · Trend following · 1d
- Dual directional Trailing Stop Moving Average Trend StrategyPine Script · Trend following · 1m
- Trend Following Strategy Based on Multiple IndicatorsPine Script · Trend following · 2h
- WaveTrend and DER Based Swing Trading StrategyPine Script · Trend following · 1d
- Dynamic Moving Average Trend Trading StrategyPine Script · Trend following · 1d