EMA and Heikin Ashi Trading Strategy
This strategy uses exponential moving averages (EMA) and Heikin Ashi to determine trends and generate trading signals when prices break through EMAs of different periods.

Here is an article about EMA and Heikin Ashi trading strategies:
Overview
This strategy uses exponential moving averages (EMA) and Heikin Ashi to determine trends and generate trading signals when prices break through EMAs of different periods.
Trading Logic
The strategy uses 15-period and 50-period EMAs. It calculates the current Heikin Ashi closing price and compares it to the EMAs. If the closing price is above both EMAs and the 15-period EMA is above the 50-period EMA, a long signal is generated. If the closing price is below both EMAs and the 15-period EMA is below the 50-period EMA, a short signal is generated.
When the price breaks back above the 15-period EMA, a reverse trade is made.
Advantage Analysis
Using EMAs helps filter out market noise and determine trend direction.
Combining EMAs of different periods captures both short-term and mid-term trends.
Heikin Ashi filters out false breakouts and confirms trading signals.
The strategy is simple and easy to implement.
Risk Analysis
EMAs have lag and may miss trend turning points.
Fixed parameters fail to adapt to changing markets, requiring dynamic optimization.
Frequent trading leads to potentially high transaction costs.
Breakout trading is susceptible to false breakouts, requiring additional indicator confirmation.
Risks can be reduced through parameter optimization, integrating other indicators, etc.
Optimization Directions
Dynamically optimize EMA periods based on market changes.
Optimize breakout filters to avoid false breakouts, e.g. add volume confirmation.
Incorporate other indicators like MACD to confirm signals.
Use lagging EMA for trends and leading EMA for ranges.
Summary
This strategy uses EMAs to determine trend direction and Heikin Ashi to verify signals. It is simple and straightforward but EMA lag and false breakout risks need to be addressed. Improvements can be made via parameter optimization, indicator integration to reduce risk and improve strategy performance.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1_close | 0 | price: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_2 | 15 | MA1_Length |
| v_input_3 | 50 | MA2_Length |
Source Pine Script
/*backtest
start: 2023-10-09 00:00:00
end: 2023-10-12 02:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("EMA & Heikin Ashi", shorttitle="EMA & Heikin Ashi", overlay=true, initial_capital=1)
// squaa's Strategy
//
// Idea by Thw on March 10, 2018.
//
//
// The strategy should be used with high leverages,
// never stop running,
// and is always long or short.
// Input
price = input(close)
MA1_Length = input(15)
MA2_Length = input(50)
haclose = request.security(heikinashi(syminfo.tickerid), timeframe.period, close)
// === FUNCTION EXAMPLE ===
start = timestamp(2018, 01, 01, 20, 00) // backtest start window
window() => time >= start ? true : false // create function "within window of time"
// Calculation
MA1 = ema(price, MA1_Length)
MA2 = ema(price, MA2_Length)
// Strategy
long = haclose > MA1 and haclose > MA2 and MA1 > MA2 and window()
short = haclose < MA1 and haclose < MA2 and MA1 < MA2 and window()
// MA trend output color
MA2_color = long?lime:short?red:blue
strategy.entry("Long", strategy.long, when=long)
strategy.entry("Short", strategy.short, when=short)
strategy.close("Long", when=haclose < MA1)
strategy.close("Short", when=haclose > MA1)
// MA output
EMA1 = plot(MA1, title="EMA 1", style=linebr, linewidth=1, color=MA2_color)
EMA2 = plot(MA2, title="EMA 2", style=linebr, linewidth=3, color=MA2_color)
fill(EMA1, EMA2, color=silver, transp=50)
//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-17. 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/EMA-and-Heikin-Ashi-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
- Kana Candle Breakout Strategy Based on Moving Average and Support ResistancePine Script · Breakout · 1h
- Momentum Breakout Trading Strategy 440964Pine Script · Breakout · 5m
- Multi Technical Indicator Dynamic Wave Trading StrategyPine Script · Breakout · 1h
- Quantitative Trading Strategy Based on Ichimoku with Multiple SignalsPine Script · Breakout · 1h
- Moving Average Tracking Trading StrategyPine Script · Breakout · 3h
- EMA ADX VOL CRYPTO KILLERPine Script · Breakout · 1d