Home » Technical Analysis Functions » Understanding ta.pivot_point_levels() Function in Pine Script

Understanding ta.pivot_point_levels() Function in Pine Script

Photo of author
Published on

Pine Script offers built-in functions that enable traders and analysts to create complex tools for market analysis. One such function is ta.pivot_point_levels(), designed to calculate pivot point levels using various methodologies. Let’s dive into the details of this function, including its syntax, arguments, and how to effectively use it in your scripts.


The ta.pivot_point_levels() function is defined as follows:

ta.pivot_point_levels(type, anchor, developing) → array<float>

This function returns an array of floating-point numbers, each representing a pivot point level calculated based on the parameters provided.


  • type (series string): Specifies the type of pivot point levels to calculate. It accepts values such as “Traditional”, “Fibonacci”, “Woodie”, “Classic”, “DM”, “Camarilla”. This parameter determines the calculation methodology for the pivot points.
  • anchor (series bool): This boolean series triggers the reset of the pivot point calculations. When true, the calculations reset; when false, the results calculated at the last reset are maintained.
  • developing (series bool): An optional parameter that, when set to false (default), keeps the pivot point values constant until the anchor condition is met again. If set to true, the pivot points are recalculated constantly with each new bar between the last anchor reset and the current bar.


Let’s consider an example to illustrate how to implement ta.pivot_point_levels() in a script:

indicator("Weekly Pivots", max_lines_count=500, overlay=true)
timeFrame = "1W"
pivotType = input.string("Traditional", "Type", options=["Traditional", "Fibonacci", "Woodie", "Classic", "DM", "Camarilla"])
isWeekChange = timeframe.change(timeFrame)
pivotLevels = ta.pivot_point_levels(pivotType, isWeekChange)
if isWeekChange
    for level in pivotLevels
        line.new(time, level, time + timeframe.in_seconds(timeFrame) * 1000, level, xloc=xloc.bar_time)

In this example, we create an indicator called “Weekly Pivots” that draws pivot point levels on a weekly basis. The type of pivot points (Traditional, Fibonacci, etc.) can be selected through the script’s input options. The pivot points are recalculated and drawn each week, as determined by the isWeekChange condition.

Code Walkthrough

  1. Indicator Definition: The indicator function declares a new indicator called “Weekly Pivots” with a maximum of 500 lines allowed on the chart (max_lines_count=500) and specifies that it will be drawn over the chart (overlay=true).
  2. Time Frame Setting: The variable timeFrame is set to “1W”, indicating that the pivot points will be calculated based on weekly data.
  3. Pivot Type Selection: The input.string function creates a dropdown menu in the indicator settings for selecting the type of pivot point calculation. The default method is “Traditional”, but users can also choose from “Fibonacci”, “Woodie”, “Classic”, “DM”, and “Camarilla”.
  4. Week Change Detection: The isWeekChange variable uses the timeframe.change function to detect when a new week starts based on the specified timeFrame. This function returns true at the start of a new week, triggering the calculation and plotting of new pivot points.
  5. Pivot Point Calculation: The ta.pivot_point_levels function calculates the pivot levels (support and resistance) based on the selected pivot type and whether a new week has begun (isWeekChange). This function returns a list of pivot levels to be plotted.
  6. Conditional Plotting: The if isWeekChange condition checks if there’s a change to a new week. If true, it proceeds to plot the pivot levels.
  7. Plotting Pivot Levels: Inside the if condition, a for loop iterates over the pivotLevels list. For each level in the list, a horizontal line is drawn using line.new. The line starts at the current bar’s time (time) and extends to the end of the week (time + timeframe.in_seconds(timeFrame) * 1000). The xloc.bar_time parameter ensures that the line is positioned based on the bar’s timestamp.
  8. Line Parameters: In the line.new function, the first two parameters specify the starting point of the line (both time and price level), the next two parameters define the ending point, and the final parameter (xloc) specifies that the x-location is based on the bar’s timestamp.

Key Features and Takeaways

  • The ta.pivot_point_levels() function is versatile, supporting multiple methodologies for calculating pivot points.
  • It allows for dynamic pivot point calculation with the developing parameter, adapting to real-time market movements.
  • The function’s flexibility in handling weekly resets (or any other timeframe) makes it a powerful tool for time-based pivot point analysis.
  • Users must be mindful of the restrictions with certain pivot types, especially the “Woodie” type, to avoid runtime errors.

By incorporating ta.pivot_point_levels() into your Pine Script tools, you can enhance your market analysis with dynamic and adaptable pivot point calculations, tailored to your specific trading strategy and analysis needs.

Leave a Comment