Put the same chart in front of three people and ask each of them to draw a Fibonacci retracement. You will get three sets of levels. One anchored on the close of the big green candle, one on its wick, and one on a swing two weeks earlier that "looked like the real start". All three then point at the 0.618 line as if it meant something, and none of them can say why their 0.618 is the right one. The ratios are the easy part of a fib: they are fixed numbers. Everything that makes a fib useful or useless happens in the two clicks before the ratios appear. This guide gives those two clicks a rule. It covers which swings to anchor on, which end is 0, how to tell whether the leg is finished, and how to check the levels against the bars you already have. Then it shows the same rule done by PineScripter's chart agent while you watch, and by a Pine Script v6 indicator.
Short answer
Anchor a Fibonacci retracement on two confirmed swing points: the start and the end of one completed leg, using the wicks (the swing low's low and the swing high's high), not the closes. For a leg that went up, click the swing low first and the swing high second. The retracement levels (0.236, 0.382, 0.5, 0.618, 0.786) then measure how much of the rise has been given back, with 0 at the high and 1 at the low. A leg is only complete once both of its swings are confirmed by the bars after them. The levels describe proportions of a past move. They do not say price will react at any of them.
Key facts
- A retracement level is the end of the leg minus the leg's size times the ratio. For a rise from 100 to 200, the 0.618 level is 200 - 100 x 0.618 = 138.2.
- Most disagreement between fibs comes from the anchors, not the ratios. Wick versus close alone can move every level by the size of a candle body.
- Anchor on confirmed swings. With 5 bars on each side, a swing high is known 5 bars after it prints, and a leg whose end is not yet confirmed can still extend.
- In PineScripter's fib retracement tool the first click is level 1 and the second click is level 0. Click the start of the leg first and its end second.
- The tool shows 0, 0.236, 0.382, 0.5, 0.618, 0.786 and 1 by default, plus the 1.618, 2.618, 3.618 and 4.236 extensions beyond the start of the leg.
- PineScripter's chart agent reads the most recent swing points with their times and prices, so it anchors on the same swings every time you ask, and it places the fib with the same two clicks a person makes.
- The Pine Script below anchors on the highest confirmed swing high and the lowest confirmed swing low inside a window you set, and redraws on the last bar only.
| Anchoring choice | Common setting | What changing it does |
|---|---|---|
| Anchor points | Confirmed swing low and swing high | Anchoring on any candle makes the fib a matter of taste |
| Price at each anchor | Wicks (the low and the high) | Closes shrink the leg and shift every level toward the middle |
| Which leg | The last completed leg, or the range of a set window | An older, larger leg gives wider levels that matter on a higher timeframe |
| Bars on each side of a swing | 5 | Higher picks bigger legs and confirms them later |
| Click order | Start of the leg, then its end | Reversed clicks put 0 and 1 at the wrong ends, so 0.618 lands where 0.382 should be |
The ratios are fixed. The anchors are where fibs go wrong
A retracement fib is arithmetic on two prices. Take a leg that rose from A to B. The 0.382 level is B minus 38.2% of the distance from A to B, the 0.5 level is the midpoint, the 0.618 level is B minus 61.8% of it, and so on. Nothing about the ratios changes from one chart to the next. That is exactly why two fibs on the same chart can disagree: if the ratios are the same, every difference between them comes from where A and B were placed.
There are three common ways the anchors drift. The first is wick versus close. Anchoring on the close of the low candle instead of its wick shortens the leg by however long that wick was, and every level moves with it. The second is picking a candle that stands out instead of a swing. A long green body feels like the start of a move, but if the bar before it had a lower low, the move started there. The third is choosing the leg after looking at where price is now, which quietly turns the fib into a tool for agreeing with yourself. All three have the same fix: decide the anchoring rule first, then apply it.
Anchor on confirmed swings, wick to wick
A swing low is a bar whose low is not beaten by a set number of bars on each side of it, and a swing high is the mirror image. Five bars on each side is a common middle setting. Anchoring a fib on swings, rather than on candles that look important, gives you two prices with a definition you can repeat on any chart. Use the swing low's low and the swing high's high, because the swing is defined on the wick and that is where the move actually turned.
The definition has a cost, and it matters for fibs more than for most drawings. A swing is only known once the bars after it have closed without going further. On a 1 hour chart with 5 bars each side, the swing high at the top of a rally is not a swing high until five hours later. Until then, the leg you are measuring may still be extending, and every level you draw from it will move. A fib anchored on an unconfirmed high is a fib you will redraw. The pivot high and low guide covers why swing points always arrive late and how Pine Script reports them on the confirming bar.
Click order is the other half of anchoring. For a leg that went up, the retracement measures how much of the rise has been given back, so 0 belongs at the high, where the leg ended, and 1 at the low, where it started. In PineScripter's fib retracement tool the first click becomes level 1 and the second becomes level 0, so you click the swing low first and the swing high second. For a leg that went down, click the swing high first and the swing low second. If your fib shows 0.618 near the top of a rise, the clicks were reversed and every label is pointing at the wrong price.
Which leg: the last completed one, or the range of a window
Charts contain legs inside legs. A daily rise is made of hourly rises and pullbacks, and each of those can carry its own fib. There are two rules that hold up. The first is the last completed leg: the most recent confirmed swing low and the confirmed swing high after it (or the reverse for a fall). It describes the move that just happened. The second is the range of a window: the highest swing high and the lowest swing low inside the last N bars, anchored in the order they happened. It describes the dominant move of that period and is less sensitive to small wobbles. The script further down uses the second rule.
Pick one and write it down, including N if you use a window. "The last 150 bars on the 1 hour" is a rule. "The move that looks important" is not. A useful habit is to say the anchors out loud before drawing: swing low at this time and price, swing high at that time and price. If you cannot name them, the fib is not ready to draw.
Check the fib against the bars you already have
A fib on its own invites storytelling. Price comes near 0.618, and it is easy to remember the times it turned there and forget the times it went straight through. The check is to look at the bars already on the chart, inside the leg and after it, and count. How many times did price trade into each level and close back on the side it came from? How many times did it pass through? Do the same on a higher timeframe with the same anchoring rule. If the levels only line up with turns on the one timeframe where you drew them, that tells you something too.
Replay is the other check. Step through the leg bar by bar and stop on the bar where the second swing was confirmed. That is the first moment the fib could honestly have been drawn. Anything that happened before that bar was not something the fib could have described at the time, however neat it looks on the finished chart. The counts and the replay are both descriptions of the past on the bars you loaded. They are the way to keep a fib honest, not a way to make it predictive.
Ask the agent to anchor it while you watch
On PineScripter's chart you can hand the whole job to the chart agent in one sentence: "Draw a fib retracement on BTCUSDT 1h from the last confirmed swing low to the swing high after it." The agent first reads the chart. Among what it gets back are the market, the timeframe, ATR, and the most recent swing points with 5 bars on each side, each with its side, its price and its time. So when you say "the last swing low", it is not guessing from candle shapes. It is reading the same list of confirmed swings every time you ask.
Then it draws, and you see it happen. An AI cursor opens the Fibonacci tools in the drawing toolbar, picks Fib retracement, and clicks the two anchors in order, the swing low first and the swing high second, so 0 lands on the high and 1 on the low. What it draws is saved with your other drawings on that market, and if the result is not what you meant, the batch is undone from the chat in one click.
The rest of the check is a conversation. Say "now switch to the 4h and anchor the same way", and it changes the timeframe, reads the swings there and draws again, so you can compare the two sets of levels. Say "anchor it on the highest and lowest swing of the last 150 bars instead", and it redraws with the other rule. It describes what is on the chart. It does not say which level price will respect, and it does not suggest a trade at any of them. The agent works on PineScripter's chart, on crypto spot markets, not on your TradingView chart.
Turn the anchoring rule into an indicator
Once the rule is written down it is a short script. The version below stores every confirmed swing high and swing low with the bar it happened on. On the last bar it finds the highest swing high and the lowest swing low inside the window, works out which came first to decide whether the leg went up or down, and draws the seven retracement levels from the start of the leg to the current bar, each labelled with its ratio and price.
//@version=6
indicator("Fib from the range's swings", overlay = true, max_lines_count = 20, max_labels_count = 20)
swingLen = input.int(5, "Bars on each side of a swing", minval = 1)
lookback = input.int(150, "Look for swings in the last (bars)", minval = 20)
ph = ta.pivothigh(high, swingLen, swingLen)
pl = ta.pivotlow(low, swingLen, swingLen)
// Confirmed swings, each stored with the bar it happened on.
var array<float> highs = array.new<float>()
var array<int> highBars = array.new<int>()
var array<float> lows = array.new<float>()
var array<int> lowBars = array.new<int>()
if not na(ph)
highs.push(ph)
highBars.push(bar_index - swingLen)
if not na(pl)
lows.push(pl)
lowBars.push(bar_index - swingLen)
var array<line> fibLines = array.new<line>()
var array<label> fibLabels = array.new<label>()
ratios = array.from(0.0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.0)
if barstate.islast
for ln in fibLines
ln.delete()
for lb in fibLabels
lb.delete()
fibLines.clear()
fibLabels.clear()
// The highest swing high and the lowest swing low inside the window.
float hiPrice = na
int hiBar = na
float loPrice = na
int loBar = na
for [k, b] in highBars
if bar_index - b <= lookback and (na(hiPrice) or highs.get(k) > hiPrice)
hiPrice := highs.get(k)
hiBar := b
for [k, b] in lowBars
if bar_index - b <= lookback and (na(loPrice) or lows.get(k) < loPrice)
loPrice := lows.get(k)
loBar := b
if not na(hiPrice) and not na(loPrice)
leg = hiPrice - loPrice
// Low first means the leg went up: 0 sits at the end of the leg (the high)
// and 1 at its start (the low), so 0.618 is 61.8% of the rise given back.
upLeg = loBar < hiBar
startBar = math.min(hiBar, loBar)
for r in ratios
price = upLeg ? hiPrice - leg * r : loPrice + leg * r
fibLines.push(line.new(startBar, price, bar_index, price, extend = extend.right, color = color.new(color.gray, 30)))
fibLabels.push(label.new(bar_index + 3, price, str.tostring(r, "0.000") + " " + str.tostring(price, format.mintick), style = label.style_none, textcolor = color.gray, size = size.small))Three details in it are worth knowing. The swings come from ta.pivothigh and ta.pivotlow with the same length on both sides, and each is stored at the bar where it happened, five bars before the bar that confirmed it. The fib is rebuilt on the last bar only, from swings that were already confirmed, so it never leans on a bar that has not closed. And the direction comes from the order of the two swings, the same rule as the click order above: if the low came first, 0 sits at the high. Lines and labels are deleted and redrawn together on each update, which keeps the script well inside the drawing limits. The drawing objects guide covers what happens when a script does not clean up after itself.
Common mistakes, and how the rule avoids them
Anchoring on the current bar is the most common. Price makes a new high, someone draws a fib to it, and the next bar goes higher. The leg was not finished. Waiting for the swing to confirm costs a few bars and saves redrawing. The second is mixing wick and close: one anchor on a wick, the other on a body, because that is where the cursor happened to land. Pick wicks and use them at both ends. The third is reversing the clicks, which turns every label into its complement, so 0.382 is printed where 0.618 belongs.
The last mistake is reading the levels as targets. A retracement is a ruler laid across a finished move. The 0.618 line is the price where 61.8% of that move had been given back, and that is all it is. Count how price behaved at the levels on the bars you have, check the same rule on another timeframe and in replay, and keep any decision about what to do outside the drawing.
Frequently asked questions
Where do you anchor a Fibonacci retracement?
On two confirmed swing points that start and end one completed leg, using the wicks: the swing low's low and the swing high's high. For a leg that went up, the start is the swing low and the end is the swing high.
Should a fib be drawn from wicks or closes?
Wicks, at both ends. Swings are defined on the high and the low, and that is where the move turned. Anchoring on closes shortens the leg and moves every level toward the middle. Whichever you choose, use the same at both anchors.
Which end of the fib is 0?
The end of the leg. For a rise, 0 is at the swing high and 1 at the swing low, so 0.618 is the price where 61.8% of the rise had been given back. In PineScripter's tool the first click is 1 and the second click is 0, so click the start of the leg first.
Can an AI draw a Fibonacci retracement on my chart?
PineScripter's chart agent can draw one on PineScripter's chart, on crypto spot markets. It reads the confirmed swing points with their times and prices, then places the fib retracement with two clicks while you watch its cursor, and the batch can be undone in one click. It does not draw on your TradingView chart, and it does not say what to trade.
Does the fib indicator repaint?
It is redrawn on the last bar from confirmed swings only, so it never depends on a bar that has not closed. When a new swing is confirmed and becomes the new high or low of the window, the anchors move to it. That is the honest delay of any swing-based fib, not a change to past values.
The practical takeaway
Decide the anchors before you look at the levels. Two confirmed swings, wick to wick, the start of the leg clicked first and its end second, chosen by a rule you can say out loud: the last completed leg, or the range of a window you named. Once the rule is that explicit, you can draw the fib by hand, have the agent draw it while you watch, or run it as a script, and all three land on the same prices. Then count how price behaved at those prices on the bars you have, and read the fib as what it is: a ruler laid across a move that already happened.
The chart agent, the fib tools and the editor that turns the anchoring rule into a script all live in one chat in PineScripter. Ask the agent to anchor the fib, check it on another timeframe and in replay, then ask for the indicator that draws it on every chart.
Sources
- Pine Script v6 reference: ta.pivothigh
- Pine Script v6 reference: ta.pivotlow
- Pine Script v6 reference: line.new
- Pine Script v6 reference: barstate.islast
Related reading: zones from the same swing points, why swing points arrive late, the kinds of repainting, lines, labels and the drawing limit, bar replay.
Disclaimer: PineScripter is a coding tool for Pine Script development. It does not provide financial advice and does not guarantee trading profits. Always backtest strategies thoroughly and understand the risks before live trading.