OPEN-SOURCE SCRIPT

Swing High/Low (Adaptive)

316
Swing High/Low (Adaptive)

Overview

The Indicator is a pivot point detection tool that identifies swing highs and lows with invalidation tracking. The key differentiator of this indicator is its adaptive invalidation system. Most pivot indicators simply mark every detected pivot without considering whether subsequent price action has made earlier pivots less relevant.

How It Works

The indicator uses Pine Script's native ta.pivotlow() and ta.pivothigh() functions combined with custom logic to detect swing points. The adaptive algorithm evaluates each potential pivot against the following criteria:

For Low Pivots:
  • Confirms a new low pivot when it's the next expected pivot type in the swing sequence
  • If consecutive lows occur, only accepts a new low if it's lower than the previous low
  • Marks the previous low as invalidated when a stronger low is detected


For High Pivots:
  • Confirms a new high pivot when it's the next expected pivot type in the swing sequence
  • If consecutive highs occur, only accepts a new high if it's higher than the previous high
  • Marks the previous high as invalidated when a stronger high is detected


This approach ensures that the indicator maintains clean swing structure and automatically adjusts when price action creates stronger pivots, providing a more realistic view of support and resistance levels.

Settings

Pivot Settings:
  • Left Bars: Number of bars to the left required for pivot confirmation (default: 5)
  • Right Bars: Number of bars to the right required for pivot confirmation (default: 5)


Pivot Display Settings:
  • Toggle visibility for low and high pivots independently
  • Customizable colors for valid pivot markers
  • Low pivots marked with upward triangle (▲)
  • High pivots marked with downward triangle (▼)


Invalid Pivot Settings:
  • Optional display of invalidated pivots
  • Separate color customization for invalid low and high pivots
  • Helps visualize where market structure expectations changed


ZigZag Settings:
  • Toggle ZigZag line display on/off
  • Separate colors for upward and downward price swings
  • Adjustable line width


Use Cases

1. Market Structure Analysis
Identify key swing points to understand the current market structure and trend direction. The adaptive invalidation feature ensures you're always looking at the most relevant pivots.

2. Support and Resistance Identification
Use confirmed swing highs and lows as potential support and resistance levels for entry and exit planning.

3. Trend Confirmation
The ZigZag visualization helps confirm trends by showing the sequence of higher highs and higher lows (uptrend) or lower highs and lower lows (downtrend).

Disclaimer

This indicator is designed as a technical analysis tool and should be used in conjunction with other forms of analysis and proper risk management. Past performance does not guarantee future results, and traders should thoroughly test any strategy before implementing it with real capital.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.