PINE LIBRARY

Pivot Points. High & Lows By Reversal Percentage

1 252
Library "Pivot Points. High & Lows By Reversal Percentage" by Jal9000

This Pine Script library provides a robust function for identifying and tracking pivot points (reversal points) in price data, suitable for integration into custom trading indicators and strategies.

🛠️ Main Features:

- ✅ Identifies pivot highs and lows based on configurable price movement thresholds.
- ✅ Lightweight. No candle backtracing used. Much less computation heavy.
- ✅ Supports multiple calls (with different values) within a single script.
- ✅ Compatible with request.security for multi-timeframe analysis.
- ✅ Returns both confirmed and temporary pivots for flexible integration.
- ✅ Pinescript V5 and V6 compliant code.

Purpose:

The pivots library enables Pine Script developers to easily add pivot point detection to their scripts. It identifies significant price reversals by evaluating price movements against a minimum range threshold (min_range_pct) and confirming reversals based on a percentage (reversal_pct) of the prior trend’s magnitude. The library supports multiple simultaneous calls with different settings, making it ideal for multi-timeframe strategies.

How It Works:

The library’s f_calculatePivot function tracks price movements to detect pivot points:

  • Minimum Range Threshold: A potential pivot is considered if the price moves beyond the min_range_pct percentage of the current high (for a high pivot) or low (for a low pivot), ensuring sufficient movement.
  • Reversal Confirmation: A pivot is confirmed if the price reverses from the potential pivot by at least the reversal_pct percentage of the distance between the last confirmed pivot and the current potential pivot, measuring the retracement relative to the prior trend’s magnitude.
  • The function alternates between tracking highs (in an uptrend) and lows (in a downtrend), updating the trend when a pivot is confirmed.
  • State management uses an array of pivot_state objects, allowing independent calculations for different timeframes and min_range_pct values within the same script.


## Technical Reference

Functions:
Pine Script®

- Parameters:
  • _high: The high price series (e.g., high or math.max(open, close)).
  • _low: The low price series (e.g., low or math.min(open, close)).
  • _min_range_pct: The minimum percentage price movement to consider a potential pivot.
  • _reversal_pct: The percentage of the prior trend’s distance required to confirm a pivot.

- Returns:
A tuple containing:
  • isNewPivot: Boolean indicating if a new pivot was confirmed.
  • last_confirmed_pivot: The most recent confirmed pivot (type pivot).
  • temp_pivot: The current temporary pivot (type pivot).


Pivot type:
  • idx (series int): Bar index of the pivot.
  • typ (series int): Type of pivot (PIVOT_HIGH or PIVOT_LOW).
  • prc (series float): Price of the pivot.
  • tme (series int): Timestamp of the pivot.


Constants (internal):
  • TREND_LONG, TREND_SHORT: Trend direction indicators (1, -1).
  • PIVOT_HIGH, PIVOT_LOW: Pivot type indicators (1, -1).


Example of Use:
Pine Script®


## Release Notes
v1

- Initial release of the pivots library with f_calculatePivot function for detecting pivot points and supporting multiple configurations and timeframes.

v2
- Code is Pinescript V6 ready. Remains identified as V5, but changing the version number is the only thing that is required to be v6.

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。