Sidechair

math.* constants

Browse the reference

Mathematical constants: math.pi, math.e, math.phi (the golden ratio) and math.rphi (its reciprocal, about 0.618).

Try it in the editor

These are const float values, accurate to the precision of a double. math.pi (3.14159...) is the ratio of a circle's circumference to its diameter and is what you pass to math.sin and math.cos for a full cycle: 2 * math.pi. math.e (2.71828...) is the base of the natural logarithm, so math.exp(x) equals math.pow(math.e, x). math.phi is the golden ratio, (1 + math.sqrt(5)) / 2, and math.rphi is 1 / math.phi, which also equals math.phi - 1.

math.phi and math.rphi are the source of the Fibonacci ratios 1.618 and 0.618 used in retracement and extension levels.

Constants

NameValueDescription
math.e2.718281828459045Euler's number, the base of natural logarithms.
math.phi1.618033988749895The golden ratio.
math.pi3.141592653589793The ratio of a circle's circumference to its diameter.
math.rphi0.618033988749895The reciprocal of the golden ratio.

Remarks

  • Because they are const, you can use them in places that need a value known before the script runs, such as an input default.

Example

Pine ScriptA sine wave and golden-ratio bandsOpen in editor
//@version=6
indicator("Math constants")
wave = math.sin(2 * math.pi * bar_index / 60)
plot(wave, "Sine", color.blue, 2)
hline(math.rphi, "0.618", color.orange)
hline(-math.rphi, "-0.618", color.orange)
plot(math.sin(2 * math.pi * bar_index / 60 + math.pi / 2) * math.rphi, "Shifted", color.new(color.purple, 40))

See also

Runs on Sidechair