PINE LIBRARY

DynamicPeriodPublic

Dynamic Period Calculation Library

This library provides tools for adaptive period determination, useful for creating indicators or strategies that automatically adjust to market conditions.

Overview
The Dynamic Period Library calculates adaptive periods based on pivot points, enabling the creation of responsive indicators and strategies that adjust to market volatility.

Key Features
  • Dynamic Periods: Computes periods using distances between pivot highs and lows.
  • Customizable Parameters: Users can adjust detection settings and period constraints.
  • Robust Handling: Includes fallback mechanisms for cases with insufficient pivot data.


Use Cases
  • Adaptive Indicators: Build tools that respond to market volatility by adjusting their periods dynamically.
  • Dynamic Strategies: Enhance trading strategies by integrating pivot-based period adjustments.


Function: `dynamic_period`

Description
Calculates a dynamic period based on the average distances between pivot highs and lows.

Parameters
  • `left` (default: 5): Number of left-hand bars for pivot detection.
  • `right` (default: 5): Number of right-hand bars for pivot detection.
  • `numPivots` (default: 5): Minimum pivots required for calculation.
  • `minPeriod` (default: 2): Minimum allowed period.
  • `maxPeriod` (default: 50): Maximum allowed period.
  • `defaultPeriod` (default: 14): Fallback period if no pivots are found.


Returns
A dynamic period calculated based on pivot distances, constrained by `minPeriod` and `maxPeriod`.

Example




Implementation Notes
  • Pivot Detection: Requires sufficient historical data to identify pivots accurately.
  • Edge Cases: Ensures a default period is applied when pivots are insufficient.
  • Constraints: Limits period values to a user-defined range for stability.
crimsonvaultPine utilitiesPivot points and levels

Libreria Pine

In pieno spirito TradingView, l'autore ha pubblicato questo codice Pine come libreria open-source in modo che altri programmatori Pine della nostra comunità possano riutilizzarlo. Un saluto all'autore! È possibile utilizzare questa libreria privatamente o in altre pubblicazioni open-source, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento.

Declinazione di responsabilità