B3 Consolidation Box: Breakout / Breakdown Indicator for ThinkorSwim

Daruka

New member
Hi Ben! Thank you for the indicator. Is it possible to make the list display the shares that are currently being consolidated?
 

alohakitty26

New member
Hi, I'm using this instead of ORB today and I love it and I have one request for you!! Could you change candle color when it's going down just like Heikin Ashi please? I know candle in this chart won't indicate downside as color, but I'm just so use to see different color when doing down. ( I use Heikin Ashi ) Thanx!!
 

Schminga

New member
@Playstation As requested here is B3 Consolidation Box with all lines removed. Only the grey consolidation box remains
Load this study on a 5 minute chart of /ES and you 'll see all the consolidation boxes displayed

Code:
# Consolidation Box Barebones - with Grey Consolidation Box
# tomsk
# 11.23.2019

# As requested by Playstation, this is B3 Consolidation Box with all lines removed
# Only the grey consolidation box remains

# B3 Consolidation Box
# Hammond B3
# 2.2.2019

input BarsUsedForRange = 2;
input BarsRequiredToRemainInRange = 7;
input ColorPrice = yes;
input HideBoxLines = no;
input HideLabels = no;

# Identify Consolidation
def HH = highest(high[1], BarsUsedForRange);
def LL = lowest(low[1], BarsUsedForRange);
def maxH = highest(hh, BarsRequiredToRemainInRange);
def maxL = lowest(ll, BarsRequiredToRemainInRange);
def HHn = if maxH == maxH[1] or maxL == maxL then maxH else HHn[1];
def LLn = if maxH == maxH[1] or maxL == maxL then maxL else LLn[1];
def Bh = if high <= HHn and HHn == HHn[1] then HHn else double.nan;
def Bl = if low >= LLn and LLn == LLn[1] then LLn else double.nan;
def CountH = if isnan(Bh) or isnan(Bl) then 2 else CountH[1] + 1;
def CountL = if isnan(Bh) or isnan(Bl) then 2 else CountL[1] + 1;

