How to create trading strategies, backtest them and optimize them with just a few clicks?

Wesley Wilian
4 min readApr 12, 2023

--

I am very pleased with the result of the backtest platform I created called triggerbot.io, which I discussed in this article. The new feature now is that it is also possible to optimize the technical analysis parameters of your strategy.

OK, but what does optimizing a strategy mean?

When creating a trading strategy based on technical analysis, we have some conditions that we define based on technical analysis functions.

Technical analysis is a market analysis approach that is based on the premise that prices reflect virtually all available information about an asset. It is used to predict the future price movement of an asset. With this there are the technical analysis functions, such as the use of simple moving averages (SMA), parabolic sar (SAR), relative strength index (RSI), among others.

These technical analysis functions have parameters, for example, moving averages and relative strength index use the time period (which is basically how many points of the price history chart it will consider), there is also the source parameter which basically boils down to what information of the chart points will be considered, in the case of the candlestick chart they can have sources such as OHLC, being consecutively open, high, low, close (referring to the price of the asset in a given period at each point of the chart). There are many other technical analysis functions with more complex parameters than those mentioned here, these were the most basic.

You must be wondering, where does optimization come in? The answer is simple, by varying the parameters of these technical analysis functions, the time period can vary between different values, the source too and many others can enter the equation forming a search space, being a sea of possibilities, forming various possible combinations. Maximizing a value such as profit is the optimization process.

Optimization can maximize some statistic of the strategy, such as profit. So, just form a search space with all possible combinations of the strategy’s parameters and find the best desired value, be it profit, win rate, among others. Simple, right? Not? Maybe a graph will help.

Imagine a simple trading strategy that considers moving averages, one of the simplest, buy when a shorter period simple moving average crosses above a longer period simple moving average, and close the position when the opposite occurs. This strategy can be represented with the image below, where conditions and actions are connected.

Visual representation of a simple moving average crossover strategy

Finally, time to optimize this strategy, in the optimization request, we can specify the desired range of values for the parameters of each technical analysis function that we addressed previously, thus, the time period and the source. The following image displays the range of values of the optimization request of this example. It was requested to maximize the profit value of the strategy considering the Google stocks with the ticker GOOG, the search space of this optimization is of 6400 iterations.

Definition of the search space of the optimization request

We’ve come so far, where is the result of the optimization?

This is the good part, in addition to the backtest statistics of the best strategy found, a parallel coordinates chart of the entire search space with all dimensions is presented. Yes that’s right, each dimension is the same thing as a parameter of the technical analysis function, this makes it possible to extract insights from the strategy of what may make sense or not. The image below shows the parallel coordinates chart of the optimization result.

Parallel coordinates chart showing the result of each optimization iteration

Always take into account overfitting as well, tests with partial periods are advised, for example optimizing 80% and testing with the remaining 20% of the time series. Otherwise, the optimized strategy may not generalize well to new datasets, such as future data.

Interested?

The optimization and backtest features can be easily used on the platform, access triggerbot.io and check it out.

And of course if you have any feedback/suggestions to make the platform better, please let me know!

Thanks!

--

--

No responses yet