How to add and use William’s Fractals in Tradingview

William’s Fractals in Tradingview

Fractals is one of five indicators of the Bill William’s trading strategy. This strategy allows you to detect support and resistance areas.

  • A buy fractal is an arrow pointing to the top
  • Sell fractal is an arrow pointing to the bottom

William’s Fractals Pine Script

The following script needs to be  added to the pine script editor inside Tradingview.

To add the script to your chart you need to click on “Add to Chart”

// Bill Williams Fractal Template
// Coded By: Matthew Spencer
// Define our title and that this script will overlay the candles.
study("Williams Fractals",shorttitle="Fractals", overlay=true)
// Define "n" as the number of periods and keep a minimum value of 2 for error handling.
n = input(title="Periods", defval=2, minval=2, type=integer)
// 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])
// 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])
// Plot the fractals as shapes on the chart.
plotshape(dnFractal, style=shape.triangleup, location=location.abovebar, offset=-2, color=olive, transp=0) // Down Arrow above candles
plotshape(upFractal, style=shape.triangledown, location=location.belowbar, offset=-2, color=maroon, transp=0)  // Up Arrow below candles

 

If you have any questions don’t hesitate to ask. William’s fractals work well with the ichimoku indicator and EMA.