Table as a screener based on a simple condition

Post Reply
kalmb
Posts: 1
Joined: Thu Nov 21, 2024 9:04 pm

Table as a screener based on a simple condition

Post by kalmb »

Hello Everyone

Please forgive the noob pine question, but I wouldn't know where to find this answer in the manual:

I have the code below which would add filter based on one condition ( RSI , if the RSI > 50 the text color turn red).

My question is, how can I seperate the rows that met the condition from rows that not met the condition ?
seperate or shift the rows up and down ( like below picture of other script explain what I mean )
https://ibb.co/pwFbdpP

Thank you in advance!

https://ibb.co/pwFbdpP

Code: Select all

//@version=5
indicator("2 arrays", overlay = true)

rsi1 = request.security('AAPL', timeframe.period, ta.rsi(close, 14))
rsi2 = request.security('DIS',  timeframe.period, ta.rsi(close, 14))
rsi3 = request.security('MSFT', timeframe.period, ta.rsi(close, 14))
rsi4 = request.security('V',    timeframe.period, ta.rsi(close, 14))
rsi5 = request.security('TSLA', timeframe.period, ta.rsi(close, 14))
 
tsi1 = request.security('AAPL', timeframe.period, ta.tsi(close, 13, 25))
tsi2 = request.security('DIS',  timeframe.period, ta.tsi(close, 13, 25))
tsi3 = request.security('MSFT', timeframe.period, ta.tsi(close, 13, 25))
tsi4 = request.security('V',    timeframe.period, ta.tsi(close, 13, 25))
tsi5 = request.security('TSLA', timeframe.period, ta.tsi(close, 13, 25))
 
symbols = array.from('AAPL', 'DIS', 'MSFT', 'V', 'TSLA')
 
rsi_arr = array.from(rsi1, rsi2, rsi3, rsi4, rsi5)
tsi_arr = array.from(tsi1, tsi2, tsi3, tsi4, tsi5)
 
sorted_index = array.sort_indices(rsi_arr, order.descending)
 
var tbl = table.new(position.top_right, 3, 6, frame_width  = 1, border_width = 1, border_color = #696969)
 
if barstate.islast
    table.clear(tbl, 0, 0, 2, 5)
 
    table.cell(tbl, 0, 0, text = 'Symbol', text_color = color.white, bgcolor = #696969)
    table.cell(tbl, 1, 0, text = 'RSI',    text_color = color.white, bgcolor = #696969)
    table.cell(tbl, 2, 0, text = 'TSI',    text_color = color.white, bgcolor = #696969)
 
    for i = 0 to array.size(symbols) - 1
        si = array.get(sorted_index, i)
        table.cell(tbl, 0, i + 1, text = str.tostring(array.get(symbols, si)), text_color = color.white, bgcolor = #696969)
        table.cell(tbl, 1, i + 1, text = str.tostring(math.round(array.get(rsi_arr, si), 2)), text_color = array.get(rsi_arr, si) > 50 ? color.red : color.white, bgcolor = #aaaaaa)
        table.cell(tbl, 2, i + 1, text = str.tostring(math.round(array.get(tsi_arr, si), 2)), text_color = color.white, bgcolor = #aaaaaa)
SamiFX
Expert Trader
Posts: 7
Joined: Thu Nov 30, 2023 9:44 am

Re: Table as a screener based on a simple condition

Post by SamiFX »

Right now your code is putting all of them in the table. You have to use for loop and store the filtered ones in array and plot them in top table. And remaining in bottom table
Post Reply