Do you mind sharing that scan. Appreciate itThanks @Mark-RO , I actually cut the original script down, getting rid of all the plots of H and L targets and painting strategies and am now able to scan for tickers that cross above the Balance Line within whatever bar timeframe I want.
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
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;
# 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;
Just set the scan condition as: Balance is TRUE?!@tenacity11, here you go. This needs to be loaded as a Study first, then it can be used in the Scan Tab:
Ruby: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 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; # 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;
@BenTen - This script is not working for all tickers. The aggregation setup for my thinkorSwim is 1D 1M and enabled the extended hours chart as well still i dont see the same chart for all tickers. Any reason or am i missing something.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:
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
Unfortunately, many indicators do not perform well on 1min charts. And many indicators do not perform well with extended hours enabled.@BenTen - This script is not working for all tickers. The aggregation setup for my thinkorSwim is 1D 1M and enabled the extended hours chart as well still i dont see the same chart for all tickers. Any reason or am i missing something.
Please guide and thank you in advance.
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);
boxhigh.setlineWeight(3);
BoxLow.setpaintingStrategy(paintingStrategy.HORIZONTAL);
BoxLow.setdefaultColor(color.dark_red);
BoxHigh.SETHIDING(HideBoxLines);
BoxLow.SETHIDING(HideBoxLines);
boxlow.setlineWeight(3);
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;
def Balance = if isnan(boxhigh) and isnan(boxlow) then (eh+el)/2 else double.nan;
plot IN = if boxhigh then boxlow<close<boxhigh else double.nan;
plot UP = if balance then close crosses above boxhigh[1] else double.nan;
plot DWN = if balance then close crosses below boxlow[1] else double.nan;
plot MID = if !isnan(expL) and !isnan(ExpH) then ((ExpH+expl)/2) else double.nan;
Mid.setdefaultColor(CREATECOLOR(255,255,255));
mid.setpaintingStrategy(PAIntingStrategy.SQUARES);
That is beyond the scope and purpose of this indicator. You could start a new thread with the idea of creating a new indicator.@MerryDay First of all Happy thanks giving to you and every one in this form, you guys have helped me a ton during this learning process of trading.
I cleaned up the code from the first post to fit my need, it still plots Box High (green line), Box Low (red line) and Box Mid (white line). So what I want to know/figure out is how to calculate average ATR of the box.
Below is the chart for Costco on Daily time frame.
As you can see, the code plotted two consolidation boxes. I want to figure out how to calculate the average ATR of the candles WITHIN EACH of the box (two boxes = two separate ATR values, one for each box). I tried using bar count tutorial @XeoNoX provided under tutorial section but I still can't seem to figure it out.
Thank you so much for your help. Happy holidays,
No problem at all, i was able to figure out how to calcualte total bars inside the consolidation box but i am not able to figure out how to calculate ATR for those bar numbers. Maybe i thought there was an easier solution that I am not aware of but i guess there isnt an easier solution lol. no problem at all, i'll just do it manually. Thank you for your time none the lessThat is beyond the scope and purpose of this indicator. You could start a new thread with the idea of creating a new indicator.
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);
Is it possible scan when price is breaking out from the box?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.
Someone already created a scan for the original. Just manipulate the code I've give and create one.Is it possible scan when price is breaking out from the box?
The original author strictly writes studies for TradingView and no more thinkScript, last I heard from him. Look for "HammondB3" and that's the original author for this study.Is there Tradingview version of this indicator?
Would it be possible for you to add alerts when it breaks please! Thank youB3 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);
@3AMBH are you using this strategy? the video was interesting for sure, never looked at the market like this. how are you using the strategy?Hi Ben, I found your b3 indicator after having watched this video:
At the very least the video shines a light on how to trade contractions or consolidation boxes. The presenter shows in detail the 3 phases of the market and how to profit. He is a Forex trader but his concepts are good for all markets.
Please give it a try:
Not using it@3AMBH are you using this strategy? the video was interesting for sure, never looked at the market like this. how are you using the strategy?
@tomsk can you add back the stop loss line that is on the original study? Maybe just make it optional. Its nice to have for visual reference.@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
@Jonas J so now when you scan are the stocks more current and not the ones that are days and weeks out like the original scan?Thanks @Mark-RO , I actually cut the original script down, getting rid of all the plots of H and L targets and painting strategies and am now able to scan for tickers that cross above the Balance Line within whatever bar timeframe I want.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Darvas Box with Target Levels for ThinkorSwim (Scalping Strategy) | Indicators | 19 | ||
S | Volatility Box Indicator for ThinkorSwim | Indicators | 99 | |
RedK Chop & Breakout Scout V2.0 for ThinkOrSwim | Indicators | 17 | ||
G | Potential Breakout (PBO) Indicator for ThinkorSwim | Indicators | 8 | |
Repaints B4 Balanced BB Breakout For ThinkOrSwim | Indicators | 843 |
Start a new thread and receive assistance from our community.
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.
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.