Reversal Indicator

StrategicalCharts · study · 67 行 · 点赞 2,663 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator("Reversal Indicator", overlay=true)
 
length = input.int(19, title="BBands Length", minval=1, tooltip="Bollinger band length used in calculation")   
mult = input.float(2, title="BBands Multiplier", minval=0.001, maxval=50, tooltip="Bollinger band multiplier used in calculation")    
 
showBBands = false
showBBandsMiddle = false
BBandsFill = false
// showBBands = input.bool(false, "BBands Upper and Lower")
// showBBandsMiddle = input.bool(false, "BBands Middle")
// BBandsFill = input.bool(false, "BBands Fill")
 
 
showCheckmarks = input.bool( true , title="Show Checkmarks", tooltip="Checkmarks provide confirmation",  group="Reversal")
isRsi = input.bool( false , title="RSI confluence", tooltip="Show reversal signal only when RSI is overbought/oversold",  group="RSI")
rsiLen = input.int( 14 , title="RSI Length",  group="RSI")
overSold = input.int( 30 , title="RSI Oversold",  group="RSI")
overBought = input.int ( 70 , title="RSI Overbought",  group="RSI")
 
 
//calculate bollinger bands
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
 
//calculate RSI
vrsi = ta.rsi(close, rsiLen)
rsiBull = ta.crossover(vrsi, overSold)
rsiBear = ta.crossunder(vrsi, overBought)
 
// BULLISH SIGNAL
// Order: went out lower band AND red candle AND came back in AND green candle
bullReversal =  low[1]<lower[1] and close[1]<open[1] and close>lower and close>open  
// everything above AND candle close above signal candles wick.
bullReversalConfirm =   low[2]<lower[2] and close[2]<open[2] and close[1]>lower[1] and close[1]>open[1] and close>high[1]
 
// BEARISH SIGNAL
// Order: went out upper band AND green candle AND came back in AND red candle
bearReversal  = high[1]>upper[1] and close[1]>open[1] and close<upper and close<open 
// everything above AND candle close below signal candles wick.
bearReversalConfirm =  high[2]>upper[2] and close[2]>open[2] and close[1]<upper[1] and close[1]<open[1] and close<low[1]
 
if isRsi
    bullReversal:=bullReversal and rsiBull
    bearReversal:=bearReversal and rsiBear
    bullReversalConfirm:=false
    bearReversalConfirm:=false
  
 
// UI    
plotchar(bullReversal, "Bull Reversal", "R", location.belowbar,color.rgb(124, 251, 216),size=size.tiny)
plotchar(bearReversal, "Bear Reversal", "R", location.abovebar,color=color.yellow,size=size.tiny)
 
plotchar(showCheckmarks?bullReversalConfirm:na, "Bull Reversal Confirm", "", location.belowbar, text="✓", color=color.rgb(124, 251, 216),size=size.tiny)
plotchar(showCheckmarks?bearReversalConfirm:na, "Bear Reversal Confirm", "", location.abovebar, text="✓", color=color.yellow,size=size.tiny)
 
 
barcolor(bullReversal?color.rgb(124, 251, 216):na, title="Bull Reversal Bar")
barcolor(bearReversal?color.yellow:na, title="Bear Reversal Bar")
 
// For Debugging
// plot(basis, color=showBBandsMiddle?color.yellow:na, title="Basis")
// p1=plot(lower, color=showBBands?color.green:na, title="Lower")
// p2=plot(upper, color=showBBands?color.red:na, title="Upper")
// fill(p1, p2, title = "BBands Fill", color=BBandsFill?color.rgb(33, 150, 243, 95):na, editable=true)

← 返回列表