Skip to Content
NeurotraderDocs
Tutorials

First plugin

A walkthrough from the plugin skeleton to an algorithm of your own, built, added to Neurotrader and running in a simulation.

In this tutorial you take the plugin skeleton, make it your own, build it, add it to Neurotrader and run it in a backtest. At the end you have an algorithm called My Trend under Your algorithms and a finished run whose orders you can inspect.

The strategy is deliberately simple: buy when the price crosses above its moving average, and sell when it crosses back below. The point is the path from source code to a running algorithm, not the rule.

It takes about half an hour. Most of that is the first build.

Requirements

  • Neurotrader installed and signed in. See Installation.
  • Rust 1.85 or newer, with cargo on your path. Install it from rustup.rs.
  • On Windows, Microsoft's C++ Build Tools. Rust needs them to link a library.
  • git, or a browser to download the skeleton as an archive.

No toolchain on this computer

The Assistant page in the app can install Rust and the C++ Build Tools for you. Open Assistant, choose the toolchain button at the end of the toolbar, and choose Set up. See Algorithm Assistant use.

Check the toolchain:

cargo --version
rustc --version

Walkthrough

Skeleton copy

The skeleton is a public project made to be copied. Clone it into a folder of your own:

git clone https://github.com/sigmastone-io/neurotrader-plugin-skeleton.git my-trend
cd my-trend

It holds three files that matter:

FileDescription
Cargo.tomlThe package, built as a dynamic library
src/lib.rsOne line that publishes the algorithm to the engine
src/trend.rsThe example algorithm

Package name

Neurotrader files a plugin under its package name, so give yours a name of its own. In Cargo.toml, change the two names:

[package]
edition = "2024"
name = "my-trend"
version = "0.1.0"

[lib]
name = "my_trend"
path = "src/lib.rs"
crate-type = ["cdylib"]

Leave the rest of the file as it is, including panic = "unwind" under [profile.release].

Algorithm identity

Every algorithm has an id, a UUID that you choose once and never change. Simulations and run records refer to the algorithm by it. The skeleton's id belongs to the skeleton, so generate a new one:

[guid]::NewGuid().ToString()

Open src/trend.rs and put your UUID into id():

pub fn id() -> AlgorithmId {
    "paste-your-uuid-here".into()
}

In definition(), in the same file, change the name the app shows:

name: "My Trend".to_owned(),

Default period

Make one change to the strategy so the plugin is yours: a slower average. In src/trend.rs, change the default window from 20 candles to 50 in both places it is stated.

In impl Default for Parameters:

impl Default for Parameters {
    fn default() -> Self {
        Self { period: 50 }
    }
}

In the parameter schema inside definition():

"default": 50,

The first is what an instance uses when no period is given. The second is what the parameter form in the app shows. Keep them equal.

Read the rest of trend.rs while you are there. It is a complete algorithm in about 300 lines: parameters, a refusal in validate, a declared moving average, an order in step and a piece of state that survives a pause. Plugin authoring explains each part.

Build

cargo build --release

The first build downloads and compiles the SDK and its dependencies, and can take several minutes. Later builds take seconds.

The result is one file in target/release/:

PlatformFile
Windowsmy_trend.dll
Linuxlibmy_trend.so
macOSlibmy_trend.dylib

Build on the same kind of system the engine runs on. A library for another platform is refused.

Plugin upload

  1. In the app, open Algorithms.
  2. Under Your algorithms, choose Add algorithm.
  3. Choose Upload a package, then Next.
  4. Choose the library file from target/release/, then Next.
  5. Check the review and choose Add algorithm.
Screenshot
The Add algorithm dialog on its second step, Where, with the file my_trend.dll chosen and its size shown, and the note that the engine checks the package in a separate process before it keeps it

The engine checks the library in a separate process, keeps a copy and loads it. A message says Added My Trend, and the algorithm appears under Your algorithms with a green dot and the state Available.

Screenshot
The Algorithms page with My Trend selected under Your algorithms, showing the Available state, and the detail pane on the right listing the Period parameter with its default of 50

Select the row to open the detail pane. It shows the description, the Period parameter with its default of 50, and the library the algorithm came from.

You can do the same with the API:

curl -X POST "http://127.0.0.1:8080/v1/plugin/upload" \
  -H "Authorization: Bearer $TOKEN" \
  -F "package=@target/release/libmy_trend.so"

Simulation

Now run it over historical prices.

  1. Open Simulations and start a new simulation.
  2. Details: name it, keep Single account, and choose USDT as the primary quote asset.
  3. Balances: give the account 10,000 USDT.
  4. Data: add BTCUSDT with a one-hour interval over the last two full years.
  5. Algorithms: add My Trend from the catalog. Leave Period at 50.
  6. Review: create the simulation.

My Trend trades exactly one instrument. With two data sources the run is refused before it starts with the message your validate returns: "Trend trades exactly one pair, but it was given 2."

Start the run. Neurotrader downloads the candles the first time, runs the algorithm over them and records the run.

Screenshot
A finished run of the My Trend simulation on BTCUSDT hourly candles: the four summary figures, the net worth line, and the candle chart with buy and sell marks and the SMA 50 line drawn over the price

Result check

Open the run and check that the algorithm did what the code says:

  • The candle chart carries a line labelled SMA 50. That is the indicator you declared, recorded by the engine at every step.
  • Every buy mark sits just after the price closed above the line, and every sell just after it closed below.
  • No order filled on the candle that triggered it. Each one filled at the open of the next candle.
  • For the first 49 candles nothing happens. The average has no value until its window is full.

If the marks do not match the rule, the code is wrong, whatever the return says. Reading the orders is the real test of a plugin.

Change and rebuild

The loop from here is: edit, build, upload again.

  1. Change the code and run cargo build --release.
  2. In Algorithms, choose Add algorithm and upload the new file.
  3. The dialog says the name is taken. Choose Replace it.

The plugin keeps its place in the catalog, and the simulation you set up keeps working, because the algorithm's id did not change. No restart is needed. If a run is using the plugin at that moment, the upload is refused until the run ends or you stop it.

If you would rather have the engine build from your project folder each time, link the project instead of uploading. See Plugin upload.

Next steps

Limits of a backtest

A plugin that did well on past prices can lose money on live ones. Nothing here is investment advice, and what your algorithm trades is your responsibility.

On this page