OPEN-SOURCE SCRIPT

Price to Sales Ratio [Gabremoku]

329
Price to Sales Ratio [Gabremoku] is a valuation indicator designed to help investors analyze how expensive or cheap a stock is relative to its revenue.

The script calculates the P/S ratio using market capitalization divided by total trailing-twelve-month revenue, then enriches that raw valuation with historical averages, rolling Z-score, percentile ranking, 52-week extremes, and sector benchmark comparison. The price-to-sales ratio is commonly used as a revenue multiple, especially for companies where earnings may be weak, negative, or highly variable.

This makes the indicator useful for growth stocks, cyclical companies, and early-stage businesses where price-to-earnings can be less informative than revenue-based valuation.

What it shows
📊 Current P/S Ratio — the live valuation multiple based on:

current stock price

total shares outstanding

trailing-twelve-month revenue

📈 Historical Average — choose between:

Cumulative Average for the full available history

Rolling Average based on a user-defined lookback in years

🧮 Z-Score Mode — switch from raw P/S to a statistical valuation view that shows how far the current ratio is from its rolling average in standard deviations.

📍 Historical Percentile — shows where the current P/S sits within its historical range over the selected lookback.

📅 52-Week High / Low — provides a fast valuation range reference for the last trading year.

🏭 Sector Benchmark — compare the company’s P/S ratio against a benchmark using:

Auto-detected sector

Sector index

Manual sector value

Why P/S matters
The P/S ratio tells you how much investors are paying for each dollar of company revenue. A lower P/S ratio is often considered more attractive when comparing similar companies in the same industry, but sector differences matter a lot.

That last part is important: P/S should not be judged in isolation. Technology companies often trade at much higher revenue multiples than energy, materials, or consumer businesses, so comparing a stock only against a generic threshold can be misleading. Sector-relative comparison is generally more meaningful than absolute comparison.

Benchmark logic
This indicator includes one of its strongest features: sector context.

It can automatically estimate a sector benchmark through:

exact ticker lookup

keyword-based sector detection

manual fallback sector selection

That matters because P/S multiples vary materially by industry, and valuation comparison is most useful when done against companies or sectors with similar economic characteristics.

The script then colors the main P/S line with a practical valuation model:

🟢 Green — P/S below benchmark, potentially undervalued relative to sector

🟠 Orange — P/S above benchmark but below historical average, more neutral / fair-value zone

🔴 Red — P/S above historical average, potentially expensive relative to its own history

Features
✅ Live Price-to-Sales ratio calculation

✅ Uses total shares outstanding and TTM revenue

✅ Cumulative or rolling historical average

✅ Z-score mode for statistical valuation

✅ Historical percentile ranking

✅ 52-week valuation high/low

✅ Sector benchmark comparison

✅ Auto sector detection with hybrid logic

✅ Manual and sector-index benchmark options

✅ Dynamic color coding based on valuation regime

✅ Ultra-smooth gradient fill between current P/S and benchmark

✅ Dashboard with key statistics

✅ Last-value chart label

How to use
A practical way to read the script is:

🔎 Start with the current P/S ratio.

📊 Compare it with the sector benchmark to see whether the stock trades richer or cheaper than its industry.

🧮 Check the Z-score to understand whether the current valuation is stretched versus its own historical behavior.

📍 Use the percentile to see where today’s valuation sits within the selected lookback window.

This approach combines absolute valuation, relative valuation, and historical context in one screen, which is much more useful than reading the raw P/S ratio alone.

Operational suggestion
💡 Suggested workflow

🟢 Value watchlist setup: look for stocks with current P/S below sector benchmark and below their own historical average. A lower P/S relative to peers can indicate more attractive valuation, provided the business quality is not deteriorating.

🟠 Neutral zone: if the stock is above benchmark but still below or near its historical average, it may be in a fairer valuation zone rather than clearly cheap or expensive.

🔴 Stretch zone: if the stock is trading with a high Z-score, high percentile, and above both benchmark and average, it may be priced aggressively relative to its own history and sector context.

📈 Best use case: this indicator is especially useful for companies with unstable earnings, where P/E may be less reliable and revenue multiples can provide a cleaner valuation anchor.

A strong practical rule:

use P/S for initial screening

use sector benchmark for context

use Z-score and percentile for timing

then confirm with margins, growth, debt, and cash flow

Because revenue alone does not tell you whether that revenue is profitable.

Notes
This indicator is best suited for relative valuation analysis, not for making a final investment decision on its own. A low P/S ratio can reflect undervaluation, but it can also reflect weak margins, declining sales quality, or poor business outlook, so it should always be paired with profitability and growth analysis.

Author: Gabremoku

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.