Fractal Chaos Bands for ThinkorSwim non-repainting version

SteveDay

Member
Plus
I've written a version which is far simpler to read and matches the one used by Gemini (Exchange), plus I made the fractal length adjustable.

Please let me know if it's of any use.

It can be turned into a Backtesting Strategy by un-commenting the last 2 lines.

http://tos.mx/ls25cP8

PS: It doesn't use any forward-looking code like the this version
https://usethinkscript.com/threads/fractal-chaos-bands-for-thinkorswim.134/
, so what you see is on the chart is exactly how it behaves with realtime data.

PPS: What I define as "Repainting" is when an indicator updates only the latest bar using realtime data. Whereas the older Fractal Chaos Bands by BenTen & WalkingBallista was based on the WilliamsFractal code from TOS, which looks ahead into the future (relative to the current position) by up to 10 bars! (I call that "Forward-Looking", which can result in the entire chart being redrawn.)

Anything using the built-in WilliamsFractal study/code will appear to give incredible results on historical charts, but live trading performance won't be comparable in the slightest. (IMO the WilliamsFractal should only be used as a drawing tool, not as a trading tool).

I was deeply disappointed when I found out the Zig-Zag indicator was not performing live as it appeared to on old data. (TTM_ScalperAlert is another one that looks ahead into the future, but at least that is limited to 3 bars - which might not be bad on 1min charts, but could lead to large losses on a 5min or greater timeframes.).


Code:
#//# SD_FractalChaosBands_FCB
#//# Color scheme is a clone of the FCB used on Gemini.com
#//# by Steve Day [2023/02/19]

declare upper;


input fractal_length = 5;
Assert(fractal_length >= 3, "ERROR: The fractal_length must be greater than 3. (fractal_length = " + (fractal_length) + ")");

#//# If the fractal length is even then +1 to it.
def frac_len = if fractal_length % 2 == 0 then fractal_length + 1 else fractal_length;

#//# Fractal Variables
def side_length = Floor(frac_len / 2);
def middle = Ceil(frac_len / 2);

#//# Highest Left & Right of Middle High..
def high_left   = Highest(HIGH[middle], side_length);
def high_middle = HIGH[middle - 1];
def high_right  = Highest(HIGH, side_length);

#//# Lowest Left & Right of Middle Low..
def low_left    = Lowest(LOW[middle - 1], side_length);
def low_middle  = LOW[middle - 1];
def low_right   = Lowest(LOW, side_length);


#//# High/Low Fractal code..
def high_frac;
def low_frac;

high_frac = if high_middle >= Max(high_left, high_right) then high_middle
            else high_frac[1];

low_frac = if low_middle <= Min(low_left, low_right) then low_middle
            else low_frac[1];

plot "Fractal High" = Max(high_frac[1], low_frac[1]);
plot "Fractal Low" = Min(high_frac[1], low_frac[1]);

"Fractal High".SetDefaultColor(CreateColor(0,127,255));
"Fractal Low".SetDefaultColor(CreateColor(133,201,158));

input Show_Cloud = yes;
DefineGlobalColor("Fractal Cloud", CreateColor(225,225,225));
AddCloud(if Show_Cloud == yes then "Fractal Low" else Double.NaN, "Fractal High", GlobalColor("Fractal Cloud"), GlobalColor("Fractal Cloud"), showborder = no);



#//# For Backtesting..
#AddOrder(OrderType.BUY_AUTO, CLOSE > "Fractal High", tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "FCB_Long");

#AddOrder(OrderType.SELL_AUTO, CLOSE < "Fractal Low", tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "FCB_Short");

I made a couple of revisions to allow users to toggle the repainting (last bar only) & twist prevention on/off.

Just replace the 2 plot lines with these 6 lines (To perfectly match the output from Gemini's JS engine the settings would be: Repainting = yes, PreventTwisting = no):

Code:
input Repainting = yes;
input PreventTwisting = no;
def max_frac = Max(high_frac[!Repainting], low_frac[!Repainting]);
def min_frac = Min(high_frac[!Repainting], low_frac[!Repainting]);
plot "Fractal High" = if !PreventTwisting then high_frac[!Repainting] else max_frac;
plot "Fractal Low"  = if !PreventTwisting then low_frac[!Repainting] else min_frac;

I'm experimenting with adding markers/different colored clouds, but so far they're just cluttering up the simplicity of the system. Right now I just wanted to get a clean version out the door.
 
Last edited:

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