Fibonacci retracement
All indicators

LibraryMarket structure

Indicator

Fibonacci retracement

How far price has pulled back into the last swing leg, at the Fibonacci ratios 0.236, 0.382, 0.5, 0.618 and 0.786 between the last confirmed swing high and low.

Market structureOn the price1 inputFib

How it is calculated

Swings as in structure. The leg runs from the older of the last swing high and low to the newer: up when the high is newer. Each level is end minus ratio times (end minus start), so level_0 is the leg's end, level_1000 its start and level_618 the 0.618 retracement. leg is +1 for an up leg, -1 for a down leg.

Reference: Fibonacci retracement of the last swing leg (#546)

How to read it

The levels move when a new swing is confirmed, length bars after its extreme, and hold until the next one. In an up leg the levels sit below the high, in a down leg above the low; nothing shows before the first swing high and low.

In a strategy

Buy a pullback in an up leg: when f = ctx.ind("fib_retracement", length=3) has f.leg of 1, a long limit at f.level_618 with the stop below f.level_1000, the leg's low.

Inputs

InputTypeDefaultRange or choices
Swing bars each sidelengthWhole number3min 1, max 50

What it draws

LineDrawn as
0Steps
0.236Steps
0.382Steps
0.5Steps
0.618Steps
0.786Steps
1Steps

Used in

No strategy template reads it yet.

OrionQuant