This is an adaptive trading strategy based on Volume Weighted Average Price (VWAP) and Garman-Klass Volatility (GKV). The strategy dynamically adjusts the standard deviation bands of VWAP through volatility to achieve intelligent market trend tracking. It opens long positions when price breaks above the upper band and closes positions when breaking below the lower band, with higher volatility leading to higher breakout thresholds and lower volatility leading to lower thresholds.
The core of the strategy combines VWAP with GKV volatility. It first calculates VWAP as the price pivot, then builds bands using the standard deviation of closing prices. The key is using the GKV formula for volatility calculation, which considers four price points (open, high, low, close) and is more accurate than traditional volatility measures. Volatility dynamically adjusts band width - when volatility increases, bands widen, raising breakout thresholds; when volatility decreases, bands narrow, lowering breakout thresholds. This adaptive mechanism effectively avoids false breakouts.
The strategy achieves dynamic market tracking through innovative combination of VWAP and GKV volatility. Its adaptive nature enables stable performance across different market environments. While there are some potential risks, the strategy shows good application prospects through proper risk control and continuous optimization.
/*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)