
This strategy is a trend reversal trading system based on the Bollinger Bands indicator, which captures market reversal opportunities by monitoring the relationship between price and Bollinger Bands. The strategy operates on a 5-minute timeframe, using a 20-period moving average as the middle band and 3.4 standard deviations for the upper and lower bands. Trading signals are generated when prices touch the upper or lower bands.
The core logic is built on mean reversion theory. When price touches the lower band, the system considers the market oversold and tends to go long; when price touches the upper band, the system considers the market overbought and tends to go short. Specifically: 1. Long condition: When the 5-minute candlestick’s low first touches or breaks the lower band (current low <= lower band AND previous low > lower band) 2. Short condition: When the 5-minute candlestick’s high first touches or breaks the upper band (current high >= upper band AND previous high < upper band) 3. Exit condition: Close positions when price reverts to the middle band
This strategy captures market reversal opportunities through Bollinger Bands touches, featuring clear logic and reasonable risk control. Through appropriate parameter settings and comprehensive trading rules, the strategy shows good stability in range-bound markets. However, when applying to live trading, attention must be paid to trend breakthrough risks. It is recommended to combine other technical indicators for trade confirmation and dynamically adjust strategy parameters based on market conditions. Optimization focuses mainly on multi-period coordination, trend filtering, and dynamic parameter adjustment.
/*backtest
start: 2024-11-11 00:00:00
end: 2024-12-11 00:00:00
period: 5h
basePeriod: 5h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("5-Min Bollinger Bands Touch Strategy", overlay=true, margin_long=100, margin_short=100)
// Input parameters
length = input(20, title="Bollinger Bands Length")
mult = input(3.4, title="Bollinger Bands Deviation")
// Bollinger Bands calculation
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
// Plot Bollinger Bands
plot(basis, color=color.blue, title="Basis")
p1 = plot(upper, color=color.red, title="Upper Band")
p2 = plot(lower, color=color.green, title="Lower Band")
fill(p1, p2, color=color.new(color.gray, 90))
// Bullish buying condition: 5-min low touches lower Bollinger Band
bullish_entry = low <= lower and low[1] > lower[1]
// Bearish selling condition: 5-min high touches upper Bollinger Band
bearish_entry = high >= upper and high[1] < upper[1]
// Entry and exit conditions
longCondition = bullish_entry
shortCondition = bearish_entry
// Strategy entries
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Optional: Add exit conditions (you may want to customize these)
// Example: Exit long position after a certain profit or loss
strategy.close("Long", when = high >= basis)
strategy.close("Short", when = low <= basis)
// Alerts
alertcondition(bullish_entry, title='Bullish BB Touch', message='5-min low touched Lower Bollinger Band')
alertcondition(bearish_entry, title='Bearish BB Touch', message='5-min high touched Upper Bollinger Band')
// Plot entry points
plotshape(bullish_entry, title="Bullish Entry", location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green)
plotshape(bearish_entry, title="Bearish Entry", location=location.abovebar, style=shape.triangledown, size=size.small, color=color.red)