0bps

Strategy vault / Trend following

Enhanced EMA Crossover Strategy with RSI MACD ATR

This strategy uses the crossover of two Exponential Moving Averages (EMAs) as the main trading signal, combined with the Relative Strength Index (RSI), Moving Average Convergence Divergence (MACD), and Average True…

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

IMG

Overview

This strategy uses the crossover of two Exponential Moving Averages (EMAs) as the main trading signal, combined with the Relative Strength Index (RSI), Moving Average Convergence Divergence (MACD), and Average True Range (ATR) as auxiliary indicators to improve the reliability of trading signals. When the fast EMA crosses above the slow EMA, RSI is below 70, MACD line is above the signal line, and ATR value increases by more than 10% compared to the previous period, a long signal is generated; conversely, when the fast EMA crosses below the slow EMA, RSI is above 30, MACD line is below the signal line, and ATR value increases by more than 10% compared to the previous period, a short signal is generated. The strategy also sets fixed-point stop loss and take profit to control risk.

Strategy Principle

  1. Calculate the 8-period and 14-period EMAs as the fast and slow lines.
  2. Calculate the 14-period RSI and MACD indicators, using 12, 26, 9 as parameters for MACD.
  3. Calculate the 14-period ATR value.
  4. When the fast EMA crosses above the slow EMA, RSI is below 70, MACD line is above the signal line, and ATR value increases by more than 10% compared to the previous period, a long signal is generated.
  5. When the fast EMA crosses below the slow EMA, RSI is above 30, MACD line is below the signal line, and ATR value increases by more than 10% compared to the previous period, a short signal is generated.
  6. Set a stop loss of 100 points and a take profit of 200 points.
  7. Execute trades based on the trading signals and exit trades according to the stop loss and take profit settings.

Strategy Advantages

  1. Combines multiple technical indicators to improve the reliability of trading signals.
  2. Uses ATR as a filtering condition to trade only when market volatility increases, avoiding frequent trades in low-volatility ranges.
  3. Sets fixed-point stop loss and take profit to effectively control risk.
  4. The code is concise and easy to understand, making it easy to comprehend and optimize.

Strategy Risks

  1. Under certain market conditions, such as sideways markets or early stages of trend reversals, the strategy may generate more false signals.
  2. Fixed-point stop loss and take profit may not adapt to different market volatility situations, sometimes leading to premature stop loss or delayed take profit.
  3. The strategy does not consider fundamental factors of the market and relies entirely on technical indicators, which may lead to a disconnect from the market in some cases.

Strategy Optimization Directions

  1. Consider introducing more technical indicators or market sentiment indicators, such as Bollinger Bands, trading volume, etc., to further improve signal reliability.
  2. Optimize the setting of stop loss and take profit, such as using dynamic stop loss and take profit or volatility-based stop loss and take profit, to better adapt to market changes.
  3. Combine fundamental analysis, such as economic data and major events, to filter trading signals and avoid false signals in certain special situations.
  4. Optimize parameters, such as EMA periods, RSI and MACD parameters, etc., to find the most suitable parameter combination for the current market.

Summary

This strategy generates relatively reliable trading signals by combining multiple technical indicators such as EMA, RSI, MACD, and ATR, while controlling risk by setting fixed-point stop loss and take profit. Although the strategy still has some shortcomings, it can be improved through further optimization, such as introducing more indicators, optimizing stop loss and take profit, and combining fundamental analysis. Overall, the strategy is clear in its logic, easy to understand and implement, and suitable for beginners to learn and use.

Source Pine Script

/*backtest
start: 2024-03-01 00:00:00
end: 2024-03-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Enhanced EMA Crossover Strategy", overlay=true)

// Indicators
ema_fast = ema(close, 8)
ema_slow = ema(close, 14)
rsi = rsi(close, 14)

// Correcting the MACD variable definitions
[macd_line, signal_line, _] = macd(close, 12, 26, 9)
atr_value = atr(14)

// Entry conditions with additional filters
long_condition = crossover(ema_fast, ema_slow) and rsi < 70 and (macd_line > signal_line) and atr_value > atr_value[1] * 1.1
short_condition = crossunder(ema_fast, ema_slow) and rsi > 30 and (macd_line < signal_line) and atr_value > atr_value[1] * 1.1

// Adding debug information
plotshape(series=long_condition, color=color.green, location=location.belowbar, style=shape.xcross, title="Long Signal")
plotshape(series=short_condition, color=color.red, location=location.abovebar, style=shape.xcross, title="Short Signal")

// Risk management based on a fixed number of points
stop_loss_points = 100
take_profit_points = 200

// Order execution
if (long_condition)
    strategy.entry("Long", strategy.long, comment="Long Entry")
    strategy.exit("Exit Long", "Long", stop=close - stop_loss_points, limit=close + take_profit_points)

if (short_condition)
    strategy.entry("Short", strategy.short, comment="Short Entry")
    strategy.exit("Exit Short", "Short", stop=close + stop_loss_points, limit=close - take_profit_points)

// Plotting EMAs for reference
plot(ema_fast, color=color.blue, title="Fast EMA")
plot(ema_slow, color=color.orange, title="Slow EMA")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-04-29. 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/Enhanced-EMA-Crossover-Strategy-with-RSI-MACD-ATR.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