Build, install, and run

Start in an Algolang checkout with Go 1.26.3 or later, Git and Make installed. You need access to the dependencies pinned by the checkout. Run:

make build testdata
bin/algo version
bin/smacross --algolang-describe
bin/smacross --algolang-selftest

make build resolves the pinned nseries indicator library and builds the engine, bundled adapters and strategies into bin/. make testdata derives small fixtures from the committed trade sample. A strategy is an executable, not a script interpreted by algo: the engine starts it, sends data and account events, and receives orders. --algolang-describe lists its inputs; --algolang-selftest checks its SDK integration. Neither establishes that its trading idea works.

After the introductory chapters, each chapter follows a strategy: run it, understand the new idea, then inspect what happened. The examples teach mechanics, not expected returns. This book supplies the concepts and execution rules needed by its examples; docs/algolang.md is an additional API reference. Shell commands run from the checkout root. Create two ordinary working folders for your own source/configuration and saved runs:

mkdir -p examples/learning results/learning

examples/learning/ contains the programs and JSON files you create while reading; results/learning/ contains reports, logs and exports. The supplied programs live in strategies/demo/go/ and the small book fixtures in docs/examples/. Keep generated results out of source control.

Reading and compiling the complete listings

Every demonstration named in the strategy chapters has its complete source at the end of the relevant chapter, including local helper files. Numbered reading notes explain the design, and inline comments explain individual steps. Shorter code blocks in the discussion isolate an expression or show an alternative; use the complete listing as the buildable starting point. The SDK, indicators, nseries and strategies/kit are shared libraries provided by the checkout, rather than omitted strategy implementation.

In complete repository listings, "MODULE/sdk/strategy", "MODULE/indicators" and "MODULE/strategies/kit" stand for the local module’s imports. Run go list -m and substitute that value for MODULE when copying a listing into your own directory inside this checkout. Retain aliases such as algolang. This keeps the book independent of a private repository address. The supplied source files already have the real imports: compile them directly using the command beside each listing. For a program with several files, copy all of them into the same directory before building that directory. The small hand-written crossover below retains the house manual’s short import algolang / import indicators notation and explains its exact substitutions.

make strategy-guide refreshes these listings from the source files before building Markdown-derived HTML, PDF and Hugo pages. make strategy-guide-smoke extracts every complete listing, substitutes its imports and compiles it. It runs standalone SDK probes and the book’s offline trading recipes. A capability-required program needs an engine run: the current standalone selftest offers no capabilities and refuses it, a limitation called out beside those listings.

A first call without an archive

Prove the plumbing with the supplied minute bars:

bin/algo run \
  --adapter bin/file-csv-adapter \
  --adapter-inputs Path=testdata/msft-1m.csv,TickSize=0.01,PointValue=1 \
  --strategy bin/smacross --symbols MSFT --bar-interval 1m \
  --inputs Fast=3,Slow=8 \
  --commission-per-order 1 --slippage-ticks 1 \
  --cache off --plate full --color never --chart lines \
  --results-dir results/learning/first

This is a short plumbing check using 3/8-minute averages. The actual first strategy in the crossover chapter uses 20/200 daily averages. The small sample cannot support a 200-day study. Expect a warm-up shortfall on the sample; investigate the same note in a research run.

The command names the source, its file, the strategy, the instruments and the bar interval. --inputs configures the strategy; --adapter-inputs configures the source. Their namespaces are separate. --symbols A,B sends both symbols to one strategy instance. It does not launch two independent backtests.

Install for use outside the checkout

make install
algo run \
  --strategy /usr/local/algolang/strategies/smacross \
  --symbols fut:XCME:ES --bar-interval 1d \
  --inputs Fast=20,Slow=200 \
  --date-from 2020-01-01 --date-to 2024-12-31 \
  --commission-per-share 2.50 --slippage-ticks 1

