• Get $40 off VIP by signing up for a free account! Sign Up

Two Legged Pullback Indicator For ThinkOrSwim

tradegeek

Active member
2019 Donor
Code:
# "Normal" PullBack Zone
# Attempting to define a typical pullback area using imp_volatility()
# v.01 7.31.18
# Nube

input AcceptableBarsToEntry = 7;
input HeadroomTicks = 1;
input Fixins = no;

def c  = close;
def na = Double.NaN;
def bn = BarNumber();
def tick = TickSize();

def firstThing  = Average(c,20);
def secondThing = Average(c,100);
def upCross   = c > secondThing &&
                firstThing crosses above secondThing;
def upStop    = c crosses below secondThing;
def downCross = c < secondThing &&
                firstThing crosses below secondThing;
def downStop  = c crosses above firstThing;

def iv  = if   !IsNaN(imp_volatility())
          then imp_volatility()
          else iv[1];
def SD1 = c * iv * Sqrt((AcceptableBarsToEntry/(AggregationPeriod.DAY/GetAggregationPeriod())) / 365);
def SD2 = SD1 * 2;

def buyBar = if   upCross
                  then bn
                  else buyBar[1];
def buyStop = if   bn == buyBar
              then c - SD2 - tick * HeadroomTicks
              else if   upStop
                   then na
                   else buyStop[1];
def buyPrice   = if   bn == buyBar
                 then c
                 else buyPrice[1];
def buyRetrace = if   bn == buyBar
                 then c - SD1
                 else if   upStop
                      then na
                      else buyRetrace[1];
def buyRiskOff = if   bn == buyBar
                 then c + SD1
                 else if   upStop
                      then na
                      else buyRiskOff[1];

def sellBar = if   downCross
              then bn
              else sellBar[1];
def sellPrice = if   bn == sellBar
                then c
                else sellPrice[1];
def sellStop = if   bn == sellBar
               then c + SD2 + tick * HeadroomTicks
               else if   downStop
                    then na
                    else sellStop[1];
def sellRetrace = if   bn == sellBar
                  then c + SD1
                  else if   downStop
                       then na
                       else sellRetrace[1];
def sellRiskOff = if   bn == sellBar
                  then c - SD1
                  else if   downStop
                       then na
                       else sellRiskOff[1];

plot
LongEntry;
LongEntry.  SetDefaultColor(CreateColor(100,200,100));
LongEntry.  SetPaintingStrategy(PaintingStrategy.Arrow_Up);
LongEntry = if   bn == buyBar
            then low - tick * HeadroomTicks
            else na;
          
plot
LongRetrace = Round(buyRetrace,2);
LongRetrace.  SetStyle(Curve.Short_Dash);
LongRetrace.  SetDefaultColor(CreateColor(100,200,100));

plot
LongStop = Round(buyStop,2);
LongStop.  SetDefaultColor(CreateColor(200,100,100));
LongStop.  SetStyle(Curve.Firm);

plot
LongRiskOff = Round(buyRiskOff,2);
LongRiskOff.  SetDefaultColor(Color.Pink);
LongRiskOff.  SetStyle(Curve.Medium_Dash);

plot
ShortEntry;
ShortEntry.  SetDefaultColor(CreateColor(200,100,100));
ShortEntry.  SetPaintingStrategy(PaintingStrategy.Arrow_Down);
ShortEntry = if   bn == sellBar
             then high + tick * HeadroomTicks
             else na;
          
plot
ShortRetrace = Round(sellRetrace,2);
ShortRetrace.  SetStyle(Curve.Short_Dash);
ShortRetrace.  SetDefaultColor(CreateColor(200,100,100));

plot
ShortStop = Round(sellStop,2);
ShortStop.  SetDefaultColor(CreateColor(100,200,100));
ShortStop.  SetStyle(Curve.Firm);

plot
ShortRiskOff = Round(sellRiskOff,2);
ShortRiskOff.  SetDefaultColor(CreateColor(155,225,155));
ShortRiskOff.  SetStyle(Curve.Medium_Dash);

AddChartBubble(Fixins && LongEntry, LongStop, "Long Stop \n" +LongStop, Color.Red,0);
AddChartBubble(Fixins && LongEntry, LongRiskOff, "Long Risk Off: " +LongRiskOff+ "\n 1 SD: "+ Round(SD1,2), Color.Pink);
AddChartBubble(Fixins && ShortEntry, ShortStop, "Short Stop \n" +ShortStop, Color.Green);
AddChartBubble(Fixins && ShortEntry, ShortRiskOff, "Short Risk Off: " +ShortRiskOff+ "\n 1 SD: "+ Round(SD1,2), CreateColor(155,225,155), 0);

