Fractal Boxes by Mobius for ThinkorSwim

markos

Well-known member
VIP
KCfh6cy.png


Code:
# Fractal Boxes
# Mobius 2017
# Altered Fractals to show Box Breakouts

input sequenceCount = 4;

def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1
                  with count1
                  while count1 != sequenceCount and
                        count1 != -1
                  do if GetValue(high, -i1) > high or
                       (GetValue(high, -i1) == high and
                        count1 == 0)
                     then -1
                     else if GetValue(high, -i1) < high
                          then count1 + 1
                          else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1
                 with count2
                 while count2 != sequenceCount and
                       count2 != -1
                 do if GetValue(high, i2) > high or
                      (GetValue(high, i2) == high and
                       count2 >= 1)
                    then -1
                    else if GetValue(high, i2) < high
                         then count2 + 1
                         else count2;
def downRightSide = fold i3 = 1 to maxSideLength + 1
                    with count3
                    while count3 != sequenceCount and
                          count3 != -1
                    do if GetValue(low, -i3) < low or
                         (GetValue(low, -i3) == low and
                          count3 == 0)
                          then -1
                        else if GetValue(high, -i3) > low
                             then count3 + 1
                             else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1
                   with count4
                   while count4 != sequenceCount and
                         count4 != -1
                   do if GetValue(low, i4) < low or
                        (GetValue(low, i4) == low and
                         count4 >= 1)
                      then -1
                      else if GetValue(low, i4) > low
                      then count4 + 1
                      else count4;

def UF = if upRightSide == sequenceCount and
                    upLeftSide == sequenceCount
                 then high
                 else UF[1];
def pUF = if UF != UF[1]
          then UF[1]
          else pUF[1];
def DF = if downRightSide == sequenceCount and
                      downLeftSide == sequenceCount
                   then low
                   else DF[1];
def pDF = if DF != DF[1]
          then DF[1]
          else pDF[1];
plot UpFractal = UF;
plot DownFractal = DF;
def trend = if UF > pUF and DF > pDF
            then 1
            else if UF < pUF and DF < pDF
            then -1
            else 0;
UpFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
UpFractal.AssignValueColor(if Trend == 1
                           then color.green
                           else if Trend == -1
                                then color.red
                                else color.white);
UpFractal.SetLineWeight(2);
DownFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
DownFractal.AssignValueColor(if Trend == 1
                           then color.green
                           else if Trend == -1
                                then color.red
                                else color.white);
DownFractal.SetLineWeight(2);
AddCloud(if Trend ==  1 then UpFractal else double.nan, DownFractal, Color.green, Color.green);
AddCloud(if Trend == -1 then UpFractal else double.nan, DownFractal, Color.red, Color.red);
AddCloud(if Trend ==  0 then UpFractal else double.nan, DownFractal, Color.white, Color.white);

Code Share: https://tos.mx/SEidEM
 

Attachments

  • KCfh6cy.png
    KCfh6cy.png
    151.1 KB · Views: 237
Last edited by a moderator:
This Fractal Boxes study may have alerted you to the downside break if it had alarms put on it.
Or the break beyond the Expected Move, possibly. Had to kill the premium sellers without a net (hedge) today.
It's all there in the chart share.
Could someone please backtest it on a few short timeframes?
 
/CL (1) contract - raw signal to raw signal.

def sellsignal = Trend == -1 and close < DownFractal;
def buysignal = Trend == 1 and close > UpFractal;

AddOrder(OrderType.SELL_AUTO, sellsignal equals 1, open[-1], 1, Color.RED, Color.RED);
AddOrder(OrderType.BUY_AUTO, buysignal equals 1, open[-1], 1, Color.GREEN, Color.GREEN);

Example:
5M-180days = +$4,670 / 254 trades
10M-180days = -3,860 / 159 trades
15M-180days = -670 / 99 trades
30M-180days = +15,180.00 / 53 trades
1H-180days = +3,850.00 / 23 trades
4H-180days = -11,930 / 12 trades
1D-5years = +22,780 / 7 trades
 
Last edited by a moderator:
Thanks @mc01439 ! (y)
I guess it more of a consolidation zone to help keep nervous folks in a trade by showing them there's no need to panic until it breaks out. Any thoughts? Just curious on your take. Hope you had a good day, markos
 
Last edited:
Thanks @mc01439 ! (y)
I guess it more of a consolidation zone to help keep nervous folks in a trade by showing them there's no need to panic until it breaks out. Any thoughts? Just curious on your take. Hope you had a good day, markos
Hello , where can I find Mobius_IMO_ms? Thanks
 
It is on the bottom of the screen
Have you been through the tutorials on this site yet? It's a pretty good place to start. The TMO oscillator by Mobius can be found in several places.
Here are two:
https://usethinkscript.com/threads/tmo-with-higher-agg_mobius-tsl.91/
https://usethinkscript.com/threads/tmo-or-rsi-in-laguerre-time-with-fe-q-a.477/
In this second entry you will find links to more TMO information. RSI Laguerre is closely associated with it, thus it is intertwined in many threads.
 
Have you been through the tutorials on this site yet? It's a pretty good place to start. The TMO oscillator by Mobius can be found in several places.
Here are two:
https://usethinkscript.com/threads/tmo-with-higher-agg_mobius-tsl.91/
https://usethinkscript.com/threads/tmo-or-rsi-in-laguerre-time-with-fe-q-a.477/
In this second entry you will find links to more TMO information. RSI Laguerre is closely associated with it, thus it is intertwined in many threads.
thanks
 
The boxes don't seem to refresh/generate automatically. Any idea why?
@KarlWolff there is nothing wrong with the study. It is just as Mobius created it. That being said, it completes the next fractal box when a box is complete according to your settings. Play with it under different time frames and fractal periods and you'll see how it might help you. Give it time and watch it work. If it doesn't suit you, that's ok.
 
Hello my friends this is what I am working on for the shorter time frames like 5 minutes...
What do you think about improving the accuracy???
Code:
# Fractal Boxes
# Mobius 2017
# Altered Fractals to show Box Breakouts
input MobiusFractalBoxTime = aggregationPeriod.thirtY_MIN;
def HIGHBOX = high(period = MobiusFractalBoxTime);
def LOWBOX = low(period = MobiusFractalBoxTime);


input sequenceCount = 40;

def maxSideLength = sequenceCount + 800;
def upRightSide = fold i1 = 1 to maxSideLength + 1
                  with count1
                  while count1 != sequenceCount and
                        count1 != -1
                  do if GetValue(high, -i1) > HIGHBOX or
                       (GetValue(high, -i1) == HIGHBOX and
                        count1 == 0)
                     then -1
                     else if GetValue(high, -i1) < HIGHBOX
                          then count1 + 1
                          else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1
                 with count2
                 while count2 != sequenceCount and
                       count2 != -1
                 do if GetValue(high, i2) > HIGHBOX or
                      (GetValue(high, i2) == HIGHBOX and
                       count2 >= 1)
                    then -1
                    else if GetValue(high, i2) < HIGHBOX
                         then count2 + 1
                         else count2;
def downRightSide = fold i3 = 1 to maxSideLength + 1
                    with count3
                    while count3 != sequenceCount and
                          count3 != -1
                    do if GetValue(low, -i3) < LOWBOX or
                         (GetValue(low, -i3) == LOWBOX and
                          count3 == 0)
                          then -1
                        else if GetValue(high, -i3) > LOWBOX
                             then count3 + 1
                             else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1
                   with count4
                   while count4 != sequenceCount and
                         count4 != -1
                   do if GetValue(low, i4) < LOWBOX or
                        (GetValue(low, i4) == LOWBOX and
                         count4 >= 1)
                      then -1
                      else if GetValue(low, i4) > LOWBOX
                      then count4 + 1
                      else count4;

def UF = if upRightSide == sequenceCount and
                    upLeftSide == sequenceCount
                 then high
                 else UF[1];
def pUF = if UF != UF[1]
          then UF[1]
          else pUF[1];
def DF = if downRightSide == sequenceCount and
                      downLeftSide == sequenceCount
                   then low
                   else DF[1];
def pDF = if DF != DF[1]
          then DF[1]
          else pDF[1];
plot UpFractal = UF;
plot DownFractal = DF;
def trend = if UF > pUF and DF > pDF
            then 1
            else if UF < pUF and DF < pDF
            then -1
            else 0;
UpFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
UpFractal.AssignValueColor(if Trend == 1
                           then color.green
                           else if Trend == -1
                                then color.red
                                else color.white);
UpFractal.SetLineWeight(2);
DownFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
DownFractal.AssignValueColor(if Trend == 1
                           then color.green
                           else if Trend == -1
                                then color.red
                                else color.white);
DownFractal.SetLineWeight(2);
AddCloud(if Trend ==  1 then UpFractal else double.nan, DownFractal, Color.green, Color.green);
AddCloud(if Trend == -1 then UpFractal else double.nan, DownFractal, Color.red, Color.red);
AddCloud(if Trend ==  0 then UpFractal else double.nan, DownFractal, Color.white, Color.white);
 
This works pretty nicely as both a range and trend indicator, one question however:
Does this Update in real time?
unknown.png

