ATR OSC and Volume Screener (ATROSCVS)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("ATR OSC and Volume Screener", "ATROSCVS", max_boxes_count = 500)
import peacefulLizard50262/Boxes_Plot/1 as b

average_true_range(source, length)=>
    true_range = high - low
    _range = math.abs(open - close)
    a_range = (true_range * 2 + _range)/3
    average_true_range = ta.rma(a_range, length)

tr_score(source, length)=>
    mean = ta.sma(source, length)
    tr = average_true_range(source, length)
    z_score = (source - mean)/tr

max(source, outlier_level, dev_lookback)=>
    var float max = na
    src = array.new<float>()
    stdev = math.abs((source - ta.ema(source, dev_lookback))/ta.stdev(source, dev_lookback))
    array.push(src, stdev < outlier_level ? source : -1.7976931348623157e+308)
    max := math.max(nz(max[1]), array.get(src, 0))

min(source, outlier_level, dev_lookback) =>
    var float min = na
    src = array.new<float>()
    stdev = math.abs((source - ta.ema(source, dev_lookback))/ta.stdev(source, dev_lookback))
    array.push(src, stdev < outlier_level ? source : 1.7976931348623157e+308)
    min := math.min(nz(min[1]), array.get(src, 0))

min_max(src, outlier_level, dev_lookback) =>
    out = (src - min(src, outlier_level, dev_lookback))/(max(src, outlier_level, dev_lookback) - min(src, outlier_level, dev_lookback)) * 100
    math.max(math.min(100, out), 0)

osc(source, length, smoothing, outlier_level, dev_lookback)=>
    ta.sma(min_max(tr_score(source, length), outlier_level, dev_lookback), smoothing)

macd(source, length_fast, length_slow, length_macd, smoothing, dev_lookback, outlier_level)=>
    center = ta.ema(source, length_macd)
    fast = ta.ema(source, length_fast) - center
    slow = ta.ema(source, length_slow) - center
    macd = fast - slow
    macd_abs = min_max(math.abs(macd), outlier_level, dev_lookback)
    sine = macd > 0 ? (macd_abs/2) + 50 : macd < 0 ? 50 - (macd/2) : 0

volume_normalized(smoothing, dev_lookback, outlier_level)=>
    min_max(ta.sma(volume, smoothing), outlier_level, dev_lookback)

source = close
values = input.bool(false, "Enable Values")
length_osc = input.int(14, "ATR Osc Length", 1)
smoothing_osc = input.int(1, "ATR Osc Smoothing", 1)
outlier_lookback_osc = input.int(20, "ATR Osc Outlier Lookback", 1)
outlier_level_osc = input.float(1, "ATR Osc Outlier Level", 0.5, step = 0.5)

smoothing_vol = input.int(1, "Volume Smoothing", 1)
outlier_lookback_vol = input.int(100, "Volume Outlier Lookback", 1)
outlier_level_vol = input.float(1, "Volume Outlier Level", 0.5, step = 0.5)

scale = input.float(1, "Scale", 1, 10, 0.5)

