Volume Shock [Badr Edge]

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

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

Pine Script

//@version=6
// Volume Shock [Badr Edge] · v1.0.0
// Educational chart-marking tool. Markers show what happened on a bar. They are not trade signals.
indicator("Volume Shock [Badr Edge]", shorttitle = "BE Vol Shock", overlay = true)
const color GOLD  = #D9B46C
const color TEAL  = #4FB8A0
const color ROSE  = #E07A6C
const color GREY  = #8F939B
const color PANEL = #0F1013
const string G_S = "Shock"
lookN  = input.int(100, "Lookback (bars)", minval = 20, maxval = 1000, group = G_S, tooltip = "Volume is compared with the average and spread of this many earlier bars.")
zMin   = input.float(3.0, "Shock threshold (standard deviations)", minval = 1.0, step = 0.25, group = G_S, tooltip = "A bar is a shock when its volume is this many standard deviations above the average. Higher values mark fewer bars.")
minMove = input.float(0.0, "Minimum bar range (x ATR 14)", minval = 0, step = 0.25, group = G_S, tooltip = "Optional. Ignore shock bars with a range smaller than this.")
const string G_V = "Visuals"
showMarks = input.bool(true, "Shock markers", group = G_V, tooltip = "A small diamond on each shock bar, below an up bar and above a down bar. It marks unusual volume. It is not a trade signal.")
paintBar  = input.bool(false, "Colour shock bars", group = G_V)
showStats = input.bool(true, "Tally table", group = G_V, tooltip = "Counts, on the bars loaded on this chart, how often the bar after a shock closed against the shock bar's direction.")
const string G_Y = "Style"
colShock = input.color(GOLD, "Shock", group = G_Y)
showWm   = input.bool(true, "Watermark", group = G_Y)
const string G_A = "Alerts"
useAlerts = input.bool(true, "Alert on a volume shock", group = G_A, tooltip = "Create the alert with \"Any alert() function call\". Fires once, after the bar closes.")
 
avg = ta.sma(volume, lookN)[1]
dev = ta.stdev(volume, lookN)[1]
z   = dev > 0 ? (volume - avg) / dev : na
atr = ta.atr(14)
bool shock = barstate.isconfirmed and not na(z) and z >= zMin and high - low >= minMove * nz(atr[1])
bool upBar = close >= open
 
var int nShock = 0
var int nRev   = 0
bool prevShock = shock[1]
bool prevUp    = upBar[1]
if barstate.isconfirmed and prevShock and close != close[1]
    nShock += 1
    if (close < close[1]) == prevUp
        nRev += 1
 
plotshape(showMarks and shock and upBar, "Volume shock on an up bar", shape.diamond, location.belowbar, color.new(colShock, 0), size = size.tiny)
plotshape(showMarks and shock and not upBar, "Volume shock on a down bar", shape.diamond, location.abovebar, color.new(colShock, 0), size = size.tiny)
barcolor(paintBar and shock ? colShock : na, title = "Shock bar colour")
plot(z, "Volume z-score", display = display.data_window)
plot(nShock, "Shocks counted", display = display.data_window)
plot(nRev, "Next bar closed against the shock bar", display = display.data_window)
 
if useAlerts and shock
    alert(syminfo.ticker + " volume shock: " + str.tostring(z, "0.0") + " standard deviations above the " + str.tostring(lookN) + "-bar average", alert.freq_once_per_bar_close)
 
var table tally = table.new(position.top_right, 1, 2, frame_color = color.new(GREY, 75), frame_width = 1)
if barstate.islast and showStats
    tally.cell(0, 0, "VOLUME SHOCKS", text_color = GOLD, text_size = size.small, text_halign = text.align_left, bgcolor = color.new(PANEL, 10))
    tally.cell(0, 1, nShock == 0 ? "No shocks on the loaded bars" : "Next bar closed the other way after " + str.tostring(nRev) + " of " + str.tostring(nShock) + " (" + str.tostring(100.0 * nRev / nShock, "0") + "%)", text_color = GREY, text_size = size.small, text_halign = text.align_left, bgcolor = color.new(PANEL, 10))
 
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)

← 返回列表