SeekAlgo/Docs/Strategy Authoring
Docs/Strategy Authoring

Strategy Authoring

How to create backtestable strategies with the current order API and sample patterns.

Strategy Authoring

A strategy is an indicator plus trading rules.

The current samples mostly use these patterns:

  • moving-average crossovers
  • momentum confirmation
  • volatility breakouts
  • trend following with stops
  • bar-pattern entries
  • multi-symbol basket selection

Canonical Shape

script({ type: 'strategy', priceStudy: true, orderSize: 1 });

const fastLen = input.integer("Fast", 10);
const slowLen = input.integer("Slow", 20);

const fast = ta.ema(close, fastLen);
const slow = ta.ema(close, slowLen);
const fastSeries = series(fast);
const slowSeries = series(slow);

if (ta.crossover(fastSeries, slowSeries) && strategy.param_by_id("trade", "position") === 0) {
  strategy.entry({ id: "trade", type: "long" });
}

if (ta.crossunder(fastSeries, slowSeries) && strategy.param_by_id("trade", "position") !== 0) {
  strategy.exit({ id: "trade" });
}

Trade Management

  • keep one stable id per trade idea
  • check the position before sending another entry
  • exit with the same id you used for entry
  • use a symbol field when the order belongs to a basket leg

Platform Settings Still Matter

The signal logic is only half of a strategy. The script({...}) header controls:

  • date range
  • resolution
  • order sizing
  • commission
  • slippage
  • cash behavior

Use Platform Settings as the reference for those fields.

orderSize is the default quantity. If an entry passes qty, that explicit value overrides the header default. You can also read the configured defaults through strategy.default_qty_value, strategy.default_qty_type, and strategy.initial_capital. strategy.default_qty_value is the raw configured value, so if strategy.default_qty_type is cur or poe, omit qty when you want settings-driven sizing.

Current Order Shape

The recommended current order shape is object-style orders:

strategy.entry({ id: "ema_long", type: "long" });
strategy.entry({ id: "ema_long_scaled", type: "long", qty: 5 });
strategy.exit({ id: "ema_long" });

For multi-symbol strategies:

strategy.entry({ id: "btc_leg", type: "long", symbol: "BTCUSDT:BINANCE:FUTURE:DEFAULT" });
strategy.entry({ id: "eth_leg", type: "long", qty: 2, symbol: "ETHUSDT:BINANCE:FUTURE:DEFAULT" });
strategy.exit({ id: "btc_leg", symbol: "BTCUSDT:BINANCE:FUTURE:DEFAULT" });

Practical Rules

  • build the signal first, then add risk controls
  • verify the no-position and in-position paths separately
  • prefer readable trade ids over short placeholders
  • keep the first version to one market and one rule set before adding baskets

Next Reading