Formulas are expressions which operate with variables. Variables can be any of the following:
- ID of any of the other inputs you have provided for the model, whatever these inputs are.
- 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:
- Mathematical operations. These are +, -, *, /
- Lookbacks. Format is
VARIABLE[OFFSET]
. For example,C[1]
means “C 1 candle ago”. - Functions. See the list below and remember that the “series” parameter can’t be an expression containing mathematical operators.
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 availablemax(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.min(series, length)
does the same, but for the min elementma(series, length)
returns simple moving average build on a given seriessum(series, length)
returns rolling sum of the last “length” elements of the seriesabs(series)
returns absolute value for each element of the seriessqrt(series)
returns square root for each element of the seriesstdev(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