Create scan based on difference in Earnings

hdsouza

New member
I want to get a scan of all stocks which have at least a 100% Earnings increase over the last year.
For example for stock symbol PENN , Current earnings = 0.93 and the Earning a year ago is 0.38
So percentage Earnings increase over the year = ((0.93 * 100)/0.38) - 100 = 144

Here is the TOS script I wrote, but it does not give me any stocks when I run the scan.
Code:
declare lower;
def EPS = GetActualEarnings();
def EPS_YearAgo = EPS[-5];
def EPS_YearDiff = ((EPS * 100) / EPS_YearAgo) - 100;
def EPS_Good = EPS_YearDiff is greater than 100;
plot scan = EPS_Good;

Please help. Thanks
 

XeoNoX

Well-known member
VIP
You can test it with the label first in a chart and make sure the values are right as I didn't check for formulas to see if you are calculating right, you are going to have to aggregate by DAY so to get years back you have to count by trading days.

Code:
def Get_earnings = if IsNaN(GetActualEarnings()) then 0 else GetActualEarnings();
def EPS_YearAgo = Sum(Get_earnings, 252);
def EPS_2YearAgo = Sum(Get_earnings, 504);;
def EPS_YearDiff = ((EPS_YearAgo * 100) /  EPS_2YearAgo) - 100;
def EPS_Good = EPS_YearDiff is greater than 100;
def test = EPS_Good;

AddLabel (yes, "              TEST " +  (  EPS_YearDiff)  );
 

hdsouza

New member
Thanks @XeoNoX . That set me on the right path. I was able to get it to work right. except when there is no EPS a year ago (stock = BRMK), then the EPSGrowthYoY becomes infinity.

To correct this if I add: if (EPS[252] == 0) then {EPSGrowthYoY = 0;} it errors out.

Code:
declare lower;
def EPS = if !isNaN(GetActualEarnings()) then GetActualEarnings() else EPS[1];
def EPSGrowthYoY = 100*(EPS - EPS[252])/AbsValue(EPS[252]);
#if (EPS[252] == 0) then {EPSGrowthYoY = 0;}
def EPS_Good =  EPSGrowthYoY is greater than 100;
plot scan = EPS_Good;
AddLabel(yes, "EPSGrowthYoY% = " + EPSGrowthYoY+"%", color = Color.Blue);
 

Similar threads

Top