OPEN-SOURCE SCRIPT
Confirmed Fibonacci with Market Structure

Confirmed Fibonacci with Market Structure
-Description
A Fibonacci retracement tool for trend-continuation setups. It draws only after price has confirmed a directional move through market structure, then locks the levels in place so the pullback zone stays where it was set.
-What it does
The script applies three conditions before it draws a retracement, and once it draws, the anchors are fixed until the setup is invalidated:
- it requires a break of structure, not just any swing;
- it requires the impulse to be large enough relative to recent volatility;
- it can require agreement from the higher timeframe.
The result is a small number of retracements, drawn on moves that have shifted structure, that stay in place once set.
-How the detection works
1. Swing pivots. The script identifies swing highs and lows using pivot detection — a bar is a pivot high when it is the highest over a set number of bars to its left and right (the Pivot length input), and the reverse for a pivot low. These pivots define the prior swing and the structural reference levels.
2. Break of structure. For a bullish leg, the script takes the most recent prior swing low as the origin, then looks for an impulse high that trades above the last swing high formed before that low. Trading above that prior high is the break of structure — confirmation that buyers have shifted structure upward. The bearish case is the mirror image (a swing high origin, and an impulse low that breaks the prior swing low).
3. Displacement filter. The impulse is only accepted if its size (impulse high minus origin low) is at least a chosen multiple of ATR(14) — the Min displacement (ATR) input. Normalising to ATR judges a move on a quiet instrument and a volatile one on the same scale, and filters out small, insignificant structural breaks.
4. Draw timing. In Fast Draw mode the leg confirms on an asymmetric impulse pivot (fewer bars required to the right of the extreme), so the fib appears sooner after the high or low. With Fast Draw off, it instead waits for a completed pullback pivot before drawing — slower, but it only commits once a retracement is already underway.
-The Fibonacci leg and golden zone
When a bullish leg confirms, 0.0 is placed at the impulse high and 1.0 at the origin low, so the retracement levels measure how far price pulls back into the move (bearish legs are inverted). The shaded 0.618–0.786 band is the golden zone — the area where trend-continuation pullbacks commonly find support or resistance. A dashed line marks the broken structure level (BOS), and the impulse leg is labelled at its anchors (HH/HL for a bull leg, LH/LL for a bear leg).
-Higher-timeframe bias
The optional bias filter reads swing structure from the next standard timeframe up (for example, a 1-hour chart reads the 4-hour). That timeframe is rated bullish when its recent structure prints higher highs and higher lows, and bearish on lower highs and lower lows. With the filter on, the script only draws bullish legs in a bullish higher-timeframe context and bearish legs in a bearish one, and it clears the active leg if the higher timeframe flips against it. The request uses confirmed values with no lookahead.
-Invalidation and refresh
A bullish leg is invalidated when price closes below its origin low, with a small ATR buffer to absorb wicks; bearish legs mirror this. A leg is also cleared if it goes stale — when no new structure forms within a configurable number of bars. Until one of those happens, the anchors stay locked, so the levels on your chart are the same ones set when the leg confirmed.
-How to use it
This tool is built for trending markets and continuation trading, not ranges. The premise is simple: after a structure break and a displaced impulse, a trend often pauses and retraces before continuing in the same direction, and the golden zone is where that retracement commonly runs out of steam.
- Trade with the leg, into the pullback. On a confirmed bullish leg, treat the 0.618–0.786 golden zone as a pullback entry zone for longs — you are looking to join the move as price retraces into it, not to fade it. On a bearish leg, the same zone is where you look for shorts as price pulls back up into it.
- Use the higher-timeframe filter for alignment. Leaving HTF Bias on keeps you taking pullbacks in the direction of the larger trend, which is the context where continuation setups tend to hold up best. Turning it off shows every confirmed leg regardless of the bigger picture.
- Anchor risk to the structure the tool already marks. The origin (the 1.0 level, where the leg began) is the natural invalidation — a close back through it means the continuation idea has failed, which is also when the script clears the leg. Targets are typically toward the impulse extreme or beyond it. The BOS line shows the level whose break confirmed the move.
- Read the zone, don't blindly buy or sell it. The golden zone is an area of interest, not a trigger. Wait for your own confirmation inside it — a reaction candle, a lower-timeframe shift in structure, or whatever you normally use — before committing.
- The golden zone isn't the only level worth watching. Shallower retracements such as the 0.382 or the 0.500 often hold in strong trends that don't pull back far, while the deeper 0.618–0.786 zone tends to come into play on bigger retracements. Different instruments and timeframes react at different levels, so test which ones your pairs respect and toggle the levels you don't use off to keep the chart clean.
- Filter the chop. In ranging or low-momentum conditions a structure break is more likely to fail. Raise Min displacement (ATR) so the tool only draws on decisive moves, and set Pivot length to suit the timeframe (suggested starting points are in each input's tooltip).
-Inputs
-Structure
- Fast Draw (default on). On, the retracement is drawn as soon as the impulse, break of structure and displacement all confirm — the earliest possible draw. Off, it waits for a completed pullback pivot before drawing, which is slower but only commits once a retracement is already under way. Turning it off gives later but more conservative entries.
- Pivot length (default 8). Bars to the left and right used to confirm the structural swing highs and lows that define the prior swing and the break-of-structure reference. Higher values track larger, slower swings and draw fewer legs; lower values react to smaller swings and draw more. Rough starting points: 18 on 15m, 8 on 1h, 4 on 4h, 3 on daily.
- Impulse pivot R (default 3, Fast Draw only). The number of bars required to the right of the impulse extreme before it is accepted. Lower confirms the leg sooner after the high or low; higher waits for more confirmation, so the leg draws later but the extreme is more settled.
- Pullback pivot length (default 2, used only when Fast Draw is off). Bars left and right for the pullback pivot the script waits on before drawing. Lower draws faster on shallower pullbacks; higher requires a deeper, more developed pullback first.
- Min displacement (ATR) (default 1.5). The minimum impulse size, measured in ATR(14) units, before a structure break counts. Raising it ignores small moves and only draws on decisive ones; lowering it draws on smaller breaks too. As a guide: 0 accepts any impulse, 1.0 is modest, 1.5 is meaningful, 2.5 and up captures only major moves.
- Invalidation buffer (ATR) (default 0.25). A tolerance, in ATR(14) units, added beyond the origin before the leg is invalidated, so a single wick through the level doesn't cancel the setup. Higher gives the trade more room before it's cleared; lower invalidates more strictly.
- Max leg age (bars) (default 150). If no new structure forms within this many bars, the leg is treated as stale and cleared. Lower keeps only fresh setups on the chart; higher lets a quiet leg persist longer.
- Pivots retained (default 15). How many recent pivots the script keeps in memory to look back through when building a sequence. Higher allows it to reference older swings; lower keeps it focused on the most recent structure. Mostly affects edge cases — the default suits most charts.
HTF Bias
- Use HTF bias filter (default on). When on, the script only draws legs that agree with the higher-timeframe trend and clears a leg if that timeframe flips against it. Turning it off shows every confirmed leg regardless of the larger trend.
- HTF pivot length (default 3). Bars left and right used to read swing structure on the higher timeframe. Higher reads a broader, slower higher-timeframe trend; lower makes the bias more responsive.
Fib Levels
- 0.000 to 1.000 toggles. Switch each standard retracement level on or off independently, so you can show only the ones you trade.
- Custom level (default off, 0.75). Enables one extra level at a ratio you choose, with its own colour — useful for a level such as 0.705 or 0.79 that sits outside the standard set. Drawn alongside the standard levels.
Visual
- Colour Theme (default "Default"). Sets the dashboard colours and the fib line colour. Ten themes are included; purely cosmetic.
- 0.500 line color, Golden zone fill, Golden zone edge, Impulse line color, BOS line/label color. Individual colour controls for those specific elements, so you can tune contrast against your chart.
- Show BOS line + label (default on). Draws the dashed line at the broken structure level with a "BOS" tag. Off hides it for a cleaner chart.
- Show impulse line (default on). Draws the dashed line connecting the two anchors of the leg.
- Extend right (default on). Extends the level lines to the right of the current bar so they project forward; off ends them at the current bar.
- Price labels (default on). Shows the price value beside each level.
- Anchor markers (default on). Labels the two anchor points (HH/HL or LH/LL) of the leg.
- Info panel (default on). Shows the dashboard with structure state, higher-timeframe bias, anchor prices and how long ago the impulse confirmed.
Alerts
- Alert on new fib drawn (default on). Fires when a new bullish or bearish leg is drawn.
- Alert on Golden Zone touch (default on). Fires the first time price touches the golden zone of the active leg.
**Notes**
Swing pivots confirm a fixed number of bars after the actual high or low, so a leg appears after that confirmation delay rather than at the exact extreme — this is inherent to pivot-based detection. Once drawn, anchors are locked and do not move. The higher-timeframe bias uses confirmed values without lookahead, so it does not repaint on historical bars, though like any higher-timeframe data it can update within a forming higher-timeframe bar in real time. These levels are decision support, not buy or sell signals.
**Disclaimer**
This indicator is for educational and informational purposes only and is not financial or investment advice. Past performance does not guarantee future results. Always do your own analysis and manage your own risk.
-Description
A Fibonacci retracement tool for trend-continuation setups. It draws only after price has confirmed a directional move through market structure, then locks the levels in place so the pullback zone stays where it was set.
-What it does
The script applies three conditions before it draws a retracement, and once it draws, the anchors are fixed until the setup is invalidated:
- it requires a break of structure, not just any swing;
- it requires the impulse to be large enough relative to recent volatility;
- it can require agreement from the higher timeframe.
The result is a small number of retracements, drawn on moves that have shifted structure, that stay in place once set.
-How the detection works
1. Swing pivots. The script identifies swing highs and lows using pivot detection — a bar is a pivot high when it is the highest over a set number of bars to its left and right (the Pivot length input), and the reverse for a pivot low. These pivots define the prior swing and the structural reference levels.
2. Break of structure. For a bullish leg, the script takes the most recent prior swing low as the origin, then looks for an impulse high that trades above the last swing high formed before that low. Trading above that prior high is the break of structure — confirmation that buyers have shifted structure upward. The bearish case is the mirror image (a swing high origin, and an impulse low that breaks the prior swing low).
3. Displacement filter. The impulse is only accepted if its size (impulse high minus origin low) is at least a chosen multiple of ATR(14) — the Min displacement (ATR) input. Normalising to ATR judges a move on a quiet instrument and a volatile one on the same scale, and filters out small, insignificant structural breaks.
4. Draw timing. In Fast Draw mode the leg confirms on an asymmetric impulse pivot (fewer bars required to the right of the extreme), so the fib appears sooner after the high or low. With Fast Draw off, it instead waits for a completed pullback pivot before drawing — slower, but it only commits once a retracement is already underway.
-The Fibonacci leg and golden zone
When a bullish leg confirms, 0.0 is placed at the impulse high and 1.0 at the origin low, so the retracement levels measure how far price pulls back into the move (bearish legs are inverted). The shaded 0.618–0.786 band is the golden zone — the area where trend-continuation pullbacks commonly find support or resistance. A dashed line marks the broken structure level (BOS), and the impulse leg is labelled at its anchors (HH/HL for a bull leg, LH/LL for a bear leg).
-Higher-timeframe bias
The optional bias filter reads swing structure from the next standard timeframe up (for example, a 1-hour chart reads the 4-hour). That timeframe is rated bullish when its recent structure prints higher highs and higher lows, and bearish on lower highs and lower lows. With the filter on, the script only draws bullish legs in a bullish higher-timeframe context and bearish legs in a bearish one, and it clears the active leg if the higher timeframe flips against it. The request uses confirmed values with no lookahead.
-Invalidation and refresh
A bullish leg is invalidated when price closes below its origin low, with a small ATR buffer to absorb wicks; bearish legs mirror this. A leg is also cleared if it goes stale — when no new structure forms within a configurable number of bars. Until one of those happens, the anchors stay locked, so the levels on your chart are the same ones set when the leg confirmed.
-How to use it
This tool is built for trending markets and continuation trading, not ranges. The premise is simple: after a structure break and a displaced impulse, a trend often pauses and retraces before continuing in the same direction, and the golden zone is where that retracement commonly runs out of steam.
- Trade with the leg, into the pullback. On a confirmed bullish leg, treat the 0.618–0.786 golden zone as a pullback entry zone for longs — you are looking to join the move as price retraces into it, not to fade it. On a bearish leg, the same zone is where you look for shorts as price pulls back up into it.
- Use the higher-timeframe filter for alignment. Leaving HTF Bias on keeps you taking pullbacks in the direction of the larger trend, which is the context where continuation setups tend to hold up best. Turning it off shows every confirmed leg regardless of the bigger picture.
- Anchor risk to the structure the tool already marks. The origin (the 1.0 level, where the leg began) is the natural invalidation — a close back through it means the continuation idea has failed, which is also when the script clears the leg. Targets are typically toward the impulse extreme or beyond it. The BOS line shows the level whose break confirmed the move.
- Read the zone, don't blindly buy or sell it. The golden zone is an area of interest, not a trigger. Wait for your own confirmation inside it — a reaction candle, a lower-timeframe shift in structure, or whatever you normally use — before committing.
- The golden zone isn't the only level worth watching. Shallower retracements such as the 0.382 or the 0.500 often hold in strong trends that don't pull back far, while the deeper 0.618–0.786 zone tends to come into play on bigger retracements. Different instruments and timeframes react at different levels, so test which ones your pairs respect and toggle the levels you don't use off to keep the chart clean.
- Filter the chop. In ranging or low-momentum conditions a structure break is more likely to fail. Raise Min displacement (ATR) so the tool only draws on decisive moves, and set Pivot length to suit the timeframe (suggested starting points are in each input's tooltip).
-Inputs
-Structure
- Fast Draw (default on). On, the retracement is drawn as soon as the impulse, break of structure and displacement all confirm — the earliest possible draw. Off, it waits for a completed pullback pivot before drawing, which is slower but only commits once a retracement is already under way. Turning it off gives later but more conservative entries.
- Pivot length (default 8). Bars to the left and right used to confirm the structural swing highs and lows that define the prior swing and the break-of-structure reference. Higher values track larger, slower swings and draw fewer legs; lower values react to smaller swings and draw more. Rough starting points: 18 on 15m, 8 on 1h, 4 on 4h, 3 on daily.
- Impulse pivot R (default 3, Fast Draw only). The number of bars required to the right of the impulse extreme before it is accepted. Lower confirms the leg sooner after the high or low; higher waits for more confirmation, so the leg draws later but the extreme is more settled.
- Pullback pivot length (default 2, used only when Fast Draw is off). Bars left and right for the pullback pivot the script waits on before drawing. Lower draws faster on shallower pullbacks; higher requires a deeper, more developed pullback first.
- Min displacement (ATR) (default 1.5). The minimum impulse size, measured in ATR(14) units, before a structure break counts. Raising it ignores small moves and only draws on decisive ones; lowering it draws on smaller breaks too. As a guide: 0 accepts any impulse, 1.0 is modest, 1.5 is meaningful, 2.5 and up captures only major moves.
- Invalidation buffer (ATR) (default 0.25). A tolerance, in ATR(14) units, added beyond the origin before the leg is invalidated, so a single wick through the level doesn't cancel the setup. Higher gives the trade more room before it's cleared; lower invalidates more strictly.
- Max leg age (bars) (default 150). If no new structure forms within this many bars, the leg is treated as stale and cleared. Lower keeps only fresh setups on the chart; higher lets a quiet leg persist longer.
- Pivots retained (default 15). How many recent pivots the script keeps in memory to look back through when building a sequence. Higher allows it to reference older swings; lower keeps it focused on the most recent structure. Mostly affects edge cases — the default suits most charts.
HTF Bias
- Use HTF bias filter (default on). When on, the script only draws legs that agree with the higher-timeframe trend and clears a leg if that timeframe flips against it. Turning it off shows every confirmed leg regardless of the larger trend.
- HTF pivot length (default 3). Bars left and right used to read swing structure on the higher timeframe. Higher reads a broader, slower higher-timeframe trend; lower makes the bias more responsive.
Fib Levels
- 0.000 to 1.000 toggles. Switch each standard retracement level on or off independently, so you can show only the ones you trade.
- Custom level (default off, 0.75). Enables one extra level at a ratio you choose, with its own colour — useful for a level such as 0.705 or 0.79 that sits outside the standard set. Drawn alongside the standard levels.
Visual
- Colour Theme (default "Default"). Sets the dashboard colours and the fib line colour. Ten themes are included; purely cosmetic.
- 0.500 line color, Golden zone fill, Golden zone edge, Impulse line color, BOS line/label color. Individual colour controls for those specific elements, so you can tune contrast against your chart.
- Show BOS line + label (default on). Draws the dashed line at the broken structure level with a "BOS" tag. Off hides it for a cleaner chart.
- Show impulse line (default on). Draws the dashed line connecting the two anchors of the leg.
- Extend right (default on). Extends the level lines to the right of the current bar so they project forward; off ends them at the current bar.
- Price labels (default on). Shows the price value beside each level.
- Anchor markers (default on). Labels the two anchor points (HH/HL or LH/LL) of the leg.
- Info panel (default on). Shows the dashboard with structure state, higher-timeframe bias, anchor prices and how long ago the impulse confirmed.
Alerts
- Alert on new fib drawn (default on). Fires when a new bullish or bearish leg is drawn.
- Alert on Golden Zone touch (default on). Fires the first time price touches the golden zone of the active leg.
**Notes**
Swing pivots confirm a fixed number of bars after the actual high or low, so a leg appears after that confirmation delay rather than at the exact extreme — this is inherent to pivot-based detection. Once drawn, anchors are locked and do not move. The higher-timeframe bias uses confirmed values without lookahead, so it does not repaint on historical bars, though like any higher-timeframe data it can update within a forming higher-timeframe bar in real time. These levels are decision support, not buy or sell signals.
**Disclaimer**
This indicator is for educational and informational purposes only and is not financial or investment advice. Past performance does not guarantee future results. Always do your own analysis and manage your own risk.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน