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

//@version=5
indicator("Trap Car" , overlay = true , precision = 3   , max_labels_count = 500)
smoothK = input.int(3, 'K', minval=1)
smoothD = input.int(3, 'D', minval=1)
lengthRSI = input.int(14, 'RSI Length', minval=1)
lengthStoch = input.int(14, 'Stochastic Length', minval=1)
src = input(close, title='RSI Source')
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

cond = k == 0 
cond2 = k == 100


symbol =  input.string("🚘" ,  title = "Symbol for Stochastic Above 95 " , tooltip = "Only the first character is displayed")
symbol2  =  input.string("🚖" ,  title = "Symbol for Stochastic Between 5 - 95 " , tooltip = "Only the first character is displayed")
symbol3  =  input.string("🚔" ,  title = "Symbol for Stochastic below 5 " , tooltip = "Only the first character is displayed")
symsize =  input.string("Auto" ,  title =  "Symbol Size"  , options = ["Tiny" ,  "Small" , "Normal" , "Large" , "Huge" , "Auto"])
Locating =  input.string("Above Bar" , title = "Location" ,  options = ["Above Bar" ,  "Below Bar",   "Top" ,  "Bottom"])
colorSym  =  input.color(color.red ,  title =  "Color of Symbol" , tooltip = "This Works only for Symbols with no default colors , emoji have default colors so it wont work on them ")
textCol = input.color(color.red , title = "Color of Text")






candleSize(sizes) =>
    sizing = switch sizes
        "Tiny" => size.tiny
        "Small" => size.small
        "Normal" => size.normal
        "Large" => size.large
        "Huge" => size.huge
    sizing

location(locating) =>
    location = switch Locating
        "Above Bar" => location.abovebar
        "Below Bar" => location.belowbar
        "Top" => location.top
        "Bottom" => location.bottom
    location



sizeofsymbol =  candleSize(symsize)


plotchar((close > 0 or close < 0) and symsize == "Tiny" and k > 95, title = "Something" , char  =  symbol , location = location(Locating) , size = size.tiny , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Small" and k > 95, title = "Something" , char  =  symbol , location = location(Locating) , size = size.small , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Normal" and k > 95, title = "Something" , char  =  symbol , location = location(Locating) , size = size.normal  , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Large" and k > 95, title = "Something" , char  =  symbol , location = location(Locating) , size = size.large , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Huge" and k > 95, title = "Something" , char  =  symbol , location = location(Locating) , size = size.huge , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Auto" and k > 95, title = "Something" , char  =  symbol , location = location(Locating)  , display = display.pane , color  = colorSym)

plotchar((close > 0 or close < 0) and symsize == "Tiny" and k >=5 and k <= 95, title = "Something" , char  =  symbol2 , location = location(Locating) , size = size.tiny , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Small" and k >=5 and k <= 95, title = "Something" , char  =  symbol2 , location = location(Locating) , size = size.small , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Normal" and k >=5 and k <= 95, title = "Something" , char  =  symbol2 , location = location(Locating) , size = size.normal  , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Large" and k >=5 and k <= 95, title = "Something" , char  =  symbol2 , location = location(Locating) , size = size.large , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Huge" and k >=5 and k <= 95, title = "Something" , char  =  symbol2 , location = location(Locating) , size = size.huge , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Auto" and k >=5 and k <= 95, title = "Something" , char  =  symbol2 , location = location(Locating)  , display = display.pane , color  = colorSym)


plotchar((close > 0 or close < 0) and symsize == "Tiny" and k < 5, title = "Something" , char  =  symbol3 , location = location(Locating) , size = size.tiny , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Small" and k < 5, title = "Something" , char  =  symbol3 , location = location(Locating) , size = size.small , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Normal" and k < 5, title = "Something" , char  =  symbol3 , location = location(Locating) , size = size.normal  , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Large" and k < 5, title = "Something" , char  =  symbol3 , location = location(Locating) , size = size.large , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Huge" and k < 5, title = "Something" , char  =  symbol3 , location = location(Locating) , size = size.huge , display = display.pane , color  = colorSym)
plotchar((close > 0 or close < 0) and symsize == "Auto" and k < 5, title = "Something" , char  =  symbol3 , location = location(Locating)  , display = display.pane , color  = colorSym)


label.new(x = bar_index , y =low , text = cond ? "Buy" : cond2 ? "Sell" : str.tostring(k ,  "#.##") , style = label.style_diamond ,  color = color.rgb(255, 82, 82, 100) , textcolor = textCol , yloc  = yloc.belowbar , size = size.auto)

alertcondition(cond,  "Buy Alert" ,  "This is a Buy Signal Alert")
alertcondition(cond2,  "Sell Alert" ,  "This is a Sell Signal Alert")