MQL5 Cookbook Developing a Framework for a Trading System Based on the Triple Screen Strategy

Post on: 16 Март, 2015 No Comment

MQL5 Cookbook Developing a Framework for a Trading System Based on the Triple Screen Strategy

Introduction

When searching for or developing trading systems, many traders must have heard about the Triple Screen strategy introduced by Dr. Alexander Elder. There are lots of people in the Internet whose judgment on that strategy is negative. However, many people believe that it can help one to profit. You do not have to trust either of the two opinions. Everything should always be checked first-hand. If you study programming, it’s all in your hands as you can check the trading strategy performance using back-testing.

In this article, we will develop a framework for a trading system based on the Triple Screen strategy in MQL5. The Expert Advisor will not be developed from scratch. Instead, we will simply modify the program from the previous article MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors. So the article will also demonstrate how you can easily modify patterns of ready-made programs.

The Expert Advisor from the previous article already features the possibility to enable/disable the Stop Loss/Take Profit and Trailing Stop levels, position volume increase and position reversal on the opposite signal. All the necessary functions have been set in place. So our task is centered around changing the list of external parameters by adding additional options and modifying some existing functions.

For illustrative purposes, we will arrange for signals on three time frames to be generated using the Moving Average indicator. Later on, in continuing to experiment on the developed framework, you will be able to employ any other indicator by slightly modifying the code. We will also implement the opportunity to set time frames for each screen. If the parameter responsible for the indicator period has zero value, this will denote that the corresponding screen is not used. In other words, the system can be set up to have one or two time frames.

Before you start, make a copy of the folder with the files of the Expert Advisor from the previous article and rename it.

Expert Advisor Development

Let’s start with the external parameters. Below is the code of the updated list. New lines are singled out. Time frames are declared with the ENUM_TIMEFRAMES enumeration type. You will be able to select any time frame from the drop-down list.

The IndicatorSegments parameter, as well as the AllowedNumberOfSegments variable and the CorrectInputParameters() function have been removed to simplify the example. Those of you who are interested in this condition can try to implement it on your own. You should also remove the enumeration of indicators in the Enums.mqh file as this Expert Advisor will only employ one indicator.

Since there will be a separate indicator on each time frame, we will need a separate variable to get a handle of each of the indicators:

The new bar will be checked using the minimum time frame. When setting the minimum time frame in the external parameters, we do not have to follow a specific order, i.e. maximum, intermediate, minimum. The reverse order and basically any order would do. So we need a function that will identify the minimum time frame out of all time frames specified.

Since the Expert Advisor can be set to operate on three time frames, as well as on one or two, all options need to be considered when determining the minimum time frame. Below if the code of the GetMinimumTimeframe() function:

To save the minimum time frame value, we will create another global scope variable:

The GetMinimumTimeframe() function will need to be called when initializing the Expert Advisor in the OnInit() function.

The MinimumTimeframe variable value is then used in the CheckNewBar() and GetBarsData() functions.

The GetIndicatorHandle() function now looks as shown below. The period and time frame is specified for each indicator.

Further, we need to add arrays for getting indicator values (separately for each time frame):

The GetIndicatorsData() function for getting indicator values now looks as shown below. The obtained handles are checked for accuracy and if everything is fine, the arrays are filled with indicator values.

The GetTradingSignal() and GetSignal() functions should be modified according to the task at hand. Below is the code of these functions for your consideration.

The GetSignal() function, just like in determining the minimum time frame, takes into account all possible variants of external parameter states relating to position opening conditions. The code of the function is provided below:

Now, we only need to make small changes to the OnInit() and OnDeinit() functions. You can see the changes highlighted in the below code:

The framework for trading systems based on the Triple Screen strategy is ready. It can be modified at any time, by changing the indicators or adding some additional conditions, if necessary.

Optimizing Parameters and Testing Expert Advisor

Let’s proceed to parameter optimization and check the results. The Strategy Tester is set as shown below (be sure to specify the lowest of the three time frames):

Fig. 1. Strategy Tester settings.

MQL5 Cookbook Developing a Framework for a Trading System Based on the Triple Screen Strategy

The Expert Advisor parameters for optimization have been set as shown below. Time frames can be set for optimization but I prefer to set them manually.

Fig. 2. Settings of the Expert Advisor.

The optimization has been completed in about 30 minutes on a dual-core processor. The Optimization Graph is provided below:

Fig. 3. Optimization Graph.

Maximum balance test results show less drawdown than the maximum recovery factor test results, which is why the maximum balance test results are used for demonstration purposes:

Fig. 4. Maximum balance test results.

Fig. 5. Maximum balance test graph.

Conclusion

The article has demonstrated that the Expert Advisor can be fairly quickly modified, if the main functions are available. You can get a new trading system by only changing the signal block and indicators. Attached to the article is a downloadable archive containing the source codes of the Expert Advisor described herein above for your further self-study, as well as a set-file with the input parameter settings.

Categories
Options  
Tags
Here your chance to leave a comment!