Library · Pine Script v5 · Library

Points

by Electrified-Trading

Points is a Pine Script v5 library that stores paired x and y coordinates as two synchronized arrays.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code258
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

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

Points.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 functions for simplifying operations with collections of x+y coordinates.  Where x is typically a bar index or time (millisecond) value.
library('Points')

//////////////////////////////////////////////////
// @function Creates two arrays. One for X (int[]) and another for Y (float[]). 
// @param size The initial size of the arrays.
export new(int size = 0) =>
    [array.new_int(size), array.new_float(size)]
//////////////////////////////////////////////////    

//////////////////////////////////////////////////
// @function Checks the size of the arrays and if they're equal returns the size. 
// @param xA The X array.
// @param yA The Y array.
export size(int[] xA, float[] yA) =>
    if array.size(xA) != array.size(yA)
        runtime.error('Point arrays are out of sync.')
    array.size(xA)
//////////////////////////////////////////////////    

checkBounds(int[] xA, float[] yA, int index) =>
    if size(xA, yA) <= index
        runtime.error('Requested index is greater than available.')  
    else if index < 0
        runtime.error('Index is less than zero.')
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Gets the X and Y values of the arrays at the index. 
// @param xA The X array.
// @param yA The Y array.
// @param index The index.
// @returns [x, y]
export get(int[] xA, float[] yA, int index) =>
    checkBounds(xA, yA, index)
    [array.get(xA, index), array.get(yA, index)]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Sets the X and Y values of the arrays at the index. 
// @param xA The X array.
// @param yA The Y array.
// @param index The index.
// @param x The x value.
// @param y The y value.
// @returns [index, x, y]
export set(int[] xA, float[] yA, int index, int x, float y) =>
    checkBounds(xA, yA, index)
    array.set(xA, index, x)
    array.set(yA, index, y)
    [index, x, y]
//////////////////////////////////////////////////

//////////////////////////////////////////////////
// @function Adds X and Y values to the end of the arrays (as the last element). 
// @param xA The X array.
// @param yA The Y array.
// @param x The x value.
// @param y The y value.
// @returns [index, x, y]
export push(int[] xA, float[] yA, int x, float y) =>
    index = size(xA, yA)
    array.push(xA, x)
    array.push(yA, y)
    [index, x, y]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Adds X and Y values to the beginning of the arrays (as the first element). 
// @param xA The X array.
// @param yA The Y array.
// @param x The x value.
// @param y The y value.
// @returns [index, x, y]
export unshift(int[] xA, float[] yA, int x, float y) =>
    size(xA, yA) // validate
    array.unshift(xA, x)
    array.unshift(yA, y)
    [0, x, y]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Inserts X and Y values to the arrays at the index. 
// @param xA The X array.
// @param yA The Y array.
// @param index The index to insert at.
// @param x The x value.
// @param y The y value.
// @returns [index, x, y]
export insert(int[] xA, float[] yA, int index, int x, float y) =>
    checkBounds(xA, yA, index)
    array.insert(xA, index, x)
    array.insert(yA, index, y)
    [index, x, y]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Inserts the X and Y values into the arrays based upon the X value assuming the the arrays is ordered by X. 
// @param xA The X array.
// @param yA The Y array.
// @param x The x value.
// @param y The y value.
// @returns [index, x, y]
export add(int[] xA, float[] yA, int x, float y) =>
    last = size(xA, yA) - 1
    if last < 0
        push(xA, yA, x, y)
    else if array.get(xA, last) <= x
        push(xA, yA, x, y)
    else
        done = false
        last -= 1
        while not done and last >= 0
            if x < array.get(xA, last)
                last -= 1
            else
                done := true

        if last < 0
            unshift(xA, yA, x, y)
        else
            insert(xA, yA, last + 1, x, y)
//////////////////////////////////////////////////

