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

//@version=4
study("Market Signals Complex", overlay=true)
// plot(close, title="Option 1", color=color.silver, linewidth=2, style=plot.style_line, trackprice=true, editable=false)

// Relative Strength Index

// RSI Input
rsiSource = input(title="RSI Source", type=input.source, defval=close)
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=65)
rsiOversold = input(title="RSI Oversold Level", type=input.integer, defval=35)

// Get RSI Value
rsiValue = rsi(rsiSource, rsiLength)
isRsiOB = rsiValue >= rsiOverbought
isRsiOS = rsiValue <= rsiOversold

// RSI Buy/Sell Signals
plotshape(isRsiOB, title="Overbought", location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, size=size.tiny)
plotshape(isRsiOS, title="Oversold", location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, size=size.tiny)



// Bullish Engulfing Candles
bullEng = close >= open[1] and close[1] < open[1]
bearEng = close <= open[1] and close[1] > open[1]
printEng = ((isRsiOS or isRsiOS[1] and bullEng) or (isRsiOB or isRsiOB[1] and bearEng))

plotshape(printEng and bullEng, title="Bullish Engulfing", location=location.belowbar, color=color.blue, transp=0, style=shape.flag, size=size.tiny, text="Engulfing")
plotshape(printEng and bearEng, title="Bearish Engulfing", location=location.abovebar, color=color.orange, transp=0, style=shape.flag, size=size.tiny, text="Engulfing")



// EMA Bands
showRibbon = input(true, "Show Ribbon")
ema_1 = input(5, title="EMA 1 Length")
ema_2 = input(18, title="EMA 2 Length")
ema_3 = input(21, title="EMA 3 Length")
ema_4 = input(28, title="EMA 4 Length")
ema_5 = input(34, title="EMA 5 Length")

ema1 = ema(close, ema_1)
ema2 = ema(close, ema_2)
ema3 = ema(close, ema_3)
ema4 = ema(close, ema_4)
ema5 = ema(close, ema_5)

ribbonDir = ema5 < ema2
colorEma = ribbonDir ? color.green : color.red
p1 = plot(ema1, color=showRibbon ? ribbonDir ? #1573d4 : color.gray : na, linewidth=2, transp=15, title="EMA 1")
p2 = plot(ema2, color=showRibbon ? ribbonDir ? #3096ff : color.gray : na, linewidth=2, transp=15, title="EMA 2")
plot(ema3, color=showRibbon ? ribbonDir ? #57abff : color.gray : na, linewidth=2, transp=15, title="EMA 3")
plot(ema4, color=showRibbon ? ribbonDir ? #85c2ff : color.gray : na, linewidth=2, transp=15, title="EMA 4")
plot(ema5, color=showRibbon ? ribbonDir ? #9bcdff : color.gray : na, linewidth=2, transp=15, title="EMA 5")
p8 = plot(ema5, color=showRibbon ? na : colorEma, linewidth=2, transp=0, title="EMA 8")
fill(p1, p2, color = #1573d4, transp = 85)
fill(p2, p8, color = #363a45, transp = 85)



// Long EMAs
showLongEMA = input(true, "Show Long EMAs")
emaLong_1 = input(50, title = "Long EMA Length 1")
emaLong_2 = input(200, title = "Long EMA Length 2")
emaLong1 = ema(close, emaLong_1)
emaLong2 = ema(close, emaLong_2)

plot(emaLong1, transp=showLongEMA ? 0 : 100, color = color.purple, linewidth=2, title="EMA Long 1")
plot(emaLong2, transp=showLongEMA ? 0 : 100, color = color.red, linewidth=2, title="EMA Long 2")


// BB Area
showBB = input(true, "Show Bollinger Bands")
length = input(20, minval=1)
src = input(close, title="Source")

mult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis1 = sma(src, length)
dev1 = mult1 * stdev(src, length)
upper1 = basis1 + dev1
lower1 = basis1 - dev1

mult2 = input(3.0, minval=0.001, maxval=50, title="StdDev")
basis2 = sma(src, length)
dev2 = mult2 * stdev(src, length)
upper2 = basis2 + dev2
lower2 = basis2 - dev2

mult3 = input(4.0, minval=0.001, maxval=50, title="StdDev")
basis3 = sma(src, length)
dev3 = mult3 * stdev(src, length)
upper3 = basis3 + dev3
lower3 = basis3 - dev3

mult4 = input(6.0, minval=0.001, maxval=50, title="StdDev")
basis4 = sma(src, length)
dev4 = mult4 * stdev(src, length)
upper4 = basis4 + dev4
lower4 = basis4 - dev4

offset = input(0, "Offset", minval = -500, maxval = 500)

p1_1 = plot(upper1, transp=showBB ? 85 : 100, title="Upper", color=#fc7f03, offset = offset)
p2_2 = plot(lower1, transp=showBB ? 85 : 100, title="Lower", color=#fc7f03, offset = offset)
fill(p1_1, p2_2, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(252, 127, 3, 98))

p1_3 = plot(upper2, transp=showBB ? 85 : 100, title="Upper", color=color.rgb(252, 148, 3, 85), offset = offset)
p2_4 = plot(lower2, transp=showBB ? 85 : 100, title="Lower", color=color.rgb(252, 148, 3, 85), offset = offset)

p1_5 = plot(upper3, transp=showBB ? 85 : 100, title="Upper", color=#fc2803, offset = offset)
p2_6 = plot(lower3, transp=showBB ? 85 : 100, title="Lower", color=#fc2803, offset = offset)

p1_7 = plot(upper4, transp=showBB ? 85 : 100, title="Upper", color=#fc2803, offset = offset)
p2_8 = plot(lower4, transp=showBB ? 85 : 100, title="Lower", color=#fc2803, offset = offset)

// Fill Upper Bands
fill(p1_1, p1_3, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(255, 71, 46, 70))
fill(p1_3, p1_5, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(133, 16, 0, 65))
fill(p1_5, p1_7, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(102, 12, 0, 80))

//Fill Lower Bands
fill(p2_2, p2_4, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(30, 115, 1, 70))
fill(p2_4, p2_6, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(23, 87, 1, 65))
fill(p2_6, p2_8, transp=showBB ? 0 : 100, title = "Background", color=color.rgb(14, 56, 0, 80))


// WT 
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
obLevel1 = input(60, "Over Bought Level 1")
obLevel2 = input(53, "Over Bought Level 2")
osLevel1 = input(-60, "Over Sold Level 1")
osLevel2 = input(-53, "Over Sold Level 2")

ap = hlc3
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)

wt1 = tci
wt2 = sma(wt1, 4)

cross_01_up = crossover(wt1, wt2)
cross_01_down = crossunder(wt1, wt2)

// Green Cross
plotshape(cross_01_up and (wt2 <= -50), style=shape.labelup, text="↑", textcolor=color.white, transp=1, title="cross 01", color=color.green, size=size.small, location=location.belowbar)
//plotchar(cross_01_up and (rsi_1 <= 45), title="cross_01 Bottom", char="x", location=location.bottom, color=color.green, transp=5, text="Secret Cross", textcolor=color.green)

// Red Cross
plotshape(cross_01_down and (wt2 >= 50), style=shape.labeldown, text="↓", textcolor=color.white, transp=1, title="cross 01", color=color.red, size=size.small)
//plotchar(cross_01_down and (rsi_1 >= 60), title="cross_01 Bottom", char="x", location=location.bottom, color=color.red, transp=5, text="Secret Cross", textcolor=color.red)










