Sidechair

math.exp()

Browse the reference

Returns e raised to the power of a number, the inverse of math.log.

Try it in the editor

math.exp(x) is Euler's number e, about 2.71828, raised to x. math.exp(math.log(y)) returns y for positive y.

Use it to turn log returns back into price ratios.

Syntax

Pine Script
math.exp(number: simple int/float) -> simple float
math.exp(number: input int/float) -> input float
math.exp(number: const int/float) -> const float
math.exp(number: series int/float) -> series float

Arguments

NameTypeDefaultDescription
numberconst/input/simple/series int/floatrequiredThe power to raise e to. A large value gives a very large result; na gives na.

Returns

const/input/simple/series float: e to the power of number.

Remarks

  • math.exp(0) is 1. Very large inputs overflow to na.

Example

Pine ScriptRebuild price from log returnsOpen in editor
//@version=6
indicator("Rebuilt close", overlay = true)
logRet = math.log(close / close[1])
level = ta.valuewhen(bar_index == 1, close[1], 0) * math.exp(ta.cum(nz(logRet)))
plot(level, "Rebuilt", color = color.orange)
plot(close, "Close", color = color.new(color.gray, 60))

See also

Runs on Sidechair