The Cyclically Adjusted Price-to-Earnings Ratio (CAPE Ratio), also known as the Shiller P/E Ratio, is a long-term valuation measure for stocks. It was developed by Robert Shiller and smooths out earnings fluctuations by using an inflation-adjusted average of the last 10 years of earnings.
This TradingView Pine Script indicator calculates the CAPE Ratio for a specific stock by:
Fetching historical Earnings Per Share (EPS) data using request.earnings(). Adjusting the EPS for inflation by dividing it by the Consumer Price Index (CPI). Computing the 10-year (40-quarter) moving average of the inflation-adjusted EPS. Calculating the CAPE Ratio as (Stock Price) / (10-year Average EPS adjusted for inflation). Plotting the CAPE Ratio on the chart with a reference line at CAPE = 20, a historically significant threshold.