Spice
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Author @Crypto_Chili_
// Thanks to Lij_MC MarketVision A indicator for inspiring me to add more features to this indicator. At first it was just the RSI Arrows and the BB reversals candles + Condition but then I found MarketVision A and loved the extra Leledc and 3 Line Strike features. 
// Thank you to all the creators mentioned in this source code. Names will be above their indicator
// Hope you enjoy this 

//@version=5
indicator('Spice', shorttitle='Spice',overlay=true)

//Toggles

ShowRecentSignalsIn    = input.int(200, "Signals Shown in x No. of Bars", minval = 0, maxval = 100000000, step = 5, inline = "Signals")
show_BB                = input.bool(defval=false, title='Show BB?')
show_bullish3strike    = input.bool(defval=true, title='Show Bullish 3 Strike Candles')
show_bearish3strike    = input.bool(defval=true, title='Show Bearish 3 Strike Candles')
ShowLeledcHigh         = input.bool(defval=true, title='Show Leledc Exhaustion High')
ShowLeledcLow          = input.bool(defval=true, title='Show Leledc Exhaustion Low')

show_topR              = input.bool(defval=false, title='Show Top Reversals?‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎', inline='1', group='Top/Bot Reversal')
show_botR              = input.bool(defval=false, title='Show Bottom Reversals?', inline='1', group='Top/Bot Reversal')
show_topbox            = input.bool(defval=true, title='Show Confirmed First Bar‎ ‎ ‎ ‎ ‎ ‎ ‎', inline='2', group='Top/Bot Reversal')
show_botbox            = input.bool(defval=true, title='Show Confirmed First Bar', inline='2', group='Top/Bot Reversal')
show_topbox2            = input.bool(defval=true, title='Show Confirmed Second Bar‎ ‎ ‎', inline='3', group='Top/Bot Reversal')
show_botbox2            = input.bool(defval=true, title='Show Confirmed Second Bar', inline='3', group='Top/Bot Reversal')

show_rsi               = input.bool(defval=true, title='Show RSI Arrows?', group='RSI Timeframes')
remove_ema             = input.bool(defval=true, title='Remove EMAs?', group='EMAs')
show_ema1              = input.bool(defval=true, title='Show EMA 1', group='EMAs', inline='3')
show_ema2              = input.bool(defval=true, title='Show EMA 2', group='EMAs', inline='4')
show_ema3              = input.bool(defval=true, title='Show EMA 3', group='EMAs', inline='5')
show_ema4              = input.bool(defval=true, title='Show EMA 4', group='EMAs', inline='6')

// EMAs
ema1Length = input(20, title = "- Length", group='EMAs', inline='3')
ema2Length = input(50, title = "- Length", group='EMAs', inline='4')
ema3Length = input(100, title = "- Length", group='EMAs', inline='5')
ema4Length = input(200, title = "- Length", group='EMAs', inline='6')

ema1 = ta.ema(close, ema1Length)
ema2 = ta.ema(close, ema2Length)
ema3 = ta.ema(close, ema3Length)
ema4 = ta.ema(close, ema4Length)

plot(not remove_ema and show_ema1 ? ema1:na, color=color.rgb(255, 0, 0, 30), linewidth=1, title="EMA 1")
plot(not remove_ema and show_ema2 ? ema2:na, color=color.rgb(255, 183, 77, 30), linewidth=1, title="EMA 2")
plot(not remove_ema and show_ema3 ? ema3:na, color=color.rgb(91, 156, 246, 30), linewidth=2, title="EMA 3")
plot(not remove_ema and show_ema4 ? ema4:na, color=color.rgb(255, 255, 255, 30), linewidth=3, title="EMA 4")

// Multi Timeframe RSI (LTF) by @millerrh, with my own touches to make it an overlay
rsi_mid = 50
rsiHigh = 70
rsiLow = 30

rsi_len = (6)
rsi_src = (close)
show1m = input(true, title='1m', group='RSI Timeframes')
show5m = input(true, title='5m', group='RSI Timeframes')
show15m = input(true, title='15m', group='RSI Timeframes')
show30m = input(true, title='30m', group='RSI Timeframes')
show1h = input(true, title='1h', group='RSI Timeframes')
show4h = input(true, title='4h', group='RSI Timeframes')
show1D = input(true, title='1D', group='RSI Timeframes')

rsiCurrent = ta.rsi(rsi_src, rsi_len)
rsi1m = request.security(syminfo.tickerid, '1', ta.rsi(rsi_src, rsi_len))
rsi5m = request.security(syminfo.tickerid, '5', ta.rsi(rsi_src, rsi_len))
rsi15m = request.security(syminfo.tickerid, '15', ta.rsi(rsi_src, rsi_len))
rsi30m = request.security(syminfo.tickerid, '30', ta.rsi(rsi_src, rsi_len))
rsi1h = request.security(syminfo.tickerid, '60', ta.rsi(rsi_src, rsi_len))
rsi4h = request.security(syminfo.tickerid, '240', ta.rsi(rsi_src, rsi_len))
rsi1D = request.security(syminfo.tickerid, 'D', ta.rsi(rsi_src, rsi_len))