s01 = input.symbol('XRPUSDT',  group = 'Symbols', inline = 's01')
s02 = input.symbol('BTCUSDT',  group = 'Symbols', inline = 's02')
s03 = input.symbol('DOGEUSDT', group = 'Symbols', inline = 's03')
s04 = input.symbol('BNBUSDT',  group = 'Symbols', inline = 's04')
s05 = input.symbol('ETHUSDT',  group = 'Symbols', inline = 's05')
s06 = input.symbol('ADAUSDT',  group = 'Symbols', inline = 's06')
s07 = input.symbol('XRPBTC',   group = 'Symbols', inline = 's07')
s08 = input.symbol('DOGEBTC',  group = 'Symbols', inline = 's08')
s09 = input.symbol('TRXUSDT',  group = 'Symbols', inline = 's09')
s10 = input.symbol('BTCBUSD',  group = 'Symbols', inline = 's10')
s11 = input.symbol('ETHBUSD',  group = 'Symbols', inline = 's11')
s12 = input.symbol('BNBBUSD',  group = 'Symbols', inline = 's12')
s13 = input.symbol('VETUSDT',  group = 'Symbols', inline = 's13')
s14 = input.symbol('ETHBTC',   group = 'Symbols', inline = 's14')
s15 = input.symbol('BNBBTC',   group = 'Symbols', inline = 's15')
s16 = input.symbol('EOSUSDT',  group = 'Symbols', inline = 's16')
s17 = input.symbol('XLMUSDT',  group = 'Symbols', inline = 's17')
s18 = input.symbol('LTCUSDT',  group = 'Symbols', inline = 's18')
s19 = input.symbol('XRPBUSD',  group = 'Symbols', inline = 's19')
s20 = input.symbol('WINUSDT',  group = 'Symbols', inline = 's20')
s21 = input.symbol('DOTUSDT',  group = 'Symbols', inline = 's21')
s22 = input.symbol('BTTUSDT',  group = 'Symbols', inline = 's22')
s23 = input.symbol('BCHUSDT',  group = 'Symbols', inline = 's23')
s24 = input.symbol('ADABTC',   group = 'Symbols', inline = 's24')
s25 = input.symbol('IOSTUSDT', group = 'Symbols', inline = 's25')
s26 = input.symbol('CHZUSDT',  group = 'Symbols', inline = 's26')
s27 = input.symbol('LINKUSDT', group = 'Symbols', inline = 's27')
s28 = input.symbol('TRXBTC',   group = 'Symbols', inline = 's28')
s29 = input.symbol('DOGEBUSD', group = 'Symbols', inline = 's29')
s30 = input.symbol('BTCEUR',   group = 'Symbols', inline = 's30')
s31 = input.symbol('FILUSDT',  group = 'Symbols', inline = 's31')
s32 = input.symbol('HOTUSDT',  group = 'Symbols', inline = 's32')
s33 = input.symbol('SXPUSDT',  group = 'Symbols', inline = 's33')
s34 = input.symbol('ADABUSD',  group = 'Symbols', inline = 's34')
s35 = input.symbol('RVNUSDT',  group = 'Symbols', inline = 's35')
s36 = input.symbol('ATOMUSDT', group = 'Symbols', inline = 's36')

[osc01, vol01] = request.security(s01, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc02, vol02] = request.security(s02, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc03, vol03] = request.security(s03, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc04, vol04] = request.security(s04, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc05, vol05] = request.security(s05, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc06, vol06] = request.security(s06, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc07, vol07] = request.security(s07, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc08, vol08] = request.security(s08, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc09, vol09] = request.security(s09, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc10, vol10] = request.security(s10, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc11, vol11] = request.security(s11, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc12, vol12] = request.security(s12, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc13, vol13] = request.security(s13, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc14, vol14] = request.security(s14, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc15, vol15] = request.security(s15, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc16, vol16] = request.security(s16, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc17, vol17] = request.security(s17, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc18, vol18] = request.security(s18, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc19, vol19] = request.security(s19, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc20, vol20] = request.security(s20, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc21, vol21] = request.security(s21, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc22, vol22] = request.security(s22, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc23, vol23] = request.security(s23, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc24, vol24] = request.security(s24, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc25, vol25] = request.security(s25, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc26, vol26] = request.security(s26, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc27, vol27] = request.security(s27, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc28, vol28] = request.security(s28, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc29, vol29] = request.security(s29, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc30, vol30] = request.security(s30, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc31, vol31] = request.security(s31, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc32, vol32] = request.security(s32, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc33, vol33] = request.security(s33, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc34, vol34] = request.security(s34, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc35, vol35] = request.security(s35, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])
[osc36, vol36] = request.security(s36, timeframe.period, [osc(source, length_osc, smoothing_osc, outlier_level_osc, outlier_lookback_osc), volume_normalized(smoothing_vol, outlier_lookback_vol, outlier_level_vol)])

