ICT Killzones + Pivots [TFO] By tradeforopp

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #238554 quote
    slimanbslimanb
    Participant
    New

    Pine Script™ indicator
    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=5
    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) =>
    result = switch _style
    ‘Solid’ => line.style_solid
    ‘Dotted’ => line.style_dotted
    ‘Dashed’ => line.style_dashed
    result

    get_size(x) =>
    result = switch x
    ‘Auto’ => size.auto
    ‘Tiny’ => size.tiny
    ‘Small’ => size.small
    ‘Normal’ => size.normal
    ‘Large’ => size.large
    ‘Huge’ => size.huge

    get_table_pos(pos) =>
    result = switch pos
    “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 ————————————————–
    var g_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(true, “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(“1200-1201”, “”, inline = “CO”, group = g_SETTINGS)

    var g_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)
    box_transparency = input.int(70, “Box Transparency”, 0, 100, group = g_KZ)
    text_transparency = input.int(50, “Text Transparency”, 0, 100, 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)

    var g_LABELS = “Killzone Pivots”
    show_pivots = input.bool(true, “Show Pivots”, inline = “PV”, group = g_LABELS)
    use_alerts = input.bool(false, “Alert Broken Pivots”, inline = “PV”, group = g_LABELS)
    show_labels = input.bool(true, “Show Pivot Labels”, inline = “LB”, group = g_LABELS)
    show_midpoints = input.bool(false, “Show Pivot Midpoints”, 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)

    var g_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))

    var g_DWM = “Day – Week – Month”
    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)
    sep_unlimited = input.bool(true, “Unlimited”, tooltip = “Unlimited will show as many of the selected lines as possible. Otherwise, the session drawing limit will be used”, 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)

    var g_OPEN = “Opening Prices”
    open_unlimited = input.bool(true, “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(true, “”, 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)

    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)

    var g_VERTICAL = “Timestamps”
    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(true, “”, 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 ————————————————–
    type kz
    string _title

    box[] _box

    line[] _hi_line
    line[] _md_line
    line[] _lo_line

    label[] _hi_label
    label[] _lo_label

    bool[] _hi_valid
    bool[] _md_valid
    bool[] _lo_valid

    float[] _range_store
    float _range_current

    type hz
    line[] LN
    label[] LB
    bool[] CO

    type dwm_hl
    line[] hi_line
    line[] lo_line
    label[] hi_label
    label[] lo_label

    type dwm_info
    string tf
    float o = na
    float h = na
    float l = na
    float ph = na
    float pl = na

    var as_kz = 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())
    var lo_kz = 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())
    var na_kz = 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())
    var nl_kz = 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())
    var np_kz = 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())

    var hz_1 = hz.new(array.new_line(), array.new_label(), array.new_bool())
    var hz_2 = hz.new(array.new_line(), array.new_label(), array.new_bool())
    var hz_3 = hz.new(array.new_line(), array.new_label(), array.new_bool())
    var hz_4 = hz.new(array.new_line(), array.new_label(), array.new_bool())

    var d_hl = dwm_hl.new(array.new_line(), array.new_line(), array.new_label(), array.new_label())
    var w_hl = dwm_hl.new(array.new_line(), array.new_line(), array.new_label(), array.new_label())
    var m_hl = dwm_hl.new(array.new_line(), array.new_line(), array.new_label(), array.new_label())

    var d_info = dwm_info.new(“D”)
    var w_info = dwm_info.new(“W”)
    var m_info = dwm_info.new(“M”)

    t_as = not na(time(“”, asia, gmt_tz))
    t_lo = not na(time(“”, london, gmt_tz))
    t_na = not na(time(“”, nyam, gmt_tz))
    t_nl = not na(time(“”, nylu, gmt_tz))
    t_np = not na(time(“”, nypm, gmt_tz))
    t_co = not na(time(“”, cutoff, gmt_tz))

    t_h1 = not na(time(“”, h1, gmt_tz))
    t_h2 = not na(time(“”, h2, gmt_tz))
    t_h3 = not na(time(“”, h3, gmt_tz))
    t_h4 = not na(time(“”, h4, gmt_tz))

    t_v1 = not na(time(“”, v1, gmt_tz))
    t_v2 = not na(time(“”, v2, gmt_tz))
    t_v3 = not na(time(“”, v3, gmt_tz))
    t_v4 = not na(time(“”, v4, gmt_tz))

    var d_sep_line = array.new_line()
    var w_sep_line = array.new_line()
    var m_sep_line = array.new_line()

    var d_line = array.new_line()
    var w_line = array.new_line()
    var m_line = array.new_line()

    var d_label = array.new_label()
    var w_label = array.new_label()
    var m_label = array.new_label()

    var v1_line = array.new_line()
    var v2_line = array.new_line()
    var v3_line = array.new_line()
    var v4_line = array.new_line()

    var transparent = #ffffff00
    var ext_current = ext_which == ‘Most Recent’
    var ext_past = ext_pivots == ‘Past Mitigation’

    update_dwm_info(dwm_info n) =>
    if timeframe.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)

    if dhl or show_d_open
    update_dwm_info(d_info)
    if whl or show_w_open
    update_dwm_info(w_info)
    if mhl or show_m_open
    update_dwm_info(m_info)
    // —————————————- Variables & Constants ————————————————–

    // —————————————- Functions ————————————————–
    get_box_color(color c) =>
    result = color.new(c, box_transparency)

    get_text_color(color c) =>
    result = color.new(c, text_transparency)
    // —————————————- Functions ————————————————–

    // —————————————- Core Logic ————————————————–
    dwm_sep(string tf, bool use, line[] arr, color col) =>
    if use
    if timeframe.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))
    if not sep_unlimited and arr.size() > max_days
    arr.pop().delete()

    dwm_open(string tf, bool use, line[] lns, label[] lbls, dwm_info n, color col) =>
    if use
    if timeframe.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))
    if not sep_unlimited and lns.size() > max_days
    lns.pop().delete()
    lbls.pop().delete()
    else if lns.size() > 0
    lns.get(0).set_x2(time)
    lbls.get(0).set_x(time)

    dwm_hl(string tf, bool use, dwm_hl hl, dwm_info n, color col) =>
    if use
    if timeframe.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))
    if not sep_unlimited and hl.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()
    else if hl.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)

    dwm() =>
    if timeframe.in_seconds(“”)
    if use
    if t and not t[1]
    arr.unshift(line.new(bar_index, high*1.0001, bar_index, low, style = vl_style, width = vl_width, extend = extend.both, color = col))

    vlines() =>
    if timeframe.in_seconds(“”)
    if use
    if t and not t[1]
    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)
    if not open_unlimited and hz.LN.size() > max_days
    hz.LN.pop().delete()
    hz.LB.pop().delete()
    hz.CO.pop()
    if not t and hz.CO.size() > 0
    if not hz.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() =>
    if timeframe.in_seconds(“”)
    if k._box.size() > max_days
    k._box.pop().delete()
    if k._hi_line.size() > max_days
    k._hi_line.pop().delete()
    k._lo_line.pop().delete()
    k._hi_valid.pop()
    k._lo_valid.pop()
    if show_midpoints
    k._md_line.pop().delete()
    k._md_valid.pop()
    if k._hi_label.size() > max_days
    k._hi_label.pop().delete()
    k._lo_label.pop().delete()

    adjust_in_kz(kz kz, bool t) =>
    if t
    kz._box.get(0).set_right(time)
    kz._box.get(0).set_top(math.max(kz._box.get(0).get_top(), high))
    kz._box.get(0).set_bottom(math.min(kz._box.get(0).get_bottom(), low))

    kz._range_current := kz._box.get(0).get_top() – kz._box.get(0).get_bottom()

    if show_pivots and kz._hi_line.size() > 0
    if high > kz._hi_line.get(0).get_y1()
    kz._hi_line.get(0).set_xy1(time, high)
    kz._hi_line.get(0).set_xy2(time, high)

    if low 0
    if high > kz._hi_label.get(0).get_y()
    kz._hi_label.get(0).set_xy(time, high)
    if low
    if not t and kz._box.size() > 0
    if t[1]
    array.unshift(kz._range_store, kz._range_current)
    if kz._range_store.size() > range_avg
    kz._range_store.pop()

    if kz._box.size() > 0 and show_pivots
    for i = 0 to kz._box.size() – 1
    if not ext_current or (ext_current and i == 0)
    if ext_past ? true : (kz._hi_valid.get(i) == true)
    kz._hi_line.get(i).set_x2(time)
    if high > kz._hi_line.get(i).get_y1() and kz._hi_valid.get(i) == true
    if use_alerts and i == 0
    alert(“Broke “+kz._title+” High”, alert.freq_once_per_bar)
    kz._hi_valid.set(i, false)
    else if (use_cutoff ? t_co : false)
    kz._hi_valid.set(i, false)

    if ext_past ? true : (kz._lo_valid.get(i) == true)
    kz._lo_line.get(i).set_x2(time)
    if low
    if timeframe.in_seconds(“”)
    store = array.new_int()
    if as_kz._range_store.size() > 0
    store.push(as_kz._range_store.size())
    if lo_kz._range_store.size() > 0
    store.push(lo_kz._range_store.size())
    if na_kz._range_store.size() > 0
    store.push(na_kz._range_store.size())
    if nl_kz._range_store.size() > 0
    store.push(nl_kz._range_store.size())
    if np_kz._range_store.size() > 0
    store.push(np_kz._range_store.size())
    result = store.min()

    set_table(table tbl, kz kz, int row, string txt, bool use, bool t, color col) =>
    if use
    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)
    if show_range_avg
    table.cell(tbl, 2, row, str.tostring(kz._range_store.avg()), text_size = range_size, text_color = txt_color)

    if show_range and barstate.islast
    var tbl = 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)
    if show_range_avg
    table.cell(tbl, 2, 0, “Avg (“+str.tostring(get_min_days_stored())+”)”, text_size = range_size, text_color = txt_color)

    set_table(tbl, as_kz, 1, as_txt, use_asia, t_as, as_color)
    set_table(tbl, lo_kz, 2, lo_txt, use_london, t_lo, lo_color)
    set_table(tbl, na_kz, 3, na_txt, use_nyam, t_na, na_color)
    set_table(tbl, nl_kz, 4, nl_txt, use_nylu, t_nl, nl_color)
    set_table(tbl, np_kz, 5, np_txt, use_nypm, t_np, np_color)
    // —————————————- Core Logic ————————————————–

    Pine-Script.odt
    #238830 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Hola!
    Aquí tienes el código.

    //----------------------------------------------//
    //PRC_ICT Killzones and Pivots
    //version = 0
    //10.10.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //----------------------------------------------//
    //-----INPUTS-----------------------------------//
    //----------------------------------------------//
    openAS=020000
    closeAS=060000
    openLO=080000
    closeLO=110000
    openNYam=153000
    closeNYam=170000
    openNYlch=180000
    closeNYlch=190000
    openNYpm=193000
    closeNYpm=220000
    openNY=openNYam
    closeNY=closeNYpm
    limitday=180000
    openTrueDay=060000
    
    ShowNylch=1
    
    if gettimeframe<=3600 then
    //----------------------------------------------//
    //-----ASIA Zone--------------------------------//
    //----------------------------------------------//
    once maxHighAS=high
    once minLowAS=low
    if opentime>=openAS and opentime<=closeAS then
    barAS=barAS+1
    if high>=maxHighAS then
    maxHighAS=high
    else
    maxHighAS=maxHighAS
    endif
    if low<=minLowAS then
    minLowAS=low
    else
    minLowAS=minLowAS
    endif
    endif
    if opentime=closeAS then
    drawrectangle(barindex[barAS],minLowAS,barindex,maxHighAS)coloured("blue")fillcolor("blue",30)
    drawtext("AS.H: #maxHighAS#",barindex[round(barAS/2)],maxHighAS+0.3*tr)
    drawtext("AS.L: #minLowAS#",barindex[round(barAS/2)],minLowAS-0.3*tr)
    prevLowAS=minLowAS
    prevHighAS=maxHighAS
    previdxAS=barindex
    barAS=0
    minLowAS=high*100
    maxHighAS=0
    endif
    if low crosses under prevLowAS then
    drawsegment(previdxAS,prevLowAS,barindex,prevLowAS)coloured("blue")
    prevLowAS=0
    elsif opentime=limitday and prevLowAS<>0 then
    drawsegment(previdxAS,prevLowAS,barindex,prevLowAS)coloured("blue")
    prevLowAS=0
    elsif islastbarupdate and prevLowAS<>0 then
    drawsegment(previdxAS,prevLowAS,barindex,prevLowAS)coloured("blue")
    endif
    if high crosses over prevHighAS then
    drawsegment(previdxAS,prevHighAS,barindex,prevHighAS)coloured("blue")
    prevHighAS=0
    elsif opentime=limitday and prevHighAS<>0 then
    drawsegment(previdxAS,prevHighAS,barindex,prevHighAS)coloured("blue")
    prevHighAS=0
    elsif islastbarupdate and prevHighAS<>0 then
    drawsegment(previdxAS,prevHighAS,barindex,prevHighAS)coloured("blue")
    endif
    //----------------------------------------------//
    //-----London Zone------------------------------//
    //----------------------------------------------//
    once maxHighLO=high
    once minLowLO=low
    if opentime>=openLO and opentime<=closeLO then
    barLO=barLO+1
    if high>=maxHighLO then
    maxHighLO=high
    else
    maxHighLO=maxHighLO
    endif
    if low<=minLowLO then
    minLowLO=low
    else
    minLowLO=minLowLO
    endif
    endif
    if opentime=closeLO then
    drawrectangle(barindex[barLO],minLowLO,barindex,maxHighLO)coloured("red")fillcolor("red",30)
    drawtext("LO.H: #maxHighLO#",barindex[round(barLO/2)],maxHighLO+0.3*tr)
    drawtext("LO.L: #minLowLO#",barindex[round(barLO/2)],minLowLO-0.3*tr)
    prevLowLO=minLowLO
    prevHighLO=maxHighLO
    previdxLO=barindex
    barLO=0
    minLowLO=high*100
    maxHighLO=0
    endif
    if low crosses under prevLowLO then
    drawsegment(previdxLO,prevLowLO,barindex,prevLowLO)coloured("red")
    prevLowLO=0
    elsif opentime=limitday and prevLowLO<>0 then
    drawsegment(previdxLO,prevLowLO,barindex,prevLowLO)coloured("red")
    prevLowLO=0
    elsif islastbarupdate and prevLowLO<>0 then
    drawsegment(previdxLO,prevLowLO,barindex,prevLowLO)coloured("red")
    endif
    if high crosses over prevHighLO then
    drawsegment(previdxLO,prevHighLO,barindex,prevHighLO)coloured("red")
    prevHighLO=0
    elsif opentime=limitday and prevHighLO<>0 then
    drawsegment(previdxLO,prevHighLO,barindex,prevHighLO)coloured("red")
    prevHighLO=0
    elsif islastbarupdate and prevHighLO<>0 then
    drawsegment(previdxLO,prevHighLO,barindex,prevHighLO)coloured("red")
    endif
    if ShowNylch then
    //----------------------------------------------//
    //-----New York AM------------------------------//
    //----------------------------------------------//
    once maxHighNYam=high
    once minLowNYam=low
    if opentime>=openNYam and opentime<=closeNYam then
    barNYam=barNYam+1
    if high>=maxHighNYam then
    maxHighNYam=high
    else
    maxHighNYam=maxHighNYam
    endif
    if low<=minLowNYam then
    minLowNYam=low
    else
    minLowNYam=minLowNYam
    endif
    endif
    if opentime=closeNYam then
    drawrectangle(barindex[barNYam],minLowNYam,barindex,maxHighNYam)coloured("green")fillcolor("green",30)
    drawtext("NYam.H: #maxHighNYam#",barindex[round(barNYam/2)],maxHighNYam+0.3*tr)
    drawtext("NYam.L: #minLowNYam#",barindex[round(barNYam/2)],minLowNYam-0.3*tr)
    prevLowNYam=minLowNYam
    prevHighNYam=maxHighNYam
    previdxNYam=barindex
    barNYam=0
    minLowNYam=high*100
    maxHighNYam=0
    endif
    if low crosses under prevLowNYam then
    drawsegment(previdxNYam,prevLowNYam,barindex,prevLowNYam)coloured("green")
    prevLowNYam=0
    elsif opentime=limitday and prevLowNYam<>0 then
    drawsegment(previdxNYam,prevLowNYam,barindex,prevLowNYam)coloured("green")
    prevLowNYam=0
    elsif islastbarupdate and prevLowNYam<>0 then
    drawsegment(previdxNYam,prevLowNYam,barindex,prevLowNYam)coloured("green")
    endif
    if high crosses over prevHighNYam then
    drawsegment(previdxNYam,prevHighNYam,barindex,prevHighNYam)coloured("green")
    prevHighNYam=0
    elsif opentime=limitday and prevHighNYam<>0 then
    drawsegment(previdxNYam,prevHighNYam,barindex,prevHighNYam)coloured("green")
    prevHighNYam=0
    elsif islastbarupdate and prevHighNYam<>0 then
    drawsegment(previdxNYam,prevHighNYam,barindex,prevHighNYam)coloured("green")
    endif
    //----------------------------------------------//
    //-----New York lunch Zone----------------------//
    //----------------------------------------------//
    once maxHighNYlch=high
    once minLowNYlch=low
    if opentime>=openNYlch and opentime<=closeNYlch then
    barNYlch=barNYlch+1
    if high>=maxHighNYlch then
    maxHighNYlch=high
    else
    maxHighNYlch=maxHighNYlch
    endif
    if low<=minLowNYlch then
    minLowNYlch=low
    else
    minLowNYlch=minLowNYlch
    endif
    endif
    if opentime=closeNYlch then
    drawrectangle(barindex[barNYlch],minLowNYlch,barindex,maxHighNYlch)coloured("yellow")fillcolor("yellow",30)
    prevLowNYlch=minLowNYlch
    prevHighNYlch=maxHighNYlch
    previdxNYlch=barindex
    barNYlch=0
    minLowNYlch=high*100
    maxHighNYlch=0
    endif
    //----------------------------------------------//
    //-----New York PM -----------------------------//
    //----------------------------------------------//
    once maxHighNYpm=high
    once minLowNYpm=low
    if opentime>=openNYpm and opentime<=closeNYpm then
    barNYpm=barNYpm+1
    if high>=maxHighNYpm then
    maxHighNYpm=high
    else
    maxHighNYpm=maxHighNYpm
    endif
    if low<=minLowNYpm then
    minLowNYpm=low
    else
    minLowNYpm=minLowNYpm
    endif
    endif
    if opentime=closeNYpm then
    drawrectangle(barindex[barNYpm],minLowNYpm,barindex,maxHighNYpm)coloured("purple")fillcolor("purple",30)
    drawtext("NYpm.H: #maxHighNYpm#",barindex[round(barNYpm/2)],maxHighNYpm+0.3*tr)
    drawtext("NYpm.L: #minLowNYpm#",barindex[round(barNYpm/2)],minLowNYpm-0.3*tr)
    prevLowNYpm=minLowNYpm
    prevHighNYpm=maxHighNYpm
    previdxNYpm=barindex
    barNYpm=0
    minLowNYpm=high*100
    maxHighNYpm=0
    endif
    if low crosses under prevLowNYpm then
    drawsegment(previdxNYpm,prevLowNYpm,barindex,prevLowNYpm)coloured("purple")
    prevLowNYpm=0
    elsif opentime=limitday and prevLowNYpm<>0 then
    drawsegment(previdxNYpm,prevLowNYpm,barindex,prevLowNYpm)coloured("purple")
    prevLowNYpm=0
    elsif islastbarupdate and prevLowNYpm<>0 then
    drawsegment(previdxNYpm,prevLowNYpm,barindex,prevLowNYpm)coloured("purple")
    endif
    if high crosses over prevHighNYpm then
    drawsegment(previdxNYpm,prevHighNYpm,barindex,prevHighNYpm)coloured("purple")
    prevHighNYpm=0
    elsif opentime=limitday and prevHighNYpm<>0 then
    drawsegment(previdxNYpm,prevHighNYpm,barindex,prevHighNYpm)coloured("purple")
    prevHighNYpm=0
    elsif islastbarupdate and prevHighNYpm<>0 then
    drawsegment(previdxNYpm,prevHighNYpm,barindex,prevHighNYpm)coloured("purple")
    endif
    else
    once maxHighNY=high
    once minLowNY=low
    if opentime>=openNY and opentime<=closeNY then
    barNY=barNY+1
    if high>=maxHighNY then
    maxHighNY=high
    else
    maxHighNY=maxHighNY
    endif
    if low<=minLowNY then
    minLowNY=low
    else
    minLowNY=minLowNY
    endif
    endif
    if opentime=closeNY then
    drawrectangle(barindex[barNY],minLowNY,barindex,maxHighNY)coloured("purple")fillcolor("purple",30)
    drawtext("NY.H: #maxHighNY#",barindex[round(barNY/2)],maxHighNY+0.3*tr)
    drawtext("NY.L: #minLowNY#",barindex[round(barNY/2)],minLowNY-0.3*tr)
    prevLowNY=minLowNY
    prevHighNY=maxHighNY
    previdxNY=barindex
    barNY=0
    minLowNY=high*100
    maxHighNY=0
    endif
    if low crosses under prevLowNY then
    drawsegment(previdxNY,prevLowNY,barindex,prevLowNY)coloured("purple")
    prevLowNY=0
    elsif opentime=limitday and prevLowNY<>0 then
    drawsegment(previdxNY,prevLowNY,barindex,prevLowNY)coloured("purple")
    prevLowNY=0
    elsif islastbarupdate and prevLowNY<>0 then
    drawsegment(previdxNY,prevLowNY,barindex,prevLowNY)coloured("purple")
    endif
    if high crosses over prevHighNY then
    drawsegment(previdxNY,prevHighNY,barindex,prevHighNY)coloured("purple")
    prevHighNY=0
    elsif opentime=limitday and prevHighNY<>0 then
    drawsegment(previdxNY,prevHighNY,barindex,prevHighNY)coloured("purple")
    prevHighNY=0
    elsif islastbarupdate and prevHighNY<>0 then
    drawsegment(previdxNY,prevHighNY,barindex,prevHighNY)coloured("purple")
    endif
    endif
    //----------------------------------------------//
    //-----Limit Day--------------------------------//
    //----------------------------------------------//
    if opentime=openTrueDay then
    openTD=open
    barTD=barindex
    else
    if opentime=limitday then
    drawvline(barindex)style(dottedline)
    drawsegment(barTD,openTD,barindex,openTD)style(dottedline1)
    endif
    endif
    endif
    return
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

ICT Killzones + Pivots [TFO] By tradeforopp


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
slimanb @slimanb Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván GonzálezIván González
1 year, 11 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 10/07/2024
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...