def LE = if !IsNaN(c) then buyPrice else na;
def SE = if !IsNaN(c) then sellPrice else na;
AddCloud(if (Fixins, LE, na), LongRetrace, CreateColor(155,225,155));
AddCloud(if (Fixins, ShortRetrace, na), SE, Color.Pink);

# f/ "Normal" PullBack Zone
 
Last edited by a moderator:
@tradegeek
I am giving this a try. I was wondering what is the meaning when the lines stretch to the right for many bars, even when the opening position signal is pretty old. This means that the opening is still valid? Thanks for sharing this signal!
 
Last edited by a moderator:
@tradegeek
I am giving this a try. I was wondering what is the meaning when the lines stretch to the right for many bars, even when the opening position signal is pretty old. This means that the opening is still valid? Thanks for sharing this signal!
The answer would be maybe. No indicator can be used in isolation. You would need to use your other indicators to determine if you were still in an applicable trading zone.
 
Thanks for providing this study. Is this supposed to work on the 1min chart? I just added it and it is not showing anything on the chart. Is there something I am missing?
 
Thanks for providing this study. Is this supposed to work on the 1min chart? I just added it and it is not showing anything on the chart. Is there something I am missing?
You haven't provided enough information to troubleshoot what issue you might be having.
The indicator does work on a one minute chart.
I went into settings and made the sizes over big and the colors very contrast-y so to provide a distinct visual:
ASHZfo0.png
 
@MerryDay thanks for the screenshot. I can see it now on the 1 min. Do you mind explaining the concept behind this indicator? I was actually thinking it was similar to this indicator:
but I realized it follows a different strategy. Thanks.

Any idea if anyone here made a script similar to the one on the youtube channel?
Thanks again for your help.
 
Here is a 2-Legged Pullback Counter code. It may require further editing to improve. Such as, there is a need for inputs for tick count etc.

Code:
# Counting Legs for Two Leg Pullback
# mrb 20220212
# This script counts pullbacks to buy on high probability moves
# buy point for bull side is second pullback after a swing high
# buy point for bull side is second pullback after a swing low
###

def SwLo1 = 10000;
def SwHi1 = 0;
#---> Count Bull Retracement Legs
def BullRetrace = if high == high[1]
    then if high < high[2] and high < high[-1]
            then 1
            else 0
    else if high < high[1] and high < high[-1]
    then 1
    else 0;
def SwLo2 = if BullRetrace and high < SwLo1
    then high
    else SwLo2[1];
def SwLo = if BullRetrace and high < SwLo2[1]
    then 1
    else 0;
def BullCount = if BullRetrace and SwLo
    then 1
        else if BullRetrace
        then BullCount[1] + 1
        else BullCount[1];
def BullCountDisplay = if BullCount == 2
    then 1
    else 0;

#---> Look and Feel BULL Swing
AddChartBubble(BullRetrace, low -2, BullCount, if BullCount == 2
    then Color.YELLOW
        else if BullCount == 1
        then Color.CYAN
    else Color.LIGHT_GREEN);
Alert(BullRetrace, "BULL SWING",  Alert.TICK, Sound.Ring);

plot SW = if BullRetrace then low else Double.NaN;
SW.SetLineWeight(5);
SW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
SW.SetDefaultColor(Color.YELLOW);
SW.HideBubble();

#---> Count Bear Retracement Legs
def BearRetrace = if low == low[1]
    then if low < low[2] and low < low[-1]
            then 1
            else 0
    else if low > low[1] and low > low[-1]
    then 1
    else 0;
def SwHi2 = if BearRetrace and low > SwHi1
    then low
    else SwHi2[1];
def SwHi = if BearRetrace and low > SwHi2[1]
    then 1
    else 0;
def BearCount = if BearRetrace and SwHi
    then 1
    else if BearRetrace
        then BearCount[1] + 1
        else BearCount[1];
def BearCountDisplay = if BearCount == 2
    then 1
    else 0;

#---> Look and Feel BEAR Swing
AddChartBubble(BearRetrace, high +1, BearCount, if BearCount == 2
    then Color.MAGENTA
        else if BearCount == 1
        then Color.WHITE
    else Color.GRAY);
