Silen's Financials P/E & P/S[x10] Rates
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © The_Silen

//@version=4
study("Silen's Financials P/E & P/S[x10] Rates", overlay=true, scale = scale.left)
string str= (syminfo.prefix+":"+syminfo.ticker) 

float pe_rate_pos = 0
float pe_rate_neg = 0
int pe_rate_max = 100
transp_pe_pos = color.new(color.green,50)
transp_pe_neg = color.new(color.red,50)



eps_rate = financial (str, "EARNINGS_PER_SHARE", "TTM")
pe_rate = close/eps_rate
pe_rate_fwd_fq = financial (str, "PRICE_EARNINGS_FORWARD", "FQ")
pe_rate_fwd_fy = financial (str, "PRICE_EARNINGS_FORWARD", "FY") 


tso = financial (str, "TOTAL_SHARES_OUTSTANDING", "FQ")
rev_total = financial (str, "TOTAL_REVENUE", "TTM")
market_cap = tso * close
ps_rate = market_cap / rev_total
ps_rate_fwd_fq = financial (str, "PRICE_SALES_FORWARD", "FQ") 
ps_rate_fwd_fy = financial (str, "PRICE_SALES_FORWARD", "FY") 

//targeta = close / (((ps_rate / 3) / 2) + ((pe_rate / 17.5) / 2))

if (pe_rate > 0)
    pe_rate_pos := pe_rate
    
if (pe_rate < 0)
    pe_rate_neg := pe_rate *(-1)

if (pe_rate_pos > pe_rate_max)
    pe_rate_pos := pe_rate_max
    
if (pe_rate_neg > pe_rate_max)
    pe_rate_neg := pe_rate_max
    
if (pe_rate_pos == 0)
    transp_pe_pos := color.new(color.green,100)

if (pe_rate_neg == 0)
    transp_pe_neg := color.new(color.red,100)
    
    

plot(pe_rate_pos, color = transp_pe_pos)
plot(pe_rate_neg, color = transp_pe_neg)
plot(ps_rate * 10, color = color.yellow, transp = 50 )
//plot(pe_rate_fwd_fq, color = color.white)
//plot(pe_rate_fwd_fy, color = color.blue)
//plot(targeta, color = color.purple)