Abstract
Trend following strategies have a wide-ranging role in quantitative trading fields, which can capture important unilateral market trends for large gains, while this is vulnerable to losses in the period of consolidation. In this paper, we explored the trend trading system in the Chinese futures market based on machine learning techniques and statistical methods. This research utilized the Long-Short-Term Memory network to extract features of time series then predicted the price movements by Machine Learning classifiers. Moreover, based on rebar futures data, the results reveal that the annualized return improved from 6.39% to 15.68% after the trading signals generated in the trading strategy were filtered using the XGBoost model. Also, futures on gold and soybean were used to further test the integrated strategy and the results of the experiment show the effectiveness of the model in filtering false trading signals.
Introduction
The new field of quantitative trading combined with computer science technology has been well developed in recent years, with people using data mining and artificial intelligence to integrate technical analysis in the stock market to build profitable portfolios [1]. Such techniques as artificial neural networks [2], swarm intelligence [3] and evolutionary algorithms [4] have been applied to financial markets in a variety of ways. The price fluctuations of financial investment products such as stocks, commodity futures and hedge funds in the capital market are always uncertain. It is a mathematical state of random walk containing natural noise. Stakeholders try to challenge the construction of reliable forecasting models in order to gain higher returns on their portfolios while reducing investment risk. Predictability of the stock market is of interest to investors in the field of quantitative analysis. For example, one way for predicting the future movement of stock prices and optimizing investment strategies is combination of classical trading strategies (e.g. the turtle trading method) and Machine Learning (ML) algorithms [5].
Many researchers have conducted study on ML-assisted quantitative investment, this seems to have put forward many new methods. Zhang and Wang [6] construct a quantitative trading system based on Support Vector Machines (SVM) for CSI 300 stock index, also predict its up and down trends and transform them into trading signals. In the back-testing results, it is shown that the trading system performs better in the profit-loss ratio and the model can have stable characteristics in profitability in storming. Also, Vats and Samdani [7] applied Neural Networks, Support Vector Machines, Multiple Kernel Learning, Random Forest Method and K-Means Clustering techinique to stock market forecasting. They demonstrated that both clustering and non-clustering techniques can perform well in terms of prediction performance. The paper also summarizes the computation speed and efficiency of each model and makes it evident that machine learning is feasible when applied to stock trading in real-time. Similarly, Deep learning (DL) techniques are employed to study the mechanism of arbitrage trading. Long shape et al. [8] proposes the use of cointegration test in time series analysis with Long-Short-Term Memory(LSTM)-based method for spread trend forecasting for ferrous metal futures (including coke, iron ore and rebar). The empirical analysis shows that LSTM is superior to BackPropagation (BP) neural network and Recurrent Neural Networks (RNN) in terms of time series forecasting performance, and the comparison of four trading strategies reveals that LSTM neural network generally achieves better returns in back-test period. On the other hand, Hidden Markov Model is an important probabilistic model about time series in machine learning algorithms, also, it is a black box model that can be applied to predict the hidden state of commodity futures markets. However, it has the disadvantage that investors cannot directly know whether the current state is a buy state or a sell state. As such, the McCulloch-Pitts Neuron (M-P) model, which is able to predict the direction of trading, has an advantage over the former. The empirical results state that using quantitative strategy based on M-P neuron model in A-share market can improve the benchmark return by 31.11%, see Zheng shape et al. [9]. The above researches focus on the optimization of traditional quantitative trading strategies by machine learning or deep learning, allowing trading systems to be more competitive in the financial markets.
Trend following strategy is an essential part of traditional quantitative trading system, which is a dynamic channel strategy designed for short-term trading based on technical indicators [10]. Yet, there are some limitations to the performance of trading strategies based on technical indicators in a volatile futures market [11]. For instance, moving averages which are foundational indicators in trend following strategies, suffer from misleading crossing signals [12]. Likewise, the Donchian channel is subject to the problem of false trading signals. Richard Donchian, known as the “Father of Trend Following”, developed the Donchian channel indicator in the mid-20th century to help traders identify whether a price movement was likely to continue or reverse its direction [13]. Thus, the Donchian trading strategy is classic trend trading, a simple but versatile technical indicator. It usually consists of three moving averages, upper and lower bands around a midrange or median band. Regarding its trading pattern, the Donchian channel indicator can recognize some price breakouts and thus generate trading signals. Not only that, such a price channel can detect the trend, market swing highs and lows, support and resistance levels, market volatility and spotting breakouts [14]. In addition, Swart [15] used a trend-following trading strategy based on Donchian channel for portfolio optimization in the study of the South African futures market. In the empirical evidence, it is found that the strategy can generate high returns in most cases, but lacks well-stable returns in long-term investment and shows inferior tolerance in the face of market risk.
According to the issues raised in the works of literature, the motivation case is presented in Figure 1. Although Donchian channel can identify some trading opportunities, the strategy is not always applicable in the intricate futures market. For example, when the width between channels is narrow and there are short-term market shocks, it is difficult to capture the price trend of futures. Frequent price breakthroughs of the channel would potentially cause the system to successively buy at high prices and sell at low prices, consequently resulting in continuous losses and high transaction costs. This explains the problem of false breakthroughs of the channel. Therefore, Donchian channel generates false trading signals during reversal and oscillation periods as one of the reasons for its poor returns.

