> "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.
Multi-Indicator "InSync" Calculation
The script generates two main signals:
thinkScript Code
Shareable Link
https://tos.mx/SnjZe1
Created by Drew Griffith.
Multi-Indicator "InSync" Calculation
- Script defines a custom indicator called insync by summing the values of several normalized technical indicators:
- Bollinger Percent B (BBP): Normalized to 0-100.
- 2-period Relative Strength Index (RSI2).
- 14-period Relative Strength Index (RSI14).
- Money Flow Index (MFI).
- Stochastic Full (STO).
- The insync value is then rounded to the nearest multiple of 10 (numberofdigits = -1).
- This score likely represents the overall market strength or weakness across multiple timeframes/metrics.
- It defines two complex patterns, LongWickReversal and ShortWickReversal, which look for candles with a long wick in the direction of the desired reversal and a small body.
- The WickMultiplier (default 1.65) requires the reversal wick (e.g., lower wick for a bullish reversal) to be at least $1.65$ times the size of the candle body.
- The BodyPercentage (default 0.40) requires the candle body to be no more than $40\%$ of the total bar range (hi - lo).
- The specific logic is complex and handles both up and down candles (cl > op or cl < op) and Doji/Pin-bar cases (cl == op).
The script generates two main signals:
| Signal | Candlestick Condition | EMA Condition | Color Condition (Strong Signal) |
| signalUP (Bullish) | LongWickReversal == 1 | Close is below EMA10 and above or at EMA30, with EMA10 > EMA30 (price is pulling back into the short-term trend). | insync <= insync_bullpull (default 220, indicating strong oversold conditions). |
| signalDN (Bearish) | ShortWickReversal == 1 | Close is above EMA10 and below or at EMA30, with EMA10 < EMA30 (price is rallying into the short-term downtrend). | insync >= insync_bearpull (default 300, indicating strong overbought conditions). |
- The signals are plotted as up/down arrows (PaintingStrategy.ARROW_UP/ARROW_DOWN).
- The arrow is colored Green/Red for the strong "InSync" condition, and Gray if the EMA and wick conditions are met, but the "InSync" condition is not met.
- The script also includes audible alerts for both signals.
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 by a moderator: