Momentum Capture Strategy Based on Moving Average
This strategy uses moving average as the main trading signal, combined with Heikin-Ashi to detect trend reversal, aiming to capture short-term price momentum. It is optimized from Gustavo Bramao's Heikin Ashi MA…

Overview
This strategy uses moving average as the main trading signal, combined with Heikin-Ashi to detect trend reversal, aiming to capture short-term price momentum. It is optimized from Gustavo Bramao's Heikin Ashi MA strategy by removing the repainting function to generate non-lagging signals.
Strategy Logic
Calculate Heikin-Ashi close price nAMAn as the price baseline.
Calculate fast moving average fma and slow moving average sma based on nAMAn.
Generate buy signal when fma crosses over sma, and sell signal when fma crosses below sma.
The repainting is removed in this strategy to generate real-time trading signals and avoid backtesting bias.
Advantage Analysis
Heikin-Ashi helps determine trend reversal points more accurately.
The MA crossover filters out false signals effectively.
No lagging in signal generation ensures reliable live performance.
Flexible parameter tuning adaptable for different products.
Simple and clear logic, easy to understand and implement.
Can be automated completely to minimize manual trading risks.
Risk Analysis
Poor performance in range-bound market with price whipsaws.
Prone to generating false signals with dual MA crossover.
Inappropriate MA parameters may cause missing trends or increasing drawdown.
Trading cost impacts net profit in live trading.
Strict stop loss required to control single trade loss.
Mechanical trading strategies have inherent drawdown risks and require proper capital management.
Risk Management Solutions:
Add volatility filter to avoid range-bound market.
Add filters to ensure signal quality.
Optimize MA parameters through thorough testing.
Adjust trading frequency to reduce cost impact.
Set proper stop loss to control loss in single trades.
Optimize capital management to control position sizing.
Enhancement Directions
Optimize MA parameters to improve signal quality.
Add trend filter to avoid whipsaw market.
Incorporate volume indicators to confirm trend.
Implement dynamic stop loss and profit taking to optimize profit capturing.
Integrate capital management module to control position sizing.
Add algorithmic trading module for full automation.
Summary
This strategy integrates Heikin-Ashi and MA crossover techniques to create a simple and practical short-term trend following strategy. It generates reliable real-time trading signals and shows good performance in live trading. Further optimizations on parameters, risk management, and algorithmic trading modules can turn it into a fully automated strategy that is trustworthy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_timeframe_1 | D | Heikin Ashi EMA Time Frame |
| v_input_1 | false | Heikin Ashi EMA Shift |
| v_input_2 | 20 | Slow EMA Period |
| v_input_int_1 | 5 | Length |
| v_input_3_hlc3 | 0 | xPrice: hlc3 | high | low | open | hl2 | close | hlcc4 | ohlc4 |
| v_input_float_1 | 2.5 | Fastend |
| v_input_4 | 20 | Slowend |
Source Pine Script
/*backtest
start: 2022-10-25 00:00:00
end: 2023-10-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
//Heikin/Kaufman by Gustavo v5
// strategy('Heikin Ashi EMA v5 no repaint ', shorttitle='Heikin Ashi EMA v5 no repaint', overlay=true, max_bars_back=500, default_qty_value=1000, initial_capital=100000, currency=currency.EUR)
// Settings - H/K
res1 = input.timeframe(title='Heikin Ashi EMA Time Frame', defval='D')
test = input(0, 'Heikin Ashi EMA Shift')
sloma = input(20, 'Slow EMA Period')
nAMA = hlc3
//Kaufman MA
Length = input.int(5, minval=1)
xPrice = input(hlc3)
xvnoise = math.abs(xPrice - xPrice[1])
Fastend = input.float(2.5, step=.5)
Slowend = input(20)
nfastend = 2 / (Fastend + 1)
nslowend = 2 / (Slowend + 1)
nsignal = math.abs(xPrice - xPrice[Length])
nnoise = math.sum(xvnoise, Length)
nefratio = nnoise != 0 ? nsignal / nnoise : 0
nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMAn = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
//Heikin Ashi Open/Close Price
ha_t = ticker.heikinashi(syminfo.tickerid)
ha_close = request.security(ha_t, timeframe.period, nAMAn)
mha_close = request.security(ha_t, res1, hlc3)
//Moving Average
fma = ta.ema(mha_close[test], 1)
sma = ta.ema(ha_close, sloma)
plot(fma, title='MA', color=color.new(color.black, 0), linewidth=2, style=plot.style_line)
plot(sma, title='SMA', color=color.new(color.red, 0), linewidth=2, style=plot.style_line)
//Strategy
golong = ta.crossover(fma, sma)
goshort = ta.crossunder(fma, sma)
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-11-01. 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/Momentum-Capture-Strategy-Based-on-Moving-Average.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
- Momentum Crossover Moving Average and MACD Filter Heikin Ashi Candlestick StrategyPine Script · Momentum · 1d
- Black Swan Volatility and Moving Average Crossover Momentum Tracking StrategyPine Script · Momentum · 45m
- ADX Momentum Trend StrategyPine Script · Momentum · 10m
- Bollinger Bands Momentum Trend Following Quantitative StrategyPine Script · Momentum · 1d
- KST EMA Momentum Trend Following StrategyPine Script · Momentum · 1d
- MACD Momentum Indicator Backtest StrategyPine Script · Momentum · 1h