Bollinger Bands + RSI Strategy//@version=5
strategy("Bollinger Bands + RSI Strategy", overlay=true,
description="This is a trading strategy based on Bollinger Bands and RSI. The strategy generates buy and sell signals based on price action and market momentum. It buys when the price crosses above the lower Bollinger Band while the RSI is below 30 (indicating oversold conditions). It sells when the price crosses below the upper Bollinger Band while the RSI is above 70 (indicating overbought conditions). Positions are closed when the price crosses the middle Bollinger Band (the moving average).")
// Bollinger Bands parameters
length = input.int(20, title="Bollinger Bands Length")
src = input(close, title="Source")
mult = input.float(2.0, title="Bollinger Bands Multiplier")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper_band = basis + dev
lower_band = basis - dev
// RSI parameters
rsi_length = input.int(14, title="RSI Length")
rsi = ta.rsi(src, rsi_length)
// Plot Bollinger Bands
plot(upper_band, color=color.red, linewidth=2, title="Upper Bollinger Band")
plot(lower_band, color=color.green, linewidth=2, title="Lower Bollinger Band")
plot(basis, color=color.blue, linewidth=1, title="Middle Band")
// Buy Condition
buy_condition = ta.crossover(close, lower_band) and rsi < 30
if buy_condition
strategy.entry("Buy", strategy.long)
// Sell Condition
sell_condition = ta.crossunder(close, upper_band) and rsi > 70
if sell_condition
strategy.entry("Sell", strategy.short)
// Exit Conditions (optional: use the middle Bollinger Band for exits)
exit_condition = ta.cross(close, basis)
if exit_condition
strategy.close("Buy")
strategy.close("Sell")
// Optional: Plot RSI for additional insight
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)
plot(rsi, color=color.purple, title="RSI", linewidth=1, offset=-5)
Harris
Harris RSIThis is a variation of Wilder's RSI that was altered by Michael Harris.
CALCULATION
The average change of each of the length's source value is compared to the more recent source value.
The average difference of both positive or negative changes is found.
The range of 100 is divided by the divided result of the average incremented and decremented ratio plus one.
This result of the above is subracted from the range value of 100
I have added some signals and filtering options with moving averages:
Trend OB/OS: Uptrend after above Overbought Level. Downtrend after below Oversold Level (For the traditional RSI OB=60 and OS=40 is used)
OB/OS: When above Overbought, or below oversold
50-Cross: Above 50 line is uptrend, below is downtrend
Direction: Moving up or down
RSI vs MA: RSI above MA is an uptrend, RSI below MA is a downtrend
The signals I added are just some potential ideas, always backtest your own strategies.