This paper examines two transactional strategies based on the classifier which opens positions using some rules and closes them using different rules. A rule set contains time-varying parameters that when matched allow making an investment decision. Researches contain the study of variability of these parameters and the relationship between learning period and testing (using the learned parameters). The strategies are evaluated based on the time series of cumulative profit achieved in the test periods. The study was conducted on the most popular currency pair EURUSD (Euro-Dollar) sampled with interval of 1 hour. An important contribution to the theory of algotrading resulting from presented research is specification of the parameter space (quite large, consisting of 11 parameters) that achieves very good results using cross validation.

1. Introduction

The aim of this work is to verify the hypothesis of patterns extraction possibility from time series, which could be classified as providing better statistic and more accurate prognosis. Another important objective is confirmation of assumption that financial markets time series have a “memory” of pattern efficiency in a time period following the time series that was used in learning period. This approach is consistent with the classic aim of machine learning shown by Murphy [1], especially to financial markets described by Satchwell [2]. Research intention was also to follow reproducibility principle of other researchers’ studies, as well as by themselves, in other data environments, to make sense of the use of computational intelligence in its reasonable reproducibility [3, 4], in extracting of the regularity from chaos [5, 6].

An investment strategy with a relatively high complexity (measured by the number of factors included in the model) was built, derived from a strategies group called strategy of simple rules. In the literature those strategies are considered to be mainly strategies based on moving averages—their intersections and derivatives shown, for example, by Brock et al. [7], Cai et al. [8], and many other authors [911]. Of course, the world of algorithms as well as prediction methods using a completely different nature, such as regression [12], multiple regression [13, 14], Fourier and wavelet transforms, and many others [15, 16] is plenteous. These methods are used as a basis for comparison; however the main focus is on mentioned simple rules.

This paper proposes strategy, which differs by suggesting different behaviors than the ones proposed when using Bollinger’s Band, which has its foundation in a band built in an unusual way. According to the strategy based on that band, generally it can be assumed that the trend is horizontal and it is recommended to open position to the center of the band, after its cross by the price from the inside. In proposed strategies, another band that is based on maxima of the maxima and minima of the minima of last several candles is used.

Considered strategies move away from the principle of opening positions to the center of the band. In one modification, hereinafter referred to as substrategy, position opens into the center of the band, whereas in another one, position opens on the outside. By treating the two considered substrategies as an entirety and as strategies that are mutually retrieving (although a more appropriate word would be complementary) it is assumed that, in the selected trading section, opening positions in opposite directions, of course not at the same time, can be done intentionally and effectively. During the trading, nature of the market (trend, volatility) may change. The market may be in some periods horizontal, in other trended. It is appropriate to seek all opportunities for profit. A similar philosophy is applied by several Krutsinger correspondents [17], who belong to most prominent traders in USA, who advocate unfounded reversal of the direction of opening the positions in case of series of failures.

Returning to the issue of complexity of strategy, there are often opinions that the growing complexity of the prediction model is not indicated, because in learning section it leads to overfitting [1, 8, 14]. This results in a greater error in the test sections. The problem of selecting the proper ratio between learning and testing phase is still unsolved for the nonstationary time series [5, 18]. In this situation the right approach seems to be the use of the idea of computational intelligence [3, 6] which helps to compute adequate length of learning and testing period.

Therefore in this paper two rather complex strategies (described below) are used, achieving results that are assessed as rewarding. Attention is drawn to the fact that the satisfaction problem belongs to the other sciences and depends on the trader’s individual perception of the relationship between profit and risk, greed and fear [19]. However, the issue of emotions in the trade is not considered here, but only noticed because there is the assumption that trading is done automatically.

The tests were deliberately performed in a fragment of the time series of a heavily diversified course, which contains both rising and downward trends as well as horizontal elements (Figure 1). This time series consists of 4734 1-hour candles, of the most important and the most fluent currency pair EURUSD from October 22, 2012.

A choice of parameters essential for defining the rules of opening and closing positions is crucial to the effectiveness of the strategy. Parametric space presented in this paper is a result of many trials prior to its final approval.

2. Characteristics of Investment Strategies

