OPEN-SOURCE SCRIPT
已更新 Golden Pockets

Identify high-probability bounce zones using the 0.618 Fibonacci retracement.
When price touches a golden pocket level, it is expected to react and reverse, making these levels ideal for entries or exits.
This indicator automatically detects swing highs and lows using a 5-bar pivot and plots a golden pocket each time a new structure forms:
Levels recalculate if the swing extends further and are removed the moment price closes through them, keeping only valid, untested zones on the chart.
Features
Settings
When price touches a golden pocket level, it is expected to react and reverse, making these levels ideal for entries or exits.
This indicator automatically detects swing highs and lows using a 5-bar pivot and plots a golden pocket each time a new structure forms:
- Bullish GP forms on a higher-high. The 0.618 of the swing low to high is plotted as a support level where price is expected to bounce upward.
- Bearish GP forms on a lower-low. The 0.618 of the swing high to low is plotted as a resistance level where price is expected to reject downward.
Levels recalculate if the swing extends further and are removed the moment price closes through them, keeping only valid, untested zones on the chart.
Features
- Levels recalculate in real time if the swing extends to a new extreme
- Levels are removed automatically when price closes through them
- Levels with more history behind them are shown at full opacity — newer, closer levels are dimmed to reflect lower reliability
- An optional swing trace shows the range used to calculate each level
- Built-in alerts notify you when price reaches a golden pocket
Settings
- Show controls how many levels are visible per side (set to 0 to disable)
- Color, Style, Width customize the appearance of bullish and bearish lines independently
- Show the trace toggles the dashed swing line on or off
- Enable alerts activates the built-in alert conditions
版本注释
- Changed MAX_DIM to 50- Changed bufferSize to 10
- Made code formatting consistent
版本注释
- Rewrote internals using a user-defined type (GpLevel) replacing 10 parallel arrays with 2 typed arrays
- Unified all bull/bear logic into shared functions (createGp, updateGp, removeGp, capGp, rankLevels, checkAlerts, findConsolExtreme)
- Replaced magic number line extensions (+200, +20) with extend.right for cleaner level drawing
- Fixed alerts: removed redundant "Enable alerts" toggle — alerts now fire correctly via TradingView's native alert system
- Alerts now only trigger for visible levels (matching what's shown on chart)
- Fixed float comparison for anchor deduplication using epsilon tolerance (syminfo.mintick)
- Buffer size is now decoupled from display count — levels persist in a fixed buffer so visible levels aren't prematurely evicted
- Display count (Show) maxval is now derived from a single BUFFER_SIZE constant
- Skipped GP creation entirely when Show is set to 0
- Renamed variables for clarity: showSwing → showTrace, swingLine → traceLine, slDet → isSwingLow, shDet → isSwingHigh
- Adopted Pine Script v6 method syntax throughout (.get(), .push(), .delete(), .set_y1(), etc.)
- Extracted consolidation scan into findConsolExtreme, eliminating duplicated lookback logic
- Defined named constants for fib ratio, max fade, lookback limit, and buffer size
版本注释
- Swing detection changed from manual strict 5-bar checks to ta.pivotlow/ta.pivothigh (2,2)
- Safer delete logic for optional trace lines (na-check before delete)
- Style mapping refactor to switch-based line-style resolver
- Consolidation extreme seed now uses dynamic back index
- Removed epsilonEq helper; anchor dedupe now uses direct equality
- Selection/ranking internals switched to visited-array tracking
- Alert scan adds early-exit once hit is found
版本注释
New- "Use closes instead of wicks" option: builds swings and anchors from closing prices, matching the line chart. Off by default, candle behavior is unchanged.
- Up to 20 golden pockets per side can now be tracked (previously 9), so older large-structure levels are no longer pushed out.
Fixed
- Potential runtime error when a structure reached close to 10,000 bars back.
- Levels silently disappearing when many pockets were active, due to the chart's default drawing limit.
- Potential "historical offset" runtime error on charts with very deep history.
- Exact anchor selection around double bottoms and double tops with equal extremes.
Changed
- Cleaner alerts: a pocket broken by a close through it no longer fires a "hit" alert on the breaking bar. Alerts only signal touches of still-valid levels.
Under the hood
- Fully modernized to Pine Script v6: enums, user-defined types and methods, native index sorting, official style-guide formatting. About 15% smaller with the core logic unchanged.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。