The cloud appears to have a delay of over 0 bars, so would that mean I would not be able to catch the first run down (in the picture) until after four bars, which in this case might be fine but might take away potential profits?

Thanks for the study!
 
Last edited:
Can someone please help me with the original version of this indicator from Mobius...All I would like it to do is be able to change the opacity of it and the color of the boxes...What code do I need to add to it to allow that?
 
Can someone please help me with the original version of this indicator from Mobius...All I would like it to do is be able to change the opacity of it and the color of the boxes...What code do I need to add to it to allow that?

Look at the code for where colors are assigned... However, for opacity you would use a different function... Instead of Color.color you would use CreateColor(R, G, B) instead...
 
Can someone explain this to me. I don´t know which fractal is meant and how they are calculated. Does the green box appear when an up fractal occurs and the red box when a down fractal? What does the white box mean? I don´t comprehend the code. Does Mobius mean the Bill Williams´s fractals?
 
Hello all. I love the Fractal Boxes script and have adopted it into my trading. However, it would work best for me if it were more opaque and faded behind my candles. Is this possible? Here is the script I have been using.

# Fractal Boxes
# Mobius 2017
# Altered Fractals to show Box Breakouts

input sequenceCount = 4;

def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1
with count1
while count1 != sequenceCount and
count1 != -1
do if GetValue(high, -i1) > high or
(GetValue(high, -i1) == high and
count1 == 0)
then -1
else if GetValue(high, -i1) < high
then count1 + 1
else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1
with count2
while count2 != sequenceCount and
count2 != -1
do if GetValue(high, i2) > high or
(GetValue(high, i2) == high and
count2 >= 1)
then -1
else if GetValue(high, i2) < high
then count2 + 1
else count2;
def downRightSide = fold i3 = 1 to maxSideLength + 1
with count3
while count3 != sequenceCount and
count3 != -1
do if GetValue(low, -i3) < low or
(GetValue(low, -i3) == low and
count3 == 0)
then -1
else if GetValue(high, -i3) > low
then count3 + 1
else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1
with count4
while count4 != sequenceCount and
count4 != -1
do if GetValue(low, i4) < low or
(GetValue(low, i4) == low and
count4 >= 1)
then -1
else if GetValue(low, i4) > low
then count4 + 1
else count4;

def UF = if upRightSide == sequenceCount and
upLeftSide == sequenceCount
then high
else UF[1];
def pUF = if UF != UF[1]
then UF[1]
else pUF[1];
def DF = if downRightSide == sequenceCount and
downLeftSide == sequenceCount
then low
else DF[1];
def pDF = if DF != DF[1]
then DF[1]
else pDF[1];
plot UpFractal = UF;
plot DownFractal = DF;
def trend = if UF > pUF and DF > pDF
then 1
else if UF < pUF and DF < pDF
then -1
else 0;
UpFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
UpFractal.AssignValueColor(if Trend == 1
then color.green
else if Trend == -1
then color.red
else color.white);
UpFractal.SetLineWeight(2);
DownFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
DownFractal.AssignValueColor(if Trend == 1
then color.green
else if Trend == -1
then color.red
else color.white);
DownFractal.SetLineWeight(2);
AddCloud(if Trend == 1 then UpFractal else double.nan, DownFractal, Color.green, Color.green);
AddCloud(if Trend == -1 then UpFractal else double.nan, DownFractal, Color.red, Color.red);
AddCloud(if Trend == 0 then UpFractal else double.nan, DownFractal, Color.white, Color.white);
 
Really liking this study, especially on RENKO charts- thanks for posting! Has anybody found a fix yet to the updating issue? It's really troublesome, especially on faster charts, when you have to constantly refresh the screen. I'll post a vid here for a quick example:


Other studies used in video FYI:
PPS in TOS
VWAP in TOS
Halftrend: https://usethinkscript.com/threads/half-trend-halftrend-scalper-indicator-for-thinkorswim.3305/
Tape Momentum: https://usethinkscript.com/threads/tape-reading-indicator-for-thinkorswim.569/
Fractal Energy: https://usethinkscript.com/threads/...nergy-fle-aka-chop-index-for-thinkorswim.341/
 
Really liking this study, especially on RENKO charts- thanks for posting! Has anybody found a fix yet to the updating issue? It's really troublesome, especially on faster charts, when you have to constantly refresh the screen. I'll post a vid here for a quick example:


