这是一个基于成交量加权平均价格(VWAP)和Garman-Klass波动率(GKV)的自适应交易策略。该策略通过波动率动态调整VWAP的标准差波段,实现对市场趋势的智能跟踪。当价格突破上轨时开仓做多,突破下轨时平仓,波动率越大突破门槛越高,波动率越小突破门槛越低。
策略的核心是将VWAP与GKV波动率相结合。首先计算VWAP作为价格中枢,然后利用收盘价的标准差构建波段。关键在于使用GKV公式计算波动率,其考虑了开高低收四个价格,比传统波动率更准确。波动率会动态调整波段宽度 - 当波动率升高时,波段变宽,提高突破门槛;当波动率降低时,波段变窄,降低突破门槛。这种自适应机制有效避免了虚假突破。
该策略通过将VWAP与GKV波动率创新结合,实现了对市场的动态跟踪。其自适应特性使其在不同市场环境下都能保持稳定表现。虽然存在一些潜在风险,但通过合理的风险控制和持续优化,策略具有良好的应用前景。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Adaptive VWAP Bands with Garman Klass Volatility", overlay=true)
// Inputs
length = input.int(25, title="Volatility Length")
vwapLength = input.int(14, title="VWAP Length")
vol_multiplier = input.float(1,title="Volatility Multiplier")
// Function to calculate Garman-Klass Volatility
var float sum_gkv = na
if na(sum_gkv)
sum_gkv := 0.0
sum_gkv := 0.0
for i = 0 to length - 1
sum_gkv := sum_gkv + 0.5 * math.pow(math.log(high[i]/low[i]), 2) - (2*math.log(2)-1) * math.pow(math.log(close[i]/open[i]), 2)
gcv = math.sqrt(sum_gkv / length)
// VWAP calculation
vwap = ta.vwma(close, vwapLength)
// Standard deviation for VWAP bands
vwapStdDev = ta.stdev(close, vwapLength)
// Adaptive multiplier based on GCV
multiplier = (gcv / ta.sma(gcv, length)) * vol_multiplier
// Upper and lower bands
upperBand = vwap + (vwapStdDev * multiplier)
lowerBand = vwap - (vwapStdDev * multiplier)
// Plotting VWAP and bands
plot(vwap, title="VWAP", color=color.blue, linewidth=2)
plot(upperBand, title="Upper Band", color=color.green, linewidth=1)
plot(lowerBand, title="Lower Band", color=color.red, linewidth=1)
var barColor = color.black
// Strategy: Enter long above upper band, go to cash below lower band
if (close > upperBand)
barColor := color.green
strategy.entry("Long", strategy.long)
else if (close < lowerBand)
barColor := color.fuchsia
strategy.close("Long")
barcolor(barColor)