Price Earnings Gap (PEG) Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
> "PEG" stands for price earnings gap and also known as the holy grail setup. looking for a pullback from a previous gap and the stock is in a consolidation between the EMA10-30. The candlesticks are important here to confirm the move. The insync code helps to confirm the move. Arrows will still be plotted if insync value does NOT confirm the move, but gray color instead of red or green. Consider a half size position on a gray signal.

Created by Drew Griffith.

VJWwtJk.png


thinkScript Code
Rich (BB code):
declare upper;
def cl = close;
def lo = low;
def hi = high;
def op = open;

input ema_10 = 10;
input ema_30 = 30;
input WickMultiplier = 1.65; #2.0
input BodyPercentage = 0.40; #.25
input insync_bullpull=220;
input insync_bearpull=300;

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

plot EMA30 = MovAvgExponential(cl, ema_30);
EMA30.AssignValueColor(Color.MAGENTA);
EMA30.HideBubble();
EMA30.HideTitle();
EMA30.Hide();
EMA30.SetLineWeight(2);
EMA30.SetPaintingStrategy(PaintingStrategy.LINE);

# InSync calcs
# study definitions
def bbp_length = 20;
def mfi_length = 14;
def sto_length = 14;
def rsi2_length = 2;
def rsi14_length = 14;
def rsi2 = RSI(length = rsi2_length);
def rsi14 = RSI(length = rsi14_length);
def mfi = MoneyFlowIndex(length = mfi_length);
def sto = StochasticFull("k period" = sto_length);
def bp = BollingerPercentB(length = bbp_length, "average type" = "exponential");
def bbp = if bp >= 100 then 100 else if bp <= 0 then 0 else bp;
def insync = Round(bbp + rsi2 + rsi14 + mfi + sto, numberofdigits = -1);

def LongWickReversal = if cl > op
    and (op - lo) >= ((cl - op) * WickMultiplier)
    and (hi - cl) <= ((hi - lo) * BodyPercentage)
    or cl < op
    and (cl - lo) >= ((op - cl) * WickMultiplier)
    and (hi - cl) <= ((hi - lo) * BodyPercentage)
    or cl == op and cl != hi
    and hi - lo >= Average(hi - lo, 50) then 1
    else 0;

def ShortWickReversal = if cl < op
    and (hi - op) >= ((op - cl) * WickMultiplier)
    and (cl - lo) <= ((hi - lo) * BodyPercentage)
    or cl > op
    and (hi - cl) >= ((cl - op) * WickMultiplier)
    and (cl - lo) <= ((hi - lo) * BodyPercentage)
    or cl == op and cl != lo
    and (hi - lo) >= ((cl - lo) * WickMultiplier)
    and (cl - lo) <= ((hi - lo) * BodyPercentage)
    or op == lo and cl == lo
    and hi - lo >= Average(hi - lo, 50) then 1 else 0;

plot signalUP = if cl < EMA10 and cl >= EMA30 and EMA10 > EMA30
     and (LongWickReversal == 1)
     then lo else Double.NaN;
signalUP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
signalUP.SetLineWeight(2);
signalUP.AssignValueColor(if cl < EMA10 and cl >= EMA30 and EMA10 > EMA30
     and (LongWickReversal == 1) and insync <= insync_bullpull
     then Color.GREEN else Color.gray);

plot signalDN = if cl > EMA10 and cl <= EMA30 and EMA10 < EMA30
     and (ShortWickReversal == 1)
     then hi else Double.NaN;
signalDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
signalDN.SetLineWeight(2);
signalDN.AssignValueColor(if cl > EMA10 and cl <= EMA30 and EMA10 < EMA30
     and (ShortWickReversal == 1) and insync >= insync_bearpull
     then Color.RED else Color.gray);

input audibleAlerts = yes;
Alert(If(signalUP, 1, 0) within 1 bars, "BULLISH PEG", Alert.BAR, Sound.Ding);
Alert(If(signalDN, 1, 0) within 1 bars, "BEARISH PEG", Alert.BAR, Sound.Ding);

Shareable Link
https://tos.mx/SnjZe1

 
Last edited:

mo2020

New member
Dynamic StopLoss following an indicator I need your help ben to convert it to TOS . Thanks

 
Last edited:

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
@ukwildcat1998 Still works for me. Please check again.



@mo2020 Please create a new post with your request. Do not post it under any other topics.

 
Last edited:

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top