Algorithms
Algorithms in the catalogue and algorithm instances in a simulation: labels, parameters, indicators, and the built-in, plugin and remote kinds.
An algorithm is the set of rules that decides when to buy and when to sell. When you set up a simulation you pick algorithms from a catalogue and give each one its settings. This page explains the difference between an algorithm in the catalogue and an algorithm in a simulation, what you can configure, and where algorithms come from.
Catalogue entries and instances
The word "algorithm" covers two things, and it helps to keep them apart.
A catalogue entry is an algorithm as the engine knows it: its name, its description, the parameters it accepts and the indicators it reads. SMA Crossover is a catalogue entry. The Algorithms page lists every entry.
An algorithm instance is one use of a catalogue entry inside one simulation: the entry, plus the parameter values you gave it, the data sources it reads and, optionally, a label. An instance belongs to its simulation. Changing its parameters changes nothing in the catalogue and nothing in any other simulation.
Results are always reported per instance. In a comparison, each row of the results table is one instance.
The same algorithm added twice
Because an instance is a use of an entry, you can add the same algorithm to a simulation more than once. Each instance has its own parameters and its own data sources.
This is how you tune a strategy. Create a comparison, add SMA Crossover three times with different periods, and the run shows which settings did best. It is also how you compare one strategy on two instruments: add it twice and link each instance to a different data source.
Labels
A label is the name of an instance. You enter it in the Label field of the Add algorithm dialog, above the parameters.
A label is not a parameter. It does not change what the algorithm does. It
tells two instances of the same algorithm apart in the simulation's list, in
the results and on the charts, so use it to say what is different about the
instance, for example SMA 9/21 and SMA 20/50.
- In a comparison, the label is optional. An instance without one is shown under the algorithm's own name.
- On an account that several algorithms share, the label is required. It must
be unique on that account and cannot contain
/,.or@. See Algorithm groups. - In an instrument sweep, the app labels each copy with the instrument it trades.
Parameters
Each algorithm declares its own parameters: their names, their types, their defaults and their limits. The app builds the parameter form from that declaration, so every algorithm, including one you wrote yourself, gets a form that fits it.
What to expect from the form:
- Defaults are filled in. A new instance starts with the algorithm's default values. You can add it without changing anything.
- Required parameters are marked. A required field left empty shows Required. and the instance cannot be saved.
- Optional parameters can be left empty. An empty optional field is not sent at all, and the algorithm uses its own behaviour for a missing value. For some parameters, empty has a meaning of its own: an empty Drift Band on Constant Mix means the algorithm rebalances on its schedule only.
- Limits are checked as you type. A value outside the declared limits shows a message such as Must be at least 2. or Must be greater than 0. A whole-number parameter refuses a fraction.
- What you see is what runs. The app sends every value the form shows, defaults included, so the settings recorded with a run are the settings you read on the screen.
An algorithm with no parameters, such as Buy and Hold, shows no form.
To change the parameters of an instance later, select its configure button on the Algorithms card. The change applies from the next run. Each run keeps a copy of the setup it used, so earlier runs still show the parameters they ran with.
Some rules connect two parameters, for example a slow period that must be longer than the fast one. The engine checks these when the run starts and reports the reason if it refuses.
Data read by an instance
Each instance reads the data sources you link it to. Some algorithms have requirements: Buy and Hold trades exactly one instrument, and Equal Weight needs at least two, all quoted in the same asset. An instance whose data does not fit its algorithm is refused when the run starts, with the reason. See Data sources.
Origin of an algorithm
The Algorithms page shows the catalogue in two groups, Your algorithms and Built-in.
- Built-in algorithms ship with Neurotrader. They include yardsticks such as Cash and Buy and Hold and well-known indicator strategies such as SMA Crossover and Donchian Breakout. See Built-in algorithms.
- Plugin algorithms are algorithms you write in Rust with the Neurotrader SDK and add to the engine as a library, either as an uploaded package or as a linked project the engine builds. One library can carry several algorithms. See Plugin upload and Plugin authoring.
- Remote algorithms are programs of your own, in any language, that the engine calls over HTTP or WebSocket on every step. You add the built-in Remote algorithm to a simulation and give it your program's URL. See Remote algorithms.
All three kinds receive the same information on each step and run in the same way. A simulation can mix them.
An algorithm from a library also shows whether it can run:
| Availability | Meaning |
|---|---|
| Available | The library is loaded. The algorithm is ready to run. |
| Not loaded | The library is in the catalogue but not loaded. Load it to use the algorithm. |
| Failed to load | The engine could not load the library. The details pane gives the reason. |
| Building | The engine is building the linked project. |
A simulation that uses an algorithm which is not available does not start, and the message names the algorithm.
Indicators
An indicator is a value calculated from the candles, such as a moving average. An algorithm declares the indicators it needs, and Neurotrader calculates them and hands the algorithm the current values on every step. The details pane of the Algorithms page lists what each algorithm declares.
The available indicators are the simple and the exponential moving average (SMA, EMA), Bollinger Bands, the relative strength index (RSI), the rate of change (ROC), MACD, the Donchian channel and the average true range (ATR).
Because the engine calculates the indicators, it also records them. A run's charts draw the indicator values the algorithm read, next to the candles and the orders, so you can see why it traded when it did.
An indicator has no value until it has seen enough candles: a 21-candle average needs 21 candles. In a backtest, an algorithm therefore does not trade during its first candles. In a live run, Neurotrader fills the indicators from recent history before the first live candle, so the algorithm can act from the start.
Related
- Algorithm setup
- Algorithm groups: several algorithms on one account
- Built-in algorithms
- Plugin authoring
- Remote algorithms
list_algorithmsin the API reference
Data sources
The market data a simulation reads: instruments, providers and venues, the range and interval every source shares, and where the candles come from.
Algorithm groups
Several algorithms trading one account together as a single algorithm: how a group shares the balance, what it reports and where it runs.