MULTI

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

//@version=5

indicator('Multiple', overlay=true)

////////////
// INPUTS //

// SMA
rsi_len = input.int( 14, title = "RSI Length", group = "Indicators")
rsi_os = input.float(30, title = "RSI Overbought", group = "Indicators")
rsi_ob = input.float(70, title = "RSI Oversold", group = "Indicators")

// TSI
tsi_long_len = input.int( 25, title = "TSI Long Length", group = "Indicators")
tsi_shrt_len = input.int( 13, title = "TSI Short Length", group = "Indicators")
tsi_ob = input.float( 30, title = "TSI Overbought", group = 'Indicators')
tsi_os = input.float(-30, title = "TSI Oversold", group = 'Indicators')

// ADX Params
adx_smooth = input.int( 14, title = "ADX Smoothing", group = 'Indicators')
adx_dilen = input.int( 14, title = "ADX DI Length", group = 'Indicators')
adx_level = input.float(40, title = "ADX Level", group = 'Indicators')

// SuperTrend
sup_atr_len = input.int( 10, "Supertrend ATR Length", group = 'Indicators')
sup_factor = input.float(3.0, "Supertrend Factor", group = 'Indicators')

/////////////
// SYMBOLS //

u01 = input.bool(true, title = "", group = 'Symbols', inline = 's01')


u02 = input.bool(true, title = "", group = 'Symbols', inline = 's02')
u03 = input.bool(true, title = "", group = 'Symbols', inline = 's03')
u04 = input.bool(true, title = "", group = 'Symbols', inline = 's04')
u05 = input.bool(true, title = "", group = 'Symbols', inline = 's05')
u06 = input.bool(true, title = "", group = 'Symbols', inline = 's06')
u07 = input.bool(true, title = "", group = 'Symbols', inline = 's07')
u08 = input.bool(true, title = "", group = 'Symbols', inline = 's08')
u09 = input.bool(true, title = "", group = 'Symbols', inline = 's09')
u10 = input.bool(true, title = "", group = 'Symbols', inline = 's10')

s01 = input.symbol('NIFTY', group = 'Symbols', inline = 's01')


s02 = input.symbol('BANKNIFTY', group = 'Symbols', inline = 's02')
s03 = input.symbol('HDFCBANK', group = 'Symbols', inline = 's03')
s04 = input.symbol('AXISBANK', group = 'Symbols', inline = 's04')
s05 = input.symbol('ICICIBANK', group = 'Symbols', inline = 's05')
s06 = input.symbol('KOTAKBANK', group = 'Symbols', inline = 's06')
s07 = input.symbol('SBIN', group = 'Symbols', inline = 's07')
s08 = input.symbol('NIFTY', group = 'Symbols', inline = 's08')
s09 = input.symbol('NIFTY', group = 'Symbols', inline = 's09')
s10 = input.symbol('NIFTY', group = 'Symbols', inline = 's10')
//////////////////
// CALCULATIONS //

// Get only symbol


only_symbol(s) =>
array.get(str.split(s, ":"), 1)

id_symbol(s)=>
switch s
1 => only_symbol(s01)
2 => only_symbol(s02)
3 => only_symbol(s03)
4 => only_symbol(s04)
5 => only_symbol(s05)
6 => only_symbol(s06)
7 => only_symbol(s07)
8 => only_symbol(s08)
9 => only_symbol(s09)
10 => only_symbol(s10)
=> na

// for TSI
double_smooth(src, long, short) =>
fist_smooth = ta.ema(src, long)
ta.ema(fist_smooth, short)

// ADX
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)

plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)


minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)

truerange = ta.rma(ta.tr, len)

plus = fixnan(100 * ta.rma(plusDM, len) / truerange)


minus = fixnan(100 * ta.rma(minusDM, len) / truerange)

[plus, minus]

adx_func(dilen, adxlen) =>


