Library · Pine Script v5 · Library

PivotPointsDailyTraditional

by Electrified-Trading

PivotPointsDailyTraditional is a Pine Script library that provides calculation functions for standard daily pivot points.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code166
Settings0inputs
LicenceMPL-2.0
Last update1 year ago7 Jul 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

166 lines of Pine Script v5 from PivotPoints.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

PivotPoints.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Electrified (electrifiedtrading)

// @version=5
// @description Provides the traditional daily pivot values and a pivot vacinity function.
library('PivotPointsDailyTraditional', true)
import Electrified/DailyLevels/8 as Daily

// https://www.tradingview.com/support/solutions/43000521824-pivot-points-standard/
// Traditional
// PP = (HIGHprev + LOWprev + CLOSEprev) / 3
// R1 = PP * 2 - LOWprev
// S1 = PP * 2 - HIGHprev
// R2 = PP + (HIGHprev - LOWprev)
// S2 = PP - (HIGHprev - LOWprev)
// R3 = PP * 2 + (HIGHprev - 2 * LOWprev)
// S3 = PP * 2 - (2 * HIGHprev - LOWprev)
// R4 = PP * 3 + (HIGHprev - 3 * LOWprev)
// S4 = PP * 3 - (3 * HIGHprev - LOWprev)
// R5 = PP * 4 + (HIGHprev - 4 * LOWprev)
// S5 = PP * 4 - (4 * HIGHprev - LOWprev)


///////////////////////////////////////////////////
// @function Returns the P value.
// @param level The level to caclulate.
// @param daysPrior The number of days in the past to do the calculation.
export P(
  simple int daysPrior = 0) =>
    Daily.HLC3(daysPrior + 1)
///////////////////////////////////////////////////

///////////////////////////////////////////////////
// @function Calculates the R value for a given pivot level.
// @param level The level to caclulate.
// @param daysPrior The number of days in the past to do the calculation.
export R(
  int level,
  simple int daysPrior = 0) =>
    day = daysPrior + 1
    switch level
        1 => P(daysPrior) * 2 - Daily.L(day) 
        2 => P(daysPrior) + Daily.H(day) - Daily.L(day)
        =>
            if level < 1
                runtime.error('"level" must be at least one.')
                na
            else
                ratio = level - 1
                P(daysPrior) * ratio + Daily.H(day) - ratio * Daily.L(day)
///////////////////////////////////////////////////

///////////////////////////////////////////////////
// @function Calculates the S value for a given pivot level.
// @param level The level to caclulate.
// @param daysPrior The number of days in the past to do the calculation.
export S(
  int level,
  simple int daysPrior = 0) =>
    day = daysPrior + 1
    switch level
        1 => P(daysPrior) * 2 - Daily.H(day) 
        2 => P(daysPrior) - Daily.H(day) + Daily.L(day)
        =>
            if level < 1
                runtime.error('"level" must be at least one.')
                na
            else
                ratio = level - 1
                P(daysPrior) * ratio + Daily.L(day) - ratio * Daily.H(day)
///////////////////////////////////////////////////

levelsUp(
  simple int daysPrior,
  simple int maxLevel = 3) =>
    levels = array.new_float(maxLevel + 1)
    array.set(levels, 0, P(daysPrior))
    for i = 1 to maxLevel
        array.set(levels, i, R(i, daysPrior))
    levels
////

levelsDn(
  simple int daysPrior,
  simple int maxLevel = 3) =>
    levels = array.new_float(maxLevel + 1)
    array.set(levels, 0, P(daysPrior))
    for i = 1 to maxLevel
        array.set(levels, i, S(i, daysPrior))
    levels    
////


