Noise Area Bands [Badr Edge]

kh_badrr · study · 107 行 · 点赞 4 · TradingView 原页

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

Pine Script

//@version=6
// Noise Area Bands [Badr Edge] · v1.0.0
// Educational chart-marking tool. Markers show what happened on a bar. They are not trade signals.
indicator("Noise Area Bands [Badr Edge]", shorttitle = "BE Noise Area", overlay = true)
const color GOLD = #D9B46C
const color TEAL = #4FB8A0
const color ROSE = #E07A6C
const color GREY = #8F939B
const string TZ = "America/New_York"
const int MAX_SLOTS = 420
const string G_B = "Bands"
sess    = input.session("0930-1600", "Session (New York time)", group = G_B, tooltip = "Bands are built from the open of this session and reset every day.")
lookN   = input.int(14, "Days in the average", minval = 5, maxval = 60, group = G_B, tooltip = "For each time of day, the band width is the average absolute move from the open at that same time over this many past sessions.")
mult    = input.float(1.0, "Band multiplier", minval = 0.25, step = 0.25, group = G_B)
useGap  = input.bool(true, "Widen for the overnight gap", group = G_B, tooltip = "The upper band starts from the higher of today's open and the prior close, the lower band from the lower of the two.")
const string G_V = "Visuals"
showVwap  = input.bool(true, "Session VWAP", group = G_V)
showOpen  = input.bool(false, "Session open line", group = G_V)
showMarks = input.bool(true, "Outside-band markers", group = G_V, tooltip = "A small triangle when a candle closes outside the band and on the same side of VWAP. A marker shows what happened. It is not a trade signal.")
firstOnly = input.bool(true, "First marker per side each day", group = G_V)
const string G_Y = "Style"
showWm = input.bool(true, "Watermark", group = G_Y)
const string G_A = "Alerts"
useAlerts = input.bool(true, "Alert on a close outside the band", group = G_A, tooltip = "Create the alert with \"Any alert() function call\". Fires once, after the bar closes.")
 
tfOK  = timeframe.isintraday and timeframe.in_seconds() <= 1800
inS   = tfOK and not na(time(timeframe.period, sess, TZ))
start = inS and not inS[1]
 
var matrix<float> moves = matrix.new<float>(lookN + 1, MAX_SLOTS, na)
var int   row  = -1
var int   slot = 0
var float dOpen  = na
var float pClose = na
var float lastC  = na
var float sumPV  = 0.0
var float sumV   = 0.0
var bool  upDone = false
var bool  dnDone = false
float sigma = na
 
if start
    pClose := lastC
    dOpen  := open
    row    := (row + 1) % (lookN + 1)
    slot   := 0
    sumPV  := 0.0
    sumV   := 0.0
    upDone := false
    dnDone := false
else if inS
    slot += 1
if inS and slot < MAX_SLOTS
    moves.set(row, slot, na)
    float s = 0.0
    int   n = 0
    for r = 0 to lookN
        float v = moves.get(r, slot)
        if not na(v)
            s += v
            n += 1
    if n >= math.min(lookN, 5)
        sigma := s / n
    moves.set(row, slot, math.abs(close / dOpen - 1))
if inS
    sumPV += hlc3 * volume
    sumV  += volume
    lastC := close
 
float vw    = inS and sumV > 0 ? sumPV / sumV : na
float baseU = useGap ? math.max(dOpen, nz(pClose, dOpen)) : dOpen
float baseL = useGap ? math.min(dOpen, nz(pClose, dOpen)) : dOpen
float ub    = inS and not na(sigma) ? baseU * (1 + mult * sigma) : na
float lb    = inS and not na(sigma) ? baseL * (1 - mult * sigma) : na
 
bool outUp = not na(ub) and close > ub and close > nz(vw, close - 1)
bool outDn = not na(lb) and close < lb and close < nz(vw, close + 1)
bool up = false
bool dn = false
if barstate.isconfirmed
    up := outUp and (firstOnly ? not upDone : not outUp[1])
    dn := outDn and (firstOnly ? not dnDone : not outDn[1])
    if up
        upDone := true
    if dn
        dnDone := true
 
pU = plot(ub, "Upper band", color.new(GOLD, 15), 1, plot.style_linebr)
pL = plot(lb, "Lower band", color.new(GOLD, 15), 1, plot.style_linebr)
fill(pU, pL, color.new(GOLD, 94), "Noise area")
plot(showVwap ? vw : na, "Session VWAP", color.new(TEAL, 25), 1, plot.style_linebr)
plot(showOpen and inS ? dOpen : na, "Session open", color.new(GREY, 55), 1, plot.style_linebr)
plotshape(showMarks and up, "Close above the band", shape.triangleup, location.belowbar, color.new(TEAL, 0), size = size.tiny)
plotshape(showMarks and dn, "Close below the band", shape.triangledown, location.abovebar, color.new(ROSE, 0), size = size.tiny)
plot(sigma * 100, "Average move at this time (%)", display = display.data_window)
 
if useAlerts and up
    alert(syminfo.ticker + " closed above the noise area and above VWAP", alert.freq_once_per_bar_close)
if useAlerts and dn
    alert(syminfo.ticker + " closed below the noise area and below VWAP", alert.freq_once_per_bar_close)
 
var table wm = table.new(position.bottom_right, 1, 1)
if barstate.islast and showWm
    wm.cell(0, 0, "BADR EDGE", text_color = color.new(GREY, 72), text_size = size.small)
var table note = table.new(position.top_right, 1, 1)
if barstate.islast and (not tfOK or na(sigma) and inS)
    note.cell(0, 0, tfOK ? "Noise Area Bands needs more chart history. Scroll back or use a higher timeframe." : "Noise Area Bands works on 1m to 30m charts.", text_color = GOLD, bgcolor = color.new(color.black, 20), text_size = size.small)

← 返回列表