Power Earnings Gaps (PEG) Scanner for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
Power Earnings Gappers (PEG) is a strategy shared by @traderstewie at Art of Trading. If you haven't check out the original article, you can do so here.

This scanner for ThinkorSwim just makes it easier to find potential stocks that fit the criteria. It was developed by Drew Griffith.



PEG Scanner

Rich (BB code):
#hint: SCAN (only) for "PEG" stands for power earnings gap. looking for a pullback from a previous gap and the stock is in a consolidation phase.

declare upper;
input percentage = 0.5; #hint: % gap
input wthn = 30; # periods to look for gap
def x = 1 + percentage / 100;

def cl = close;
def lo = low;
def hi = high;
def op = open;
def vo = volume;
def barnumber = BarNumber();

def gapup = lo > hi[1] * x;
def sign_up = if gapup then barnumber else 0;
def cup = (barnumber - Highest(sign_up[1], wthn));
def count_up = if barnumber <= wthn then 0 else if cup > wthn then 0 else cup;

def gapdn = hi * x < lo[1];
def sign_dn = if gapdn then barnumber else 0;
def cdn = (barnumber - Highest(sign_dn[1], wthn));
def count_dn = if barnumber <= wthn then 0 else if cdn > wthn then 0 else cdn;

input ema_10 = 10;
input ema_30 = 30;
input ema_300 = 300;

def EMA10 = MovAvgExponential(cl, ema_10);
#EMA10.AssignValueColor(Color.CYAN);
#EMA10.HideBubble();
#EMA10.HideTitle();
#EMA10.SetLineWeight(1);
#EMA10.SetPaintingStrategy(PaintingStrategy.LINE);

def EMA30 = MovAvgExponential(cl, ema_30);
#EMA30.AssignValueColor(Color.MAGENTA);
#EMA30.HideBubble();
#EMA30.HideTitle();
#EMA30.SetLineWeight(1);
#EMA30.SetPaintingStrategy(PaintingStrategy.LINE);

#def EMA300 = MovAvgExponential(cl, ema_300);
#EMA300.AssignValueColor(Color.GREEN);
#EMA300.HideBubble();
#EMA300.HideTitle();
#EMA300.SetLineWeight(2);
#EMA300.SetStyle(Curve.LONG_DASH);
#EMA300.SetPaintingStrategy(PaintingStrategy.LINE);

plot signal =
if cl <= EMA10 and cl >= EMA30 and EMA10 >= EMA30 and count_up > 0 and average(vo,5) < average(vo,50) then 1 else
if cl >= EMA10 and cl <= EMA30 and EMA10 <= EMA30 and count_dn > 0 and average(vo,5) < average(vo,50) then 1 else 0;
 
Last edited:
N

Neel

New member
Hi
This is an interesting strategy. But, Im confused how to use this. As in, how do I set up the scanner - do I have to copy the script into the scanner part or do I have to copy this as an indicator/strategy code and set up the scanner separately ?
Thanks is advance
 
MBF

MBF

Active member
VIP
Warehouse
Copy the script, go to studies in TOS, click Create, delete everything then paste script above into study, change the name at the top and hit okay. Go to Scan, hit Study Filter, go all the way down to custom, hit delete, add condition, scroll to study, find whatever you named the study, click it, select "is true" within "however many bars". Hit okay and scan.
Don't forget aggregation periods for your scans.
 
markos

markos

Well-known member
VIP
Warehouse
@MBF thank you for giving that very succinct explanation. It often takes me three paragraphs to say what you did in four sentences or so. 🙏
Much wine for you, my friend.
 
  • Like
Reactions: MBF
MBF

MBF

Active member
VIP
Warehouse
@MBF thank you for giving that very succinct explanation. It often takes me three paragraphs to say what you did in four sentences or so. 🙏
Much wine for you, my friend.
Welcome!
I'm always willing to help with the small but important things so you guys can handle the big stuff I am not that great at ... yet.
 
J

jacqshen

New member
Warehouse
I got the scan set up and it works great showing me the stocks that have gapped up on their past earnings but what do I need to add for it to show me stocks that have had earning gap ups within the past day or two? Thanks in advance!!
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@jacqshen Have you tried to use the "within X bars" feature? That will allows you to set a lookback period.
 
J

jacqshen

New member
Warehouse
@BenTen I did try “within 1 bar” and “within 3 bars”. I’ll play with it a little more and see what happens. Thanks!
 
markos

markos

Well-known member
VIP
Warehouse
@jacqshen There may not be many stocks that have earnings yet. Or, gaps may not have happened yet.
Save it as a Dynamic Scan and it will update every 3 minutes so that when earnings come rolling in over the next few weeks you can see the gappers when they occur.
Go here: Marketwach > Calendar > Uncheck all > Check Earnings > now you can see that there were only 8 or so companies that reported today.
 
J

jacqshen

New member
Warehouse
@markos Thank you! I will go do this. Learning so much here!
 
markos

markos

Well-known member
VIP
Warehouse
@jacqshen Put this in as a Watchlist Column. Then you'll know the scheduled date. I use this one. Origin unknown, no citation.
Code:
#Days_til_Earns Markos uTS
input length = 60;
def xx= -geteventOffset(events.EARNINGS);
def yy = sum(hasEarnings(type = earningTime.AFTER_MARKET),length)[-length +1] >0;
plot x=xx+yy*.5;
x.assignvaluecolor( if yy!=0 then color.LIGHT_RED else color.DARK_GRAY);


@BenTen please feel free to move or copy this to another thread.
 
Last edited:

Top