Alert(BearRetrace, "BEAR SWING",  Alert.TICK, Sound.Ring); # Alert on a retracementthinkor

plot SW1 = if BearRetrace then low else Double.NaN;
SW1.SetLineWeight(5);
SW1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
SW1.SetDefaultColor(Color.MAGENTA);
SW1.HideBubble();

AssignBackgroundColor(if BullCountDisplay
    then Color.LIGHT_GREEN
    else if BearCountDisplay
    then Color.LIGHT_RED
    else Color.BLACK);
 
Last edited by a moderator:
Does someone have an indicator that will find second entries like the Mack Pats system?
I have search the site and can't find any.


price action indicator shows you 2nd entries, failed 2nd entries, and traps as defined by Mack's PATS strategy from priceactiontradingsystem.com
 
Does someone have an indicator that will find second entries like the Mack Pats system?
I have search the site and can't find any.


price action indicator shows you 2nd entries, failed 2nd entries, and traps as defined by Mack's PATS strategy from priceactiontradingsystem.com
I have searched for this before and not found a free one. There is a website (byebyemoney on youtube's website) that sells it for $50 though. If mentioning this is not allowed, mod pls delete my response.
 
Code:
# Counting Legs for Two Leg Pullback
# mrb 20220212
# This script counts pullbacks to buy on high probability moves
# buy point for bull side is second pullback after a swing high
# buy point for bull side is second pullback after a swing low
###

def SwLo1 = 10000;
def SwHi1 = 0;
#---> Count Bull Retracement Legs
def BullRetrace = if high == high[1]
    then if high < high[2] and high < high[-1]
            then 1
            else 0
    else if high < high[1] and high < high[-1]
    then 1
    else 0;
def SwLo2 = if BullRetrace and high < SwLo1
    then high
    else SwLo2[1];
def SwLo = if BullRetrace and high < SwLo2[1]
    then 1
    else 0;
def BullCount = if BullRetrace and SwLo
    then 1
        else if BullRetrace
        then BullCount[1] + 1
        else BullCount[1];
def BullCountDisplay = if BullCount == 2
    then 1
    else 0;

#---> Look and Feel BULL Swing
AddChartBubble(BullRetrace, low -2, BullCount, if BullCount == 2
    then Color.YELLOW
        else if BullCount == 1
        then Color.CYAN
    else Color.LIGHT_GREEN);
Alert(BullRetrace, "BULL SWING",  Alert.TICK, Sound.Ring);

plot SW = if BullRetrace then low else Double.NaN;
SW.SetLineWeight(5);
SW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
SW.SetDefaultColor(Color.YELLOW);
SW.HideBubble();

#---> Count Bear Retracement Legs
def BearRetrace = if low == low[1]
    then if low < low[2] and low < low[-1]
            then 1
            else 0
    else if low > low[1] and low > low[-1]
    then 1
    else 0;
def SwHi2 = if BearRetrace and low > SwHi1
    then low
    else SwHi2[1];
def SwHi = if BearRetrace and low > SwHi2[1]
    then 1
    else 0;
def BearCount = if BearRetrace and SwHi
    then 1
    else if BearRetrace
        then BearCount[1] + 1
        else BearCount[1];
def BearCountDisplay = if BearCount == 2
    then 1
    else 0;

#---> Look and Feel BEAR Swing
AddChartBubble(BearRetrace, high +1, BearCount, if BearCount == 2
    then Color.MAGENTA
        else if BearCount == 1
        then Color.WHITE
    else Color.GRAY);
Alert(BearRetrace, "BEAR SWING",  Alert.TICK, Sound.Ring); # Alert on a retracementthinkor

plot SW1 = if BearRetrace then low else Double.NaN;
SW1.SetLineWeight(5);
SW1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
SW1.SetDefaultColor(Color.MAGENTA);
SW1.HideBubble();

AssignBackgroundColor(if BullCountDisplay
    then Color.LIGHT_GREEN
    else if BearCountDisplay
    then Color.LIGHT_RED
    else Color.BLACK);
I did find this script posted on the forum via search. I haven't checked it out so I'm not sure how well it works.
 
That script is a start, but very confusing to read, looks like it only picks up the bull side and not the bear. Can someone clean it up and relabel it to be more readable?
 
Does someone have an indicator that will find second entries like the Mack Pats system?
I have search the site and can't find any.


price action indicator shows you 2nd entries, failed 2nd entries, and traps as defined by Mack's PATS strategy from priceactiontradingsystem.com
This is Michael Chen, he has video's on youtube relating to MacsPAT System. He got sued for it. I have watched his video's a 1000 times, still don't understand what he is doing-
 

Could some help fix this code to do two legged pullbacks with numbers.

What I would like is for the purple and white dots to have numbers 1,2,3,4, etc.
The numbers need to reset, the purple with a lower low and the white with a higher high.
Also the dots sometimes triggers when the low or high is equal to the candle next to it, if that can be fixed that would be great.

Thanks
John

Here is the code.

# Counting Legs for Two Leg Pullback
# mrb 20220212
# This script counts pullbacks to buy on high probability moves
# buy point for bull side is second pullback after a swing high
# buy point for bull side is second pullback after a swing low
###

def SwLo1 = 10000;
def SwHi1 = 0;
#---> Count Bull Retracement Legs
def BullRetrace = if high == high[1]
then if high < high[2] and high < high[-1]
then 1
else 0
else if high < high[1] and high < high[-1]
then 1
else 0;
def SwLo2 = if BullRetrace and high < SwLo1
then high
else SwLo2[1];
def SwLo = if BullRetrace and high < SwLo2[1]
then 1
else 0;
def BullCount = if BullRetrace and SwLo
then 1
else if BullRetrace
then BullCount[1] + 1
else BullCount[1];
def BullCountDisplay = if BullCount == 2
then 1
else 0;

#---> Look and Feel BULL Swing


plot SW = if BullRetrace then low else Double.NaN;
SW.SetLineWeight(5);
SW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
SW.SetDefaultColor(Color.YELLOW);
SW.HideBubble();

#---> Count Bear Retracement Legs
def BearRetrace = if low == low[1]
then if low < low[2] and low < low[-1]
then 1
else 0
else if low > low[1] and low > low[-1]
then 1
else 0;
def SwHi2 = if BearRetrace and low > SwHi1
then low
else SwHi2[1];
def SwHi = if BearRetrace and low > SwHi2[1]
then 1
else 0;
def BearCount = if BearRetrace and SwHi
then 1
else if BearRetrace
then BearCount[1] + 1
else BearCount[1];
def BearCountDisplay = if BearCount == 2
then 1
else 0;

#---> Look and Feel BEAR Swing


plot SW1 = if BearRetrace then high else Double.NaN;
SW1.SetLineWeight(5);
SW1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
SW1.SetDefaultColor(Color.MAGENTA);
SW1.HideBubble();

AssignBackgroundColor(if BullCountDisplay
then Color.LIGHT_GREEN
else if BearCountDisplay
then Color.LIGHT_RED
else Color.BLACK);
 

Could some help fix this code to do two legged pullbacks with numbers.

What I would like is for the purple and white dots to have numbers 1,2,3,4, etc.
The numbers need to reset, the purple with a lower low and the white with a higher high.
Also the dots sometimes triggers when the low or high is equal to the candle next to it, if that can be fixed that would be great.

Thanks
John

Here is the code.

# Counting Legs for Two Leg Pullback
# mrb 20220212
# This script counts pullbacks to buy on high probability moves
# buy point for bull side is second pullback after a swing high
# buy point for bull side is second pullback after a swing low
###

def SwLo1 = 10000;
def SwHi1 = 0;
#---> Count Bull Retracement Legs
def BullRetrace = if high == high[1]
then if high < high[2] and high < high[-1]
then 1
else 0
else if high < high[1] and high < high[-1]
then 1
else 0;
def SwLo2 = if BullRetrace and high < SwLo1
then high
else SwLo2[1];
def SwLo = if BullRetrace and high < SwLo2[1]
then 1
else 0;
def BullCount = if BullRetrace and SwLo
then 1
else if BullRetrace
then BullCount[1] + 1
else BullCount[1];
def BullCountDisplay = if BullCount == 2
then 1
else 0;

#---> Look and Feel BULL Swing


plot SW = if BullRetrace then low else Double.NaN;
SW.SetLineWeight(5);
SW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
SW.SetDefaultColor(Color.YELLOW);
SW.HideBubble();

#---> Count Bear Retracement Legs
def BearRetrace = if low == low[1]
then if low < low[2] and low < low[-1]
then 1
else 0
else if low > low[1] and low > low[-1]
then 1
else 0;
def SwHi2 = if BearRetrace and low > SwHi1
then low
else SwHi2[1];
def SwHi = if BearRetrace and low > SwHi2[1]
then 1
else 0;
def BearCount = if BearRetrace and SwHi
then 1
else if BearRetrace
then BearCount[1] + 1
else BearCount[1];
def BearCountDisplay = if BearCount == 2
then 1
else 0;

#---> Look and Feel BEAR Swing


plot SW1 = if BearRetrace then high else Double.NaN;
SW1.SetLineWeight(5);
SW1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
SW1.SetDefaultColor(Color.MAGENTA);
SW1.HideBubble();

AssignBackgroundColor(if BullCountDisplay
then Color.LIGHT_GREEN
else if BearCountDisplay
then Color.LIGHT_RED
else Color.BLACK);
Adjusted the script that ronviv1 posted above so the bubbles are now numbers above/below the candles and changed SwLo1 to the high of day so it'll count the numbers below the candles correctly for /NQ, /NKD, /BTC, etc.

Code:
# Counting Legs for Two Leg Pullback
# mrb 20220212
# This script counts pullbacks to buy on high probability moves
# buy point for bull side is second pullback after a swing high
# buy point for bull side is second pullback after a swing low
###

def SwLo1 = high(period = AggregationPeriod.DAY);
def SwHi1 = 0;
#---> Count Bull Retracement Legs
def BullRetrace = 
    (if (high == high[1])
    then if (high < high[2]) and (high < high[-1])
            then 1
            else 0
    else if (high < high[1]) and (high < high[-1])
    then 1
    else 0);
def SwLo2 =
    (if BullRetrace and (high < SwLo1)
    then high
    else SwLo2[1]);
def SwLo =
    (if BullRetrace and (high < SwLo2[1])
    then 1
    else 0);
def BullCount =
    (if BullRetrace and SwLo
    then 1
        else if BullRetrace
        then (BullCount[1] + 1)
        else BullCount[1]);
#def BullCountDisplay =
#    (if BullCount == 2
#    then 1
#    else 0);

Alert(BullRetrace, "BULL SWING",  Alert.TICK, Sound.Ring);

plot SW = if BullRetrace then BullCount else Double.NaN;
SW.SetLineWeight(5);
SW.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
SW.AssignValueColor(
        if (BullCount % 2 == 0)
        then Color.YELLOW
        else if (BullCount == 1)
        then Color.CYAN
        else Color.LIGHT_GREEN
);
SW.HideBubble();

plot SBull = if (BullRetrace and (BullCount % 2 == 0)) then low else Double.NaN;
SBull.SetLineWeight(5);
SBull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
SBull.SetDefaultColor(Color.YELLOW);
SBull.HideBubble();

#---> Count Bear Retracement Legs
def BearRetrace =
    (if (low == low[1])
    then if (low < low[2]) and (low < low[-1])
            then 1
            else 0
    else if (low > low[1]) and (low > low[-1]) #3
    then 1
    else 0);
def SwHi2 =
    (if BearRetrace and (low > SwHi1)
    then low
    else SwHi2[1]);
def SwHi =
    (if BearRetrace and (low > SwHi2[1])
    then 1
    else 0);
def BearCount =
    (if BearRetrace and SwHi
    then 1
    else if BearRetrace
        then (BearCount[1] + 1)
        else BearCount[1]);
#def BearCountDisplay =
#    (if BearCount == 2
#    then 1
#    else 0);

Alert(BearRetrace, "BEAR SWING",  Alert.TICK, Sound.Ring); # Alert on a retracementthinkor

plot SW1 = if BearRetrace then BearCount else Double.NaN;
SW1.SetLineWeight(5);
SW1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
SW1.AssignValueColor(
        (if (BearCount % 2 == 0)
        then Color.MAGENTA
        else if (BearCount == 1)
        then Color.WHITE
        else Color.GRAY)
);
SW1.HideBubble();

plot SBear = if (BearRetrace and (BearCount % 2 == 0)) then low else Double.NaN;
SBear.SetLineWeight(5);
SBear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
SBear.SetDefaultColor(Color.MAGENTA);
SBear.HideBubble();

#AssignBackgroundColor(if BullCountDisplay
#    then Color.LIGHT_GREEN
#    else if BearCountDisplay
#    then Color.LIGHT_RED
#    else Color.BLACK);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
234 Online
Create Post

Similar threads

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.
Back
Top