PROTECTED SOURCE SCRIPT

INDIBOT PRO ANAKLYS ABO SALTAN

41
//version=5
indicator(title = "INDIBOT PRO ANAKLYS", overlay = true, max_bars_back = 5000, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500,calc_bars_count = 5000)
showHL = input.bool(false, "Major Pullback", inline = "HL", group = "Pullback", inline = 'smc11')

colorHL = input.color(#000000, "", group = "Pullback", inline='smc11')
showMn = input.bool(false, "Minor pullback", group = "Pullback")

//market structure
showSMC = input.bool(true, "True SMC Market Structure", group = "Market Structure",inline ='smc1')
lengSMC = input.int(40, title=": Lenght", inline="liveSMC", group="Market Structure", inline = 'smc1')
colorIDM = input.color(color.rgb(0, 0, 0, 20), "IDM", group = "Market Structure")
structure_type = input.string ("Choch with IDM",title='Smc Structure Type ', group="Market Structure", options=["Choch without IDM", "Choch with IDM"])
showCircleHL = input.bool(true, "True SMC Swing", inline = "HL", group = "Market Structure")

bull = input.color(color.green, "Bullish", group = "Market Structure",inline = 'smc12')
bear = input.color(color.red , "Bearish", group = "Market Structure",inline = 'smc12')

// mitatypeTouch = input.string("Touch","Mitigation Type",options = ["Touch","Break"],group = "Order Block") == "Touch"

//order block
extndBox = input.bool(true,"Extend box on break",group = "Order Block")
showExob = input.bool(true,"Show EXT OB",group = "Order Block")
showIdmob = input.bool(true,"Show IDM OB",group = "Order Block")
showBrkob = input.bool(true,"Show Break EXT OB & IDM OB ",group = "Order Block")
txtsiz = input.string( size.auto ,"EXT OB & IDM OB Text Size",options = [size.auto,size.tiny,size.small,size.normal,size.large,size.huge],group ='Order Block')

clrtxtextbullbg = input.color(color.rgb(76, 175, 79, 86),"EXT OB BG Color : Demand",group = "Order Block",inline = "clr13")
clrtxtextbearbg = input.color(color.rgb(255, 82, 82, 83),"Supply",group = "Order Block",inline = "clr13")
clrtxtextbulliembg = input.color(color.rgb(76, 175, 79, 86),"IDM OB BG Color : Demand",group = "Order Block",inline = "clr113")
clrtxtextbeariembg = input.color(color.rgb(255, 82, 82, 86),"Supply",group = "Order Block",inline = "clr113")

clrtxtextbull = input.color(color.green,"EXT OB Text Color : Demand",group = "Order Block",inline = "clr1")
clrtxtextbear = input.color(color.red,"Supply",group = "Order Block",inline = "clr1")
clrtxtextbulliem = input.color(color.green,"IDM OB Text Color : Demand",group = "Order Block",inline = "clr11")
clrtxtextbeariem = input.color(color.red,"Supply",group = "Order Block",inline = "clr11")


showPOI = input.bool(true, "(Order + Breaker + Mitigation + propulsion) Block", group="Order Block")
poi_type = input.string ("Mother Bar",title='Zone Type', group="Order Block", options=["---", "Mother Bar"])
colorSupply = input.color(#cd5c4800, 'Bullish', group = "Order Block")
colorDemand = input.color(#2f825f00, 'Bearish', group = "Order Block")
colorMitigated = input.color(#c0c0c000, 'Mitigated', group = "Order Block")

showSCOB = input.bool(true, "Show SCOB", inline = "Bar", group = "Order Block")
scobUp = input.color(#0b3ff9 , "Bullish SCOB", group = "Order Block")
scobDn = input.color(#da781d, "Bearish SCOB", group = "Order Block")

//Demand Zone & Supply Zone

show_order_blocks=input.bool(false,"Demand & Supply Zone",group = 'Demand Zone & Supply Zone', inline = 'smc6')
ibull_ob_css = input.color(#5f6b5d19, 'Demand Zone', inline = 'ob1', group = 'Demand Zone & Supply Zone')
ibear_ob_css = input.color(#ef3a3a19, 'Supply Zone', inline = 'ob1', group = 'Demand Zone & Supply Zone')
ob_type__ = 'All' //ob_type__= input.string('All', '',options = ['All','Internal','External'], group = 'Order Blocks',inline = 'ob1')
i_tf_ob = input.timeframe("", "Zone Timeframe", group = 'Demand Zone & Supply Zone')
mittigation_filt= 'wick' //input.string('Wicks', "Mitigation Method",options = ['Touch','Wicks','Close','Average'], group = 'Demand Zone & Supply Zone',inline = 'smc6')
overlapping_filt= true //input(false, 'Hide Overlap', inline = 'ob3', group = 'Order Blocks')
max_obs = input.int(8, 'Max OBs', minval = 3, group = 'Demand Zone & Supply Zone', inline = 'ob4')
length_extend_ob = input.int(defval = 20,title = "Length", minval = 0, maxval = 500 ,group = 'Demand Zone & Supply Zone', inline = "ob4")
ob_extend =false //input.bool(false,"Extend",group = 'Demand Zone & Supply Zone', inline = "ob4")
text_size_ob_ = size.normal
ob_text_color_1 = color.new(#787b86, 0)
volume_text = false //input.bool(false, 'Volume', group='Order Blocks',inline = 'ob1_t')
percent_text = false //input.bool(false, 'Percentage', group='Order Blocks',inline = 'ob1_t')
show_line_ob_1 = false
line_style_ob_1 = line.style_solid


//Order flow
// mitatypeTouchof = input.string("Touch","Mitigation Type",options = ["Touch","Break"],group = "Order Flow") == "Touch"

showMajoinMiner = input.bool(false,"Show Major OF's",group = "Order Flow",inline = "mc")
showISOB = input.bool(true,"Show Minor OF's",group = "Order Flow",inline = "mc1")

showMajoinMinerMax = input.int(10," : Max Count",group = "Order Flow",inline = "mc")
showISOBMax = input.int(10," : Max Count",group = "Order Flow",inline = "mc1")

showTsted = input.bool(false,"Show Break ",inline = "tstd",group = "Order Flow")
maxTested = input.int(20,"OF's Count",inline = "tstd",group = "Order Flow")

ClrMajorOFBull = input.color(color.rgb(33, 149, 243, 71),"Major ORDER FLOW COLOR", group = "Order Flow",inline = "mj")
ClrMajorOFBear = input.color(color.rgb(33, 149, 243, 72),"", group = "Order Flow",inline = "mj")
ClrMinorOFBull = input.color(color.rgb(155, 39, 176, 81),"Minor ORDER FLOW COLOR", group = "Order Flow",inline = "mj1")
ClrMinorOFBear = input.color(color.rgb(155, 39, 176, 86),"", group = "Order Flow",inline = "mj1")
clrObBBTated = input.color(color.rgb(136, 142, 252, 86),"Major/Minor OB Tested", group = "Order Flow")


//Candle
showISB = input.bool(false, 'Inside Bar Candle', inline = "smc3", group = "Candle")
colorOSB_up = input.color(#0b3ff9,'',inline = 'smc3', group = "Candle")

showOSB = input.bool(false, 'Outside Bar Candle', inline = "smc4", group = "Candle")
colorOSB_down = input.color(#da781d,'', group = "Candle", inline = 'smc4')
colorISB = input.color(color.rgb(187, 6, 247, 77),'Inside Bar', group = "Candle")


//fvg
show_fvg = input(false, 'Fair Value Gaps (FVG)', group = 'Fair Value Gaps', inline = 'fvg_css')
i_tf = input.timeframe("", "Timeframe", group = 'Fair Value Gaps',inline = 'smc7')
max_width_fvg = 1.5
remove_small = true //input.bool(true,"Filter FVG",group = 'Fair Value Gaps', inline = "width")
mittigation_filt_fvg= input.string('Touch', 'Mitigation Method',options = ['Touch','Wicks','Close','Average'], group = 'Fair Value Gaps', inline = "smc7")
fvg_color_fill = true // input.bool(true,"Fill",group = 'Fair Value Gaps', inline = "mt")
fvg_shade_fill = false //input.bool(false,"Shade",group = 'Fair Value Gaps', inline = "mt")
max_fvg = input.int(defval = 8,title = ": No", minval = 0, maxval = 50 ,group = 'Fair Value Gaps', inline = 'fvg_css')
length_extend = input.int(defval = 20,title = "Length", minval = 0, maxval = 100 ,group = 'Fair Value Gaps', inline = "OS")
fvg_extend =false //input.bool(false,"Extend",group = 'Fair Value Gaps', inline = "OS")
i_mtfbearishfvgcolor = input.color(color.yellow, "", group = 'Fair Value Gaps', inline = "fvg_css")
i_mtfbullishfvgcolor = input.color(color.yellow, "", group = 'Fair Value Gaps', inline = "fvg_css")
mid_style = 'Solid'
i_midPointColor = color.rgb(249, 250, 253, 99)
fvg_extend_B = true //input.bool(true,"Extend (Current)",group = 'Fair Value Gaps', inline = "mid")


//liquidity

liquidity_level_group = "Liquidity Levels"

currentTF = input.bool(false, title = "Liquidity Levels", group=liquidity_level_group, inline="smc8")
displayLimit = input.int(20, title = ": No", group=liquidity_level_group, inline="smc8")
lowLineColorHTF = input.color(#00bbf94d, "", group = liquidity_level_group, inline = "smc8")
highLineColorHTF = input.color(#e91e624d, "", group = liquidity_level_group, inline = "smc8")

htfTF = input.timeframe("", title = "Timeframe", inline="smc9",group=liquidity_level_group)
_candleType = input.string("Close", title = "Mitigation Method", options=["Close", "Wick"], group=liquidity_level_group,inline = 'smc9')

leftBars = 20 //input.int(8, title = "Pivot Length", group=liquidity_level_group, inline="2")
mitiOptions = 'Remove' //input.string("Remove", title = "Mitigated", inline="3", options=["Remove", "Show"], group=liquidity_level_group)


length_extend_liq = input.int(defval = 20,title = "Length", minval = 0, maxval = 500 ,group = liquidity_level_group, inline = "smc10")
extentionMax = false //input.bool(false, title = "Extend", group=liquidity_level_group, inline="4")
_highLineStyleHTF = "Solid"//input.string("Solid", title = "Line Style", options=["Solid", "Dashed", "Dotted"], group=liquidity_level_group,inline='5')
highLineStyleHTF = _highLineStyleHTF=="Solid" ? line.style_solid : _highLineStyleHTF=="Dashed" ? line.style_dashed : line.style_dotted
box_width = 2.5//input.float(3.0, title = "Width", group=liquidity_level_group,inline='5', minval = 1, maxval = 10, step = 0.5)
lineWidthHTF=2

liquidity_text_color = input.color(color.black , 'Text Color', inline = 'smc10', group = liquidity_level_group)
highBoxBorderColorHTF = color.new(highLineColorHTF,90)
lowBoxBorderColorHTF = color.new(lowLineColorHTF,90)
displayStyle_liq = "Boxes"//'Lines'





isOTE = input.bool(false,"Show OTE", inline = "ote", group = "Structure")
ote1 = input.float(0.78,"",inline = "ote",group = "Structure")
ote2 = input.float(0.61,"",inline = "ote",group = "Structure")
oteclr = input.color(#ff95002b,"",inline = "ote",group = "Structure")

sizGd = input.string(size.normal,"OTE Zone Size",options = [size.auto,size.tiny,size.small,size.normal,size.large,size.huge],group = "Structure")
// maxOTECount = input.int(20, title="Max OTE Count", inline = "maxote", group="Structure")

showPdh = input.bool(false,"Show PDH", inline = "PDH", group = "Structure")
lengPdh = input.int(40, title="", inline = "PDH", group="Structure")
showPdl = input.bool(false,"Show PDL", inline = "PDL", group = "Structure")
lengPdl = input.int(40, title="", inline = "PDL", group="Structure")
showMid = input.bool(true, "Show Equilibrium", inline = "mid", group = "Structure")
lengMid = input.int(40, title="", inline = "mid", group="Structure")

showSw = input.bool(true, "Show Swing Sweep", inline = "sweep", group = "Structure")
markX = input.bool(false, 'Mark "X"', inline = "sweep", group = "Structure")
colorSweep = input.color(color.gray, "", group = "Structure", inline = 'sweep')
showTP = false //input.bool(false, 'Show Target profit',group = 'Structure')
colorTP = color.new(color.purple, 0) // 0 is full opacity


mergeRatio = 0.1 // Set a default value
maxBarHistory = 2000 // Default value to avoid errors









//#region variable declaration
//Constant
const string IDM_TEXT = "I D M"
const string CHOCH_TEXT = "CHoCH"
const string BOS_TEXT = "B O S"
const string PDH_TEXT = "PDH"
const string PDL_TEXT = "PDL"
const string MID_TEXT = "0.5"

//line babel
var label idm_label = na
var line idm_line = na
var label choch_label = na
var line choch_line = na
var label bos_label = na
var line bos_line = na
var line pdh_line = na
var label pdh_label = na
var line pdl_line = na
var label pdl_label = na
var line mid_line = na
var line mid_line1 = na
var line mid_line2 = na
var label mid_label = na
var label mid_label1 = na
var label mid_label2 = na

//high low
var puHigh = high
var puLow = low
var puHigh_ = high
var puLow_ = low
var L = low
var H = high
var idmLow = low
var idmHigh = high
var lastH = high
var lastL = low
var H_lastH = high
var L_lastHH = low
var H_lastLL = high
var L_lastL = low
var motherHigh = high[1]
var motherLow = low[1]

//bar indexes
var int motherBar = time[1]
var int puBar = na
var int puHBar = na
var int puLBar = na
var int idmLBar = na
var int idmHBar = na
var int HBar = time
var int LBar = time
var int lastHBar = time
var int lastLBar = time

//structure confirm
var bool mnStrc = na
var bool prevMnStrc = na
var bool isPrevBos = na
var bool findIDM = false
var bool isBosUp = false
var bool isBosDn = false
var bool isCocUp = true
var bool isCocDn = true

//poi
var bool isSweepOBS = false
var int current_OBS = na
var float high_MOBS = na
var float low_MOBS = na

var bool isSweepOBD = false
var int current_OBD = na
var float low_MOBD = na
var float high_MOBD = na

//Array
var arrTopBotBar = array.new_int(1, time)
var arrTop = array.new_float(1, high)
var arrBot = array.new_float(1, low)

var arrPbHBar= array.new_int(0)
var arrPbHigh = array.new_float(0)
var arrPbLBar = array.new_int(0)
var arrPbLow = array.new_float(0)

var demandZone = array.new_box(0)
var supplyZone = array.new_box(0)
var supplyZoneIsMit = array.new_int(0)
var demandZoneIsMit = array.new_int(0)
var arrIdmHigh = array.new_float(0)
var arrIdmLow = array.new_float(0)
var arrIdmHBar = array.new_int(0)
var arrIdmLBar = array.new_int(0)
var arrLastH = array.new_float(0)
var arrLastHBar = array.new_int(0)
var arrLastL = array.new_float(0)
var arrLastLBar = array.new_int(0)
var arrIdmLine = array.new_line(0)
var arrIdmLabel = array.new_label(0)
var arrBCLine = array.new_line(0)
var arrBCLabel = array.new_label(0)
var arrHLLabel = array.new_label(0)
var arrHLCircle = array.new_label(0)

//color
color transp = color.new(color.gray,100)

//Caculate
curTf = timeframe.in_seconds(timeframe.period)
dayTf = timeframe.in_seconds("1D")
i_loop = 2*dayTf/curTf
[pdh, pdl] = request.security(syminfo.tickerid, 'D', [high[1], low[1]])
len = curTf*1000

//#endregion

//#region Inside Bar
isb = motherHigh > high and motherLow < low
if isb
motherHigh := motherHigh
motherLow := motherLow
motherBar := motherBar
else
motherHigh := high
motherLow := low
motherBar := time

//#endregion

//#region drawing function
isGreenBar(int bar) => close[bar] > open[bar]

textCenter(int left, int right) => int(math.avg(left,right))

getStyleLabel(bool style) => style ? label.style_label_down : label.style_label_up

getStyleArrow(bool style) => style ? label.style_arrowdown : label.style_arrowup

getYloc(bool style) => style ? yloc.abovebar : yloc.belowbar

getDirection(bool trend, int HBar, int LBar, float H, float L) =>
x = trend ? HBar : LBar
y = trend ? H : L
[x, y]

getTextLabel(float current, float last, string same, string diff) => current > last ? same : diff

getPdhlBar(float value) =>
int x = na
if value == pdh
for i = i_loop to 1 by 1
if (high == pdh)
x := time
break
else
for i = i_loop to 1 by 1
if (low == pdl)
x := time
break
x

updateTopBotValue() =>
array.push(arrTop, high)
array.push(arrBot, low)
array.push(arrTopBotBar, time)

updateLastHLValue() =>
array.push(arrLastH,lastH)
array.push(arrLastHBar,lastHBar)
array.push(arrLastL,lastL)
array.push(arrLastLBar,lastLBar)

updateIdmHigh() =>
array.push(arrIdmHigh,puHigh)
array.push(arrIdmHBar,puHBar)

updateIdmLow() =>
array.push(arrIdmLow,puLow)
array.push(arrIdmLBar,puLBar)

getNLastValue(arr, n) =>
if array.size(arr) > n - 1
array.get(arr, array.size(arr) - n)

removeNLastLabel(arr, n) =>
if array.size(arr) > n - 1
label.delete(array.get(arr, array.size(arr) - n))

removeNLastLine(arr, n) =>
if array.size(arr) > n - 1
line.delete(array.get(arr, array.size(arr) - n))

removeLastLabel(arr, n) =>
if array.size(arr) > n - 1
for i = 1 to n
label.delete(array.get(arr, array.size(arr) - i))

removeLastLine(arr, n) =>
if array.size(arr) > n - 1
for i = 1 to n
line.delete(array.get(arr, array.size(arr) - i))

var arrmitOBBulla = array.new_bool(0)
var arrmitOBBull = array.new_box(0)
// var arrmitOBBulli = array.new_int(0)

var arrmitOBBeara = array.new_bool(0)
var arrmitOBBear = array.new_box(0)
// var arrmitOBBeari = array.new_int(0)

if extndBox
if arrmitOBBull.size() > 0
i = 0
while i < arrmitOBBull.size()
bx = arrmitOBBull.get(i)
bx.set_right(time)
if close > bx.get_top() and not arrmitOBBulla.get(i)
arrmitOBBulla.set(i,true)
if low < bx.get_top() and arrmitOBBulla.get(i)
//bx.set_right(arrmitOBBulli.get(i))
//arrmitOBBulli.remove(i)
arrmitOBBull.remove(i)
arrmitOBBulla.remove(i)
i -= 1
i += 1
if arrmitOBBear.size() > 0
i = 0
while i < arrmitOBBear.size()
bx = arrmitOBBear.get(i)
bx.set_right(time)
if close < bx.get_bottom() and not arrmitOBBeara.get(i)
arrmitOBBeara.set(i,true)
if high > bx.get_bottom() and arrmitOBBeara.get(i)
//bx.set_right(arrmitOBBeari.get(i))
//arrmitOBBeari.remove(i)
arrmitOBBear.remove(i)
arrmitOBBeara.remove(i)
i -= 1
i += 1


removeZone(zoneArray, box zone,zoneArrayisMit,isBull) =>
index = array.indexof(zoneArray, zone)
if not showBrkob
box.delete(zone)
else
box.set_right(zone, time)
box.set_extend(zone,extend.none)
// box.set_bgcolor(zone, colorMitigated)
// box.set_border_color(zone, colorMitigated)
if not isBull
arrmitOBBull.unshift(zone)
// arrmitOBBulli.unshift(time)
arrmitOBBulla.unshift(false)
else
arrmitOBBear.unshift(zone)
// arrmitOBBeari.unshift(time)
arrmitOBBeara.unshift(false)

array.remove(zoneArray, index)
array.remove(zoneArrayisMit, index)

fixStrcAfterBos() =>
removeLastLabel(arrBCLabel, 1)
removeLastLine(arrBCLine, 1)
removeLastLabel(arrIdmLabel, 1)
removeLastLine(arrIdmLine, 1)
removeLastLabel(arrHLLabel, 2)
removeLastLabel(arrHLCircle, 2)

fixStrcAfterChoch() =>
removeLastLabel(arrBCLabel, 2)
removeLastLine(arrBCLine, 2)
removeNLastLabel(arrHLLabel, 2)
removeNLastLabel(arrHLLabel, 3)
removeNLastLabel(arrHLCircle, 2)
removeNLastLabel(arrHLCircle, 3)
removeNLastLabel(arrIdmLabel, 2)
removeNLastLine(arrIdmLine, 2)

var float lstHlPrs = na
var float lstHlPrsIdm = na
var box lstBxIdm = na

drawIDM(bool trend) =>
[x, y] = getDirection(trend, idmLBar, idmHBar, idmLow, idmHigh)
//label.new(bar_index,low)
box lstBx_ = na
if trend
idx = -1
float lstPrs = na
if demandZone.size() > 0
for i = 0 to demandZone.size() -1
bx = demandZone.get(i)
if demandZoneIsMit.get(i) == 0 and ((bx.get_top() > lstPrs) or na(lstPrs)) and bx.get_top() <= y and bx.get_bottom() >= lstHlPrsIdm
idx := i
lstPrs := bx.get_top()
if idx != -1
lstBxIdm.set_text("Hist IDM OB")
lstBx_ := demandZone.get(idx)
if showIdmob
demandZone.get(idx).set_text("IDM OB")
demandZone.get(idx).set_text_color(clrtxtextbulliem)
demandZone.get(idx).set_bgcolor(clrtxtextbulliembg)
demandZoneIsMit.set(idx,1)
else
removeZone(demandZone,demandZone.get(idx),demandZoneIsMit,true)
else
idx = -1
float lstPrs = na
if supplyZone.size() > 0
for i = 0 to supplyZone.size() -1
bx = supplyZone.get(i)
if supplyZoneIsMit.get(i) == 0 and ((bx.get_bottom() < lstPrs) or na(lstPrs)) and bx.get_bottom() >= y and bx.get_top() <= lstHlPrsIdm
idx := i
lstPrs := bx.get_top()
if idx != -1
lstBxIdm.set_text("Hist IDM OB")
lstBx_ := supplyZone.get(idx)
if showIdmob
supplyZone.get(idx).set_text("IDM OB")
supplyZone.get(idx).set_text_color(clrtxtextbeariem)
supplyZone.get(idx).set_bgcolor(clrtxtextbeariembg)
supplyZoneIsMit.set(idx,1)
else
removeZone(supplyZone,supplyZone.get(idx),supplyZoneIsMit,false)


colorText = trend and H_lastH > L_lastHH or not trend and H_lastLL > L_lastL ? color.red : colorIDM
if showSMC
ln = line.new(x, y, time, y, xloc.bar_time, color = colorIDM, style = line.style_dotted)
lbl = label.new(textCenter(time, x), y, IDM_TEXT, xloc.bar_time, color = transp, textcolor = colorText, style = getStyleLabel(not trend), size = size.small)
array.push(arrIdmLine,ln)
array.push(arrIdmLabel,lbl)
array.clear(trend ? arrIdmLow : arrIdmHigh)
array.clear(trend ? arrIdmLBar : arrIdmHBar)

lstBx_

var box lstBx = na

drawStructure(name, trend) =>
[x, y] = getDirection(trend, lastHBar, lastLBar, lastH, lastL)
box lstBx_ = na
if trend
// label.new(bar_index,lstHlPrs)
// label.new(bar_index,y)
idx = -1
float lstPrs = na
if demandZone.size() > 0
// var arrlx = array.new_label(0)
// if arrlx.size() > 0
// while arrlx.size() > 0
// arrlx.pop().delete()
for i = 0 to demandZone.size() -1
bx = demandZone.get(i)
// if demandZoneIsMit.get(i) == 0 and ((bx.get_top() < lstPrs) or na(lstPrs)) and bx.get_top() <= y
// arrlx.unshift(label.new(bar_index,bx.get_top(),color = color.green))
if demandZoneIsMit.get(i) == 0 and ((bx.get_top() < lstPrs) or na(lstPrs)) and bx.get_top() <= y and bx.get_bottom() >= lstHlPrs
idx := i
lstPrs := bx.get_top()
if idx != -1
lstBx.set_text("Hist EXT OB")
lstBx_ := demandZone.get(idx)
if showExob
demandZone.get(idx).set_text("EXT OB")
demandZone.get(idx).set_text_color(clrtxtextbull)
demandZone.get(idx).set_bgcolor(clrtxtextbullbg)
demandZoneIsMit.set(idx,1)
else
removeZone(demandZone,demandZone.get(idx),demandZoneIsMit,true)

//label.new(bar_index,demandZone.get(idx).get_top(),color = color.red)
else
idx = -1
float lstPrs = na
if supplyZone.size() > 0
for i = 0 to supplyZone.size() -1
bx = supplyZone.get(i)
if supplyZoneIsMit.get(i) == 0 and ((bx.get_top() > lstPrs) or na(lstPrs)) and bx.get_bottom() >= y and bx.get_top() <= lstHlPrs
idx := i
lstPrs := bx.get_top()
if idx != -1
lstBx.set_text("Hist EXT OB")
lstBx_ := supplyZone.get(idx)
if showExob
supplyZone.get(idx).set_text("EXT OB")
supplyZone.get(idx).set_text_color(clrtxtextbear)
supplyZone.get(idx).set_bgcolor(clrtxtextbearbg)
supplyZoneIsMit.set(idx,1)
else
removeZone(supplyZone,supplyZone.get(idx),supplyZoneIsMit,false)


color = trend ? bull : bear
if name == "BOS" and showSMC
ln = line.new(x, y, time, y, xloc.bar_time, color = color, style = line.style_dashed)
lbl = label.new(textCenter(time, x), y, BOS_TEXT, xloc.bar_time, color = transp, style = getStyleLabel(trend), textcolor = color, size = size.small)
array.push(arrBCLine,ln)
array.push(arrBCLabel,lbl)
if name == "ChoCh" and showSMC
ln = line.new(x, y, time, y, xloc.bar_time, color = color, style = line.style_dashed)
lbl = label.new(textCenter(time, x), y, CHOCH_TEXT, xloc.bar_time, color = transp, style = getStyleLabel(trend), textcolor = color, size = size.small)
array.push(arrBCLine,ln)
array.push(arrBCLabel,lbl)

[lstHlPrs,lstBx_]

drawLiveStrc(bool condition, bool direction, color color1, color color2, string txt, int length, label lbl, line ln) =>
var line _ln = ln
var label _lbl = lbl
if condition
colorText = direction ? color1 : color2
[x, y] = if txt == IDM_TEXT
getDirection(direction, idmHBar, idmLBar, idmHigh, idmLow)
else
getDirection(direction, lastHBar, lastLBar, lastH, lastL)
_txt = txt + " - " + str.tostring(y)
_ln := line.new(x, y, time + len*length, y, xloc.bar_time, color = colorIDM, style = line.style_dotted),
_lbl := label.new(time + len*length, y, _txt, xloc.bar_time, color = transp, textcolor = colorText, style = label.style_label_left, size = size.small)
line.delete(_ln[1])
label.delete(_lbl[1])

fibo_limit(ratio, range_high, range_low) =>
range_1 = range_high - range_low
range_ratio = range_high - range_1 * ratio
range_ratio

drawPrevStrc(bool condition, string txt, label lbl, line ln,ote) =>
var float val = na
var int valiIdx = na
var line _ln = ln
var label _lbl = lbl
idDirUP = lastLBar < lastHBar
[x, y, color, x2, style] = switch
txt == PDH_TEXT => [getPdhlBar(pdh), pdh, bull, time + len*lengPdh, line.style_solid]
txt == PDL_TEXT => [getPdhlBar(pdl), pdl, bear, time + len*lengPdl, line.style_solid]
txt == MID_TEXT => [math.min(lastLBar, lastHBar), math.avg(lastL, lastH), colorIDM, time + len*lengMid, line.style_dotted]
=> [math.min(lastLBar, lastHBar), idDirUP ? fibo_limit(ote, lastH,lastL) : fibo_limit(ote, lastL, lastH), colorIDM, time + len, line.style_dotted]
_txt = txt + " - " + str.tostring(y)
if condition
val := y
valiIdx := x
_ln := line.new(x, y, x2, y, xloc.bar_time, color = color, style = style)
if txt != ""
_lbl := label.new(x2, y, _txt, xloc.bar_time, color = transp, textcolor = color, style = label.style_label_left, size = size.small)
line.delete(_ln[1])
label.delete(_lbl[1])
[val,valiIdx,idDirUP]
//_ln

var arrPrevPrsMin = array.new_float(1,0)
var arrPrevIdxMin = array.new_int(1,0)

var arrlstHigh = array.new_float(1,0)
var arrlstLow = array.new_float(1,0)

var arrOBTstdo = array.new_box(0)

var arrOBTstd = array.new_box(0)
var arrOBTstdTy = array.new_int(0)

i = 0
while i < arrOBTstd.size()
bx = arrOBTstd.get(i)
if arrOBTstdTy.get(i) == 1 and low < bx.get_bottom()
if showTsted
arrOBTstdo.unshift(arrOBTstd.remove(i))
else
arrOBTstd.remove(i).delete()
arrOBTstdTy.remove(i)
i -=1
else if arrOBTstdTy.get(i) == -1 and high > bx.get_top()
if showTsted
arrOBTstdo.unshift(arrOBTstd.remove(i))
else
arrOBTstd.remove(i).delete()
arrOBTstdTy.remove(i)
i -=1
i += 1

if arrOBTstdo.size() > maxTested
arrOBTstdo.pop().delete()


var arrOBBullm = array.new_box(0)
var arrOBBearm = array.new_box(0)
var arrOBBullisVm = array.new_bool(0)
var arrOBBearisVm = array.new_bool(0)

var arrOBBulls = array.new_box(0)
var arrOBBears = array.new_box(0)
var arrOBBullisVs = array.new_bool(0)
var arrOBBearisVs = array.new_bool(0)


getProcess(arrOBBull,arrOBBear,arrOBBullisV,arrOBBearisV)=>
alertBullOf = false
alertBearOf = false

if arrOBBull.size() > 0
i = 0
while i < arrOBBull.size()
bx = arrOBBull.get(i)
bx.set_right(time)
if not arrOBBullisV.get(i)
if low < bx.get_bottom()
bx.delete()
arrOBBull.remove(i)
arrOBBullisV.remove(i)
i -=1
else if high > bx.get_top()
arrOBBullisV.set(i,true)
else
if low < bx.get_top() and low[1] > bx.get_top()
alertBullOf := true
if low < bx.get_top()
bx.set_bgcolor(clrObBBTated)
bx.set_border_color(clrObBBTated)
//if showTsted
arrOBTstd.unshift(bx)
arrOBTstdTy.unshift(1)
// if arrOBTstd.size() > maxTested
// arrOBTstd.pop().delete()
// else
// bx.delete()
arrOBBull.remove(i)
arrOBBullisV.remove(i)
i -=1
i += 1
if arrOBBear.size() > 0
i = 0
while i < arrOBBear.size()
bx = arrOBBear.get(i)
bx.set_right(time)
if not arrOBBearisV.get(i)
if high > bx.get_top()
bx.delete()
arrOBBear.remove(i)
arrOBBearisV.remove(i)
i -=1
else if low < bx.get_bottom()
arrOBBearisV.set(i,true)
else
if high > bx.get_bottom() and high[1] < bx.get_bottom()
alertBearOf := true
if high > bx.get_bottom()
bx.set_bgcolor(clrObBBTated)
bx.set_border_color(clrObBBTated)
//if showTsted
arrOBTstd.unshift(bx)
arrOBTstdTy.unshift(-1)
// if arrOBTstd.size() > maxTested
// arrOBTstd.pop().delete()
// else
// bx.delete()
arrOBBear.remove(i)
arrOBBearisV.remove(i)
i -=1
i += 1

[alertBullOf,alertBearOf]

[alertBullOfMajor,alertBearOfMajor] = getProcess(arrOBBullm,arrOBBearm,arrOBBullisVm,arrOBBearisVm)
[alertBullOfMinor,alertBearOfMinor] = getProcess(arrOBBulls,arrOBBears,arrOBBullisVs,arrOBBearisVs)

alertcondition(alertBullOfMajor,"Major Bullish order flow","Major Bullish order flow")
alertcondition(alertBearOfMajor,"Major Bearish order flow","Major Bearish order flow")
alertcondition(alertBullOfMinor,"Minor Bullish order flow","Minor Bullish order flow")
alertcondition(alertBearOfMinor,"Minor Bearish order flow","Minor Bearish order flow")

labelMn(bool trend) =>
[x, y] = getDirection(trend, puHBar, puLBar, puHigh, puLow)
color = trend ? bear : bull
txt = trend ? getTextLabel(puHigh, arrlstHigh.get(0), "HH", "LH") : getTextLabel(puLow, arrlstLow.get(0), "HL", "LL")
if showMn
label.new(x, y, "", xloc.bar_time, getYloc(trend), color, getStyleArrow(trend), size = size.tiny ,textcolor = color.red)

if showISOB
if txt == "HH" or txt == "LL"
arrPrevPrsMin.set(0,y)
arrPrevIdxMin.set(0,x)
if txt == "HL" or txt == "LH"
if arrPrevPrsMin.get(0) != 0
if txt == "HL"
arrOBBulls.unshift(box.new(arrPrevIdxMin.get(0),arrPrevPrsMin.get(0),x,y,bgcolor = ClrMinorOFBull,border_color = ClrMinorOFBull,xloc = xloc.bar_time))
arrOBBullisVs.unshift(false)
if arrOBBulls.size() > showISOBMax
arrOBBulls.pop().delete()
arrOBBullisVs.pop()

else
arrOBBears.unshift(box.new(x,y,arrPrevIdxMin.get(0),arrPrevPrsMin.get(0),bgcolor = ClrMinorOFBear,border_color = ClrMinorOFBear,xloc = xloc.bar_time))
arrOBBearisVs.unshift(false)
if arrOBBears.size() > showISOBMax
arrOBBears.pop().delete()
arrOBBearisVs.pop()

arrPrevPrsMin.set(0,0)
arrPrevIdxMin.set(0,0)

if trend
arrlstHigh.set(0,y)
else
arrlstLow.set(0,y)

var arrPrevPrs = array.new_float(1,0)
var arrPrevIdx = array.new_int(1,0)

labelHL(bool trend) =>
[x, y] = getDirection(trend, HBar, LBar, H, L)
txt = trend ? getTextLabel(H, getNLastValue(arrLastH, 1), "HH", "LH") : getTextLabel(L, getNLastValue(arrLastL, 1), "HL", "LL")
if showMajoinMiner
if txt == "HH" or txt == "LL"
arrPrevPrs.set(0,y)
arrPrevIdx.set(0,x)
if txt == "HL" or txt == "LH"
if arrPrevPrs.get(0) != 0
if txt == "HL"
arrOBBullm.unshift(box.new(arrPrevIdx.get(0),arrPrevPrs.get(0),x,y,bgcolor = ClrMajorOFBull,border_color = ClrMajorOFBull,xloc = xloc.bar_time))
arrOBBullisVm.unshift(false)
if arrOBBullm.size() > showMajoinMinerMax
arrOBBullm.pop().delete()
arrOBBullisVm.pop()

else
arrOBBearm.unshift(box.new(x,y,arrPrevIdx.get(0),arrPrevPrs.get(0),bgcolor = ClrMajorOFBear,border_color = ClrMajorOFBear,xloc = xloc.bar_time))
arrOBBearisVm.unshift(false)
if arrOBBearm.size() > showMajoinMinerMax
arrOBBearm.pop().delete()
arrOBBearisVm.pop()


arrPrevPrs.set(0,0)
arrPrevIdx.set(0,0)



if showHL
lbl = label.new(x, y, txt, xloc.bar_time, color = transp, textcolor = colorHL, style = getStyleLabel(trend))
array.push(arrHLLabel, lbl)
if showCircleHL
lbl2 = label.new(x, y, '', xloc.bar_time, getYloc(trend), color = trend ? bull : bear, style = label.style_circle, size = size.tiny)
array.push(arrHLCircle, lbl2)
y
sweepHL(bool trend) =>
[x, y] = getDirection(trend, lastHBar, lastLBar, lastH, lastL)
if showSw
line.new(x, y, time, y, xloc.bar_time, color = colorSweep, style = line.style_dotted)
if markX
label.new(textCenter(time, x), y, "X", xloc.bar_time, color = transp, textcolor = colorSweep, style = getStyleLabel(trend), size = size.small)



TP(H, L) =>
target = isCocUp ? high + math.abs(H - L) : low - math.abs(H - L)
target := target < 0 ? 0 : target
if showTP
line.new(bar_index, isCocUp ? high : low, bar_index, target, color = colorTP, style = line.style_arrow_right)

createBox(left, right, top, bottom, color) =>
box.new(left=left, right=right, top=top, bottom=bottom, xloc = xloc.bar_time, bgcolor=color, border_color=color,text_color = color.new(color,20),text_halign = text.align_center ,extend = extend.none,text_size = txtsiz)

marginZone(zone) => [box.get_top(zone), box.get_bottom(zone), box.get_left(zone)]

handleZone(zoneArray,zoneArrayisMit, left, top, bot, color,isBull) =>
_top = top
_bot = bot
_left = left

zone = getNLastValue(zoneArray, 1)
//zmt = getNLastValue(zoneArrayisMit, 1)

[topZone, botZone, leftZone] = marginZone(zone)
rangeTop = math.abs(_top-topZone)/(topZone-botZone) < mergeRatio
rangeBot = math.abs(_bot-botZone)/(topZone-botZone) < mergeRatio

//Merge zone
if _top >= topZone and _bot <= botZone or rangeTop or rangeBot
_top := math.max(_top,topZone)
_bot := math.min(_bot,botZone)
_left := leftZone
removeZone(zoneArray, zone,zoneArrayisMit,isBull)


if not (_top <= topZone and _bot >= botZone)
array.push(zoneArray, createBox(_left, time, _top, _bot, color))
zoneArrayisMit.push(0)


processZones(zones, isSupply,zonesmit) =>
isAlertextidm = false
if array.size(zones) > 0
for i = array.size(zones) - 1 to 0 by 1
zone = array.get(zones, i)
if zonesmit.get(i) == 0 or zonesmit.get(i) == 1
zone.set_right(time)
[topZone, botZone, leftZone] = marginZone(zone)
//isTouch = (isSupply and high >= botZone and high < topZone) or (not isSupply and low <= topZone and low > botZone)
//Breaker block zones
if isSupply and low < botZone and close > topZone
array.push(demandZone,createBox(leftZone, time, topZone, botZone, colorDemand))
demandZoneIsMit.push(0)
else if not isSupply and high > topZone and close < botZone
array.push(supplyZone, createBox(leftZone, time, topZone, botZone, colorSupply))
supplyZoneIsMit.push(0)
//Mitigated zones
else if (isSupply and high >= botZone and high[1] < botZone) or (not isSupply and low <= topZone and low[1] > topZone) //mitatypeTouch ? isTouch : (isSupply and high >= topZone and high[1] < topZone) or (not isSupply and low <= botZone and low[1] > botZone)
box.set_right(zone, time)
box.set_extend(zone,extend.none)
// box.set_bgcolor(zone, colorMitigated)
// box.set_border_color(zone, colorMitigated)

if extndBox and high >= topZone and low <= botZone
if isSupply
arrmitOBBull.unshift(zone)
// arrmitOBBulli.unshift(time)
arrmitOBBulla.unshift(false)
else
arrmitOBBear.unshift(zone)
// arrmitOBBeari.unshift(time)
arrmitOBBeara.unshift(false)

if isSupply
if supplyZoneIsMit.get(i) == 1
isAlertextidm := true
if supplyZoneIsMit.get(i) != 1
box.set_bgcolor(zone, colorMitigated)
box.set_border_color(zone, colorMitigated)
supplyZoneIsMit.set(i, supplyZoneIsMit.get(i) == 1 ? 3 : 2)
else
if demandZoneIsMit.get(i) == 1
isAlertextidm := true
if demandZoneIsMit.get(i) != 1
box.set_bgcolor(zone, colorMitigated)
box.set_border_color(zone, colorMitigated)
demandZoneIsMit.set(i, demandZoneIsMit.get(i) == 1 ? 3 : 2)

if showBrkob
zones.remove(i)
zonesmit.remove(i)

// if not showBrkob
// zone.delete()



// //Delete sweep zones
else if (time - leftZone > len*maxBarHistory) or (isSupply and high >= topZone) or (not isSupply and low <= botZone)
// box.set_bgcolor(zone, colorMitigated)
// box.set_border_color(zone, colorMitigated)

removeZone(zones, zone,zonesmit,not isSupply)

0

isAlertextidm

scob(zones, isSupply) =>
[topZone, botZone, leftZone] = marginZone(getNLastValue(zones, 1))

if not isb[1]
if not isSupply and low[1] < low[2] and low[1] < low and close > high[1] and low[1] < topZone and low[1] > botZone
scobUp
else if isSupply and high[1] > high[2] and high[1] > high and close < low[1] and high[1] < topZone and high[1] > botZone
scobDn
else
na
//#endregion

//#region get value from array
top = getNLastValue(arrTop, 1)
bot = getNLastValue(arrBot, 1)
topBotBar = getNLastValue(arrTopBotBar, 1)

top1 = getNLastValue(arrTop, 2)
bot1 = getNLastValue(arrBot, 2)
topBotBar1 = getNLastValue(arrTopBotBar, 2)
//#endregion

//#region Outside Bar
osb = high > top and low < bot

//#endregion

//#region Minor Structure
if high >= top and low <= bot //notrend
if not na(mnStrc)
prevMnStrc := mnStrc ? true : false
else
if prevMnStrc and isGreenBar(0) and not isGreenBar(1)
puHigh := top
puHigh_ := top
puHBar := topBotBar
labelMn(true)
labelMn(false)
if high > H
updateIdmLow()

if not prevMnStrc and not isGreenBar(0) and isGreenBar(1)
puLow := bot
puLow_ := bot
puLBar := topBotBar
labelMn(true)
labelMn(false)
if low < L
updateIdmHigh()

if low < L and isGreenBar(0)
updateIdmHigh()

if high > H and not isGreenBar(0)
updateIdmLow()

updateTopBotValue()
puHigh := high
puHigh_ := high
puLow := low
puLow_ := low
puHBar := time
puLBar := time
mnStrc := na

if high >= top and low > bot //uptrend
if prevMnStrc and na(mnStrc)
puHigh := top1
puHigh_ := top1
puHBar := topBotBar1
labelMn(true)
labelMn(false)
else if (not prevMnStrc and na(mnStrc)) or not mnStrc
labelMn(false)

if high > H
updateIdmLow()

updateTopBotValue()
puHigh := high
puHigh_ := high
puHBar := time
prevMnStrc := na
mnStrc := true

if high < top and low <= bot //downtrend
if not prevMnStrc and na(mnStrc)
puLow := bot1
puLow_ := bot1
puLBar := topBotBar1
labelMn(false)
labelMn(true)
else if (prevMnStrc and na(mnStrc)) or mnStrc
labelMn(true)

if low < L
updateIdmHigh()

updateTopBotValue()
puLow := low
puLow_ := low
puLBar := time
prevMnStrc := na
mnStrc := false
//#endregion

//#region update IDM
if high >= H
H := high
HBar := time
L_lastHH := low
idmLow := getNLastValue(arrIdmLow, 1)
idmLBar := getNLastValue(arrIdmLBar, 1)

if low <= L
L := low
LBar := time
H_lastLL := high
idmHigh := getNLastValue(arrIdmHigh, 1)
idmHBar := getNLastValue(arrIdmHBar, 1)

//#endregion

// #region structure mapping
// Check for IDM
if findIDM and isCocUp and isCocUp
if low < idmLow
if structure_type == "Choch with IDM" and idmLow == lastL
if isPrevBos
fixStrcAfterBos()
lastL := getNLastValue(arrLastL, 1)
lastLBar := getNLastValue(arrLastLBar, 1)
else
fixStrcAfterChoch()
findIDM := false
isBosUp := false
lastH := H
lastHBar := HBar
lstHlPrs := labelHL(true) //Confirm HH
lstBx_ = drawIDM(true)
if not na(lstBx_)
lstBxIdm := lstBx_
updateLastHLValue()
H_lastH := getNLastValue(arrLastH, 1)
L := low
LBar := time

if findIDM and isCocDn and isBosDn
if high > idmHigh
if structure_type == "Choch with IDM" and idmHigh == lastH
if isPrevBos
fixStrcAfterBos()
lastH := getNLastValue(arrLastH, 1)
lastHBar := getNLastValue(arrLastHBar, 1)
else
fixStrcAfterChoch()
findIDM := false
isBosDn := false
lastL := L
lastLBar := LBar
lstHlPrs := labelHL(false) //Confirm LL
updateLastHLValue()
lstBx_ = drawIDM(false)
if not na(lstBx_)
lstBxIdm := lstBx_
L_lastL := getNLastValue(arrLastL, 1)
H := high
HBar := time

//Check for ChoCh

if isCocDn and high > lastH
if structure_type == "Choch without IDM" and idmHigh == lastH and close > idmHigh
removeLastLabel(arrIdmLabel, 1)
removeLastLine(arrIdmLine, 1)
if close > lastH
[lstHlPrsIdm_,lstBx_] = drawStructure("ChoCh", true) //Confirm CocUp
lstHlPrsIdm := lstHlPrsIdm_
if not na(lstBx_)
lstBx := lstBx_
findIDM := true
isBosUp := true
isCocUp := true
isBosDn := false
isCocDn := false
isPrevBos := false
L_lastL := getNLastValue(arrLastL, 1)
TP(lastH,lastL)
else
if idmHigh == lastH
removeLastLine(arrIdmLine, 1)
sweepHL(true)


if isCocUp and low < lastL
if structure_type == "Choch without IDM" and idmLow == lastL and close < idmLow
removeLastLabel(arrIdmLabel, 1)
removeLastLine(arrIdmLine, 1)
if close < lastL
[lstHlPrsIdm_,lstBx_] = drawStructure("ChoCh", false) //Confirm CocDn
lstHlPrsIdm := lstHlPrsIdm_
if not na(lstBx_)
lstBx := lstBx_
findIDM := true
isBosUp := false
isCocUp := false
isBosDn := true
isCocDn := true
isPrevBos := false
H_lastH := getNLastValue(arrLastH, 1)
TP(lastH,lastL)
else
if idmLow == lastL
removeLastLine(arrIdmLine, 1)
sweepHL(false)
//sweepHL(false)

//Check for BoS
if not findIDM and not isBosUp and isCocUp
if high > lastH
if close > lastH
findIDM := true
isBosUp := true
isCocUp := true
isBosDn := false
isCocDn := false
isPrevBos := true
lstHlPrs := labelHL(false) //Confirm HL
[lstHlPrsIdm_,lstBx_] = drawStructure("BOS", true) //Confirm BosUp
lstHlPrsIdm := lstHlPrsIdm_
if not na(lstBx_)
lstBx := lstBx_

lastL := L
lastLBar := LBar
L_lastL := L
TP(lastH,lastL)
else
sweepHL(true)

if not findIDM and not isBosDn and isCocDn
if low < lastL
if close < lastL
findIDM := true
isBosUp := false
isCocUp := false
isBosDn := true
isCocDn := true
isPrevBos := true
lstHlPrs := labelHL(true) //Confirm LH
[lstHlPrsIdm_,lstBx_] = drawStructure("BOS", false) //Confirm BosDn
lstHlPrsIdm := lstHlPrsIdm_
if not na(lstBx_)
lstBx := lstBx_

lastH := H
lastHBar := HBar
H_lastH := H
TP(lastH,lastL)
else
sweepHL(false)

//#endregion

//#trigger update High and Low
if high > lastH
lastH := high
lastHBar := time

if low < lastL
lastL := low
lastLBar := time

//#endregion
if showPOI
if not isSweepOBS
high_MOBS := high[3]
low_MOBS := low[3]
current_OBS := time[3]
if high_MOBS > high[4] and high_MOBS > high[2]
isSweepOBS := true
else
if low_MOBS > high[1]
handleZone(supplyZone,supplyZoneIsMit, current_OBS, high_MOBS, low_MOBS, colorSupply,false)
isSweepOBS := false
else
if poi_type == "Mother Bar" and isb[2]
high_MOBS := math.max(high_MOBS,motherHigh[2])
low_MOBS := math.min(low_MOBS,motherLow[2])
current_OBS := math.min(current_OBS,motherBar)
else
high_MOBS := high[2]
low_MOBS := low[2]
current_OBS := time[2]

if not isSweepOBD
low_MOBD := low[3]
high_MOBD := high[3]
current_OBD := time[3]
if low_MOBD < low[4] and low_MOBD < low[2]
isSweepOBD := true
else
if high_MOBD < low[1]
handleZone(demandZone,demandZoneIsMit, current_OBD, high_MOBD, low_MOBD, colorDemand,true)
isSweepOBD := false
else
if poi_type == "Mother Bar" and isb[2]
high_MOBD := math.max(high_MOBD,motherHigh[2])
low_MOBD := math.min(low_MOBD,motherLow[2])
current_OBD := math.min(current_OBD,motherBar)
else
high_MOBD := high[2]
low_MOBD := low[2]
current_OBD := time[2]
//#endregion

//#region run function
barcolor(showSCOB ? scob(supplyZone, true) : na, -1)
barcolor(showSCOB ? scob(demandZone, false) : na, -1)
barcolor(showISB and isb ? colorISB : na, 0,title="InSide Bar")
barcolor(osb and isGreenBar(0) and showOSB ? colorOSB_up : na)
barcolor(osb and not isGreenBar(0) and showOSB ? colorOSB_down : na)
isAlertextidmSell = processZones(supplyZone, true,supplyZoneIsMit)
isAlertextidmBuy = processZones(demandZone, false,demandZoneIsMit)
drawLiveStrc(showSMC and findIDM, not isCocUp, colorIDM, colorIDM, IDM_TEXT,lengSMC , idm_label, idm_line)
drawLiveStrc(showSMC, not isCocUp, bull, bear, CHOCH_TEXT, lengSMC, choch_label, choch_line)
drawLiveStrc(showSMC and not findIDM, isCocUp, bull, bear, BOS_TEXT,lengSMC , bos_label, bos_line)
drawPrevStrc(showPdh, PDH_TEXT, pdh_label, pdh_line,0.0)
drawPrevStrc(showPdl, PDL_TEXT, pdl_label, pdl_line,0.0)
drawPrevStrc(showMid, MID_TEXT, mid_label, mid_line,0.0)
if isOTE
// o1 = drawPrevStrc(true, "", mid_label1, mid_line1,ote1)
// o2 = drawPrevStrc(true, "", mid_label2, mid_line2,ote2)
// linefill.new(o1,o2,oteclr)
// var arrOte = array.new_box(0)

var box bxf = na
bxf.set_right(time)
var bxty = 0
minb = math.min(bxf.get_top(),bxf.get_bottom())
maxb = math.max(bxf.get_top(),bxf.get_bottom())
if not na(bxf)
// if bxty == 0
// if high < minb
// bxty := -1
// if low > maxb
// bxty := 1
if (bxty == 1 and low < minb) or (bxty == -1 and high > maxb)
bxf.delete()
bxf := na
bxty := 0



[ot,oi1,dir] = drawPrevStrc(true, "", mid_label1, mid_line1,ote1)
[ob,_,_] = drawPrevStrc(true, "", mid_label2, mid_line2,ote2)
if not na(oi1) and (bxty == 0 ? oi1 != oi1[1] : true)//and (oi1 != oi1[1] or na(ot[1] or ot != ot[1]))
// if bxf.get_left() == oi1 and arrOte.size() > 0
// arrOte.get(0).delete()

bxf.delete()
bxf := box.new(oi1,ot,time,ob,xloc = xloc.bar_time,border_color = na,bgcolor = oteclr,text = "Golden zone",text_color = color.new(oteclr,20),text_halign = text.align_center,text_size = sizGd)
// arrOte.unshift(bxf)
// if arrOte.size() > maxOTECount
// arrOte.pop().delete()

bxty := dir ? 1 : -1

alertcondition(isAlertextidmSell,"IDM EXT Alert Supply","IDM EXT Alert Supply")
alertcondition(isAlertextidmBuy,"IDM EXT Alert Demand","IDM EXT Alert Demand")

//#endregion





//2

//indicator(" SMC LEGEND 2 ",overlay = true, max_bars_back = 5000, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500)

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Input Settings
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//----------------------------------------}
//Order Blocks
//----------------------------------------{



show_order_blocks_mtf = false
ibull_ob_css_2 = color.new(#5d606b, 25)
ibear_ob_css_2 = color.new(#5d606b, 25)
ob_type__mtf = 'All'
i_tf_ob_mtf = '240'

// mitigation_filt_mtf = input.string('Wicks', 'Mitigation Method', options = ['Touch','Wicks','Close','Average'], group = 'Order Blocks', inline = 'mob3')
mittigation_filt_mtf = 'Wicks'

overlapping_filt_mtf = true
max_obs_mtf = 4
length_extend_ob_mtf = 20
ob_extend_mtf = false
// v_filter = true
text_size_ob2 = "Medium"
text_size_ob_2 = text_size_ob2 == "Small" ? size.tiny : text_size_ob2 == "Medium" ? size.small : text_size_ob2 == "Large" ? size.normal : text_size_ob2 == "Medium2" ? size.normal : size.small
ob_text_color_2 = color.new(#787b86, 0)
volume_text_2 = false
percent_text_2 = false
show_line_ob_2 = false
line_style_ob2 = "Solid"
line_style_ob_2 = line_style_ob2 == "Solid" ? line.style_solid : line_style_ob2 == "Dashed" ? line.style_dashed : line.style_dotted



v_buy = #00dbff4d
v_sell = #e91e634d

tf_s1=i_tf_ob_mtf==''?timeframe.period:i_tf_ob_mtf
timeframe_st=not(str.contains(tf_s1,'S')) and not(str.contains(tf_s1,'D')) and not(str.contains(tf_s1,'W')) and not(str.contains(tf_s1,'M')) ? str.tonumber(tf_s1)>=60? str.tostring(str.tonumber(tf_s1)/60) +"H": tf_s1 +"M" : tf_s1

timeframe1=timeframe_st + ' : '
show_iob = ob_type__=='All' or ob_type__=='Internal' //input(true, 'Internal', inline = 'ob', group = 'Order Blocks')
show_ob = ob_type__=='All' or ob_type__=='External' //input(false, 'External', inline = 'ob', group = 'Order Blocks')
show_iob_mtf = ob_type__mtf=='All' or ob_type__mtf=='Internal' //input(true, 'Internal', inline = 'ob', group = 'Order Blocks')
show_ob_mtf = ob_type__mtf=='All' or ob_type__mtf=='External' //input(false, 'External', inline = 'ob', group = 'Order Blocks')
ob_showlast = 5//input.int(10, 'LookBack', minval = 1, inline = 'ob', group = 'Order Blocks')
iob_showlast = 5//input.int(5, 'LookBack', minval = 1, inline = 'iob', group = 'Order Blocks')
max_width_ob = 3//input.float(3, 'Max OB Width', minval = 0.1,maxval = 3, inline = 'close', group = 'Order Blocks')
max_width_ob:=max_width_ob==3?20:max_width_ob

style = 'Colored'
v_lookback= 10
ob_loockback=10
timediff=(time[1]-time[101])/100

//----------------------------------------}
//BOS and MSS
//----------------------------------------{

// Constants
color CLEAR = color.rgb(0,0,0,100)

// Inputs
showms=input(false,title="ICT Market Structure ",inline="0",group = "Market Structure")
bosColor1 = input.color(color.green , '', group="Market Structure",inline="0")
bosColor2 = input.color(color.red , '', group="Market Structure",inline="0")
ms_type =input.string("All", options=["All", "External","Internal"], title="", group="Market Structure",inline="0")
show_equal_highlow = input(false, 'Equal Highs & Lows', group = 'Market Structure',inline = 'equilibrium_zone')
eq_bear_color = input.color(#787b86 , '', group="Market Structure",inline="equilibrium_zone")
eq_bull_color = input.color(#787b86 , '', group="Market Structure",inline="equilibrium_zone")
eq_threshold = input.float(0.3, '', minval = 0, maxval = 0.5, step = 0.1, group = 'Market Structure',inline = 'equilibrium_zone')
showSwing = false // or false, depending on default behavior
swingSize = 10 // fixed swing point period
label_sizes_s = "Medium" // fixed label size: "Small", "Medium", or "Large"

label_size_buysell_s = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
label_size_buysell = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge



length_eqh = 3

//----------------------------------------}
//Fair Value Gaps (FVG
//----------------------------------------{



i_bullishfvgcolor = color.new(color.green,100)
i_bearishfvgcolor = color.new(color.green,90)
i_fillByMid = true
i_deleteonfill = true
i_textColor = color.white
i_mtf = "HTF"
i_tfos = 10
i_mtfos = 50
//----------------------------------------}
//Liquidity Levels
//----------------------------------------{


//----------------------------------------}
//Key Levels
//----------------------------------------{
var Show_4H_Levels = input.bool(defval=false, title='4H', group='Key Levels', inline='4H')
Color_4H_Levels = input.color(title='', defval=color.orange, group='Key Levels', inline='4H')
Style_4H_Levels = 'Dotted' //input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="4H")
Text_4H_Levels = true//input.bool(defval=false, title='Shorten', group='Key Levels', inline='4H')

var Show_Daily_Levels = input.bool(defval=false, title='Daily', group='Key Levels', inline='Daily')
Color_Daily_Levels = input.color(title='', defval=#08bcd4, group='Key Levels', inline='Daily')
Style_Daily_Levels ='Dotted'//input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="Daily")
Text_Daily_Levels =true //input.bool(defval=false, title='Shorten', group='Key Levels', inline='Daily')

var Show_Monday_Levels = input.bool(defval=false, title='Monday', group='Key Levels', inline='Monday')
Color_Monday_Levels = input.color(title='', defval=color.white, group='Key Levels', inline='Monday')
Style_Monday_Levels = 'Dotted' //input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="Monday")
Text_Monday_Levels =true // input.bool(defval=false, title='Shorten', group='Key Levels', inline='Monday')

var Show_Weekly_Levels = input.bool(defval=false, title='Weekly', group='Key Levels', inline='Weekly')
WeeklyColor = input.color(title='', defval=#fffcbc, group='Key Levels', inline='Weekly')
Weekly_style ='Dotted' //input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="Weekly")
WeeklyTextType =true // input.bool(defval=false, title='Shorten', group='Key Levels', inline='Weekly')

var Show_Monthly_Levels = input.bool(defval=false, title='Monthly', group='Key Levels', inline='Monthly')
MonthlyColor = input.color(title='', defval=#098c30, group='Key Levels', inline='Monthly')
Monthly_style = 'Dotted' //input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="Monthly")
MonthlyTextType = true //input.bool(defval=false, title='Shorten', group='Key Levels', inline='Monthly')

var Show_Quaterly_Levels = input.bool(defval=false, title='Quarterly', group='Key Levels', inline='Quarterly')
quarterlyColor = input.color(title='', defval=#bcffd0, group='Key Levels', inline='Quarterly')
Quaterly_style = 'Dotted'//input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="Quarterly")
QuarterlyTextType =true // input.bool(defval=false, title='Shorten', group='Key Levels', inline='Quarterly')

var Show_Yearly_Levels = input.bool(defval=false, title='Yearly', group='Key Levels', inline='Yearly')
YearlyColor = input.color(title='', defval=#ffbcdb, group='Key Levels', inline='Yearly')
Yearly_style = 'Dotted' //input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="Yearly")
YearlyTextType = true //input.bool(defval=false, title='Shorten', group='Key Levels', inline='Yearly')

labelsize = 'Small' //input.string(defval='Small', title='Text Size', options=['Small', 'Medium', 'Large'],group = "Key Levels", inline='H')

var pdhtext = Text_Daily_Levels ? 'PDH' : 'Prev Day High'
var pdltext = Text_Daily_Levels ? 'PDL' : 'Prev Day Low'
var dotext = Text_Daily_Levels ? 'DO' : 'Daily Open'
var pdmtext = Text_Daily_Levels ? 'PDM' : 'Prev Day Mid'
var pwhtext = WeeklyTextType ? 'PWH' : 'Prev Week High'
var pwltext = WeeklyTextType ? 'PWL' : 'Prev Week Low'
var wotext = WeeklyTextType ? 'WO' : 'Weekly Open'
var pwmtext = WeeklyTextType ? 'PWM' : 'Prev Week Mid'
var pmhtext = MonthlyTextType ? 'PMH' : 'Prev Month High'
var pmltext = MonthlyTextType ? 'PML' : 'Prev Month Low'
var motext = MonthlyTextType ? 'MO' : 'Monthly Open'
var pmmtext = MonthlyTextType ? 'PMM' : 'Prev Month Mid'
var pqhtext = QuarterlyTextType ? 'PQH' : 'Prev Quarter High'
var pqltext = QuarterlyTextType ? 'PQL' : 'Prev Quarter Low'
var qotext = QuarterlyTextType ? 'QO' : 'Quarterly Open'
var pqmtext = QuarterlyTextType ? 'PQM' : 'Prev Quarter Mid'
var cyhtext = YearlyTextType ? 'CYH' : 'Current Year High'
var cyltext = YearlyTextType ? 'CYL' : 'Current Year Low'
var yotext = YearlyTextType ? 'YO' : 'Yearly Open'
var cymtext = YearlyTextType ? 'CYM' : 'Current Year Mid'
var pihtext = Text_4H_Levels ? 'P-4H-H' : 'Prev 4H High'
var piltext = Text_4H_Levels ? 'P-4H-L' : 'Prev 4H Low'
var iotext = Text_4H_Levels ? '4H-O' : '4H Open'
var pimtext = Text_4H_Levels ? 'P-4H-M' : 'Prev 4H Mid'
var pmonhtext = Text_Monday_Levels ? 'MDAY-H' : 'Monday High'
var pmonltext = Text_Monday_Levels ? 'MDAY-L' : 'Monday Low'
var pmonmtext = Text_Monday_Levels ? 'MDAY-M' : 'Monday Mid'

displayStyle = 'Standard'
distanceright = 25
radistance = 250
linesize = 'Small'
linestyle = 'Solid'
var untested_monday = false

//----------------------------------------}
//Session Levels
//----------------------------------------{


var is_londonrange_enabled = input.bool(defval=false, title='London', group='Session Levels', inline='london')
var london_OC = true//input.bool(defval=true, title='O/C', group='Session Levels', inline='london')
var london_HL =true// input.bool(defval=true, title='H/L', group='Session Levels', inline='london')
var is_usrange_enabled = input.bool(defval=false, title='New York', group='Session Levels', inline='US')
var us_OC =true //input.bool(defval=true, title='O/C', group='Session Levels', inline='US')
var us_HL = true//input.bool(defval=true, title='H/L', group='Session Levels', inline='US')
var is_tokyorange_enabled = input.bool(defval=false, title='Tokyo', group='Session Levels', inline='asia')
var asia_OC = true//input.bool(defval=true, title='O/C', group='Session Levels', inline='asia')
var asia_HL = true//input.bool(defval=true, title='H/L', group='Session Levels', inline='asia')
SessionTextType = false//input.bool(defval=false, title='ShortHand', group='Sessions', inline='FXColor')

Londont = "0800-1600"
USt = "1400-2100"
Asiat = "0000-0900"

LondonColor = input.color(title='', defval=color.rgb(15, 13, 13), group='Session Levels', inline='london')
USColor = input.color(title='', defval=color.rgb(190, 8, 236), group='Session Levels', inline='US')
AsiaColor = input.color(title='', defval=color.rgb(33, 5, 241), group='Session Levels', inline='asia')

Short_text_London = true//input.bool(defval=false, title='Shorten', group='Session Levels', inline='london')
Short_text_NY =true// input.bool(defval=false, title='Shorten', group='Session Levels', inline='US')
Short_text_TKY = true//input.bool(defval=false, title='Shorten', group='Session Levels', inline='asia')

var London_high_text = Short_text_London ? 'Lon-H' : 'London High'
var London_low_text = Short_text_London ? 'Lon-L' : 'London Low'
var London_open_text = Short_text_London ? 'Lon-O' : 'London Open'

var NY_high_text = Short_text_NY ? 'NY-H' : 'New York High'
var NY_low_text = Short_text_NY ? 'NY-L' : 'New York Low'
var NY_open_text = Short_text_NY ? 'NY-O' : 'New York Open'

var Tokyo_high_text = Short_text_TKY ? 'TK-H' : 'Tokyo High'
var Tokyo_low_text = Short_text_TKY ? 'TK-L' : 'Tokyo Low'
var Tokyo_open_text = Short_text_TKY ? 'TK-O' : 'Tokyo Open'


//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
color transparent = #ffffff00
length = 50
is_newbar(res) =>
t = time(res)
not na(t) and (na(t[1]) or t > t[1])

Show_MS(x, y, txt, css, dashed, down, lbl_size)=>
label.new(int(math.avg(x, bar_index)), y, txt, color = transparent, textcolor = css, style = down ? label.style_label_down : label.style_label_up, size = lbl_size)
line.new(x, y, bar_index, y, color = css, style = dashed ? line.style_dashed : line.style_solid)

f_barssince(_cond, _count) =>
_barssince = bar_index - ta.valuewhen(_cond, bar_index, _count)
_barssince

//Swings detection/measurements
calculate_swing_points(length)=>
var prev = 0
prev := high[length] > ta.highest(length) ? 0 : low[length] < ta.lowest(length) ? 1 : prev[1]
t = prev == 0 and prev[1] != 0 ? high[length] : 0
b = prev == 1 and prev[1] != 1 ? low[length] : 0
[t, b]

var t_MS = 0, var int_t_MS = 0
var internal_y_up = 0., var internal_x_up = 0, var internal_y_dn = 0., var internal_x_dn = 0
var y_up = 0., var x_up = 0 , var y_dn = 0., var x_dn = 0
var crossed_up = true, var crossed_down = true
var internal_up_broke = true, var internal_dn_broke = true
var up_trailing = high, var down_trailing = low
var up_trailing_x = 0, var down_trailing_x = 0
var high_text = '', var low_text = ''
bullish_OB_Break = false
bearish_OB_Break = false


//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Market Structure
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



bosConfType = 'Candle High'//input.string('Candle Close', 'BOS Confirmation', ['Candle Close', 'Wicks'], tooltip='Choose whether candle close/wick above previous swing point counts as a BOS.')
MSS = true//input.bool(false, 'Show MSS', tooltip='Renames the first counter t_MS BOS to MSS' )
// showSwing = false//input.bool(true, 'Show Swing Points', tooltip='Show or hide HH, LH, HL, LL')

// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
pivot_high_found = ta.pivothigh(high, swingSize, swingSize)
pivot_low_found = ta.pivotlow(low, swingSize, swingSize)



var float prevHigh_s = na,var float prevLow_s = na,var int prevHighIndex_s = na,var int prevLowIndex_s = na
bool higher_highs = false, bool lower_highs = false, bool higher_lows = false, bool lower_lows = false

var int prevSwing_s = 0

if not na(pivot_high_found)
if pivot_high_found >= prevHigh_s
higher_highs := true
prevSwing_s := 2
else
lower_highs := true
prevSwing_s := 1
prevHigh_s := pivot_high_found
prevHighIndex_s := bar_index - swingSize


if not na(pivot_low_found)
if pivot_low_found >= prevLow_s
higher_lows := true
prevSwing_s := -1
else
lower_lows := true
prevSwing_s := -2
prevLow_s := pivot_low_found
prevLowIndex_s := bar_index - swingSize




//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Fair Value Gaps
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// }

// ———————————————————— Global data {
//Using current bar data for HTF highs and lows instead of security to prevent future leaking
var htfH = open
var htfL = open

if close > htfH
htfH:= close
if close < htfL
htfL := close


//Security Data, used for HTF Bar Data reference


sClose = request.security(ticker.standard(syminfo.tickerid), i_tf, close[1], barmerge.gaps_off, barmerge.lookahead_on)
sHighP2 = request.security(ticker.standard(syminfo.tickerid), i_tf, high[2], barmerge.gaps_off, barmerge.lookahead_on)
sLowP2 = request.security(ticker.standard(syminfo.tickerid), i_tf, low[2], barmerge.gaps_off, barmerge.lookahead_on)
sOpen = request.security(ticker.standard(syminfo.tickerid), i_tf, open[1], barmerge.gaps_off, barmerge.lookahead_on)
sBar = request.security(ticker.standard(syminfo.tickerid), i_tf, bar_index, barmerge.gaps_off, barmerge.lookahead_on)

// }

//var keyword can be used to hold data in memory, with pinescript all data is lost including variables unless the var keyword is used to preserve this data
var bullishgapholder = array.new_box(0)
var bearishgapholder = array.new_box(0)

var bullishgapholder_fill = array.new_box(0)
var bearishgapholder_fill = array.new_box(0)

var bullish_high_holder = array.new_line(0)
var bearish_high_holder = array.new_line(0)
var bullish_low_holder = array.new_line(0)
var bearish_low_holder = array.new_line(0)
var bullishmidholder = array.new_line(0)
var bearishmidholder = array.new_line(0)
var bullishlabelholder = array.new_label(0)
var bearishlabelholder = array.new_label(0)
var transparentcolor = color.new(color.white,100)

var fvg_apper=false
var fvg_break=false


fvg_apper:=false
fvg_break:=false
// ———————————————————— Functions {

//function paramaters best declared with '_' this helps defer from variables in the function scope declaration and elsewhere e.g. close => _close
create_fvg_func(_upperlimit,_lowerlimit,_midlimit,_bar,_boxholder,_boxholder_fill,_midholder,_highholder,_lowholder,_labelholder,_boxcolor,_mtfboxcolor, _htf)=>
timeholder = str.tostring(i_tf)
offset = i_mtfos
boxbgcolor = _mtfboxcolor
bg_color = color.new(_mtfboxcolor,90)
if _htf == false
timeholder := str.tostring(timeframe.period)
offset := i_tfos
boxbgcolor := _boxcolor
array.push(_boxholder,box.new(_bar,_upperlimit,_bar+(timediff)*length_extend,_lowerlimit,border_color=fvg_color_fill? bg_color : na,bgcolor = fvg_color_fill? bg_color : na, extend = fvg_extend ? extend.right:extend.none,xloc = xloc.bar_time,text='',text_color=#787b86,text_halign=text.align_right,text_size=size.small))
array.push(_boxholder_fill,box.new(_bar,_upperlimit,_bar+(timediff)*length_extend,_lowerlimit,border_color=fvg_color_fill? bg_color : na ,bgcolor = fvg_color_fill? bg_color : na, extend = fvg_extend ? extend.right:extend.none,xloc = xloc.bar_time))
array.push(_midholder,line.new(_bar,(_lowerlimit+_upperlimit)/2.0,_bar+(timediff)*length_extend,_midlimit,color = i_midPointColor, extend = fvg_extend ? extend.right:extend.none,style=lineStyle(mid_style),width=1,xloc = xloc.bar_time))
array.push(_lowholder,line.new(_bar,_lowerlimit,_bar+(timediff)*length_extend,_lowerlimit,color = i_fillByMid?boxbgcolor:na, extend = fvg_extend ? extend.right:extend.none,width=1,xloc = xloc.bar_time))
array.push(_highholder,line.new(_bar,_upperlimit,_bar+(timediff)*length_extend,_upperlimit,color = i_fillByMid?boxbgcolor:na, extend = fvg_extend ? extend.right:extend.none,width=1,xloc = xloc.bar_time))


//checks for gap between current candle and 2 previous candle e.g. low of current candle and high of the candle before last, this is the fa

免責事項

この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。