symbols_osc = array.from(
 osc01,
 osc02, 
 osc03, 
 osc04, 
 osc05, 
 osc06, 
 osc07, 
 osc08, 
 osc09, 
 osc10, 
 osc11, 
 osc12, 
 osc13, 
 osc14, 
 osc15, 
 osc16, 
 osc17, 
 osc18, 
 osc19, 
 osc20, 
 osc21, 
 osc22, 
 osc23, 
 osc24, 
 osc25, 
 osc26, 
 osc27, 
 osc28, 
 osc29, 
 osc30, 
 osc31, 
 osc32, 
 osc33, 
 osc34, 
 osc35, 
 osc36)

symbols_vol = array.from(
 vol01,
 vol02, 
 vol03, 
 vol04, 
 vol05, 
 vol06, 
 vol07, 
 vol08, 
 vol09, 
 vol10, 
 vol11, 
 vol12, 
 vol13, 
 vol14, 
 vol15, 
 vol16, 
 vol17, 
 vol18, 
 vol19, 
 vol20, 
 vol21, 
 vol22, 
 vol23, 
 vol24, 
 vol25, 
 vol26, 
 vol27, 
 vol28, 
 vol29, 
 vol30, 
 vol31, 
 vol32, 
 vol33, 
 vol34, 
 vol35, 
 vol36)

symbol_name = array.from(
 s01,
 s02, 
 s03, 
 s04, 
 s05, 
 s06, 
 s07, 
 s08, 
 s09, 
 s10, 
 s11, 
 s12, 
 s13, 
 s14, 
 s15, 
 s16, 
 s17, 
 s18, 
 s19, 
 s20, 
 s21, 
 s22, 
 s23, 
 s24, 
 s25, 
 s26, 
 s27, 
 s28, 
 s29, 
 s30, 
 s31, 
 s32, 
 s33, 
 s34, 
 s35, 
 s36)

symbol_name_osc = array.from(
 s01 + "\n" + str.tostring(math.round(osc01, 0)),
 s02 + "\n" + str.tostring(math.round(osc02, 0)), 
 s03 + "\n" + str.tostring(math.round(osc03, 0)), 
 s04 + "\n" + str.tostring(math.round(osc04, 0)), 
 s05 + "\n" + str.tostring(math.round(osc05, 0)), 
 s06 + "\n" + str.tostring(math.round(osc06, 0)), 
 s07 + "\n" + str.tostring(math.round(osc07, 0)), 
 s08 + "\n" + str.tostring(math.round(osc08, 0)), 
 s09 + "\n" + str.tostring(math.round(osc09, 0)), 
 s10 + "\n" + str.tostring(math.round(osc10, 0)), 
 s11 + "\n" + str.tostring(math.round(osc11, 0)), 
 s12 + "\n" + str.tostring(math.round(osc12, 0)), 
 s13 + "\n" + str.tostring(math.round(osc13, 0)), 
 s14 + "\n" + str.tostring(math.round(osc14, 0)), 
 s15 + "\n" + str.tostring(math.round(osc15, 0)), 
 s16 + "\n" + str.tostring(math.round(osc16, 0)), 
 s17 + "\n" + str.tostring(math.round(osc17, 0)), 
 s18 + "\n" + str.tostring(math.round(osc18, 0)), 
 s19 + "\n" + str.tostring(math.round(osc19, 0)), 
 s20 + "\n" + str.tostring(math.round(osc20, 0)), 
 s21 + "\n" + str.tostring(math.round(osc21, 0)), 
 s22 + "\n" + str.tostring(math.round(osc22, 0)), 
 s23 + "\n" + str.tostring(math.round(osc23, 0)), 
 s24 + "\n" + str.tostring(math.round(osc24, 0)), 
 s25 + "\n" + str.tostring(math.round(osc25, 0)), 
 s26 + "\n" + str.tostring(math.round(osc26, 0)), 
 s27 + "\n" + str.tostring(math.round(osc27, 0)), 
 s28 + "\n" + str.tostring(math.round(osc28, 0)), 
 s29 + "\n" + str.tostring(math.round(osc29, 0)), 
 s30 + "\n" + str.tostring(math.round(osc30, 0)), 
 s31 + "\n" + str.tostring(math.round(osc31, 0)), 
 s32 + "\n" + str.tostring(math.round(osc32, 0)), 
 s33 + "\n" + str.tostring(math.round(osc33, 0)), 
 s34 + "\n" + str.tostring(math.round(osc34, 0)), 
 s35 + "\n" + str.tostring(math.round(osc35, 0)), 
 s36 + "\n" + str.tostring(math.round(osc36, 0)))

