wnG - Spikes Identifier
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wingoutoulouse

//@version=5
indicator(title="wnG - Spikes Identifier", shorttitle="wnG - Spikes Identifier [p]", overlay=true)

// NO INPUTS - TRADING SYSTEM
src_SPIKE = input(ohlc4,"Spike Source",group="Spike")
lps = input (false, title = "",group="Spike",inline="line 1")
len1_SMA = input.int(7,"Low Spike",group="Spike",inline="line 1")
mps = input (false, title = "",group="Spike",inline="line 2")
len2_SMA = input.int(14,"Mid Spike",group="Spike",inline="line 2")
hps = input (true, title = "",group="Spike",inline="line 3")
len3_SMA = input.int(21,"High Spike",group="Spike",inline="line 3")
vhps = input (true, title = "",group="Spike",inline="line 4")
len4_SMA = input.int(28,"Very High Spike",group="Spike",inline="line 4")

i_background = input.bool(true,title="Show BackGround ?",group="Charts")
i_strat = input.bool(true,title="Show Shapes ?",group="Charts")
i_line = input.bool(false,title="Show Levels ?",group="Charts")

spk1 = 1.6
spk2 = 2.4
spk3 = 3.2
spk4 = 4.

// Moving Average (Mid Point Fair Value)
ma1_Spike = ta.sma(src_SPIKE, len1_SMA)
ma2_Spike = ta.sma(src_SPIKE, len2_SMA)
ma3_Spike = ta.sma(src_SPIKE, len3_SMA)
ma4_Spike = ta.sma(src_SPIKE, len4_SMA)

// ATR (Dynamic Volatility Units)
rng1 = ta.sma(ta.tr,len1_SMA)
rng2 = ta.sma(ta.tr,len2_SMA)
rng3 = ta.sma(ta.tr,len3_SMA)
rng4 = ta.sma(ta.tr,len4_SMA)

// ATR deviation 
up1 = ma1_Spike + rng1 * spk1
up2 = ma2_Spike + rng2 * spk2
up3 = ma3_Spike + rng3 * spk3
up4 = ma4_Spike + rng4 * spk4

dn1 = ma1_Spike - rng1 * spk1
dn2 = ma2_Spike - rng2 * spk2
dn3 = ma3_Spike - rng3 * spk3
dn4 = ma4_Spike - rng4 * spk4

// Low Probability Trade Setup
ERhigh1 = high > up1 ? 1 : 0
ERlow1 = low < dn1 ? 1 : 0

// Medium Probability Trade Setup
ERhigh2 = high > up1 and high > up2 ? 1 : 0
ERlow2 = low < dn1 and low < dn2 ? 1 : 0

// High Probability Trade Setup
ERhigh3 = high > up1 and high > up2 and high > up3 ? 1 : 0
ERlow3 = low < dn1 and low < dn2 and low < dn3 ? 1 : 0

// Very High Probability Trade Setup
ERhigh4 = high > up1 and high > up2 and high > up3 and high > up4 ? 1 : 0
ERlow4 = low < dn1 and low < dn2 and low < dn3 and low < dn4 ? 1 : 0

// Plots Based on Selection
vHiPERh = vhps and ERhigh4 and i_background ? color.new(color.red,80) : na
vHiPERl = vhps and ERlow4 and i_background ? color.new(color.lime,80) : na

HiPERh = hps and ERhigh3 and i_background ? color.new(color.red,80) : na
HiPERl = hps and ERlow3 and i_background ? color.new(color.green,80) : na

MiPERh = mps and ERhigh2 and i_background ? color.new(color.orange,80) : na
MiPERl = mps and ERlow2 and i_background ? color.new(color.teal,80) : na

LoPERh = lps and ERhigh1 and i_background ? color.new(color.yellow,80) : na
LoPERl = lps and ERlow1 and i_background ? color.new(color.navy,80) : na


// Highlights
bgcolor(vHiPERh)
bgcolor(vHiPERl)
bgcolor(HiPERh)
bgcolor(HiPERl)
bgcolor(MiPERh)
bgcolor(MiPERl)
bgcolor(LoPERh)
bgcolor(LoPERl)

plot(i_line and lps ? up1 : na, color=color.new(color.maroon,50))
plot(i_line and lps ? dn1 : na, color=color.new(color.maroon,50))
plot(i_line and mps ? up2 : na, color=color.new(color.orange,50))
plot(i_line and mps ? dn2 : na, color=color.new(color.orange,50))
plot(i_line and hps ? up3 : na, color=color.new(color.yellow,50))
plot(i_line and hps ? dn3 : na, color=color.new(color.yellow,50))
plot(i_line and vhps ? up4 : na, color=color.new(color.white,50))
plot(i_line and vhps ? dn4 : na, color=color.new(color.white,50))

plotshape(i_strat and lps and ERhigh1 ? 1 : na,style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)
plotshape(i_strat and lps and ERlow1 ? 1 : na,style=shape.triangleup, color=color.lime, location=location.belowbar, size=size.small)

plotshape(i_strat and mps and ERhigh2 ? 1 : na,style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)
plotshape(i_strat and mps and ERlow2 ? 1 : na,style=shape.triangleup, color=color.lime, location=location.belowbar, size=size.small)

plotshape(i_strat and hps and ERhigh3 ? 1 : na,style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)
plotshape(i_strat and hps and ERlow3 ? 1 : na,style=shape.triangleup, color=color.lime, location=location.belowbar, size=size.small)

plotshape(i_strat and vhps and ERhigh4 ? 1 : na,style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)
plotshape(i_strat and vhps and ERlow4 ? 1 : na,style=shape.triangleup, color=color.lime, location=location.belowbar, size=size.small)

alertcondition(ERhigh1, title="High Spike [low]", message = "High Spike - Low probability")
alertcondition(ERlow1, title="Low Spike [low]", message = "Low Spike - Low probability")
alertcondition(ERhigh2, title="High Spike [medium]", message = "High Spike - Medium probability")
alertcondition(ERlow2, title="Low Spike [medium]", message = "Low Spike - Medium probability")
alertcondition(ERhigh3, title="High Spike [high]", message = "High Spike - High probability")
alertcondition(ERlow1, title="Low Spike [high]", message = "Low Spike - High probability")
alertcondition(ERhigh4, title="High Spike [very high]", message = "High Spike - Very High probability")
alertcondition(ERlow4, title="Low Spike [very high]", message = "Low Spike - Very High probability")