Other studies used in video FYI:
PPS in TOS
VWAP in TOS
Halftrend: https://usethinkscript.com/threads/half-trend-halftrend-scalper-indicator-for-thinkorswim.3305/
Tape Momentum: https://usethinkscript.com/threads/tape-reading-indicator-for-thinkorswim.569/
Fractal Energy: https://usethinkscript.com/threads/...nergy-fle-aka-chop-index-for-thinkorswim.341/

This should fix the updating problem.

Ruby:
# Fractal Boxes
# Mobius 2017
# Altered Fractals to show Box Breakouts
# Modified to Fix Plot not Updating without Refresh

input sequenceCount = 4;

def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1
with count1
while count1 != sequenceCount and
count1 != -1
do if GetValue(high, -i1) > high or
(GetValue(high, -i1) == high and
count1 == 0)
then -1
else if GetValue(high, -i1) < high
then count1 + 1
else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1
with count2
while count2 != sequenceCount and
count2 != -1
do if GetValue(high, i2) > high or
(GetValue(high, i2) == high and
count2 >= 1)
then -1
else if GetValue(high, i2) < high
then count2 + 1
else count2;
def downRightSide = fold i3 = 1 to maxSideLength + 1
with count3
while count3 != sequenceCount and
count3 != -1
do if GetValue(low, -i3) < low or
(GetValue(low, -i3) == low and
count3 == 0)
then -1
else if GetValue(high, -i3) > low
then count3 + 1
else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1
with count4
while count4 != sequenceCount and
count4 != -1
do if GetValue(low, i4) < low or
(GetValue(low, i4) == low and
count4 >= 1)
then -1
else if GetValue(low, i4) > low
then count4 + 1
else count4;

def UF = if isnan(close) then uf[1] else if upRightSide == sequenceCount and
upLeftSide == sequenceCount
then high
else UF[1];
def pUF = if UF != UF[1]
then UF[1]
else pUF[1];
def DF = if isnan(close) then df[1] else if downRightSide == sequenceCount and
downLeftSide == sequenceCount
then low
else DF[1];
def pDF = if DF != DF[1]
then DF[1]
else pDF[1];

def trend = if UF > pUF and DF > pDF
then 1
else if UF < pUF and DF < pDF
then -1
else 0;

def hibn  = if high == (uf)
            then BarNumber()
            else hibn[1];
def lobn  = if low == (df)
            then BarNumber()
            else lobn[1];
def hibn1 = HighestAll(hibn);
def lobn1 = HighestAll(lobn);
def r1 =    if isnan(hibn) then r1[1] else if BarNumber() == (hibn)
            then high
            else r1[1];
plot res = r1;
res.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
res.AssignValueColor(if trend == 1
then Color.GREEN
else if trend == -1
then Color.RED
else Color.WHITE);
res.SetLineWeight(2);

def s1  =   if isnan(lobn) then s1[1] else if BarNumber() == (lobn)
            then low
            else s1[1];
plot sup = s1;
sup.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sup.AssignValueColor(if trend == 1
then Color.GREEN
else if trend == -1
then Color.RED
else Color.WHITE);
sup.SetLineWeight(2);

AddCloud(if trend == 1 then res else Double.NaN, sup, Color.GREEN, Color.GREEN);
AddCloud(if trend == -1 then res else Double.NaN, sup, Color.RED, Color.RED);
AddCloud(if trend == 0 then res else Double.NaN, sup, Color.WHITE, Color.WHITE);

input pricecolor = yes;
AssignPriceColor(if pricecolor == no then Color.CURRENT else if close >= open then Color.GREEN else Color.RED);
 
Is there a way to call pattern in thinkscript ? I want draw an arrow when price at certain level when there is a pattern form, for example when there is fractal pattern form I want to know when the price close above/below the up/down fractal, or when there is a doji form I want to draw arrows when price close below that doji, the code I have only show the fractals but it doesn't show arrow when price is close above/below last fractal, I also try to use wizard but it complete trash.
Code:
# Fractal Boxes
# Mobius 2017
# Altered Fractals to show Box Breakouts

input sequenceCount = 2;

def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do
    if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1
    else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do
    if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1
    else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

def downRightSide = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do
    if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1
    else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do
    if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1
    else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

plot UpFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;
plot DownFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;

UpFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
UpFractal.SetDefaultColor(GetColor(3));
UpFractal.SetLineWeight(5);
DownFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
DownFractal.SetDefaultColor(GetColor(4));
DownFractal.SetLineWeight(5);

plot upside =  close > UpFractal ;
upside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
upside.SetDefaultColor(GetColor(3));
upside.SetLineWeight(5);

plot Data =  close crosses above WilliamsFractal()."UpFractal" within 15 bars;
Data.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
Data.SetDefaultColor(GetColor(3));
Data.SetLineWeight(5);
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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