[DAOL] Volume Effort Map

DAOLSEC · study · 162 行 · 点赞 5 · TradingView 原页

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

Pine Script

//@version=6
indicator("[DAOL] Volume Effort Map", shorttitle="DAOL Effort", overlay=false, precision=2)
 
// Written for DAOL; no Community script code copied.
// Foundation: same-time relative volume and Wilder ATR; no novelty claim for
// these concepts or general effort-versus-result analysis.
// https://www.tradingview.com/support/solutions/43000705489-relative-volume-at-time/
// https://www.tradingview.com/support/solutions/43000501823-average-true-range-atr/
// This implementation compares BAR volume, not cumulative session volume.
// Volume is reported feed volume, not bid/ask delta or smart-money detection.
 
int priorDays = input.int(20, "Prior observed exchange dates", minval=5, maxval=40, group="Same-time volume")
int minSamples = input.int(5, "Minimum matching historical bars", minval=2, maxval=40, group="Same-time volume")
float highVolume = input.float(1.5, "High relative volume (x)", minval=1.0, maxval=10.0, step=0.1, group="Classification")
int atrLength = input.int(14, "ATR length", minval=2, maxval=100, group="Classification")
float lowProgress = input.float(0.20, "Low net close progress (prior ATR)", minval=0.01, maxval=2.0, step=0.05, group="Classification")
float strongProgress = input.float(0.50, "Directional progress (prior ATR)", minval=0.05, maxval=5.0, step=0.05, group="Classification")
float edgeZone = input.float(25.0, "Close near edge (% of bar range)", minval=1.0, maxval=49.0, step=1.0, group="Classification")
bool colorBars = input.bool(false, "Color price bars", group="Display")
bool showDashboard = input.bool(true, "Show dashboard", group="Display")
 
if not timeframe.isminutes or timeframe.multiplier > 60
    runtime.error("Use a standard time-based intraday chart from 1 to 60 minutes.")
if not chart.is_standard
    runtime.error("Use standard candles/bars. Synthetic chart prices and volumes are unsuitable.")
if minSamples > priorDays
    runtime.error("Minimum matching historical bars must be <= Prior observed exchange dates.")
if lowProgress >= strongProgress
    runtime.error("Low progress threshold must be smaller than directional progress threshold.")
 
// Calendar date and bar-opening clock minute in the exchange timezone.
// No holidays/weekends invented: ring advances only on dates present in chart.
// Overnight trading crossing midnight is split by calendar date, NOT trade date.
int dateKey = year(time, syminfo.timezone) * 10000 + month(time, syminfo.timezone) * 100 + dayofmonth(time, syminfo.timezone)
int slot = hour(time, syminfo.timezone) * 60 + minute(time, syminfo.timezone)
int slotsPerDay = 1440
int capacity = priorDays + 1
var array<float> history = array.new_float(capacity * slotsPerDay, na)
var int activeDate = na
var int activeRow = -1
var int availableDays = 0
float currentATR = ta.atr(atrLength)
 
var float closedRV = na
var float closedBaseline = na
var float closedProgress = na
var float closedCLV = na
var float closedRangeATR = na
var int closedSamples = 0
var int state = 0
var int previousState = 0
var bool initialized = false
var string status = "Collecting same-time history"
bool changed = false
 
// 0 normal activity; 1 high activity / upward progress; -1 downward;
// 2 high activity / low net progress; 3 high activity / mixed result.
f_name(int s) =>
    s == 1 ? "High activity / upward progress" : s == -1 ? "High activity / downward progress" : s == 2 ? "High activity / low net progress" : s == 3 ? "High activity / mixed result" : "Normal or low activity"
f_color(int s) =>
    s == 1 ? color.lime : s == -1 ? color.red : s == 2 ? color.rgb(230, 175, 40) : s == 3 ? color.aqua : color.gray
 
if barstate.isconfirmed
    if na(activeDate) or dateKey != activeDate
        activeRow := (activeRow + 1) % capacity
        activeDate := dateKey
        availableDays := math.min(availableDays + 1, capacity)
        for m = 0 to slotsPerDay - 1
            array.set(history, activeRow * slotsPerDay + m, na)
 
    // Compute BEFORE storing current volume; current date is always excluded.
    float total = 0.0
    int count = 0
    for age = 1 to priorDays
        if age < availableDays
            int row = (activeRow - age + capacity) % capacity
            float observation = array.get(history, row * slotsPerDay + slot)
            if not na(observation) and observation >= 0.0
                total += observation
                count += 1
    float average = count > 0 ? total / count : na
    bool ready = count >= minSamples and not na(average) and average > 0.0 and not na(volume) and volume >= 0.0 and not na(currentATR[1]) and currentATR[1] > 0.0 and not na(close[1])
    closedSamples := count
    closedBaseline := average
    closedRV := ready ? volume / average : na
    closedProgress := ready ? (close - close[1]) / currentATR[1] : na
    float barRange = high - low
    closedCLV := ready ? (barRange > 0.0 ? (close - low) / barRange : 0.5) : na
    closedRangeATR := ready ? barRange / currentATR[1] : na
    state := 0
    if ready
        if closedRV >= highVolume
            if math.abs(closedProgress) <= lowProgress
                state := 2
            else if closedProgress >= strongProgress and closedCLV >= 1.0 - edgeZone / 100.0
                state := 1
            else if closedProgress <= -strongProgress and closedCLV <= edgeZone / 100.0
                state := -1
            else
                state := 3
        changed := initialized and state != previousState
        previousState := state
        initialized := true
        status := f_name(state)
    else
        initialized := false
        status := na(volume) ? "Missing current volume" : count < minSamples ? "Collecting same-time history" : na(average) or average <= 0.0 ? "No positive historical volume baseline" : "Waiting for valid ATR/price"
    // Missing observations remain NA; real zero-volume bars remain zero.
    array.set(history, activeRow * slotsPerDay + slot, not na(volume) and volume >= 0.0 ? volume : na)
 
