PEG Ratio scan study for ThinkorSwim


New member
I'm trying to create a script to scan for PEG ratio. Price to Earnings / Growth where growth is the average trailing 5 years growth ideally. See

I'd also like to have it show up as a column in the scan results if possible. I came up with something but it's not working. This is my first attempt at thinkscript after looking at some examples online. I'm not sure if this is the best way to get the anuallized trailing earnings or if there is something better.

Can someone please help me figure this out?

def AE = if IsNaN(GetActualEarnings()) then 0 else GetActualEarnings();
def EPS_TTM = Sum(AE, 252);#The sum of the trailing twelve months EPS
def EPS_24= Sum(AE, 252);#The sum of the trailing 24 months EPS
def EPS_PY = EPS_24 - EPS_TTM; # prioryear last 24 - last 12
def GROWTH = (EPS_TTM - EPS_PY)/EPS_PY * 100;
def PE = close/ EPS_TTM;
plot scan = PEG;

Similar threads