LOG
LOG in ProBuilder returns the natural logarithm of a value, the logarithm to base e. Input must be positive. Syntax, the inverse link to EXP, examples.
Syntax
LOG(a)Parameters
| Name | Type | Description |
|---|---|---|
a | number | A strictly positive value or expression. Zero and negative inputs are undefined and raise an error. |
Formula
LOG(x) = natural logarithm of x, base e, defined for x > 0LOG(1) returns 0, LOG(e) returns 1, and values between 0 and 1 return negative results. As a approaches zero the output falls without bound.
How it works
LOG is the natural logarithm, base e, sometimes called the Neperian logarithm. It answers the question: to what power must e be raised to reach a. The input must be positive; feeding it zero or a negative value is undefined.
LOG and EXP are inverses, so LOG(EXP(x)) returns x and EXP(LOG(x)) returns x for positive x. The most common use in trading is the log return, LOG(close / close[1]), which is additive across bars and symmetric for equal up and down moves, making it well suited to volatility work.
Examples
Example 1, Natural log of a value (Indicator)
// Natural logarithm of a fixed input
variable1 = 7.389
logValue = LOG(variable1)
RETURN logValue AS "LOG(7.389)"LOG(7.389) returns approximately 2, since e squared is close to 7.389.
Example 2, Log return over one bar (ProScreener)
// Screen instruments by their latest one-bar log return
r = LOG(close / close[1])
SCREENER[r > 0.01](r AS "Log return")The ratio close / close[1] is always positive on valid data, so the LOG input stays inside its domain.
Example 3, Log-based volatility filter (ProOrder)
// Standard deviation of log returns as a volatility gate
logRet = LOG(close / close[1])
vol = STD[20](logRet)
IF vol < 0.02 AND NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIFLog returns feed a standard deviation that measures volatility, and entries are only allowed while volatility stays contained.
Common errors and gotchas
- Input must be strictly positive.
LOG(0)andLOGof any negative value are undefined and raise an error. Guard the argument when it can reach zero or below. - Natural log, not base 10.
LOGuses base e, not base 10. For a base-10 logarithm, divide byLOG(10). - Inverse of EXP, not the reciprocal.
LOGundoesEXP. It is not1 / EXP. To raise a base to a power, usePow.
Related instructions
EXP, the natural exponential, the inverse ofLOG.Pow, raises a base to a power.SQRT, square root, often used together in volatility formulas.ABS, absolute value.ROC, rate of change, an alternative return measure.Variation, percentage change between bars.HistoricVolatility, built-in volatility measure related to log returns.