def ExpH = if barnumber() == 1 then double.nan
           else if CountH[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn[-BarsRequiredToRemainInRange]
           else if High <= ExpH[1] then ExpH[1]
           else double.nan;

def ExpL = if barnumber() == 1 then double.nan
           else if Countl[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn[-BarsRequiredToRemainInRange]
           else if Low >= ExpL[1] then ExpL[1] else double.nan;

# Plot the High and Low of the Box; Paint Cloud
plot BoxHigh = if !isnan(expL) and !isnan(ExpH) then ExpH else double.nan;
     boxhigh.setdefaultColor(color.dark_green);
     BoxHigh.setpaintingStrategy(paintingStrategy.HORIZONTAL);
     BoxHigh.SETHIDING(HideBoxLines);

plot BoxLow = if !isnan(expL) and !isnan(ExpH) then ExpL else double.nan;
     BoxLow.setpaintingStrategy(paintingStrategy.HORIZONTAL);
     BoxLow.setdefaultColor(color.dark_red);
     BoxLow.SETHIDING(HideBoxLines);

addcloud(BoxHigh, BoxLow, color.gray, color.gray);

# Things to the Right of a Finished Box
def eH = if barnumber() == 1 then double.nan else if !isnan(BoxHigh[1]) and isnan(BoxHigh) then BoxHigh[1] else eh[1];
def eL = if barnumber() == 1 then double.nan else if !isnan(BoxLow[1]) and isnan(BoxLow) then BoxLow[1] else el[1];

assignPriceColor(if !ColorPrice then color.current else if !isnan(BoxHigh) then color.gray else
                    if high > eh  and low < el then color.yellow else
                    if high > eh then color.green else if low < el then color.red else color.gray);
# Consolidation Box Barebones
For some reason, TOS not giving a white "OK" to this script. Tried several times.
 

MrDrB

New member
Can someone explain when new consolidation boxes are drawn? I'm having trouble deciphering from the code. Taking the default settings as an example (7 bars inside 2 "parent" bars), I've seen these conditions met but new boxes not drawn...doesn't seem to matter if it happens inside target levels or outside of them, the extreme targets are met or not, etc
 

JP382

Member
I am working on an indicator / scanner tonight for this so I will let you know in a few days if I get some accurate results. Primary results I am testing and looking for are scanning multiple timeframes in a single scanner, or multiple watchlist indicators that all display it coming out of consolidation / sideways movement.

-Chad
nashtech.xyz
Were you ever able to build this?
 

Mark-RO

New member
Hey folks, here's a Scan for this interesting script.
Hopefully somebody finds some use for it.

To install this scan filter: first create a new study (copy and paste the code below), then add it to the scanner.
In the scan filter's pull-down menu select the type of scan you wish to use and choose the "Is True" option on the right.

If you want your indicator to show and match the scan results remember to use the same settings as the scanner, or modify both indicator and scanner to match.

Hint "+++OFF+++": Disables this filter (rather than deleting it from a stack of other multiple filters).

Hint "---OFF---": Returns a negative result from this filter. Useful when used together with other filters in "Any of the following".

Code:
# Trade_By_ColorTrend_scan
# Scan by Mark-RO, v1.3 - 05.23.2021

# To install this scan filter: first create a new study (copy and paste the code below), then add it to the scanner.
# In the scan filter's pull-down menu select the type of scan you wish to use and choose the "Is True" option on the right.

#Hint "+++OFF+++": Disables this filter (rather than deleting it from a stack of other multiple filters).

#Hint "---OFF---": Returns a negative result from this filter. Useful when used together with other filters in "Any of the following".

#---------------------------------

input BarsUsedForRange = 2; #hint BarsUsedForRange: default is 2. Alt is 3.

input BarsRequiredToRemainInRange = 3; #hint BarsRequiredToRemainInRange: default is 7. Alt is 3.

input TargetMultiple = 0.5;

# Identify Consolidation

def HH = Highest(high[1], BarsUsedForRange);

def LL = Lowest(low[1], BarsUsedForRange);

def maxH = Highest(HH, BarsRequiredToRemainInRange);

def maxL = Lowest(LL, BarsRequiredToRemainInRange);

def HHn = if maxH == maxH[1] or maxL == maxL then maxH else HHn[1];

def LLn = if maxH == maxH[1] or maxL == maxL then maxL else LLn[1];

def Bh = if high <= HHn and HHn == HHn[1] then HHn else Double.NaN;

def Bl = if low >= LLn and LLn == LLn[1] then LLn else Double.NaN;

def CountH = if IsNaN(Bh) or IsNaN(Bl) then 2 else CountH[1] + 1;

def CountL = if IsNaN(Bh) or IsNaN(Bl) then 2 else CountL[1] + 1;

def ExpH = if BarNumber() == 1 then Double.NaN else

            if CountH[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn[-BarsRequiredToRemainInRange] else

            if high <= ExpH[1] then ExpH[1] else Double.NaN;

def ExpL = if BarNumber() == 1 then Double.NaN else

            if CountL[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn[-BarsRequiredToRemainInRange] else

            if low >= ExpL[1] then ExpL[1] else Double.NaN;

def BoxHigh = if !IsNaN(ExpL) and !IsNaN(ExpH) then ExpH else Double.NaN;

def BoxLow = if !IsNaN(ExpL) and !IsNaN(ExpH) then ExpL else Double.NaN;

def eH = if BarNumber() == 1 then Double.NaN else if !IsNaN(BoxHigh[1]) and IsNaN(BoxHigh) then BoxHigh[1] else eH[1];

def eL = if BarNumber() == 1 then Double.NaN else if !IsNaN(BoxLow[1]) and IsNaN(BoxLow) then BoxLow[1] else eL[1];

def diff = (eH - eL) * TargetMultiple;

def Buy = high > eH && low >= eL;

def Sell = high <= eH && low < eL;

#----------------------------------------------

# Only one of these can be scanned for at one time.
# Use "#" comment marks to turn off the one you don't need.

plot Long_Buys = Buy;

plot Short_Sells = Sell;

plot "+++OFF+++" = Close > 0;

plot "---OFF---" = Close < 0;

#----------------------------------------------

Shared Link: http://tos.mx/XGaYhg4
 
Last edited:

Marcoxiii

New member
VIP
Found this really interesting indicator for ThinkorSwim called B3 Consolidation Box that I wanted to share with everyone here.

Want to know if a stock is under consolidation? Well, this indicator is perfect for that. It basically highlights when a stock is consolidating and at which level it will be breaking down or breaking out. In addition, a stop loss level will be provided in case it's a false breakout/breakdown and target levels so you can know where to take profit.

Here are a few examples:

eMdcH7K.png


5t51NRr.png


voXgIWa.png


Notes:
  • Grey shadow box is your Consolidation box.
  • The white dotted line is Stop loss
  • Red lines are Profit Target Levels for Breakdown
  • Green lines are Profit Target Levels for Breakout
  • Use this indicator on the 5, 10, or 15 mins timeframe with Pre-market on.


thinkScript Code

Rich (BB code):
# B3 Consolidation Box   v1

# -- Automates a box and shows the breakouts via price color with targets based on the box's range.

# -- In a system the gray balance line would be your stop, or you may exit on any trip back within the old box range.

# -- The color of the candles does not tell you when to be long or short, it simply tells you the last signal given.

# -- You must manage your trade targets via your own profit protection tactics.

# Intended only for the use of the person(s) to who(m) this script was originally distributed.

# User of the script assumes all risk;

# The coder and the distributers are not responsible for any loss of capital incurred upon usage of this script.

# amalia added commentary after chatting more with B3 about the study:

# The first 2 inputs will need to be set for the chart you are looking at. What you want to find is the consolidation box settings that give you actionable targeting. If the price is shooting way past the tgt6 point, you need to lower the second input. The first input should likely be either 1, 2 or 3 only. Script is based on a strategy I learned from Ben's webcasts on TOS. He was doing some futurescast thing on consolidation boxes, and I had to see if I could make it work too. My Hypothesis is it is a great little scalper... you have to be willing to take singles and doubles and forget homers. He was trading ES

declare upper;

input BarsUsedForRange = 2;

input BarsRequiredToRemainInRange = 7;

input TargetMultiple = 0.5;

input ColorPrice = yes;

input HideTargets = no;

input HideBalance = no;

input HideBoxLines = no;

input HideCloud = no;

input HideLabels = no;

# Identify Consolidation

def HH = highest(high[1], BarsUsedForRange);

def LL = lowest(low[1], BarsUsedForRange);

def maxH = highest(hh, BarsRequiredToRemainInRange);

def maxL = lowest(ll, BarsRequiredToRemainInRange);

def HHn = if maxH == maxH[1] or maxL == maxL then maxH else HHn[1];

def LLn = if maxH == maxH[1] or maxL == maxL then maxL else LLn[1];

def Bh = if high <= HHn and HHn == HHn[1] then HHn else double.nan;

def Bl = if low >= LLn and LLn == LLn[1] then LLn else double.nan;

def CountH = if isnan(Bh) or isnan(Bl) then 2 else CountH[1] + 1;

def CountL = if isnan(Bh) or isnan(Bl) then 2 else CountL[1] + 1;

def ExpH = if barnumber() == 1 then double.nan else

            if CountH[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn[-BarsRequiredToRemainInRange] else

            if High <= ExpH[1] then ExpH[1] else double.nan;

def ExpL = if barnumber() == 1 then double.nan else

            if Countl[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn[-BarsRequiredToRemainInRange] else

            if Low >= ExpL[1] then ExpL[1] else double.nan;

# Plot the High and Low of the Box; Paint Cloud

plot BoxHigh = if !isnan(expL) and !isnan(ExpH) then ExpH else double.nan;

plot BoxLow = if !isnan(expL) and !isnan(ExpH) then ExpL else double.nan;

boxhigh.setdefaultColor(color.dark_green);

BoxHigh.setpaintingStrategy(paintingStrategy.HORIZONTAL);

BoxLow.setpaintingStrategy(paintingStrategy.HORIZONTAL);

BoxLow.setdefaultColor(color.dark_red);

BoxHigh.SETHIDING(HideBoxLines);

BoxLow.SETHIDING(HideBoxLines);

addcloud(if !HideCloud then BoxHigh else double.nan, BoxLow, color.gray, color.gray);

# Things to the Right of a Finished Box

def eH = if barnumber() == 1 then double.nan else if !isnan(BoxHigh[1]) and isnan(BoxHigh) then BoxHigh[1] else eh[1];

def eL = if barnumber() == 1 then double.nan else if !isnan(BoxLow[1]) and isnan(BoxLow) then BoxLow[1] else el[1];

def diff = (eh - el) * TargetMultiple;

plot Balance = if isnan(boxhigh) and isnan(boxlow) then (eh+el)/2 else double.nan;

plot Htgt_1 = if isnan(Boxhigh) and high >= eh then eh + diff else double.nan;

plot Htgt_2 = if isnan(Boxhigh) and high >= eh then eh + diff*2 else double.nan;

plot Htgt_3 = if isnan(Boxhigh) and high >= eh then eh + diff*3 else double.nan;

plot Htgt_4 = if isnan(Boxhigh) and high >= eh then eh + diff*4 else double.nan;

plot Htgt_5 = if isnan(Boxhigh) and high >= eh then eh + diff*5 else double.nan;

plot Htgt_6 = if isnan(Boxhigh) and high >= eh then eh + diff*6 else double.nan;

plot Ltgt_1 = if isnan(BoxLow) and Low <= eL then eL - diff else double.nan;

plot Ltgt_2 = if isnan(BoxLow) and Low <= eL then eL - diff*2 else double.nan;

plot Ltgt_3 = if isnan(BoxLow) and Low <= eL then eL - diff*3 else double.nan;

plot Ltgt_4 = if isnan(BoxLow) and Low <= eL then eL - diff*4 else double.nan;

plot Ltgt_5 = if isnan(BoxLow) and Low <= eL then eL - diff*5 else double.nan;

plot Ltgt_6 = if isnan(BoxLow) and Low <= eL then eL - diff*6 else double.nan;

Balance.SETHIDING(HideBalance);

Balance.setdefaultColor(CREATECOLOR(255,255,255));

Balance.setpaintingStrategy(PAIntingStrategy.SQUARES);

Htgt_2.setlineWeight(2);

Htgt_4.setlineWeight(2);

Htgt_6.setlineWeight(2);

Htgt_1.setdefaultColor(CREATECOLOR( 50, 100 , 75));

Htgt_1.setpaintingStrategy(PAIntingStrategy.DASHES);

Htgt_2.setdefaultColor(CREATECOLOR( 50, 100 , 75));

Htgt_2.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Htgt_3.setdefaultColor(CREATECOLOR( 50, 100 , 75));

Htgt_3.setpaintingStrategy(PAIntingStrategy.DASHES);

Htgt_4.setdefaultColor(CREATECOLOR( 50, 100 , 75));

Htgt_4.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Htgt_5.setdefaultColor(CREATECOLOR( 50, 100 , 75));

Htgt_5.setpaintingStrategy(PAIntingStrategy.DASHES);

Htgt_6.setdefaultColor(CREATECOLOR( 50, 100 , 75));

Htgt_6.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Ltgt_2.setlineWeight(2);

Ltgt_4.setlineWeight(2);

Ltgt_6.setlineWeight(2);

Ltgt_1.setdefaultColor(CREATECOLOR( 100, 50 , 75));

Ltgt_1.setpaintingStrategy(PAIntingStrategy.DASHES);

Ltgt_2.setdefaultColor(CREATECOLOR( 100, 50 , 75));

Ltgt_2.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Ltgt_3.setdefaultColor(CREATECOLOR( 100, 50 , 75));

Ltgt_3.setpaintingStrategy(PAIntingStrategy.DASHES);

Ltgt_4.setdefaultColor(CREATECOLOR( 100, 50 , 75));

Ltgt_4.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Ltgt_5.setdefaultColor(CREATECOLOR( 100, 50 , 75));

Ltgt_5.setpaintingStrategy(PAIntingStrategy.DASHES);

Ltgt_6.setdefaultColor(CREATECOLOR( 100, 50 , 75));

Ltgt_6.setpaintingStrategy(paintingStrategy.HORIZONTAL);

Htgt_1.SETHIDING(HIDETARGETS);

Htgt_2.SETHIDING(HIDETARGETS);

Htgt_3.SETHIDING(HIDETARGETS);

Htgt_4.SETHIDING(HIDETARGETS);

Htgt_5.SETHIDING(HIDETARGETS);

Htgt_6.SETHIDING(HIDETARGETS);

Ltgt_1.SETHIDING(HIDETARGETS);

Ltgt_2.SETHIDING(HIDETARGETS);

Ltgt_3.SETHIDING(HIDETARGETS);

Ltgt_4.SETHIDING(HIDETARGETS);

Ltgt_5.SETHIDING(HIDETARGETS);

Ltgt_6.SETHIDING(HIDETARGETS);

# Labels

addlabel(!HideLabels, "TgtLvls = " + diff + "pts each | Bal = " + balance, if high > eh  and low < el then color.yellow else if high > eh then color.green else if low < el then color.red else color.gray);

addlabel(!HideLabels && high > eh && low < el, "OUTSIDE BAR!!", color.yellow);

addlabel(!HideLabels && high > eh && low >= el, "Long", color.green);

addlabel(!HideLabels && high <= eh && low < el, "Short", color.red);

#Price Color

assignPriceColor(if !ColorPrice then color.current else if !isnan(BoxHigh) then color.gray else

                    if high > eh  and low < el then color.yellow else

                    if high > eh then color.green else if low < el then color.red else color.gray);

Shareable Link

https://tos.mx/oPI7Kp

Video Tutorial

Is there Tradingview version of this indicator?
 

rad14733

Well-known member
VIP
@Marcoxiii Perhaps you can find someone over at Tradingview to help you just like we constantly get members wanting us to convert code from that platform... These forums are about Thinkorswim and Thikscript, not Tradingview and Pinescript... Why would we be inclined to make such effort for a relatively new member with on 14 posts who wants our code converted to another platform...??? Try seeing it from our point of view and it makes sense, right...???
 

Marcoxiii

New member
VIP
@Marcoxiii Perhaps you can find someone over at Tradingview to help you just like we constantly get members wanting us to convert code from that platform... These forums are about Thinkorswim and Thikscript, not Tradingview and Pinescript... Why would we be inclined to make such effort for a relatively new member with on 14 posts who wants our code converted to another platform...??? Try seeing it from our point of view and it makes sense, right...???
I see what you mean, but I thought someone might already have it just like BTD indicator which has TOS and Tradingview version. It makes more sense to me to ask the community that I have a subscription with than asking other communities. Thanks for the tip, I will try with tradingview community.
 

Dreambigger628

New member
VIP
Hello,

I’m new to this site and still playing around with the indicators. This one has quickly become a favorite and I was curious if anyone knows how to convert this into a strategy that can be backtested and then maybe even into an algorithm? I feel like it could be possible but all this code is way over my head.

Thanks!
 

amao11

New member
Hey folks, here's the first version of a Scan for this interesting script.
Hopefully somebody finds some use for it.

Import this as a new study then select the type of scan you wish to use from the pull down menu.
Or comment out (#) the ones not being used.
If you want your indicator to show and match the scan results remember to use the same settings as the scanner, or modify both indicator and scanner to match.

Shared link: http://tos.mx/5ySOlQq


Code:
# Trade_By_ColorTrend_scan
# Original Indicator: http://tos.mx/hBNTSgz
#
# Scan by Mark-RO, v1.0 - 04.17.2021
# Shared link: http://tos.mx/5ySOlQq
#
# The +++OFF+++ disables this scan (rather than deleting it from a stack of multiple filters).
# The ---OFF--- gives a negative result from this filter. Useful when used together with other filters in "Any of the following".


input BarsUsedForRange = 2; #hint BarsUsedForRange: default is 2. Alt is 3.

input BarsRequiredToRemainInRange = 3; #hint BarsRequiredToRemainInRange: default is 7. Alt is 3.

input TargetMultiple = 0.5;

# Identify Consolidation

def HH = Highest(high[1], BarsUsedForRange);

def LL = Lowest(low[1], BarsUsedForRange);

def maxH = Highest(HH, BarsRequiredToRemainInRange);

def maxL = Lowest(LL, BarsRequiredToRemainInRange);

def HHn = if maxH == maxH[1] or maxL == maxL then maxH else HHn[1];

def LLn = if maxH == maxH[1] or maxL == maxL then maxL else LLn[1];

def Bh = if high <= HHn and HHn == HHn[1] then HHn else Double.NaN;

def Bl = if low >= LLn and LLn == LLn[1] then LLn else Double.NaN;

def CountH = if IsNaN(Bh) or IsNaN(Bl) then 2 else CountH[1] + 1;

def CountL = if IsNaN(Bh) or IsNaN(Bl) then 2 else CountL[1] + 1;

def ExpH = if BarNumber() == 1 then Double.NaN else

            if CountH[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn[-BarsRequiredToRemainInRange] else

            if high <= ExpH[1] then ExpH[1] else Double.NaN;

def ExpL = if BarNumber() == 1 then Double.NaN else

            if CountL[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn[-BarsRequiredToRemainInRange] else

            if low >= ExpL[1] then ExpL[1] else Double.NaN;

def BoxHigh = if !IsNaN(ExpL) and !IsNaN(ExpH) then ExpH else Double.NaN;

def BoxLow = if !IsNaN(ExpL) and !IsNaN(ExpH) then ExpL else Double.NaN;

def eH = if BarNumber() == 1 then Double.NaN else if !IsNaN(BoxHigh[1]) and IsNaN(BoxHigh) then BoxHigh[1] else eH[1];

def eL = if BarNumber() == 1 then Double.NaN else if !IsNaN(BoxLow[1]) and IsNaN(BoxLow) then BoxLow[1] else eL[1];

def diff = (eH - eL) * TargetMultiple;

def Buy = high > eH && low >= eL;

def Sell = high <= eH && low < eL;


#------------------------------------------------

#Comment out (#) the ones not being used:

plot Long_Buys = Buy is true;

plot Short_Sells = Sell is true;

plot "+++OFF+++" = close > 0;

plot "---OFF---" = close < -0;

#End Scan
I use this box all the time. Finally someone came up with a scanner for it. I tried to make it work but dont understand the “comment out #” commands for instances. could you please give me the instructions on how to install it in baby steps? (Think of me as a 5 year old) i would greatly appreciate it. Thank you!!!
 

MerryDay

Administrative
Staff member
Staff
VIP
@amao11 Below is a tutorial of one method to use the script in post #67 in the TOS scanner.
I provide these directions with several cautions:
  1. The original script was not written to work in the manner of this scan
  2. This script has been know to repaint. Read more: Everything You Wanted To Know About Repainting
With the above caveats, here is the step-by-step to use in a scan:
Create the Custom Study
  1. Copy the code
  2. In Studies, click Create
  3. Paste the above study
  4. Name as: B3_Consolidation_Box
  5. Save
Click on the scanner.
  1. Click on +Add filter
  2. Click on the pencil icon next to the filter you just added
  3. Click edit
  4. At the top of the box: click on the 1st pull-down window, click study
  5. Type in B3_Consolidation_Box
  6. Under Plot, click on the pull-down window, choose Long_Buys
  7. In the middle column, choose is true
  8. Save
I didn't write this script. Any questions should be referred to the original poster. HTH
 

sellitmarin

New member
VIP
I'm very interested in seeing when forex major pairs breakout one way or the other, like using the ORB scan. Is there a way to do this and setup notifications when the pairs break out of one time frame consolidation and another one, in other words, two consecutive time frames = notification for entry? The idea is 4HR chart will show a break out LONG, then the 15 Min shows the white line breaks as well LONG. Then it says... buy that MOFO now dont miss this opportunity.
 

sellitmarin

New member
VIP
I did a search, it shows things in consolidation but not the ones that break out into the long or short. Should I add more bars?
 

Similar threads

Top