L.S.C : CF-SW ORG ORS ORI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © devilpretnd

//@version=5
indicator("L.S.C : CF-SW ORG ORS ORI", overlay=true, max_boxes_count=500, max_labels_count=500)


////////////////////////////////////////////////////////////     SETTING


showORG = input(true,title="Show ORG [ Order Release Gap ]",group="ORG")
bullORGColor = input.color(color.new(#244a8d, 47), title="Bullish ORG:",inline="i_1",group="ORG")
bearORGColor = input.color(color.new(#df3535, 66),title="Bearish ORG:",inline="i_2",group="ORG")


////////////////////////////////////////////////////////////     CFSW


var bool inSwingLow = false  
var bool inSwingHigh = false  

var int EL = 0
var int EH = 0


destroyedHigh = close > high[1]
destroyedLow = close < low[1]

CFSWL = destroyedHigh and EH == 0
CFSWH = destroyedLow and EL == 0


if CFSWH
    EH := 0
    EL := 1
    inSwingLow := true  
    inSwingHigh := false 

if CFSWL
    EH := 1
    EL := 0
    inSwingLow := false  
    inSwingHigh := true  


////////////////////////////////////////////////////////////     ORG


var box bullOrgBox = na
var box bearOrgBox = na


bullORG = high[2] < low 
bearORG = low[2] > high


if bullORG and showORG
    bullOrgBox := box.new(bar_index-2, low,bar_index,high[2], bgcolor=bullORGColor, border_color=na)

if bearORG and showORG
    bearOrgBox := box.new(bar_index-2, low[2],bar_index,high, bgcolor=bearORGColor, border_color=na)   


////////////////////////////////////////////////////////////     ORS 


var color ORScandleColor = na


bullORS = low > low[1] and low[1] < low[2]
bearORS = high < high[1] and high[1] > high[2] 


if inSwingHigh and bullORS
    ORScandleColor := bullORS ? color.rgb(86, 153, 240, 11) : na

else
    ORScandleColor := na

if inSwingLow and bearORS 
    ORScandleColor := bearORS ? color.rgb(86, 153, 240, 11) : na


////////////////////////////////////////////////////////////     ORI


var color ORIcandleColor = na


bullORI = high < high[1] and low > low[1]
bearORI = low > low[1] and high < high[1]


if inSwingHigh and bullORI 
    ORIcandleColor := bullORI ? color.rgb(255, 255, 255) : na

else
    ORIcandleColor := na

if inSwingLow and bearORI 
    ORIcandleColor := bearORI ? color.rgb(255, 255, 255) : na


////////////////////////////////////////////////////////////     ORI & ORS 


////////////////////////////////////////////////////////////     PLOT


barcolor(ORScandleColor, offset=-1, title = 'ORS  [ Order Release Sweep ]')
barcolor(ORIcandleColor, offset=-1, title = 'ORI  [ Order Release Internal ]')

plotshape(CFSWH, title='Show CF Swing High :', style=shape.cross, location=location.abovebar, color=color.rgb(76, 213, 255), size = size.tiny)
plotshape(CFSWL, title='Show CF Swing Low :', style=shape.cross, location=location.belowbar, color=color.rgb(255, 244, 92), size = size.tiny)

