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

31 KiB

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

))

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

))

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

))

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

))

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

))

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 --------------------------------------------------