Syntax & Variables
Kafal operates on a vectorized runtime, meaning variables automatically represent entire time-series arrays without the need for manual iteration.
Standard Assignment
Variables are declared using the standard = operator. Mathematical operations and indicator calls apply to the entire historical dataset simultaneously.
// Standard assignment
len_fast = 10
len_slow = 30
// Calling built-in technical indicators
fast_ma = ta.sma(close, len_fast)
slow_ma = ta.sma(close, len_slow)
// Boolean logic
is_bullish = fast_ma > slow_maThe Pipe Operator
When chaining multiple functions, Kafal utilizes a functional pipe operator (|) to keep logic linear. Use the pipe assignment operator (=>) to bind the result.
// Using the Pipe Operator (clean and linear)
// The value on the left is passed as the first argument to the next function.
signal => close | ta.rsi(14) | zscore(50) | math.abs()Historical Referencing
To reference previous values in a time-series, use the historical bracket operator [n].
// Get the close price from 1 bar ago
prev_close = close[1]
// Check if the current close is higher than the previous close
is_rising = close > close[1]Note: Under the hood, the Kafal AST securely intercepts this syntax and converts it into a safe memory lookup
history(series, n).