//@version=6 indicator("JL All-in-One RSI Stoch RSI BB MAs v2", overlay = false, max_labels_count = 500, max_lines_count = 500) // Inputs src = input.source(close, "Source") maType = input.string("SMA", "Moving Average Type", options = ["SMA", "EMA"]) showMAs = input.bool(true, "Show Moving Averages") showBB = input.bool(true, "Show Bollinger Bands") showRSI = input.bool(true, "Show RSI") showStochRSI = input.bool(true, "Show Stochastic RSI") rsiLen = input.int(14, "RSI Length", minval = 1) rsiMaLen = input.int(14, "RSI MA Length", minval = 1) showRsiDivergences = input.bool(true, "Show RSI Divergences") rsiDivPivotLeft = input.int(5, "RSI Divergence Pivot Left", minval = 1) rsiDivPivotRight = input.int(5, "RSI Divergence Pivot Right", minval = 1) stochRsiLen = input.int(14, "Stoch RSI Length", minval = 1) stochLen = input.int(14, "Stoch Length", minval = 1) stochSmoothK = input.int(3, "Stoch RSI K Smoothing", minval = 1) stochSmoothD = input.int(3, "Stoch RSI D Smoothing", minval = 1) bbLen = input.int(20, "Bollinger Bands Length", minval = 1) bbMult = input.float(2.0, "Bollinger Bands Multiplier", minval = 0.1, step = 0.1) // Helpers ma(source, length) => maType == "EMA" ? ta.ema(source, length) : ta.sma(source, length) // A single Pine script can only create one TradingView pane, so the lower // indicators are separated into fixed vertical bands inside this pane. rsiHeight = 180.0 rsiBase = 0.0 stochBase = 200.0 // Moving averages on price chart ma9 = ma(src, 9) ma20 = ma(src, 20) ma50 = ma(src, 50) ma100 = ma(src, 100) ma200 = ma(src, 200) plot(showMAs ? ma9 : na, "9 MA", color = color.yellow, linewidth = 2, force_overlay = true) plot(showMAs ? ma20 : na, "20 MA", color = color.blue, linewidth = 2, force_overlay = true) plot(showMAs ? ma50 : na, "50 MA", color = color.aqua, linewidth = 3, force_overlay = true) plot(showMAs ? ma100 : na, "100 MA", color = color.rgb(235, 31, 31), linewidth = 2, force_overlay = true) plot(showMAs ? ma200 : na, "200 MA", color = color.purple, linewidth = 2, force_overlay = true) // Bollinger Bands on price chart bbBasis = ta.sma(src, bbLen) bbDev = bbMult * ta.stdev(src, bbLen) bbUpper = bbBasis + bbDev bbLower = bbBasis - bbDev bbUpperPlot = plot(showBB ? bbUpper : na, "BB Upper", color = color.new(color.gray, 0), force_overlay = true) bbBasisPlot = plot(showBB ? bbBasis : na, "BB Basis", color = color.new(color.gray, 35), force_overlay = true) bbLowerPlot = plot(showBB ? bbLower : na, "BB Lower", color = color.new(color.gray, 0), force_overlay = true) fill(bbUpperPlot, bbLowerPlot, color = showBB ? color.new(color.gray, 97) : na, title = "BB Fill") // RSI rsi = ta.rsi(src, rsiLen) rsiMa = ta.sma(rsi, rsiMaLen) rsiBand = rsiBase + rsi * rsiHeight / 100.0 rsiMaBand = rsiBase + rsiMa * rsiHeight / 100.0 rsiPlot = plot(showRSI ? rsiBand : na, "RSI", color = color.rgb(255, 255, 255), linewidth = 2) plot(showRSI ? rsiMaBand : na, "RSI MA", color = color.yellow, linewidth = 2) rsiOverboughtPlot = plot(showRSI ? rsiBase + 70.0 * rsiHeight / 100.0 : na, "RSI Overbought Fill Edge", color = color.new(color.white, 100)) rsiOversoldPlot = plot(showRSI ? rsiBase + 30.0 * rsiHeight / 100.0 : na, "RSI Oversold Fill Edge", color = color.new(color.white, 100)) fill(rsiPlot, rsiOverboughtPlot, 180, 126, showRSI and rsi >= 70 ? color.new(color.red, 70) : na, color.new(color.red, 100), title = "RSI Overbought Line Fill") fill(rsiPlot, rsiOversoldPlot, 54, 0, color.new(color.green, 100), showRSI and rsi <= 30 ? color.new(color.green, 70) : na, title = "RSI Oversold Line Fill") // Regular RSI divergences drawn in the RSI section. rsiPivotLow = ta.pivotlow(rsi, rsiDivPivotLeft, rsiDivPivotRight) rsiPivotHigh = ta.pivothigh(rsi, rsiDivPivotLeft, rsiDivPivotRight) var float prevBullPriceLow = na var float prevBullRsiLow = na var int prevBullBar = na if showRSI and showRsiDivergences and not na(rsiPivotLow) currentBullBar = bar_index - rsiDivPivotRight currentBullPriceLow = low[rsiDivPivotRight] currentBullRsiLow = rsiPivotLow bullDiv = not na(prevBullPriceLow) and currentBullPriceLow < prevBullPriceLow and currentBullRsiLow > prevBullRsiLow if bullDiv prevBullY = rsiBase + prevBullRsiLow * rsiHeight / 100.0 currentBullY = rsiBase + currentBullRsiLow * rsiHeight / 100.0 line.new(prevBullBar, prevBullY, currentBullBar, currentBullY, color = color.lime, width = 2) label.new(currentBullBar, currentBullY, "Bull", color = color.new(color.lime, 15), textcolor = color.black, style = label.style_label_up, size = size.tiny) prevBullPriceLow := currentBullPriceLow prevBullRsiLow := currentBullRsiLow prevBullBar := currentBullBar var float prevBearPriceHigh = na var float prevBearRsiHigh = na var int prevBearBar = na if showRSI and showRsiDivergences and not na(rsiPivotHigh) currentBearBar = bar_index - rsiDivPivotRight currentBearPriceHigh = high[rsiDivPivotRight] currentBearRsiHigh = rsiPivotHigh bearDiv = not na(prevBearPriceHigh) and currentBearPriceHigh > prevBearPriceHigh and currentBearRsiHigh < prevBearRsiHigh if bearDiv prevBearY = rsiBase + prevBearRsiHigh * rsiHeight / 100.0 currentBearY = rsiBase + currentBearRsiHigh * rsiHeight / 100.0 line.new(prevBearBar, prevBearY, currentBearBar, currentBearY, color = color.red, width = 2) label.new(currentBearBar, currentBearY, "Bear", color = color.new(color.red, 15), textcolor = color.white, style = label.style_label_down, size = size.tiny) prevBearPriceHigh := currentBearPriceHigh prevBearRsiHigh := currentBearRsiHigh prevBearBar := currentBearBar // Stochastic RSI rsiForStoch = ta.rsi(src, stochRsiLen) stochRsiRaw = ta.stoch(rsiForStoch, rsiForStoch, rsiForStoch, stochLen) stochK = ta.sma(stochRsiRaw, stochSmoothK) stochD = ta.sma(stochK, stochSmoothD) stochKBand = stochBase + stochK stochDBand = stochBase + stochD stochKPlot = plot(showStochRSI ? stochKBand : na, "Stoch RSI K", color = color.blue, linewidth = 2) plot(showStochRSI ? stochDBand : na, "Stoch RSI D", color = color.yellow, linewidth = 1) stochOverboughtPlot = plot(showStochRSI ? stochBase + 80 : na, "Stoch RSI Overbought Fill Edge", color = color.new(color.white, 100)) stochOversoldPlot = plot(showStochRSI ? stochBase + 20 : na, "Stoch RSI Oversold Fill Edge", color = color.new(color.white, 100)) fill(stochKPlot, stochOverboughtPlot, 300, 280, showStochRSI and stochK >= 80 ? color.new(color.red, 70) : na, color.new(color.red, 100), title = "Stoch RSI Overbought Line Fill") fill(stochKPlot, stochOversoldPlot, 220, 200, color.new(color.green, 100), showStochRSI and stochK <= 20 ? color.new(color.green, 70) : na, title = "Stoch RSI Oversold Line Fill") // Reference levels for each visual band stochNeutralLow = hline(220, "Stoch RSI 20", color = color.new(color.white, 65), linestyle = hline.style_dashed) stochNeutralHigh = hline(280, "Stoch RSI 80", color = color.new(color.white, 65), linestyle = hline.style_dashed) fill(stochNeutralLow, stochNeutralHigh, color = color.new(color.purple, 90), title = "Stoch RSI 20-80 Band") hline(280, "Stoch RSI Overbought", color = color.new(color.white, 65), linestyle = hline.style_dashed) hline(250, "Stoch RSI Mid", color = color.new(color.white, 65), linestyle = hline.style_dashed) hline(220, "Stoch RSI Oversold", color = color.new(color.white, 65), linestyle = hline.style_dashed) hline(190, "Stoch RSI/RSI Divider", color = color.new(color.rgb(70, 71, 71), 20), linestyle = hline.style_solid, linewidth = 2) rsiNeutralHigh = hline(126, "RSI 70", color = color.new(color.white, 65), linestyle = hline.style_dashed) hline(90, "RSI Mid", color = color.new(color.white, 65), linestyle = hline.style_dashed) rsiNeutralLow = hline(54, "RSI 30", color = color.new(color.white, 65), linestyle = hline.style_dashed) fill(rsiNeutralLow, rsiNeutralHigh, color = color.new(color.purple, 90), title = "RSI 30-70 Full Band") // Dashboard var table dash = table.new(position.top_right, 2, 2, border_width = 1) if barstate.islast table.cell(dash, 0, 0, "RSI / MA", text_color = color.white, bgcolor = color.new(color.orange, 30)) table.cell(dash, 1, 0, str.tostring(rsi, "#.##") + " / " + str.tostring(rsiMa, "#.##")) table.cell(dash, 0, 1, "Stoch RSI", text_color = color.white, bgcolor = color.new(color.purple, 30)) table.cell(dash, 1, 1, "K " + str.tostring(stochK, "#.##") + " / D " + str.tostring(stochD, "#.##"))