redZone = (rsiCurrent > rsiHigh and (show5m and timeframe.multiplier < 5 ? rsi5m > rsiHigh : true) and (show15m and timeframe.multiplier < 15 ? rsi15m > rsiHigh : true) and (show30m and timeframe.multiplier < 30 ? rsi30m > rsiHigh : true) and (show1h and timeframe.multiplier < 60 ? rsi1h > rsiHigh : true) and (show4h and timeframe.multiplier < 240 ? rsi4h > rsiHigh : true) and (show1D and not timeframe.isdaily ? rsi1D > rsiHigh : true))
greenZone = (rsiCurrent < rsiLow and (show5m and timeframe.multiplier < 5 ? rsi5m < rsiLow : true) and (show15m and timeframe.multiplier < 15 ? rsi15m < rsiLow : true) and (show30m and timeframe.multiplier < 30 ? rsi30m < rsiHigh : true) and (show1h and timeframe.multiplier < 60 ? rsi1h < rsiLow : true) and (show4h and timeframe.multiplier < 240 ? rsi4h < rsiLow : true) and (show1D and not timeframe.isdaily ? rsi1D < rsiLow : true))

sinceRed = ta.barssince(redZone)
sinceGreen = ta.barssince(greenZone)

rsi_UpArrow = not greenZone and (sinceGreen < 2)
rsi_DownArrow = not redZone and (sinceRed < 2)

plotshape(show_rsi ? rsi_UpArrow:na, title='Up Arrow', style=shape.triangleup, location=location.belowbar, size=size.small, color=color.rgb(0, 187, 212, 50), show_last = ShowRecentSignalsIn)
plotshape(show_rsi ? rsi_DownArrow:na, title='Down Arrow', style=shape.triangledown, location=location.abovebar, size=size.small, color=color.rgb(103, 58, 183,50), show_last = ShowRecentSignalsIn)

