Algorithms
An algorithm is a versioned configuration that defines when to enter and exit trades, how much to risk, and how to behave between trades. This page covers every configurable option.
Algorithm Types
Section titled “Algorithm Types”The type field controls which directions the algorithm can trade:
| Type | Description |
|---|---|
LONG | Only opens long positions (buy low, sell high) |
SHORT | Only opens short positions (sell high, buy low) |
BOTH | Opens both long and short positions based on separate entry/exit rules |
When type is BOTH, you define four conditions: longEntry, longExit, shortEntry, shortExit. For LONG or SHORT, only the relevant pair is needed.
Entry & Exit Conditions
Section titled “Entry & Exit Conditions”Each condition is built from two indicator groups:
Condition triggered = ALL required TRUE AND (no optionals OR at least ONE optional TRUE)Required Group (AND)
Section titled “Required Group (AND)”Every indicator in the required group must signal true simultaneously. Use this for your core signal — the conditions that must always hold.
Optional Group (OR)
Section titled “Optional Group (OR)”At least one indicator in the optional group must signal true. Use this for confirmation signals where any one of several alternatives is acceptable.
Example
Section titled “Example”A long entry condition with:
- Required: RSI below 30, price below lower Bollinger Band
- Optional: volume spike (CMF > 0.1) OR Stochastic oversold
Triggers when RSI and Bollinger are both satisfied, and either volume or Stochastic confirms.
Entry-Specific Options
Section titled “Entry-Specific Options”| Field | Description |
|---|---|
buyBack | Dollar amount for buyback after exit (ValueConfig) |
trailingBB | Enable trailing buyback |
armedBy | Only allow re-entry after a stop loss (SL) or take profit (TP) has fired |
Exit-Specific Options
Section titled “Exit-Specific Options”| Field | Description |
|---|---|
stopLoss | Stop loss level (ValueConfig) |
takeProfit | Take profit level (ValueConfig) |
trailingSL | Enable trailing stop loss — SL level follows price as it moves in your favor |
Indicator Configuration
Section titled “Indicator Configuration”Each indicator in a condition group is defined by:
| Field | Description |
|---|---|
type | Indicator name (e.g., RSI, BollingerBands, ADX) |
source | Price data input — 1_open, 1_close, 1_high, 1_low, 2_typical, 2_weighted, etc. |
signal | How the indicator value becomes a boolean (see signal types below) |
period | Lookback period in seconds |
threshold | Comparison value for threshold-based signals |
valueAMAPeriod | Auxiliary moving average period (for AMA-based signals) |
Signal Types
Section titled “Signal Types”| Signal | Triggers When |
|---|---|
point_above_value | Price candle > indicator value |
point_below_value | Price candle < indicator value |
value_above_threshold | Indicator value > threshold parameter |
value_below_threshold | Indicator value < threshold parameter |
value_above_valueAMA | Indicator value > its own adaptive moving average |
value_below_valueAMA | Indicator value < its own adaptive moving average |
Some indicators define additional signal aliases specific to their behavior (e.g., RSI crossover signals, band touch signals).
Position Sizing
Section titled “Position Sizing”The positionSize field controls how much capital is allocated per trade:
| Type | Description | Example |
|---|---|---|
ABS | Fixed USD amount (capped at available equity) | { type: "ABS", value: 500 } — $500 per trade |
REL | Percentage of current equity | { type: "REL", value: 0.5 } — 50% of equity |
DYN | Dynamic, driven by an indicator value | Requires valueFactor indicator config |
Dynamic Sizing
Section titled “Dynamic Sizing”When type is DYN, the position size is modulated by an indicator:
valueFactor— the indicator config that produces a 0–1 factorinverted— iftrue, uses1 - factorinstead- The effective size:
value * factor(orvalue * (1 - factor)if inverted)
Ladder Sizing
Section titled “Ladder Sizing”The optional ladder field enables scaled entries/exits — splitting the position across multiple price levels.
Order Types
Section titled “Order Types”| Type | Description |
|---|---|
MARKET | Immediate fill at current market price |
LIMIT | Fill at specified price or better |
TWAP | Time-weighted average price — splits execution over a duration |
SMART | Platform-selected execution strategy |
Stop Loss & Take Profit
Section titled “Stop Loss & Take Profit”SL and TP are defined as ValueConfig on the exit condition:
Absolute (ABS)
Section titled “Absolute (ABS)”Fixed USD distance from entry price.
- Stop loss:
{ type: "ABS", value: 50 }— exit if position loses $50 - Take profit:
{ type: "ABS", value: 100 }— exit if position gains $100
Relative (REL)
Section titled “Relative (REL)”Percentage distance from entry price.
- Stop loss:
{ type: "REL", value: 0.05 }— exit at 5% loss - Take profit:
{ type: "REL", value: 0.10 }— exit at 10% gain
Dynamic (DYN)
Section titled “Dynamic (DYN)”SL/TP level modulated by an indicator (e.g., ATR-based stops):
valueFactorindicator produces a factor (0–1)- Effective level:
value * factor inverted: trueuses1 - factor
Trailing Stop Loss
Section titled “Trailing Stop Loss”Set trailingSL: true on the exit condition. The stop loss level moves with price:
- Long: SL ratchets up as price rises, never moves down
- Short: SL ratchets down as price falls, never moves up
The trailing distance is defined by the stopLoss ValueConfig (ABS or REL).
Timeout & Cooldown
Section titled “Timeout & Cooldown”After exiting a trade, the algorithm enters a timeout state before it can re-enter. The timeout config controls this behavior:
| Mode | Description |
|---|---|
COOLDOWN_ONLY | Wait cooldownBars bars, then re-enter the same direction if the entry condition is still true |
REGULAR | Wait cooldownBars bars. Can enter the opposite direction immediately; same direction requires cooldown |
STRICT | Wait cooldownBars bars AND both entry conditions must be false before any re-entry is allowed |
cooldownBars is measured in candle bars at the algorithm’s primary timeframe.
Versioning
Section titled “Versioning”Algorithms use immutable versioning:
- Creating an algorithm assigns an
algoIdandversion: 1 - Each update creates a new version (
version: 2,3, …) - Previous versions are never modified
- Backtests and live runs lock to a specific version
- You can run multiple versions simultaneously for comparison
This means you can safely iterate on a strategy without losing previous configurations.
State Machine
Section titled “State Machine”The algorithm execution follows a three-state machine:
entry condition metCASH ──────────────────────────→ POSITION ↑ │ │ │ exit condition / SL / TP │ cooldown expired ↓ └──────────────────────────── TIMEOUTStates:
| State | Description |
|---|---|
CASH | No open position. Evaluating entry conditions each bar. |
POSITION | In a trade (long or short). Evaluating exit conditions, scanning SL/TP. |
TIMEOUT | Post-trade cooldown. Waiting cooldownBars before re-entry. |
Exit reasons:
| Reason | Trigger |
|---|---|
SIGNAL | Exit condition indicators triggered |
STOP_LOSS | SL price level hit |
TAKE_PROFIT | TP price level hit |
TRAILING_STOP | Trailing SL level hit |
SHUTDOWN | Manual stop requested |
MANUAL | Manual exit |