B3 Consolidation Box: Breakout / Breakdown Indicator for ThinkorSwim

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

Hi, is there anything with candle color on one chart for different time frame. I am not talking about overlapping candle timeframe. More like a label on the chart with the candle color red or green for the time frames... more like MTF
 

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

Hi, is there anything with candle color on one chart for different time frame. I am not talking about overlapping candle timeframe. More like a label on the chart with the candle color red or green for the time frames... more like MTF
No, there is nothing like that available for this indicator. It's an interesting idea. What would it tell us? The noise in the lowers would have it flipping back and forth more often so that would not be helpful and the lag on the highers would not be informative.
 
Last edited:
@amalia do you have watchlist columns for this study? Would be nice to know when the stock is in a consolidation without scrolling through every chart.
yes, you can stuff this code into a watchlist script. Just change the 3rd to last line of code from:
Rich (BB code):
assignPriceColor
to
Rich (BB code):
assignBackGroundColor
 
No, there is nothing like that available for this indicator. It's an interesting idea. What would it tell us? The noise in the lowers would have it flipping back and forth more often so that would not be helpful and the lag on the highers would not be informative.
The candles assist me with day trading especially if i can see the colors on the different time frames. For example, green or red candles on say minutes of 5, 15, 30, 1H, help me to day trade better.
The script below is the closest i have seem except it overlap. There is a label that comes with it but doesn't give candle color. I dont mind the flickering but when it remains green or red tells me how to buy or sell. I have set up four windows to show the candles in different frames but too much space is used up. Thanks for your prompt response. Hope you understand what i am trying to say!

DECLARE UPPER;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.FIFTEEN_MIN;
DEF H = high(period = Time_Frame);
DEF L = low(period = Time_Frame);
DEF O = open(period = Time_Frame);
DEF C = close(period = Time_Frame);
def NA = double.Nan;


#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;
def side = if side[1] == 1 then 2 else 1;
DEF sider = side;
AddCloud( if sider == 2 then O else Double.NaN, if sider == 2 then C else Double.NaN, COLOR.light_Red, COLOR.light_Green);
AddCloud( if sider == 1 then O else Double.NaN, if sider == 1 then C else Double.NaN, COLOR.light_red, COLOR.light_green);

Def newbar = if O != O[1] then 1 else 0;

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount = Time_Frame / GetAggregationPeriod();
def bn = BarNumber();
# Determine the position of each bar using the remainder with value of 0 = lowerTimeFrameBarCount
def remainder = bn % lowerTimeFrameBarCount;
def bar = if remainder == 0 then lowerTimeFrameBarCount else remainder;
#Find the middle bar in the lower timeframe - odd numbers add 0.5 to plot the wicks on the higher time frame
def midBar = if lowerTimeFrameBarCount % 2 == 0 then lowerTimeFrameBarCount/2 else lowerTimeFrameBarCount/2 + 0.5;

def openbar = if lowerTimeFrameBarCount % 2 == 0 then LowertimeFrameBarCount else LowerTimeFrameBarCount - 5;

### making stuff up here drawing the wick through the middle candle.
def nan = double.nan;
def hb = if bar == midBar then h else nan;
def lb = if bar == midBar then l else nan;
def bb = c > o;



AddChart(if bb then hb else na, if bb then lb else na, if bb then o else na, if bb then c else na, type = ChartType.bar, growcolor = color.light_green );

AddChart( if !bb then hb else na, if !bb then lb else na, if !bb then o else na, if !bb then c else na, type = ChartType.Bar, growColor = color.Light_red);



plot highs = if bb then hb else na;
highs.setpaintingStrategy(PaintingStrategy.POINTS);
highs.setDefaultColor(Color.Green);

plot lhighs = if !bb then hb else na;
lhighs.setpaintingStrategy(paintingstrategy.points);
lhighs.setdefaultColor(Color.Red);

plot lows = if bb then lb else na;
lows.setpaintingStrategy(PaintingStrategy.Points);
lows.setdefaultColor(Color.Green);