plot(closedRV, "Same-time relative volume (x)", color=f_color(state), style=plot.style_columns, linewidth=2)
hline(1.0, "Historical volume baseline", color=color.gray, linestyle=hline.style_dotted)
hline(highVolume, "High activity threshold", color=color.orange, linestyle=hline.style_dashed)
plot(closedProgress, "Signed net progress (prior ATR)", display=display.data_window)
plot(closedRangeATR, "Full bar range (prior ATR)", display=display.data_window)
plot(closedCLV * 100.0, "Close location: low=0 high=100", display=display.data_window)
plot(closedBaseline, "Mean matching historical bar volume", display=display.data_window)
plot(closedSamples, "Matching historical bars", display=display.data_window)
barcolor(colorBars and not na(closedRV) ? f_color(state) : na)
 
var table dashboard = table.new(position.top_right, 2, 7, border_width=1)
if barstate.islast and showDashboard
    color panel = color.rgb(35, 35, 35)
    table.cell(dashboard, 0, 0, "DAOL Volume Effort Map", text_color=color.white, bgcolor=color.rgb(19, 62, 103))
    table.cell(dashboard, 1, 0, "Latest closed bar", text_color=color.white, bgcolor=color.rgb(19, 62, 103))
    table.cell(dashboard, 0, 1, "Volume / same-time mean", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 1, 1, na(closedRV) ? "N/A" : str.tostring(closedRV, "#.00") + "x", text_color=f_color(state), bgcolor=panel)
    table.cell(dashboard, 0, 2, "Net close progress", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 1, 2, na(closedProgress) ? "N/A" : str.tostring(closedProgress, "#.00") + " ATR", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 0, 3, "Full bar range", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 1, 3, na(closedRangeATR) ? "N/A" : str.tostring(closedRangeATR, "#.00") + " ATR", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 0, 4, "Close location", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 1, 4, na(closedCLV) ? "N/A" : str.tostring(closedCLV * 100.0, "#.0") + "%", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 0, 5, "Historical samples", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 1, 5, str.tostring(closedSamples) + " / " + str.tostring(priorDays), text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 0, 6, "Context", text_color=color.white, bgcolor=panel)
    table.cell(dashboard, 1, 6, status, text_color=f_color(state), bgcolor=panel)
 
alertcondition(changed and state == 1, "DAOL: High activity / upward progress", "DAOL Volume Effort Map: high same-time volume, upward close progress and close near bar high. {{ticker}} | {{interval}}")
alertcondition(changed and state == -1, "DAOL: High activity / downward progress", "DAOL Volume Effort Map: high same-time volume, downward close progress and close near bar low. {{ticker}} | {{interval}}")
alertcondition(changed and state == 2, "DAOL: High activity / low net progress", "DAOL Volume Effort Map: high same-time volume but low net close progress. Not proof of absorption. {{ticker}} | {{interval}}")
alertcondition(changed and state == 3, "DAOL: High activity / mixed result", "DAOL Volume Effort Map: high same-time volume without a clear directional or low-progress classification. {{ticker}} | {{interval}}")
alertcondition(changed, "DAOL: Any activity-state change", "DAOL Volume Effort Map: closed-bar activity state changed. {{ticker}} | {{interval}}")
 
// USAGE / PUBLICATION NOTES
// Use 1-60 minute standard charts; start with 5 or 15 minutes. Load enough
// history for >=5 matching bar-opening clock times on prior observed dates.
// Same-time baseline is arithmetic mean of prior exact clock-minute matches
// in exchange timezone, excluding current date. Not cumulative volume, not
// TradingView's identical RVOL-at-Time implementation. Missing times skipped.
// Session settings, partial bars, holidays, DST, overnight calendar boundaries
// and illiquid feeds influence comparability. No historical calendar slots
// are manufactured. Repeated local-time bars on a DST fallback date overwrite
// that date's clock slot; use markets without ambiguous local times if needed.
// Low net progress may coexist with large intrabar movement: inspect full
// bar range separately. Gaps count in close-to-close progress. Prior-bar ATR
// is used to avoid inflating denominator with the same bar being evaluated.
// Closed-bar measurements held during live bar. First valid state initializes
// silently; alerts on later transitions only, once per bar close. No 2-bar
// persistence by default: each classification describes one completed bar.
// No guaranteed predictive value, absorption, buy/sell volume or profit claims.
// Tested numerically outside Pine; TradingView compilation/feed testing pending.

← 返回列表