Motivation case.
To address the shortcomings of the trend following trading system described above, we use machine learning techniques to explore the changing patterns of price sequences. According to the past price trajectory, to classify and predict the rise and fall of futures prices using technical analysis and financial time series analysis. In addition, the LSTM-based method extracts features from selected technical indicators and trading data [16], and the resulting output is used as learning features for the ML classifications. Meanwhile, trend trading strategy also generates trading signals which are compared with the direction of closing price movements predicted by ML, and if the two produce the same direction then it guides investors to make a corresponding buy or sell action. Although the combined signals might have the potential problem of timeliness [17], i.e. waiting for technical indicators and the predictor to point in the same direction, the combined signals are fairly reliable in long-term investing, especially in price consolidation. In general, this is the main concept we propose to eliminate filter false trading signals and enhance the overall performance of the system.
Overview, this paper will explore the application of computational intelligence in quantitative trading by using trend following trading system based on LSTM-extracted features and machine learning. First, the information transferability of LSTM neural networks is utilized, this technique is applied in feature extraction to improve ML predictors. Second, the tradable nature of AI technique combined with technical analysis is confirmed by implementing ML-based trend trading systems. In addition, we expect that the introduction of ML and DL can lead to a stronger predictability of technical indicator trading system, and such a hybrid model can solve the problem of false signals, which is prevalent in traditional trend trading. Ultimately, the trading signals filtering approach proposed in this paper can improve the profitable returns of the portfolio, it can maintain stable returns to cope with the shock period of the equity market, and improve the risk resistance of the strategy.
The remainder of this paper is organized as follows. In Section 2, the LSTM technique and LSTM-based feature extraction are proposed. Among them, Section 3 describes the prediction method of future price trends based on ML and a trend trading strategy, the combined system is also presented. In Section 4, experiments are given to show the effectiveness of the ML-based trend trading system. Experimental results of testing the system using rebar, gold and soybean futures are presented in Section res. Finally, conclusions are drawn in Section 5.
Futures, as a financial derivative, are used primarily to hedge against the risks posed by the spot market. Futures are a standardized contract developed from a forward contract, which is a contract with someone to purchase a forward commodity for the purpose of hedging. A futures contract is an agreement in which the buyer agrees to receive an asset at a specified price after a specified period of time and the seller agrees to deliver an asset at a given price after a period of time. The price that the parties agree to use for future transactions is called the futures price. The specified date on which the parties must trade in the future is called the settlement date or delivery date. This subject matter can be a certain commodity (e.g. gold, crude oil, agricultural products) and the date of delivery of the futures can be a week later, a month later, or even a year later. After the expiration and the existence of the spot price of the underlying, the difference between the two prices multiplied by the number of contracts is the respective profit and loss. This is a simple explanation of how futures trading works. It is very important to note that we use the continuous and most liquid contract. Most futures contracts have a delivery period, and usually, the longest contract term is no more than one year. The most liquid contract is the most active and easily traded contract in the market, i.e. the one with the highest volume. According to the Shanghai Futures Exchange, for example, the most liquid contract is defined as the January, May, and October futures prices of the rebar contract each year. When the most liquid contract is close to the delivery date, it will change to the later contract, so that it will never be delivered, making it easier for traders to research. For example, if it is November 2021, the most liquid rebar futures contract at this time will be January 2023; the most liquid contract will be May 2023. On the other hand, according to the long-term pattern of market changes, the futures contract one month to four months after the nearest delivery month is the closest to the expected spot price and is the most actively traded. Such contracts are then linked together to form a continuous price series, which is a continuous contract. Thus, for example, in the case of the continuous and most liquid rebar contract, such contract data is a long-term price series made up of the January, May, and October futures prices for each year. The advantage of using this is that the backtest results might be closer to the actual trading situation. Today, the futures market has matured and futures exchanges, margins, opening and closing positions, etc. have become an important part of the operation of the futures market. Technical analysis is a financial market analysis method that applies the simplest laws of supply and demand changes in the financial market to find and figure out a set of analyses of market trends and predict future market trends.
Technical analysis relies on historical price and volume information to predict stock market trends, such as technical indicators [18]. The use of technical indicators for trend trading has been proven to be one of the most profitable tools by many traders and has been used as an indicator for stock buying and selling signals [19]. Han shape et al. [20] provides evidence that using a simple moving average timing strategy when constructing a commodity futures portfolio can be very robust in the U.S. commodity futures market. Clare [21] has also demonstrated that these trend trades can generate significant average excess returns in the U.S. commodity futures market using a variety of trend following strategies. However, some researchers have found that technical analysis performs differently in the Chinese futures market than in other countries or regions. Because China has an unique futures market partten, individual investors make up the majority of investors in the Chinese futures market. Thus, Li [22] indicates that trend-following strategies applied in the Chinese futures market do not perform as well as those in the U.S. futures market, as reflected by the lower average annual excess returns in the former. Whereas the problems pointed out by the academics are consistent with the aspects of interest to us, we attempt to explore the Chinese futures market in depth. Therefore, in order to make the trend strategy perform better, this paper will introduce Machine or Deep learning techniques to achieve higher profits.
The advantages of Machine or Deep learning are also obvious. Compared to traditional technical indicator strategies, despite the latter’s trend predictability, such strategies are difficult to combat in the face of complex market fluctuations from a long-term investment perspective. On the contrary, with the boom in computer intelligence, a diverse range of forecasting models have been introduced. For the large amount of non-linear data generated in the equity market, the hidden patterns and complex relationships need to be identified by more efficient models. It has been demonstrated that ML techniques can increase the efficiency by 60-86% compared to technical or fundamental analysis [23, 24].
At present, Artificial Intelligence (AI) technologies are rapidly evolving in various fields. Many AI-based trading rules are being applied to the global equity market, such as combining technical analysis and Machine or Deep learning for trading, in an attempt to use these techniques to augment the already popular and widely used traditional algorithms. Sang [25] experimented with trend indicators for forecasting, such as Simple Moving Average (SMA), Relative Strength Index (RSI), and Moving average convergence divergence (MACD), and introduced LSTM in each of these three technical indicators trading methods for experiments. The empirical evidence shows that the total profit is significantly improved after applying the neural network in traditional technical analysis. More, Ayala [26] proposes a decision process that combines technical indicators with machine learning methods to generate a trading decision. The models are trained in Linear Model (LM), Artificial Neural Network (ANN), Random Forests (RF) and Support Vector Regression (SVR) and the one with the highest predictive power is selected. Also, the Triple Exponential Moving Average (TEMA) and Moving Average Convergence/Divergence (MACD) strategies are compared separately. The best-performing ML model and technical indicator strategies are selected, combined and new trading rules are proposed. The empirical results show that the hybrid model increases the profitability of each strategy and reduces the number of trades.
In summary, numerous researchers have discovered the strong power contained in neural networks in quantitative finance and have demonstrated the feasibility of neural networks in predicting stock and commodity futures prices through many experiments. However, this does not generalize that the price prediction performance of neural networks is better than traditional technical indicators, and the performance of ML techniques cannot be denied because deep learning techniques are popular. Therefore, in this paper, we decided to more precisely exploit the characteristics of the information transfer method of LSTM neural network and use it to make reasonable extraction of data features. In addition, the underlying machine learning model is used as a predictor to predict the direction of futures price movement. Thus, we use Machine and Deep learning techniques to enhance the ability of traditional technical indicators to predict trends.
Materials and methods
Background method
Theory of Long-Short-Term Memory network
LSTM is a neural network, a variant of Recurrent Neural Network (RNN), that can be used to process time series and has the ability to remember long and short-term information [27]. It combines short-term memory with long-term memory through gate control to solve the long-term dependence of RNN due to the issue of gradient vanishing and gradient explosion [28]. The main reason for gradient vanishing is the requirement to compute recursive derivatives. LSTM can solve and allow the learning between arbitrary long-distance dependencies. In brief, it means that LSTM is able to have better performance in long sequences compared to RNN. Further, the gate mechanism of the LSTM is possible to regulate the flow of information, which removes or modifies the information of cell states. Providing a path for information to be passed down selectively, it consists of sigmoid layers, hyperbolic tangent layers and point-wise multiplication operations [29]. LSTM introduces computable memory units that can effectively associate memory and input remotely, and are therefore suitable for dynamically grasping the structure of data over time with a high degree of predictability [30]. The key components of each cell are an input layer, a hidden layer and an output layer. Figure 2 illustrates the LSTM architecture at time t.

