- Platform
-
- Thinkorswim
The P/E ratio is one of the more popular methods for valuing stocks. It is simple to calculate and easy to understand. Track the current and historical P/E ratio, to find stocks that are under and over valued. (from tosindicators)
Code:
# P/E Ratio
# Free for use. Header credits must be included when any form of the code included in this package is used.
# v1.0 - barbaros - for b4signals.com
declare lower;
def earningsValue = if IsNan(GetActualEarnings()) then 0 else GetActualEarnings();
def earningsTTM = Sum(earningsValue, 252);
plot pe = close / earningsTTM;
def LowestPE = LowestAll(pe);
def HighestPE = HighestAll(pe);
def MedianPE = Median(pe,200);
AddLabel(yes, " P/E Ratio: " + pe + " ", color.white);
AddLabel(yes, " Lowest P/E: " + LowestPE + " ", color.yellow);
AddLabel(yes, " Highest P/E: " + HighestPE + " ", color.yellow);
AddLabel(yes, " Median P/E: " + MedianPE + " ", if pe <= MedianPE then color.light_green else color.light_red);
