Returns the natural logarithm of a number: the power e must be raised to in order to get it.
math.log(x) answers the question: e to what power gives x. It is defined for positive numbers, and gives na for negatives.
Log of a price ratio is a continuously compounded return, which adds across bars. That makes math.log(close / close[1]) the standard input for volatility.
Syntax
math.log(number: simple int/float) -> simple float
math.log(number: input int/float) -> input float
math.log(number: const int/float) -> const float
math.log(number: series int/float) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| number | const/ | required | The number to take the natural logarithm of. 0 or below gives na. |
Returns
const/input/simple/series float: the natural logarithm of the number.
Remarks
math.log(1)is 0.
Example
//@version=6
indicator("Log return")
r = math.log(close / close[1]) * 100
plot(r, "Log return %", color = r >= 0 ? color.green : color.red, style = plot.style_columns)See also
Runs on Sidechair