0bps

Strategy vault / Breakout

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.

Author
ChaoZhang
Complexity
Starter · 57 lines
Parameters
3
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

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

  1. Using EMAs helps filter out market noise and determine trend direction.

  2. Combining EMAs of different periods captures both short-term and mid-term trends.

  3. Heikin Ashi filters out false breakouts and confirms trading signals.

  4. The strategy is simple and easy to implement.

Risk Analysis

  1. EMAs have lag and may miss trend turning points.

  2. Fixed parameters fail to adapt to changing markets, requiring dynamic optimization.

  3. Frequent trading leads to potentially high transaction costs.

  4. Breakout trading is susceptible to false breakouts, requiring additional indicator confirmation.

Risks can be reduced through parameter optimization, integrating other indicators, etc.

Optimization Directions

  1. Dynamically optimize EMA periods based on market changes.

  2. Optimize breakout filters to avoid false breakouts, e.g. add volume confirmation.

  3. Incorporate other indicators like MACD to confirm signals.

  4. 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

NameDefaultWhat it controls
v_input_1_close0price: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_215MA1_Length
v_input_350MA2_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.

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/EMA-and-Heikin-Ashi-Trading-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