ZigZag Fibonacci
ZigZag Fibonacci is an indicator drawn over the price chart.
core language
1
indicator "ZigZag Fibonacci"2
pane: price3
4
input deviation = 3%5
6
swings = zigzag(deviation: deviation, depth: 12)7
8
if swings.len >= 2:9
last_swing = swings.last()10
previous_swing = swings.get(swings.len - 2)11
fib from: (previous_swing.bar, previous_swing.price), to: (last_swing.bar, last_swing.price), levels: [0.382, 0.5, 0.618, 0.786]12
polyline points: swings.map(s => (s.bar, s.price)), color: gray, width: 1What 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.