IOFin F-Score by zdmre
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zdmre
//@version=5
indicator('IOFin F-Score by zdmre', overlay = false, precision=0)

period = input.string('FY', 'Financial Period', options=['FQ', 'FY'], tooltip='FQ: Financial Quarter\nFY: Financial Year')

pb = request.financial(syminfo.tickerid,"BOOK_VALUE_PER_SHARE", period)
de = request.financial(syminfo.tickerid,"DEBT_TO_EQUITY", period)
pfcf= close/request.financial(syminfo.tickerid,"FREE_CASH_FLOW", period)
sgr = request.financial(syminfo.tickerid,'SUSTAINABLE_GROWTH_RATE', period)
peg = request.financial(syminfo.tickerid,'PEG_RATIO', period)
evtoebitda = request.financial(syminfo.tickerid,'ENTERPRISE_VALUE_EBITDA', period)
roe = request.financial(syminfo.tickerid,'RETURN_ON_EQUITY', period) 
roic = request.financial(syminfo.tickerid,'RETURN_ON_INVESTED_CAPITAL', period)
qr = request.financial(syminfo.tickerid,'QUICK_RATIO', period)
opmar = request.financial(syminfo.tickerid,'OPERATING_MARGIN', period)

pb_ = na(pb) ? na : pb < 3  ? 1 : 0
de_ = na(de) ? na : de < 0.5 ? 1 : 0
pfcf_ = na(pfcf) ? na : (pfcf > 0) and (pfcf <= 20) ? 1 : 0
sgr_ = na(sgr) ? na : sgr > 0.3 ? 1 : 0
peg_ = na(peg) ? na : (peg > 0) and (peg < 1) ? 1 : 0
evtoebitda_ = na(evtoebitda) ? na : evtoebitda < 10 ? 1 : 0,
roe_ = na(roe) ? na : roe > 0.3 ? 1 : 0
roic_ = na(roic) ? na : roic > 0.07 ? 1 : 0
qr_ = na(qr) ? na : qr >= 1 ? 1 : 0
opmar_ = na(opmar) ? na : opmar > 0.15 ? 1 : 0

iofinf = pb_ + de_ + pfcf_ + sgr_ + peg_ + evtoebitda_ + roe_ + roic_ + qr_ + opmar_
io_c = color.from_gradient(iofinf, 2, 9  , color.new(#f64343, 0), color.new(#41fc47, 0))   
if barstate.islast
    label.new(bar_index, iofinf,  text="IOFin F-Score: " + str.tostring(iofinf), size = size.normal, textcolor=color.rgb(0, 0, 0),  style=label.style_label_left, color = io_c)
plot(iofinf,style=plot.style_stepline_diamond, linewidth=4, join=true, color = io_c)