International Session Open/Close Indicator v3

iamgregr · study · 56 行 · 点赞 16 · TradingView 原页

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

Pine Script

//@version=6
indicator("International Session Open/Close Indicator - Compromise v6", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500)
 
// Only draw past lines and labels for the last 20 days, so the limits aren't exceeded
recentLimit = timenow - 20 * 86400000
 
// Open: dashed line with label at the top. Close: dotted line with label at the bottom
f_session(string sess, string tz, string nm, color col) =>
    inS    = not na(time(timeframe.period, sess, tz))
    startS = inS and not inS[1]
    endS   = not inS and inS[1]
    if startS and time > recentLimit
        line.new(bar_index, high, bar_index, low, extend=extend.both, color=col, width=2, style=line.style_dashed)
        label.new(bar_index, high, nm, style=label.style_label_down, color=col, textcolor=color.white, size=size.tiny)
    if endS and time > recentLimit
        line.new(bar_index, high, bar_index, low, extend=extend.both, color=col, width=2, style=line.style_dotted)
        label.new(bar_index, low, nm, style=label.style_label_up, color=col, textcolor=color.white, size=size.tiny)
    inS
 
// Session hours in local exchange time so daylight saving is handled automatically
// Mid-tone colours so the lines work on both light and dark backgrounds
f_session("1000-1600", "Australia/Sydney", "SYD", #F08C00)  // orange
f_session("0900-1530", "Asia/Tokyo",       "TKY", #E53935)  // red
f_session("0930-1500", "Asia/Shanghai",    "SHA", #8E44AD)  // purple
f_session("0900-1530", "Asia/Seoul",       "KSP", #26A69A)  // teal
f_session("0900-1730", "Europe/Berlin",    "EUR", #7CB342)  // green
f_session("0800-1630", "Europe/London",    "LDN", #26C6DA)  // cyan
f_session("0930-1600", "America/New_York", "NYC", #3D7BF5)  // blue
 
// Upcoming sessions: faint shaded box from open to close, with the same lines and labels
var bool futureDrawn = false
todayUtc = timestamp("UTC", year(timenow), month(timenow), dayofmonth(timenow))
priceTop = ta.highest(high, 300)
priceBot = ta.lowest(low, 300)
 
f_future(string nm, string tz, int sh, int sm, int eh, int em, color col, float top, float bot, int todayUtc) =>
    for d = -1 to 8
        dayTs = todayUtc + d * 86400000
        st = timestamp(tz, year(dayTs), month(dayTs), dayofmonth(dayTs), sh, sm)
        en = timestamp(tz, year(dayTs), month(dayTs), dayofmonth(dayTs), eh, em)
        if st > timenow and st < timenow + 8 * 86400000
            box.new(st, top, en, bot, xloc=xloc.bar_time, bgcolor=color.new(col, 92), border_color=col, border_width=1)
            line.new(st, top, st, bot, xloc=xloc.bar_time, color=col, width=2, style=line.style_dashed)
            label.new(st, top, nm, xloc=xloc.bar_time, style=label.style_label_down, color=col, textcolor=color.white, size=size.tiny)
            line.new(en, top, en, bot, xloc=xloc.bar_time, color=col, width=2, style=line.style_dotted)
            label.new(en, bot, nm, xloc=xloc.bar_time, style=label.style_label_up, color=col, textcolor=color.white, size=size.tiny)
 
if barstate.islast and not futureDrawn
    f_future("SYD", "Australia/Sydney", 10, 0, 16, 0, #F08C00, priceTop, priceBot, todayUtc)
    f_future("TKY", "Asia/Tokyo",        9, 0, 15, 30, #E53935, priceTop, priceBot, todayUtc)
    f_future("SHA", "Asia/Shanghai",     9, 30, 15, 0, #8E44AD, priceTop, priceBot, todayUtc)
    f_future("KSP", "Asia/Seoul",        9, 0, 15, 30, #26A69A, priceTop, priceBot, todayUtc)
    f_future("EUR", "Europe/Berlin",     9, 0, 17, 30, #7CB342, priceTop, priceBot, todayUtc)
    f_future("LDN", "Europe/London",     8, 0, 16, 30, #26C6DA, priceTop, priceBot, todayUtc)
    f_future("NYC", "America/New_York",  9, 30, 16, 0, #3D7BF5, priceTop, priceBot, todayUtc)
    futureDrawn := true

← 返回列表