P/E Ratio

A custom indicator created by TrendSpider Team on TrendSpider. You can import this custom indicator into your TrendSpider account. Don't have TrendSpider? Create an account first, then import the custom indicator.

Chart featuring the P/E Ratio indicator

This indicator paints the trailing P/E ratio for a given ticker symbol.

Source code

This indicator had been implemented by TrendSpider Team in JavaScript on TrendSpider. Check out the developer documentation to learn more about JS on TrendSpider.

describe_indicator('P/E Ratio', 'lower');
const epsMathType = input('P/E Type', 'Trailing', ['Qtr', 'Trailing']);
const earnings = await request.earnings(constants.ticker);
if (!Array.isArray(earnings)) {
    return;
}
const pastEarnings = earnings.filter(record => !record.isFuture);
const epsSeries = pastEarnings.map(record => record.eps);
const trailingEpsSeries = sum(epsSeries, 4);
const values = epsMathType == 'Qtr' ? epsSeries : trailingEpsSeries;
const timestamps = pastEarnings.map(record => record.timestamp);
const epsLanded = land_points_onto_series(
    timestamps,
    values,
    time,
    'ge'
);
let epsInterpolated = interpolate_sparse_series(epsLanded, 'constant');
if (epsInterpolated[epsInterpolated.length - 1] == null) {
    epsInterpolated = horizontal_line(values[values.length - 1]);
}
const resultingLine = for_every(close, epsInterpolated, (c, eps) => c / eps); 
paint(resultingLine, { name: 'PE Ratio', color: 'grey' });