Skip to content

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.

The type field controls which directions the algorithm can trade:

TypeDescription
LONGOnly opens long positions (buy low, sell high)
SHORTOnly opens short positions (sell high, buy low)
BOTHOpens 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.

Each condition is built from two indicator groups:

Condition triggered = ALL required TRUE AND (no optionals OR at least ONE optional TRUE)

Every indicator in the required group must signal true simultaneously. Use this for your core signal — the conditions that must always hold.

At least one indicator in the optional group must signal true. Use this for confirmation signals where any one of several alternatives is acceptable.

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.

FieldDescription
buyBackDollar amount for buyback after exit (ValueConfig)
trailingBBEnable trailing buyback
armedByOnly allow re-entry after a stop loss (SL) or take profit (TP) has fired
FieldDescription
stopLossStop loss level (ValueConfig)
takeProfitTake profit level (ValueConfig)
trailingSLEnable trailing stop loss — SL level follows price as it moves in your favor

Each indicator in a condition group is defined by:

FieldDescription
typeIndicator name (e.g., RSI, BollingerBands, ADX)
sourcePrice data input — 1_open, 1_close, 1_high, 1_low, 2_typical, 2_weighted, etc.
signalHow the indicator value becomes a boolean (see signal types below)
periodLookback period in seconds
thresholdComparison value for threshold-based signals
valueAMAPeriodAuxiliary moving average period (for AMA-based signals)
SignalTriggers When
point_above_valuePrice candle > indicator value
point_below_valuePrice candle < indicator value
value_above_thresholdIndicator value > threshold parameter
value_below_thresholdIndicator value < threshold parameter
value_above_valueAMAIndicator value > its own adaptive moving average
value_below_valueAMAIndicator value < its own adaptive moving average

Some indicators define additional signal aliases specific to their behavior (e.g., RSI crossover signals, band touch signals).

The positionSize field controls how much capital is allocated per trade:

TypeDescriptionExample
ABSFixed USD amount (capped at available equity){ type: "ABS", value: 500 } — $500 per trade
RELPercentage of current equity{ type: "REL", value: 0.5 } — 50% of equity
DYNDynamic, driven by an indicator valueRequires valueFactor indicator config

When type is DYN, the position size is modulated by an indicator:

  • valueFactor — the indicator config that produces a 0–1 factor
  • inverted — if true, uses 1 - factor instead
  • The effective size: value * factor (or value * (1 - factor) if inverted)

The optional ladder field enables scaled entries/exits — splitting the position across multiple price levels.

TypeDescription
MARKETImmediate fill at current market price
LIMITFill at specified price or better
TWAPTime-weighted average price — splits execution over a duration
SMARTPlatform-selected execution strategy

SL and TP are defined as ValueConfig on the exit condition:

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

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

SL/TP level modulated by an indicator (e.g., ATR-based stops):

  • valueFactor indicator produces a factor (0–1)
  • Effective level: value * factor
  • inverted: true uses 1 - factor

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).

After exiting a trade, the algorithm enters a timeout state before it can re-enter. The timeout config controls this behavior:

ModeDescription
COOLDOWN_ONLYWait cooldownBars bars, then re-enter the same direction if the entry condition is still true
REGULARWait cooldownBars bars. Can enter the opposite direction immediately; same direction requires cooldown
STRICTWait 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.

Algorithms use immutable versioning:

  • Creating an algorithm assigns an algoId and version: 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.

The algorithm execution follows a three-state machine:

entry condition met
CASH ──────────────────────────→ POSITION
↑ │
│ │ exit condition / SL / TP
│ cooldown expired ↓
└──────────────────────────── TIMEOUT

States:

StateDescription
CASHNo open position. Evaluating entry conditions each bar.
POSITIONIn a trade (long or short). Evaluating exit conditions, scanning SL/TP.
TIMEOUTPost-trade cooldown. Waiting cooldownBars before re-entry.

Exit reasons:

ReasonTrigger
SIGNALExit condition indicators triggered
STOP_LOSSSL price level hit
TAKE_PROFITTP price level hit
TRAILING_STOPTrailing SL level hit
SHUTDOWNManual stop requested
MANUALManual exit