//////////////////////////////////////////////////
// @function Removes the last element from the arrays and returns their value. 
// @param xA The X array.
// @param yA The Y array.
// @returns [x, y]
export pop(int[] xA, float[] yA) =>
    if size(xA, yA) == 0
        [int(na), float(na)]
    else
        [array.pop(xA), array.pop(yA)]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Removes the first element from the arrays and returns their value. 
// @param xA The X array.
// @param yA The Y array.
// @returns [x, y]
export shift(int[] xA, float[] yA) =>
    if size(xA, yA) == 0
        [int(na), float(na)]
    else
        [array.shift(xA), array.shift(yA)]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Removes the element from the arrays at the index and returns their value. 
// @param xA The X array.
// @param yA The Y array.
// @returns [x, y]
export remove(int[] xA, float[] yA, int index) =>
    [x, y] = get(xA, yA, index)
    array.remove(xA, index)
    array.remove(yA, index)
    [x, y]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Gets the X and Y values of the first element. 
// @param xA The X array.
// @param yA The Y array.
// @returns [x, y]
export first(int[] xA, float[] yA) =>
    len = size(xA, yA)
    if len == 0
        [int(na), float(na)]
    else
        [array.get(xA, 0), array.get(yA, 0)]
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Gets the X and Y values of the last element. 
// @param xA The X array.
// @param yA The Y array.
// @returns [x, y]
export last(int[] xA, float[] yA) =>
    len = size(xA, yA)
    if len == 0
        [int(na), float(na)]
    else
        last = len - 1
        [array.get(xA, last), array.get(yA, last)]
//////////////////////////////////////////////////    

getLastIndex(int[] xA, int start) =>
    size = array.size(xA)
    if not na(start)
        if start >= size
            runtime.error("Value of 'start' is greater than available.")
        start
    else
        size - 1
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Gets the indexes that have values at or above the low value and below the high value. 
// @param xA The X array.
// @param lo The inclusive low value.
// @param hi The excluded hi value.
// @param start The optional index to start the backwards search.
// @param ordered If true, the search ends when the first value is found that is less than the low.
export allIndexesBetween(int[] xA, int lo, int hi, int start = na, bool ordered = false) =>
    int[] indexes = array.new_int()
    last = na(lo) or na(hi) ? -1 : getLastIndex(xA, start)
    while last >= 0
        x = array.get(xA, last)
        if x <= lo
            if ordered
                last := -1
        else if x < hi
            array.push(indexes, last)
        last -= 1
    array.reverse(indexes) // because unshifting is expensive
    indexes
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Gets the first found from the end that has a value at or above the low value and below the high value. 
// @param xA The X array.
// @param lo The inclusive low value.
// @param hi The excluded hi value.
// @param start The optional index to start the backwards search.
// @param ordered If true, the search ends when the first value is found that is less than the low.
export lastIndexBetween(int[] xA, int lo, int hi, int start = na, bool ordered = false) =>
    int index = -1
    last = na(lo) or na(hi) ? -1 : getLastIndex(xA, start)
    while index == -1 and last >= 0
        x = array.get(xA, last)
        if x <= lo
            if ordered
                last := -1
        else if x < hi
            index := last
        last -= 1
    index
////////////////////////////////////////////////// 

//////////////////////////////////////////////////
// @function Gets the first found from the end that has a value below the high value. 
// @param xA The X array.
// @param hi The excluded hi value.
// @param start The optional index to start the backwards search.
export lastIndexBelow(int[] xA, int hi, int start = na) =>
    int index = -1
    last = na(hi) ? -1 : getLastIndex(xA, start)
    while index == -1 and last >= 0
        if array.get(xA, last) < hi
            index := last
        last -= 1
    index
//////////////////////////////////////////////////

Overview

Points creates empty or sized integer and float arrays, checks that both arrays share the same length, and raises a runtime error when they diverge or when an index is out of range. Exported functions get, set, push, unshift, and insert values at a given index or at either end. It draws nothing and has no inputs, signals, or market-specific logic.

Details

Published by

Electrified-Trading on GitHub

Type

Library, Pine Script v5

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 2 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

Trade Your Charts With a Regulated Broker

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

Compare brokers