Invest-Long : Script for quick checks before investing
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rvc8280

//@version=5
indicator("LongTerm Investing",shorttitle="Longterm", overlay = true)

// Chec kon Daily, Weekly, Monthly time frames

tf1 = "1D"
tf2 = "1W"
tf3 = "1M"

var stats = table.new(position = position.bottom_right, columns = 18, rows = 18, bgcolor = color.white, border_width = 1, border_color=color.black, frame_color=color.black, frame_width=1)

table.cell(table_id = stats, column = 0, row = 0 , text = "D-RSI ", text_color=color.black)
table.cell(table_id = stats, column = 0, row = 1 , text = "W-RSI ", text_color=color.black)
table.cell(table_id = stats, column = 0, row = 2 , text = "M-RSI ", text_color=color.black)

expr = ta.rsi(close, 14)

//RSI on all 3 time frames all should be green and D>W>M

rs1 = request.security(syminfo.tickerid , tf1, expr)
rs2 = request.security(syminfo.tickerid , tf2, expr)
rs3 = request.security(syminfo.tickerid , tf3, expr)

table.cell(table_id = stats, column = 1, row = 0 , text = " "+str.tostring(math.round(rs1,1)), bgcolor=color.white, text_color=color.green)
table.cell(table_id = stats, column = 1, row = 1 , text = " " +str.tostring(math.round(rs2,1)), bgcolor=color.white, text_color=color.green)
table.cell(table_id = stats, column = 1, row = 2 , text = " " +str.tostring(math.round(rs3,1)), bgcolor=color.white, text_color=color.green)

get_ma_htf(tf, len)=> request.security(syminfo.tickerid, tf, ta.sma(close, len)[1])


//Check Close is above 20 SMA and 50 SMA on Daily / Weekly / Monthly time frames 
d_e_20 = get_ma_htf(tf1, 20)
w_e_20 = get_ma_htf(tf2, 20)
m_e_20 = get_ma_htf(tf3, 20)

d_e_50 = get_ma_htf(tf1, 50)
w_e_50 = get_ma_htf(tf2, 50)
m_e_50 = get_ma_htf(tf3, 50)

table.cell(table_id = stats, column = 2, row = 0 , text = "C>D-20 ", bgcolor=close>d_e_20?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 2, row = 1 , text = "C>W-20 ", bgcolor=close>w_e_20?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 2, row = 2 , text = "C>M-20 ", bgcolor=close>m_e_20?color.green:color.red, text_color=color.white)


table.cell(table_id = stats, column = 3, row = 0 , text = "C>D-50 ", bgcolor=close>d_e_50?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 3, row = 1 , text = "C>W-50 ", bgcolor=close>w_e_50?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 3, row = 2 , text = "C>M-50 ", bgcolor=close>m_e_50?color.green:color.red, text_color=color.white)


//Check SMA 13> SMA 34, SMA 34 > SMA 55 and SMA 20 > SMA 50  on Daily / Weekly time frames 

d_e_13 = get_ma_htf(tf1, 13)
d_e_34 = get_ma_htf(tf1, 34)
d_e_55 = get_ma_htf(tf1, 55)
table.cell(table_id = stats, column = 4, row = 0 , text = "D 13>34 ", bgcolor=d_e_13>d_e_34?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 4, row = 1 , text = "D 34>55 ", bgcolor=d_e_34>d_e_55?color.green:color.red, text_color=color.white)

w_e_13 = get_ma_htf(tf2, 13)
w_e_34 = get_ma_htf(tf2, 34)
w_e_55 = get_ma_htf(tf2, 55)

table.cell(table_id = stats, column = 5, row = 0 , text = "W 13>34 ", bgcolor=w_e_13>w_e_34?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 5, row = 1 , text = "W 34>55 ", bgcolor=w_e_34>w_e_55?color.green:color.red, text_color=color.white)


table.cell(table_id = stats, column = 4, row = 2 , text = "D 20>50 ", bgcolor=d_e_20>d_e_50?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 5, row = 2 , text = "W 20>50 ", bgcolor=w_e_20>w_e_50?color.green:color.red, text_color=color.white)


// Check  Current close is above Weekly Pivot and Monthly Pivot. And also verify Close is above 4 Week High. 

expr_pivot = (high + low + close) / 3.0

wk_piv = request.security(syminfo.tickerid , tf2, expr_pivot[1])
month_piv = request.security(syminfo.tickerid , tf3, expr_pivot[1])
table.cell(table_id = stats, column = 6, row = 0 , text = "C>WK-P", bgcolor=close>wk_piv?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 6, row = 1 , text = "C>Mo-P", bgcolor=close>month_piv?color.green:color.red, text_color=color.white)

expr_4wkhigh = ta.highest(4)
wk4_high = request.security(syminfo.tickerid , tf2, expr_4wkhigh)
table.cell(table_id = stats, column = 6, row = 2 , text = "C>4WK-H", bgcolor=close>wk4_high[1]?color.green:color.red, text_color=color.white)


// Verify Close is above Dail VWMA, Daily VWMA is > Weekly VWMA and Weekly > Monthly.
 

scrp_tkr = syminfo.ticker

expr_2 = ta.vwma(hlc3, 20)
v_wma(tf) => request.security(scrp_tkr,tf,expr_2)
vwma_D = v_wma('D')
vwma_W = v_wma('W')
vwma_M = v_wma('M')

table.cell(table_id = stats, column = 7, row = 0 , text = "C>D-VWMA", bgcolor=close>vwma_D?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 7, row = 1 , text = "D>W-VWMA", bgcolor=vwma_D>vwma_W?color.green:color.red, text_color=color.white)
table.cell(table_id = stats, column = 7, row = 2 , text = "W>M-VWMA", bgcolor=vwma_W>vwma_M?color.green:color.red, text_color=color.white)


// Similarly you can add more checks based on different time frames
