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

res(MAResolution) =>
    if MAResolution == '00 Current'
        timeframe.period
    else
        if MAResolution == '01 1m'
            '1'
        else
            if MAResolution == '02 3m'
                '3'
            else
                if MAResolution == '03 5m'
                    '5'
                else
                    if MAResolution == '04 15m'
                        '15'
                    else
                        if MAResolution == '05 30m'
                            '30'
                        else
                            if MAResolution == '06 45m'
                                '45'
                            else
                                if MAResolution == '07 1h'
                                    '60'
                                else
                                    if MAResolution == '08 2h'
                                        '120'
                                    else
                                        if MAResolution == '09 3h'
                                            '180'
                                        else
                                            if MAResolution == '10 4h'
                                                '240'
                                            else
                                                if MAResolution == '11 1D'
                                                    '1D'
                                                else
                                                    if MAResolution == '12 1W'
                                                        '1W'
                                                    else
                                                        if MAResolution == '13 1M'
                                                            '1M'


//@version=5
indicator(title='Dragon Double RSI by @Dragon_Trader95', shorttitle='Doubel RSI')

ShowCrose =input(title='Show Crose', defval=true)


//RSI
ShowFastRSI =input(title='Show Regular RSI', defval=false, group="RSI Settings")
rsiSourceInput = input.source(close, 'Source', group='RSI Settings')
TimeFrame1 = input.string(title='Resolution For Fast RSI', defval='00 Current', options=['00 Current', '01 1m', '02 3m', '03 5m', '04 15m', '05 30m', '06 45m', '07 1h', '08 2h', '09 3h', '10 4h', '11 1D', '12 1W', '13 1M'], group="RSI Settings")
rsiLengthInput = input.int(14, minval=1, title='RSI Length', group='RSI Settings')
rsiOverbought = input.int(title='RSI Overbought Level', defval=70, group='RSI Settings')
rsiOversold = input.int(title='RSI Oversold Level', defval=30, group='RSI Settings')

rsi = request.security(syminfo.tickerid, res(TimeFrame1), ta.rsi(rsiSourceInput, rsiLengthInput))
rsiPlot = plot(ShowFastRSI ? rsi : na, 'Regular RSI', color=rsi<rsiOversold ? color.new(color.green, 0) : rsi>rsiOverbought ?color.new(color.red, 0) : color.new(#7E57C2, 50), linewidth=1)

rsiUpperBand = hline(rsiOverbought, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(rsiOversold, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background 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")

// rsiUpperBand = hline(70, 'RSI Upper Band', color=#787B86, display= display.none)
// hline(50, 'RSI Middle Band', color.new(color.lime, 70), linestyle=hline.style_solid, linewidth=1)
// hline(20, 'RSI Middle Band', color.new(color.lime, 90), linestyle=hline.style_solid, linewidth=1)
// hline(80, 'RSI Middle Band', color.new(color.red, 90), linestyle=hline.style_solid, linewidth=1)
// rsiLowerBand = hline(30, 'RSI Lower Band', color=#787B86, display= display.none)
// fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title='RSI Background Fill')


//Doubel RSI
ShowSlowsRSI =input(title='Show Slows RSI', defval=true, group="Doubel RSI Settings")
TimeFrame2 = input.string(title='Resolution For RSI Length 1', defval='00 Current', options=['00 Current', '01 1m', '02 3m', '03 5m', '04 15m', '05 30m', '06 45m', '07 1h', '08 2h', '09 3h', '10 4h', '11 1D', '12 1W', '13 1M'], group="Doubel RSI Settings")
TimeFrame3 = input.string(title='Resolution For RSI Length 2', defval='00 Current', options=['00 Current', '01 1m', '02 3m', '03 5m', '04 15m', '05 30m', '06 45m', '07 1h', '08 2h', '09 3h', '10 4h', '11 1D', '12 1W', '13 1M'], group="Doubel RSI Settings")
rsiLengthInput1 = input.int(100, minval=1, title='RSI Length 1', group='Doubel RSI Settings')
rsiLengthInput2 = input.int(25, minval=1, title='RSI Length 2', group='Doubel RSI Settings')
rsiSourceInputDoubel = input.source(close, 'Source', group='Doubel RSI Settings')

rsi1 = request.security(syminfo.tickerid, res(TimeFrame2), ta.rsi(rsiSourceInputDoubel, rsiLengthInput1))
rsi2 = request.security(syminfo.tickerid, res(TimeFrame3), ta.rsi(rsiSourceInputDoubel, rsiLengthInput2))

plot(ShowSlowsRSI ? rsi1 : na, 'Slowest RSI', color=rsi1<40 ? color.new(color.green, 0) : rsi1>60 ?color.new(color.red, 0) : color.new(color.orange, 0), linewidth=1)
rsi2Plot = plot(ShowSlowsRSI ? rsi2 : na, 'Slow RSI', color=#78909c, linewidth=1)
fill(rsi2Plot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100),  title = "Overbought Gradient Fill")
fill(rsi2Plot, midLinePlot, 30,  0,  top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0),      title = "Oversold Gradient Fill")

// rsiUpperBand1 = hline(60, 'RSI Upper Band', color=color.new(color.red, 70), display= display.none)
// rsiLowerBand1 = hline(40, 'RSI Lower Band', color=color.new(color.green, 70), display= display.none)
// rsiUpperBand1x = hline(58, 'RSI Upper Band', color=color.new(color.red, 70), display= display.none)
// rsiLowerBand1y = hline(42, 'RSI Lower Band', color=color.new(color.green, 70), display= display.none)
// fill(rsiUpperBand1, rsiUpperBand1x, color=color.new(color.red, 70), title='RSI Background Fill')
// fill(rsiLowerBand1, rsiLowerBand1y, color=color.new(color.green, 70), title='RSI Background Fill')

crossunderOB1 = barstate.isconfirmed and ta.crossover(rsi, rsiOverbought)
crossoverOS1 = barstate.isconfirmed and ta.crossunder(rsi, rsiOversold)

bool IsCrossoverForSlowsRSI = false
bool IsCrossunderForSlowsRSI = false

if ShowSlowsRSI and ShowCrose and barstate.isconfirmed and ta.crossover(rsi2,rsi1)
    lun1 = label.new(bar_index, na, color=color.green, textcolor=color.green, style=label.style_xcross, size=size.auto)
    label.set_y(lun1, rsi1)
    IsCrossoverForSlowsRSI := true
    
if ShowSlowsRSI and ShowCrose and barstate.isconfirmed and ta.crossunder(rsi2,rsi1)
    lun1 = label.new(bar_index, na, color=color.red, textcolor=color.red, style=label.style_xcross, size=size.auto)
    label.set_y(lun1, rsi1)
    IsCrossunderForSlowsRSI := true
    
alertcondition(IsCrossoverForSlowsRSI, title='Slow RSI Crossover Call-out', message='Crossover Call-out')
alertcondition(IsCrossunderForSlowsRSI, title='Slow RSI Crossunder Call-out', message='Crossunder Call-out')
alertcondition(IsCrossunderForSlowsRSI and IsCrossoverForSlowsRSI, title='Slow RSI Crossunder-Crossover Call-out', message='Slow RSI Crossunder-Crossover Call-out')

