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:

gus_1973

New member
@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:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@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.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime

trader360

New member
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?
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
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
 

trader360

New member
@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.
 

ronviv1

New member
VIP
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:

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