Session Killzones ICT - Clean

deltaterminal · study · 171 行 · 点赞 4 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// =====================================================================
//  Session Killzones ICT — Clean
//  Version: 1.0
//
//  Highlights the three main trading sessions (Asia / London / New York)
//  and the two ICT killzones most traders reference (London AM, NY AM) directly
//  on your chart, with a small top-right dashboard that tells you which
//  session and which killzone you are in right now.
//
//  Works on any intraday timeframe and any liquid asset.
//  No repainting. No lookahead. Pine v6 strict.
// =====================================================================
indicator("Session Killzones ICT — Clean", shorttitle = "Sessions KZ",
         overlay = true,
         max_boxes_count = 200, max_labels_count = 200)
 
// =============================
//  INPUTS
// =============================
grpTZ = "Timezone"
tz    = input.string("Europe/Paris", "Timezone", options = ["Europe/Paris", "Europe/London", "America/New_York", "Asia/Tokyo", "UTC"], group = grpTZ,
         tooltip = "All session times below are interpreted in this timezone. DST is handled automatically.")
 
grpSess = "Sessions"
showAsia   = input.bool(true,  "Show Asia session",   group = grpSess)
sessAsia   = input.session("0100-0900", "Asia session (HHmm-HHmm)",   group = grpSess)
colAsia    = input.color(color.new(#FFD54F, 88), "Asia colour", group = grpSess)
 
showLondon = input.bool(true,  "Show London session", group = grpSess)
sessLondon = input.session("0900-1730", "London session (HHmm-HHmm)", group = grpSess)
colLondon  = input.color(color.new(#42A5F5, 88), "London colour", group = grpSess)
 
showNY     = input.bool(true,  "Show New York session", group = grpSess)
sessNY     = input.session("1430-2300", "New York session (HHmm-HHmm)", group = grpSess)
colNY      = input.color(color.new(#66BB6A, 88), "New York colour", group = grpSess)
 
grpKZ = "ICT Killzones"
showLondonKZ = input.bool(true,  "Show London AM killzone", group = grpKZ)
sessLondonKZ = input.session("1000-1300", "London AM killzone (HHmm-HHmm)", group = grpKZ,
         tooltip = "ICT London AM window (10:00-13:00 Paris by default). A clock, not an edge: in our Gold sweep study, sweeps in this window reversed by end of day 44% of the time.")
colLondonKZ  = input.color(color.new(#1E88E5, 70), "London KZ colour", group = grpKZ)
 
showNYKZ = input.bool(true,  "Show NY AM killzone", group = grpKZ)
sessNYKZ = input.session("1530-1800", "NY AM killzone (HHmm-HHmm)", group = grpKZ,
         tooltip = "ICT NY AM window (15:30-18:00 Paris by default). A clock, not an edge: in our Gold sweep study, sweeps in this window reversed by end of day 49% of the time.")
colNYKZ  = input.color(color.new(#2E7D32, 70), "NY KZ colour", group = grpKZ)
 
drawKZBoxes = input.bool(true, "Draw killzone range boxes", group = grpKZ,
         tooltip = "Draws a box for each killzone marking its high/low range. Helps see sweeps and retests.")
 
grpUI = "Dashboard"
showDash   = input.bool(true, "Show dashboard", group = grpUI)
dashPos    = input.string("top_right", "Position", options = ["top_right", "top_left", "bottom_right", "bottom_left", "middle_right"], group = grpUI)
dashSize   = input.string("small", "Size", options = ["tiny", "small", "normal"], group = grpUI)
 
// =============================
//  SESSION HELPERS
// =============================
inSession(string spec) =>
    not na(time(timeframe.period, spec, tz))
 
asiaOn     = showAsia   and inSession(sessAsia)
londonOn   = showLondon and inSession(sessLondon)
nyOn       = showNY     and inSession(sessNY)
londonKZOn = showLondonKZ and inSession(sessLondonKZ)
nyKZOn     = showNYKZ     and inSession(sessNYKZ)
 
// =============================
//  BACKGROUND SHADING
// =============================
bgcolor(asiaOn   ? colAsia   : na, title = "Asia BG")
bgcolor(londonOn ? colLondon : na, title = "London BG")
bgcolor(nyOn     ? colNY     : na, title = "NY BG")
 
// =============================
//  KILLZONE RANGE BOXES
// =============================
var box   curLondonKZ = na
var float lonKZHi     = na
var float lonKZLo     = na
var int   lonKZStart  = na
 
if drawKZBoxes and showLondonKZ
    startedLonKZ = londonKZOn and not londonKZOn[1]
    endedLonKZ   = not londonKZOn and londonKZOn[1]
    if startedLonKZ
        lonKZHi    := high
        lonKZLo    := low
        lonKZStart := time
        curLondonKZ := box.new(left = bar_index, top = high, right = bar_index + 1, bottom = low,
             border_color = color.new(#1E88E5, 40), bgcolor = color.new(#1E88E5, 88), xloc = xloc.bar_index)
    if londonKZOn and not na(curLondonKZ)
        lonKZHi := math.max(lonKZHi, high)
        lonKZLo := math.min(lonKZLo, low)
        box.set_top(curLondonKZ, lonKZHi)
        box.set_bottom(curLondonKZ, lonKZLo)
        box.set_right(curLondonKZ, bar_index)
    if endedLonKZ
        curLondonKZ := na
 
var box   curNYKZ    = na
var float nyKZHi     = na
var float nyKZLo     = na
 
if drawKZBoxes and showNYKZ
    startedNYKZ = nyKZOn and not nyKZOn[1]
    endedNYKZ   = not nyKZOn and nyKZOn[1]
    if startedNYKZ
        nyKZHi := high
        nyKZLo := low
        curNYKZ := box.new(left = bar_index, top = high, right = bar_index + 1, bottom = low,
             border_color = color.new(#2E7D32, 40), bgcolor = color.new(#2E7D32, 88), xloc = xloc.bar_index)
    if nyKZOn and not na(curNYKZ)
        nyKZHi := math.max(nyKZHi, high)
        nyKZLo := math.min(nyKZLo, low)
        box.set_top(curNYKZ, nyKZHi)
        box.set_bottom(curNYKZ, nyKZLo)
        box.set_right(curNYKZ, bar_index)
    if endedNYKZ
        curNYKZ := na
 
// =============================
//  DASHBOARD
// =============================
f_pos(string p) =>
    p == "top_left"      ? position.top_left :
     p == "top_right"     ? position.top_right :
     p == "bottom_left"   ? position.bottom_left :
     p == "bottom_right"  ? position.bottom_right : position.middle_right
 
f_size(string s) =>
    s == "tiny"   ? size.tiny :
     s == "normal" ? size.normal : size.small
 
var table dash = table.new(position = f_pos(dashPos), columns = 2, rows = 6,
         bgcolor = color.new(color.black, 80), border_color = color.new(color.gray, 60), border_width = 1)
 
string curSession = asiaOn ? "Asia" : londonOn ? "London" : nyOn ? "New York" : "Off-session"
color  curSessionCol = asiaOn ? #FFD54F : londonOn ? #42A5F5 : nyOn ? #66BB6A : color.gray
string curKZ = londonKZOn ? "London AM" : nyKZOn ? "NY AM" : "—"
color  curKZCol = londonKZOn ? #1E88E5 : nyKZOn ? #2E7D32 : color.gray
 
if showDash and barstate.islast
    table.clear(dash, 0, 0, 1, 5)
    table.cell(dash, 0, 0, "Sessions KZ", text_color = color.white, text_size = f_size(dashSize), bgcolor = color.new(color.black, 40))
    table.cell(dash, 1, 0, str.format("{0}", timeframe.period), text_color = color.white, text_size = f_size(dashSize), bgcolor = color.new(color.black, 40))
 
    table.cell(dash, 0, 1, "Session", text_color = color.silver, text_size = f_size(dashSize))
    table.cell(dash, 1, 1, curSession, text_color = curSessionCol, text_size = f_size(dashSize))
 
    table.cell(dash, 0, 2, "Killzone", text_color = color.silver, text_size = f_size(dashSize))
    table.cell(dash, 1, 2, curKZ, text_color = curKZCol, text_size = f_size(dashSize))
 
    table.cell(dash, 0, 3, "Asia", text_color = color.silver, text_size = f_size(dashSize))
    table.cell(dash, 1, 3, asiaOn ? "active" : "—", text_color = asiaOn ? #FFD54F : color.gray, text_size = f_size(dashSize))
 
    table.cell(dash, 0, 4, "London", text_color = color.silver, text_size = f_size(dashSize))
    table.cell(dash, 1, 4, londonOn ? "active" : "—", text_color = londonOn ? #42A5F5 : color.gray, text_size = f_size(dashSize))
 
    table.cell(dash, 0, 5, "New York", text_color = color.silver, text_size = f_size(dashSize))
    table.cell(dash, 1, 5, nyOn ? "active" : "—", text_color = nyOn ? #66BB6A : color.gray, text_size = f_size(dashSize))
 
// =============================
//  ALERTS
// =============================
alertcondition(asiaOn   and not asiaOn[1],   "Asia session open",    "Asia session has opened.")
alertcondition(londonOn and not londonOn[1], "London session open",  "London session has opened.")
alertcondition(nyOn     and not nyOn[1],     "NY session open",      "New York session has opened.")
alertcondition(londonKZOn and not londonKZOn[1], "London AM KZ open", "London AM killzone has opened.")
alertcondition(nyKZOn     and not nyKZOn[1],     "NY AM KZ open",     "NY AM killzone has opened.")

← 返回列表