Long-short-term memory network and each memory unit.
The detail equations are given:
It is worth noting the calculation of the cell state
In this paper, we use a feature extraction method via LSTM-based networks to reduce data dimensionality and extract useful features from cluttered information. The inputs include historical price series of futures, technical indicators and time series features extracted from the price series. These inputs will be further processed by the LSTM, and the extracted outputs are used as learning inputs for the ML classifiers. Eventually, we use these extracted effective features to train the ML models and predict the up and down trend of futures prices.
Our LSTM neural network organized according to the nature of the input features and the applicability of the output features is shown in Figure 3.

LSTM-based feature extraction mechanism.
An input layer, two LSTM layers, a dense layer follows by each LSTM layer and an output layer are the essential components of the network structure. However, the neural network has two potential problems that may affect the training task of the model. One is the gradient vanishing which results in convergence difficulties, and the other is the issue of over-fitting which leads to poor performance on the test set. Therefore, in this paper, a layer of Dropout is added after the LSTM layer, i.e., a pre-determined number of neurons are randomly allowed to stop working at each training time, with the aim of improving the power of the LSTM network [32]. It is worth noting that although the input data has been extracted by the computation of LSTMs and Dropouts, features still need to be flattened by a fully-connected layer then achieve feature crosses. Hence, the output after this step is used as the learning features for the following ML classification models. The second fully connected layer and the activation function are introduced for training purposes.
Trend-following trading system based on machine learning
We construct a trend following trading system based on ML technique for the following three steps: 1) construction for ML predictor, aiming to predict price up and down trends using historical data of futures. The specific process is discussed in Section 2) trend trading strategy construction, using the strategy to generate trading signals. The main ideas are mentioned in Section 3) combination of trend trading strategy and ML classifiers. The new trading rule uses the predicted values generated in step (1) to compare with the trading signals from step (2), in order to filter the trading signals with the ML-based models. The specific ideas we propose are addressed in Section 3.2.4.
In general, the specific process is shown in Figure 4.

