EMA Reverse Buy-Sell Strategy

Author: ChaoZhang, Date: 2023-11-28 16:54:14
Tags:

img

Overview

This is a trend following strategy based on EMA lines. It uses two EMA lines with different periods, 21 and 55. When the faster EMA line crosses above the slower EMA line, a buy signal is generated. When the faster EMA crosses below the slower one, a sell signal is generated.

In addition, the strategy incorporates reverse trading, ATR stop loss, and reversal take profit to enhance its stability and profitability.

Strategy Logic

  1. Use 21 and 55 period EMA lines. 21 EMA represents short-term trend and 55 EMA represents long-term trend.

  2. When 21 EMA crosses above 55 EMA, it indicates the short-term trend changes to upward, generating a buy signal.

  3. When 21 EMA crosses below 55 EMA, it indicates the short-term trend turns downward, generating a sell signal.

  4. Reverse trading: only buy when price is below open price, and only sell when price is above open price. This aims to buy on short-term pullbacks and sell on rebounds.

  5. ATR stop loss: use N times ATR to set stop loss price. This dynamically adjusts stop loss based on market volatility.

  6. Reversal take profit: use entry price minus N times ATR as profit target. This takes advantage of price retesting previous support-turned-resistance area.

Advantages of the Strategy

  1. Captures mid- to long-term trends using dual EMA.

  2. Reverse trading suits short-term pullback trades of trends.

  3. ATR stop adapts to market volatility.

  4. Reversal take profit sits near important technical levels with higher probability.

  5. Simple and clear logic, easy to understand and modify.

  6. Applicable for high volatile markets like cryptocurrencies.

Risks and Solutions

  1. Dual EMA may generate false signals. Can lengthen EMA periods.

  2. Reverse trades prone to stop loss. Can loosen stop loss a bit.

  3. Fake breakouts happen frequently. Add other filters.

  4. High risk on take profit. Manually remove take profit orders in time.

Optimization Suggestions

  1. Add indicators like MACD, KD to filter signals in overbought/oversold zones.

  2. Add more EMA like 120 period EMA to judge trend comprehensively.

  3. Set different slippage for longs and shorts to better entry price.

  4. Loosen ATR stop loss for highly volatile crypto trading.

  5. Optimize ATR multiplier and trailing stop mechanisms for maximum profit and minimum drawdown.

Conclusion

In conclusion, this is a relatively simple dual EMA trend following strategy. Its strength lies in clean logic, flexible parameters, applicability in mid- to long-term trends and short-term reversals. We also analyzed its potential weaknesses and solutions, along with several recommendations for future improvements. Overall speaking, this strategy is practical to some extent and has room to evolve, but its parameters need adjustments for different markets.


/*backtest
start: 2022-11-21 00:00:00
end: 2023-11-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheHulkTrading

// Simple EMA strategy, based on ema55+ema21 and ATR(Average True Range) and it enters a deal from ema55 when the other entry conditions are met


//@version=4
strategy("Simple Ema_ATR Strategy HulkTrading", overlay=true)

atr_multiplier = input(2, minval=1, title="ATR Multiplier") // ATR Multiplier. Recommended values between 1..4


emaFast=ema(close,21)
emaSlow=ema(close,55)

//Basically long and short conditions

//If long: 
// 1) close must be less than open (because we are searching for a pullback)
// 2) emaFast(21) must be bigger than emaSlow(55) - for a trend detection
// 3) Difference between emaFast and emaSlow must be greater than ATR(14) - for excluding flat
longCond = close < open and emaFast > emaSlow and abs(emaSlow-emaFast) > atr(14)  

//For short conditions are opposite
shortCond = close > open and emaFast < emaSlow and abs(emaSlow-emaFast) > atr(14) 

//Stop levels and take profits, based on ATR multiplier

stop_level_long = strategy.position_avg_price - atr_multiplier*atr(14)
take_level_long = strategy.position_avg_price + atr_multiplier*atr(14)
stop_level_short = strategy.position_avg_price + atr_multiplier*atr(14)
take_level_short = strategy.position_avg_price - atr_multiplier*atr(14)


//Entries and exits 
strategy.entry("Long", strategy.long, when=longCond, limit = emaSlow)
strategy.exit("Stop Loss/TP","Long", stop=stop_level_long, limit = take_level_long)
strategy.entry("Short", strategy.short, when=shortCond, limit = emaSlow)
strategy.exit("Stop Loss/TP","Short", stop=stop_level_short, limit = take_level_short)



More