【七分鐘精通 RSI 下】100%有效RSI背离策略全分享|高勝率RSI背離策略|利用RSI抄底逃頂
我们知道RSI作为震荡指标,超买和超卖功能仅在震荡区间有效,但是如果遇到强势单边行情,RSI会一直超买或者一直超卖。
不少朋友在震荡区间使用RSI养成了习惯,一看到超买就立刻做空,一看到超卖就立刻做多,当趋势来临时候依旧如此,造成了巨大的亏损。
每次到这个时候,不少交易者就开始觉得是指标不好用。指标是庄家骗人的工具啊,指标都是延迟的。
技术指标绝对不是交易的灵丹妙药,它最本质的功能是过滤掉随机价格波动噪音,而80%的价格波动不具备任何交易价值。在噪音里折腾只能是换着姿势来回挨打。
其次,我们作为人的时间精力有限,且尤其讨厌做机械重复的活儿。而技术指标就是帮助人进行机械重复过滤价格噪音的工具,通过技术指标使得交易者能够用有限的时间和精力抓住有效的机会。
回到主题,本期我们给大家介绍一个关于RSI的经典进阶策略——RSI背离。这个概念相信很多人都听说过,各种交易老师尤其偏好。
背离,乍一听是一个非常晦涩的词汇,让人摸不着头脑。
以下是 TradingView 内置 RSI Divergence Indicator 的源代码
//@version=6
indicator(title="RSI Divergence Indicator", format=format.price, timeframe="", timeframe_gaps=true)
len = input.int(title="RSI Period", minval=1, defval=14)
src = input(title="RSI Source", defval=close)
lbR = input(title="Pivot Lookback Right", defval=5, display = display.data_window)
lbL = input(title="Pivot Lookback Left", defval=5, display = display.data_window)
rangeUpper = input(title="Max of Lookback Range", defval=60, display = display.data_window)
rangeLower = input(title="Min of Lookback Range", defval=5, display = display.data_window)
plotBull = input(title="Plot Bullish", defval=true, display = display.data_window)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=false, display = display.data_window)
plotBear = input(title="Plot Bearish", defval=true, display = display.data_window)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false, display = display.data_window)
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = ta.rsi(src, len)
plot(osc, title="RSI", linewidth=2, color=#2962FF)
hline(50, title="Middle Line", color=#787B86, linestyle=hline.style_dotted)
obLevel = hline(70, title="Overbought", color=#787B86, linestyle=hline.style_dotted)
osLevel = hline(30, title="Oversold", color=#787B86, linestyle=hline.style_dotted)
fill(obLevel, osLevel, title="Background", color=color.rgb(33, 150, 243, 90))
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
inRangePl = _inRange(plFound[1])
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and inRangePl
// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCondAlert = priceLL and oscHL and plFound
bullCond = plotBull and bullCondAlert
plot(
plFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor),
display = display.pane
)
plotshape(
bullCond ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and inRangePl
// Price: Higher Low
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCondAlert = priceHL and oscLL and plFound
hiddenBullCond = plotHiddenBull and hiddenBullCondAlert
plot(
plFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor),
display = display.pane
)
plotshape(
hiddenBullCond ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label",
text=" H Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
inRangePh = _inRange(phFound[1])
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and inRangePh
// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCondAlert = priceHH and oscLH and phFound
bearCond = plotBear and bearCondAlert
plot(
phFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor),
display = display.pane
)
plotshape(
bearCond ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and inRangePh
// Price: Lower High
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
hiddenBearCondAlert = priceLH and oscHH and phFound
hiddenBearCond = plotHiddenBear and hiddenBearCondAlert
plot(
phFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor),
display = display.pane
)
plotshape(
hiddenBearCond ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish Label",
text=" H Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
alertcondition(bullCondAlert, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar")
alertcondition(hiddenBullCondAlert, title='Hidden Bullish Divergence', message='Found a new Hidden Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar')
alertcondition(bearCondAlert, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar')
alertcondition(hiddenBearCondAlert, title='Hidden Bearish Divergence', message='Found a new Hidden Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar')
忽略仅用于自定义显示风格相关的参数。
len
(RSI 周期):计算 RSI 的周期长度(以 K 线数量为单位)。越大越平滑;越小越灵敏。默认值:14
src
(RSI 数据源):计算 RSI 的价格数据源(例如:收盘价、开盘价、最高价、最低价等)。默认值:close
lbR
(枢轴点右侧回溯范围):确认当前 K 线是否为枢轴点时需要比较的右侧 K 线数量。默认值:5
lbL
(枢轴点左侧回溯范围):确认当前 K 线是否为枢轴点时需要比较的左侧 K 线数量。默认值:5
lbR
根 K 线数据来确认枢轴点,所以会引入信号延迟。rangeUpper
(最大回溯范围):计算 RSI 和价格之间背离时,向过去回溯的最大 K 线数量。默认值:60
rangeLower
(最小回溯范围):计算 RSI 和价格背离时,向过去回溯的最小 K 线数量。默认值:5
flowchart TD
A([开始]) --> B([计算 RSI])
B --> C([检测枢轴点])
C -->|检测到枢轴点| D([验证枢轴点是否在范围内])
C -->|未检测到枢轴点| E([结束])
D -->|在范围内| F([检查背离条件])
D -->|不在范围内| E
F -->|背离成立| G([绘制背离信号])
F -->|背离不成立| E
G --> H([触发警报])
H --> E
len
和数据源 src
(默认 close
)计算 RSI(相对强弱指数):osc = ta.rsi(src, len)
lbL
个左侧和 lbR
个右侧值。ta.pivotlow(osc, lbL, lbR)
lbL
个左侧和 lbR
个右侧值。ta.pivothigh(osc, lbL, lbR)
ta.pivotlow
或 ta.pivothigh
返回 na
(空值),则说明当前 K 线不是枢轴点。plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
ta.valuewhen(condition, source, occurrence)
occurrence (simple int) The occurrence of the condition. The numbering starts from 0 and goes back in time, so '0' is the most recent occurrence of
condition
, '1' is the second most recent and so forth. Must be an integer >= 0.
ta.valuewhen(plFound, osc[lbR], 1)
ta.valuewhen(phFound, osc[lbR], 1)
ta.valuewhen(plFound, low[lbR], 1)
ta.valuewhen(phFound, low[lbR], 1)
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) // RSI 高于前期低点
📈priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) // 价格低于 RSI 前期低点对应价格
📉bullCond = priceLL and oscHL and plFound
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) // RSI 低于前期高点
📉priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) // 价格高于 RSI 前期高点对应价格
📈bearCond = priceHH and oscLH and phFound
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) // RSI 低于前期低点
📉priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) // 价格高于 RSI 前期低点对应价格
📈hiddenBullCond = priceHL and oscLL and plFound
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) // RSI 高于前期高点
📈priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) // 价格低于 RSI 前期高点对应价格
📉hiddenBearCond = priceLH and oscHH and phFound
_inRange
函数验证检测到的确认的最近两个枢轴点是否符合用户定义的回溯范围(rangeLower
和 rangeUpper
):
_inRange(cond) => bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper inRangePl = _inRange(plFound[1]) // 检测枢轴低点是否在有效范围内
在认识RSI背离之前,这里给大家提前强调一个重要概念:所有的背离都离不开趋势的支持。
从价格行为学的角度来定义一个上升趋势,基本结构是由 ABC 的 N 字形态构成的,从而形成了相对应的高低点。