Installation places algo in /usr/local/bin, adapters in /usr/local/algolang/adapters, and strategies in /usr/local/algolang/strategies. It also builds the marketfeed adapter from marketfeed.ref, against this Algolang checkout. The example needs a populated marketfeed archive; installation does not acquire market history.

For a user-owned prefix, run make install PREFIX="$HOME/.local" and put $HOME/.local/bin on PATH. The installed strategies then live under $HOME/.local/algolang/strategies. The adapter directory is stamped into the build; ALGOLANG_ADAPTERS overrides it. Strategy paths are always explicit.

Without --adapter, a single run probes the installed adapters and selects the one able to serve it. A config file must name its adapter. During development we will use bin/ paths to make the selected builds obvious:

make marketfeed-adapter
export MARKETFEED_DIR=/usr/local/marketfeed

Change MARKETFEED_DIR to the archive on your machine. Every marketfeed command below assumes that setup and the required historical coverage.

A repeatable report format

Use this explicit display and persistence convention throughout a study:

mkdir -p examples/learning results/learning
bin/algo run \
  --adapter bin/marketfeed-adapter --data-protocol pb \
  --strategy bin/smacross --symbols fut:XCME:ES \
  --bar-interval 1d --inputs Fast=20,Slow=200 \
  --date-from 2020-01-01 --date-to 2024-12-31 \
  --initial-capital USD100000 \
  --commission-per-share 2.50 --slippage-ticks 1 \
  --report on --plate full --color never --chart lines \
  --equity-sampling bar \
  --results-dir results/learning/cross \
  --export results/learning/cross.algorun \
  > results/learning/cross.txt 2> results/learning/cross.log

--plate full requests the full set of report plates, --color never keeps escape sequences out of saved text, and --chart lines gives a portable text chart. On a suitable terminal, use --color auto --chart braille for the usual interactive display. Standard output holds the report; standard error holds strategy diagnostics and engine messages. Keep both and check the exit status. A results directory can contain partial output from a failed run.

Under the results directory, index.json identifies the runs. Each successful run writes result.json, trades.csv, equity.csv and report.html. Continuous runs also preserve roll provenance. An .algorun export is the portable, self-contained run set, including the bars read, fills, trades, equity and plots. --equity-sampling bar keeps every equity mark in the CSV; the default daily sampling keeps the last mark of each UTC date. Metrics use every bar regardless of that CSV setting.

Reopen a saved study without fetching data or rerunning a strategy:

bin/algo report results/learning/cross \
  --plate full --color never --chart lines
bin/algo report results/learning/cross.algorun --format json

The HTML performance report is a run result. The HTML and PDF built from this book are documentation; they serve different purposes.

Flags worth learning first

PurposeFlags and convention
Choose code and data--strategy PATH, --adapter PATH, --adapter-inputs Key=Value
Choose instruments--symbols SYMBOL or a comma-separated list; prefer this over the older --symbol alias
Choose the clock--bar-interval 1d, --session rth, --date-from, --date-to
Set strategy parameters--inputs Fast=20,Slow=200; names are the exported input names
Set money assumptions--initial-capital, --base-currency, --commission-per-order, --commission-per-share, --slippage-ticks
Set execution assumptions--simulation-resolution, --limit-fill, --bracket-ambiguity, --include-path, --path-interval
Save and display--results-dir, --export, --plate, --color, --chart, --equity-sampling
Inspect a problem--lifecycle-json FILE, --fills-json FILE, --cache off or --cache refresh
Run a study--config FILE; add --verify to validate the expanded plan before running

Date-only bounds use local exchange dates, with --date-to inclusive and session bounds covering open through close. RFC 3339 timestamps give the exact window start < bar.CloseTime <= end. Use explicit bounds; an unbounded run changes as the archive grows. With --config, only selected flags can override its keys; check bin/algo run -h when converting a command.


Previous: Meet Algolang · Next: Data, decisions, and fills