Volume Flow Indicator (Classic)

BY_Tse · study · 32 行 · 点赞 14 · TradingView 原页

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

Pine Script

//@version=6
// Volume Flow Indicator, Markos Katsanos (TASC, June 2004)
// Pine v6 port of the author's published reference code. Defaults follow the author:
// 3-bar EMA smoothing on raw VFI, 30-bar SMA signal line.
indicator("Volume Flow Indicator", shorttitle = "VFI", format = format.price, precision = 2)
 
period = input.int(130, "VFI period", minval = 2)
coef   = input.float(0.2, "Price cutoff coefficient", minval = 0, step = 0.05)
vcoef  = input.float(2.5, "Max volume cutoff", minval = 1, step = 0.5)
smooth = input.int(3, "EMA smoothing", minval = 1)
sigLen = input.int(30, "Signal SMA length", minval = 1)
 
tp     = hlc3
inter  = math.log(tp) - math.log(tp[1])
vinter = ta.stdev(inter, 30)
cutoff = coef * vinter * close
vave   = ta.sma(volume, period)[1]
vmax   = vave * vcoef
vc     = math.min(volume, vmax)
mf     = tp - tp[1]
vcp    = mf > cutoff ? vc : mf < -cutoff ? -vc : 0.0
vfi    = ta.ema(math.sum(vcp, period) / vave, smooth)
signal = ta.sma(vfi, sigLen)
 
// Most INDEX: and TVC: symbols report no volume and would otherwise plot nothing.
cumVol = ta.cum(nz(volume))
if barstate.islast and cumVol == 0
    runtime.error("VFI needs volume data. This symbol reports none.")
 
hline(0, "Zero", color.gray, hline.style_dotted)
plot(signal, "Signal", color.orange)
plot(vfi, "VFI", vfi >= 0 ? color.green : color.red, 2)

← 返回列表