Rule of 40
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © barnabygraham

// The rule of 40 is a popular metric for measuring the quality of SaaS companies. It is the sum of the year over year sales growth and profit margin. Companies are considered good if this sum is above 40.

//@version=5
indicator("Rule of 40")

sales = request.financial(syminfo.tickerid,'TOTAL_REVENUE','FY')
var salesGrowth = 0.
if sales != sales[1]
    salesGrowth := ((sales/sales[1])-1)*100

netIncome = request.financial(syminfo.tickerid,'NET_INCOME','FY')
operatingMargin = (netIncome/sales)*100

ruleOf40 = salesGrowth + operatingMargin
plot(ruleOf40,'Rule of 40')

plot(salesGrowth,'Sales Growth',color=color.orange,display=display.none)
plot(operatingMargin,'Operating Margin',color=color.teal,display=display.none)