IB Sessions: NY / London / Overnight

reecio2005 · study · 96 行 · 点赞 11 · TradingView 原页

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

Pine Script

//@version=6
indicator("IB Sessions: NY / London / Overnight", "IB Sessions", true, max_lines_count = 500, max_labels_count = 500)
tz = input.string("America/New_York", "Timezone")
keep = input.int(10, "Days to show", 1, 20)
onN = input.bool(true, "NY IB", inline = "n")
sN = input.session("0930-1030", "", inline = "n")
eN = input.session("0930-1600", "until", inline = "n")
cN = input.color(color.yellow, "", inline = "n")
onL = input.bool(true, "London IB", inline = "l")
sL = input.session("0300-0400", "", inline = "l")
eL = input.session("0300-1600", "until", inline = "l")
cL = input.color(color.fuchsia, "", inline = "l")
onO = input.bool(true, "Overnight IB", inline = "o")
sO = input.session("1800-1900", "", inline = "o")
eO = input.session("1800-0930", "until", inline = "o")
cO = input.color(color.silver, "", inline = "o")
showD = input.bool(true, "Deviations", inline = "d")
cD = input.color(color.aqua, "", inline = "d")
devs = array.from(input.float(-2.0, "Dev 1"), input.float(-2.5, "Dev 2"), input.float(2.0, "Dev 3"), input.float(2.5, "Dev 4"))
wR = input.int(2, "High/Low width", 1, 5, inline = "r")
sR = input.string("Solid", "", ["Solid", "Dashed", "Dotted"], inline = "r")
wC = input.int(1, "Mid width", 1, 5, inline = "c")
sC = input.string("Dashed", "", ["Solid", "Dashed", "Dotted"], inline = "c")
wD = input.int(1, "Dev width", 1, 5, inline = "v")
sD = input.string("Dotted", "", ["Solid", "Dashed", "Dotted"], inline = "v")
showL = input.bool(true, "Labels", inline = "b")
lSz = input.string("Small", "", ["Tiny", "Small", "Normal"], inline = "b")
lTr = input.int(85, "Label bg", 0, 100)
 
f_st(s) => s == "Dashed" ? line.style_dashed : s == "Dotted" ? line.style_dotted : line.style_solid
lsz = lSz == "Tiny" ? size.tiny : lSz == "Normal" ? size.normal : size.small
 
type Day
    int x0
    float hi
    float lo
    bool done
    array<line> ln
    array<label> lb
 
f_add(Day d, float y, string t, color c, int w, string s) =>
    d.ln.push(line.new(d.x0, y, bar_index, y, color = c, width = w, style = f_st(s)))
    if showL
        d.lb.push(label.new(bar_index, y, t + " " + str.tostring(y, format.mintick), style = label.style_label_left, color = color.new(c, lTr), textcolor = c, size = lsz))
 
f_set(Day d, int i, float y, string t) =>
    d.ln.get(i).set_y1(y)
    d.ln.get(i).set_y2(y)
    if showL
        d.lb.get(i).set_y(y)
        d.lb.get(i).set_text(t + " " + str.tostring(y, format.mintick))
 
f_ib(bool on, string ss, string ex, string p, color c) =>
    var days = array.new<Day>()
    var Day d = na
    inS = not na(time(timeframe.period, ss, tz))
    inE = not na(time(timeframe.period, ex, tz))
    st = inS and not inS[1]
    en = not inS and inS[1]
    if on
        if st
            d := Day.new(bar_index, high, low, false, array.new<line>(), array.new<label>())
            f_add(d, high, p + " High", c, wR, sR)
            f_add(d, low, p + " Low", c, wR, sR)
            f_add(d, (high + low) / 2, p + " Mid", c, wC, sC)
            days.push(d)
            if days.size() > keep
                o = days.shift()
                for x in o.ln
                    x.delete()
                for x in o.lb
                    x.delete()
        else if inS and not na(d)
            d.hi := math.max(d.hi, high)
            d.lo := math.min(d.lo, low)
        if not na(d) and (inS or inE)
            m = (d.hi + d.lo) / 2
            if not d.done
                f_set(d, 0, d.hi, p + " High")
                f_set(d, 1, d.lo, p + " Low")
                f_set(d, 2, m, p + " Mid")
            if en and not d.done
                d.done := true
                if showD
                    for k in devs
                        f_add(d, m + k * (d.hi - m), p + (k > 0 ? " +" : " ") + str.tostring(k, "0.0#"), cD, wD, sD)
            for x in d.ln
                x.set_x2(bar_index)
            for x in d.lb
                x.set_x(bar_index)
    on
 
f_ib(onN, sN, eN, "NY IB", cN)
f_ib(onL, sL, eL, "LDN IB", cL)
f_ib(onO, sO, eO, "ON IB", cO)
// END OF SCRIPT

← 返回列表