symbol_name_vol = array.from(
 s01 + "\n" + str.tostring(math.round(vol01, 0)),
 s02 + "\n" + str.tostring(math.round(vol02, 0)), 
 s03 + "\n" + str.tostring(math.round(vol03, 0)), 
 s04 + "\n" + str.tostring(math.round(vol04, 0)), 
 s05 + "\n" + str.tostring(math.round(vol05, 0)), 
 s06 + "\n" + str.tostring(math.round(vol06, 0)), 
 s07 + "\n" + str.tostring(math.round(vol07, 0)), 
 s08 + "\n" + str.tostring(math.round(vol08, 0)), 
 s09 + "\n" + str.tostring(math.round(vol09, 0)), 
 s10 + "\n" + str.tostring(math.round(vol10, 0)), 
 s11 + "\n" + str.tostring(math.round(vol11, 0)), 
 s12 + "\n" + str.tostring(math.round(vol12, 0)), 
 s13 + "\n" + str.tostring(math.round(vol13, 0)), 
 s14 + "\n" + str.tostring(math.round(vol14, 0)), 
 s15 + "\n" + str.tostring(math.round(vol15, 0)), 
 s16 + "\n" + str.tostring(math.round(vol16, 0)), 
 s17 + "\n" + str.tostring(math.round(vol17, 0)), 
 s18 + "\n" + str.tostring(math.round(vol18, 0)), 
 s19 + "\n" + str.tostring(math.round(vol19, 0)), 
 s20 + "\n" + str.tostring(math.round(vol20, 0)), 
 s21 + "\n" + str.tostring(math.round(vol21, 0)), 
 s22 + "\n" + str.tostring(math.round(vol22, 0)), 
 s23 + "\n" + str.tostring(math.round(vol23, 0)), 
 s24 + "\n" + str.tostring(math.round(vol24, 0)), 
 s25 + "\n" + str.tostring(math.round(vol25, 0)), 
 s26 + "\n" + str.tostring(math.round(vol26, 0)), 
 s27 + "\n" + str.tostring(math.round(vol27, 0)), 
 s28 + "\n" + str.tostring(math.round(vol28, 0)), 
 s29 + "\n" + str.tostring(math.round(vol29, 0)), 
 s30 + "\n" + str.tostring(math.round(vol30, 0)), 
 s31 + "\n" + str.tostring(math.round(vol31, 0)), 
 s32 + "\n" + str.tostring(math.round(vol32, 0)), 
 s33 + "\n" + str.tostring(math.round(vol33, 0)), 
 s34 + "\n" + str.tostring(math.round(vol34, 0)), 
 s35 + "\n" + str.tostring(math.round(vol35, 0)), 
 s36 + "\n" + str.tostring(math.round(vol36, 0)))

b.boxes_plot(symbols_osc, values ? symbol_name_osc : symbol_name, 6, 0, scale)
b.boxes_plot(symbols_vol, values ? symbol_name_vol : symbol_name, 6, 1, scale)
