Dsteam 2
Dsteam 2
0 at
https://mozilla.org/MPL/2.0/
// © Llopezf
//@version=5
//functions
xrf(values, length) =>
r_val = float(na)
if length >= 1
for i = 0 to length by 1
if na(r_val) or not na(values[i])
r_val := values[i]
r_val
r_val
xsa(src,len,wei) =>
sumf = 0.0
ma = 0.0
out = 0.0
sumf := nz(sumf[1]) - nz(src[len]) + src
ma := na(src[len]) ? na : sumf/len
out := na(out[1]) ? ma : (src*wei+out[1]*(len-wei))/len
out
//-----------------------------------------------------------------------------}
//TDI - Traders Dynamic Index
//-----------------------------------------------------------------------------{
// USER Interface
RSI_input = input.int(title="RSI", defval=21, minval=5, group='TDI Components',
inline="RSI")
RSI_c = input.color(title="Color", defval=#1dc72b, group='TDI Components',
inline="RSI")
TL_input = input.int(title="TrendLine", defval=7, minval=3, group='TDI Components',
inline="TL")
TL_c = input.color(title="Color", defval=#FF0000, group='TDI Components',
inline="TL")
BL_input = input.int(title="BaseLine", defval=34, minval=14, group='TDI
Components', inline="BL")
BL_c = input.color(title="Color", defval=color(color.orange), group='TDI
Components', inline="BL")
VB_input = input.float(title="Volatility Bands", defval=1.6185, minval=1.0,
group='TDI Components', inline="VB")
VB_c = input.color(title="Color", defval=#b2ebf200, group='TDI Components',
inline="VB")
BU_c = input.color(title="Bullish", defval=#0066ff00, group='Color Scheme',
inline="CS")
BE_c = input.color(title="Bearish", defval=#ff000000, group='Color Scheme',
inline="CS")
is_showDataTBL = input.bool(title='Show Data Table', defval=false)
// TDI Setup
r = ta.rsi(close, RSI_input)
r_plot = ta.sma(r, 2)
r_tl = ta.sma(r, TL_input)
r_gbl = ta.sma(r, BL_input)
// Plots
if is_showDataTBL
var main_table = table.new(position.middle_right, 5, 5, frame_color=#000000,
frame_width=2, border_color=#000000, border_width=1)
table.cell(main_table, 0, 0, 'TF', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 1, 0, 't3', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 2, 0, 't2', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 3, 0, 't1', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 4, 0, 't0', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 0, 1, 'R', text_color=color.white, text_size=size.small,
bgcolor=color.new(color.black, 50))
table.cell(main_table, 0, 2, 'TL', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 0, 3, 'BL', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
table.cell(main_table, 0, 4, 'EMA', text_color=color.white,
text_size=size.small, bgcolor=color.new(color.black, 50))
for i = 1 to 4
table.cell(main_table, i, 1, str.tostring(r_plot[4-i], '#.#'),
text_color=#000000, text_size=size.small, bgcolor=color.new(r_plotc[4-i], 50))
table.cell(main_table, i, 2, str.tostring(r_tl[4-i], '#.#'),
text_color=#000000, text_size=size.small, bgcolor=color.new(r_tlc[4-i], 50))
table.cell(main_table, i, 3, str.tostring(r_gbl[4-i], '#.#'),
text_color=#000000, text_size=size.small, bgcolor=color.new(r_gblc[4-i], 50))
table.cell(main_table, i, 4, str.tostring(EMA_score[4-i], '#'),
text_color=#000000, text_size=size.small, bgcolor=color.new(EMA_score_C[4-i], 50))
//-----------------------------------------------------------------------------}
//Divergence Indicator
//-----------------------------------------------------------------------------{
oscillator = input.string(title="Select Oscillator",defval="RSI",options=["RSI",
"MACD", "Stochastic","Money Flow","Demand Index","Chaikin Money flow"])
//Tradingview built-in divergence indicator script used to show Divergence
//Thanks to Tradingview for providing this unique Built-in Divergence Indicator
lbR = input(title="Pivot Lookback Right", defval=2)
lbL = input(title="Pivot Lookback Left", defval=6)
rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=false)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
plot(
plFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor),
transp=0
)
plotshape(
bullCond ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor,
transp=0
)
plot(
plFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor),
transp=0
)
plotshape(
hiddenBullCond ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label",
text=" H Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor,
transp=0
)
plot(
phFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor),
transp=0
)
plotshape(
bearCond ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=0
)
plot(
phFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor),
transp=0
)
plotshape(
hiddenBearCond ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish Label",
text=" H Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=0
)
alertcondition(condition = (bullCond or hiddenBullCond), title = "Bullish
Divergence", message = "Bullish Divergence")
alertcondition(condition = (bearCond or hiddenBearCond), title = "Bearish
Divergence", message = "Bearish Divergence")