The order flow sentiment index (OFSi) is the ratio between the number of open long positions to the total number of open positions in one instrument. For instance, if there are in total 1,000 open positions and 540 of them are ‘buy’ orders the OFSi is equal to 540/1,000 = 54%.
We are using two other definitions of the OFSi. Alternatively, instead of counting the number of open positions one can compare the volume of open ‘buy’ positions or the number of traders who have positive exposure to the market. For instance, if there are 600 traders who have open ‘EURUSD’ positions and 360 of these traders have a positive exposure to ‘EURUSD’ – the value of the OFSi = 360/600 = 60%.
Below, we present the EURUSD price chart together with the OFSi’s based on the number of trades and the volume of trades.
Figure 1. Price (top pane) and two OFSi’s (bottom pane) for EURUSD symbol
The goal of the present paper is to use OFSi in the creation of a profitable trading strategy and provide guidance for further research.
We start by assuming that OFSi can be used to predict price movements of various instruments in our database, i.e. there is a dependence between the value of the sentiment index and the future trading return. In particular, there would be some range of the sentiment index that predicts positive future returns and the remaining range of the index will predict negative future returns. If we can identify such range of values with high probability – we can either go long when the sentiment index predicts positive returns or go short otherwise. If we label positive returns as +1 and negative returns as -1, this becomes a simple classification problem to predict +/-1s given the value of the OFSI.
In machine learning, the robust way to solve this problem is to split the dataset into three parts: training set, validation set and the test set. The test set is usually set apart and the model is trained on the training set and model hyperparameters are tuned on the validation set. If, on all sets: training, validation and test one sees the same pattern of behaviour we believe the model does not suffer from overfitting.
Our trading strategy will have two thresholds – lower and upper. If the value of the sentiment goes below the lower threshold or above the upper threshold – the strategy predicts to go short the instrument. If the value of OFSI is between the lower and upper thresholds we long the instrument. This is the simplest possible model and we encourage the readers to explore more complex strategies than the one used here.
How did we come to this idea? The answer is by observing the histograms of the positive and negative returns. Diagrams below, show the distribution of different OFSi values. The data is separated into two groups – one for which the future trading return is positive (blue) and another one for which the future trading return is negative (red). The two histograms are for training and validation sets.
Figure 2.a, 2b. EURUSD OFSI Histograms for positive and negative price returns. Top chart (2a) is for the training set, bottom (2b) is for the validation set.
One can clearly see that blue histogram prevails in the center of the chart and red histogram in the tails. This means that if the sentiment for EURUSD obtains central values – there is a higher probability of positive return while if the sentiment is at an extreme – there is a greater probability of negative future returns. This pattern for EURUSD is robust over the training, validation and testing periods.
Backtest and Equity Curves.
Our benchmark strategy was the best performing of the ‘buy & hold’ and ‘sell & hold’ strategies. By the ‘buy and hold’ trading strategy we mean the strategy that buys the instrument and holds it indefinitely. ‘Sell and hold’ strategy correspondingly sells and indefinitely holds a short position. Our goal is to consistently outperform the best one out of the two.
Below are the equity curves of the OFSI trading strategy with variable duration, each period = 15 minutes (after the buy or sell signal is observed position is held for 1 or 1200 periods).
Figure 5. EURUSD OFSi Trading strategies equities. Trade duration in the top row – 1200 periods, trades duration in the bottom row is single period.
For both choices of trade duration our strategy outperforms the baseline strategies. This is a good result but can we improve this any further? What tools do we have at our disposal? The answer is the segmented OFSi. On the Internet, there are many sources of free sentiment for many trading instruments. Because sentiment indices are freely available for the most liquid instruments one can argue that the information contained in these indices is already adopted by the market and it is quite hard to generate extra value. Therefore, we can use our filters to segment order flow which is a proprietary index to improve on the strategy definition we proposed and the obtained results.
For this paper we have used an OFSi filtered by positions opened by traders which, at the time of opening these positions, had equity of more than $10,000. On the one hand, this greatly reduces the number of open orders on the other it greatly improves the quality of the signal and OFSi’s predictive ability.
Below are the backtests on the training and validation sets of an OFSI strategy that uses the segmented order flow (red):
Figure 6. EURUSD OFSi Equity comparison for unfiltered and filtered OFSI Trading strategies. Filter: Equity > $10k. Trades duration is one period.
We can see that red curve overperforms both our benchmarks and the ‘buy and hold’ strategies. We obtain similar results for other instruments tested.
Finally, we need to check if the overperformance persists on the test set. We took the test set to be the trading returns for the period from March to October 2018. The test result is presented below:
As before, the backtest on the segmented order flow overperforms both the benchmarks and the non-segmented OFSi.
In the paper we have tested an idea that one can build a profitable trading strategy using the OFSi indicator. We have split our dataset into training, validation and test sets to avoid overfitting and backtested the OFSI strategy on each of these sets. When we compare the backtests of this strategy with the benchmark – it outperforms the best of the naive strategies on all subsamples. To improve our results we have created a segmented OFSi using extra condition that equity > $10,000 and were able to obtain even better results. This shows that OFSi can be used to produce profitable trading strategies.
In this piece of content, we have only dealt with the simplest trading ideas and we were not using any other additional signals. We believe that these results could be improved further and we encourage the readers to experiment with OFSi powered by PsyQuation for even greater benefit.