The objective of the two strategies considered is to make investment decisions about buying or selling—opening long or short position in the market studied—the currency pair EURUSD. The decision is based on the intersection of the current price and one of two barriers of additional indicator, called the ribbon. The band is made of two values calculated at the opening of each candle on the basis of historical data of the market. During the candle, values of the band do not change; therefore, barriers are creating step functions. In case when the current price exceeds any of the barrier values (goes out of the band), a decision to buy or sell is made—the type of decision depends on the variant of the considered strategy—decision for substrategy TewiMiC is different than in case of TewiMiD. Names of the strategies are derived from the name of the project, in which the research was carried out.

2.1. Definition of the Band

The values of barriers forming a band are calculated using the maximum and minimum values of the last candle (OHLC: Open, High, Low, Close prices). In the case of the upper band, it is the maximum of the maximal values of the last candles, whereas in the case of the bottom band, it is the minimum of the minimal values of last candles:

As mentioned earlier, strategy comes in two versions that differ in terms of opening the positions when crossing the band. These differences result from different investor assumption about currently prevailing market trend. In the first case it is believed that the trend has just started and positions need to be opened in accordance with it. In the second case, the play is against the trend. The two considered variants, TewiMiC and TewiMiD, are based on excesses of the lower limit of the band. TewiMiD implies existence of a downward trend, for which when crossing (down) the lower limit of the band, a short position (assuming the price drop) is opened. This is known in the literature and in trading as Sell Stop model.

TewiMiC assumes the opposite case; therefore it is needed to open a long position (assuming the price increase). This is Buy Limit model.

2.2. Strategy Parameters

Considered strategies are based on a objects classification (events that meet the conditions contained in the set of rules which depend on the value of certain parameters). Object—the event—is another candle. Rules are logical sentences like “if the price is greater than the upper barrier of the band” and the parameter is, for example, the upper barrier, which is a variable value.

These parameters will determine whether the strategy will earn or lose. Appropriate selection of parameter values is therefore a key optimization issue in the use of the strategy. Considered strategies have 11 parameters, which are subject of optimization.is the number of candles, based on which the calculation of the current value of the band barrier is made; for researched time series, value of generally ranges from 10 to 30;is the number of steps forward, after which the position is closed in case when none other close conditions were met before; this value belongs to range from 3 to 40;is StopLoss condition; usually it remained in range from 0.002 to 0.017 expressed in values of EURUSD, which in researched period stayed in range from 1.2 to 1.4, as can be seen in Figure 1;is TakeProfit condition, generally ranged from 0.0015 to 0.009;is band buffer, offset from the barrier of the band defining the actual level of the expected crossing of the price, ranged from −0.002 to 0.003;is maximum number of open positions at the same time, ranged from 3 to 20;is the number of candles that determines average volume value; generally ranged from 2 to 10;is maximum value of the difference between the current value of the volume and the average value calculated on the basis of candles back, ranged from 150 to 500;is the number of candles on the cumulative profit curve, based on which current drawdown is calculated, ranged from 5 to 25;is the highest acceptable drawdown on the cumulative yield curve; generally ranged from 0.0021 to 0.008;is acceptable amount of the cumulative loss for all currently open positions, ranged from 0.0005 to 0.003.

2.3. Conditions of Opening

As mentioned before, the signal to open the position is the intersection of the current price of the observed value and some barrier (that results from the calculated band). Special parameter called the buffer () has been added, causing the offset of barrier from its actual value. Thus, the condition for opening TewiMIC strategy is where price is current value for EURUSD, bottomBorder () is value of lower band barrier for parameter , here minimum of last minima, buffor () is value of buffer that moves said barrier, current is number of currently opened positions, Vol is current value of volume (in the candle), meanVol () is mean of volume of last candles, and the opening condition for TewiMiD is as follows:

As a result of these conditions, long positions, in substrategy TewiMIC, are opened when three conditions are met simultaneously: crossing the bottom barrier reduced by buffer by the current price, the number of open positions is less than the limit (which is the optimized parameter ), and the difference between the current volume and the average of the volume of the last candle is less than the parameter .

