Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Williams Fractals", shorttitle="Beppo Fractals", overlay=true)
- n = input.int(2, title="Periods", minval=2)
- fractalBars = input("3", title="3 or 5 Bar Fractal")
- // Function to get daily timeframe data
- getDailyData(value) =>
- request.security(syminfo.tickerid, "D", value, lookahead=barmerge.lookahead_on)
- geth4Data(value) =>
- request.security(syminfo.tickerid,"240",value,lookahead=barmerge.lookahead_on)
- // Logic
- var bool dnFractalD = na
- var bool upFractalD = na
- var bool dnFractalh4 = na
- var bool upFractalh4 = na
- if fractalBars == "5"
- dnFractalD := (getDailyData(high[n-2]) < getDailyData(high[n])) and
- (getDailyData(high[n-1]) < getDailyData(high[n])) and
- (getDailyData(high[n+1]) < getDailyData(high[n])) and
- (getDailyData(high[n+2]) < getDailyData(high[n]))
- upFractalD := (getDailyData(low[n-2]) > getDailyData(low[n])) and
- (getDailyData(low[n-1]) > getDailyData(low[n])) and
- (getDailyData(low[n+1]) > getDailyData(low[n])) and
- (getDailyData(low[n+2]) > getDailyData(low[n]))
- dnFractalh4 := (geth4Data(high[n-2]) < geth4Data(high[n])) and
- (geth4Data(high[n-1]) < geth4Data(high[n])) and
- (geth4Data(high[n+1]) < geth4Data(high[n])) and
- (geth4Data(high[n+2]) < geth4Data(high[n]))
- upFractalh4 := (geth4Data(low[n-2]) > geth4Data(low[n])) and
- (geth4Data(low[n-1]) > geth4Data(low[n])) and
- (geth4Data(low[n+1]) > geth4Data(low[n])) and
- (geth4Data(low[n+2]) > geth4Data(low[n]))
- else
- if fractalBars == "3"
- dnFractalD := (getDailyData(high[n-1]) < getDailyData(high[n])) and
- (getDailyData(high[n+1]) < getDailyData(high[n]))
- upFractalD := (getDailyData(low[n-1]) > getDailyData(low[n])) and
- (getDailyData(low[n+1]) > getDailyData(low[n]))
- dnFractalh4 := (geth4Data(high[n-1]) < geth4Data(high[n])) and
- (geth4Data(high[n+1]) < geth4Data(high[n]))
- upFractalh4 := (geth4Data(low[n-1]) > geth4Data(low[n])) and
- (geth4Data(low[n+1]) > geth4Data(low[n]))
- // Plot the fractals as shapes on the chart.
- plotshape(dnFractalh4, style=shape.triangledown, location=location.abovebar, size=size.tiny, offset=-2, color=color.blue)
- plotshape(upFractalh4, style=shape.triangleup, location=location.belowbar, size=size.tiny, offset=-2, color=color.blue)
- plotshape(dnFractalD, style=shape.triangledown, location=location.abovebar, size=size.tiny, offset=-2, color=color.red)
- plotshape(upFractalD, style=shape.triangleup, location=location.belowbar, size=size.tiny, offset=-2, color=color.red)
Advertisement
Add Comment
Please, Sign In to add comment