Files
ai-exchange/ICT Killzones & Pivots [TFO]_,_ICT Killzones & Pivots [TFO].md
2026-04-24 13:39:01 +08:00

1674 lines
31 KiB
Markdown

# ICT Killzones & Pivots \[TFO]","ICT Killzones & Pivots \[TFO]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeforopp
//@version=6
indicator("ICT Killzones & Pivots \[TFO]","ICT Killzones & Pivots \[TFO]",true,max\_labels\_count=500,max\_lines\_count=500,max\_boxes\_count=500)
// ---------------------------------------- Constant Functions --------------------------------------------------
get\_line\_type(\_style) =>
switch\_style
"Solid"=>line.style\_solid
"Dotted"=>line.style\_dotted
"Dashed"=>line.style\_dashed
get\_size(x) =>
switchx
"Auto"=>size.auto
"Tiny"=>size.tiny
"Small"=>size.small
"Normal"=>size.normal
"Large"=>size.large
"Huge"=>size.huge
get\_table\_pos(pos) =>
switchpos
"Bottom Center"=>position.bottom\_center
"Bottom Left"=>position.bottom\_left
"Bottom Right"=>position.bottom\_right
"Middle Center"=>position.middle\_center
"Middle Left"=>position.middle\_left
"Middle Right"=>position.middle\_right
"Top Center"=>position.top\_center
"Top Left"=>position.top\_left
"Top Right"=>position.top\_right
// ---------------------------------------- Constant Functions --------------------------------------------------
// ---------------------------------------- Inputs --------------------------------------------------
varg\_SETTINGS="Settings"
max\_days=input.int(3,"Session Drawing Limit",1,tooltip="Only this many drawings will be kept on the chart, for each selected drawing type (killzone boxes, pivot lines, open lines, etc.)",group=g\_SETTINGS)
tf\_limit=input.timeframe("30","Timeframe Limit",tooltip="Drawings will not appear on timeframes greater than or equal to this",group=g\_SETTINGS)
gmt\_tz=input.string('America/New\_York',"Timezone",options= \['America/New\_York','GMT-12','GMT-11','GMT-10','GMT-9','GMT-8','GMT-7','GMT-6','GMT-5','GMT-4','GMT-3','GMT-2','GMT-1','GMT+0','GMT+1','GMT+2','GMT+3','GMT+4','GMT+5','GMT+6','GMT+7','GMT+8','GMT+9','GMT+10','GMT+11','GMT+12','GMT+13','GMT+14'],tooltip="Note GMT is not adjusted to reflect Daylight Saving Time changes",group=g\_SETTINGS)
lbl\_size=get\_size(input.string('Normal',"Label Size",options= \['Auto','Tiny','Small','Normal','Large','Huge'],tooltip="The size of all labels",group=g\_SETTINGS))
txt\_color=input.color(color.black,"Text Color",tooltip="The color of all label and table text",group=g\_SETTINGS)
use\_cutoff=input.bool(false,"Drawing Cutoff Time",inline="CO",tooltip="When enabled, all pivots and open price lines will stop extending at this time",group=g\_SETTINGS)
cutoff=input.session("1800-1801","",inline="CO",group=g\_SETTINGS)
vartf\_limit\_is\_equal\_or\_more\_chart\_tf=timeframe.in\_seconds('') <=timeframe.in\_seconds(tf\_limit)
varg\_KZ="Killzones"
show\_kz=input.bool(true,"Show Killzone Boxes",inline="KZ",group=g\_KZ)
show\_kz\_text=input.bool(true,"Display Text",inline="KZ",group=g\_KZ)
use\_asia=input.bool(true,"",inline="ASIA",group=g\_KZ)
as\_txt=input.string("Asia","",inline="ASIA",group=g\_KZ)
asia=input.session("2000-0000","",inline="ASIA",group=g\_KZ)
as\_color=input.color(color.blue,"",inline="ASIA",group=g\_KZ)
use\_london=input.bool(true,"",inline="LONDON",group=g\_KZ)
lo\_txt=input.string("London","",inline="LONDON",group=g\_KZ)
london=input.session("0200-0500","",inline="LONDON",group=g\_KZ)
lo\_color=input.color(color.red,"",inline="LONDON",group=g\_KZ)
use\_nyam=input.bool(true,"",inline="NYAM",group=g\_KZ)
na\_txt=input.string("NY AM","",inline="NYAM",group=g\_KZ)
nyam=input.session("0930-1100","",inline="NYAM",group=g\_KZ)
na\_color=input.color(#089981,"",inline="NYAM",group=g\_KZ)
use\_nylu=input.bool(true,"",inline="NYLU",group=g\_KZ)
nl\_txt=input.string("NY Lunch","",inline="NYLU",group=g\_KZ)
nylu=input.session("1200-1300","",inline="NYLU",group=g\_KZ)
nl\_color=input.color(color.yellow,"",inline="NYLU",group=g\_KZ)
use\_nypm=input.bool(true,"",inline="NYPM",group=g\_KZ)
np\_txt=input.string("NY PM","",inline="NYPM",group=g\_KZ)
nypm=input.session("1330-1600","",inline="NYPM",group=g\_KZ)
np\_color=input.color(color.purple,"",inline="NYPM",group=g\_KZ)
box\_transparency=input.int(70,"Box Transparency",0,100,group=g\_KZ)
text\_transparency=input.int(50,"Text Transparency",0,100,group=g\_KZ)
varg\_LABELS="Killzone Pivots"
show\_pivots=input.bool(true,"Show Pivots",inline="PV",group=g\_LABELS)
use\_alerts=input.bool(true,"Alert Broken Pivots",inline="PV",tooltip="The desired killzones must be enabled at the time that an alert is created, along with the show pivots option, in order for alerts to work",group=g\_LABELS)
show\_midpoints=input.bool(false,"Show Pivot Midpoints",inline="mp",group=g\_LABELS)
stop\_midpoints=input.bool(true,"Stop Once Mitigated",inline="mp",group=g\_LABELS)
show\_labels=input.bool(true,"Show Pivot Labels",inline="LB",tooltip="Show labels denoting each killzone's high and low. Optionally choose to show the price of each level. Right side will show labels on the right-hand side of the chart until they are reached",group=g\_LABELS)
label\_price=input.bool(false,"Display Price",inline="LB",group=g\_LABELS)
label\_right=input.bool(false,"Right Side",inline="LB",group=g\_LABELS)
ext\_pivots=input.string("Until Mitigated","Extend Pivots...",options= \['Until Mitigated','Past Mitigation'],group=g\_LABELS)
ext\_which=input.string("Most Recent","...From Which Sessions",options= \['Most Recent','All'],group=g\_LABELS)
ash\_str=input.string("AS.H","Killzone 1 Labels",inline="L\_AS",group=g\_LABELS)
asl\_str=input.string("AS.L","",inline="L\_AS",group=g\_LABELS)
loh\_str=input.string("LO.H","Killzone 2 Labels",inline="L\_LO",group=g\_LABELS)
lol\_str=input.string("LO.L","",inline="L\_LO",group=g\_LABELS)
nah\_str=input.string("NYAM.H","Killzone 3 Labels",inline="L\_NA",group=g\_LABELS)
nal\_str=input.string("NYAM.L","",inline="L\_NA",group=g\_LABELS)
nlh\_str=input.string("NYL.H","Killzone 4 Labels",inline="L\_NL",group=g\_LABELS)
nll\_str=input.string("NYL.L","",inline="L\_NL",group=g\_LABELS)
nph\_str=input.string("NYPM.H","Killzone 5 Labels",inline="L\_NP",group=g\_LABELS)
npl\_str=input.string("NYPM.L","",inline="L\_NP",group=g\_LABELS)
kzp\_style=get\_line\_type(input.string(defval='Solid',title="Pivot Style",options= \['Solid','Dotted','Dashed'],inline="KZP",group=g\_LABELS))
kzp\_width=input.int(1,"",inline="KZP",group=g\_LABELS)
kzm\_style=get\_line\_type(input.string(defval='Dotted',title="Midpoint Style",options= \['Solid','Dotted','Dashed'],inline="KZM",group=g\_LABELS))
kzm\_width=input.int(1,"",inline="KZM",group=g\_LABELS)
varg\_RNG="Killzone Range"
show\_range=input.bool(false,"Show Killzone Range",tooltip="Show the most recent ranges of each selected killzone, from high to low",group=g\_RNG)
show\_range\_avg=input.bool(true,"Show Average",tooltip="Show the average range of each selected killzone",group=g\_RNG)
range\_avg=input.int(5,"Average Length",0,tooltip="This many previous sessions will be used to calculate the average. If there isn't enough data on the current chart, it will use as many sessions as possible",group=g\_RNG)
range\_pos=get\_table\_pos(input.string('Top Right',"Table Position",options= \['Bottom Center','Bottom Left','Bottom Right','Middle Center','Middle Left','Middle Right','Top Center','Top Left','Top Right'],group=g\_RNG))
range\_size=get\_size(input.string('Normal',"Table Size",options= \['Auto','Tiny','Small','Normal','Large','Huge'],group=g\_RNG))
varg\_DWM="Day - Week - Month"
sep\_unlimited=input.bool(false,"Unlimited",tooltip="Unlimited will show as many of the selected lines as possible. Otherwise, the session drawing limit will be used",group=g\_DWM)
alert\_HL=input.bool(false,"Alert High/Low Break",tooltip="Alert when any selected highs and lows are traded through. The desired timeframe's high/low option must be enabled at the time that an alert is created",group=g\_DWM)
show\_d\_open=input.bool(false,"D Open",inline="DO",group=g\_DWM)
dhl=input.bool(false,"High/Low",inline="DO",tooltip="",group=g\_DWM)
ds=input.bool(false,"Separators",inline="DO",tooltip="Mark where a new day begins",group=g\_DWM)
d\_color=input.color(color.blue,"",inline="DO",group=g\_DWM)
show\_w\_open=input.bool(false,"W Open",inline="WO",group=g\_DWM)
whl=input.bool(false,"High/Low",inline="WO",tooltip="",group=g\_DWM)
ws=input.bool(false,"Separators",inline="WO",tooltip="Mark where a new week begins",group=g\_DWM)
w\_color=input.color(#089981,"",inline="WO",group=g\_DWM)
show\_m\_open=input.bool(false,"M Open",inline="MO",group=g\_DWM)
mhl=input.bool(false,"High/Low",inline="MO",tooltip="",group=g\_DWM)
ms=input.bool(false,"Separators",inline="MO",tooltip="Mark where a new month begins",group=g\_DWM)
m\_color=input.color(color.red,"",inline="MO",group=g\_DWM)
htf\_style=get\_line\_type(input.string(defval='Solid',title="Style",options= \['Solid','Dotted','Dashed'],inline="D0",group=g\_DWM))
htf\_width=input.int(1,"",inline="D0",group=g\_DWM)
dow\_labels=input.bool(true,"Day of Week Labels",inline="DOW",group=g\_DWM)
dow\_yloc=input.string('Bottom',"",options= \['Top','Bottom'],inline="DOW",group=g\_DWM)
dow\_xloc=input.string('Midnight',"",options= \['Midnight','Midday'],inline="DOW",group=g\_DWM)
dow\_hide\_wknd=input.bool(true,"Hide Weekend Labels",group=g\_DWM)
varg\_OPEN="Opening Prices"
open\_unlimited=input.bool(false,"Unlimited",tooltip="Unlimited will show as many of the selected lines as possible. Otherwise, the session drawing limit will be used",group=g\_OPEN)
use\_h1=input.bool(false,"",inline="H1",group=g\_OPEN)
h1\_text=input.string("True Day Open","",inline="H1",group=g\_OPEN)
h1=input.session("0000-0001","",inline="H1",group=g\_OPEN)
h1\_color=input.color(color.black,"",inline="H1",group=g\_OPEN)
use\_h2=input.bool(false,"",inline="H2",group=g\_OPEN)
h2\_text=input.string("06:00","",inline="H2",group=g\_OPEN)
h2=input.session("0600-0601","",inline="H2",group=g\_OPEN)
h2\_color=input.color(color.black,"",inline="H2",group=g\_OPEN)
use\_h3=input.bool(false,"",inline="H3",group=g\_OPEN)
h3\_text=input.string("10:00","",inline="H3",group=g\_OPEN)
h3=input.session("1000-1001","",inline="H3",group=g\_OPEN)
h3\_color=input.color(color.black,"",inline="H3",group=g\_OPEN)
use\_h4=input.bool(false,"",inline="H4",group=g\_OPEN)
h4\_text=input.string("14:00","",inline="H4",group=g\_OPEN)
h4=input.session("1400-1401","",inline="H4",group=g\_OPEN)
h4\_color=input.color(color.black,"",inline="H4",group=g\_OPEN)
use\_h5=input.bool(false,"",inline="H5",group=g\_OPEN)
h5\_text=input.string("00:00","",inline="H5",group=g\_OPEN)
h5=input.session("0000-0001","",inline="H5",group=g\_OPEN)
h5\_color=input.color(color.black,"",inline="H5",group=g\_OPEN)
use\_h6=input.bool(false,"",inline="H6",group=g\_OPEN)
h6\_text=input.string("00:00","",inline="H6",group=g\_OPEN)
h6=input.session("0000-0001","",inline="H6",group=g\_OPEN)
h6\_color=input.color(color.black,"",inline="H6",group=g\_OPEN)
use\_h7=input.bool(false,"",inline="H7",group=g\_OPEN)
h7\_text=input.string("00:00","",inline="H7",group=g\_OPEN)
h7=input.session("0000-0001","",inline="H7",group=g\_OPEN)
h7\_color=input.color(color.black,"",inline="H7",group=g\_OPEN)
use\_h8=input.bool(false,"",inline="H8",group=g\_OPEN)
h8\_text=input.string("00:00","",inline="H8",group=g\_OPEN)
h8=input.session("0000-0001","",inline="H8",group=g\_OPEN)
h8\_color=input.color(color.black,"",inline="H8",group=g\_OPEN)
hz\_style=get\_line\_type(input.string(defval='Dotted',title="Style",options= \['Solid','Dotted','Dashed'],inline="H0",group=g\_OPEN))
hz\_width=input.int(1,"",inline="H0",group=g\_OPEN)
varg\_VERTICAL="Timestamps"
v\_unlimited=input.bool(false,"Unlimited",tooltip="Unlimited will show as many of the selected lines as possible. Otherwise, the session drawing limit will be used",group=g\_VERTICAL)
use\_v1=input.bool(false,"",inline="V1",group=g\_VERTICAL)
v1=input.session("0000-0001","",inline="V1",group=g\_VERTICAL)
v1\_color=input.color(color.black,"",inline="V1",group=g\_VERTICAL)
use\_v2=input.bool(false,"",inline="V2",group=g\_VERTICAL)
v2=input.session("0800-0801","",inline="V2",group=g\_VERTICAL)
v2\_color=input.color(color.black,"",inline="V2",group=g\_VERTICAL)
use\_v3=input.bool(false,"",inline="V3",group=g\_VERTICAL)
v3=input.session("1000-1001","",inline="V3",group=g\_VERTICAL)
v3\_color=input.color(color.black,"",inline="V3",group=g\_VERTICAL)
use\_v4=input.bool(false,"",inline="V4",group=g\_VERTICAL)
v4=input.session("1200-1201","",inline="V4",group=g\_VERTICAL)
v4\_color=input.color(color.black,"",inline="V4",group=g\_VERTICAL)
vl\_style=get\_line\_type(input.string(defval='Dotted',title="Style",options= \['Solid','Dotted','Dashed'],inline="V0",group=g\_VERTICAL))
vl\_width=input.int(1,"",inline="V0",group=g\_VERTICAL)
// ---------------------------------------- Inputs --------------------------------------------------
// ---------------------------------------- Variables & Constants --------------------------------------------------
typekz
string\_title
array\<box> \_box
array\<line> \_hi\_line
array\<line> \_md\_line
array\<line> \_lo\_line
array\<label> \_hi\_label
array\<label> \_lo\_label
array\<bool> \_hi\_valid
array\<bool> \_md\_valid
array\<bool> \_lo\_valid
array\<float> \_range\_store
float\_range\_current
typehz
array\<line> LN
array\<label> LB
array\<bool> CO
typedwm\_hl
array\<line> hi\_line
array\<line> lo\_line
array\<label> hi\_label
array\<label> lo\_label
boolhit\_high=false
boolhit\_low=false
typedwm\_info
stringtf
floato=na
floath=na
floatl=na
floatph=na
floatpl=na
typelines\_helper
hz\_hz
stringh
stringh\_text
colorh\_color
initLines() =>
array\<lines\_helper> res=array.new\<lines\_helper>()
ifuse\_h1
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h1,h1\_text,h1\_color))
ifuse\_h2
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h2,h2\_text,h2\_color))
ifuse\_h3
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h3,h3\_text,h3\_color))
ifuse\_h4
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h4,h4\_text,h4\_color))
ifuse\_h5
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h5,h5\_text,h5\_color))
ifuse\_h6
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h6,h6\_text,h6\_color))
ifuse\_h7
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h7,h7\_text,h7\_color))
ifuse\_h8
res.push(lines\_helper.new(hz.new(array.new\_line(),array.new\_label(),array.new\_bool()),h8,h8\_text,h8\_color))
res
vararray\<lines\_helper> lines=initLines()
typekz\_helper
kz\_kz
stringsession
colorc
stringbox\_txt
stringhi\_txt
stringlo\_txt
initKZ() =>
array\<kz\_helper> res=array.new\<kz\_helper>()
ifuse\_asia
res.push(kz\_helper.new(
kz.new(as\_txt,array.new\_box(),array.new\_line(),array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label(),array.new\_bool(),array.new\_bool(),array.new\_bool(),array.new\_float()),
asia,as\_color,as\_txt,ash\_str,asl\_str
&#x20;))
ifuse\_london
res.push(kz\_helper.new(
kz.new(lo\_txt,array.new\_box(),array.new\_line(),array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label(),array.new\_bool(),array.new\_bool(),array.new\_bool(),array.new\_float()),
london,lo\_color,lo\_txt,loh\_str,lol\_str
&#x20;))
ifuse\_nyam
res.push(kz\_helper.new(
kz.new(na\_txt,array.new\_box(),array.new\_line(),array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label(),array.new\_bool(),array.new\_bool(),array.new\_bool(),array.new\_float()),
nyam,na\_color,na\_txt,nah\_str,nal\_str
&#x20;))
ifuse\_nylu
res.push(kz\_helper.new(
kz.new(nl\_txt,array.new\_box(),array.new\_line(),array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label(),array.new\_bool(),array.new\_bool(),array.new\_bool(),array.new\_float()),
nylu,nl\_color,nl\_txt,nlh\_str,nll\_str
&#x20;))
ifuse\_nypm
res.push(kz\_helper.new(
kz.new(np\_txt,array.new\_box(),array.new\_line(),array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label(),array.new\_bool(),array.new\_bool(),array.new\_bool(),array.new\_float()),
nypm,np\_color,np\_txt,nph\_str,npl\_str
&#x20;))
res
vararray\<kz\_helper> \_kz=initKZ()
vard\_hl=dwm\_hl.new(array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label())
varw\_hl=dwm\_hl.new(array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label())
varm\_hl=dwm\_hl.new(array.new\_line(),array.new\_line(),array.new\_label(),array.new\_label())
vard\_info=dwm\_info.new("D")
varw\_info=dwm\_info.new("W")
varm\_info=dwm\_info.new("M")
t\_co=notna(time("",cutoff,gmt\_tz))
typets\_helper
stringsession
array\<line> lines
colorc
initTS() =>
array\<ts\_helper> res=array.new\<ts\_helper>()
ifuse\_v1
res.push(ts\_helper.new(v1,array.new\_line(),v1\_color))
ifuse\_v2
res.push(ts\_helper.new(v2,array.new\_line(),v2\_color))
ifuse\_v3
res.push(ts\_helper.new(v3,array.new\_line(),v3\_color))
ifuse\_v4
res.push(ts\_helper.new(v4,array.new\_line(),v4\_color))
res
vararray\<ts\_helper> ts\_data=initTS()
vard\_sep\_line=array.new\_line()
varw\_sep\_line=array.new\_line()
varm\_sep\_line=array.new\_line()
vard\_line=array.new\_line()
varw\_line=array.new\_line()
varm\_line=array.new\_line()
vard\_label=array.new\_label()
varw\_label=array.new\_label()
varm\_label=array.new\_label()
vartransparent=#ffffff00
varext\_current=ext\_which=='Most Recent'
varext\_past=ext\_pivots=='Past Mitigation'
update\_dwm\_info(dwm\_infon) =>
iftimeframe.change(n.tf)
n.ph:=n.h
n.pl:=n.l
n.o:=open
n.h:=high
n.l:=low
else
n.h:=math.max(high,n.h)
n.l:=math.min(low,n.l)
ifdhlorshow\_d\_open
update\_dwm\_info(d\_info)
ifwhlorshow\_w\_open
update\_dwm\_info(w\_info)
ifmhlorshow\_m\_open
update\_dwm\_info(m\_info)
// ---------------------------------------- Variables & Constants --------------------------------------------------
// ---------------------------------------- Functions --------------------------------------------------
get\_box\_color(colorc) =>
color.new(c,box\_transparency)
get\_text\_color(colorc) =>
color.new(c,text\_transparency)
// ---------------------------------------- Functions --------------------------------------------------
// ---------------------------------------- Core Logic --------------------------------------------------
dwm\_sep(stringtf,booluse,array\<line> arr,colorcol) =>
ifuse
iftimeframe.change(tf)
arr.unshift(line.new(bar\_index,high\*1.0001,bar\_index,low,style=htf\_style,width=htf\_width,extend=extend.both,color=col))
ifnotsep\_unlimitedandarr.size() >max\_days
arr.pop().delete()
dwm\_open(stringtf,booluse,array\<line> lns,array\<label> lbls,dwm\_infon,colorcol) =>
ifuse
iflns.size() >0
lns.get(0).set\_x2(time)
lbls.get(0).set\_x(time)
iftimeframe.change(tf)
lns.unshift(line.new(time,n.o,time,n.o,xloc=xloc.bar\_time,style=htf\_style,width=htf\_width,color=col))
lbls.unshift(label.new(time,n.o,tf+" OPEN",xloc=xloc.bar\_time,style=label.style\_label\_left,color=transparent,textcolor=txt\_color,size=lbl\_size))
ifnotsep\_unlimitedandlns.size() >max\_days
lns.pop().delete()
lbls.pop().delete()
dwm\_hl(stringtf,booluse,dwm\_hlhl,dwm\_infon,colorcol) =>
ifuse
ifhl.hi\_line.size() >0
hl.hi\_line.get(0).set\_x2(time)
hl.lo\_line.get(0).set\_x2(time)
hl.hi\_label.get(0).set\_x(time)
hl.lo\_label.get(0).set\_x(time)
iftimeframe.change(tf)
hl.hi\_line.unshift(line.new(time,n.ph,time,n.ph,xloc=xloc.bar\_time,style=htf\_style,width=htf\_width,color=col))
hl.lo\_line.unshift(line.new(time,n.pl,time,n.pl,xloc=xloc.bar\_time,style=htf\_style,width=htf\_width,color=col))
hl.hi\_label.unshift(label.new(time,n.ph,"P"+tf+"H",xloc=xloc.bar\_time,style=label.style\_label\_left,color=transparent,textcolor=txt\_color,size=lbl\_size))
hl.lo\_label.unshift(label.new(time,n.pl,"P"+tf+"L",xloc=xloc.bar\_time,style=label.style\_label\_left,color=transparent,textcolor=txt\_color,size=lbl\_size))
hl.hit\_high:=false
hl.hit\_low:=false
ifnotsep\_unlimitedandhl.hi\_line.size() >max\_days
hl.hi\_line.pop().delete()
hl.lo\_line.pop().delete()
hl.hi\_label.pop().delete()
hl.lo\_label.pop().delete()
ifhl.hi\_line.size() >0andalert\_HL
ifnothl.hit\_highandhigh>hl.hi\_line.get(0).get\_y1()
hl.hit\_high:=true
alert(str.format("Hit P{0}H",tf))
ifnothl.hit\_lowandlow\<hl.lo\_line.get(0).get\_y1()
hl.hit\_low:=true
alert(str.format("Hit P{0}L",tf))
dwm() =>
iftf\_limit\_is\_equal\_or\_more\_chart\_tf
// DWM - Separators
dwm\_sep("D",ds,d\_sep\_line,d\_color)
dwm\_sep("W",ws,w\_sep\_line,w\_color)
dwm\_sep("M",ms,m\_sep\_line,m\_color)
// DWM - Open Lines
dwm\_open("D",show\_d\_open,d\_line,d\_label,d\_info,d\_color)
dwm\_open("W",show\_w\_open,w\_line,w\_label,w\_info,w\_color)
dwm\_open("M",show\_m\_open,m\_line,m\_label,m\_info,m\_color)
// DWM - Highs and Lows
dwm\_hl("D",dhl,d\_hl,d\_info,d\_color)
dwm\_hl("W",whl,w\_hl,w\_info,w\_color)
dwm\_hl("M",mhl,m\_hl,m\_info,m\_color)
methodvline(ts\_helperthis) =>
boolt=notna(time("",this.session,gmt\_tz))
boolt\_prev=notna(time("",this.session,gmt\_tz,bars\_back=1))
array\<line> arr=this.lines
colorcol=this.c
iftandnott\_prev
arr.unshift(line.new(bar\_index,high\*1.0001,bar\_index,low,style=vl\_style,width=vl\_width,extend=extend.both,color=col))
ifnotv\_unlimited
ifarr.size() >max\_days
arr.pop().delete()
vlines() =>
iftf\_limit\_is\_equal\_or\_more\_chart\_tf
for \[\_,value] ints\_data
vline(value)
methodhz\_line(lines\_helperthis) =>
boolt=notna(time("",this.h,gmt\_tz))
boolt\_prev=notna(time("",this.h,gmt\_tz,bars\_back=1))
hzhz=this.\_hz
stringtxt=this.h\_text
colorcol=this.h\_color
iftandnott\_prev
hz.LN.unshift(line.new(bar\_index,open,bar\_index,open,style=hz\_style,width=hz\_width,color=col))
hz.LB.unshift(label.new(bar\_index,open,txt,style=label.style\_label\_left,color=transparent,textcolor=txt\_color,size=lbl\_size))
array.unshift(hz.CO,false)
ifnotopen\_unlimitedandhz.LN.size() >max\_days
hz.LN.pop().delete()
hz.LB.pop().delete()
hz.CO.pop()
ifnottandhz.CO.size() >0
ifnothz.CO.get(0)
hz.LN.get(0).set\_x2(bar\_index)
hz.LB.get(0).set\_x(bar\_index)
if (use\_cutoff?t\_co:false)
hz.CO.set(0,true)
hz\_lines() =>
iftf\_limit\_is\_equal\_or\_more\_chart\_tf
for \[\_,value] inlines
hz\_line(value)
del\_kz(kzk) =>
ifk.\_box.size() >max\_days
k.\_box.pop().delete()
ifk.\_hi\_line.size() >max\_days
k.\_hi\_line.pop().delete()
k.\_lo\_line.pop().delete()
k.\_hi\_valid.pop()
k.\_lo\_valid.pop()
ifshow\_midpoints
k.\_md\_line.pop().delete()
k.\_md\_valid.pop()
ifk.\_hi\_label.size() >max\_days
k.\_hi\_label.pop().delete()
k.\_lo\_label.pop().delete()
update\_price\_string(labelL,floatP) =>
S=L.get\_text()
pre=str.substring(S,0,str.pos(S," "))
str.trim(pre)
L.set\_text(str.format("{0} ({1})",pre,P))
adjust\_in\_kz(kzkz,boolt) =>
ift
kzBox0=kz.\_box.get(0)
kzBox0.set\_right(time)
newTop=math.max(kzBox0.get\_top(),high)
kzBox0.set\_top(newTop)
newBottom=math.min(kzBox0.get\_bottom(),low)
kzBox0.set\_bottom(newBottom)
kz.\_range\_current:=newTop-newBottom
ifshow\_pivotsandkz.\_hi\_line.size() >0
kzHiLine0=kz.\_hi\_line.get(0)
kzHiLine0.set\_x2(time)
ifhigh>kzHiLine0.get\_y1()
kzHiLine0.set\_xy1(time,high)
kzHiLine0.set\_xy2(time,high)
kzLoLine0=kz.\_lo\_line.get(0)
kzLoLine0.set\_x2(time)
iflow\<kzLoLine0.get\_y1()
kzLoLine0.set\_xy1(time,low)
kzLoLine0.set\_xy2(time,low)
ifshow\_midpoints
kzMidLine0=kz.\_md\_line.get(0)
kzMidLine0.set\_x2(time)
kzMidLine0.set\_xy1(time,math.avg(kzHiLine0.get\_y2(),kzLoLine0.get\_y2()))
kzMidLine0.set\_xy2(time,math.avg(kzHiLine0.get\_y2(),kzLoLine0.get\_y2()))
ifshow\_labelsandkz.\_hi\_label.size() >0
iflabel\_right
kz.\_hi\_label.get(0).set\_x(time)
kz.\_lo\_label.get(0).set\_x(time)
ifhigh>kz.\_hi\_label.get(0).get\_y()
kz.\_hi\_label.get(0).set\_xy(time,high)
iflabel\_price
update\_price\_string(kz.\_hi\_label.get(0),high)
iflow\<kz.\_lo\_label.get(0).get\_y()
kz.\_lo\_label.get(0).set\_xy(time,low)
iflabel\_price
update\_price\_string(kz.\_lo\_label.get(0),low)
adjust\_out\_kz(kzkz,boolt,boolt\_prev) =>
boxCount=kz.\_box.size()
ifnottandboxCount>0
ift\_prev
array.unshift(kz.\_range\_store,kz.\_range\_current)
ifkz.\_range\_store.size() >range\_avg
kz.\_range\_store.pop()
ifshow\_pivotsandboxCount>0
fori=0toboxCount-1by1
ifnotext\_currentori==0
kzHiValid=kz.\_hi\_valid.get(i)
ifext\_pastorkzHiValid
kz.\_hi\_line.get(i).set\_x2(time)
ifshow\_labelsandlabel\_right
kz.\_hi\_label.get(i).set\_x(time)
ifkzHiValidandhigh>kz.\_hi\_line.get(i).get\_y1()
ifuse\_alertsandi==0
alert('Broke '+kz.\_title+' High',alert.freq\_once\_per\_bar)
kz.\_hi\_valid.set(i,false)
ifshow\_labelsandlabel\_right
kz.\_hi\_label.get(i).set\_style(label.style\_label\_down)
elseifuse\_cutoff?t\_co:false
kz.\_hi\_valid.set(i,false)
kzLoValid=kz.\_lo\_valid.get(i)
ifext\_pastorkzLoValid
kz.\_lo\_line.get(i).set\_x2(time)
ifshow\_labelsandlabel\_right
kz.\_lo\_label.get(i).set\_x(time)
ifkzLoValidandlow\<kz.\_lo\_line.get(i).get\_y1()
ifuse\_alertsandi==0
alert("Broke "+kz.\_title+" Low",alert.freq\_once\_per\_bar)
kz.\_lo\_valid.set(i,false)
ifshow\_labelsandlabel\_right
kz.\_lo\_label.get(i).set\_style(label.style\_label\_up)
elseifuse\_cutoff?t\_co:false
kz.\_lo\_valid.set(i,false)
ifshow\_midpointsandnott
ifstop\_midpoints?kz.\_md\_valid.get(i) :true
kz.\_md\_line.get(i).set\_x2(time)
ifkz.\_md\_valid.get(i) andlow<=kz.\_md\_line.get(i).get\_y1() andhigh>=kz.\_md\_line.get(i).get\_y1()
kz.\_md\_valid.set(i,false)
else
break
methodmanage\_kz(kz\_helperthis) =>
kzkz=this.\_kz
c=this.c
stringbox\_txt=this.box\_txt
stringhi\_txt=this.hi\_txt
stringlo\_txt=this.lo\_txt
iftf\_limit\_is\_equal\_or\_more\_chart\_tf
t=notna(time("",this.session,gmt\_tz))
t\_prev=notna(time("",this.session,gmt\_tz,bars\_back=1))
iftandnott\_prev
\_c=get\_box\_color(c)
\_t=get\_text\_color(c)
kz.\_box.unshift(box.new(time,high,time,low,xloc=xloc.bar\_time,border\_color=show\_kz?\_c:na,bgcolor=show\_kz?\_c:na,text=show\_kzandshow\_kz\_text?box\_txt:na,text\_color=\_t))
ifshow\_pivots
kz.\_hi\_line.unshift(line.new(time,high,time,high,xloc=xloc.bar\_time,style=kzp\_style,color=c,width=kzp\_width))
kz.\_lo\_line.unshift(line.new(time,low,time,low,xloc=xloc.bar\_time,style=kzp\_style,color=c,width=kzp\_width))
ifshow\_midpoints
kz.\_md\_line.unshift(line.new(time,math.avg(high,low),time,math.avg(high,low),xloc=xloc.bar\_time,style=kzm\_style,color=c,width=kzm\_width))
array.unshift(kz.\_md\_valid,true)
array.unshift(kz.\_hi\_valid,true)
array.unshift(kz.\_lo\_valid,true)
ifshow\_labels
\_hi\_txt=label\_price?str.format('{0} ({1})',hi\_txt,high) :hi\_txt
\_lo\_txt=label\_price?str.format('{0} ({1})',lo\_txt,low) :lo\_txt
iflabel\_right
kz.\_hi\_label.unshift(label.new(time,high,\_hi\_txt,xloc=xloc.bar\_time,color=transparent,textcolor=txt\_color,style=label.style\_label\_left,size=lbl\_size))
kz.\_lo\_label.unshift(label.new(time,low,\_lo\_txt,xloc=xloc.bar\_time,color=transparent,textcolor=txt\_color,style=label.style\_label\_left,size=lbl\_size))
else
kz.\_hi\_label.unshift(label.new(time,high,\_hi\_txt,xloc=xloc.bar\_time,color=transparent,textcolor=txt\_color,style=label.style\_label\_down,size=lbl\_size))
kz.\_lo\_label.unshift(label.new(time,low,\_lo\_txt,xloc=xloc.bar\_time,color=transparent,textcolor=txt\_color,style=label.style\_label\_up,size=lbl\_size))
del\_kz(kz)
adjust\_in\_kz(kz,t)
adjust\_out\_kz(kz,t,t\_prev)
for \[\_,value] in\_kz
manage\_kz(value)
dwm()
vlines()
hz\_lines()
new\_dow\_time=dow\_xloc=='Midday'?time-timeframe.in\_seconds("D") /2\*1000:time
new\_day=dayofweek(new\_dow\_time,gmt\_tz) !=dayofweek(new\_dow\_time,gmt\_tz)\[1]
vardow\_top=dow\_yloc=='Top'
varsaturday="SATURDAY"
varsunday="SUNDAY"
varmonday="MONDAY"
vartuesday="TUESDAY"
varwednesday="WEDNESDAY"
varthursday="THURSDAY"
varfriday="FRIDAY"
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==1andnew\_dayandnotdow\_hide\_wknd,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=sunday)
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==2andnew\_day,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=monday)
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==3andnew\_day,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=tuesday)
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==4andnew\_day,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=wednesday)
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==5andnew\_day,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=thursday)
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==6andnew\_day,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=friday)
plotchar(dow\_labelsandtimeframe.isintradayanddayofweek(new\_dow\_time,gmt\_tz) ==7andnew\_dayandnotdow\_hide\_wknd,location=dow\_top?location.top:location.bottom,char='',textcolor=txt\_color,text=saturday)
get\_min\_days\_stored() =>
store=array.new\_int()
for \[\_,value] in\_kz
inttmpStoreSize=value.\_kz.\_range\_store.size()
iftmpStoreSize>0
store.push(tmpStoreSize)
store.min()
methodset\_table(tabletbl,kzkz,introw,stringtxt,boolt,colorcol) =>
table.cell(tbl,0,row,txt,text\_size=range\_size,bgcolor=get\_box\_color(col),text\_color=txt\_color)
table.cell(tbl,1,row,str.tostring(kz.\_range\_current),text\_size=range\_size,bgcolor=t?get\_box\_color(col) :na,text\_color=txt\_color)
ifshow\_range\_avg
table.cell(tbl,2,row,str.tostring(kz.\_range\_store.avg()),text\_size=range\_size,text\_color=txt\_color)
ifshow\_rangeandbarstate.islast
vartbl=table.new(range\_pos,10,10,chart.bg\_color,chart.fg\_color,2,chart.fg\_color,1)
table.cell(tbl,0,0,"Killzone",text\_size=range\_size,text\_color=txt\_color)
table.cell(tbl,1,0,"Range",text\_size=range\_size,text\_color=txt\_color)
ifshow\_range\_avg
table.cell(tbl,2,0,"Avg ("+str.tostring(get\_min\_days\_stored()) +")",text\_size=range\_size,text\_color=txt\_color)
for \[index,value] in\_kz
set\_table(tbl,value.\_kz,index+1,value.box\_txt,notna(time("",value.session,gmt\_tz)),value.c)
// ---------------------------------------- Core Logic --------------------------------------------------