plot llows = if !bb then lb else na;
llows.setpaintingStrategy(PaintingStrategy.POINTS);
llows.SetDefaultColor(Color.Red);



#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = yes;
AddLabel(Show_Label, Concat(if Time_Frame < 3600000 then Time_Frame / 60000 + "m" else if Time_Frame < 86400000 then Time_Frame / 3600000 + "h" else if Time_Frame < 604800000 then Time_Frame / 86400000 + "D" else if Time_Frame < 2592000000 then Time_Frame / 604800000 + "Wk" else if Time_Frame < 31536000000 then Time_Frame / 2592000000 + "Mo" else Time_Frame / 31536000000 + "Yr", if Time_Frame then " CANDLES" else ""), Color.light_Gray);

# end
 
Hi, @tomsk !
Thank you for the script https://usethinkscript.com/threads/...down-indicator-for-thinkorswim.103/post-10280

I was trying to change it for me personally, but had no success at all. I am trying to make a scanner study which scans for the consolidation only in the of the day (last X amount of candles) for the last trading day so I can trade breakout next morning if I like. Could you please give me any advise with that? Appreciate any help, from anyone. Thank you
 
Last edited:
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:

View attachment 4364

View attachment 4365

View attachment 4366

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

Hello Benten: this is a great indicator. For me it works great on the 30 min and 1 hr timeframe. However, the Targets would be better if we would use the following FIB Extensions:
FibExt1 = 1.618;
def FibExt2 = 2.618;
def FibExt3 = 4.236;

From the Balance Price Line.

It will great if you can work on it

I would really appreciate it!
 

B3 Consolidation Indicator REDONE for ThinkorSwim (Breakout / Breakdown Box)​

Shows an area of possible stock consolidation. It basically highlights when a stock is consolidating and at which level it will be breaking down or breaking out.


Code:
DEF   SUPPORT2 = low;
 DEF   MIN = Min(open, close);

declare upper;

input HideBalance = no;

input HideBoxLines = no;

input HideCloud = no;

input BarsUsedForRange = 5;

input BarsRequiredToRemainInRange = 7;

# Identify Consolidation

def MINMIN = lowest(MIN[1], BarsUsedForRange);

def SUPPORT2L = lowest(SUPPORT2[1], BarsUsedForRange);

def maxMIN = lowest(MINMIN, BarsRequiredToRemainInRange);

def maxSUPPORT2 = lowest(SUPPORT2L, BarsRequiredToRemainInRange);

def MINn = if maxMIN == maxMIN[1] or maxSUPPORT2 == maxSUPPORT2 then maxMIN else MINn[1];

def SUPPORT2n = if maxMIN == maxMIN[1] or maxSUPPORT2 == maxSUPPORT2 then maxSUPPORT2 else SUPPORT2n[1];

def Bh = if MIN >= MINn and MINn == MINn[1] then MINn else double.nan;

def Bl = if SUPPORT2 >= SUPPORT2n and SUPPORT2n == SUPPORT2n[1] then SUPPORT2n 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 MINn[-BarsRequiredToRemainInRange] else

            if MIN >= ExpH[1] then ExpH[1] else double.nan;

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

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

            if SUPPORT2 >= 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_RED);

BoxHigh.setpaintingStrategy(paintingStrategy.HORIZONTAL);

BoxLow.setpaintingStrategy(paintingStrategy.HORIZONTAL);

BoxLow.setdefaultColor(color.LIGHT_GREEN );

BoxHigh.SETHIDING(HideBoxLines);

BoxLow.SETHIDING(HideBoxLines);
BOXHigh.SetLineWeight(3);
BOXLOW.SetLineWeight(3);
addcloud(if !HideCloud then BoxHigh else double.nan, BoxLow, color.LIGHT_GREEN , color.LIGHT_GREEN );

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

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

Balance.SETHIDING(HideBalance);

Balance.setdefaultColor(COLOR.LIGHT_GREEN );

