ETH HOD/LOD VWAP

Each_Penny · study · 93 行 · 点赞 5 · TradingView 原页

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

Pine Script

//@version=6
indicator("ETH HOD/LOD VWAP", overlay=true, precision=2, max_bars_back=5000)
 
// ─── Inputs ───────────────────────────────────────────────────────────────────
color_hod  = input.color(color.new(#ff5252, 0), "HOD Line",        group="Aesthetics")
color_lod  = input.color(color.new(#00f2ff, 0), "LOD Line",        group="Aesthetics")
width_hod  = input.int(1, "HOD Thickness", minval=1, maxval=4,     group="Aesthetics")
width_lod  = input.int(1, "LOD Thickness", minval=1, maxval=4,     group="Aesthetics")
show_cloud = input.bool(true,                   "Show Range Cloud", group="Aesthetics")
label_off  = input.int(2, "Label Offset", minval=0,                group="Aesthetics")
 
// ─── ETH Session (18:00 → 17:00 New York) ─────────────────────────────────────
// Shift time +6h so 18:00 NY rolls to the next calendar day; a change in that
// day marks a new Globex session (also handles the Fri→Sun weekend gap and DST).
int eth_day     = dayofmonth(time + 6 * 3600000, "America/New_York")
bool is_eth_open = na(eth_day[1]) or eth_day != eth_day[1]
 
// ─── State ────────────────────────────────────────────────────────────────────
var float eth_high    = na
var float eth_low     = na
var float h_vol_price = 0.0
var float h_vol       = 0.0
var float l_vol_price = 0.0
var float l_vol       = 0.0
 
var array<chart.point> h_points = array.new<chart.point>()
var array<chart.point> l_points = array.new<chart.point>()
 
var polyline pl_h = na
var polyline pl_l = na
 
// ─── Accumulation ─────────────────────────────────────────────────────────────
float bar_vwp = hlc3 * volume
 
if is_eth_open
    eth_high    := high
    eth_low     := low
    h_vol_price := bar_vwp
    h_vol       := volume
    l_vol_price := bar_vwp
    l_vol       := volume
    array.clear(h_points)
    array.clear(l_points)
else
    if high > eth_high
        eth_high    := high
        h_vol_price := bar_vwp
        h_vol       := volume
        array.clear(h_points)
    else
        h_vol_price += bar_vwp
        h_vol       += volume
 
    if low < eth_low
        eth_low     := low
        l_vol_price := bar_vwp
        l_vol       := volume
        array.clear(l_points)
    else
        l_vol_price += bar_vwp
        l_vol       += volume
 
float vwap_h = h_vol > 0 ? h_vol_price / h_vol : na
float vwap_l = l_vol > 0 ? l_vol_price / l_vol : na
 
if not na(vwap_h)
    array.push(h_points, chart.point.from_time(time, vwap_h))
if not na(vwap_l)
    array.push(l_points, chart.point.from_time(time, vwap_l))
 
// ─── Draw on last bar ─────────────────────────────────────────────────────────
if barstate.islast
    polyline.delete(pl_h)
    polyline.delete(pl_l)
 
    if array.size(h_points) >= 2
        pl_h := polyline.new(h_points, curved=false, line_color=color_hod, line_width=width_hod, xloc=xloc.bar_time)
    if array.size(l_points) >= 2
        pl_l := polyline.new(l_points, curved=false, line_color=color_lod, line_width=width_lod, xloc=xloc.bar_time)
 
// ─── Labels ───────────────────────────────────────────────────────────────────
var label lb_h = label.new(bar_index, na, "",
     style=label.style_label_left, textcolor=color.white,
     color=color_hod, size=size.small)
var label lb_l = label.new(bar_index, na, "",
     style=label.style_label_left, textcolor=color.white,
     color=color_lod, size=size.small)
 
if barstate.islast
    label.set_xy(lb_h, bar_index + label_off, vwap_h)
    label.set_text(lb_h, "H-VWAP: " + str.tostring(vwap_h, "#.##"))
    label.set_xy(lb_l, bar_index + label_off, vwap_l)
    label.set_text(lb_l, "L-VWAP: " + str.tostring(vwap_l, "#.##"))

← 返回列表