Fractal Boxes by Mobius for ThinkorSwim

/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);
Hello Mc01439,
Greetings my friend, I tried adding this code but got errors with the words "Trend" and "DownFractal" and "Upfractal" If you get any spare time to respond, Can you kindly let me know how you would use this in script without errors please?

Kindest Regards and THanks in advance
Mark
 
Last edited by a moderator:
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);

This may help you develop the code as you want. It adds the TOS doji indicator from the patterns dropdown in the upper right corner of the charr to the code you posted. It is displayed as a Line.

Screenshot 2024-01-10 145551.png
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);

#
# TD Ameritrade IP Company, Inc. (c) 2007-2023
#

#wizard text: Inputs: length:
#wizard input: length
#wizard text: body factor:
#wizard input: bodyFactor

input length = 20;
input bodyFactor = 0.05;

assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);

def d = if IsDoji(length, bodyFactor) then close else d[1];
plot Doji = d;

Doji.SetPaintingStrategy(PaintingStrategy.LINE);
Doji.SetDefaultColor(CreateColor(153, 153, 255));
Doji.SetLineWeight(3);
 

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
271 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