Library · Pine Script v5 · Library

MathConstantsUniversal

by ricardosantos79· code credited to RicardoSantos

This Pine Script library provides exported functions for standard physical and universal mathematical constants.

View on GitHub

GitHub stars261on the repository
Pine versionv5runs as is
Lines of code72
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago13 Nov 2021

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

72 lines of Pine Script v5 from beta/libs/Math/MathConstantsUniversal.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

MathConstantsUniversal.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=5

// @description Mathematical Constants
library(title='MathConstantsUniversal')

//  reference:
//      https://github.com/mathnet/mathnet-numerics/blob/master/src/Numerics/Constants.cs


// A collection of frequently used mathematical constants.
    
// UNIVERSAL CONSTANTS {

// @function Speed of Light in Vacuum: c_0 = 2.99792458e8 [m s^-1] (defined, exact; 2007 CODATA)
export SpeedOfLight () => //{
    2.99792458e8
//}

// @function Magnetic Permeability in Vacuum: mu_0 = 4*Pi * 10^-7 [N A^-2 = kg m A^-2 s^-2] (defined, exact; 2007 CODATA)
export MagneticPermeability () => //{
    1.2566370614359172953850573533118011536788677597500e-6
//}

// @function Electric Permittivity in Vacuum: epsilon_0 = 1/(mu_0*c_0^2) [F m^-1 = A^2 s^4 kg^-1 m^-3] (defined, exact; 2007 CODATA)
export ElectricPermittivity () => //{
    8.8541878171937079244693661186959426889222899381429e-12
//}

// @function Characteristic Impedance of Vacuum: Z_0 = mu_0*c_0 [Ohm = m^2 kg s^-3 A^-2] (defined, exact; 2007 CODATA)
export CharacteristicImpedanceVacuum () => //{
    376.73031346177065546819840042031930826862350835242
//}

// @function Newtonian Constant of Gravitation: G = 6.67429e-11 [m^3 kg^-1 s^-2] (2007 CODATA)
export GravitationalConstant () => //{
    6.67429e-11
//}

// @function Planck's constant: h = 6.62606896e-34 [J s = m^2 kg s^-1] (2007 CODATA)
export PlancksConstant () => //{
    6.62606896e-34
//}

// @function Reduced Planck's constant: h_bar = h / (2*Pi) [J s = m^2 kg s^-1] (2007 CODATA)
export DiracsConstant () => //{
    1.054571629e-34
//}

// @function Planck mass: m_p = (h_bar*c_0/G)^(1/2) [kg] (2007 CODATA)
export PlancksMass () => //{
    2.17644e-8
//}

// @function Planck temperature: T_p = (h_bar*c_0^5/G)^(1/2)/k [K] (2007 CODATA)
export PlancksTemperature () => //{
    1.416786e32
//}

// @function Planck length: l_p = h_bar/(m_p*c_0) [m] (2007 CODATA)
export PlancksLength () => //{
    1.616253e-35
//}

// @function Planck time: t_p = l_p/c_0 [s] (2007 CODATA)
export PlancksTime () => //{
    5.39124e-44
//}

//}

Overview

MathConstantsUniversal exports high-precision numerical values including the speed of light, gravitational constant, Planck constant, magnetic permeability, and electric permittivity based on CODATA standards. The library contains no user-configurable settings and does not plot or generate signals on the chart. It serves strictly as a calculation helper for other scripts requiring universal scientific constants, with no visual output or direct trading functionality.

Details

Published by

ricardosantos79 on GitHub

Code credit

RicardoSantos, as written in the script's header

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

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

Zignaly2Beta

by ruckard
13 stars

This library provides helper functions to format and build JSON webhook alert payloads for the Zignaly automated trading platform. It constructs formatted messages containing parameters such as trading pair, exchange, account type, leverage, margin mode, hedge

Library v5
Updated 1 year ago · None stated GitHub repository of Zignaly2Beta

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