
做交易的朋友对 VWAP 一定不陌生 —— 作为经典的 “价格 - 成交量” 双维度工具,它常被用来判断市场的 “公平价值”。但老司机们都懂一个痛点:传统 VWAP 用久了会 “跑偏”,持仓时间一长,这条线就慢慢脱离实时行情,参考价值大打折扣。
图片
今天要深挖的「Dynamic Swing Anchored VWAP 」,就是 TradingView 编辑精选的 “VWAP 升级版”。它靠 “动态锚定 + 自适应调整” 解决了漂移问题,不管是日内短线还是摆动交易,都能精准抓趋势、找机会。
源码:
indicator('Dynamic Swing Anchored VWAP ', overlay = true, max_bars_back = 5000, max_labels_count = 500, max_polylines_count = 100)//~~}// ~~ Tooltips {var string t1 = 'Number of bars used to detect swing highs and lows. Larger values identify bigger, more significant swings but react slower. Smaller values detect more frequent swings but may produce more noise.'var string t2 = 'Controls how quickly the VWAP adjusts to new price action. Lower values make the VWAP react faster (tighter to price), higher values make it smoother and slower to change.'var string t3 = 'When enabled, the VWAP reaction speed changes automatically based on market volatility. High volatility shortens the tracking period (more responsive), low volatility lengthens it (smoother).'var string t4 = 'Controls how strongly volatility influences the VWAP reaction speed. Values above 1 increase the effect of volatility changes; values below 1 make it less sensitive to volatility.'var string t5 = 'Color used for swing high/low labels drawn on the chart to indicate pivot points.'var string t6 = 'Color used for swing low labels when marking pivot points.'var string t7 = 'Color used for VWAP lines when in an uptrend.'var string t8 = 'Color used for VWAP lines when in a downtrend.'var string t9 = 'Width of the VWAP lines drawn on the chart. Larger values make the lines thicker and more visible.'//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Inputs {prd = input.int(50, title='Swing Period', minval=2, group='Swing Points', tooltip=t1)baseAPT = input.float(20, 'Adaptive Price Tracking', minval=1, step=1, group='Swing Points', tooltip=t2)useAdapt = input.bool(false, 'Adapt APT by ATR ratio', group='Swing Points', tooltip=t3)volBias = input.float(10.0, 'Volatility Bias', minval=0.1, step=0.1, group='Swing Points', tooltip=t4)highS = input.color(color.lime, title='Swing Labels', group='Style', inline='Swing', tooltip=t5)lowS = input.color(color.red, title='', group='Style', inline='Swing', tooltip=t6)S = input.color(color.lime, title='VWAP Lines', group='Style', inline='VWAP', tooltip=t7)R = input.color(color.red, title='', group='Style', inline='VWAP', tooltip=t8)xx = input.int(2, minval=1, title='', group='Style', inline='VWAP', tooltip=t9)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Global Variable {b = bar_index//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ PIVOTS Variables {var ph = float(na)var pl = float(na)var phL = bvar plL = bvar lab = label(na)var prev = float(na)ph := ta.highestbars(high, prd) == 0 ? high : phpl := ta.lowestbars(low, prd) == 0 ? low : plphL := ta.highestbars(high, prd) == 0 ? b : phLplL := ta.lowestbars(low, prd) == 0 ? b : plLdir = phL > plL ? 1 : -1//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Adaptation {atrLen = 50atr = ta.atr(atrLen)atrAvg = ta.rma(atr, atrLen)ratio = atrAvg > 0 ? atr / atrAvg : 1.0aptRaw = useAdapt ? baseAPT / math.pow(ratio, volBias) : baseAPTaptClamped = math.max(5.0, math.min(300.0, aptRaw))aptSeries = math.round(aptClamped)// alpha from APT (half-life -> EWMA alpha)alphaFromAPT(apt) => decay = math.exp(-math.log(2.0) / math.max(1.0, apt)) 1.0 - decay//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ VWAP Variables {var p = hlc3 * volume var vol = volume type dataPoints array<chart.point> points polyline poly = navar vwap = dataPoints.new(array.new<chart.point>())//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Main {if dir != dir[1] x = dir > 0 ? plL : phL y = dir > 0 ? pl : ph loc = dir > 0 ? label.style_label_up : label.style_label_down col = dir > 0 ? highS : lowS txt = dir > 0 and pl < prev ? 'LL' : dir > 0 and pl > prev ? 'HL' : dir < 0 and ph < prev ? 'LH' : dir < 0 and ph > prev ? 'HH' : '' label.new(x, y, text=txt, style=loc, color=color.new(col, 20), textcolor=color.white) prev := dir > 0 ? ph[1] : pl[1] barsback = b - x p := y * volume[barsback] vol := volume[barsback] vap = p / vol vwap.poly.delete() polyline.new(vwap.points, false, false, line_color = dir < 0 ? R : S, line_width = xx) vwap.points.clear() for i = barsback to 0 by 1 apt_i = aptSeries[i] alpha = alphaFromAPT(apt_i) pxv = hlc3[i] * volume[i] v_i = volume[i] p := (1.0 - alpha) * p + alpha * pxv vol := (1.0 - alpha) * vol + alpha * v_i vappe = vol > 0 ? p / vol : na vwap.points.push(chart.point.from_index(b - i, vappe)) vwap.poly := polyline.new(vwap.points, false, false, line_color = dir < 0 ? R : S, line_width = xx)else apt_0 = aptSeries alpha = alphaFromAPT(apt_0) pxv = hlc3 * volume v0 = volume p := (1.0 - alpha) * p + alpha * pxv vol := (1.0 - alpha) * vol + alpha * v0 vap = vol > 0 ? p / vol : na vwap.poly.delete() vwap.points.push(chart.point.from_index(b, vap)) vwap.poly := polyline.new(vwap.points, false, false, line_color = dir > 0 ? R : S, line_width = xx)//~~ }一、先搞懂:为什么传统 VWAP 会 “失效”?传统 VWAP(成交量加权平均价)的核心是 “从开盘算到收盘”,按每笔成交量给价格加权。但问题出在 “静态计算” 上:要是遇上延长趋势(比如连续 3 天上涨),早期价格数据会一直拉着 VWAP 走,导致线条跟不上最新行情;多会话交易(比如跨夜持仓)时,旧数据的权重不会自动衰减,参考线逐渐 “失真”。简单说:市场在变,VWAP 却在 “吃老本”,自然没法给交易者靠谱的支撑 / 阻力参考。二、动态锚定 VWAP:解决痛点的 3 个核心目的直击传统 VWAP 的短板,目标特别明确:1. 紧跟实时行情,拒绝 “漂移”它不会从开盘死算到收盘,而是在市场关键的 “摆动点”(比如突然的高点 / 低点)自动重启计算,让 VWAP 始终贴着当前市场结构走。2. 精准标记 “公平价值路径”通过 “新数据权重高、旧数据权重低” 的衰减模型,算出的 VWAP 更能反映当下的真实供需平衡,相当于给价格画了条 “合理跑道”。3. 捕捉两类核心交易机会回撤机会:趋势中价格回踩动态 VWAP 时,往往是加仓 / 入场的好节点;均值回归:价格偏离 VWAP 过远时,指标会发出 “回归信号”,适合做反转交易。三、双引擎驱动!指标工作原理大揭秘这款指标的厉害之处,在于内置了两个 “核心引擎”,协同实现动态跟踪 ——引擎 1:摆动锚定引擎(Swing Anchor Engine)相当于指标的 “眼睛”,负责找对计算的 “起点”:扫描识别:根据你设置的 “摆动周期”(比如 10 根 K 线),自动在图表上找摆动高点、摆动低点;锚定重启:一旦市场方向翻转(比如从涨转跌),确认了新的 “枢轴点”,引擎会立刻在这个点 “重新打卡”,从 0 开始计算新的 VWAP;事件驱动:不是按时间算,而是按 “市场变化” 算,确保每段 VWAP 都对应最新的行情结构。举个例子:你把摆动周期设为 8 根 K 线,当价格连续涨 8 根 K 线后突然下跌,形成新的摆动高点,指标会立刻以这个高点为锚点,重启 VWAP 计算,避免被之前的上涨数据带偏。引擎 2:自适应 VWAP 核心(Adaptive VWAP Core)相当于指标的 “大脑”,负责让 VWAP “聪明起来”:1. 衰减模型加权传统 VWAP 是 “所有数据平等加权”,而它会给最近的价格 × 成交量数据加高分,旧数据的权重随着时间慢慢降低。比如今天的交易数据权重占 60%,昨天的占 30%,前天的只占 10%,越新越靠谱。2. 响应速度可调你可以自己设 “基准响应速度”(用 K 线数量表示):设低一点(比如 5 根 K 线):VWAP 跟价格贴得紧,适合日内高频交易,能快速抓短期机会;设高一点(比如 20 根 K 线):VWAP 更平滑,能过滤杂波,适合摆动交易看中期趋势。3. 波动率自动适配这是最关键的 “黑科技”—— 指标会实时算 “平均真实波动幅度(ATR)”,根据波动率调整速度:高波动时(比如原油突然暴跌、币圈插针):自动加速响应,VWAP 紧跟价格跳变,避免滞后;低波动时(比如股市横盘):自动减速,过滤小波动噪音,不让你频繁误操作。四、核心亮点:这两个特性碾压传统 VWAP这款指标能入选 TradingView 编辑精选,全靠两个 “独家优势”:1. 事件驱动锚定,参考线永远 “新鲜”传统 VWAP 是 “时间驱动”,不管市场变不变,都按固定节奏算;它是 “事件驱动”,市场一出现关键摆动点就重启,每段 VWAP 都对应 “当下的市场故事”,不存在 “过期参考” 的问题。2. 自适应响应,全市场场景通杀不管是高波动的期货、币圈,还是低波动的蓝筹股;不管是日内 T+0,还是持仓 3-5 天的摆动交易,它都能通过调整参数 + 自动适配波动率,给出贴合场景的信号。(小补充:指标最近更新了 “次要颜色修复”,但核心技术没动,不用怕升级影响使用习惯。)五、交易者怎么用?适用场景与策略建议这款指标的适用场景极广,尤其在趋势市场里效果炸裂,分享 3 个实战用法:1. 日内交易:抓趋势中的回踩机会用法:当价格沿趋势上涨(下跌),动态 VWAP 会跟着向上(向下)走,一旦价格短暂回踩这条线,且不跌破(突破),就是加仓入场点;逻辑:VWAP 是 “公平价值线”,趋势中价格回踩公平价值,大概率会继续沿趋势走。2. 摆动交易:找趋势延续信号用法:设置较高的响应速度(比如 15 根 K 线),让 VWAP 更平滑,当价格突破前期高点 / 低点,新锚定的 VWAP 跟着抬头 / 低头,说明趋势确认,可持仓跟进;优势:比传统 VWAP 更早确认趋势转向,避免错过大行情。3. 震荡市场:抓均值回归机会用法:当价格偏离动态 VWAP 过远(比如超过 2 倍 ATR),且指标颜色开始变(提示回归),可以做 “高抛低吸”;注意:只适合震荡行情,趋势中别硬做反转,容易被趋势拍死。 本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。658配资提示:文章来自网络,不代表本站观点。