
#### Overview
The Volume-Volatility Composite Index Trend Following Strategy is a quantitative trading system based on the relationship between trading volume and price volatility. This strategy creates a composite index by calculating the interrelationship between trading volume and price fluctuations to capture market momentum changes, while confirming trend direction through short-term and long-term moving average crossovers. Its core lies in identifying key market turning points where trading volume abnormally increases accompanied by expanded price volatility, while also utilizing Fibonacci ratios to manage risk and profit targets. This system can be used for both trend following and, through the reversal mode setting, for adding positions during trends, achieving a flexible trading strategy adaptable to different market environments.
The core calculation logic of this strategy includes the following key steps:
Volume Analysis: Uses Simple Moving Average (SMA) to calculate volume average (vol_ma), and compares current volume with the average to obtain a percentage indicator (vol_percent = volume / vol_ma * 100).
Volatility Calculation: Quantifies price volatility by calculating the ratio of the candlestick range to the closing price (volatility = (high - low) / close * 100).
Composite Index Construction: Multiplies volume percentage by volatility to create a composite indicator (volatility_index = volume * volatility), which simultaneously reflects both volume and price volatility anomalies.
Moving Average System: Calculates short-term (index_short_ma) and long-term (index_long_ma) moving averages of the composite index, and applies a sensitivity magnification factor (index_magnification) to increase signal sensitivity.
Dynamic Threshold: Constructs a dynamic filtering threshold by multiplying the long-term moving average by a threshold magnification factor (index_threshold_magnification), used to filter market noise.
Pattern Recognition: Analyzes a specified number of lookback_bars to detect specific reversal pattern formations, triggering signals when the volatility index shows specific trend changes and price formations meet reversal conditions.
Signal Generation:
Risk Management: Automatically sets take-profit (take_profit) and stop-loss (stop_loss) levels based on Fibonacci ratios, calculated using pattern amplitude (bearish_range), ensuring reasonable risk-reward ratios.
Comprehensive Indicator Advantage: By combining trading volume with volatility, this strategy can more comprehensively capture abnormally active market points, avoiding the potential misleading of single indicators.
Dynamic Adaptability: Adopts a dynamic threshold mechanism (index_threshold_magnification_auto), enabling the strategy to self-adapt to volatility characteristics under different market conditions, reducing false signals.
Pattern Confirmation Mechanism: Enhances signal reliability by retrospectively analyzing candlestick patterns through the lookback_bars parameter, requiring not only indicator crossovers but also compatible price formations, significantly reducing false breakout risks.
Flexible Strategy Modes: Can switch between trend-following and reversal strategies through the reversal_s parameter, allowing the system to adapt to different market environments and trading needs.
Systematic Risk Management: Stop-loss and take-profit mechanisms based on Fibonacci levels automatically adjust risk parameters according to actual market volatility ranges, avoiding the inflexibility that can come with fixed levels.
Intuitive Visualization: The strategy provides visualization of volume bars and indicator curves, making trading signals clear and intuitive, facilitating traders’ understanding of market conditions and decision-making bases.
Adjustable Parameters: Offers multiple adjustable parameters (vol_length, index_short_length, index_long_length, etc.), allowing traders to customize settings based on different market characteristics and personal risk preferences.
Parameter Sensitivity Risk: The strategy depends on multiple parameter settings, such as volume moving average length (vol_length), index moving average lengths (index_short_length, index_long_length), etc. Improper parameter selection may lead to overfitting or signal delays. Solution: Conduct historical backtesting optimization to find parameter combinations that perform stably under different market environments, avoiding over-optimization for specific time periods.
False Breakout Risk: Although the strategy has a dynamic threshold filtering mechanism, situations where the index briefly breaks through the threshold and quickly retreats may still occur in highly volatile markets. Solution: Increase signal confirmation periods, or combine with other technical indicators (such as RSI, MACD) for multiple confirmations to improve signal reliability.
Improper Stop-Loss Range Risk: Fibonacci-based stop-loss settings may be insufficient to protect capital safety in extremely volatile markets. Solution: Add maximum stop-loss percentage limits, or dynamically adjust the stopLossFib parameter based on historical volatility, ensuring risk is controlled within acceptable ranges.
Trend Judgment Error Risk: In consolidating or oscillating markets, moving average crossover signals may appear frequently, leading to excessive trading. Solution: Introduce trend strength indicators (such as ADX) to filter signals in weak trend markets, or add trading frequency limitation conditions.
Liquidity Risk: The strategy is sensitive to volume changes and may produce erroneous signals or face slippage issues in low liquidity markets. Solution: Add minimum volume threshold conditions to avoid trading in low liquidity environments, or adjust the index sensitivity (index_magnification) to reduce reactions to minor fluctuations.
Out-of-Sample Performance Risk: The strategy may perform well on historical data, but future market condition changes may lead to performance degradation. Solution: Use out-of-sample testing and forward testing methods, periodically reassess and adjust strategy parameters to maintain strategy adaptability.
Multi-Timeframe Confirmation Mechanism: The current strategy operates only within a single timeframe. Introducing a multi-timeframe analysis framework requiring higher timeframe trend direction to align with trading signals would improve win rates. This would avoid counter-trend operations in major trends, reducing the risk of being “crushed”.
Market State Classification Processing: Add market state classification mechanisms (trending/oscillating markets) to automatically adjust strategy parameters or trading rules according to different market states. For example, market states can be determined through ATR or volatility indicators, raising threshold requirements in high-volatility environments and relaxing conditions in low-volatility environments.
Machine Learning Parameter Optimization: Introduce machine learning algorithms to dynamically optimize strategy parameters, such as using genetic algorithms or reinforcement learning methods to find optimal parameter combinations, enabling the strategy to self-adapt to market changes.
Sentiment Indicator Integration: Integrate market sentiment indicators (such as VIX, fund flows, etc.) into the signal generation logic to enhance the ability to predict market turning points. Market sentiment often leads price movements, and combining sentiment indicators can capture market turning signals in advance.
Take-Profit Strategy Optimization: Implement a partial profit-taking mechanism, taking profits in batches according to the Fibonacci sequence, both securing partial profits and allowing remaining positions to fully benefit from trend returns. For example, different position percentages could be closed at the 0.382, 0.618, 1.0, 1.618 levels, etc.
Trading Cost Consideration: The current strategy does not consider trading costs. Adding trading cost calculation logic would ensure that the expected returns from signals exceed trading costs, avoiding cost erosion from frequent small trades.
Risk Position Management: Add a dynamic position sizing module to automatically calculate optimal position sizes based on historical volatility, current signal strength, and account risk tolerance, implementing more scientific fund management.
Correlation Filtering: In multi-asset trading scenarios, add a correlation analysis module to avoid simultaneously establishing same-direction positions in highly correlated multiple assets, reducing systemic risk.
The Volume-Volatility Composite Index Trend Following Strategy innovatively combines trading volume and price volatility indicators to build a quantitative trading system capable of capturing market momentum changes. This strategy excels in identifying potential turning points and trend confirmations, while providing flexible trading execution mechanisms through Fibonacci take-profit and stop-loss management and optional reversal modes.
The core advantages of the strategy lie in its comprehensive indicator system and dynamic adaptability, capable of identifying high-quality trading opportunities in different market environments. However, users need to be vigilant about potential risks such as parameter sensitivity, false breakouts, and trend judgment errors, and can further enhance the strategy’s stability and adaptability through multi-timeframe confirmation, market state classification, machine learning optimization, and other approaches.
With reasonable parameter settings and continuous optimization, this strategy can be a powerful weapon in a trader’s toolkit, particularly suitable for finding market turning points where trading volume and price volatility anomalies coincide, helping traders capture key trading opportunities in complex and changing markets.
/*backtest
start: 2024-05-26 00:00:00
end: 2025-05-25 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"SOL_USDT"}]
*/
//@version=6
strategy("Volume and Volatility Ratio Indicator-WODI", overlay=false)
// === 用户自定义参数 ===
vol_length = input(48, title="交易量均线长度") // 交易量均线长度
index_short_length = input(13, title="指数短均线长度") // 交易量均线长度
index_long_length = input(26, title="指数均线长度") // 交易量均线长度
index_magnification = input(2, title="指数均线敏感度") // 调整指数倍率
index_threshold_magnification = input(200, title="指数阈值百分比") // 交易量/波动率指数阈值
lookback_bars = input(3, title="K线形态检测长度") // 形态检测 K 线数量
reversal_s = input.bool(title = "反转策略", defval = false, group="Position")
stopLossFib = input.float(title="止损斐波那契", defval=0, options=[0, 0.127, 0.236, 0.382, 0.5, 0.618, 0.692, 0.786, 1, 1.272, 1.414, 1.618, 2.272, 2.414, 2.618, 3, 3.414, 3.618, 4, 4.236, 4.272, 4.414, 5], group="Position")
takeProfitFib = input.float(title="止盈斐波那契", defval=1.618, options=[0, 0.127, 0.236, 0.382, 0.5, 0.618, 0.692, 0.786, 1, 1.272, 1.414, 1.618, 2.272, 2.414, 2.618, 3, 3.414, 3.618, 4, 4.236, 4.272, 4.414, 5], group="Position")
// === 计算交易量均线 ===
vol_ma = ta.sma(volume, vol_length)
// === 计算当前交易量为平均交易量的百分比 ===
vol_percent = volume / vol_ma * 100
// === 计算波动率(当前 K 线振幅) ===
volatility = (high - low) / close * 100
// === 计算交易量/波动率指数 ===
new_module = ((volume*volume)/volatility) //新算法,不好用
volatility_index = volume*volatility //
// === 计算指数平均值,用平均值做触发阈值 ===
index_short_ma = ta.sma(volatility_index, index_short_length)
index_long_ma = ta.sma(volatility_index, index_long_length)
index_threshold_magnification_auto = index_long_ma * index_threshold_magnification /100
// === 计算前 lookback_bars 根 K 线的指数趋势 ===
is_reversal_pattern = false
is_reversal_pattern_s = false
for i = 1 to lookback_bars
if volatility_index[1] > volatility_index[2] and (volatility_index[1] > volatility_index[0] or volume[1] > volume[0])and close[i+1] > close[i] and close[1] < close[0] and volume > vol_ma and volatility_index > index_threshold_magnification_auto and ((open[1] - close[1] < close[1] - low[1]) or (open[0] - close[0] < close[0] - low[0]))
if i >= lookback_bars
is_reversal_pattern := true
else if i < lookback_bars
break
for i = 1 to lookback_bars
if volatility_index[1] > volatility_index[2] and (volatility_index[1] > volatility_index[0] or volume[1] > volume[0])and close[i+1] < close[i] and close[1] > close[0] and volume > vol_ma and volatility_index > index_threshold_magnification_auto and ((close[1] - open[1] < high[1] - close[1]) or (close[0] - open[0] < high[0] - close[0]))
if i >= lookback_bars
is_reversal_pattern_s := true
else if i < lookback_bars
break
// === 绘制指标 ===
//plot(vol_ma, color=color.rgb(158, 161, 170), linewidth = 1, title="交易量均线")
//plot(index_short_ma * index_magnification, color=color.gray, linewidth = 1, title="指数短均线")
//plot(index_long_ma * index_magnification, color=#2ad7f6, linewidth = 1, title="指数长均线")
plot(index_threshold_magnification_auto, color=color.rgb(238, 66, 193), linewidth = 1, title="波动率阈值")
// === 交易量柱状图(高亮大于均值的交易量) ===
bar_color = volume > vol_ma ? (is_reversal_pattern? #bc2af6 : (is_reversal_pattern_s? #f22a2a : color.rgb(77, 231, 255, 37))) : color.rgb(120, 123, 134, 70)
plot(volatility_index*2, style=plot.style_columns, color=bar_color, title="交易量柱状图")
plot(volume, style=plot.style_stepline, color=#00000055, title="交易量")
// === 反转做多策略 ===
var float stop_loss = na
var float take_profit = na
if is_reversal_pattern and (reversal_s ? strategy.position_size >= 0 : strategy.position_size <= 0)
bearish_low = low[1] < low[0]? low[1] : low [0]// 形态最低点
bearish_high = high[lookback_bars] > high[0] ? high[lookback_bars] : high[0]// 形态最高点
bearish_range = bearish_high - bearish_low // 形态振幅
// === 计算止损 (SL) 和止盈 (TP) ===
stop_loss := reversal_s ? bearish_high + (bearish_range * stopLossFib) : bearish_low - (bearish_range * stopLossFib) //止损斐波那契
take_profit := reversal_s ? bearish_high - (bearish_range * takeProfitFib) : bearish_low + (bearish_range * takeProfitFib) //止盈斐波那契
is_reversal_pattern := false
strategy.entry(reversal_s ? "short" : "Long", reversal_s ? strategy.short : strategy.long)
if is_reversal_pattern_s and (reversal_s ? strategy.position_size <= 0 : strategy.position_size >= 0)
bearish_low = low[lookback_bars] < low[0] ? low[lookback_bars] : low[0]// 形态低点
bearish_high = high[1] > high[0]? high[1] : high [0]// 形态高点
bearish_range = bearish_high - bearish_low // 形态振幅
// === 计算止损 (SL) 和止盈 (TP) ===
stop_loss := reversal_s ? bearish_low - (bearish_range * stopLossFib) : bearish_high + (bearish_range * stopLossFib) //止损斐波那契
take_profit := reversal_s ? bearish_low + (bearish_range * takeProfitFib) : bearish_high - (bearish_range * takeProfitFib) //止盈斐波那契
is_reversal_pattern_s := false
strategy.entry(reversal_s ? "Long" : "short", reversal_s ? strategy.long : strategy.short)
// === 止损 (SL) 和止盈 (TP) ===
if low[0] < stop_loss and strategy.position_size >= 0
strategy.close("Long", qty_percent = 100)
if high[0] > take_profit and strategy.position_size >= 0
strategy.close("Long", qty_percent = 100)
if high[0] > stop_loss and strategy.position_size <= 0
strategy.close("short", qty_percent = 100)
if low[0] < take_profit and strategy.position_size <= 0
strategy.close("short", qty_percent = 100)