[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

screener_func() =>

// RSI
rsi = ta.rsi(close, rsi_len)

// TSI
pc = ta.change(close)

double_smoothed_pc = double_smooth(pc, tsi_long_len,


tsi_shrt_len)
double_smoothed_abs_pc = double_smooth(math.abs(pc), tsi_long_len,
tsi_shrt_len)

tsi = 100 * (double_smoothed_pc / double_smoothed_abs_pc)

// ADX
adx = adx_func(adx_dilen, adx_smooth)

// Supertrend
[sup_value, sup_dir] = ta.supertrend(sup_factor, sup_atr_len)

[math.round_to_mintick(close), rsi, tsi, adx, sup_dir]

// Set Up Matrix
screenerMtx = matrix.new<float>(0, 6, na)

screenerFun(numSym, sym, flg) =>

[cl, rsi, tsi, adx, sup] = request.security(sym, timeframe.period,


screener_func())

arr = array.from(numSym, cl, rsi, tsi, adx, sup)

if flg
matrix.add_row(screenerMtx, matrix.rows(screenerMtx), arr)

// Security call
screenerFun(01, s01, u01), screenerFun(02, s02, u02), screenerFun(03, s03, u03),
screenerFun(04, s04, u04),
screenerFun(05, s05, u05), screenerFun(06, s06, u06), screenerFun(07, s07, u07),
screenerFun(08, s08, u08),
screenerFun(09, s09, u09), screenerFun(10, s10, u10), screenerFun(11, s11, u11),
screenerFun(12, s12, u12),
screenerFun(13, s13, u13), screenerFun(14, s14, u14), screenerFun(15, s15, u15),
screenerFun(16, s16, u16),
screenerFun(17, s17, u17), screenerFun(18, s18, u18), screenerFun(19, s19, u19),
screenerFun(20, s20, u20),
screenerFun(21, s21, u21), screenerFun(22, s22, u22), screenerFun(23, s23, u23),
screenerFun(24, s24, u24),
screenerFun(25, s25, u25), screenerFun(26, s26, u26), screenerFun(27, s27, u27),
screenerFun(28, s28, u28),
screenerFun(29, s29, u29), screenerFun(30, s30, u30), screenerFun(31, s31, u31),
screenerFun(32, s32, u32),
screenerFun(33, s33, u33), screenerFun(34, s34, u34), screenerFun(35, s35, u35),
screenerFun(36, s36, u36),
screenerFun(37, s37, u37), screenerFun(38, s38, u38), screenerFun(39, s39, u39),
screenerFun(40, s40, u40),

///////////
// PLOTS //

var tbl = table.new(position.top_right, 6, 41, frame_color=#151715, frame_width=1,


border_width=2, border_color=color.new(color.white, 100))

if barstate.islast
table.clear(tbl, 0, 0, 5, 40)

table.cell(tbl, 0, 0, 'Symbol', text_halign = text.align_center, bgcolor =


color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 1, 0, 'Price', text_halign = text.align_center, bgcolor =
color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 2, 0, 'RSI', text_halign = text.align_center, bgcolor =
color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 3, 0, 'TSI', text_halign = text.align_center, bgcolor =
color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 4, 0, 'ADX', text_halign = text.align_center, bgcolor =
color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 5, 0, 'Supertrend', text_halign = text.align_center, bgcolor =
color.gray, text_color = color.white, text_size = size.small)

if matrix.rows(screenerMtx) > 0
for i = 0 to matrix.rows(screenerMtx) - 1

rsi_col = matrix.get(screenerMtx, i, 2) > rsi_ob ? color.red :


matrix.get(screenerMtx, i, 2) < rsi_os ? color.green : #aaaaaa
tsi_col = matrix.get(screenerMtx, i, 3) > tsi_ob ? color.red :
matrix.get(screenerMtx, i, 3) < tsi_os ? color.green : #aaaaaa
adx_col = matrix.get(screenerMtx, i, 4) > adx_level ? color.green :
#aaaaaa

sup_text = matrix.get(screenerMtx, i, 5) > 0 ? "Down" : "Up"


sup_col = matrix.get(screenerMtx, i, 5) < 0 ? color.green : color.red

table.cell(tbl, 0, i + 1, id_symbol(matrix.get(screenerMtx, i, 0)),


text_halign = text.align_left, bgcolor = color.gray, text_color = color.white,
text_size = size.small)
table.cell(tbl, 1, i + 1, str.tostring(matrix.get(screenerMtx, i, 1)),
text_halign = text.align_center, bgcolor = #aaaaaa, text_color = color.white,
text_size = size.small)
table.cell(tbl, 2, i + 1, str.tostring(matrix.get(screenerMtx, i, 2),
"#.##"), text_halign = text.align_center, bgcolor = rsi_col, text_color =
color.white, text_size = size.small)
table.cell(tbl, 3, i + 1, str.tostring(matrix.get(screenerMtx, i, 3),
"#.##"), text_halign = text.align_center, bgcolor = tsi_col, text_color =
color.white, text_size = size.small)
table.cell(tbl, 4, i + 1, str.tostring(matrix.get(screenerMtx, i, 4),
"#.##"), text_halign = text.align_center, bgcolor = adx_col , text_color =
color.white, text_size = size.small)
table.cell(tbl, 5, i + 1, sup_text,
text_halign = text.align_center, bgcolor = sup_col, text_color = color.white,
text_size = size.small)

You might also like