
本策略通过整合VoVix(波动率之波动率)异常检测、价格结构聚类分析和临界点逻辑三大核心模块,构建了一个多因子协同的量化交易系统。策略采用快慢双速ATR比率计算波动率变化率,结合Z-Score标准化构建VoVix指标,在检测到真实的波动率制度转换信号后,还需通过价格结构聚类验证和关键点确认,最终结合自适应仓位管理和时段过滤机制执行交易。系统特别强调多因子验证机制,有效区分随机波动与真实制度转换,在保证信号质量的同时控制交易频率。
VoVix核心引擎:
双重验证机制:
动态仓位管理:
智能时段控制:
市场结构突变风险:当波动率产生机制发生根本性改变时(如监管政策突变),历史参数可能失效
黑天鹅事件冲击:极端行情下波动率指标可能出现钝化
时段依赖风险:严格时段控制可能错过重大隔夜行情
参数过拟合风险:多参数系统存在曲线拟合隐忧
机器学习增强:
波动率建模升级:
动态时段优化:
风险控制增强:
本策略通过创新的VoVix量化框架,构建了制度转换检测-价格结构验证-动态风险管理三位一体的交易系统。其核心价值在于将学术界的波动率聚类理论转化为可执行的交易信号,并通过严谨的多因子验证机制控制过度交易倾向。未来可通过引入机器学习模块和更精细的波动率建模持续提升策略效能,同时保持风险控制的透明性和可解释性。
/*backtest
start: 2024-05-16 00:00:00
end: 2025-05-14 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("The VoVix Experiment", default_qty_type=strategy.fixed, initial_capital=10000, overlay=true, pyramiding=1)
// === VOLATILITY CLUSTERING ===
input_vol_cluster = input(true, '🌀 Enable Volatility Clustering', tooltip="Enable volatility clustering filter. Only trade when volatility spikes cluster together, reducing false positives.", group="Volatility Clustering")
vc_window = input.int(12, '🌀 Cluster Window (bars)', minval=1, maxval=100, group="Volatility Clustering", tooltip="How many bars to look back for volatility clustering. Lower = more sensitive, higher = only major clusters trigger.")
vc_spike_mult = input.float(1.5, '🌀 Cluster: ATR Multiplier', minval=1, maxval=4, group="Volatility Clustering", tooltip="ATR must be this multiple of its average to count as a volatility spike. Higher = only extreme events, lower = more signals.")
vc_spike_count = input.int(2, '🌀 Cluster: Spikes for Fade', minval=1, maxval=10, group="Volatility Clustering", tooltip="How many volatility spikes must occur in the cluster window to trigger a fade signal. Higher = rarer, stronger signals.")
// === CRITICAL POINT ===
input_crit_point = input(true, '🎯 Enable Critical Point Detector', tooltip="Enable critical point filter. Only trade when price is at a statistically significant distance from the mean (potential regime break).", group="Critical Point")
cp_window = input.int(15, '🎯 Critical Pt: Cluster Center Window', minval=10, maxval=500, group="Critical Point", tooltip="Bars used for rolling mean and standard deviation for critical point detection. Longer = smoother, shorter = more reactive.")
cp_distance_mult = input.float(2.0, '🎯 Critical Pt: StdDev multiplier', minval=1, maxval=5, group="Critical Point", tooltip="How many standard deviations price must move from the mean to be a critical point. Higher = only extreme moves, lower = more frequent signals.")
cp_volatility_mult = input.float(1.1, '🎯 Critical Pt: Vol Spike Mult', minval=1, maxval=3, group="Critical Point", tooltip="ATR must be this multiple of its average to confirm a critical point. Higher = stronger confirmation, lower = more trades.")
// === VOVIX REGIME ENGINE ===
input_vovix = input(true, '⚡ Enable VoVix Regime Execution', tooltip="Enable the VoVix anomaly detector. Only trade when a volatility-of-volatility spike is detected.", group="VoVix")
vovix_fast_len = input.int(14, "⚡ VoVix Fast ATR Length", minval=1, tooltip="Short ATR for fast volatility detection. Lower = more sensitive.", group="VoVix")
vovix_slow_len = input.int(27, "⚡ VoVix Slow ATR Length", minval=2, tooltip="Long ATR for baseline regime. Higher = more stable.", group="VoVix")
vovix_z_window = input.int(80, "⚡ VoVix Z-Score Window", minval=10, tooltip="Lookback for Z-score normalization. Higher = smoother, lower = more reactive.", group="VoVix")
vovix_entry_z = input.float(1.2, "⚡ VoVix Entry Z-Score", minval=0.5, tooltip="Minimum Z-score for a VoVix spike to trigger a trade.", group="VoVix")
vovix_exit_z = input.float(1.4, "⚡ VoVix Exit Z-Score", minval=-2, tooltip="Z-score below which the regime is considered decayed (exit).", group="VoVix")
vovix_local_max = input.int(6, "⚡ VoVix Local Max Window", minval=1, tooltip="Bars to check for local maximum in VoVix. Higher = stricter.", group="VoVix")
vovix_super_z = input.float(2.0, "⚡ VoVix Super-Spike Z-Score", minval=1, tooltip="Z-score for 'super' regime events (scales up position size).", group="VoVix")
// === TIME SESSION ===
session_start = input.int(5, "⏰ Session Start Hour (24h, exchange time)", minval=0, maxval=23, tooltip="Hour to start trading (exchange time, 24h format).", group="Session")
session_end = input.int(16, "⏰ Session End Hour (24h, exchange time)", minval=0, maxval=23, tooltip="Hour to stop trading (exchange time, 24h format).", group="Session")
allow_weekend = input(false, "📅 Allow Weekend Trading?", tooltip="Enable to allow trades on weekends.", group="Session")
session_timezone = input.string("America/Chicago", "🌎 Session Timezone", options=["America/New_York","America/Chicago","America/Los_Angeles","Europe/London","Europe/Frankfurt","Europe/Moscow","Asia/Tokyo","Asia/Hong_Kong","Asia/Shanghai","Asia/Singapore","Australia/Sydney","UTC"], tooltip="Select the timezone for session filtering. Choose the exchange location that matches your market (e.g., America/Chicago for CME, Europe/London for LSE, Asia/Tokyo for TSE, etc.).", group="Session")
// === SIZING ===
min_contracts = input.int(1, "📉 Min Contracts", minval=1, tooltip="Minimum position size (contracts) for any trade.", group="Adaptive Sizing")
max_contracts = input.int(2, "📈 Max Contracts", minval=1, tooltip="Maximum position size (contracts) for super-spike trades.", group="Adaptive Sizing")
// === VISUALS ===
show_labels = input(true, "🏷️ Show Trade Labels", tooltip="Show/hide entry/exit labels on chart.", group="Visuals")
glowOpacity = input.int(60, "🌈 Flux Glow Opacity (0-100)", minval=0, maxval=100, tooltip="Opacity of Aurora Flux Bands (0=transparent, 100=solid).", group="Visuals")
flux_ema_len = input.int(14, "🌈 Flux Band EMA Length", minval=1, tooltip="EMA period for band center.", group="Visuals")
flux_atr_mult = input.float(1.8, "🌈 Flux Band ATR Multiplier", minval=0.1, tooltip="Width of bands (higher = wider).", group="Visuals")
// === LOGIC ===
// --- VoVix Calculation --- //
fastATR = ta.atr(vovix_fast_len)
slowATR = ta.atr(vovix_slow_len)
voVix = fastATR / slowATR
voVix_avg = ta.sma(voVix, vovix_z_window)
voVix_std = ta.stdev(voVix, vovix_z_window)
voVix_z = voVix_std > 0 ? (voVix - voVix_avg) / voVix_std : 0
// VoVix regime logic
is_vovix_spike = voVix_z > vovix_entry_z and voVix == ta.highest(voVix, vovix_local_max)
is_vovix_super = voVix_z > vovix_super_z
is_vovix_exit = voVix_z < vovix_exit_z
// --- Adaptive Sizing (VoVix strength) --- //
adaptive_contracts = is_vovix_super ? max_contracts : min_contracts
// --- Cluster/Critical Point Logic --- //
atr = ta.atr(14)
spike = atr > (vc_spike_mult * ta.sma(atr, vc_window))
var float[] spike_vals = array.new_float(vc_window, 0)
if bar_index > vc_window
array.unshift(spike_vals, spike[1] ? 1.0 : 0.0)
if array.size(spike_vals) > vc_window
array.pop(spike_vals)
spike_count = array.sum(spike_vals)
clustered_chop = spike_count >= vc_spike_count and input_vol_cluster
cluster_mean = ta.sma(close, cp_window)
cluster_stddev = ta.stdev(close, cp_window)
dist_from_center = math.abs(close[1] - cluster_mean[1])
is_far = dist_from_center > (cp_distance_mult * cluster_stddev[1])
vol_break = atr[1] > (cp_volatility_mult * ta.sma(atr, cp_window)[1])
critical_point = is_far and vol_break and input_crit_point
// --- TIME BLOCK LOGIC --- //
bar_hour = hour(time, session_timezone)
bar_dow = dayofweek(time, session_timezone)
in_session = (session_start < session_end ? (bar_hour >= session_start and bar_hour < session_end) : (bar_hour >= session_start or bar_hour < session_end))
not_weekend = allow_weekend or (bar_dow != dayofweek.saturday and bar_dow != dayofweek.sunday)
trade_allowed = in_session and not_weekend
// --- CONFLUENCE LOGIC: Only trade when VoVix AND (Cluster OR Critical) agree AND in session --- //
confluence = input_vovix and is_vovix_spike and (critical_point or clustered_chop) and trade_allowed
// --- TRADE HANDLER --- //
long_signal = false
short_signal = false
trade_reason = ""
if confluence
long_signal := close > open
short_signal := close < open
trade_reason := "VoVix + " + (critical_point ? "Critical" : "Cluster")
// --- EXECUTION --- //
if long_signal
strategy.entry("VoVixLong", strategy.long, qty=adaptive_contracts, comment=trade_reason)
if short_signal
strategy.entry("VoVixShort", strategy.short, qty=adaptive_contracts, comment=trade_reason)
// VoVix regime exit
if input_vovix and is_vovix_exit
strategy.close("VoVixLong", comment="VoVix Regime Exit")
strategy.close("VoVixShort", comment="VoVix Regime Exit")
// --- REGIME DECAY ZONE AREA (Watermark) --- //
var float decay_zone_start = na
regime_decay_condition = is_vovix_exit
decay_confirmed = not is_vovix_exit
if regime_decay_condition and na(decay_zone_start)
decay_zone_start := bar_index
if decay_confirmed
decay_zone_start := na
show_decay_area = not na(decay_zone_start)
// === AURORA FLUX BANDS (Volatility/Divergence Bands) ===
basis = ta.ema(close, flux_ema_len)
flux_atr = ta.atr(14)
upperBand = basis + flux_atr * flux_atr_mult
lowerBand = basis - flux_atr * flux_atr_mult
color glowColor = na
if long_signal and not short_signal
glowColor := color.new(color.green, glowOpacity)
else if short_signal and not long_signal
glowColor := color.new(color.red, glowOpacity)
else if strategy.position_size > 0
glowColor := color.new(color.lime, math.max(0, glowOpacity * 0.8 + 10))
else if strategy.position_size < 0
glowColor := color.new(color.red, math.max(0, glowOpacity * 0.8 + 10))
else
glowColor := color.new(color.gray, glowOpacity)
upperPlot = plot(upperBand, 'Upper Flux', color=glowColor, linewidth=3, style=plot.style_line)
lowerPlot = plot(lowerBand, 'Lower Flux', color=glowColor, linewidth=3, style=plot.style_line)
plot(upperBand + flux_atr * 0.15, 'Upper Flux Glow 1', color=color.new(glowColor, math.max(0, glowOpacity * 0.7 + 15)), linewidth=4, style=plot.style_line)
plot(upperBand - flux_atr * 0.15, 'Upper Flux Glow 2', color=color.new(glowColor, math.max(0, glowOpacity * 0.7 + 15)), linewidth=2, style=plot.style_line)
plot(lowerBand + flux_atr * 0.15, 'Lower Flux Glow 1', color=color.new(glowColor, math.max(0, glowOpacity * 0.7 + 15)), linewidth=2, style=plot.style_line)
plot(lowerBand - flux_atr * 0.15, 'Lower Flux Glow 2', color=color.new(glowColor, math.max(0, glowOpacity * 0.7 + 15)), linewidth=4, style=plot.style_line)
fill(upperPlot, lowerPlot, color=color.new(glowColor, math.max(0, glowOpacity > 0 ? 85 : 0)), title='Volatility/Divergence Bands')
// --- VISUALS --- //
if show_labels and (long_signal or short_signal)
label.new(bar_index, high, trade_reason, color=color.new(long_signal ? color.green : color.red, 40), style=label.style_label_down)
bgcolor(
is_vovix_super ? color.new(color.purple, 90) :
is_vovix_spike ? color.new(color.blue, 95) :
critical_point ? color.new(color.yellow,90) :
clustered_chop ? color.new(color.orange,93) :
na)
plotshape(long_signal, style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small, title="Long")
plotshape(short_signal, style=shape.triangledown,location=location.abovebar, color=color.red, size=size.small, title="Short")
// --- REAL-TIME SHARPE / SORTINO CALCULATION ---
var float[] returns = array.new_float()
if strategy.closedtrades > nz(strategy.closedtrades[1])
profit = strategy.closedtrades > 0 ? (strategy.netprofit - nz(strategy.netprofit[1])) : na
if not na(profit)
array.unshift(returns, profit)
if array.size(returns) > 100
array.pop(returns)
float sharpe = na
float sortino = na
if array.size(returns) > 1
avg = array.avg(returns)
stdev = array.stdev(returns)
float[] downside_list = array.new_float()
for i = 0 to array.size(returns) - 1
val = array.get(returns, i)
if val < 0
array.push(downside_list, val)
downside_stdev = array.size(downside_list) > 0 ? array.stdev(downside_list) : na
sharpe := stdev != 0 ? avg / stdev : na
sortino := downside_stdev != 0 ? avg / downside_stdev : na