# Bill Williams Fractal Indicator from TOS

**URL:** <https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692>\
**Category:** Custom Indicators\
**Tags:** complete\
**Created:** [August 18, 2020, 2:20pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692 "2020-08-18T14:20:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis\_W](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dennis\_W](https://community.tradovate.com/u/Dennis_W)\
**Post date:** [August 18, 2020, 2:20pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/1 "2020-08-18T14:20:23Z")

</div>

I see there have been several conversions done from TOS thinkscripts, was wondering if someone could help with converting this excellent fractal indicator based on Bill Williams work. Here is the TOS thinkscript. Thank you in advance!

**# Bill Williams Fractal Template**  
**# Coded By: Rigel May 2018**

**#Define “n” as the number of periods and keep a minimum value of 2 for error handling.**  
**input n=2;**

**# Williams Fractals are a 5 point lagging indicator that will draw 2 candles behind.**  
**# The purpose of the indicator is to plot points of trend reversals.**  
**# Often these are paired with trailing stop indicators such as Parabolic SAR, Volatility Stop, and SuperTrend.**

**# Down pointing fractals occur over candles when:**  
**# High(n-2) \< High(n)**  
**# High(n-1) \< High(n)**  
**# High(n + 1) \< High(n)**  
**# High(n + 2) \< High(n)**  
**#dnFractal = (high[n-2] \< high[n]) and (high[n-1] \< high[n]) and (high[n+1] \< high[n]) and (high[n+2] \< high[n])**

**def isupfractal = if low \< low[1] and low \< low[2] and low \< low[-1] and low \< low[-2] then low else double.nan;**  
**# Up pointing fractals occur under candles when:**  
**# Low(n-2) \> Low(n)**  
**# Low(n-1) \> Low(n)**  
**# Low(n + 1) \> Low(n)**  
**# Low(n + 2) \> Low(n)**  
**#upFractal = (low[n-2] \> low[n]) and (low[n-1] \> low[n]) and (low[n+1] \> low[n]) and (low[n+2] \> low[n])**  
**def isdownfractal = if high \> high[1] and high \> high[2] and high \> high[-1] and high \> high[-2] then high else double.nan;**  
**# Plot the fractals as shapes on the chart.**

**plot upfractal = if( isupfractal, isupfractal+ (1 \* tickSize()) , double.nan);**  
**upfractal.SetPaintingStrategy(paintingStrategy.ARROW\_UP);**  
**plot downfractal = if( isdownfractal, isdownfractal - (1 \* tickSize()), double.nan);**  
**downfractal.SetPaintingStrategy(paintingStrategy.ARROW\_DOWN);plot Data = close;**

---

<div class="post-metadata">

**Author:** ![tikidave](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/tikidave/32/2889_2.png) [@tikidave](https://community.tradovate.com/u/tikidave)\
**Post date:** [August 25, 2020, 5:30pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/2 "2020-08-25T17:30:39Z")

</div>

Aloha Dennis, as far as I know we can not add an indicator to bars in the past, which would be required to get this indicator working. @Victor_Vins am I correct in this assumption and do you have a sense for if this might be possible at some point?

---

<div class="post-metadata">

**Author:** ![ThatOneGuy86](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/thatoneguy86/32/792_2.png) [@ThatOneGuy86](https://community.tradovate.com/u/ThatOneGuy86)\
**Post date:** [March 1, 2021, 1:06am UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/3 "2021-03-01T01:06:16Z")

</div>

Any further word on building this indicator? It is an excellent tool to monitor price action.

---

<div class="post-metadata">

**Author:** ![Dennis\_W](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dennis\_W](https://community.tradovate.com/u/Dennis_W)\
**Post date:** [May 13, 2021, 11:24am UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/4 "2021-05-13T11:24:02Z")

</div>

Great scalping tool as well. Many will use stops just above or below a fractal, so when a price breaks a fractal you will have a quick burst of buying. Good to jump on these momentum trades

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [May 29, 2021, 4:25am UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/5 "2021-05-29T04:25:57Z")

</div>

I took a stab at it. I have never used the indicator so there could bugs or edge cases I haven’t considered.

> **[Tradovate is a Modern Futures Trading Platform and Futures Brokerages](https://trader.tradovate.com/?shareable=92d70edc-2c26-4ba7-8933-36523bc36690)**
>
> Trade Futures and Commodities on Most Devices and with a Fixed Commission Rate or Unlimited Trading Subscription Fee Option

---

<div class="post-metadata">

**Author:** ![MadCat](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/madcat/32/1416_2.png) [@MadCat](https://community.tradovate.com/u/MadCat)\
**Post date:** [May 29, 2021, 8:46pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/6 "2021-05-29T20:46:05Z")

</div>

@latter-day-trader

Could you add the ability to control the color of the fractal “up” and “Down” arrows individually instead of all the same color for a little more visual control?

Thanks

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [May 29, 2021, 9:02pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/7 "2021-05-29T21:02:38Z")

</div>

@MadCat

Done. You may need to remove and re-add the indicator to see the new color options.

---

<div class="post-metadata">

**Author:** ![MadCat](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/madcat/32/1416_2.png) [@MadCat](https://community.tradovate.com/u/MadCat)\
**Post date:** [May 29, 2021, 9:13pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/8 "2021-05-29T21:13:43Z")

</div>

@latter-day-trader

Thanks, that works well.

---

<div class="post-metadata">

**Author:** ![JEREMIAH\_SHEBAYAN](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@JEREMIAH\_SHEBAYAN](https://community.tradovate.com/u/JEREMIAH_SHEBAYAN)\
**Post date:** [April 23, 2022, 6:21pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/10 "2022-04-23T18:21:49Z")

</div>

I need help porting this indicator from tos to tradovate. Do you think you can assist?

#Plot yesterday’s high / low  
input Showchartbubbles = yes;  
input ShowTodayOnly = yes;  
def Today = if GetDay() == GetLastDay() then 1 else 0;  
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = “day” )[1];  
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = “day” )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);  
Yhigh.SetDefaultColor(Color.UPTICK);  
Yhigh.SetLineWeight(2);  
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);  
Ylow.SetDefaultColor(Color.DOWNTICK);  
Ylow.SetLineWeight(2);

# 

# 

declare once\_per\_bar;

input PlotPreMktLinesHrsPastOpen = yes;  
def bar = BarNumber();

def nan = Double.NaN;  
def vHigh = high;  
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) \> GetTime();  
def RMhrs = RegularTradingStart (GetYYYYMMDD()) \< GetTime();  
def PMStart = RMhrs[1] and PMhrs;  
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);  
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);  
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;  
def lowBar = if PMhrs and vLow == PMLow then bar else nan;  
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];  
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0  
then PMHighBar  
else nan;  
plot PML = if PlotPreMktLinesHrsPastOpen and PMLowBar != 0  
then PMLowBar  
else nan;  
plot PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0  
then (PMHighBar + PMLowBar) / 2  
else nan;

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),  
PMHigh,  
“PM High”,  
Color.Gray,  
1);

AddChartBubble(ShowChartBubbles and bar == HighestAll(lowBar),  
PMLow,  
“PM Low”,  
Color.Gray,  
0);

AddChartBubble(ShowChartBubbles and bar == Max(HighestAll(highBar), HighestAll(lowBar)),  
(PMHighBar + PMLowBar) / 2,  
“PM Mid”,  
Color.Gray,  
1);

addcloud(pmh, yhigh,Color.light\_gray, Color.Light\_gray);  
AddCloud(pml, ylow, Color.light\_gray, Color.Light\_gray);

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [May 4, 2022, 4:17pm UTC](https://community.tradovate.com/t/bill-williams-fractal-indicator-from-tos/692/11 "2022-05-04T16:17:12Z")

</div>

I can’t help. Sorry. You can’t pay me enough to look at Thinkscript. 😂 Good luck.