For TewiMiD strategy, analogously, with significant differences, short positions will be opened and it is advisable that current volume should be greater than the average. As the result of conducted research, authors concluded that volume (number of price changes in observed time frame—here during one hour) was the most important and most sensitive factor of decision model.

These conditions can be met in two cases during the period of the current considered candle. They can be met immediately at the opening of the candle; that is, the opening value of the current candle is smaller than the barrier bottomBorder reduced by parameter . That condition can be met within the candle, when the current value of the price breaks through the lower barrier.

The result of that is that we have two distinctly different opening conditions.

2.4. Conditions of Closing

In both substrategies there are 7 cases of closing the open positions, which results in their complexity—both in terms of logic and calculation. This complexity, however, exhausts all the possible surprises and does not leave any opportunity for the unexpected market behavior. Of course, depending on the values of the parameters, frequency occurrences of closure cases can be very different.

Firstly the terms for closing the long positions that were opened by conditions for TewiMiC will be presented.(1)Opened long position will be closed, if at the close of the candle () the position remained open, where is number of candle, which was opened.(2)Position will be closed if at the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: where is the opening value for ()th candle and is StopLoss (level of acceptable risk in one trade) in pips.Then the profit (in this case loss) will be calculated as (3)Position will be closed if inside the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit (in this case loss) will be calculated as where LowPrice() is a minimum value of ()th candle.(4)Position will be closed if at the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: where is TakeProfit (maximum reward level in single trade) in pips.Then the profit will be calculated as (5)Position will be closed if inside the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit will be calculated as where is the maximum value for () candle.(6)Position will be closed if at the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit will be calculated as (7)Position will be closed if inside the next ()th—the candle after th candle, in which the position was opened, following condition is met: Then the profit will be calculated as In substrategy TewiMiD conditions will look slightly different.(1)Opened short position will be closed if at the close of the candle ()th the position remained open.(2)Position will be closed if at the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit (in this case loss) will be calculated as (3)Position will be closed if inside the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit (in this case loss) will be calculated as (4)Position will be closed if at the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit will be calculated as (5)Position will be closed if inside the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit will be calculated as (6)Position will be closed if at the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit will be calculated as (7)Position will be closed when inside the opening of the next ()th, the candle after th candle, in which the position was opened, the following condition is met: Then the profit (in this case loss) will be calculated as Additional conditions that are checked with each closing are the rules containing parameters , , and . These parameters are found in the rules limiting the risk of an unacceptable failure. Moreover, the principle stating that in the case when the opening took place at the beginning of the candle, it is permissible to keep it open until following candle is opened was used. Because of that, it was possible to avoid ambiguity involving the unpredictable sequence of the SL and TP.

3. Strategy Analysis

In both strategies a fixed period of learning is assumed (in the presented solution, 1000 one-hour candles), followed by a testing period. Data from learning period were used to find a class of patterns which allowed achieving maximum for the selected criterion, in this study Calmar ratio (which is defined as a final profit to maximum drawdown ratio) was selected. The same patterns were then searched during the test period and the test results were computed for previously unused data space. Of course, these results do not have to already be positive and acceptable and could negatively surprise investors. During the test the maximum rate of net profit (with transaction costs) was considered as a measure of the effectiveness of the investment. The authors believe that these two criteria in evaluating the quality of simulation results are legitimate. In the first phase of the validation, the training period is indicated for moderate and prudent risk management. In the test phase (in terms of actual trading) investor is mainly interested in profit.

The main aim of the research was to obtain the most effective investment strategies by dynamic selection of test period duration. Later in this paper concepts of learning period, a fixed-length 1000 candles but with different start in time, were used. Immediately after period of learning there was a variable-length test period. The authors look for the best (by the criteria described above) length of the test period in their research. This most preferred length of the learning period can be understood in two ways. This length can be changed after each learning period adjusted by additional current information feedback about profits or losses in the test period. It may also be the average length of the test window established on the basis of several recent validations.

