EMA Reverse Buy Sell Strategy
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…

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
Use 21 and 55 period EMA lines. 21 EMA represents short-term trend and 55 EMA represents long-term trend.
When 21 EMA crosses above 55 EMA, it indicates the short-term trend changes to upward, generating a buy signal.
When 21 EMA crosses below 55 EMA, it indicates the short-term trend turns downward, generating a sell signal.
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.
ATR stop loss: use N times ATR to set stop loss price. This dynamically adjusts stop loss based on market volatility.
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
Captures mid- to long-term trends using dual EMA.
Reverse trading suits short-term pullback trades of trends.
ATR stop adapts to market volatility.
Reversal take profit sits near important technical levels with higher probability.
Simple and clear logic, easy to understand and modify.
Applicable for high volatile markets like cryptocurrencies.
Risks and Solutions
Dual EMA may generate false signals. Can lengthen EMA periods.
Reverse trades prone to stop loss. Can loosen stop loss a bit.
Fake breakouts happen frequently. Add other filters.
High risk on take profit. Manually remove take profit orders in time.
Optimization Suggestions
Add indicators like MACD, KD to filter signals in overbought/oversold zones.
Add more EMA like 120 period EMA to judge trend comprehensively.
Set different slippage for longs and shorts to better entry price.
Loosen ATR stop loss for highly volatile crypto trading.
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.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2 | ATR Multiplier |
Source Pine Script
/*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)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-28. 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-Reverse-Buy-Sell-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
- Dual Breakout Volatility Channel StrategyPine Script · Breakout · 1h
- Kana Candle Breakout Strategy Based on Moving Average and Support ResistancePine Script · Breakout · 1h
- MA Trendline Breakthrough StrategyPine Script · Breakout · 1d
- Momentum Breakout Moving Average StrategyPine Script · Breakout · 1d
- Momentum Breakout Trading Strategy 440964Pine Script · Breakout · 5m
- Moving Average Crossover and Upper Rail Breakthrough Impulse StrategyPine Script · Breakout · 1m