Formula language reference

Formulas are expressions which operate with variables. Variables can be any of the following:

  1. ID of any of the other inputs you have provided for the model, whatever these inputs are.
  2. One of built-in variables which contain OHLCV values. Variables are: O, H, L, C, V.

Formulas can have the following operations applied to variables:

  1. Mathematical operations. These are +, -, *, /
  2. Lookbacks. Format is VARIABLE[OFFSET]. For example, C[1] means “C 1 candle ago”.
  3. Functions. See the list below and remember that the “series” parameter can’t be an expression containing mathematical operators.
    1. log(series) returns a series where every element is a natural logarithm of the corresponding item of the source series. log10() and log2() are also available
    2. max(series, length) returns the max element of series within the last “length” candles. For example, max(H, 20) would give you a series which is the highest High within 20 candles.
    3. min(series, length) does the same, but for the min element
    4. ma(series, length) returns simple moving average build on a given series
    5. sum(series, length) returns rolling sum of the last “length” elements of the series
    6. abs(series) returns absolute value for each element of the series
    7. sqrt(series) returns square root for each element of the series
    8. stdev(series, length) returns standard deviation of the series

Provided the limitation for what functions can take as “series”, in some cases you will need to create multiple formula inputs. Like, you can’t create an input like ma(C - C[1], 10) directly, but you can create 2 inputs, A being C - C[1] and B being ma(A, 10).

Here are a few examples of formulas explained:
1. (C - C[1]) / C[1] : Close change% since 1 candle ago
2. C - ma(C, 20) : distance from Close to MA(20)
3. 100 * (C - B)/(A - B) if A is "Bbands.High" and B is "Bbands.Low" then this formula is Bbands %B

Nov 7, 2024

Contact Us

Not finding what you're looking for? Contact Us Directly