Open Source Drduit RSI Ultimate - Revision Tradingview Indicator

Just copy this code to your tradingview

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DucTri_dev

//@version=5
indicator(title = "DRDUIT RSI ULTIMATE", shorttitle = "DrDuit RSI Ultimate")
// Define
BEAR_COLOR = color.red
BULL_COLOR = color.green
TEXT_COLOR = color.white
NA_COLOR = color.new(color.white, 100)

// --- User input
// --- RSI 1 ---
Inp_RSI_1_Length = input.int(defval = 14, title = "Length", minval = 1, group = "RSI 1", inline = "i1")
Inp_RSI_1_Timeframe = input.timeframe(defval = "", title = "Timeframe", group = "RSI 1", inline = "i1")

// --- RSI 2 3
Inp_RSI_2_Length = input.int(defval = 7, title = "Length", minval = 1, group = "RSI 2", inline = "i2")
Inp_RSI_2_Timeframe = input.timeframe(defval = "", title = "Timeframe", group = "RSI 2", inline = "i2")

Inp_RSI_3_Length = input.int(defval = 21, title = "Length", minval = 1, group = "RSI 3", inline = "i3")
Inp_RSI_3_Timeframe = input.timeframe(defval = "", title = "Timeframe", group = "RSI 3", inline = "i3")

// RSI 1 Divergence
Inp_RSI_1_ShowDivergence = input.bool(true, title = "Show Divergence", group = "RSI Divergence", tooltip = "Only applies to RSI 1")
Inp_RSI_1_LookLeft = input.int(5, title = "Peak's left bars", group = "RSI Divergence", tooltip = "Number of bars to the left of the Peak (Bottom)")
Inp_RSI_1_LookRight = input.int(5, title = "Peak's right bars", group = "RSI Divergence", tooltip = "Number of bars to the right of the Peak (Bottom)")
Inp_RSI_1_PricePeak = input.bool(false, title = "Price needs peak/bottom", group = "RSI Divergence", tooltip = "Price makes peak/bottom or just bigger/smaller")
Inp_RSI_1_PP_Source = input.string("high/low", title = "Price check for RSI divergence", group = "RSI Divergence", options = ["high/low","close"], tooltip = "Source to check higher high or lower low of price when RSI makes new high or low.")
Inp_RSI_1_MinRange = input.int(5, title = "Min Range", group = "RSI Divergence", inline = "div2", tooltip = "Shortest distance between 2 Peaks (bottoms).")
Inp_RSI_1_MaxRange = input.int(60, title = "Max Range", group = "RSI Divergence", inline = "div2", tooltip = "Largest distance between 2 Peaks (bottoms).")

// RSI 1 Alert
// Inp_RSI_1_OB_Level = input.int(70, title = "Overbought", group = "RSI Alert", inline = "rsiAlert")
// Inp_RSI_1_OS_Level = input.int(30, title = "Oversold", group = "RSI Alert", inline = "rsiAlert")

