Asian Range + CE Deviations

reecio2005 · study · 78 行 · 点赞 39 · TradingView 原页

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

Pine Script

//@version=6
indicator("Asian Range + CE Deviations", shorttitle = "Asia Range", overlay = true, max_lines_count = 500, max_labels_count = 500)
sess = input.session("2000-0200", "Asian session (NY time)")
tz   = input.string("America/New_York", "Timezone")
keep = input.int(20, "Days to show", minval = 1, maxval = 90)
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"))
S = "Style"
cR = input.color(color.white, "High / Low", group = S, inline = "r")
wR = input.int(1, "", minval = 1, maxval = 5, group = S, inline = "r")
sR = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = S, inline = "r")
cC = input.color(color.orange, "CE", group = S, inline = "c")
wC = input.int(1, "", minval = 1, maxval = 5, group = S, inline = "c")
sC = input.string("Dashed", "", options = ["Solid", "Dashed", "Dotted"], group = S, inline = "c")
cD = input.color(color.aqua, "Deviations", group = S, inline = "d")
wD = input.int(1, "", minval = 1, maxval = 5, group = S, inline = "d")
sD = input.string("Dotted", "", options = ["Solid", "Dashed", "Dotted"], group = S, inline = "d")
showL = input.bool(true, "Labels", group = S, inline = "l")
lSize = input.string("Small", "", options = ["Tiny", "Small", "Normal"], group = S, inline = "l")
lFill = input.int(85, "Label background transparency", minval = 0, maxval = 100, group = S)
 
f_st(string s) => s == "Dashed" ? line.style_dashed : s == "Dotted" ? line.style_dotted : line.style_solid
lsz = lSize == "Tiny" ? size.tiny : lSize == "Normal" ? size.normal : size.small
 
type Day
    int x0
    float hi
    float lo
    bool done
    array<line> lns
    array<label> lbs
 
f_add(Day d, float y, string name, color col, int w, string st) =>
    d.lns.push(line.new(d.x0, y, bar_index, y, color = col, width = w, style = f_st(st)))
    if showL
        d.lbs.push(label.new(bar_index, y, name + " " + str.tostring(y, format.mintick), style = label.style_label_left, color = color.new(col, lFill), textcolor = col, size = lsz))
 
f_set(Day d, int i, float y, string name) =>
    d.lns.get(i).set_y1(y)
    d.lns.get(i).set_y2(y)
    if showL
        d.lbs.get(i).set_y(y)
        d.lbs.get(i).set_text(name + " " + str.tostring(y, format.mintick))
 
inS = not na(time(timeframe.period, sess, tz))
var array<Day> days = array.new<Day>()
var Day cur = na
 
if inS and not inS[1]
    cur := Day.new(bar_index, high, low, false, array.new<line>(), array.new<label>())
    f_add(cur, high, "Asia High", cR, wR, sR)
    f_add(cur, low, "Asia Low", cR, wR, sR)
    f_add(cur, (high + low) / 2, "CE", cC, wC, sC)
    days.push(cur)
    if days.size() > keep
        Day old = days.shift()
        for l in old.lns
            l.delete()
        for b in old.lbs
            b.delete()
else if inS and not na(cur)
    cur.hi := math.max(cur.hi, high)
    cur.lo := math.min(cur.lo, low)
 
if not na(cur)
    ce = (cur.hi + cur.lo) / 2
    if not cur.done
        f_set(cur, 0, cur.hi, "Asia High")
        f_set(cur, 1, cur.lo, "Asia Low")
        f_set(cur, 2, ce, "CE")
    if not inS and inS[1] and not cur.done
        cur.done := true
        for k in devs
            f_add(cur, ce + k * (cur.hi - ce), (k > 0 ? "+" : "") + str.tostring(k, "0.0#") + " SD", cD, wD, sD)
    for l in cur.lns
        l.set_x2(bar_index)
    for b in cur.lbs
        b.set_x(bar_index)
// END OF SCRIPT

← 返回列表