OPEN-SOURCE SCRIPT

TopBot [CHE]

117
TopBot [CHE] — Structure pivots with buffered acceptance and gradient trend visualization

Summary

TopBot detects swing structure from confirmed pivot highs and lows, derives support and resistance levels, and switches trend only after a buffered and accepted break. It renders labels for recent structure points, maintains dynamic support and resistance lines that freeze on contact, and colors candles using a gradient that reflects consecutive trend persistence. The gradient communicates strength without extra panels, while the buffered acceptance reduces fragile flips around key levels. Everything runs in the main chart for immediate context.

Motivation: Why this design?

Classical swing tools often flip on single-bar spikes and produce lines that extend forever without acknowledging when price invalidates them. This script addresses that by requiring a user-controlled buffer and a run of consecutive closes before changing trend, while also freezing lines once price interacts with them. The gradient color layer communicates regime persistence so users can quickly judge whether a move is maturing or just starting.

What’s different vs. standard approaches?

Baseline reference: Simple pivot labeling and unbuffered break-of-structure tools.
Architecture differences:

Buffered level testing using ticks, percent, or ATR.
Acceptance logic that requires multiple consecutive closes.
Synchronized structure labeling with a single Top and Bottom within the active set.
Progressive support and resistance management that freezes lines on first contact.
Gradient candle and wick coloring driven by consecutive trend counts with windowed normalization and gamma control.
Practical effect: Fewer whipsaw flips, clearer status of active levels, and visual feedback about trend persistence without a secondary pane.

How it works (technical)

The script confirms swing points using left and right bar pivots, then forms a current structure window to classify each pivot as higher high, lower high, higher low, or lower low. Recent labels are trimmed to a user cap, and a postprocess step ensures one highest and one lowest label while preserving side information for the others. Support updates on higher low events, resistance on lower high events. Trend flips only after the close has moved beyond the active level by a chosen buffer and this condition holds for a chosen number of consecutive bars. Lines for new levels extend to the right and freeze once price touches them. A running count of consecutive trend bars produces a strength score, which is normalized over a rolling window, shaped by gamma, and mapped to user-defined dark and neon colors for both up and down regimes. Wick coloring uses `plotcandle`; fallback bar coloring uses `barcolor`. No higher-timeframe data is requested. Signals confirm only after the right-bar lookback of the pivot function.

Parameter Guide

Left Bars / Right Bars (default five each): Pivot sensitivity. Larger values confirm later and reduce noise; smaller values respond faster with more noise.
Draw S/R Lines (default true): Enables support and resistance line creation and updates.
Support / Resistance Colors (lime, red): Line colors for each side.
Line Style (Solid, Dashed, Dotted; default Dotted) and Width (default three): Visual style of S/R lines.
Max Labels & Lines (default ten): Cap for objects to control clutter and resource usage.
Change Bar Color (default true), Up/Down colors (blue, black): Fallback bar coloring when gradients or wick coloring are disabled.
Show Neutral Candles (default false): Optional coloring when no trend is active.
Enable Gradient Bar Colors (default true): Turns on gradient body coloring from the strength score.
Enable Wick Coloring (default true): Colors wicks and borders using `plotcandle`.
Collection Period (default one hundred): Rolling window used to scale the strength score. Shorter windows react faster but vary more.
Gamma Bars / Gamma Plots (defaults zero point seven and zero point eight): Shapes perceived contrast of bar and wick gradients. Lower values brighten early; higher values compress until stronger runs appear.
Gradient Transparency / Wick Transparency (default zero): Visual transparency for bodies and wicks.
Up/Down Trend Dark and Neon Colors: Endpoints for gradient mapping in each regime.
Acceptance closes (n) (default two): Number of consecutive closes beyond a level required before trend flips. Larger values reduce false breaks but react later.
Break buffer (None, Ticks, Percent, ATR; default ATR) and Value (default zero point five) and ATR Len (default fourteen): Defines the safety margin beyond the level. ATR mode adapts to volatility; Percent and Ticks are static.

Reading & Interpretation

Labels: “Top” and “Bottom” mark the most extreme points in the active set; “LT” and “HB” indicate side labels for lower top and higher bottom.
Lines: New support or resistance is drawn when structure confirms. A line freezes once price touches it, signaling that the dynamic phase ended.
Trend: Internal state switches to up or down only after buffered acceptance.
Colors: Brighter neon tones indicate stronger and more persistent runs; darker tones suggest early or weakening runs. When gradients are off, fallback bar colors indicate trend sign.

Practical Workflows & Combinations

Trend following: Wait for a buffered and accepted break through the most recent level, then use gradient intensity to stage entries or scale-ins.
Structure-first filtering: Trade only in the direction of the last accepted trend while price remains above support or below resistance.
Exits and stops: Consider exiting on loss of gradient intensity combined with a return through the most recent structure level.
Multi-asset / Multi-timeframe: Works on liquid symbols across common timeframes. Use larger pivot bars and higher acceptance on lower timeframes. No built-in higher-timeframe aggregation is used.

Behavior, Constraints & Performance

Repaint/confirmation: Pivot confirmation waits for the right bar window; trend acceptance is based on closes and can change during a live bar. Final signals stabilize on bar close.
security/HTF: Not used. No cross-timeframe data.
Resources: Arrays and loops are used for labels, lines, and structure search up to a capped historical span. Object counts are clamped by user input and platform limits.
Known limits: Delayed confirmation at sharp turns due to pivot windows; rapid gaps can jump over buffers; gradient scaling depends on the chosen collection period.

Sensible Defaults & Quick Tuning

Start with the defaults: pivot windows at five, ATR buffer with value near one half, acceptance at two, collection period near one hundred, gamma near zero point seven to zero point eight.

Too many flips: increase acceptance, increase buffer value, or increase pivot windows.
Too sluggish: reduce acceptance, reduce buffer value, or reduce pivot windows.
Colors too flat: lower gamma or shorten the collection period.
Visual clutter: reduce the max labels and lines cap or disable wicks.

What this indicator is—and isn’t

This is a visualization and signal layer that encodes swing structure, level state, and regime persistence. It is not a complete trading system, not predictive, and does not manage orders. Use it with broader context such as higher timeframe structure, session behavior, and defined risk controls.

Disclaimer

The content provided, including all code and materials, is strictly for educational and informational purposes only. It is not intended as, and should not be interpreted as, financial advice, a recommendation to buy or sell any financial instrument, or an offer of any financial product or service. All strategies, tools, and examples discussed are provided for illustrative purposes to demonstrate coding techniques and the functionality of Pine Script within a trading context.

Any results from strategies or tools provided are hypothetical, and past performance is not indicative of future results. Trading and investing involve high risk, including the potential loss of principal, and may not be suitable for all individuals. Before making any trading decisions, please consult with a qualified financial professional to understand the risks involved.

By using this script, you acknowledge and agree that any trading decisions are made solely at your discretion and risk.

Do not use this indicator on Heikin-Ashi, Renko, Kagi, Point-and-Figure, or Range charts, as these chart types can produce unrealistic results for signal markers and alerts.

Best regards and happy trading

Chervolino


Acknowledgment
Thanks to LonesomeTheBlue for the fantastic and inspiring "Higher High Lower Low Strategy"
.
Original script:
Higher High Lower Low Strategy (With Source Code)

Credit for the original concept and implementation goes to the author; any adaptations or errors here are mine.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.