Trading in the FX market using mechanical trading strategies

The best method we have found up until now to build historically profitable machine learning based systems is to construct strategies that attempt to predict the specific outcome of a given trading setup. This means that using some set of inputs – such as bar returns or indicators – you attempt to predict how a trade would exactly end up if you managed it in a given manner (using a take profit or a trailing stop for example). Today I am going to talk about an expansion of this way of thinking that seeks to eliminate several of the limitations inherent to this methodology, which we will also discuss during the beginning of this post. This idea has come mainly from an Asirikuy member – James – who I would like to take the opportunity to thank for his valuable contributions in our search for machine learning strategies.

–

–

When you build a machine learning system that attempts to predict trade outcomes you face the limitation of having to tell your machine learning algorithm how exactly it should handle trades. It is not the same to predict the outcome of a trade that is entered with a stoploss of 10% of the daily ATR 20 period indicator or a trade that is to be entered with a stoploss of 100% of the ATR, it is also different if the trade will remain untouched until it reaches a take profit target or if the stoploss will be modified through the trade according to some criterion. In practice some trading setups end up being more predictable than others and by optimizing which trade management technique to use we arrive at the historically most favorable results.

Those of you who are well versed in the statistics of trading system design may already spot a problem in the above proposition. The fact that you must carry a search process over the possible trade outcomes to predict introduces a data-mining bias issue that needs to be accounted for (which we presently do at Asirikuy) and most importantly, it introduces a fundamental limitation in how a given machine learning system can adapt to the market. If a system is created that does a good job at predicting the outcome of a trade entered with an initial stop loss of 50% of the daily ATR 20 that is managed via a function based trailing stop that seeks to move the trade to break even after 5 bars then if the ability to predict this scenario deteriorates the system will fail rather quickly. Another problem is that the above focus on a single trade outcome exposes the system to significant feed dependency, especially if the machine learning algorithm used is not very flexible (lacks the ability to form non-linear representations).

–

–

To combat the above problems we can expand on the notion of predicting trade outcomes and take it from a single outcome to multiple trade outcomes. This means that instead of predicting how a single trade based on a single set of trade conditions would workout we attempt to predict the results for an array of possible trades and we then take a trade with the conditions that are predicted to yield the biggest profit. The simplest representation of the above idea is to get rid of the notion of the fixed SL. In this scenario instead of attempting to predict the long and short trade outcomes of a trade using a given initial SL we instead predict an array of long/short trade outcomes for different SL values. In my first tests I used SL values from 0.5 to 1.4 of the daily ATR 20 in 0.1 steps, such that I end up predicting 10 different trade outcomes. This means that I have 10 different long/short trade predictions using 10 different SL values and I can then compare the expected profits from all of them and decide to take a trade with the SL that gives the best potential result.

We can attempt to perform the above process using a simple linear regression algorithm (as implemented on the Shark open source library), retraining the algorithm on each bar using a rolling window of examples. As we would expect the above algorithm is significantly slower to back-test compared with an algorithm that attempts to predict just a single trade outcome but in the end a back-test can be obtained in less than 10x the time so it ends up being more efficient than having to test 10 different SL possibilities. The increase in adaptability coupled with the decrease in mining bias and therefore the decrease in mining bias evaluation complexity makes this an excellent advancement in our creation of machine learning strategies.

–

–

In the end what we have is something fairly complex that starts to resemble what a trader would actually do. We have a machine learning algorithm that retrains on each bar using a past given number of examples and attempts to draw a relationship between market information and the outcome of several different possible trade setups. In the case I have exposed today this is simply 10 different stoploss values but this can be expanded to mean different things. For example I envision an algorithm where you can simultaneously evaluate the potential of 1000 different potential trade outcomes including many different initial stop loss values and trailing stop functions. Whether this will work as expected or not is still unknown but it definitely feels like a great step in the right direction.

If you would like to learn more about machine learning and how you too can create constantly retraining machine learning strategies using the F4 framework please consider joining Asirikuy.com, a website filled with educational videos, trading systems, development and a sound, honest and transparent approach towards automated trading.

Many thanks Daniel for this and other posts on your blog. You always come with something very interesting. I’ve been reading your blog for some time now and I’ve found them very inspiring. I was testing your visions and ideas in R and have to say the result are really very good. Recently I’ve came to the same conclusion as you, if I’ve understood you correctly and so the trade signal is as important as subsequent trade management. Once again thank you!

Thanks a lot for writing :o) I am glad my posts have been useful to you! As you so clearly put it subsequent trade management is just as important as the signals themselves. Feel free to share any opinions, comments or questions you might have on any of my blog posts,

regarding the outcome of a given trading setup, in order to simulate a trailing stop setup, you would need a complete history of the asset, that is, all ticks, right? Or do you have other means of doing it?

Thanks for writing. Depends on how your trailing stop evolves. If you want to use a trailing stop that constantly follows price with every tick change you do need tick data but if you use other types of stops you do not. For example the function based trailing stops we use react only on bar openings so they can be simulated perfectly accurately using OHLC data. You can read this post for more information about them: http://mechanicalforex.com/2016/01/fx-trader-magazine-article-function-based-trailing-stop-mechanisms.html . Do let me know if you have other questions,