ThinkorSwim Two Legged Pullback Indicator


Active member
2019 Donor
Is there any way (TOS script, website, tools, etc..) to calculate the average pullback (percentage, points, ticks) before resuming the current trend? Or calculate on average how far above the previous high before pulling back?

# "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];

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

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

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

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

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

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


New member
Hey guys I'm looking for a script that can recognize a trend of three candles or more. (Sell or Put) on the first pull back I like a rectangle on the body of the last trend candle. Once value box is broken on ether side I like a single and arrow to witch side that was broken.

Last edited by a moderator:


New member
I am trying to make a simple pullback identifier, that will count basically two pull back. I never coded in think or swim, but i made a simple pseuocode on what i would like to do, if someone could just guide me on some functions. I would like a bubble to form that counts, whenever i get a pullback, not just an arrow indicator. Please let me know if anything needs to be cleared up, as it is very bare as of now, but id like to see if anyone could let me know of any TOS functions i could use.

if ( candle1  < candleZ )//compares the first candle, checks to see if candle 2 has a higher low then the first candle. If it does, it will add a 1 bubble.
    legCount = 1

if (candleN<candleZ && candleN >candle1)// this will check the 3rd and red of the candles, with
    legCount = 2 // prepare for 2nd entry.
   candle N++

    legCount = 0


New member
Does anyone know any indicators that will help you identify two legged pullbacks? I have a hard time recognizing them and I saw someone posted a version for Ninjatrade but curious if anything exists for TOS?

I have just joined this web site and love it. I was watching youtube about a script they are selling for 75 dollars. I would like someone to create for me. It is about multiple time frame pullback and reclimb in watchlist including intraday.
Thanks in advance.
Last edited:

Similar threads