2.2. Take Profit & Stop Loss
Returns can be either absolute or relative. As a rule, we avoid absolute numbers because they will have to be calculated for each asset individually.
Leung and Li (
2015) proved that the stop loss function has to be calculated at every moment because it is related to the price of an asset at every tick since that price is within the price range
x ∈ (L, b × L), or the investor, if
x is the entering price, can simply set a constant I (proportional to the fluctuation we add), where
x−I is the stop loss price. In addition, returns change over seasons and periods, according to the influences an asset undergoes as a result of outside or inside factors. It is obvious that orders with stop loss and take profit, when activated, oppose the market trend (take profit) or intensify the movement (stop loss), with great influence even over the liquidity during a flash crash (
Easley et al. 2011). In all these adoptive trading systems, special consideration should be given to the use of these functions, as shown by
Austin et al. (
2004). In addition, the use of cut-loss orders and take profit orders and the range of these orders reflect the risk-taking desire of the investor (
Au et al. 2003).
With regard to absolute numbers, we see a 3% take profit and a 2% stop loss in the work by
Bolgün et al. (
2010) on stocks of the Istanbul Stock Exchange. Constant take profit was used by
Krishnan and Menon (
2009), defined at 20 pips, in an interesting work that examined the influence that rate, closing price times, and indicators participating in trading systems (RSI, BB, Stoch, SAR, MACD, ADX, CCI, Williams %R, Mom, A/D) have on profit. Take profit was also set at 20 pips by
Barbosa and Belo (
2010). Even in systems that are based on the flow of buy and sell orders and not on the price itself, as postulated by
Bates et al. (
2003), stop loss and take profit were used as a function of returns 0–0.5%, 0.5–1%, etc. Similarly,
Azzini and Tettamanzi (
2008b) set staggering take profit signals on returns of 0.33%, 0.67%, etc., while in another work,
Azzini and Tettamanzi (
2008a) took three returns as take profit, logarithmically setting the constant at rTP = 0.006, 0.008, or 0.0046.
Martinez et al. (
2009) conducted experiments that converted the percentage of loss break from 0.1% to 2.0%. A small loss break percentage could impede profitable transactions, while a high one could cause bigger losses. The system executes more profitable transactions with the stop loss rules and the 0.5% percent yielded the best results.
As for the fluctuation range, we consider that take profit and stop loss functions display flexibility of profitability adjusted on each asset. In this way, with the range (R), stop loss = 0,5R and take profit = 1R were set by
Cervelló-Royo et al. (
2015). It is obvious that profit>stop loss is the only fair deal. Consequently, we make sure that 1R > 0.5R.
Klement (
2013) set the stop loss (c) in combination with a reentry condition (d), where (c) as the stop loss level is expressed in units of annual standard deviation of the return of an asset. The same applies for (d). Similarly,
Chevallier and Ielpo (
2012) set a dynamic stop loss and reduced the losses on S&P500, for which the rule is as follows: if the proposed rate of return against the variability reaches a lower limit (n), that is, the number of fluctuation days of the market that will activate the stop loss rule, then this is a signal for the selling of the investment.
We prove here that the addition of take profit and stop loss could considerably improve the results, to the point that they become profitable, in contrast to the claim laid by
Clare et al. (
2013). More specifically, this became more evident after the proof put forward by
Han et al. (
2016), who, with a stop loss at 10% of the monthly returns of a strategy based on the momentum, achieved a reduction of losses from −49.79% to −11.36%. Likewise, for monthly data from 1950 to 2004 setting stop loss on American long-term bonds investment,
Kaminski and Lo (
2014), improved the return over the buying and holding strategy by 50–100 basis points.
Lei and Li (
2009) applied a constant price stop loss, as well as trailing stop loss, for stocks of NYSE and AMEX from 1970 to 2005. They concluded that the stop loss function shields investors from holding a non-profitable position for a long period of time, which could result in big losses of capital. On the other hand, they found a distinction between the profits’ enhancement and the risk reduction. The analysis of exchange rates of high frequency by
Osler (
2005) yields facts that provide support for the idea that orders of stop loss have an influence on the fall of prices. First of all, the change in exchange rates is faster when the prices reach levels at which stop loss orders are usually placed. Secondly, the effect of stop loss orders is greater than the effect of the take profit orders, which also helps the fast changes in prices by creating an opposite trend. Thirdly, the effect of stop loss orders has a broader time duration than that of take profit orders.
All of the above stop loss and take profit rules and conditions can be evaluated and sorted with regard to the profitability of the investment through a number of ways, where the aggregate profit would be the ultimate result, but with an evaluation framework proposed by
Chan and Ma (
2015).
The take profit and stop loss functions we use and analyze below are dynamic, follow the average fluctuation and the current price for every tick, and are activated instantaneously.
2.3. Automated Trading Strategy Development and Combinations
For this research, we used an automated trading system (Expert Advisor) based on the MACD indicator. We started with a simple system and progressively added more complex features, implementing Take Profit and Stop Loss functionalities.
2.3.1. The MACD Indicator and Expert Advisor
The MACD (Moving Average Convergence/Divergence) is a well-known indicator created in 1979 by
Appel (
2005). It calculates the difference of two exponential moving averages of different periods over a time-series. The moving average with the smaller period is called the fast moving average and the moving average with the bigger period is called the slow moving average.
Another exponential moving average is calculated on the MACD line, called the Signal line:
When the MACD line is above the Signal line, this is an indication of an upward trend momentum in the time-series and when the MACD line is below the Signal line, this is an indication of a downward trend momentum in the time-series.
The default values of the three periods used in the calculations of the MACD indicator are usually
,
, and
in the daily timeframe. An example of the MACD indicator can be seen in
Figure 1.
An automated trading system (Expert Advisor) can be formulated on the basis of the MACD indicator following the rules below:
When the MACD line crosses above the Signal line, this constitutes a buy signal and any short positions are closed and a long position is opened.
When the MACD line crosses below the Signal line, this constitutes a sell signal and any long positions are closed and a short position is opened.
The abovementioned trading strategy in the form of a pseudocode can be found in
Appendix A.
2.3.2. The MACD Expert Advisor with a quicker Take Profit Signal
Sometimes, the rate of change of a time-series can be more rapid than the rate at which the MACD indicator can provide us with a signal. If a position was open during that time, even if it was a successful one up until that moment, potential profits could be diminished and never materialize or even turn into losses.
A potential solution to that problem is the use of a different Signal line to judge when to exit a position, with a faster (smaller) period than that of the normal Signal line:
where
An example of the MACD indicator with a Take Profit Signal Line can be seen in
Figure 2.
Now, the Expert Advisor, in addition to the two previous rules, closes any long positions when the MACD line crosses below the Take Profit Signal line and any short positions when the MACD line crosses above the Take Profit Signal line. After that and until the next time, the MACD line crosses the Signal line, and no position is open, in contrast with the previous strategy, where there was always a long or a short position open. The abovementioned trading strategy in the form of a pseudocode can be found in
Appendix A.
2.3.3. The MACD Expert Advisor with Signal Lines’ Hierarchy
There can be time periods when the time-series of an asset does not follow a clear upward or downward trend, but instead oscillates around a value. During these periods, the previous strategies produce a lot of signals and change positions frequently, which can potentially lead to losses, because there is not enough time for the price to move to profitable levels and every transaction and position change comes at a cost. A more effective option might involve staying out of the market during these periods and only opening a new position when clear upward or downward trends occur.
The clarity of a trend can be judged by means of the MACD, Signal, and Take Profit Signal lines. When the prevailing trend is bullish, then we have the MACD line above the Take Profit Signal line and the Take Profit Signal line above the Signal line. Likewise, when the trend is bearish, we have the MACD line below the Take Profit Signal line and the Take Profit Signal line below the Signal line.
The Expert Advisor still closes positions using the Take Profit Signal line in the same way as in the previous case, but only opens new positions if the hierarchy of the MACD, Take Profit Signal, and Signal lines matches the one outlined in the above paragraph. The abovementioned trading strategy in the form of a pseudocode can also be found in
Appendix A.
2.3.4. The Average True Range Indicator
The Average True Range or ATR indicator is a measure of volatility introduced in 1978 by
Wilder (
1978). The True Range for a specific interval is defined as
The ATR of period N is calculated as
for the first instance and after that as
2.3.5. The MACD Expert Advisor combined with the ATR Indicator for Stop Loss Strategies
The ATR indicator can be used to set a Stop Loss barrier when a new position is opened following an MACD Expert Advisor signal. When the MACD Expert Advisor opens a new long position, a Stop Loss barrier can be set at
where Opening Price is the price the long position was opened at, ATR(N) is the value of the ATR indicator of period N at that moment, and
x is a constant multiplier used to adjust the barrier’s width. When the asset’s price moves below that barrier, the long position is closed.
Likewise, when a short position is opened, a Stop Loss barrier can be set at
When the asset’s price moves above this barrier, then the short position is closed.
After a Stop Loss is triggered and a position closed, it is possible that the MACD indicator keeps signaling for the same type of position to be opened. To avoid the immediate reopening of the same type of position after a Stop Loss, a new barrier can be created in the same way. Until the price moves above
a long signal will not result in a new long position after a Stop Loss, and until the price moves below
a short signal will not result in a new short position after a Stop Loss. The
y parameter is a constant multiplier used to adjust the barrier’s width, as is the case with
x. Examples of Stop Loss Barriers and New Position Barriers can be seen in
Figure 3. The abovementioned trading strategy in the form of a pseudocode can also be found in
Appendix A.
2.3.6. The MACD Expert Advisor with sliding ATR barrier zone
The ATR Stop Loss barriers described in the above section are drawn around the price at which a new position is opened and stay fixed, even if the price follows an upward, profitable trend, until there is a new MACD signal or the price moves back to the barrier.
In the second case, when the price moves back to the Stop Loss barrier, the potential gains from the previous profitable movements are never materialized. To prevent this, the ±x × ATR(N) zone can be redrawn each time the price moves out of it and follows a profitable direction. This slides the Stop Loss barrier to values that secure some of the profits gained so far.
On the other hand, the position prevention barrier should stay at the same level and not slide, as it could prevent the Expert Advisor from opening a new position for a long time. An example of this strategy can be seen in
Figure 4.
2.3.7. The MACD Expert Advisor with sliding and variable ATR barrier zone
An asset’s price can show large or small variability as it changes over time, which reflects the value of ATR. In the previous cases, ATR barriers were of a constant range, calculated with the ATR value at the moment when a position opened. Using the latest ATR value to form an ATR window with a variable range through time, could prevent the expert advisor from exiting a position prematurely in periods when variability spikes and help him follow the price trends, as seen in
Figure 5.
2.4. Data and Implementation
We conducted our experiments on the different Take Profit – Stop Loss strategies for nine assets from the Forex, Metals, Commodities, Energy, and Cryptocurrencies categories: AUDUSD, EURGBP, EURUSD, GBPUSD, USDCHF, USDJPY, XAUUSD, OIL, and BTCUSD. This choice mainly came from the need for assets that are traded on global markets on a 24 h base (or close to 24 h), as we wanted to examine the automated trading systems in a High Frequency Trading mode (hourly timeframe). The MACD Indicator has mainly been used for stock trading, but we opted to not trade stocks as the relatively big time intervals that exist between their trade sessions, in combination with the multinational activities of most of these corporations, can cause a lot of gaps and noise in their prices. The period we examined was from 3 September 2017 to 24 February 2018 with historical data from FXTM, GEBINVEST, and OctaFX. Because our systems were used in High Frequency Trading mode, we determined that a six-month period would be enough to draw conclusions about their performance.
For the testing, we used the Metatrader 5 trading terminal from Metaquotes, and Microsoft SQL Server for the initial data processing.
We set the initial test amount at $10,000 at a 1:100 leverage ratio for all assets except for BTCUSD, whose high price and spread required an equally high margin on the broker we used, so we set the initial amount at $10,000,000 and adjusted the results in such a way as to be comparable to the other assets. For each new position the automated trading system opens, it risks 20% of its current balance and no capital is deposited or withdrawn for the six-month period apart from the initial capital. The spreads for every asset (in pips) as reported by the brokers used were AUDUSD:0.7, EURGBP:0.6, EURUSD:0.4, GBPUSD:0.7, USDCHF:0.9, USDJPY:0.5, XAUUSD:21.0, OIL:5.0, and BTCUSD:11.5. The Metatrader 5 trading terminal also automatically adds the cost of each transaction to the Gross Losses so the Net Profits represent the actual pure number a trader has won or lost at the end.
2.4.1. Back testing Limitations
The Metatrader 5 terminal offers the ability to test an automated trading system over a past time period with various methods for simulating the price changes, such as every tick, every open-high-low-close value, every open value for a specific timeframe, etc. It also offers the ability to test a rage of the parameters used by the Expert Advisor in order to identify the best combination of parameters for a back testing period. In order to speed up back-tests, Metatrader 5 also offers the ability to use distributed testing agents utilizing the resources of a local network of computers. We used this ability to form a local cluster of computers, mainly with i5, i7, and Xeon Intel CPUs for a total capacity of 130 distributed agents, in order to run our backtesting experiments. We also used a Microsoft SQL Server in order to save and process the results of our experiments during the stage of parameter selection.
It should be noted that the wider the parameters’ ranges, the greater the number of combinations of parameters. Also, back testing with an every tick simulation is far more time- and resource-consuming than back testing with open-high-low-close value, which is in turn more time-consuming than an open value only simulation.
The values of the MACD and ATR indicators are calculated over one-hour timeframes, but during an hourly timeframe, the price of an asset can reach levels that would trigger a Take Profit/Stop Loss in some strategies or an automatic Stop Loss from the broker, so we chose to run our experiments with every tick simulations.
2.4.2. Parameter Selection
For our tests, we had to choose a set of parameters for each asset that would allow for the demonstration of an improvement or worsening in the MACD Expert Advisor’s behavior with the introduction of each Take Profit/Stop Loss strategy.
Since the different periods in the MACD averages can generate widely different results and in order to render the role of these parameters less significant for our tests, we decided to choose sets of parameters that are centered on neighborhoods (±2) of similar results, with the results indicating there is room for both improvement and worsening.
The simple MACD Expert Advisor has three parameters, the periods of its moving averages, which means that even for small parameter ranges, the number of combinations is significant. Performing a back test for every asset with full parameter sweeping on an every tick simulation would be prohibitive because of the time and electrical energy it would require. We circumvented this firstly by running the simulations on open-high-low-close prices ticks, which produces results close enough to the real tick simulation, and secondly by incrementing each parameter by a step of 2 instead of 1, which reduces the combinations to 1/8, allowing us to check a wider range. Potentially suitable neighborhoods can still be identified as a step of 2 still hits a ±2 neighborhood in eight or 27 of its 125 members.
Next, we defined some requirements for a suitable neighborhood, such as a minimum amount of trades and profit range, and chose the best 100 neighborhoods that fulfilled them, sorted by the smallest relative range defined as
The specific requirements for each asset can be seen in
Table 1.
To be more certain, we ran back tests with every tick value for these 100 neighborhoods of each asset, with range ±2 around their center with step 1. The missing combinations changed the min, max and average profits of the neighborhoods, which resulted in changes in their order of classification. Finally, we conducted a supervisory review of the best options and chose a neighborhood for each asset that seemed the most fitting one and served our purposes. The final parameters are presented in
Table 2.