I created NextTrade: An open-source automated trading platform

Austin Starks
5 min readSep 23, 2022

--

I created a framework for creating automated trading strategies using a UI. Using this framework, users can create trading strategies, combine them to form complex strategies, and optimize them to find the best set of hyperparameters. Afterwards, the user can deploy the strategies for paper-trading with the click of a button.

This project is intended for people who want to create trading strategies using a UI, but don’t want to use an online service like Pluto. It provides a great baseline for a fully functional trading platform. Lastly, the system is extensible enough to create custom strategies by extending the AbstractCondition class.

Example

The rest of this article describes an example of how to create, optimize, and deploy a simple moving average trading strategy. This example assumes you’ve read the README, cloned the repo, set the environment variables, and turned the system on. You will also need to get an API key from Tradier. Navigate to localhost:3000 and do the following to create a strategy.

Register or login

You first need to create an account. An important thing to note is that all account information is saved locally. You can put the email as a@b.com and the password as 12345678. It doesn’t matter, as long as you create the account and remember the password.

Registration Form

Create a simple buy only strategy

On the home page, click My First Portfolio.

Portfolio List Page

This leads you to the Portfolio Dashboard. The dashboard shows you your current portfolio, it’s price history, your current positions, as well as other cool features that we will discuss later. For now, click Edit Strategies.

Portfolio Dashboard

We’ll create a simple strategy to start. Our strategy will spend 100% of our buying power on SPY when any of its buying conditions are met. This looks like the following picture.

Buy-only strategy

Adding Buying Conditions

Our buying conditions in this example will be simple, but in real-life, can be extended to be a lot more complex. Our strategy will trigger if:

  1. We have not bought a stock in 30 days
  2. SPY is 1 standard deviation below its 30 day average price

Click on 0 Buying Conditions -> New Compound Condition -> And Condition. Afterwards, add the two simple conditions like the following:

Compound Condition — returns true if all conditions are true

Click SUBMIT, then voila! Your first trading strategy was created.

Backtest your strategy

Navigate back to the Portfolio Page. Click the backtest button, set a date range.

Backtest Builder

Click RUN, and the system will run a backtest using your strategy.

Backtest performance

You can see how the strategies performed over time. The red line in the photo is how the portfolio performed, and the grey line is how SPY performed in the same time period.

Optimize Strategy using a Genetic Algorithm

The most powerful part of the trading platform is the ability to optimize the strategies and find the best set of hyperparameters. It’s possible to generate hundreds of strategies better than yours with just the click of a button. Here’s how.

Click Optimizer.

Optimizer Builder

Keep the default settings and click SUBMIT.

Optimization Page

This runs hundreds of backtests in the backend, and continuously chooses the backtests that yields the highest return (sortino ratio).

After some time, the optimization will terminate, leading to a collection of “optimization vectors” that make up an “optimization state”.

Edit Portfolio using an Optimization Vector

Expand an optimization vector. Click on a strategy to view the vector in more detail.

View Optimization State

Click EDIT to replace the current portfolio’s strategies with the optimized portfolio’s strategy.

Deploy the Portfolio for Paper Trading

After we developed the perfect strategy, we’re ready to deploy it. Click Settings, Active, and then SAVE to deploy the strategy with real-time data!

So what did we just do?

Using this platform, we were able to create a simple trading strategy and optimize its hyperparameters. The optimizer does this by running hundreds of backtests in the backend, and continuously evolving the hyperparameters. We were then able to deploy the strategy for real-time paper trading.

Final thoughts

While this example was overtly simple, we are able to add conditions together, create complex strategies, and optimize all of them together.

This system is over 25,000 lines of open-source code and took me over 2 years to develop. It was developed primarily for myself, but I thought this system it was a great time to introduce the system to the open-source community.

Thanks for reading! If you made it this far, you must have found this article enjoyable. Feel free to connect with me if you have any questions about the system or would like me to write about something in particular :)

--

--

Austin Starks

https://nexustrade.io/ Highly technical and ambitious. Building a no-code algotrading platform and an ecosystem of AI applications. https://nexusgenai.io