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

//@version=5
indicator("Orion:Sagitta")
s = ta.stoch(close,high,low,2)
s1 = ta.stoch(close,high,low,1)
x = s >= 80 ? color.green :
     s >= 60 and s < 80  ? color.blue :
     s >= 40 and s < 60 ? color.yellow :
     s >= 20 and s < 50 ? color.orange :
     s < 20 ? color.red : color.red

y = s > 80 ? 100 :
     s >= 60 and s < 80 ? 80 :
     s >= 40 and s < 60 ? 60 :
     s >= 20 and s < 40 ? 40 :
     s < 20 ? 20 : 0

bullishBear = (high[1] > high[0] and low[1] > low[0] and close > low[1]) and (s1>=60)
x := bullishBear  ? color.silver : x

h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", color=#787B86)
HH = ta.highest(high,1)
LL = ta.lowest(low,1)

var cHigh = high
var cLow = low

consol = cHigh > close and close > cLow
cHigh := consol and high > cHigh ? high : cHigh
cLow := consol and cLow > low ? low : cLow

cHigh := consol == false ? high : cHigh
cLow := consol == false ? low : cLow

consolFlag = consol ? y : 0

alertValueHigher = y[0] > y[1]
alertValueLower = y[0] < y[1]

if alertValueHigher
    alert("Potential Entry Establish",alert.freq_once_per_bar_close)
else if alertValueLower
    alert("Adjust Stop Loss if in trade",alert.freq_once_per_bar_close)

plot(y,style=plot.style_histogram,linewidth =  8, color=x,title="Stochastic C%")
plot(consolFlag,style=plot.style_histogram,linewidth = 3,color=color.maroon,title="Consolidation Flag")
//plot(s,color=color.white,title="Stochastic")