///////////////////////////////////////////////////
// @function Returns a value representing where the provided value is in relation to each pivot level.
// @param value The value to compare against.
// @param daysPrior The number of days in the past to do the calculation.
// @param maxLevel The maximum number of pivot levels to include.
export vacinity(
  float value,
  simple int daysPrior = 0,
  simple int maxLevel = 3) =>

    level = 0
    levelBounds = 2  
    UP = levelsUp(daysPrior, maxLevel)
    DN = levelsDn(daysPrior, maxLevel)
    p = array.get(UP, 0)
    if value == p
        0
        
    else if value > p

        levels = UP
        lo = p
        hi = array.get(levels, 1)
        while(levelBounds < maxLevel and value > hi)
            levelNext = level + 1
            levelBounds := levelNext + 1
            lo := hi
            hi := array.get(levels, levelBounds)
            level := levelNext

        (value - lo) / (hi - lo) + level
        
    else if value < p

        levels = DN
        hi = p
        lo = array.get(levels, 1)
        while(levelBounds < maxLevel and value < lo)
            levelNext = level + 1
            levelBounds := levelNext + 1
            hi := lo
            lo := array.get(levels, levelBounds)
            level := levelNext

        (value - hi) / (hi - lo) - level
        
    else
        na
///////////////////////////////////////////////////


///////////////////////////////////////////////////
// Pivot Levels Example ///////////////////////////
p = P()
plot(p, "P")
plot(R(1), "R1", color.red)
plot(R(2), "R2", color.red)
plot(S(1), "S1", color.green)
plot(S(2), "S2", color.green)
///////////////////////////////////////////////////


///////////////////////////////////////////////////
// Vacinity Testing ///////////////////////////////
// hline(2)
// hline(1)
// hline(0)
// hline(-1)
// hline(-2)

// c = close > p ? color.green : color.red
// plot(vacinity(close), color=c)
///////////////////////////////////////////////////

Overview

PivotPointsDailyTraditional imports daily high, low, and close values to compute the main pivot point along with multiple resistance and support levels. The library exports functions to fetch specific resistance and support levels for current or historical days, as well as helper routines to evaluate price proximity relative to calculated pivot thresholds.

Details

Published by

Electrified-Trading on GitHub

Draws

Library (no plots)

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

261 stars

AIActivationFunctionsBipolarSigmoid is a Pine Script library that provides mathematical implementations of the bipolar sigmoid activation function and its derivatives for machine learning algorithms. It calculates bipolar sigmoid values bounded between -1 and

Library v5 AI / machine learning
Updated 4 years ago · None stated GitHub repository of AIActivationFunctionsBipolarSigmoid

KernelFunctions

by artificial-intelligence-edge
75 stars

KernelFunctions is a Pine Script v5 library that exports kernel weight functions for Nadaraya-Watson style estimation. It calculates a Rational Quadratic kernel, a Gaussian kernel based on a radial basis function, and a periodic kernel that models repeating be

Library v5
Updated 4 days ago · MIT GitHub repository of KernelFunctions

Ta

by nersent
29 stars

This Pine Script v5 library exports thin wrappers around built-in technical analysis functions. It covers moving averages, momentum measures such as RSI and CCI, volatility tools including ATR and standard deviation, range extremes, cross detection, and runnin

Library v5
Updated 11 months ago · Custom licence GitHub repository of Ta

Bands

by heyphat
26 stars

This library exports a Band type and functions that build a simple-moving-average basis with upper and lower envelopes from standard deviation. It classifies a source as above, below, or inside those envelopes, measures band width, and scales an imported z-sco

Library v6 Volatility & bandsMoving averages
Updated 2 months ago · AGPL-3.0 GitHub repository of Bands

Mylib

by ferranbt
21 stars

This script serves as a minimal utility library written in Pine Script v6. It provides an exported helper function that calculates the sum of two numeric arguments. As a reusable code library, it produces no visual plots, charts, or trading signals, and it con

Library v6
Updated 7 weeks ago · MPL-2.0 GitHub repository of Mylib

HLevel

by stupenkov
14 stars

HLevel is a Pine Script v5 utility library designed to manage horizontal price levels for cryptocurrency charts. It defines custom types for pivots and levels, along with methods to initialize, add, track, and expire price levels based on pivot high and pivot

Library v5
Updated 3 years ago · None stated GitHub repository of HLevel

More libraries

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers