Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
4.1 kB
29
Indexable
//@version=5
// © harora
indicator("40 Scripts with Daily RVOL", overlay=true)

// Groups for input organization
g1 = "Symbols"
g3 = "Relative and Daily Average Volume"

// Inputs
vol_len = input.int(title="Relative Volume Length", defval=20, group=g3)

s1 = input.symbol("TSLA", "S1", group=g1)
s2 = input.symbol("AAPL", "S2", group=g1)
s3 = input.symbol("NFLX", "S3", group=g1)
s4 = input.symbol("", "S4", group=g1)
s5 = input.symbol("", "S5", group=g1)
s6 = input.symbol("", "S6", group=g1)
s7 = input.symbol("", "S7", group=g1)
s8 = input.symbol("", "S8", group=g1)
s9 = input.symbol("", "S9", group=g1)
s10 = input.symbol("", "S10", group=g1)
s11 = input.symbol("", "S11", group=g1)
s12 = input.symbol("", "S12", group=g1)
s13 = input.symbol("", "S13", group=g1)
s14 = input.symbol("", "S14", group=g1)
s15 = input.symbol("", "S15", group=g1)
s16 = input.symbol("", "S16", group=g1)
s17 = input.symbol("", "S17", group=g1)
s18 = input.symbol("", "S18", group=g1)
s19 = input.symbol("", "S19", group=g1)
s20 = input.symbol("", "S20", group=g1)

// Matrix and array initialization
mtx = matrix.new<float>(0, 3, na)
syms = array.new<string>(0, na)
status_array = array.new<string>(0, na)

// Function to calculate RVOL, price relation to previous close, and other metrics for a symbol
f(sym) =>
    // Request daily volume, daily average volume, close, and previous close
    [vol_v, avg_v, close_v, prev_close] = request.security(sym, "D", [volume, ta.sma(volume, vol_len), close, close[1]], gaps=barmerge.gaps_off)
    //rv_v = (vol_v / avg_v) * 100
    rv_v = (vol_v / ta.sma(vol_v[1], vol_len)) * 100
    above_below = close_v > prev_close ? "Above" : "Below"
    if not na(sym)
        matrix.add_row(mtx, matrix.rows(mtx), array.from(vol_v, rv_v, avg_v))
        syms.push(sym)
        status_array.push(above_below)

// Apply function to each symbol
f(s1), f(s2), f(s3), f(s4), f(s5), f(s6), f(s7), f(s8), f(s9), f(s10), f(s11), f(s12), f(s13), f(s14), f(s15), f(s16), f(s17), f(s18), f(s19), f(s20)

// Table and alert initialization
var table t = na
tsize = size.normal
hcol = color.gray
ccol = #aaaaaa
tcol = color.white

if barstate.isfirst
    t := table.new(position.middle_right, 5, 21, frame_color=#151715, frame_width=1, border_width=2, border_color=color.new(color.white, 100))
    t.cell(0, 0, "Symbol", text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=hcol)
    t.cell(1, 0, "Volume", text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=hcol)
    t.cell(2, 0, "DAV", tooltip="Daily Average Volume", text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=hcol)
    t.cell(3, 0, "RVOL", tooltip="Relative Volume", text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=hcol)
    t.cell(4, 0, "Price Status", text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=hcol)

mtx_rows = matrix.rows(mtx)

if mtx_rows > 0
    for i = 0 to mtx_rows - 1
        mtx_row_data = matrix.row(mtx, i)
        sym = syms.get(i)
        above_below = status_array.get(i)

        vol_ = mtx_row_data.get(0)
        rv_ = mtx_row_data.get(1)
        avgv_ = mtx_row_data.get(2)

        if barstate.islastconfirmedhistory or barstate.isrealtime
            t.cell(0, i + 1, sym, text_halign=text.align_left, text_size=tsize, text_color=tcol, bgcolor=hcol)
            t.cell(1, i + 1, str.tostring(vol_, format.volume), text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=ccol)
            t.cell(2, i + 1, str.tostring(avgv_, format.volume), text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=ccol)
            t.cell(3, i + 1, str.tostring(math.round(rv_, 2)) + "%", text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=rv_ > 50 ? color.green : color.red)
            t.cell(4, i + 1, above_below, text_halign=text.align_center, text_size=tsize, text_color=tcol, bgcolor=above_below == "Above" ? color.green : color.red)
Leave a Comment