Given that the search space is relatively broad and unknown (it is difficult to estimate how specific combination of parameters would influence strategy’s effectiveness) it is necessary to define its boundaries and then to find a combination of parameters that would maximize strategy’s efficiency. In the first step of the process, a pseudorandom strategy is used to find the boundaries of the parameter space in which may exist the optimal solution. Calmar ratio value was used to assess the adequacy of randomly selected parameter combinations for a given period of learning. It would be possible to use an iterative method that would traverse the search space with certain step. However it would be extremely time consuming method given that the space is 11-dimensional. In the second stage PSO (Particle Swarm Optimization) [20] algorithm, which already has been proved useful in finding optimal strategy parameters [21] and allows to find a satisfying combination of parameters values in relatively short time even in broad search spaces, was used. Search space for PSO algorithm has been defined in previous step. The objective function was to maximizing the Calmar ratio, as it was in the first step. The above tactic was used for each stage of the learning period and then checked “sustainability” of designated sets of parameters for test periods of different lengths—the basic rate of 100 candles and the other in the range of 10–400. Figure 2 shows how the research was conducted. Having historical data for 1000 candles, optimal parameters, for said data, have been found using approach described above. After the parameters search, tests was performed on the current data. The strategy for the learned parameters should be used as long as it will bring satisfactory results on new data. When results were no longer good enough, the next parameters search were performed on next piece of historical data. Thus, the authors aim is to determine the point where those parameters should be recalculated. Additionally, the authors set out to test a new standard of quality prediction. Now, extending the period of testing can produce better results, but more slowly or with local drawdown in comparison to first period, when the classifier “remembers” the nature of the market. This new criteria is profit attributable to one candle of the testing period.

Figures 3(a) and 3(b) show the cumulative profit for the test period equal to 100 candles (hours) for the two examined strategies.

It may be noted that the two policies, for the test period of 100, allow for systematic profit in examined period with only small drawdowns. Profit for the strategy TewiMiC 0.355, for TewiMiD profit is several times smaller and amounts to 0.094. But second strategy has smaller drawdowns. In addition, it is confirmed with the higher Calmar ratio—12.79—where the result for first of these strategies is 10.22. According to the authors, results are excellent, achieved on testing sections, not on the learning periods. On learning periods, of course, significantly better results were achieved with classifier matching. It is also clear that asymmetry results for the two strategies arise from different approaches—the first one is focused on horizontal trend, the other on a downward trend. The results depend on the nature of the market, which is automatically founded by learning strategies. Perhaps at another period of time, for other data these results could be different. In addition to the basic performance of the length of the test period equal to 100, a number of studies were conducted on different lengths of the testing period. There may be more favorable length of test window than arbitrarily selected window length of 100 candles.

Results for TewiMiC. Figures 4 and 5 show the results of the strategy TewiMiC. First (Figure 4(a)) shows the effect of test duration on the profit curve in time. To show how long in the test period optimal results are achieved we plotted 2D (twodimensional) chart of final profit for each of the examined sizes. Figure 4(b) shows that the number of candles for achieving high and satisfactory results are attributable to 80–120. The window size 100 reflects quite well expected test section.

Due to the different lengths of studied test periods, more reliable value used when making the decision is earnings per candle (that shows how much can strategy earn in one hour). This is shown in Figures 5(a) and 5(b). On this basis, Table 1, it can be concluded that the strategy is most effective for the testing period length between 60 and 110 hours. It can therefore be concluded that the average window of 100 candles well “remembers” the learned classifier parameters. Many times in the classification of patterns, it is important whether patterns are frequent. Part of the dilemma is solved by introducing earnings per candle but also in Table 1 a count of opened market positions in the testing periods is presented.

Results for TewiMiD. Figures 6(a) and 6(b) show impact of the length of the test period on the profit curve. In case of TewiMiD strategy it is difficult to determine the optimal interval length of the testing period.

It is possible, however, due to graphs showing earnings per hour (candle) (Figures 7(a) and 7(b)), depending on the length of the period and Table 2 listing the final results of the two studies. Similarly to the first strategy, length of this period is between 60 and 90 candles.

Of course, the optimal convergence test window length, at least approximately, is a great convenience in design of automatic strategy for algotrading. It should be noted that the authors assume that it is possible to test each strategy separately and it is not required to synchronize.

4. Conclusion