Trend-following trading system based on machine learning construction process.
First, the general framework of price prediction needs to be organized. Historical data for a certain time period of the futures is acquired as raw material, which is subsequently used for label and feature set creation. Specifically, increase/decrease ratios are calculated by closing price sequences, the threshold for determining ups and downs introduces a full-stop mechanism. Placing the protective stop loss is commonly adopted in the writing of trading strategies. Then the forecast target is mapped to two classes (Up, Down) to create the labels, this allows samples to be fed into the model in order to perform a binary classification task. The formulae are
Further, technical indicators calculated from futures data can be used as one of the feature sets. In addition, the historical trajectory dataset can be extracted as various time series features, since observable properties in the time domain are often referred to in the field of financial mathematics. Finally, three groups of data are selected as the input feature sets for ML models, namely, raw data, technical indicators and time series features. Afterward, LSTM neural network is employed to extract the information from the feature set. The dataset is divided into training and test sets in chronological order, followed by normalization of the sample sets respectively, then they are used in six different ML classifiers for training, prediction and evaluation.
After the framework of the predicting model is determined, the next task is to write a trend following trading system. Investors believe that historical data can provide an indication of future price movements, so trading rules derived from technical analysis have become a focal point for many traders [39]. Thus, this paper employs parameters from general traders’ practices in the design of the trading rules. A trend-following trading system is written using the basic principles based on Donchian Channel indicator. We introduce the Donchian Channel design system, which empirically fixes a period parameter to plot the channel trajectory. At last, the trading signals generated by this step are combined with ML forecasts to obtain the final trading direction. The feasibility of this machine trading system can be evaluated by backtesting in a variety of criteria for larger gains.
Futures’ price movements are in accordance with the nature of financial time series where asset values evolve over time. Hence, machine learning classification model is able to capture the trading signals of price rise and fall. The overall construction process is shown in Figure 5.

Structure of ML-based cassificatin model.
We first obtain historical price data of futures, containing 5 attributes, closing price, opening price, highest price, lowest price and trading volume. The acquired price and volume sequences are raw data, being used in the procedure to create two-class labels for the forecast targets. At the stage of feature engineering, it should be noted that if only the raw data is used as the feature set to train the model, results might expose the underfitting drawback due to poor learning ability and low complexity. Thus, feature set needs to be made up of technical indicators and time series features, these are calculated from the price information. The use of technical analysis to predict futures price trends is due to some of its advantages. For example, it has a wide range of use and is absolutely valid for all types of trading. Therefore, we refer to the method of Dvoryatkina [34], which uses technical indicators as features and calculates them through the open source TA-Lib library [35]. Similarly, the characteristics implied in the time series are equally important. For example, the Autoregressive Conditional Heteroskedasticity method involves variance and volatility in predicting stocks. Therefore, in this paper, we use TsFeatures to calculate the relevant features for time series analysis and demonstrate their validity in subsequent experiments. Together with the raw data, there are three sets of features in total, such a dataset is huge. However, it is not the case that more features mean the model can learn better, the selection of the right set of features can help the model prediction performance. We design experiments to compare the combinations of feature groups and select the optimal combination as the input data in the feature extraction step. Since the feature dimension of each time sequence is large, the input data of the model may increase the computational complexity, we carry out LSTM neural network to extract the features so that the original 112-dimensional input data is reduced to 16-dimensional output. In consideration of the strong time-series nature of futures prices, the dataset partitioning method of random sampling is not suitable. Accordingly, we use the sliding window method to divide the dataset after feature extraction [33].
Subsequently, Z-Score standardization is applied in order to unify the magnitudes of the feature sets. At the stage of predicting, this paper uses six machine learning models as classifiers to predict price trends of futures, including Logistic Regression (LR), k-Nearst Neighbors (KNN), Naive Bayesian Classifier (NBC), XGBoost, CatBoost and LightGBM Classifier. In comparing the performance of the classification tasks, the use of a confusion matrix to calculate Accuracy (ACC) and F1-Score is also required to evaluate the prediction results.
The Donchian Channel Indicator evolved from the Turtle Trading Rule, a powerful trend-following indicator developed by Richard Donchian in 1950. It has stood the test of time in the long history of the financial trading markets as a tool often used for commodity prices and stock trading as well. The principle of the Donchian Channel is not complicated. When the price trades between the middle and top of the channel, it represents that the trend is rising. When the price trades between the middle band and the bottom of the channel, it indicates that the trend is down [36]. In this paper, we use two channels, the upper and lower bands, which are calculated as follows,
The trading rule governing the system is that a buy signal is given if the latest price breaks the upper band upwards. Conversely, if the latest price crosses the lower band downwards, a sell signal is given. Meanwhile, the strategy needs to consider slippage value (the amount of variation between the real deal price and the preset deal price) and the full-stop mechanism, that is, in the case of an already held long or short position, if profit goes up to a certain percentage (such as 1%), we close long or short, which corresponds to the label settings.
A trading system that combines predictors and technical indicators is supposed to have a new trading rule. According to the trading system of Donchian channel, the strategy generates buy and sell signals during the back-test period, here, the long signal is marked as ’1’ and the short signal is marked as ’0’. Using this signal and the ML-based forecaster to produce the predicted value of price movements in an uptrend (’1’ class) and downtrend (’0’ class) for the same trading moment. If both the strategy and the forecaster generate a signal of ’1 ’, then the investor is instructed to buy; if it is ’0’, the investor is instructed to sell. This is the filtering rule for trading signals, only if signals are produced based on Donchian channel and the predictor points to the same direction the position will be taken.
Evaluation of the trading system based on ML method in view of economic performance is also essential. Back-testing allows a comparison of the original strategy performance with that of the filtered strategy. By comparing the win rate, net profit, return, annualized return, maximum drawdown, recovery factor (i.e. ratio of net profit to maximum drawdown), total profit and the total number of trades before and after using the ML-based approach, see Figure 6. We evaluate whether the application of predictive model brings positive economic benefits, and also use these criteria to select the one appropriate for the current strategy from among 6 different ML classifiers, mainly referring to win rate and total profit, in particular.

