One Script, All Modes#

A QuantScript strategy that runs in live mode is the same script you backtested and paper traded. The trading logic, indicator computations, and trade.* calls are identical — only the mode declaration and broker adapter change:

Diff: backtest → live
// Before (backtest):
mode(mode_type: "backtest", script_name: "My Strategy");
broker(adapter: "sim", config: { initial_capital: 10000 });

// After (live):
mode(mode_type: "live", script_name: "My Strategy");
broker(adapter: "demotrader");

There is no separate “production codebase”. The strategy you validated on historical data and forward-tested on streaming markets is exactly what runs against your broker — eliminating the entire class of bugs introduced by rewriting for deployment.

Broker-Agnostic Execution#

Live strategies trade through the Canonical Trading Model — a provider-neutral layer of orders, fills, positions, accounts, and instrument definitions. Strategy code never touches broker-specific APIs:

  • trade.orderSend(), trade.buy(), trade.sell() — submit market and pending orders.
  • trade.closePosition(), trade.modifyPosition() — manage open positions.
  • trade.positions(), trade.orders(), trade.fills() — introspect broker state.
  • trade.account() — equity, balance, margin, and free margin.

Broker adapters translate between this universal API and the connected broker — FX/CFD brokers, crypto exchanges, and stock brokers all behind one interface. Switching brokers means changing the adapter declaration, not rewriting trading logic.

Before execution begins, the runtime performs capability discovery: instrument constraints, supported order types, and account properties are loaded from the broker, so strategies can adapt to what the connected account actually supports.

Safety Architecture#

Live mode wraps every trade in a layered safety architecture:

  • RiskGuard — every order passes through risk validation before reaching the broker: per-order limits, portfolio exposure, drawdown circuit breakers, and kill switches. Strategy intent is always subordinate to account safety.
  • Position reconciliation — the runtime continuously reconciles its internal state against actual broker state (orders, fills, positions), detecting and recovering from disconnects, restarts, and out-of-band changes.
  • Audit trail — every trade decision, order submission, fill, and state transition is recorded in a structured, machine-readable journal with reason, context, and tags metadata for full explainability.
  • Fail-closed behaviour — when the true account state cannot be established, the platform blocks new risk rather than assuming conditions are safe.

Deployments run as continuously monitored cloud processes on quantscript.com — with start/stop lifecycle controls, health monitoring, and a dashboard showing live positions, equity, and per-strategy performance.

Multi-Strategy Accounts#

Live mode supports running multiple independent strategies on the same broker account through Virtual Trading Accounts — ownership tags isolate each strategy’s positions while capital and margin remain pooled. Each strategy sees its own equity, P&L, and drawdown as if it had a dedicated account.

Declaring Live Mode#

QuantScript
mode(mode_type: "live", script_name: "EMA Cross Live");

candles("BTCUSD", resolution_type: "1h", bars: 200);

broker(adapter: "demotrader");

risk(max_position_pct: 25, daily_loss_limit: 3);

event.onCandle((candle) => {
  if (ta.crossover(ta.ema(candle.close, 20), ta.ema(candle.close, 50))) {
    trade.orderSend({
      side: "buy",
      qty: 0.1,
      stopLoss: candle.close * 0.98,
      reason: "EMA20 crossed above EMA50"
    });
  }
});

Deploy from the platform dashboard in one click — or start with a ready-made automated strategy and study how it works.

Next Steps#