0

I'm trying to combine two indicators - Bollinger Bands with RSI in version5.

When I merge these two, the RSI didn't show in the bottom of the chart. How can I fix this?

I want BB on the chart candles as default and RSI on the bottom of the chart like as default.

I'm not a programmer. Know very little about coding, trying to learn though! Used ChatGPT also didn't work.

Here is the before and after merging the scripts screenshot.

Here is the code.

//@version=5
indicator(shorttitle="BB", title="Bollinger Bands", overlay=true, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
maType = "SMA"
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

ma(source, length, _type) =>
    switch _type
        "SMA" => ta.sma(source, length)

basis = ma(close, length, maType)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
plot(basis, "Basis", color=#2962FF, offset = 0)
p1 = plot(upper, "Upper", color=#F23645, offset = 0)
p2 = plot(lower, "Lower", color=#089981, offset = 0)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

/// RSI SETTINGS

// Inputs
rsiLengthInput = input.int(13, minval=1, title="Length")
rsiSourceInput = close
maLengthInput = 14
bbMultInput = 2.0

// RSI Calculation
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maType)
isBB = maType == "Bollinger Bands"

// Plotting RSI
rsiPlot = plot(rsi, title='RSI', color=color.new(#7E57C2, 0))

// Adding horizontal lines and fill
rsiUpperBand = hline(70, "Upper Band", color=#787B86)
midline = hline(50, "Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Fill")

CC BY-SA 4.0

2 Answers 2

1

To show RSI, indicator must be overlay false

Then, to show Bollinger Bands, plot must be overlay_true

//@version=5
indicator(shorttitle="BB", title="Bollinger Bands", overlay=false, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
maType = "SMA"
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

ma(source, length, _type) =>
    switch _type
        "SMA" => ta.sma(source, length)

basis = ma(close, length, maType)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
plot(basis, "Basis", color=#2962FF, offset = 0, force_overlay  = true)
p1 = plot(upper, "Upper", color=#F23645, offset = 0, force_overlay  = true)
p2 = plot(lower, "Lower", color=#089981, offset = 0, force_overlay  = true)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

/// RSI SETTINGS

// Inputs
rsiLengthInput = input.int(13, minval=1, title="Length")
rsiSourceInput = close
maLengthInput = 14
bbMultInput = 2.0

// RSI Calculation
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maType)
isBB = maType == "Bollinger Bands"

// Plotting RSI
rsiPlot = plot(rsi, title='RSI', color=color.new(#7E57C2, 0))

// Adding horizontal lines and fill
rsiUpperBand = hline(70, "Upper Band", color=#787B86)
midline = hline(50, "Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Fill")

rsi+bb

CC BY-SA 4.0
2
0

People,

cTrader people know this. I am more MT4, so your welcome and I am not a programmer! You must run the Bollinger bands on Array (previous indicator data) using RSI as the array data, before that run RSI or CCI on array (previous indicator data) of MACD or OBV(my favorite) or TVI(trader volume index(indicator). Adding 0.25,-0.25,0.5,-0.5,0.75,-0.75,1.25,-1.25 warning lines onto the Bollinger bands help assist with the signals and look really cool too :)! Just like that 1-2-3 perfect Bandwidth trading signals are my thing and perfect as it gets.

Louis B.W.

CC BY-SA 4.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.