Balance.setpaintingStrategy(PAIntingStrategy.SQUARES);

plot RH = (balance *2)-el  ;
plot RL =  (balance *2)-eh  ;



addcloud(if !HideCloud then rh else double.nan, rl, color.GRAY, color.GRAY);


rh.setdefaultColor(color.DARK_red);
rh.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rl.setdefaultColor(color.DARK_green);
rl.setpaintingStrategy(paintingStrategy.HORIZONTAL);
RH.SetLineWeight(3);
RL.SetLineWeight(3);


##############################################################

 DEF   H = high;
 DEF   max = Max(open, close);


# Identify Consolidation

def HH1 = highest(h[1], BarsUsedForRange);
def LL1 = highest(max[1], BarsUsedForRange);
def maxH1 = highest(hh1, BarsRequiredToRemainInRange);
def maxL1 = highest(ll1, BarsRequiredToRemainInRange);

def HHn1 = if maxH1 == maxH1[1] or maxL1 == maxL1 then maxH1 else HHn1[1];

def LLn1 = if maxH1 == maxH1[1] or maxL1 == maxL1 then maxL1 else LLn1[1];

def Bh1 = if h <= HHn1 and HHn1 == HHn1[1] then HHn1 else double.nan;

def Bl1 = if max <= LLn1 and LLn1 == LLn1[1] then LLn1 else double.nan;

def CountH1 = if isnan(Bh1) or isnan(Bl1) then 2 else CountH1[1] + 1;

def CountL1 = if isnan(Bh1) or isnan(Bl1) then 2 else CountL1[1] + 1;

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

            if CountH1[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn1[-BarsRequiredToRemainInRange] else

            if H <= ExpH1[1] then ExpH1[1] else double.nan;

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

            if Countl1[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn1[-BarsRequiredToRemainInRange] else

            if max <= ExpL1[1] then ExpL1[1] else double.nan;


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

plot BoxHigh1 = if !isnan(expL1) and !isnan(ExpH1) then ExpH1 else double.nan;


plot BoxLow1 = if !isnan(expL1) and !isnan(ExpH1) then ExpL1 else double.nan;

boxhigh1.setdefaultColor(color.dark_RED);

BoxHigh1.setpaintingStrategy(paintingStrategy.HORIZONTAL);

BoxLow1.setpaintingStrategy(paintingStrategy.HORIZONTAL);

BoxLow1.setdefaultColor(color.dark_GREEN);

BoxHigh1.SETHIDING(HideBoxLines);

BoxLow1.SETHIDING(HideBoxLines);
BOXHigh1.SetLineWeight(3);
BOXLOW1.SetLineWeight(3);
addcloud(if !HideCloud then BoxHigh1 else double.nan, BoxLow1, color.pink, color.pink);

# Things to the Right of a Finished Box

def eH1 = if barnumber() == 1 then double.nan else if !isnan(BoxHigh1[1]) and isnan(BoxHigh1) then BoxHigh1[1] else eh1[1];

def eL1 = if barnumber() == 1 then double.nan else if !isnan(BoxLow1[1]) and isnan(BoxLow1) then BoxLow1[1] else el1[1];


plot Balance1 = if isnan(boxhigh1) and isnan(boxlow1) then (eh1+el1)/2 else double.nan;

Balance1.SETHIDING(HideBalance);

Balance1.setdefaultColor(COLOR.PINK);

Balance1.setpaintingStrategy(PAIntingStrategy.SQUARES);

plot RH1 = (balance1 *2)-el1  ;
plot RL1 =  (balance1 *2)-eh1  ;



addcloud(if !HideCloud then rh1 else double.nan, rl1, color.GRAY, color.GRAY);


rh1.setdefaultColor(color.DARK_red);
rh1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rl1.setdefaultColor(color.DARK_green);
rl1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
RH1.SetLineWeight(3);
RL1.SetLineWeight(3);
Hi @Cwparker23, thanks for sharing your indicator. Does it repaint? Does It plot in real-time? Thanks
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
295 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