Formula Syntax
Operators, functions, and example formulas for the custom rule engine.
1
Arithmetic Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo (remainder)
Example: [balance] + [open pnl] * 0.5
Division by zero returns 0.
2
Comparison Operators
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to
Comparison expressions evaluate to 1 (true) or 0 (false).
3
Built-in Functions
IF(condition, value_if_true, value_if_false)
Returns one of two values based on a condition. Condition is true if non-zero; zero and NaN are false.
MAX(a, b, ...)
Returns the larger of two or more values. Requires at least 2 arguments.
MIN(a, b, ...)
Returns the smaller of two or more values. Requires at least 2 arguments.
Circular reference: a formula cannot reference its own result (e.g. the Open P&L formula cannot use [open pnl]). Doing so returns NaN.
4
Example Formulas
Trailing Balance Protection:
IF([peak open pnl] >= 1000, [balance] + [peak open pnl] * 0.5, [balance] - 1000)
This rule starts with a static $1,000 loss limit. Once the peak open profit exceeds $1,000, the trailing balance automatically adjusts so you never give back more than 50% of peak open profit.
Dynamic Profit Target:
MAX([balance] * 0.02, 500)
Sets the profit target to 2% of balance or $500, whichever is greater.