Following a review of various lengths dependence validation periods shown in Figures 4(a) and 4(b) were obtained. It is fairly obvious that a good fit of the parameters of the test period will continue for some time after the end of the learning. This is due to the assumption that there are trends in the market in different direction. The nature of trends is well explored during the learning process. The authors have found that the use of optimization methods derived from the area of artificial intelligence, including the PSO [20], given good and quickly reached the optimum values of the rules of the classifier, and good results in the initial stages of the test period. Also PSO method proves its effectiveness in similar optimization problems [22, 23]. For longer test periods, it can indeed get good results; however, the effectiveness of the strategy per hour decreases significantly. Obtained results allow concluding that the constant average length of the test window is more efficient and easier to manage than a strategy adaptively changing the length of the period. Strategies properties discovered during the learning period are effective for a short time—for test data period—good lengths for both strategies are about 50 to 120 hours at 1000 hours of learning time. In the real market it usually means from 2 to 5 days. It can be assumed that the re-learning of the parameters of the strategy should be carried out 1-2 times a week. This frequency is quite practical even for manual search of optimal parameters without fully automatic trading.

Presented trading strategies (substrategy TewiMiC and TewiMiD) are complementary, since each variant can develop a set of different parameters. Separate sets of parameters are adapted better to the nature of the market during optimization. It allows, for example, trading long positions in the markets with more frequent upward trends. It should be noted that a further optimizations discovered trends that are short-term and during one cycle of validation several changes in these trends can occur. These changes could be of different lengths. Then there is the situation that one of the variants of the strategy takes into account the length of trends for deviating significantly from trends indicated by the second variant. The two strategy variants are part of an investment strategy that allows you to combine the four options of trading strategies. You can join the strategies presented with the strategies associated with the opening of long positions based on condition (order) Buy Stop and short positions in accordance with the model Sell Limit. It is possible to add to the current strategies additional sub strategies associated with opening long positions (based on condition for Buy Stop order) and short positions (in accordance with the Sell Limit model). Interesting, according to the authors, may also be improving the combined strategies through the synthesis of recommendations. An example of such improvement may be combination of four variants, some of which (e.g., 3) indicate the need for the purchase, and some (such as 1) the need to conclude the sale of stock—then the number of transactions that were made results from accumulating all of the variants (in presented case—2 purchases). This implies a lower cost (e.g., 2 times smaller). Transaction costs for certain decisions tests can be omitted, and this reduction significantly affects the efficiency improvement investment strategy. The studies take into account the transaction costs for the pessimistic (above average costs in popular brokers). In practical terms, the strategy has big potential. With traditional software, trading programs (such as Metatrader) do not have the possibility of converting simple strategy parameters during operation. This implies the need for a hybrid solution, consisting, for example, of interprocess communication between the trading software and program developed in universal high-level language (e.g., Matlab, C#). Algotarding future will very likely be increasingly active domain for experts in algorithmization and programming and less and less for economists and econometricians.

Authors are aware of the fact that the parametric space is broad and choosing right ones is not a trivial task. It is not obvious that chosen and presented in this paper parameters are the best. There are no obvious sources that would suggest which parameters should be considered in investment strategies. To determine the parameters utilized in presented strategies an iterative computation has been used—after adding parameter the results were assessed and when they were acceptable the following parameter was added to the strategy. Even though selected parameters resulted in high efficiency, it does not mean that one should refrain from searching for better choice of parameters. Presented results can be considered as particularly good and are reproducible by scrupulous reader. Alternative strategies can be compared with presented ones using the same criteria (i.e., Calmar ratio). For many years the authors have been improving following strategy and its implementation in the real market. Current and future research aims to study the influence of the number of parameters—expanding or limiting the parameter space—and adding two additional substrategies based on the same band as aforementioned.

Conflict of Interests

The authors declare that there is no conflict of interests regarding the publication of this paper.


This work is done within the Project TEWI financed from the Innovative Economy Programme in years 2012 and 2013.

Supplementary Materials

Supplementary material include MATLAB scripts that allow to perform tests of strategies presented in the article. Main file for TewiMiC strategy is TewiMiCAllPeriods and for TewiMiC is TewiMiDAllPeriods. These materials also include csv files with sets of optimal parameters for each strategey.

  1. Supplementary Material