This advanced TradingView Pine Script indicator dynamically detects and draws support and resistance trendlines based on historical pivot points while also checking for multiple test touches. Here’s a detailed summary of its functionality:
Customizable Trendline Detection:
Historical Analysis: Users specify the number of historical bars to examine for identifying pivot points, enabling a deep scan for reliable support and resistance levels. Pivot Lookback Settings: The primary pivot lookback period (x1) is user-defined, with a secondary period (x2) calculated as half of x1, allowing the indicator to capture both local lows and highs accurately. Dynamic Trendline Construction and Multiple Test Validation:
Iterative Pivot Pairing: The script uses nested loops to identify pairs of pivot points (lows for support, highs for resistance) and calculates an interpolated price along the line connecting these pivots. Testing and Updating Trendlines: The indicator continuously checks whether the price respects the drawn trendlines. It verifies if the trendlines have been tested multiple times by iterating through historical bars, ensuring that the level holds up under repeated tests. When a level is retested, the trendline is updated and a test counter is incremented, thereby reinforcing the significance of the support or resistance level. Visual Customization Options:
Line Appearance: Users can tailor the trendlines with customizable thickness, dash patterns (solid, dotted, or dashed), and specific colors for support and resistance lines. Label Settings: Labels display the precise price levels (and optionally the number of tests), with configurable sizes and styles, offering clear visual cues on the chart. Alerting and Confirmation Mechanisms:
Breakout Alerts: The script triggers alerts when the price action breaches a trendline. It differentiates between standard alerts and those that are volume-confirmed—where the volume exceeds a set multiple of the average—thus minimizing false signals. RSI-Based Bar Coloring: When enabled, the Relative Strength Index (RSI) is computed, and bars at trendline test points are color-coded (dark red for overbought and dark green for oversold conditions), providing immediate visual feedback on market momentum. Supporting Analytical Tools:
Pivot Labels: The indicator can display pivot labels using built-in functions, marking key pivot highs and lows with their corresponding price values. Moving Averages: Two customizable moving averages (fast and slow) can be plotted (using either SMA or EMA), helping to contextualize the trendlines within the broader market trend. Efficient Object Management:
Array-Based Storage and Cleanup: Arrays are used to store drawn objects (lines and labels), and a cleanup routine ensures that outdated objects are removed with every new bar, keeping the chart clutter-free.
Helper Functions: Utility functions such as price_at for interpolating prices along the trendline and round_to_tick for rounding values enhance the script’s precision and usability.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
For quick access on a chart, add this script to your favorites — learn more here.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
For quick access on a chart, add this script to your favorites — learn more here.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.