0bps

Strategy vault / Mean reversion

Reversal Trading Strategy with EMA Crossover and Bollinger Bands

This strategy calculates two EMA lines with different periods to determine the long-term and short-term trend of the stock price. It also incorporates the upper and lower rails of the Bollinger Bands to judge whether…

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

IMG

Overview

This strategy calculates two EMA lines with different periods to determine the long-term and short-term trend of the stock price. It also incorporates the upper and lower rails of the Bollinger Bands to judge whether the stock price is in an overbought or oversold state, as signals for entry and exit. It combines multiple technical indicators such as moving averages and Bollinger Bands to locate market reversal points, which belongs to a typical trend-following and reversal trading strategy.

Strategy Logic

  1. Calculate the fast EMA (50-period) and slow EMA (200-period). The fast EMA crossing above the slow EMA is a buy signal, while the fast EMA crossing below is a sell signal.

  2. Calculate the 20-period Bollinger Bands upper and lower rails.

  3. When the price breaks through the BB upper rail, it is considered an overbought signal to go short. When the price breaks through the BB lower rail, it is considered an oversold signal to go long.

  4. Combine the EMA crossovers and BB breakout signals to determine entries and exits.

The above logic is the main way this strategy identifies trading signals. It goes long when the fast EMA crosses over the slow EMA or when the price breaks the BB lower rail. It goes short when the fast EMA crosses below the slow EMA or when the price breaks the BB upper rail.

Advantage Analysis

This is a typical strategy combining multiple technical indicators, which considers both long-term and short-term price trends, as well as overbought and oversold conditions. The main advantages are:

  1. EMA crossovers can effectively determine long-term and short-term trends.

  2. Bollinger Bands can identify overbought and oversold zones to avoid chasing tops and bottoms.

  3. Combining indicators improves robustness and avoids false signals.

  4. Backtest results can be further enhanced through parameter tuning.

Risk Analysis

There are some risks with this strategy:

  1. EMA may have lagging effect, missing best entry points.

  2. Improper BB parameter selection may miss trends.

  3. Too many combined signals increases complexity.

  4. Parameters may fail when market regimes change.

Solutions:

  1. Optimize parameters adaptive to markets.

  2. Add stop loss to control risks.

  3. Test different EMA and BB parameter combinations.

  4. Further enhancements such as combining with RSI.

Optimization Directions

There is strong potential to optimize this strategy:

  1. Test more EMA and BB parameter combinations.

  2. Incorporate other indicators like MACD, KDJ, RSI.

  3. Add trailing stop loss.

  4. Test the strategy across different time frames.

  5. Combine with unusual volume for more signals.

Through robust backtesting across different parameters and indicators, the strategy can be further improved for stability and profitability.

Conclusion

This strategy builds upon the two most important technical indicators EMA and Bollinger Bands to identify long-term/short-term trends and overbought/oversold levels, making it highly practical. Further parameter tuning and combining more indicators can lead to better results. It reflects the key idea in quantitative trading strategies to assess the market condition, design rules, and optimize the strategy. With continuous testing and enhancement, this strategy has the potential to become a reliable algorithmic trading system.

Parameters

NameDefaultWhat it controls
v_input_150Short EMA Period
v_input_2200Long EMA Period
v_input_320Bollinger Bands Length
v_input_42Bollinger Bands Multiplier

Source Pine Script

/*backtest
start: 2024-01-21 00:00:00
end: 2024-02-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Reversal Patterns, EMA Crossover, and Bollinger Bands", shorttitle="RP-EMABB", overlay=true)

// Input parameters
emaShortPeriod = input(50, title="Short EMA Period", minval=1)
emaLongPeriod = input(200, title="Long EMA Period", minval=1)
bbLength = input(20, title="Bollinger Bands Length", minval=1)
bbMultiplier = input(2.0, title="Bollinger Bands Multiplier", minval=0.1, maxval=5.0)

// Calculate EMAs
emaShort = ema(close, emaShortPeriod)
emaLong = ema(close, emaLongPeriod)

// Calculate Bollinger Bands
bbUpper = sma(close, bbLength) + bbMultiplier * stdev(close, bbLength)
bbLower = sma(close, bbLength) - bbMultiplier * stdev(close, bbLength)

// EMA Crossover and Crossunder
emaCrossover = crossover(emaShort, emaLong)
emaCrossunder = crossunder(emaShort, emaLong)

// Bollinger Bands Crossing
bbUpperCross = crossover(close, bbUpper)
bbLowerCross = crossunder(close, bbLower)

// Buy and Sell signals
strategy.entry("Buy", strategy.long, when=emaCrossover or bbLowerCross)
strategy.entry("Sell", strategy.short, when=emaCrossunder or bbUpperCross)

// Plot EMAs on the chart
plot(emaShort, color=color.blue, title="50 EMA")
plot(emaLong, color=color.red, title="200 EMA")

// Plot Bollinger Bands
plot(bbUpper, color=color.green, title="Bollinger Bands Upper")
plot(bbLower, color=color.red, title="Bollinger Bands Lower")

// Highlight Buy and Sell signals on the chart
bgcolor(emaCrossover or bbLowerCross ? color.green : na, transp=90)
bgcolor(emaCrossunder or bbUpperCross ? color.red : na, transp=90)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-21. 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/Reversal-Trading-Strategy-with-EMA-Crossover-and-Bollinger-Bands.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