STX OB Retest Fib: Order Block entry with Fibonacci targets
STX OB Retest Fib automates a classic ICT reading: it detects a break of structure (BOS) with displacement, marks the Order Block that caused it and, when price retests that zone, draws the entry, stop and three targets from the Fibonacci extension of the impulse. A tool to train your eye on institutional zone retests.
Study and visualisation tool. Zones and levels are approximated in Pine from price structure; this is a decision-support aid, not a recommendation or a buy/sell signal. Results are not guaranteed.
What does it do?
- BOS detection with displacement. Flags the break of a prior swing only when the candle exceeds a range threshold measured in ATR (filters out weak breaks).
- Automatic Order Block. Draws a box on the last opposite candle before the impulse (teal for buys, red for sells): the institutional footprint.
- Signal on the retest. Waits for price to return to the Order Block zone (with ATR tolerance) before marking the entry — not on the break.
- Entry, SL and 3 Fibonacci TPs. Plots the entry, the stop (ATR buffer) and TP1/TP2/TP3 as 1.618 / 2.0 / 2.618 extensions of the impulse, with price labels.
- One signal per Order Block. Option to limit to a single trigger per zone and avoid re-entry noise.
- Adjustable parameters. Swing lookback, displacement threshold, retest tolerance, SL buffer and line length.
How to read it
When a green (BUY) triangle appears below the candle or a red (SELL) one above it, price has just retested an Order Block after a break with displacement. The lines project the entry, the SL and the three targets. The teal/red box reminds you where the move came from. The indicator does not execute or recommend: it shows you the scenario so you decide with your own risk management.
The asset, live
Reference chart (XAUUSD). Load the indicator in your own TradingView account to see the zones and levels over live price.
How to install on TradingView
- Open the Pine Editor (bottom panel of TradingView).
- Paste the code below (Pine Script v5) and replace the content.
- "Add to chart" on the asset and timeframe you trade (it works on any market; we use it most on intraday XAUUSD).
- Adjust the parameters to your style and save with Ctrl/Cmd + S.
Pine Script v5 code
STX OB Retest Fib · Pine v5 · 105 lines · open source.
//@version=5
indicator("STX OB Retest Fib", overlay=true, max_lines_count=300, max_labels_count=120, max_boxes_count=80)
swing = input.int(5, "Swing lookback", minval=2)
dispATR = input.float(1.0, "Displacement x ATR", minval=0.1, step=0.1)
retestTol = input.float(0.1, "Retest tol x ATR", minval=0.0, step=0.05)
f1 = input.float(1.618, "TP1 x legA", step=0.001)
f2 = input.float(2.0, "TP2 x legA", step=0.001)
f3 = input.float(2.618, "TP3 x legA", step=0.001)
slBuf = input.float(0.25, "SL buffer x ATR", minval=0.0, step=0.05)
extend = input.int(40, "Line length", minval=5)
oncePerOB = input.bool(true, "1 signal per OB")
atr = ta.atr(14)
ph = ta.pivothigh(swing, swing)
pl = ta.pivotlow(swing, swing)
var float lastPH = na
var float lastPL = na
lastPH := not na(ph) ? ph : lastPH
lastPL := not na(pl) ? pl : lastPL
var float lastDownHi = na
var float lastDownLo = na
var float lastUpHi = na
var float lastUpLo = na
if close < open
lastDownHi := high
lastDownLo := low
if close > open
lastUpHi := high
lastUpLo := low
bullBOS = not na(lastPH) and close > lastPH and close[1] <= lastPH and (high - low) > dispATR * atr
bearBOS = not na(lastPL) and close < lastPL and close[1] >= lastPL and (high - low) > dispATR * atr
var float bHi = na
var float bLo = na
var float bLeg = na
var bool bUsed = true
var float sHi = na
var float sLo = na
var float sLeg = na
var bool sUsed = true
if bullBOS and not na(lastDownLo)
bHi := lastDownHi
bLo := lastDownLo
bLeg := high - lastDownLo
bUsed := false
box.new(bar_index, bHi, bar_index + 6, bLo, border_color=color.teal, bgcolor=color.new(color.teal, 85))
if bearBOS and not na(lastUpHi)
sHi := lastUpHi
sLo := lastUpLo
sLeg := lastUpHi - low
sUsed := false
box.new(bar_index, sHi, bar_index + 6, sLo, border_color=color.red, bgcolor=color.new(color.red, 85))
tol = retestTol * atr
bullRetest = not na(bHi) and (not bUsed or not oncePerOB) and low <= bHi + tol and low >= bLo - tol and close > bLo
bearRetest = not na(sHi) and (not sUsed or not oncePerOB) and high >= sLo - tol and high <= sHi + tol and close < sHi
var float buyE = na
var float sellE = na
if bullRetest
buyE := bHi
sl = bLo - slBuf * atr
t1 = buyE + f1 * bLeg
t2 = buyE + f2 * bLeg
t3 = buyE + f3 * bLeg
line.new(bar_index, buyE, bar_index + extend, buyE, color=color.gray, width=2)
line.new(bar_index, sl, bar_index + extend, sl, color=color.red, style=line.style_dashed)
line.new(bar_index, t1, bar_index + extend, t1, color=color.green)
line.new(bar_index, t2, bar_index + extend, t2, color=color.green)
line.new(bar_index, t3, bar_index + extend, t3, color=color.green)
label.new(bar_index + extend, buyE, "ENTRY " + str.tostring(buyE, format.mintick), style=label.style_label_left, color=color.gray, textcolor=color.white, size=size.small)
label.new(bar_index + extend, sl, "SL " + str.tostring(sl, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)
label.new(bar_index + extend, t1, "TP1 " + str.tostring(t1, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.black, size=size.small)
label.new(bar_index + extend, t2, "TP2 " + str.tostring(t2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.black, size=size.small)
label.new(bar_index + extend, t3, "TP3 " + str.tostring(t3, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.black, size=size.small)
bUsed := true
if bearRetest
sellE := sLo
sl = sHi + slBuf * atr
t1 = sellE - f1 * sLeg
t2 = sellE - f2 * sLeg
t3 = sellE - f3 * sLeg
line.new(bar_index, sellE, bar_index + extend, sellE, color=color.gray, width=2)
line.new(bar_index, sl, bar_index + extend, sl, color=color.red, style=line.style_dashed)
line.new(bar_index, t1, bar_index + extend, t1, color=color.lime)
line.new(bar_index, t2, bar_index + extend, t2, color=color.lime)
line.new(bar_index, t3, bar_index + extend, t3, color=color.lime)
label.new(bar_index + extend, sellE, "ENTRY " + str.tostring(sellE, format.mintick), style=label.style_label_left, color=color.gray, textcolor=color.white, size=size.small)
label.new(bar_index + extend, sl, "SL " + str.tostring(sl, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)
label.new(bar_index + extend, t1, "TP1 " + str.tostring(t1, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black, size=size.small)
label.new(bar_index + extend, t2, "TP2 " + str.tostring(t2, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black, size=size.small)
label.new(bar_index + extend, t3, "TP3 " + str.tostring(t3, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black, size=size.small)
sUsed := true
plotshape(bullRetest, title="BUY", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(bearRetest, title="SELL", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
Frequently asked questions
What is an Order Block?
It is the last candle contrary to the impulsive move that follows it: the zone where institutions placed orders before price moved with force. The indicator draws it as a box and waits for price to return to it.
What are the targets based on?
The three targets are Fibonacci extensions (1.618, 2.0 and 2.618) measured on the impulse that broke structure. They are projection levels, not promises: price may not reach them.
Does it work on any asset?
Yes. Because it is based on price structure and ATR, it works on Forex, indices, crypto or gold. We use it mostly on intraday XAUUSD, but you can adjust it.
Does it give buy/sell signals?
No. It marks contexts and levels according to the ICT methodology. It is an educational decision-support tool, not an investment recommendation or an automated signal.
Is it free?
Yes, the code is available to copy and download. You only need a TradingView account (the free plan is sufficient).
Exclusively educational content; does not constitute financial advice and does not guarantee results. Trading involves risk of capital loss.