Investep Volume + Worden (1H :00 RTH/ETH)

camicabrera · study · 139 行 · 点赞 1 · TradingView 原页

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

Pine Script

//@version=6
indicator("Investep · Volume + Worden (1H :00 RTH/ETH)", overlay = false, explicit_plot_zorder = true,
     format = format.volume)
 
// One pane / one scale: the Y axis is actual volume. Worden (0–100) is drawn
// on that axis relative to the rolling volume peak; its true value is in the
// header and Data Window.
volumeLookback = input.int(50, "Volume normalization lookback (chart bars)", minval = 1)
volumeHeight = input.float(100.0, "Volume maximum height (0–100 pane)", minval = 1.0, maxval = 100.0)
ltf = input.timeframe("5", "1H only: intrabar timeframe", options = ["1", "5", "15"])
period = input.int(12, "Worden period", minval = 2)
smooth = input.int(3, "Worden smoothing", minval = 1)
// Match the hourly candle palette; keep volume and oscillator colors independent.
upVolCol = input.color(#26a69a, "Up volume", inline = "vol")
dnVolCol = input.color(#ef5350, "Down volume", inline = "vol")
upperCol = input.color(#26a69a, "Worden upper level (80)", inline = "levels")
lowerCol = input.color(#ef5350, "Worden lower level (20)", inline = "levels")
wordenCol = input.color(color.orange, "Worden line")
// Extended-hours 1H bars already start at :00, so they take the native path
// below (chart volume, all session bars). Only RTH 1H rebuilds :00 blocks.
shift1h = timeframe.isminutes and timeframe.multiplier == 60 and syminfo.session != session.extended
regularTicker = ticker.new(syminfo.prefix, syminfo.ticker, session.regular)
 
// TC2000 WSTOC12.3: percentile rank with half credit for ties, then SMA(3).
rank(float value, array<float> history, int length) =>
    float result = na
    if array.size(history) >= length - 1
        float count = 0.0
        for j = array.size(history) - length + 1 to array.size(history) - 1
            prior = array.get(history, j)
            count += prior < value ? 1.0 : prior == value ? 0.5 : 0.0
        result := 100.0 * count / (length - 1)
    result
 
smoothed(float value, array<float> history, int length) =>
    float result = na
    if not na(value) and array.size(history) >= length - 1
        float total = value
        if length > 1
            for j = array.size(history) - length + 1 to array.size(history) - 1
                total += array.get(history, j)
        result := total / length
    result
 
var array<float> closes = array.new<float>()
var array<float> ranks = array.new<float>()
var int bucket = na
var float bO = na
var float bC = na
var float bV = na
float completedVolume = na
float completedWorden = na
float completedOpen = na
float completedClose = na
 
if shift1h
    // Only RTH 1H needs intrabars. Other timeframes use chart data directly.
    [aT, aO, aC, aV, aRth, aLast] = request.security_lower_tf(regularTicker, ltf,
         [time, open, close, volume, session.ismarket, session.islastbar_regular],
         ignore_invalid_timeframe = true)
    for i = 0 to (array.size(aT) == 0 ? na : array.size(aT) - 1)
        if array.get(aRth, i)
            t = array.get(aT, i)
            key = t - (minute(t, syminfo.timezone) * 60 + second(t, syminfo.timezone)) * 1000
            changed = not na(bucket) and key != bucket
            if changed
                if key - bucket == 60 * 60 * 1000
                    raw = rank(bC, closes, period)
                    completedWorden := smoothed(raw, ranks, smooth)
                    completedVolume := bV
                    completedOpen := bO
                    completedClose := bC
                    array.push(closes, bC)
                    array.push(ranks, raw)
                    if array.size(closes) > period
                        array.shift(closes)
                    if array.size(ranks) > smooth
                        array.shift(ranks)
                bO := na
            if na(bO)
                bO := array.get(aO, i)
                bV := 0.0
            bC := array.get(aC, i)
            bV += array.get(aV, i)
            bucket := key
            if array.get(aLast, i)
                raw = rank(bC, closes, period)
                completedWorden := smoothed(raw, ranks, smooth)
                completedVolume := bV
                completedOpen := bO
                completedClose := bC
                array.push(closes, bC)
                array.push(ranks, raw)
                if array.size(closes) > period
                    array.shift(closes)
                if array.size(ranks) > smooth
                    array.shift(ranks)
                bO := na
                bucket := na
 
// Native timeframe history excludes the candidate when ranking. Ordinary var
// rollback replaces the forming bar on each tick instead of appending ticks.
var array<float> nativeCloses = array.new<float>()
var array<float> nativeRanks = array.new<float>()
float nativeWorden = na
if not shift1h
    raw = rank(close, nativeCloses, period)
    nativeWorden := smoothed(raw, nativeRanks, smooth)
    array.push(nativeCloses, close)
    array.push(nativeRanks, raw)
    if array.size(nativeCloses) > period
        array.shift(nativeCloses)
    if array.size(nativeRanks) > smooth
        array.shift(nativeRanks)
 
done = shift1h and not na(completedClose)
live = shift1h and barstate.islast and not na(bO)
vol = not shift1h ? volume : done ? completedVolume : live ? bV : na
worden = not shift1h ? nativeWorden : done ? completedWorden : live ? smoothed(rank(bC, closes, period), ranks, smooth) : na
bull = not shift1h ? close >= open : done ? completedClose >= completedOpen : bC >= bO
peakVolume = ta.highest(vol, volumeLookback)
// Volume units per Worden point: Worden 100 sits where the rolling peak
// reaches volumeHeight. Same picture as the former 0–100 pane, but in shares.
wordenUnit = na(peakVolume) or peakVolume <= 0 ? na : peakVolume / volumeHeight
// Plot the columns first so Worden remains in front. Worden does not use volume.
plot(vol, "Volume (actual; 1H shifted)",
     style = plot.style_columns, color = color.new(bull ? upVolCol : dnVolCol, 65),
     format = format.volume)
// In RTH 1H this covers a different interval; otherwise it equals vol.
plot(volume, "Native chart volume (unshifted)",
     display = display.data_window, format = format.volume)
plot(0, "Scale floor", color = color.new(color.gray, 100), display = display.pane)
plot(100 * wordenUnit, "Scale ceiling", color = color.new(color.gray, 100), display = display.pane)
// Pane-only: their axis positions are volume units, not Worden values.
plot(80 * wordenUnit, "80", color = upperCol, display = display.pane)
plot(20 * wordenUnit, "20", color = lowerCol, display = display.pane)
plot(worden * wordenUnit, "Worden (on volume axis)", color = wordenCol, linewidth = 2, display = display.pane)
plot(worden, "Worden", color = wordenCol, format = format.price, precision = 1,
     display = display.status_line + display.data_window)

← 返回列表