Math
33 entries. What each one takes, what it returns, and a working example.
Drops the sign and keeps the magnitude; works element-wise on both scalars and series.
plot(abs(change(close, 1)))
The absolute magnitude of the per-bar price change (direction-less).
The arc-cosine of x (in radians, 0..π).
To avoid na from out-of-range input, the value is first clamped to [-1, 1]. The result is in radians; use todegrees to convert.
plot(todegrees(acos(1)))
acos(1) = 0 radians = 0 degrees.
The arc-sine of x (in radians, -π/2..π/2).
To avoid na from out-of-range input, the value is first clamped to [-1, 1]. The result is in radians (todegrees for degrees).
plot(todegrees(asin(1)))
asin(1) = π/2 radians = 90 degrees.
Single-argument; gives the angle of a slope (Δy/Δx). For a sign/quadrant-aware angle use atan2.
plot(todegrees(atan(change(close, 1))))
The slope angle (degrees) of the per-bar price change.
The angle of the point (x, y) (in radians, -π..π; quadrant-aware).
The two-argument arc-tangent: unlike atan it uses the signs to give the correct quadrant (-π..π). The result is in radians.
plot(todegrees(atan2(1, 1)))
atan2(1, 1) = π/4 radians = 45 degrees.
The element-wise average.
Can take more than two arguments.
plot(avg(high, low, close))
The per-bar average of high, low and close (same as hlc3).
In this language bool is NEVER na: bool(na) = false. A scalar input returns a real boolean, a series returns 1/0 (na→0). No collapse to the last value.
plot(bool(volume) ? 1 : 0)
0 when volume is zero/na, otherwise 1.
Rounds up (toward plus infinity): ceil(2.1) = 3. Operates element-wise.
plot(ceil(close / 10) * 10)
Snaps the close up to the nearest higher multiple of 10.
The value constrained to the [lo, hi] range.
Constrains x to the [lo, hi] range, pulling anything outside back to the bound.
plot(clamp(rsi(close, 14), 30, 70))
Constrains RSI to the 30-70 band, trimming the overshoots.
The input is in radians. The output is between -1 and 1. Operates element-wise.
plot(cos(0))
cos(0) = 1 (constant).
e to the power of x; the inverse of the logarithm. Operates element-wise.
plot(exp(log(close)))
exp undoes log and returns close (identity check).
A series of the same length: each na is filled with the last non-na value up to that point (na until the first valid value).
Do not confuse with nz: nz(x)/nz(x,y) puts a CONSTANT (0 or y) in place of na. fixnan(x) puts the LAST KNOWN value from the series (forward-fill, ffill) — not constant, varies with the data.
For type clarity; explicitly marks a numeric value as floating-point. An na input stays na. It is a no-op on already-float values.
plot(float(3))
Casts the integer 3 to 3.0.
Rounds down (toward minus infinity): floor(-2.1) = -3. Differs from int, which truncates toward zero.
plot(floor(close / 10) * 10)
Snaps the close down to the nearest lower multiple of 10 (price step).
Truncates the fraction toward zero to an integer (na is preserved).
Truncates toward zero: int(10.9)=10, int(-10.9)=-10. floor differs (rounds down, differs for negatives). An na input stays na.
plot(int(close))
The integer part of the close (truncated toward zero).
Natural logarithm (base e). Undefined for input ≤0. Operates element-wise.
plot(log(close / prev(close, 1)))
The per-bar log return.
Base-10 logarithm. Undefined for input ≤0. Operates element-wise.
plot(log10(volume))
The base-10 logarithm of volume (its order of magnitude).
math.pi / e / phi / rphi / sqrt2 / sqrt3
Math constants (dot access): pi=3.14159..., e=2.71828..., phi=golden ratio 1.61803..., rphi=inverse golden ratio 0.61803..., sqrt2=1.41421..., sqrt3=1.73205...
Picks the larger of two values element-wise; a series and a constant can be mixed.
plot(max(close - open, 0))
The size of up-bodies only; 0 on down bars.
Picks the smaller of two values element-wise; a series and a constant can be mixed.
plot(min(high - close, close - low))
The shorter of the upper and lower wick.
The remainder of a divided by b. Undefined when the divisor is 0. Operates element-wise.
plotshape(mod(barIndex, 10) == 0, style="cross", location="bottom")
A mark in the bottom band once every 10 bars.
The series without na.
Replaces na values with replacement (default 0), leaving the rest untouched.
plot(nz(change(close, 1), 0))
0 instead of na on the first bar; the normal change afterwards.
x to the power of y. Operates element-wise; base and exponent may be series.
plot(pow(2, 10))
2 to the power of 10 = 1024 (constant).
A series holding a deterministic random value in [min, max) for each bar.
It is deterministic: with the same seed the backtest and live results match exactly (seed → reproducibility). It is not a truly unpredictable number.
plot(random(0, 1, 42))
A reproducible random series in 0..1 per bar, seeded with 42.
The rounded value.
Operates element-wise.
plot(round(close, 2))
The close rounded to two decimals.
round_to_mintick(deger, tick?)
The value rounded to the nearest multiple of tick.
To snap a price to the symbol's trading step. If you want a fixed number of decimals, round is more appropriate.
plot(round_to_mintick(12.347, 0.05))
12.347 to the nearest 0.05 multiple → 12.35.
Returns only -1, 0 or +1 (positive→1, negative→-1, zero→0). Operates element-wise.
plot(sign(change(close, 1)))
+1 if price rose, -1 if it fell, 0 if unchanged.
The input is in radians. The output is between -1 and 1. Operates element-wise.
plot(sin(toradians(barIndex * 10)))
A smooth oscillating (-1..1) wave driven by the bar index.
A negative input returns na. Operates element-wise.
plot(sqrt(pow(high - low, 2)))
The square root of the squared bar range = the range itself (identity check).
The sum of the last length bars.
The first length-1 bars are None.
plot(sum(volume, 5))
The total volume of the last 5 bars (rolling window).
The input is in radians. It diverges near odd multiples of 90°. Operates element-wise.
plot(tan(0))
tan(0) = 0 (constant).
The same angle in degrees (rad × 180 / π).
Trigonometric/arc functions output radians; use this for readable degrees. The inverse is toradians.
plot(todegrees(3.141592653589793))
π radians = 180 degrees.
The same angle in radians (degrees × π / 180).
sin/cos/tan expect radians; convert a degree value with this before passing it in. The inverse is todegrees.
plot(sin(toradians(90)))
Converts 90 degrees to radians and takes its sine → 1.