Language reference

Indicators, conditions, operators, risk, schedule and built-ins.

Indicators

Declare what you measure. Each line creates a variable you can reference in conditions:

indicators {
  rsi      = RSI(14)
  ema_fast = EMA(9)
  ema_slow = EMA(21)
  atr      = ATR(14)
  vwap     = VWAP()
}
IndicatorArgsReturnsBest for
RSI(period)period (14)0–100overbought/oversold
EMA(period)9, 21, 50…price leveltrend
SMA(period)periodprice levelbaseline
ADX(period)period (14)0–100trend strength
ATR(period)period (14)price unitsvolatility
VWAP()—price levelfair value
MACD(f, s, sig)12, 26, 9MACD linemomentum
Bollinger(p, std)20, 2{lower, upper, pct_b}range/breakout
Indicators are always available by their default name (e.g. rsi, adx) even without declaring them. Declaring just gives you a custom alias.

Conditions

Entry conditions (AND)

Every condition must evaluate to true:

entry when {
  ema_fast > ema_slow              // trend
  rsi in 35..65                   // not extreme
  adx > 25                        // directional
  price > vwap                    // above fair value
  not_in_cooldown(2h)             // no recent loss
  fee_ratio_ok(30%)               // fees won't kill profit
}

Exit conditions (OR)

Any single condition triggers a close:

exit when {
  trailing_stop(callback: 1.5%)
  or rsi > 75
  or ema_fast crosses_below ema_slow
}

Operators

OperatorMeaningExample
> < >= <= == !=Numeric comparisonrsi > 70
inRange check (inclusive)rsi in 30..70
crosses_aboveCrossed above this cycleema9 crosses_above ema21
crosses_belowCrossed below this cycleema9 crosses_below ema21
orOR (only valid in exit when)or rsi > 80

Risk Management

risk {
  max_position_pct: 5%            // max 5% of capital per trade
  position_size_score_3: 25%       // score 3 → 25% of max
  position_size_score_4: 65%       // score 4 → 65% of max
  position_size_score_5: 100%      // score 5 → full max
  stop_loss_atr: 1.5              // SL at 1.5x ATR below entry
  take_profit_atr: 4               // TP at 4x ATR above entry
  cooldown_after_loss: 2h          // wait after a loss
  max_daily_loss: 5%               // stop trading if -5% today
}
Tiered sizing scales position size with the AI confidence score. A weak setup (score 3) risks less than a high-conviction one (score 5).

Schedule

schedule {
  cycle_interval: 5m               // minimum 1m
  cautious_hours: [20,21,0,1]      // UTC hours: tighter rules
  cautious_confidence: 0.65        // vs 0.5 default
  cautious_adx: 30                  // vs 20 default
  cautious_size_penalty: 50%        // half size in cautious hours
  dead_hours: [3,4]                 // no entries (existing positions managed)
}

AI Context

ai_context {
  model: "deepseek"                // or "user.my-llm"
  prompt: "Trade only momentum setups."
  min_confidence: 0.5              // LLM gate threshold
  temperature: 0.3                  // LLM creativity
}

System models: deepseek, openai, anthropic, meta. User models prefixed with user.

Built-in Functions

FunctionBlockDescription
top_volume(n, quote)symbolsTop N pairs by 24h volume on the given quote
trailing_stop(callback: %)exitDynamic trailing stop, % from peak
not_in_cooldown(duration)entryReturns true if no loss in the duration
min_time_since_last_entry(d)entryMin time between entries on same symbol
fee_ratio_ok(percent)entryTrue if expected fees ≤ % of expected profit
dynamic_adx_floor()entryReturns 20 normally, 30 in cautious hours
dynamic_confidence_floor()entryReturns 0.5 / 0.65 in cautious hours

Built-in Variables

Available without declaring:

VariableTypeNotes
pricenumberCurrent symbol price
capitalnumberBot's current cash
leveragenumber1 = spot, >1 = futures
rsi, adx, atr, vwap, macdnumberDefault-period indicators
ema_fast, ema_slownumberEMA(9) and EMA(21)
volumestring"normal", "elevated", "low"
spreadnumberBid-ask spread %
funding_ratenumberFutures funding rate
confidencenumber0–1, set by LLM gate
hourintegerCurrent UTC hour 0–23
AiTrade docs