The Relative Volatility Index (RVI) is a technical indicator that is a modified version of the Relative Strength Index (RSI). It measures the direction of volatility by calculating the standard deviation of closing prices over the past 10 days to determine market trends and strength.
The core logic of this strategy is:
Calculate the standard deviation of closing prices over the past 10 days, StdDev.
Calculate the part of closing prices that are higher than the previous day over the past 10 days, u.
Calculate the part of closing prices that are lower than the previous day over the past 10 days, d.
Use exponential smoothing to calculate the 14-day exponential moving average of u and d, nU and nD.
Calculate the ratio of nU and nD, then multiply by 100 to get the volatility index nRes.
Go short when nRes is lower than the buy zone, and go long when nRes is higher than the sell zone.
The buy and sell zone parameters and reverse trading can be set in the code.
By comparing the difference between upside and downside volatility over the past 10 days, the strategy judges the likely direction of the next market move. When upside volatility is greater, it is a bullish signal, and when downside volatility is greater, it is a bearish signal.
The RVI backtesting strategy has the following advantages:
Using standard deviation of closing prices to measure volatility better reflects market fluctuation information than just prices.
The calculation method is simple and clear, easy to understand and implement.
The buy and sell signals generated are clear, no need for secondary judgment.
The buy and sell zone parameters can be flexibly set to adjust strategy sensitivity.
Support for reverse trading, can be used in different types of markets.
Visualized display of indicator line and trading zones forms intuitive trading signals.
Backtesting has verified the effectiveness of this strategy.
This strategy also has some risks:
Buy and sell signals may have false signals, should combine trend and support/resistance analysis.
Only considers closing price volatility, cannot reflect intraday price action.
Improper parameter settings may lead to over-trading or lower returns.
Transaction costs in live trading will affect final return.
Risk of loss is greater in reverse trading mode.
The strategy can be optimized in the following aspects:
Combine with other technical indicators to filter false signals, like MACD, KD etc.
Add dynamic adjustment of position sizing.
Optimize the buy and sell zone ranges for more accurate signals.
Add stop loss mechanisms to control single trade loss.
Reduce position sizing in high volatility conditions.
Test different indicator parameter settings, like calculation periods, smoothing parameters etc.
The RVI backtesting strategy judges market direction by comparing upside/downside volatility, implementing a simple and intuitive trend following strategy. The advantages are clear logic, easy implementation, good backtesting results. It can be improved through proper optimizations. Still need risk control in live trading, and combine other indicators to verify signals. Overall this strategy provides a valuable idea for quantitative trading.
/*backtest start: 2023-08-26 00:00:00 end: 2023-09-19 00:00:00 period: 4h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 //////////////////////////////////////////////////////////// // Copyright by HPotter v1.0 23/10/2017 // The RVI is a modified form of the relative strength index (RSI). // The original RSI calculation separates one-day net changes into // positive closes and negative closes, then smoothes the data and // normalizes the ratio on a scale of zero to 100 as the basis for the // formula. The RVI uses the same basic formula but substitutes the // 10-day standard deviation of the closing prices for either the up // close or the down close. The goal is to create an indicator that // measures the general direction of volatility. The volatility is // being measured by the 10-days standard deviation of the closing prices. // // You can change long to short in the Input Settings // WARNING: // - For purpose educate only // - This script to change bars colors. //////////////////////////////////////////////////////////// strategy(title="Relative Volatility Index", shorttitle="RVI") Period = input(10, minval=1) BuyZone = input(30, minval=1) SellZone = input(70, minval=1) reverse = input(false, title="Trade reverse") hline(0, color=purple, linestyle=hline.style_dashed) hline(BuyZone, color=red, linestyle=hline.style_solid) hline(SellZone, color=green, linestyle=hline.style_solid) xPrice = close StdDev = stdev(xPrice, Period) d = iff(close > close[1], 0, StdDev) u = iff(close > close[1], StdDev, 0) nU = (13 * nz(nU[1],0) + u) / 14 nD = (13 * nz(nD[1],0) + d) / 14 nRes = 100 * nU / (nU + nD) pos = iff(nRes < BuyZone, -1, iff(nRes > SellZone, 1, nz(pos[1], 0))) possig = iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos)) if (possig == 1) strategy.entry("Long", strategy.long) if (possig == -1) strategy.entry("Short", strategy.short) barcolor(possig == -1 ? red: possig == 1 ? green : blue ) plot(nRes, color=red, title="RVI")template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6