ZigZag Fibonacci

ZigZag Fibonacci is an indicator drawn over the price chart.

core language

zigzag-fibonacci.abx
1indicator "ZigZag Fibonacci"
2pane: price
3
4input deviation = 3%
5
6swings = zigzag(deviation: deviation, depth: 12)
7
8if swings.len >= 2:
9last_swing = swings.last()
10previous_swing = swings.get(swings.len - 2)
11fib from: (previous_swing.bar, previous_swing.price), to: (last_swing.bar, last_swing.price), levels: [0.382, 0.5, 0.618, 0.786]
12polyline points: swings.map(s => (s.bar, s.price)), color: gray, width: 1
What this script says

ZigZag Fibonacci is an indicator drawn over the price chart.

You can change one input: deviation (default 3%).

It calculates swings as the zigzag swings (deviation deviation, depth 12).

On each bar, it checks whether the number of swings is at or above 2 and, if so, sets last_swing to swings.last(), sets previous_swing to swings.get(swings.len - 2), draws Fibonacci levels and draws a polyline.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account