Professional Documents
Culture Documents
rsi divergence
rsi divergence
rsi divergence
//---------------------------------------------------------------------------------
------------------------------------------------
//--- Define Colors
-----------------------------------------------------------------------------------
----------------------------
//---------------------------------------------------------------------------------
------------------------------------------------
vWhite = #FFFFFF
vViolet = #C77DF3
vIndigo = #8A2BE2
vBlue = #009CDF
vGreen = #5EBD3E
vYellow = #FFB900
vRed = #E23838
longColor = color.green
shortColor = color.red
textColor = color.white
bullishColor = color.rgb(38,166,154,0)
bearishColor = color.rgb(239,83,79,0)
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Table Settings
-----------------------------------------------------------------------------------
-----------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
rsiShowTable = input(true, title='Show RSI Table Information box',
group="DeFib Table Settings")
rsiTablePosition = input.string(title='Location', defval='top_right',
options=['top_left',
'top_center','top_right','middle_left','middle_cente','middle_right','bottom_left',
'bottom_cente','bottom_right'], group="DeFib Table Settings", inline='1')
rsiTextSize = input.string(title=' Size', defval='small',
options=['auto','tiny','small','normal','large','huge'], group="DeFib Table
Settings", inline='1')
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- RSI Input Settings
-----------------------------------------------------------------------------------
-----------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
rsiSourceInput = input.source(close, 'Source', group='RSI Settings')
rsiLengthInput = input.int(14, minval=1, title='RSI Length', group='RSI Settings',
tooltip='Here we set the RSI lenght')
rsiColorInput = input.color(#26a69a, title="RSI Color", group='RSI Settings')
rsimaColorInput = input.color(#ef534f, title="RSIMA Color", group='RSI Settings')
rsiBandColorInput = input.color(#787B86, title="RSI Band Color", group='RSI
Settings')
rsiUpperBandExtInput = input.int(title='RSI Overbought Extended Line', defval=80,
minval=50, maxval=100, group='RSI Settings')
rsiUpperBandInput = input.int(title='RSI Overbought Line', defval=70, minval=50,
maxval=100, group='RSI Settings')
rsiLowerBandInput = input.int(title='RSI Oversold Line', defval=30, minval=0,
maxval=50, group='RSI Settings')
rsiLowerBandExtInput = input.int(title='RSI Oversold Extended Line', defval=20,
minval=0, maxval=50, group='RSI Settings')
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- MA Input Settings
-----------------------------------------------------------------------------------
------------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
maTypeInput = input.string("EMA", title="MA Type", options=["SMA", "Bollinger
Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
maColorInput = input.color(color.yellow, title="MA Color", group='MA
Settings') //#7E57C2
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Divergence Input Settings
-----------------------------------------------------------------------------------
----------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
lbrInput = input(title="Pivot Lookback Right", defval=2, group='RSI
Divergence Settings')
lblInput = input(title="Pivot Lookback Left", defval=2, group='RSI
Divergence Settings')
lbRangeMaxInput = input(title="Max of Lookback Range", defval=10, group='RSI
Divergence Settings')
lbRangeMinInput = input(title="Min of Lookback Range", defval=2, group='RSI
Divergence Settings')
plotBullInput = input(title="Plot Bullish", defval=true, group='RSI
Divergence Settings')
plotHiddenBullInput = input(title="Plot Hidden Bullish", defval=true, group='RSI
Divergence Settings')
plotBearInput = input(title="Plot Bearish", defval=true, group='RSI
Divergence Settings')
plotHiddenBearInput = input(title="Plot Hidden Bearish", defval=true, group='RSI
Divergence Settings')
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- RSI Calculation
-----------------------------------------------------------------------------------
--------------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
rsi = ta.rsi(rsiSourceInput, rsiLengthInput)
rsiprevious = rsi[1]
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- MA Calculation
-----------------------------------------------------------------------------------
--------------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Stoch RSI Settings + Calculation
-----------------------------------------------------------------------------------
---------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
showStochRSI = input(false, title="Show Stochastic RSI", group='Stochastic RSI
Settings')
smoothK = input.int(title="Stochastic K", defval=3, minval=1, maxval=10,
group='Stochastic RSI Settings')
smoothD = input.int(title="Stochastic D", defval=4, minval=1, maxval=10,
group='Stochastic RSI Settings')
lengthRSI = input.int(title="Stochastic RSI Lenght", defval=14, minval=1,
group='Stochastic RSI Settings')
lengthStoch = input.int(title="Stochastic Lenght", defval=14, minval=1,
group='Stochastic RSI Settings')
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Divergence Settings
-----------------------------------------------------------------------------------
-------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 50)
hiddenBearColor = color.new(color.red, 50)
//textColor = color.white
noneColor = color.new(color.white, 100)
osc = rsi
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Define Plot & Line Colors
-----------------------------------------------------------------------------------
----------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
rsiColor = rsi >= rsiMA ? rsiColorInput : rsimaColorInput
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Plot Lines
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
hline(50, title='RSI Baseline', color=color.new(rsiBandColorInput, 50),
linestyle=hline.style_dashed, editable=false)
hline(rsiBandExtShowInput ? rsiUpperBandExtInput : na, title='RSI Upper Band',
color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed,
editable=false)
hline(rsiBandShowInput ? rsiUpperBandInput : na, title='RSI Upper Band',
color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed,
editable=false)
hline(rsiBandShowInput ? rsiLowerBandInput : na, title='RSI Upper Band',
color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed,
editable=false)
hline(rsiBandExtShowInput ? rsiLowerBandExtInput : na, title='RSI Upper Band',
color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed,
editable=false)
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- Plot Divergence
-----------------------------------------------------------------------------------
--------------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbrInput] > ta.valuewhen(plFound, osc[lbrInput], 1) and
_inRange(plFound[1])
plot(
plFound ? osc[lbrInput] : na,
offset=-lbrInput,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor)
)
plotshape(
DivergenceShowInput ? bullCond ? osc[lbrInput] : na : na,
offset=-lbrInput,
title="Regular Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
plot(
plFound ? osc[lbrInput] : na,
offset=-lbrInput,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor)
)
plotshape(
DivergenceShowInput ? hiddenBullCond ? osc[lbrInput] : na : na,
offset=-lbrInput,
title="Hidden Bullish Label",
text=" H Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbrInput] < ta.valuewhen(phFound, osc[lbrInput], 1) and
_inRange(phFound[1])
plot(
phFound ? osc[lbrInput] : na,
offset=-lbrInput,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor)
)
plotshape(
DivergenceShowInput ? bearCond ? osc[lbrInput] : na : na,
offset=-lbrInput,
title="Regular Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbrInput] > ta.valuewhen(phFound, osc[lbrInput], 1) and
_inRange(phFound[1])
plot(
phFound ? osc[lbrInput] : na,
offset=-lbrInput,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor)
)
plotshape(
DivergenceShowInput ? hiddenBearCond ? osc[lbrInput] : na : na,
offset=-lbrInput,
title="Hidden Bearish Label",
text=" H Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
//--- RSI Info Table Setting
-----------------------------------------------------------------------------------
-------------------------------------------------------
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
width_c0 = 0
width_c1 = 4
if rsiShowTable
var rsi_Table = table.new(position=rsiTablePosition, columns=2, rows=5,
bgcolor=color.rgb(18,22,33,50), frame_color=color.black, frame_width=1,
border_color=color.black, border_width=1)
//------------------------------------------------------
//--- Alerts -------------------------------------------
//------------------------------------------------------