相对波动指数(RVI)是一个改进自相对强弱指数(RSI)的技术指标。它通过计算10天内收盘价标准差来测量波动性的方向,从而判断市场趋势和力度。
该策略的核心逻辑是:
计算10天内的收盘价标准差StdDev。
计算10天内收盘价较前一日收高的部分u。
计算10天内收盘价较前一日收低的部分d。
使用指数平滑方法计算u和d的14日指数移动平均nU和nD。
计算nU和nD的比值,再乘以100得到波动指数nRes。
当nRes低于买入区时做空,当高于卖出区时做多。
可以在代码中设置买入区、卖出区参数,及反向交易。
该策略通过比较10天内收盘价波动性的多空差异,来判断市场下一步的可能走势。当多头波动性较大时为看涨信号,当空头波动性较大时为看跌信号。
相对波动指数回测策略具有以下优势:
使用收盘价标准差计算波动性,相比价格本身更能反映市场波动信息。
计算方法简单清晰,易于理解实现。
买卖信号生成明确,不需要二次判断。
可灵活设置买入区、卖出区参数,调整策略灵敏度。
支持反向交易,可用于不同类型市场。
可视化展示指标线和买卖区,形成直观的交易信号。
回测验证了该策略的有效性。
该策略也存在一些风险:
买卖信号可能出现误报,应结合趋势及支撑阻力判断。
仅考虑收盘价波动性,无法反映盘中价格行情。
参数设置不当可能导致过于频繁交易或收益下降。
实盘中交易成本会影响最终收益率。
反向交易模式下,亏损风险会加大。
该策略可以从以下方面进行优化:
结合其他技术指标过滤误报信号。比如MACD,KD等。
增加开仓仓位比例的动态调整。
优化买入区、卖出区的范围,使信号更准确。
增加止损机制来控制单笔亏损。
在高波动行情中降低仓位规模。
测试不同的指标参数设置。如计算天数,指数平滑参数等。
相对波动指数回测策略通过对比多空波动性来判断市场方向,实现了一个较为简单直观的趋势跟踪策略。该策略优点是逻辑清晰、易于实现,回测效果良好,可以通过适当优化来改进其交易表现。但交易中仍需注意风险控制,并结合其它指标来验证交易信号。整体来说,该策略为量化交易提供了一个有价值的思路。
/*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")