Writing a strategy

strategies/demo/go/smacross is the reference “real” strategy: a moving-average crossover that goes long one share when a fast SMA crosses above a slow SMA and short one share on the cross below. This chapter walks through it as a tour of the SDK. Run it first:

bin/algo run \
  --adapter bin/databento-adapter \
  --adapter-inputs Path=testdata/xnas-sample/xnas-itch-20220610.trades.csv \
  --strategy bin/smacross \
  --symbol MSFT --interval 1m
algo: warmup history for MSFT@1m has 0 of 9 requested lookback bars; continuing
[smacross] INFO: smacross: fast SMA(3) crossed below slow SMA(8); selling 1 MSFT
[smacross] INFO: smacross: fill smacross_1654865160000000000: sold 1 MSFT @ 261.85
[smacross] INFO: smacross: fast SMA(3) crossed above slow SMA(8); buying 1 MSFT
[smacross] INFO: smacross: fill smacross_1654865220000000000: bought 1 MSFT @ 262.17
[smacross] INFO: smacross: fast SMA(3) crossed below slow SMA(8); selling 1 MSFT
[smacross] INFO: smacross: fill smacross_1654865460000000000: sold 1 MSFT @ 261.09
[smacross] [smacross] 3 fills (1 buys, 2 sells)
[smacross] [smacross] final position MSFT -1 @ 261.09
...
  simulator:  resolution=tick bracket_ambiguity=conservative limit_fill=conservative slippage_ticks=0
              3 fills, commission 0.00, realized PnL -0.32
              open MSFT -1 @ 261.0900 (last 261.0300, unrealized 0.06)
              equity 99999.74 (capital 100000.00, return -0.0003%)

(The warmup note is harmless here: the strategy asked for 9 bars of history before the first decision, and the small sample has none to give. With a larger data file the engine pre-rolls that history automatically so your very first in-range bar already has a full lookback behind it.)