//---------------------------------------------------------------------------------------------------------------------------------------------------------------//
// BB Reversals + specific candle condition met next bar by @Crypto_Chili_ - The way this should be used is by waiting for a 1 or 2 bar confirmation closed above/below the high/low of the Reversal candle.
// So if its a Top R, a yellow box will print as a confirmed 1 bar if it closed below the top R's low, then you can wait for the second bar to close also below the Top R's low. Vice versa with the Bot R.
bb_length = (20)
bb_src = (close)
mult = (2.0)
basis = ta.sma(bb_src, bb_length)
dev = mult * ta.stdev(bb_src, bb_length)
upper = basis + dev
lower = basis - dev
plot(show_BB ? basis:na, "Basis", color=#FF6D00)
p1 = plot(show_BB ? upper:na, "Upper", color=#2962FF)
p2 = plot(show_BB ? lower:na, "Lower", color=#2962FF)
fill(p1,p2, title = "Background", color=color.rgb(33, 150, 243, 95))

topR = ta.crossunder(close, upper)
botR = ta.crossover(close, lower)

plotchar(show_topR ? topR:na, title='Top Reversal', char='R', location=location.abovebar, color=#e6e600, size=size.tiny, show_last = ShowRecentSignalsIn)
plotchar(show_botR ? botR:na, title='Bot Reversal', char='R', location=location.belowbar, color=#f57c00, size=size.tiny, show_last = ShowRecentSignalsIn)

barcolor(show_topR and topR ? #e6e600 : na, editable=true, title='T Reversal Bar', show_last = ShowRecentSignalsIn)
barcolor(show_botR and botR ? #f57c00 : na, editable=true, title='B Reversal Bar', show_last = ShowRecentSignalsIn)

// Candle closing below top reversal
topR_low = ta.valuewhen(topR, low, 0)
topR_since = ta.barssince(topR) == 1
topR1 = close < topR_low and topR_since
plotshape(show_topbox ? topR1:na, title="Top Reversal bar1", location=location.abovebar, color=color.rgb(255, 235, 59, 50), style=shape.square, size=size.tiny, show_last = ShowRecentSignalsIn)

// Second Candle closing below top reversal
barsSinceTopR1 = ta.barssince(topR1) == 1
topR_low2 = ta.valuewhen(topR, low, 0)
topR_since2 = ta.barssince(topR) == 2
topR2 = close < topR_low2 and topR_since2 and barsSinceTopR1
plotshape(show_topbox2 ? topR2:na, title="Top Reversal bar2", location=location.abovebar, color=color.rgb(255, 0, 0, 50), style=shape.square, size=size.tiny, show_last = ShowRecentSignalsIn)

//Candle closing above bottom reversal
botR_high = ta.valuewhen(botR, high, 0)
botR_since = ta.barssince(botR) == 1
botR1 = close > botR_high and botR_since
plotshape(show_botbox ? botR1:na, title="Bottom Reversal bar1", location=location.belowbar, color=color.rgb(245, 123, 0, 50), style=shape.square, size=size.tiny, show_last = ShowRecentSignalsIn)

// Second Candle closing above bottom reversal
barsSinceBotR1 = ta.barssince(botR1) == 1
botR_high2 = ta.valuewhen(botR, high, 0)
botR_since2 = ta.barssince(botR) == 2
botR2 = close > botR_high2 and botR_since2 and barsSinceBotR1
plotshape(show_botbox2 ? botR2:na, title="Bottom Reversal bar2", location=location.belowbar, color=color.rgb(29, 245, 0, 50), style=shape.square, size=size.tiny, show_last = ShowRecentSignalsIn)

// 3 Line Strike from Lij_MC 'MarketVision A'. Awesome creator should check out the MarketVision B.
Bullish3LineStrike = close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close > open[1]
Bearish3LineStrike = close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close < open[1]

plotshape(show_bullish3strike ? Bullish3LineStrike:na, title='3 Line Strike', location=location.belowbar, style=shape.circle, color=color.new(color.green,70), size=size.tiny, show_last=ShowRecentSignalsIn)
plotshape(show_bearish3strike ? Bearish3LineStrike:na, title='3 Line Strike', location=location.abovebar, style=shape.circle, color=color.new(color.red,70), size=size.tiny, show_last=ShowRecentSignalsIn)

// Leledc Exhaustion Bar by glaz, used updated version by Joy_Bangla
src = close
majorBarCount = 6
majorBarLen = 30
minorBarCount = 5
minorBarLen = 5

bindexSindexInput = 1
closeValInput = 4

// Function for Leledec calculation
lele(qual, len) =>
    bindex = 0
    sindex = 0
    bindex := nz(bindex[bindexSindexInput], 0)
    sindex := nz(sindex[bindexSindexInput], 0)
    ret = 0

    if close > close[closeValInput]
        bindex += 1
        bindex
    if close < close[closeValInput]
        sindex += 1
        sindex
    if bindex > qual and close < open and high >= ta.highest(high, len)
        bindex := 0
        ret := -1
        ret
    if sindex > qual and close > open and low <= ta.lowest(low, len)
        sindex := 0
        ret := 1
        ret
    ret  // return ret

// Major and Minor calculations
major = lele(majorBarCount, majorBarLen)
minor = lele(minorBarCount, minorBarLen)

major_high = major == -1 ? high:na
major_low  = major == 1 ? low:na

plotchar(ShowLeledcHigh ? major_high:na, char='∘', location=location.absolute, color=color.new(color.red, 50), size=size.small, show_last=ShowRecentSignalsIn)
plotchar(ShowLeledcLow ? major_low:na, char='∘', location=location.absolute, color=color.new(color.lime, 50), size=size.small, show_last=ShowRecentSignalsIn)

// Alerts
alertcondition(rsi_UpArrow, title='RSI Up Arrow ', message='RSI Up Arrow')
alertcondition(rsi_DownArrow, title='RSI Down Arrow ', message='RSI Down Arrow')
alertcondition(topR, title='Reversal - Top', message='Top Reversal, candle bar closing back in BB')
alertcondition(botR, title='Reversal - Bottom', message='Bottom Reversal, candle bar closing back in BB')
alertcondition(topR1, title='R Top First Bar', message='Top R Confirmed First Bar')
alertcondition(botR1, title='R Bot First Bar', message='Bottom R Confirmed First Bar')
alertcondition(topR2, title='R Top Second Bar', message='Top R Confirmed Second Bar')
alertcondition(botR2, title='R Bot Second Bar', message='Bottom R Confirmed Second Bar')
alertcondition(Bullish3LineStrike, title='3 Line Strike - Bullish', message='Bullish 3 Line Strike')
alertcondition(Bearish3LineStrike, title='3 Line Strike - Bearish', message='Bearish 3 Line Strike')
alertcondition(major_high, title='Major Exhaustion - High', message='Leledc Major Exhaustion High')
alertcondition(major_low, title='Major Exhaustion - Low ', message='Leledc Major Exhaustion Low')
alertcondition(Bullish3LineStrike and major_low, title='Bullish Double trouble', message='Bullish 3 Line Strike - Major Exhuastion')
alertcondition(Bearish3LineStrike and major_high, title='Bearish Double Trouble', message='Bearish 3 Line Strike - Major Exhuastion')
alertcondition(Bullish3LineStrike and major_low and rsi_UpArrow, title='Bullish Triple Threat', message='Bullish 3 Line Strike - Major Exhuastion - RSI Up Arrow')
alertcondition(Bearish3LineStrike and major_high and rsi_DownArrow, title='Bearish Triple Threat', message='Bearish 3 Line Strike - Major Exhuastion - RSI Down Arrow')
alertcondition(ta.cross(close, ema1), title='EMA1 cross', message='Price is crossing EMA1')
alertcondition(ta.cross(close, ema2), title='EMA2 cross', message='Price is crossing EMA2')
alertcondition(ta.cross(close, ema3), title='EMA3 cross', message='Price is crossing EMA3')
alertcondition(ta.cross(close, ema4), title='EMA4 cross', message='Price is crossing EMA4')