// RSI 1 MA
G_RSI_MA_1 = "RSI Based - MA 1"
Inp_MAType_1 = input.string("SMA", title="Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group=G_RSI_MA_1, display = display.data_window, inline = "i4")
Inp_MALength_1 = input.int(14, title="Length", group=G_RSI_MA_1, display = display.data_window, inline = "i4", tooltip = "Only applies to RSI 1")

G_RSI_MA_2 = "RSI Based - MA 2"
Inp_MAType_2 = input.string("EMA", title="Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group=G_RSI_MA_2, display = display.data_window, inline = "i5")
Inp_MALength_2 = input.int(9, title="Length", group=G_RSI_MA_2, display = display.data_window, inline = "i5", tooltip = "Only applies to RSI 1")

G_RSI_MA_3 = "RSI Based - MA 3"
Inp_MAType_3 = input.string("WMA", title="Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group= G_RSI_MA_3, display = display.data_window, inline = "i6")
Inp_MALength_3 = input.int(45, title="Length", group= G_RSI_MA_3, display = display.data_window, inline = "i6", tooltip = "Only applies to RSI 1")

G_RSI_BB_3 = "RSI Based - Bollinger Band"
Inp_BBLength = input.int(20, title="Length", group= G_RSI_BB_3, display = display.data_window, inline = "i7")
Inp_BBStd = input.float(2.0, minval=0.001, maxval=50, title="StdDev", group= G_RSI_BB_3, display = display.data_window, inline = "i7", tooltip = "Only applies to RSI 1")

// MA of Price
// G_Price_MA_1 = "Price Based - MA 1"
// Inp_ShowPriceMA_1 = input.bool(false, "Moving Average Price 1 ----- ")
// Inp_Price_MA_Type_1 = input.string("SMA", title="Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], display = display.data_window, inline = "priMa_1")
// Inp_Price_MA_Len_1 = input.int(34, title="Length", display = display.data_window, inline = "priMa_1", tooltip = "Moving Average Price")

// G_Price_MA_2 = "Price Based - MA 2"
// Inp_Price_MA_Type_2 = input.string("EMA", title="Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group= G_Price_MA_2, display = display.data_window, inline = "priMa_2")
// Inp_Price_MA_Len_2 = input.int(89, title="Length", group= G_Price_MA_2, display = display.data_window, inline = "priMa_2" ,tooltip = "Moving Average Price")

Inp_show_table = input.bool(true, "Show RSI Table", group = "RSI Table")
Inp_show_row_one = input.bool(false, "Show Row One Only", group = "RSI Table")
// Inp_tb_s1 = input.string("OANDA:EURUSD", title = "Symbol 1", group = "RSI Table", inline = "RSIT_tb_1")
Inp_tb_s2 = input.symbol("OANDA:USDJPY", title = "Symbol 2", group = "RSI Table", inline = "RSIT_tb_1")
Inp_tb_s3 = input.symbol("OANDA:GBPUSD", title = "Symbol 3", group = "RSI Table", inline = "RSIT_tb_2")
Inp_tb_s4 = input.symbol("OANDA:USDCHF", title = "Symbol 4", group = "RSI Table", inline = "RSIT_tb_2")
Inp_tb_s5 = input.symbol("OANDA:AUDUSD", title = "Symbol 5", group = "RSI Table", inline = "RSIT_tb_3")
Inp_tb_s6 = input.symbol("OANDA:USDCAD", title = "Symbol 6", group = "RSI Table", inline = "RSIT_tb_3")
Inp_tb_s7 = input.symbol("OANDA:NZDUSD", title = "Symbol 7", group = "RSI Table", inline = "RSIT_tb_4")
Inp_tb_s8 = input.symbol("OANDA:XAUUSD", title = "Symbol 8", group = "RSI Table", inline = "RSIT_tb_4")
Inp_tb_s9 = input.symbol("OANDA:XAGUSD", title = "Symbol 9", group = "RSI Table", inline = "RSIT_tb_5")
Inp_tb_s10 = input.symbol("OANDA:BTCUSD", title = "Symbol 10", group = "RSI Table", inline = "RSIT_tb_5")

type T_RSI_1
string symbol
float rsi

Symbols_RSI_1 = array.new<T_RSI_1>()

// --- Functions
f_split(s) => str.match(s, "(?<=:)[\w]+")

// Calculate RSI-based MA
f_rsi_ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

// Divergence
// lookRight = 5
// lookLeft = 5
// rangeUpper = 60
// rangeLower = 5

f_inRange(cond) =>
bars = ta.barssince(cond == true)
Inp_RSI_1_MinRange <= bars and bars <= Inp_RSI_1_MaxRange

// --- Indicator Calculation
rsi_1 = ta.rsi(close, Inp_RSI_1_Length)
rsi_2 = ta.rsi(close, Inp_RSI_2_Length)
rsi_3 = ta.rsi(close, Inp_RSI_3_Length)

RSI_TF_1_Chart = request.security(syminfo.tickerid, Inp_RSI_1_Timeframe , rsi_1)
RSI_TF_2_Chart = request.security(syminfo.tickerid, Inp_RSI_2_Timeframe , rsi_2)
RSI_TF_3_Chart = request.security(syminfo.tickerid, Inp_RSI_3_Timeframe , rsi_3)

// ma calculate: chi tinh tren rsi 1
rsi_ma_1 = f_rsi_ma(RSI_TF_1_Chart, Inp_MALength_1, Inp_MAType_1)
rsi_ma_2 = f_rsi_ma(RSI_TF_1_Chart, Inp_MALength_2, Inp_MAType_2)
rsi_ma_3 = f_rsi_ma(RSI_TF_1_Chart, Inp_MALength_3, Inp_MAType_3)

// bb calculate
base = f_rsi_ma(RSI_TF_1_Chart, Inp_BBLength, "SMA")
upper = base + ta.stdev(RSI_TF_1_Chart, Inp_BBLength) * Inp_BBStd
lower = base - ta.stdev(RSI_TF_1_Chart, Inp_BBLength) * Inp_BBStd

// ----- Calculate Divergence
// Regular Bullish
// rsi make peak
pivotLowFound = na(ta.pivotlow(RSI_TF_1_Chart, Inp_RSI_1_LookLeft, Inp_RSI_1_LookRight)) ? false : true
pivotHighFound = na(ta.pivothigh(RSI_TF_1_Chart, Inp_RSI_1_LookLeft, Inp_RSI_1_LookRight)) ? false : true

// rsi: Higher Low
rsiHL = RSI_TF_1_Chart[Inp_RSI_1_LookRight] > ta.valuewhen(pivotLowFound, RSI_TF_1_Chart[Inp_RSI_1_LookRight], 1) and f_inRange(pivotLowFound[1])

ppSourceLow = Inp_RSI_1_PP_Source == "close" ? close : low
// price make peak
pivotPriceLowFound = na(ta.pivotlow(ppSourceLow, Inp_RSI_1_LookLeft, Inp_RSI_1_LookRight)) ? false : true

// Price: Lower Low
priceLL = ppSourceLow[Inp_RSI_1_LookRight] < ta.valuewhen(pivotLowFound, ppSourceLow[Inp_RSI_1_LookRight], 1)
// Bullish Divergence = Rsi Higher Low + Price Lower Low and make Peak
pricePeakLow = Inp_RSI_1_PricePeak ? pivotPriceLowFound : true
bullDiv = priceLL and pricePeakLow and rsiHL and pivotLowFound

// Regular Bearish
// rsi: Lower High
rsiLH = RSI_TF_1_Chart[Inp_RSI_1_LookRight] < ta.valuewhen(pivotHighFound, RSI_TF_1_Chart[Inp_RSI_1_LookRight], 1) and f_inRange(pivotHighFound[1])
// Price: Higher High
ppSourceHigh = Inp_RSI_1_PP_Source == "close" ? close : high

priceHH = ppSourceHigh[Inp_RSI_1_LookRight] > ta.valuewhen(pivotHighFound, ppSourceHigh[Inp_RSI_1_LookRight], 1)
pivotPriceHighFound = na(ta.pivothigh(ppSourceHigh, Inp_RSI_1_LookLeft, Inp_RSI_1_LookRight)) ? false : true
pricePeakHigh = Inp_RSI_1_PricePeak ? pivotPriceHighFound : true

bearDiv = priceHH and pricePeakHigh and rsiLH and pivotHighFound

// ----- Calculate RSI Table
// row 1
// rsi_1_s1 = request.security(Inp_tb_s1, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s2 = request.security(Inp_tb_s2, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s3 = request.security(Inp_tb_s3, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s4 = request.security(Inp_tb_s4, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s5 = request.security(Inp_tb_s5, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s6 = request.security(Inp_tb_s6, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s7 = request.security(Inp_tb_s7, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s8 = request.security(Inp_tb_s8, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s9 = request.security(Inp_tb_s9, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)
rsi_1_s10 = request.security(Inp_tb_s10, Inp_RSI_1_Timeframe , rsi_1, ignore_invalid_symbol=true)

// Push rsi info cua row 1 vao array de alert sau nay
RSI_S1_obj = T_RSI_1.new(syminfo.tickerid, RSI_TF_1_Chart)
RSI_S2_obj = T_RSI_1.new(Inp_tb_s2, rsi_1_s2)
RSI_S3_obj = T_RSI_1.new(Inp_tb_s3, rsi_1_s3)
RSI_S4_obj = T_RSI_1.new(Inp_tb_s4, rsi_1_s4)
RSI_S5_obj = T_RSI_1.new(Inp_tb_s5, rsi_1_s5)
RSI_S6_obj = T_RSI_1.new(Inp_tb_s6, rsi_1_s6)
RSI_S7_obj = T_RSI_1.new(Inp_tb_s7, rsi_1_s7)
RSI_S8_obj = T_RSI_1.new(Inp_tb_s8, rsi_1_s8)
RSI_S9_obj = T_RSI_1.new(Inp_tb_s9, rsi_1_s9)
RSI_S10_obj = T_RSI_1.new(Inp_tb_s10, rsi_1_s10)
array.push(Symbols_RSI_1, RSI_S1_obj)
array.push(Symbols_RSI_1, RSI_S2_obj)
array.push(Symbols_RSI_1, RSI_S3_obj)
array.push(Symbols_RSI_1, RSI_S4_obj)
array.push(Symbols_RSI_1, RSI_S5_obj)
array.push(Symbols_RSI_1, RSI_S6_obj)
array.push(Symbols_RSI_1, RSI_S7_obj)
array.push(Symbols_RSI_1, RSI_S8_obj)
array.push(Symbols_RSI_1, RSI_S9_obj)
array.push(Symbols_RSI_1, RSI_S10_obj)

// row 2
// rsi_2_s1 = request.security(Inp_tb_s1, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s2 = request.security(Inp_tb_s2, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s3 = request.security(Inp_tb_s3, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s4 = request.security(Inp_tb_s4, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s5 = request.security(Inp_tb_s5, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s6 = request.security(Inp_tb_s6, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s7 = request.security(Inp_tb_s7, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s8 = request.security(Inp_tb_s8, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s9 = request.security(Inp_tb_s9, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)
rsi_2_s10 = request.security(Inp_tb_s10, Inp_RSI_2_Timeframe , rsi_2, ignore_invalid_symbol=true)

// row 3
// rsi_3_s1 = request.security(Inp_tb_s1, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s2 = request.security(Inp_tb_s2, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s3 = request.security(Inp_tb_s3, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s4 = request.security(Inp_tb_s4, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s5 = request.security(Inp_tb_s5, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s6 = request.security(Inp_tb_s6, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s7 = request.security(Inp_tb_s7, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s8 = request.security(Inp_tb_s8, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s9 = request.security(Inp_tb_s9, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)
rsi_3_s10 = request.security(Inp_tb_s10, Inp_RSI_3_Timeframe , rsi_3, ignore_invalid_symbol=true)

// -------- DRAW --------
var table rsiTable = table.new(position.bottom_right, 11, 4, bgcolor = color.new(color.gray, 70))
if barstate.islast and Inp_show_table
// We only populate the table on the last bar.
// row 0
table.cell(rsiTable, 0, 0, str.tostring(""), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 1, 0, f_split(syminfo.tickerid), bgcolor = color.new(color.gray, 70),text_color = color.new(color.yellow, 25))
table.cell(rsiTable, 2, 0, f_split(Inp_tb_s2), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 3, 0, f_split(Inp_tb_s3), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 4, 0, f_split(Inp_tb_s4), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 5, 0, f_split(Inp_tb_s5), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 6, 0, f_split(Inp_tb_s6), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 7, 0, f_split(Inp_tb_s7), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 8, 0, f_split(Inp_tb_s8), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 9, 0, f_split(Inp_tb_s9), bgcolor = color.new(color.gray, 70),text_color = color.white)
table.cell(rsiTable, 10, 0, f_split(Inp_tb_s10), bgcolor = color.new(color.gray, 70),text_color = color.white)

// row 1
table.cell(rsiTable, 0, 1, "RSI (" + str.tostring(Inp_RSI_1_Length) +")", bgcolor = color.new(color.gray, 70), text_color = color.white)
table.cell(rsiTable, 1, 1, f_split(syminfo.tickerid) == "" ? "" : str.tostring(RSI_TF_1_Chart, "#.##"), bgcolor = f_split(syminfo.tickerid) == "" ? color.new(color.purple, 70) : RSI_TF_1_Chart <30? color.new(color.red, 70) : RSI_TF_1_Chart >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color =color.new(color.yellow,25))
table.cell(rsiTable, 2, 1, f_split(Inp_tb_s2) == "" ? "" : str.tostring(rsi_1_s2, "#.##"), bgcolor = f_split(Inp_tb_s2) == "" ? color.new(color.purple, 70) : rsi_1_s2 <30? color.new(color.red, 70) : rsi_1_s2 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 3, 1, f_split(Inp_tb_s3) == "" ? "" : str.tostring(rsi_1_s3, "#.##"), bgcolor = f_split(Inp_tb_s3) == "" ? color.new(color.purple, 70) : rsi_1_s3 <30? color.new(color.red, 70) : rsi_1_s3 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 4, 1, f_split(Inp_tb_s4) == "" ? "" : str.tostring(rsi_1_s4, "#.##"), bgcolor = f_split(Inp_tb_s4) == "" ? color.new(color.purple, 70) : rsi_1_s4 <30? color.new(color.red, 70) : rsi_1_s4 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 5, 1, f_split(Inp_tb_s5) == "" ? "" : str.tostring(rsi_1_s5, "#.##"), bgcolor = f_split(Inp_tb_s5) == "" ? color.new(color.purple, 70) : rsi_1_s5 <30? color.new(color.red, 70) : rsi_1_s5 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 6, 1, f_split(Inp_tb_s6) == "" ? "" : str.tostring(rsi_1_s6, "#.##"), bgcolor = f_split(Inp_tb_s6) == "" ? color.new(color.purple, 70) : rsi_1_s6 <30? color.new(color.red, 70) : rsi_1_s6 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 7, 1, f_split(Inp_tb_s7) == "" ? "" : str.tostring(rsi_1_s7, "#.##"), bgcolor = f_split(Inp_tb_s7) == "" ? color.new(color.purple, 70) : rsi_1_s7 <30? color.new(color.red, 70) : rsi_1_s7 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 8, 1, f_split(Inp_tb_s8) == "" ? "" : str.tostring(rsi_1_s8, "#.##"), bgcolor = f_split(Inp_tb_s8) == "" ? color.new(color.purple, 70) : rsi_1_s8 <30? color.new(color.red, 70) : rsi_1_s8 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable, 9, 1, f_split(Inp_tb_s9) == "" ? "" : str.tostring(rsi_1_s9, "#.##"), bgcolor = f_split(Inp_tb_s9) == "" ? color.new(color.purple, 70) : rsi_1_s9 <30? color.new(color.red, 70) : rsi_1_s9 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
table.cell(rsiTable,10, 1, f_split(Inp_tb_s10) == "" ? "": str.tostring(rsi_1_s10, "#.##"), bgcolor = f_split(Inp_tb_s10) == "" ? color.new(color.purple, 70) : rsi_1_s10 <30? color.new(color.red, 70) : rsi_1_s10 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)

if Inp_show_row_one == false
    // row 2
    table.cell(rsiTable, 0, 2, "RSI (" + str.tostring(Inp_RSI_2_Length) +")", bgcolor = color.new(color.gray, 70), text_color = color.white)
    table.cell(rsiTable, 1, 2, f_split(syminfo.tickerid) == "" ? "" : str.tostring(RSI_TF_2_Chart, "#.##"), bgcolor = f_split(syminfo.tickerid) == "" ? color.new(color.purple, 70) : RSI_TF_2_Chart <30? color.new(color.red, 70) : RSI_TF_2_Chart >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.new(color.yellow,25))
    table.cell(rsiTable, 2, 2, f_split(Inp_tb_s2) == "" ? "" : str.tostring(rsi_2_s2, "#.##"), bgcolor = f_split(Inp_tb_s2) == "" ? color.new(color.purple, 70) : rsi_2_s2 <30? color.new(color.red, 70) : rsi_2_s2 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 3, 2, f_split(Inp_tb_s3) == "" ? "" : str.tostring(rsi_2_s3, "#.##"), bgcolor = f_split(Inp_tb_s3) == "" ? color.new(color.purple, 70) : rsi_2_s3 <30? color.new(color.red, 70) : rsi_2_s3 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 4, 2, f_split(Inp_tb_s4) == "" ? "" : str.tostring(rsi_2_s4, "#.##"), bgcolor = f_split(Inp_tb_s4) == "" ? color.new(color.purple, 70) : rsi_2_s4 <30? color.new(color.red, 70) : rsi_2_s4 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 5, 2, f_split(Inp_tb_s5) == "" ? "" : str.tostring(rsi_2_s5, "#.##"), bgcolor = f_split(Inp_tb_s5) == "" ? color.new(color.purple, 70) : rsi_2_s5 <30? color.new(color.red, 70) : rsi_2_s5 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 6, 2, f_split(Inp_tb_s6) == "" ? "" : str.tostring(rsi_2_s6, "#.##"), bgcolor = f_split(Inp_tb_s6) == "" ? color.new(color.purple, 70) : rsi_2_s6 <30? color.new(color.red, 70) : rsi_2_s6 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 7, 2, f_split(Inp_tb_s7) == "" ? "" : str.tostring(rsi_2_s7, "#.##"), bgcolor = f_split(Inp_tb_s7) == "" ? color.new(color.purple, 70) : rsi_2_s7 <30? color.new(color.red, 70) : rsi_2_s7 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 8, 2, f_split(Inp_tb_s8) == "" ? "" : str.tostring(rsi_2_s8, "#.##"), bgcolor = f_split(Inp_tb_s8) == "" ? color.new(color.purple, 70) : rsi_2_s8 <30? color.new(color.red, 70) : rsi_2_s8 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 9, 2, f_split(Inp_tb_s9) == "" ? "" : str.tostring(rsi_2_s9, "#.##"), bgcolor = f_split(Inp_tb_s9) == "" ? color.new(color.purple, 70) : rsi_2_s9 <30? color.new(color.red, 70) : rsi_2_s9 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 10, 2, f_split(Inp_tb_s10) == "" ? "" : str.tostring(rsi_2_s10, "#.##"), bgcolor = f_split(Inp_tb_s10) == "" ? color.new(color.purple, 70) : rsi_2_s10 <30? color.new(color.red, 70) : rsi_2_s10 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    // row 3
    table.cell(rsiTable, 0, 3, "RSI (" + str.tostring(Inp_RSI_3_Length) +")", bgcolor = color.new(color.gray, 70), text_color = color.white)
    table.cell(rsiTable, 1, 3, f_split(syminfo.tickerid) == "" ? "" : str.tostring(RSI_TF_3_Chart, "#.##"), bgcolor = f_split(syminfo.tickerid) == "" ? color.new(color.purple, 70) : RSI_TF_3_Chart <30? color.new(color.red, 70) : RSI_TF_3_Chart >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.new(color.yellow,25))
    table.cell(rsiTable, 2, 3, f_split(Inp_tb_s2) == "" ? "" : str.tostring(rsi_3_s2, "#.##"), bgcolor = f_split(Inp_tb_s2) == "" ? color.new(color.purple, 70) : rsi_3_s2 <30? color.new(color.red, 70) : rsi_3_s2 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 3, 3, f_split(Inp_tb_s3) == "" ? "" : str.tostring(rsi_3_s3, "#.##"), bgcolor = f_split(Inp_tb_s3) == "" ? color.new(color.purple, 70) : rsi_3_s3 <30? color.new(color.red, 70) : rsi_3_s3 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 4, 3, f_split(Inp_tb_s4) == "" ? "" : str.tostring(rsi_3_s4, "#.##"), bgcolor = f_split(Inp_tb_s4) == "" ? color.new(color.purple, 70) : rsi_3_s4 <30? color.new(color.red, 70) : rsi_3_s4 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 5, 3, f_split(Inp_tb_s5) == "" ? "" : str.tostring(rsi_3_s5, "#.##"), bgcolor = f_split(Inp_tb_s5) == "" ? color.new(color.purple, 70) : rsi_3_s5 <30? color.new(color.red, 70) : rsi_3_s5 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 6, 3, f_split(Inp_tb_s6) == "" ? "" : str.tostring(rsi_3_s6, "#.##"), bgcolor = f_split(Inp_tb_s6) == "" ? color.new(color.purple, 70) : rsi_3_s6 <30? color.new(color.red, 70) : rsi_3_s6 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 7, 3, f_split(Inp_tb_s7) == "" ? "" : str.tostring(rsi_3_s7, "#.##"), bgcolor = f_split(Inp_tb_s7) == "" ? color.new(color.purple, 70) : rsi_3_s7 <30? color.new(color.red, 70) : rsi_3_s7 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 8, 3, f_split(Inp_tb_s8) == "" ? "" : str.tostring(rsi_3_s8, "#.##"), bgcolor = f_split(Inp_tb_s8) == "" ? color.new(color.purple, 70) : rsi_3_s8 <30? color.new(color.red, 70) : rsi_3_s8 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 9, 3, f_split(Inp_tb_s9) == "" ? "" : str.tostring(rsi_3_s9, "#.##"), bgcolor = f_split(Inp_tb_s9) == "" ? color.new(color.purple, 70) : rsi_3_s9 <30? color.new(color.red, 70) : rsi_3_s9 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)
    table.cell(rsiTable, 10, 3, f_split(Inp_tb_s10) == "" ? "" : str.tostring(rsi_3_s10, "#.##"), bgcolor = f_split(Inp_tb_s10) == "" ? color.new(color.purple, 70) : rsi_3_s10 <30? color.new(color.red, 70) : rsi_3_s10 >70 ? color.new(color.green, 70)  : color.new(color.purple, 70), text_color = color.white)

rsiColor = RSI_TF_1_Chart >= 50 ? color.green : color.red

rsiPlot = plot(RSI_TF_1_Chart, color=rsiColor, title = "RSI 1")
plot(RSI_TF_2_Chart, color = color.blue, title = "RSI 2", display = display.none)
plot(RSI_TF_3_Chart, color = color.yellow, title = "RSI 3", display = display.none)

plot(rsi_ma_1, "RSI-based MA 1", color=color.yellow)
plot(rsi_ma_2, "RSI-based MA 2", color=color.blue, display = display.none)
plot(rsi_ma_3, "RSI-based MA 3", color=color.red, display = display.none)

plot(base, title = "Basis Bollinger Band", color=#2962FF, display = display.none)
plot(upper, title = "Upper Bollinger Band", color=color.green, display = display.none)
plot(lower, title = "Lower Bollinger Band", color=color.green, display = display.none)

// priceMa1 = f_rsi_ma(close, Inp_Price_MA_Len_1, Inp_Price_MA_Type_1)
// priceMa2 = f_rsi_ma(close, Inp_Price_MA_Len_2, Inp_Price_MA_Type_2)

//plot(Inp_ShowPriceMA_1 ? priceMa1 : na, "Moving Average Price 1", color = color.blue, force_overlay = true)
// plot(priceMa2, "Moving Average Price 2", color = color.yellow, force_overlay = true, display = display.none)

// Plot Divergence
plot(
pivotLowFound ? RSI_TF_1_Chart[Inp_RSI_1_LookRight] : na,
offset=-Inp_RSI_1_LookRight,
title="Bullish Divergence",
linewidth=2,
color=(Inp_RSI_1_ShowDivergence and bullDiv ? BULL_COLOR : na),
display = display.pane
)

plotshape(
Inp_RSI_1_ShowDivergence and bullDiv ? RSI_TF_1_Chart[Inp_RSI_1_LookRight] : na,
offset=-Inp_RSI_1_LookRight,
title="Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.absolute,
color=BULL_COLOR,
textcolor=TEXT_COLOR
)

plot(
pivotHighFound ? RSI_TF_1_Chart[Inp_RSI_1_LookRight] : na,
offset=-Inp_RSI_1_LookRight,
title="Bearish Divergence",
linewidth=2,
color=(Inp_RSI_1_ShowDivergence and bearDiv ? BEAR_COLOR : NA_COLOR),
display = display.pane
)

plotshape(
Inp_RSI_1_ShowDivergence and bearDiv ? RSI_TF_1_Chart[Inp_RSI_1_LookRight] : na,
offset=-Inp_RSI_1_LookRight,
title="Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.absolute,
color= BEAR_COLOR,
textcolor=TEXT_COLOR
)
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 85), title="RSI Background Fill")

// Gradient Fill
midLinePlot = plot(50, color = na, editable = false, display = display.none)
fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100), title = "Overbought Gradient Fill")
fill(rsiPlot, midLinePlot, 30, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill")

// ----- ALERT ------
// RSI Table Overbought
alertRSITableOB = false
alertRSITableOS = false

for eachSym in Symbols_RSI_1
if f_split(eachSym.symbol) != "" and eachSym.rsi > 70
alertRSITableOB :=true

if f_split(eachSym.symbol) != "" and eachSym.rsi < 30
    alertRSITableOS :=true                

AC_RSI_Chart_OB = RSI_TF_1_Chart > 70 or RSI_TF_2_Chart > 70 or RSI_TF_3_Chart > 70
AC_RSI_Chart_OS = RSI_TF_1_Chart < 30 or RSI_TF_2_Chart < 30 or RSI_TF_3_Chart < 30

alertcondition(alertRSITableOB and Inp_show_table, title='Row One: Overbought Detected', message = "Super RSI: Detected that a symbol in row one was Overbought")
alertcondition(alertRSITableOS and Inp_show_table, title='Row One: Oversold Detected', message="Super RSI: Detected that a symbol in row one was Oversold")
alertcondition(AC_RSI_Chart_OB , title = "Main Symbol: Overbought Detected", message = "{{ticker}} Super RSI: One of the three RSIs is Overbought")
alertcondition(AC_RSI_Chart_OS , title = "Main Symbol: Oversold Detected", message = "{{ticker}} Super RSI: One of the three RSIs is Oversold")

alertcondition(bullDiv, title='Main Symbol: Bullish Divergence', message="{{ticker}} Super RSI: Found a new Bullish Divergence")
alertcondition(bearDiv, title='Main Symbol: Bearish Divergence', message="{{ticker}} Super RSI: Found a new Bearish Divergence")
// TEST
// label.new(bar_index, 100, text=mess, size = size.small)
// string simpleS = str.replace(messRSIOB,":",": ")

// if barstate.islast
// // messRSIOS += f_split(eachSym.symbol) + ": " + str.tostring(eachSym.rsi, "#.##") +"\n"
// label.new(bar_index, 50, text=simpleS, size = size.small)
//to-to :
// 27-6: Hien Tai alertRSITableOB chi dang xet cho RSI 1 (RSI 14) - co khi can update lai phan nay

Get the latest drops straight to your inbox