Systematic combination of machine learning and trend trading strategies.
The experimental setup is divided into three major parts. The first part is feature selection, which is an important step in feature engineering. Its purpose is to select suitable feature groups that are suitable for training the model. Therefore, in this step, we used price data for three and six-month periods to experiment on feature groups consisting of different feature elements. Using F1-measure and Accuracy values as evaluation criteria. The features that fit the model are finally selected and the representative features are listed and explained with examples, the details are in Section 4.2. The second part is the setup of the prediction model experiments. The experimental setup starts with building the LSTM model, and the selected feature sets derived from the experiments in Section 4.2. are fed into the LSTM model. Subsequently, the sliding-window partition method is introduced to partition the dataset from the feature data output in the previous step. Next, the data is normalized and it is explained why we chose to use normalization after partitioning the dataset. After the above setup is completed, we enter the ML prediction session and finally obtain the ML prediction values and evaluation scores. The third part is the parameter setting and strategy backtesting of the Donchian trading system, generating trading signals and backtesting evaluation scores.
After performing the above steps, we obtain the experimental results for the following purposes. First, the F1-score and accuracy performance of six different ML classifiers can help us to select the best-performing predictor at the moment. Second, the trading signals generated by the Donchian indicator are compared with the prediction signals generated by the selected classifier. To obtain the win rate and net profit of the Donchian trading system after using the ML-based signal filter, these two backtest indicators are compared with the backtest results of the Donchian trading system in Section 4.4. The ML-based signal filter is then used to determine whether it helps the Donchian trading system to improve its economic performance.
Dataset
We carried out some comparative experiments on futures in Shanghai Futures Exchange and Dalian Commodity Exchange. Dataset comprised rebar futures with subscription prices, which include data over business days between January 2016 and June 2022. Models were fitted by 108,000 price sequences with 5-minute intervals in total. Also, to further validate the feasibility of our proposed system, we used data from gold (Shanghai Futures Exchange) and soybean (Dalian Commodity Exchange) futures for training models. A key point to add is that all three futures used continuous and most liquid contract data. Two-classe label (Up, Down) was set for the target of prediction.
Feature selection
This dataset not only consisted of 5 basic futures information but also 112 technical indicators calculated based on the TA-Lib (Python wrapper for Technical Analysis Library) and 46 time series features calculated from the TsFeatures packages in Kats (Kits to Analyze Time Series). The representative elements of each category are listed and given a few detailed examples, not all 112 indicators are indicated, as shown in Table 1.
Six categories of technical indicators are discussed here. The most included in the overlapping studies category is the moving average, which is the most common type of indicator in technical analysis. Take the detailed explanation of several indicators as an example [37]. [
[
Momentum indicators are designed to analyze the speed of stock price fluctuations and to study the acceleration, deceleration, and inertia of the fluctuation process and the phenomenon of stock prices turning from motion to static or static to motion. [
Volume Indicators use volume data to calculate the trend of its movement to infer the trend of the stock price. [
The volatility indicator is the degree of volatility in the price of a financial asset and is a measure of the uncertainty of an asset’s return and is used to reflect the level of risk of a financial asset. [
Three feature categories
Three feature categories
Two sets of experiments were designed to select the feature groups. The first set of experiments uses the 6-month period of data as the training set and the 2-month period as the test set. The method of dividing the training set and the test set is the sliding-window method, the specific meaning of which is mentioned in Section 4.3. The second set of experiments uses 13 months of period data as the training set, and again, the test set has a period of 2 months. In other words, the training set with different time lengths is used to train the model, but the same period is tested. Each group of experiments has four variables, ’base’, ’base_kats’, ’base_ta’, ’base_ta_kats’, referring to raw data, raw data and time series features, raw data and technical indicators, and raw data and time series features and technical indicators.
To achieve better prediction, we used the same ML models as the final experimental setup, namely LR, KNN, NBC, XGBoost, CatBoost and LightGBM Classifier, and used F1-Score, ACC and AUC (Area Under the Curve) as evaluation metrics to assist in selecting feature sets. Taking the ‘base’ group of Experiment 1 as an example, six different classifiers were trained using this feature set for a specific time, yielding test set evaluation results from January 1, 2021 to July 1, 2022. In total, there are 10 sets of results, and the performance of the feature set constructed from the raw data in each of the 6 classifiers can be obtained after taking the average of these results. Taking the mean values of all classifiers according to F1-Score, ACC and AUC respectively, the performance of the ’base’ feature group in the three metrics can be obtained. The results of the two experiments are shown in Figure 7.

Experiments for feature selection.
According to the experimental results, the F1 value of the ’base’ group is lower, not yet reaching 0.5, whether using the training set with a size of 13 months or a size of 6 months, and although the AUC value is outstanding, we do not consider the case of using only raw data as features regarding the three metrics. Also underperforming in terms of F1 values is the ’base_ta’ group, which despite being an improvement over the ’base’ group is not comparable to the remaining two groups. From the histogram, the ’base_kats’ group has an average score in the three evaluated scores, which means that it has a good performance in many dimensions. The ’base_ta_kats’ group does not perform worse either, in comparison to specific values, the difference between the two F1 values and accuracy is very small, but the latter has a higher score in terms of AUC. In addition to the above experimental results, the deep learning neural network needs to be trained by a large amount of data, so ’base_ta_kats’ (with 163 dimensions), which is a dataset of historical price data, technical analysis indicators and time series features, was chosen as the feature dataset.
This paper used Python3.7.0, Scikit-Learn for machine learning techniques and PyTorch for deep learning training tasks. The code running environment is shown in Table 2.
System environment
System environment
The general flow of the experiment for the prediction model is shown in Fig. 4. After acquiring the futures price data, features and labels are produced using them. Among them, the produced features need to be feature selected, which is the result of the experiment in Section 4.2, using the ’base_ta_kats’ group as the feature group. Next, these extracted features are output as learning features for the ML predictor. The feature groups and labels are divided into a training set and a test set employing the sliding-window partition method. Subsequently, the two datasets are normalized separately and the learning features are fed into the classifier for training to produce the final predicted values.
First, the main structure of the LSTM network consisted of one input layer, two LSTM layers, each followed by a Dropout layer, and the Dropout rate was set to 0.1, and Softmax was used as the activation function, see in Table 3. We used Mini-Batch method to train the model, a certain amount of the data is selected for training, and then the loss function is calculated and the gradient is updated so that there is no complex computation and the training is avoided being slow. Setting the epoch at 50 and batch size at 32 for training samples. In each epoch, 32 samples were selected from the training set for training until all the data in the training set were trained, then the next epoch was used. The Cross-entropy loss function was applied as a loss function to measure the difference between the output labels and the truth. The parameters were set regarding to Long’s literature [8].
LSTM network construction specific parameters
Second, the way to divide the data into training and test sets was the sliding-window partition method. This is a way of dividing the timeline, which frames the time series according to a specified unit length, one unit per slide. Setting the step size to 2 months and the window size to 13 months, in other words, the forecasts were generated recursively, using a forecast horizon of 2 months. Specifically, the initial data point is December 1, 2016, and the data within 13 months after this date is the first training set, labeled as ’train1’; January 1, 2018 to March 1, 2018 for the first test set, labeled as ’test1’. Likewise, the data from 13 months after the start of February 1, 2017 is the second training set, labeled as ’train2’, and the data from March 1, 2018 to May 1, 2018 is the second test set, labeled as ’test2’. And so on until the entire dataset is divided. The details are shown in Figure 8.

Sliding window dataset partitioning method.
Third, using data from December 1, 2016 to July 1, 2022, the data set was divided into 27 groups using this method, which means that 27 sets of prediction data were generated. After that, Z-Score normalization is performed on the test set and training set respectively, to prevent information leakage. In detail, for the sample sequence x1, x2, x3, . . . , x
n
to be normalized, according to the formula
Eventually, these normalized data were fed into six different ML classifiers for prediction. The generated predictions were evaluated using F1-measure and Accuracy value.
In the experiment, the Donchian channel indicator was required to set N=24 as the calculation parameters for the upper and lower bands. Also, the strategy had trading conditions of 1% stop-loss point and slippage cost of 1 RMB (Renminbi, Chinese currency). Using the same time as the test set for the backtesting period, that was January 1, 2018 to June 30, 2022. After the parameters were set, the strategy was back-tested, then trading signals were generated. These results are integrated directly with the ML forecast results, comparing the trading directions of both, thus completing the signal filtering. Also, the evaluation metrics of the generated back-test report contained win rate, net profit, return, annualized return, maximum drawdown and ratio of net profit to maximum drawdown.
Logistic Regression (LR), k-Nearst Neighbors (KNN), Naive Bayesian (NB), XGBoost (XGB), CatBoost (CATB) and LightGBM (LGBM) Classifier evaluation results for rebar futures
Logistic Regression (LR), k-Nearst Neighbors (KNN), Naive Bayesian (NB), XGBoost (XGB), CatBoost (CATB) and LightGBM (LGBM) Classifier evaluation results for rebar futures
Section 5.1 and Section 5.2 are a detailed analysis of experimental results using rebar futures as an example, while Section5.3 is a more experimental version of our proposed system using price data from gold and soybean futures, based on the analysis process of the first two sections.
Performance of machine learning classifiers
The average accuracy and F1 value of each model were derived from the evaluation scores of the 27 test sets, also, the standard deviation was observed, as shown in Table 4. Combining the results for all periods, the Logistic Regression classifier has the best performance among all classifiers with an accuracy value of 52.9%, yet the F1-Score is the lowest at 43.1%, and also has the largest variance of the two evaluation metrics, indicating that the LR classifier can only perform exceptionally well in some periods, but is not stable. The performance of the other five classifiers is relatively balanced, and excluding the KNN classifier with the lowest average ACC. The other four models can be treated as candidate classifiers. Observing the overall model performance, the accuracy rates are all above 50%.
Considering that financial markets at different time periods are affected by national economic policies, geopolitical events, and other macro and/or micro effects, it is more reasonable to observe the forecast results of the 27 time periods separately, as shown in Figure 9.

The Acurracy (ACC) and F1-scores results of the ML model for each time period (rebar futures).
From the perspective of accuracy, that of the classifiers reaches above 0.50 most of the time, except for the prediction time on September 1, 2019 where the ACC is only 0.40. The two outperforming time are September 2020 and January 2021, with classifier accuracies of 0.60 and above. The best performer is the LR classifier with an ACC value greater than 0.65. However, this scenario was not stable because it is at the peak as well as the trough in all time periods. The overall scores of KNN are lower, so these two are considered to be excluded first in the selection of the final classifier used. In addition to the reference accuracy, classification models usually use F1-score as one of the model evaluation criteria, which is the summed average of the precision and recall rates. In Fig. 9, it can be summarized that the overall F1-Score is around 0.50, while the LR and NBC perform anomalously and only reach a score of 0.35 in several time periods. Instead, the KNN classifier and XGBoost classifier perform more consistently in F1-Score, both fluctuating between 0.45 and 0.50. In conclusion, combining the average ACC and F1-Score values and the results of the split-time evaluation, the CatBoost and XGBoost classifiers showed better scores.
Economic performance of trend trading systems based on XGBoost classifier (rebar futures) table-5
Win rate and net profit evaluation results of Donchian channel trading system and Donchian trading system based on different classifiers (rebar futures)
Win rate and net profit evaluation results of Donchian channel trading system and Donchian trading system based on different classifiers (rebar futures)
In addition, referring to the model evaluation scores, win rate and net profit are also necessary to be considered as the assessment criterias for the model performance. As shown in Table table-4, the historical backtest without filtering i.e. using only the Donchian channel trading strategy (including the trading fee of 0.03%) produced a win rate of 40.58% and a profit of only 9216.23 RMB. After using the machine learning models as a filter, the KNN filter is not considered as a filter for the system, since the win rate and net profit decreased rather than increased. The strategies constructed by the other five filters all had a raise in win rate, which was reflected in profitability, with an average net profit increase of 103.13%. Among them, the XGBoost filter produced the highest win rate and profitability, with a 200.29% gain in net profit. Overall, the win rate improved while profitability also produced a large variation, so the XGBoost model also achieved the goal of stable profitability in the equity market.
After selecting the XGBoost filter-based Donchian channel trading strategy as the optimal medium- and long-term forecasting model for the rebar future, the economic benefits of the model was evaluated based on the other indicators. As shown in Table 5, the systematic return increased by 60.19%, and the annualized return increased from 6.39% to 15.68%, indicating that the model significantly improved the return on investment and guided investors to invest more resources in term of asset allocation.
Meanwhile, the retracement of maximum drawdown was reduced by 63.85%, indicating that the model has better return stability and risk resistance. The asset curve plotted from the backtest report from January 2018 to June 2022 is shown in Figure 10. The red curve is the strategy filtered with the XGBoost classifier and the curve shows a stable and sustained rise. The blue curve is the strategy without the filter, which is generally trending upwards. The strategy is also profitable in the backtesting cycle, but not consistently. In particular, between June 2020 and June 2021, the curve shows a trough followed by a big jump, which is not favorable for investors who want to have stable returns in the long term. The green curve is the spread series of the first two, which denotes that the trading model with XGBoost differs significantly from the one without in the view of profitability. Combining the graphs with the backtest indicators, it can be concluded that the strategy using XGBoost filter is more stable and efficient, also outstanding risk resistance is demonstrated.

Asset of XGBoost-based Donchian channel trading system (rebar futures).
From Section 5.1 and Sectionn 5.2, we need to select the best-performing machine learning model and then integrate the selected model into the technical analysis strategy for backtesting. The rebar futures are used as an example and we use the same analysis process to analyze the experimental results for gold and soybean futures.
Logistic Regression (LR), k-Nearst Neighbors (KNN), Naive Bayesian (NB), XGBoost (XGB), CatBoost (CATB) and LightGBM (LGBM) Classifier evaluation results
Logistic Regression (LR), k-Nearst Neighbors (KNN), Naive Bayesian (NB), XGBoost (XGB), CatBoost (CATB) and LightGBM (LGBM) Classifier evaluation results
Economic performance of trend trading systems based on NB classifier (gold futures)
The results of F1 values and accuracies of machine learning classifiers are shown in Table 7. The data for gold performs significantly better than that of soybean among the 6 classifiers, with most of the 27 test sets for each classifier achieving an average accuracy of 52% or more. And only the KNN classifier performs slightly worse, which is the same as the case of rebar futures. On the contrary, the NB model has the best result with an accuracy of 53%. In terms of the F1-measure, KNN is the best one, while NB does not perform quite outstandingly. In this case, we give priority to the accuracy rate as the criterion. On the other hand, the ACC of all classifiers for soybean futures is on average not as good compared to that of gold, but the F1-score is better than that of gold. Among them, KNN has the best two assessments, with accuracy and F1-score of 49.4% and 48.8%, respectively. As a result, the KNN classifier was chosen as the filter for the Donchian trading system.
Taking into account the practical application aspects, backtesting each classifier in combination with a trading strategy is time-consuming. So, we directly choose the best-performing classifier in practice and then put this filter into the trading strategy for backtesting. The economic performance of gold and soybean futures before and after using the filters in the experiment is shown in Tables 8 and 9.
Economic performance of trend trading systems based on KNN classifier (soybean futures)
The NB-based Donchian trading system outperformed the system without filters in all economic evaluation indicators under gold futures. Specifically, the win rate has increased by 1.57%, which means that the system has a higher probability of making money during the backtesting period. The net profit improved from 47,323.07 to 90,898.48, which is a remarkable improvement. The return and annualized return almost doubled after using the filter. The maximum drawdown decreased from 96,417.34 to 54,918.63, which means that the maximum loss generated by the trade was reduced by the strategy after using the filter. The value of the ratio between net profit and maximum drawdown increased as a result of an increase in the net profit and a decrease in the maximum drawdown. For soybean futures, the Donchian trading system filtered by the KNN classifier also improved in all evaluation indicators. For example, the win rate increased from 35.45% to 37.52%. Although the net profit is negative, the net loss is at least 6 times lower after using the KNN filter, in terms of loss reduction. This is also reflected in the return and annualized return indicators. The risk of the futures during the backtesting period decreases with the maximum possible loss incurred.
The results of the above experiments can be summarized by saying that the ML-based filter increases profitability and reduces investment risk for three representative contracts in the Chinese futures commodity market. The asset curve in Figure 11 illustrates that the red curve of gold futures is above the blue curve for January 2018 and June 2022 after using the NB filter. This implies that the NB-based Donchian trading strategy delivered good returns for all four and a half years. In the soybean futures data test, Figure 12 displays that the spread curve shows a steady upward trend, with the distance between the red and blue curves pulling apart from October 2018, which means that the filter-based strategy can keep the asset in a relatively stable state, despite a period of stock market volatility and difficulty in profiting from traditional technical indicators.

Asset of NB-based Donchian channel trading system for gold futures.

Asset of KNN-based Donchian channel trading system for soybean futures.
The above predictions of the upward and downward trends of the rebar prices using ML models combined with Donchian channel trading strategy yielded the following conclusions: (1) By comparing the LR, KNN, NBC, XGBoost, CatBoost, and LightGBM classification models, the XGBoost and CatBoost models have positive predictive performance in dealing with multidimensional financial time series problems, reflexing in terms of accuracy and F1-measure. (2) The above six classifiers, except the KNN model, all improve their win rates and net profits in the Donchian channel trading strategy, they can be adopted as valid filters in the trend-following strategy; of which, the most outstanding model is the XGBoost model. It was demonstrated all-around superiority among the classifiers in this paper, in terms of its predictive capability, risk resistance, profitability, and earnings stability. This classifier is the most suitable one to be used as a filter for predicting the rebar price trend in the Donchian channel trading strategy. Moreover, by verifying the performance of this ML-based Dochian trading system using more futures data, it can be concluded that the Donchian trading strategy using machine learning techniques to filter signals has also shown improved profitability and decreased the investment risk in Chinese gold and soybean futures during a certain period. In summary, a flexible combination of optional ML predictors and technical indicators can optimize traditional quantitative trading strategies.
Although the introduction of machine learning models into the Donchian channel trading strategy can effectively improve profitability, the large dimensionality of the input data in the feature extraction session and the possible existence of many noises in it may have a negative impact on the running speed of the model due to too much selectivity of the features. Further research can be conducted in the future for the direction of feature selection and noise reduction processing. In addition, we will use more strategies in our future work to further enhance the feasibility of the ML model combined with traditional strategies. Since the futures market structure in China is different from that in other countries or regions, the system can be tested its performance in other commodity futures (e.g., S&P 500 index) in the future. Regarding the improvement of the DL model, we will optimize the parameters of the LSTM model.
