该策略融合了Renko图和相对活力指数(RVI)两个指标,目标是捕捉市场主要趋势的大部分行情。适用于比特币、恒指等主流品种。
策略使用9期ATR构建Renko砖,当收盘价格超过上一Renko砖高点时构建新砖,颜色为绿色;当收盘价格低于上一Renko砖低点时构建新砖,颜色为红色。结合RVI指标判定趋势方向。
RVI指标用于判断多头力量和空头力量的相对强度。RVI数值在0-1之间波动,高于0.5代表多头力量强于空头;低于0.5代表空头力量强于多头。当RVI上穿其平滑移动平均线时,代表空头力量减弱,多头力量增强,给出做多信号;当RVI下穿其平滑移动平均线时,代表多头力量减弱,空头力量增强,给出做空信号。
综合Renko砖方向和RVI指标的做多做空信号,进入相应的多头或空头仓位。
该策略综合了两种不同类型指标的优点,目标是抓住市场主流趋势。通过对Renko和RVI参数的优化,可以获得更高的稳定性。但任何模型都无法完美,错过一定信号在所难免,关键是要把握主要方向。使用者需要清楚评估自身的风险偏好,选择适合自己的品种和参数。
/*backtest start: 2023-01-28 00:00:00 end: 2024-02-03 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=3 strategy("Lancelot RR Strategy", overlay=false) p=9 CO=close-open HL=high-low value1 = (CO + 2*CO[1] + 2*CO[2] + CO[3])/6 value2 = (HL + 2*HL[1] + 2*HL[2] + HL[3])/6 num=sum(value1,p) denom=sum(value2,p) RVI=denom!=0?num/denom:0 RVIsig=(RVI+ 2*RVI[1] + 2*RVI[2] + RVI[3])/6 rvicloselongcondition = crossunder(RVI, RVIsig) rvicloseshortcondition = crossover(RVI, RVIsig) plot(RVI,color=green,style=line,linewidth=1) plot(RVIsig,color=red,style=line,linewidth=1) bgcolor(rvicloseshortcondition ? green : na, transp = 75) bgcolor(rvicloselongcondition ? red : na, transp = 75) ///Renko/// TF = input(title='TimeFrame', defval="D") ATRlength = input(title="ATR length", defval=9, minval=2, maxval=100) SMAlength = input(title="SMA length", defval=5, minval=2, maxval=100) SMACurTFlength = input(title="SMA CurTF length", defval=20, minval=2, maxval=100) HIGH = request.security(syminfo.tickerid, TF, high) LOW = request.security(syminfo.tickerid, TF, low) CLOSE = request.security(syminfo.tickerid, TF, close) ATR = request.security(syminfo.tickerid, TF, atr(ATRlength)) SMA = request.security(syminfo.tickerid, TF, sma(close, SMAlength)) SMACurTF = sma(close, SMACurTFlength) RENKOUP = na RENKODN = na H = na COLOR = na BUY = na SELL = na UP = na DN = na CHANGE = na RENKOUP := na(RENKOUP[1]) ? ((HIGH+LOW)/2)+(ATR/2) : RENKOUP[1] RENKODN := na(RENKOUP[1]) ? ((HIGH+LOW)/2)-(ATR/2) : RENKODN[1] H := na(RENKOUP[1]) or na(RENKODN[1]) ? RENKOUP-RENKODN : RENKOUP[1]-RENKODN[1] COLOR := na(COLOR[1]) ? white : COLOR[1] BUY := na(BUY[1]) ? 0 : BUY[1] SELL := na(SELL[1]) ? 0 : SELL[1] UP := false DN := false CHANGE := false if(not CHANGE and close >= RENKOUP[1]+H*3) CHANGE := true UP := true RENKOUP := RENKOUP[1]+ATR*3 RENKODN := RENKOUP[1]+ATR*2 COLOR := lime SELL := 0 BUY := BUY+3 if(not CHANGE and close >= RENKOUP[1]+H*2) CHANGE := true UP := true RENKOUP := RENKOUP[1]+ATR*2 RENKODN := RENKOUP[1]+ATR COLOR := lime SELL := 0 BUY := BUY+2 if(not CHANGE and close >= RENKOUP[1]+H) CHANGE := true UP := true RENKOUP := RENKOUP[1]+ATR RENKODN := RENKOUP[1] COLOR := lime SELL := 0 BUY := BUY+1 if(not CHANGE and close <= RENKODN[1]-H*3) CHANGE := true DN := true RENKODN := RENKODN[1]-ATR*3 RENKOUP := RENKODN[1]-ATR*2 COLOR := red BUY := 0 SELL := SELL+3 if(not CHANGE and close <= RENKODN[1]-H*2) CHANGE := true DN := true RENKODN := RENKODN[1]-ATR*2 RENKOUP := RENKODN[1]-ATR COLOR := red BUY := 0 SELL := SELL+2 if(not CHANGE and close <= RENKODN[1]-H) CHANGE := true DN := true RENKODN := RENKODN[1]-ATR RENKOUP := RENKODN[1] COLOR := red BUY := 0 SELL := SELL+1 plotshape(UP, style=shape.arrowup, location=location.bottom, size=size.normal) renkolongcondition = UP renkoshortcondition = DN ///Long Entry/// longcondition = UP if (longcondition) strategy.entry("Long", strategy.long) ///Long exit/// closeconditionlong = rvicloselongcondition if (closeconditionlong) strategy.close("Long")