OPEN-SOURCE SCRIPT

Buffett Quality Filter (TTM)

25
//version=6
indicator("Buffett Quality Filter (TTM)", overlay = true, max_labels_count = 500)

// 1. Get financial data (TTM / FY / FQ)

// EPS (TTM) for P/E
eps = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_BASIC", "TTM")

// Profitability & moat (annual stats)
roe = request.financial(syminfo.tickerid, "RETURN_ON_EQUITY", "FY")
roic = request.financial(syminfo.tickerid, "RETURN_ON_INVESTED_CAPITAL", "FY")

// Margins (TTM – rolling 12 months)
grossMargin = request.financial(syminfo.tickerid, "GROSS_MARGIN", "TTM")
netMargin = request.financial(syminfo.tickerid, "NET_MARGIN", "TTM")

// Balance sheet safety (quarterly)
deRatio = request.financial(syminfo.tickerid, "DEBT_TO_EQUITY", "FQ")
currentRat = request.financial(syminfo.tickerid, "CURRENT_RATIO", "FQ")

// Growth (1-year change, TTM)
epsGrowth1Y = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_BASIC_ONE_YEAR_GROWTH", "TTM")
revGrowth1Y = request.financial(syminfo.tickerid, "REVENUE_ONE_YEAR_GROWTH", "TTM")

// Free cash flow (TTM) and shares to build FCF per share for P/FCF
fcf = request.financial(syminfo.tickerid, "FREE_CASH_FLOW", "TTM")
sharesOut = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")

fcfPerShare = (not na(fcf) and not na(sharesOut) and sharesOut != 0) ? fcf / sharesOut : na

// 2. Valuation ratios from price
pe = (not na(eps) and eps != 0) ? close / eps : na
pFcf = (not na(fcfPerShare) and fcfPerShare > 0) ? close / fcfPerShare : na

// 3. Thresholds (Buffett-style, adjustable)
minROE = input.float(15.0, "Min ROE %")
minROIC = input.float(12.0, "Min ROIC %")
minGM = input.float(30.0, "Min Gross Margin %")
minNM = input.float(8.0, "Min Net Margin %")
maxDE = input.float(0.7, "Max Debt / Equity")
minCurr = input.float(1.3, "Min Current Ratio")
minEPSG = input.float(8.0, "Min EPS Growth 1Y %")
minREVG = input.float(5.0, "Min Revenue Growth 1Y %")
maxPE = input.float(20.0, "Max P/E")
maxPFCF = input.float(20.0, "Max P/FCF")

// 4. Individual conditions
cROE = not na(roe) and roe > minROE
cROIC = not na(roic) and roic > minROIC
cGM = not na(grossMargin) and grossMargin > minGM
cNM = not na(netMargin) and netMargin > minNM
cDE = not na(deRatio) and deRatio < maxDE
cCurr = not na(currentRat) and currentRat > minCurr
cEPSG = not na(epsGrowth1Y) and epsGrowth1Y > minEPSG
cREVG = not na(revGrowth1Y) and revGrowth1Y > minREVG
cPE = not na(pe) and pe < maxPE
cPFCF = not na(pFcf) and pFcf < maxPFCF

// 5. Composite “Buffett Score” (0–10) – keep it on ONE line to avoid line-continuation errors
score = (cROE ? 1 : 0) + (cROIC ? 1 : 0) + (cGM ? 1 : 0) + (cNM ? 1 : 0) + (cDE ? 1 : 0) + (cCurr ? 1 : 0) + (cEPSG ? 1 : 0) + (cREVG ? 1 : 0) + (cPE ? 1 : 0) + (cPFCF ? 1 : 0)

// Strictness
minScoreForPass = input.int(7, "Min score to pass (0–10)", minval = 1, maxval = 10)
passes = score >= minScoreForPass

// 6. Visuals
bgcolor(passes ? color.new(color.green, 80) : na)
plot(score, "Buffett Score (0–10)", color = color.new(color.blue, 0))

// Info label on last bar
var label infoLabel = na
if barstate.islast
if not na(infoLabel)
label.delete(infoLabel)
infoText = str.format(
"Buffett score: {0}\nROE: {1,number,#.0}% | ROIC: {2,number,#.0}%\nGM: {3,number,#.0}% | NM: {4,number,#.0}%\nP/E: {5,number,#.0} | P/FCF: {6,number,#.0}\nD/E: {7,number,#.00} | Curr: {8,number,#.00}",
score, roe, roic, grossMargin, netMargin, pe, pFcf, deRatio, currentRat)
infoLabel := label.new(bar_index, high, infoText,
style = label.style_label_right,
color = color.new(color.black, 0),
textcolor = color.white,
size = size.small)

免責事項

この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。