EXP
EXP in ProBuilder returns e raised to the power of the input, the natural exponential function. Syntax, the inverse link to LOG, and worked code examples.
Syntax
EXP(a)Parameters
| Name | Type | Description |
|---|---|---|
a | number | The exponent to which the constant e is raised. Any real numeric expression is valid. |
Formula
EXP(x) = e^x, where e is approximately 2.71828The output is always positive. Positive exponents grow the value above 1, a zero exponent returns 1, and negative exponents give a value between 0 and 1.
How it works
EXP models continuous exponential growth or decay. It accepts any real input and always returns a positive result, so it never produces zero or a negative number. Large positive exponents grow very fast, which is worth keeping in mind when the argument is derived from price.
EXP and LOG are inverses: EXP(LOG(x)) returns x for any positive x, and LOG(EXP(x)) returns x for any x. This pairing is the basis for working in log space, for example compounding returns.
Examples
Example 1, Basic exponential values (Indicator)
// e raised to a few exponents
variable1 = EXP(1) // approximately 2.71828
variable2 = EXP(0) // exactly 1
variable3 = EXP(-1) // approximately 0.36788
RETURN variable1 AS "e^1", variable2 AS "e^0", variable3 AS "e^-1"The three calls show the growth for a positive exponent, the fixed value at zero, and the decay for a negative exponent.
Example 2, Compound a log return (ProScreener)
// Turn a summed log return back into a price ratio
logRet = LOG(close / close[20])
ratio = EXP(logRet)
SCREENER[ratio > 1.05](ratio AS "20-bar ratio")LOG measures the return in log space and EXP converts it back to a plain ratio, showing the round trip between the two functions.
Example 3, Exponentially decaying weight (ProOrder)
// Weight recency with an exponential decay factor
barsSince = BarIndex - BarIndex[5]
weight = EXP(-0.2 * barsSince)
IF NOT LongOnMarket AND close CROSSES OVER Average[20](close) AND weight > 0.3 THEN
BUY 1 CONTRACT AT MARKET
ENDIFThe negative exponent produces a weight that decays smoothly toward zero as bars pass, a common way to emphasize recent events.
Common errors and gotchas
- Output is always positive.
EXPnever returns zero or a negative value, so testing its result against a negative threshold is always false. - Grows very fast. A large positive argument can produce an enormous value. Keep the exponent bounded when it comes from raw price differences.
- Inverse of LOG, not the reciprocal.
EXPundoes the natural logarithm. It is not1 / LOG. To raise an arbitrary base to a power, usePow.
Related instructions
LOG, natural logarithm, the inverse ofEXP.Pow, raises any base to a power, unlike the fixed base e ofEXP.SQRT, square root.SQUARE, squares a value.ABS, absolute value.ExponentialAverage, exponential moving average built on similar decay ideas.ROC, rate of change, often analyzed in log space usingEXPandLOG.
