Programming your strategy in 10 steps with Universal Expert Advisor and Open Source

现成专家与编程/自由职业者的优势。
基于报价速度的剥头皮系统!Ping 和数据中心。
现成专家与编程/自由职业者的优势。
基于报价速度的剥头皮系统!Ping 和数据中心。

Table of Contents (click to show)

List

Description

The X is a builder of trading strategies.

We have developed a Universal Expert Advisor that encompasses all the most intriguing and essential functions.

Additionally, a signal module utilizing standard indicators has been incorporated.

This is a strategy builder, allowing you to program your own strategy.

It started as a project that gained significant popularity. For 15 years, we have been refining the algorithm, adding new functions and indicators, and correcting function errors.

This article will guide you through programming your strategy, integrating indicators into the advisor, and adding new signals and filters.

Open Source

A recurring question we receive is:

  1. Can I integrate my indicators into an advisor?
  2. How much does the open-source code of the Expert Advisor cost?

It’s no secret that we offer the open-source code of our advisor for sale. This is intended for traders who wish to develop their own advisors or build their own signals.

Furthermore, traders often purchase open-source code to implement their proprietary strategies and resell the advisor.

  1. The open-source code of the advisor The X can be purchased in our Market of Trade Advisors.
  2. Open Source The X for MetaTrader 5 (Not available)
  3. Open Source The X for MetaTrader 4 (Not available)
  4. By the way, we have many open-source codes for our advisors. Section: Strategy Advisors (Open Source)
  5. Try our Open Source Templates.

Programming advisors with indicators is a complex process.

We offer programming services for trade advisors. However, the development process often faces delays because clients are unsure of the functions they require.

The X is a collection of blocks and functions for trading on the FOREX market, utilized globally. We have developed functions that are frequently used, enabling the advisor to meet 90% of each trader’s needs.

Naturally, there are unique strategies that experienced programmers need to develop.

Such strategies are rare and require meticulous preparation. The cost of this work depends on its complexity.

The Real Value of Our Advisor

Starting with our article on the cost of a programmer’s work, we can estimate the approximate cost of our trading robot, The X:

Our EA contains over 10,000 lines of code. While this may seem extensive, it’s manageable because we do not write advisors using PL/SQL (Programming Language/Structured Query Language). Why? Because OOP (Object-Oriented Programming) is unfamiliar to many, and handling OOP can be quite challenging!

So, let’s calculate:

  1. The cost of 1 hour of a programmer’s work = $20 when programming functions and algorithms.
  2. The cost of 1 hour of error correction = $5.
  3. The cost of writing texts and videos = $10 (This price is based on internet rates; I create all instructions and videos myself).
  4. Assume that writing functions and blocks for The X took over 1,000 hours!
  5. Programming signals using indicators is straightforward. Therefore, we assume it took us 10 hours!

However, some aspects cannot be completed immediately:

  1. Debugging functions can take an additional 1,000 hours!
  2. Developing instructions, videos, and promotions also requires 1,000 hours!

In total, we have invested over 3,000 hours!

If we were to commission such an algorithm, we would decline. It is neither reasonable nor profitable.

The total cost of such a custom expert advisor is over $35,000! However, our advisor is sold at a price ten times lower!!!!

The cost of our open-source is TEN times less!

Such custom orders are never fulfilled:

  1. Firstly, because customers are unwilling to invest such a significant amount of money.
  2. Secondly, programmers are reluctant to dedicate so much time to development.

I assure you that programming such a complex trading robot requires more time than creating a trading strategy.

Debugging all the blocks and functions demands extended time.

We are extremely grateful to our customers who have identified mistakes and provided corrections over the past five years, as well as contributed their functions and indicators to enhance the functionality of the advisor THE X.

Programming Your Forex Trading Strategy

Firstly, I want to mention that we have updated our expert advisor’s code. It is now very easy to understand and well-commented.

You don’t need to delve into every function in detail. You can program your strategy in just 10 steps.

We have prepared a very user-friendly method for working with our open source.

Remember: We do not program strategies for the advisor for free. If you want to develop code for your strategy, please refer to the Programming section to place an order!

First Steps:

  1. Open the open-source code of the advisor that you purchased from our Market of Advisors;
  2. Press Ctrl + F to activate the search bar;
  3. Enter the term Step – This keyword will help you navigate our source code and quickly write your strategy.
  4. Search Function in Source Code
  5. Each step is well-commented and provides an example.
  6. To learn how to program your strategy, you can gradually uncomment lines marked with an asterisk // *.

In total, there are 10 steps in the open-source code for the advisor to work with your indicators.

Strategy Builder Interface

We will analyze each step in detail!

Since programming differs between the MT4 and MT5 terminals, we will divide our article into two parts:

If you are using the advisor THE X for the MT4 terminal, you can proceed directly to the Programming section for The X on the MetaTrader 4 terminal.

Programming THE X for MetaTrader 5

You need to understand the basic programming rules to develop your strategy or add a ready-made strategy using indicators from existing files (e.g., Expert Advisors from the Internet).

Programming advisors for MetaTrader 5 is more complex than for MetaTrader 4. However, the MT5 terminal allows for the creation of more powerful strategies and features a more advanced strategy tester.

In any case, you should purchase the open-source code on which the terminal will operate.

MetaTrader 5 Step 0: Loading Indicators into Resources!

// Step 0 ##############################################
// This part of the code is for programming your strategy in open source
//
// To embed the indicator into the Expert Advisor during compilation, you need to load it into the resources of the Expert Advisor
//
// For example:
// * #resource "\\Indicators\\Examples\\MACD.ex5"
// ################################################ ###########################

Here, we must add the indicators required by us to the resources.

This ensures that the advisor can be compiled for the market and prevents unnecessary issues where the compiled advisor cannot locate the desired indicator on another computer.

Rules for Naming in the Market: Use the full folder names, starting with Indicators!

The folder is denoted by \\.

For example:

If the path to your indicator is:

C:\ROBO MT5\MQL5\Indicators\Examples\MACD.ex5

Then, the path to this indicator in the programming language is written as:

“\\Indicators\\Examples\\MACD.ex5”

MetaTrader 5 Step 1: Specify the Signal Name!

// Step 1 ##############################################
// This part of the code is for programming your strategy in open source
//
// Enter the name of your signal after //
// ################################################ ####################
// For example:
// * Custom = 77, // Signal For open source
// ################################################ ############################

At this step, we must add our signal or strategy to the list of possible signals in the Expert Advisor.

This facilitates convenient management of signals during the expert setup phase.

Specifying Signal Name in Code

For example:

  1. You want to name your strategy MY STRATEGY
  2. The strategy number must also be unique. Signals from standard indicators occupy the first 22 numbers! Remember this number as we will need it later.
  3. The name must also be unique. For example, MYSTRATEGY1

In the end, we should write in the code as follows:

MYSTRATEGY1 = 77, // MY STRATEGY

You can also add more strategies and write, for example:

  1. MYSTRATEGY1 = 77, // MY STRATEGY a
  2. MYSTRATEGY2 = 78, // MY STRATEGY b
  3. MYSTRATEGY3 = 79, // MY STRATEGY c

MetaTrader 5 Step 2: Specify the Signal Display Name!

// Step 2 ##############################################
// This part of the code is for programming your strategy in open source
//
// Enter the name of your signal, which will be displayed on the screen after //
// ################################################ ####################
// For example:
// * if (i == 77) s1 = "Custom";
// ################################################ ###########################

This step is to display the name of your strategy in our EAPADpro EA panel.

It’s straightforward! However, you must use the numbers from the previous step.

Displaying Signal Name

For example:

  1. if (i == 77) s1 = “My1”;
  2. if (i == 78) s1 = “My2”;
  3. if (i == 79) s1 = “My3”;

MetaTrader 5 Step 3: Specify the Filter Name!

// Step 3 ##############################################
// This part of the code is for programming your strategy in open source
//
// Enter the name of your filter after //
// ################################################ ####################
// For example:
// * FILTERCustom = 77, // Filter For open source
// ################################################ ###########################

At this step, we need to add our filter to the list of possible filters in the Expert Advisor.

This ensures convenient management of filters during the expert setup phase.

Typically, the Filter uses the same indicator as the Signal, but with the condition that the Filter determines the current position of the Signal, and the Signal reflects the actual signal.

For example:

  1. Do you want to name your Filter MY FILTER?
  2. The filter number should also match the strategy number (This prevents confusion with other figures in the future). Filters occupy the first 22 numbers from standard indicators! Remember this number as we will need it later.
  3. The name must also be unique. For example, MYFILTER1

In the end, we should write in the code as follows:

MYFILTER1 = 77, // MY FILTER

You can also add more filters and write, for example:

  1. MYFILTER1 = 77, // MY FILTER a
  2. MYFILTER2 = 78, // MY FILTER b
  3. MYFILTER3 = 79, // MY FILTER c

MetaTrader 5 Step 4: Specify the Parameters of the Indicator or Strategy in External Variables!

// Step 4 ##############################################
// This part of the code is for programming your strategy in open source
//
// Specify all external variables of your indicator or indicators that will be used in your strategy
//
// For example:
// * input string IndicatorName = "-------- Custom Indicator ----------------";
// * input int CUSTOMMAFastPeriod = 1;
// * input int CUSTOMMASlowPeriod = 100;
// * input ENUM_APPLIED_PRICE CUSTOMMAprice = PRICE_CLOSE;
// ################################################ ###########################

At this step, you must enter all external settings of the indicators in your strategy, which can be modified from the Expert Advisor. This is useful for optimization purposes.

Additionally, you can extract specific strategy parameters here. For example, the levels where lines intersect, limiting the indicator’s operation to MAX and MIN prices on the chart, and so on.

You do not need to enter all parameters for the indicators. It’s sufficient to make those that you may want to change in the future from the Expert Advisor settings. All other parameters can be set to their default values.

Specifying Indicator Parameters

MetaTrader 5 Step 5: Create Indicator Handles to Load into the Expert Advisor!

// Step 5 ##############################################
// This part of the code is for programming your strategy in open source
//
// Create an entry in the array so that the Expert Advisor can assign the indicator handle during initialization
//
// For example:
// * case 77:
// * h_custom[tf_num][sym_num] = iCustom(array_symbol, array_tf, "::Indicators\\Examples\\MACD", CUSTOMMAFastPeriod, CUSTOMMASlowPeriod, 9, CUSTOMMAprice);
// * if (h_custom[tf_num][sym_num] == INVALID_HANDLE)
// * {
// *     PrintToLogs("Could not get MACD indicator handle");
// *     return(INIT_FAILED);
// * }
// ################################################ ###########################

This step ensures that our indicators are loaded once during the initialization of the Expert Advisor. In MetaTrader 5, there is no need to constantly load the indicator on the chart.

When creating a handle, we store the handle of an already opened indicator for future use.

Be very careful here. When creating a handle, you must specify all external variables of the indicator and use the correct name. Otherwise, the Expert Advisor will not be able to load the indicator.

Remember that we loaded the indicator into the Expert Advisor resources. Therefore, we will call the indicator from the resources!

You can refer to the MQL5 documentation on calling indicators using iCustom.

A strategy number is also required for writing this code. If your strategy uses multiple indicators, you need to specify each indicator with the same number. This ensures that the advisor correctly loads your strategy.

According to our examples above, we need to do the following:

case 77:
h_custom[tf_num][sym_num] = iCustom(array_symbol, array_tf, "::Indicators\\Examples\\MACD", CUSTOMMAFastPeriod, CUSTOMMASlowPeriod, 9, CUSTOMMAprice);
if (h_custom[tf_num][sym_num] == INVALID_HANDLE)
{
    PrintToLogs("Could not get MACD indicator handle");
    return(INIT_FAILED);
}
break;

Here, I explicitly specified only two external parameters. I replaced the parameter of this Indicator, InpSignalSMA, with a default number to demonstrate the essence of programming!

Similarly, you can add multiple indicators and handles.

If the strategy uses several indicators, you need to declare each one.

For example:

case 77:
h_custom[tf_num][sym_num] = iCustom(array_symbol, array_tf, "::Indicators\\Examples\\MACD", CUSTOMMAFastPeriod, CUSTOMMASlowPeriod, 9, CUSTOMMAprice);
h_custom2[tf_num][sym_num] = iCustom(array_symbol, array_tf, "::Indicators\\Examples\\MACD", CUSTOMMAFastPeriod, CUSTOMMASlowPeriod, 15, CUSTOMMAprice);
if (h_custom[tf_num][sym_num] == INVALID_HANDLE || h_custom2[tf_num][sym_num] == INVALID_HANDLE)
{
    PrintToLogs("Could not get MACD indicator handle");
    return(INIT_FAILED);
}
break;

Additionally, for other strategies you wish to integrate into the Expert Advisor!

MetaTrader 5 Step 6: Declare Variables to Load the Indicator(s) of the Strategy!

// Step 6 ##############################################
// This part of the code is for programming your strategy in open source
//
// Declare the handle array variables
//
// For example:
// * int h_custom[6][12];
// * int h_custom2[6][12];
// ################################################ ###########################

Here, we specify the names of our handles that were created above!

It’s straightforward.

Handles are created as arrays to support multi-currency in the EA and to allow specifying up to six signals or filters simultaneously!

MetaTrader 5 Step 7: Declare Variables for Storing Indicator Data!

// Step 7 ##############################################
// This part of the code is for programming your strategy in open source
//
// Declare the array variables for indicator values
//
// For example:
// * double custom1_buffer[];
// * double custom2_buffer[];
// ################################################ ###########################

Here, we specify the names of our data buffers!

It’s straightforward.

These arrays will store data about the indicator values for each bar. If you need to use multiple buffers, you can declare several variables.

In our case, for example, we need two buffers for the signal line and the main line of the MACD indicator.

Declaring Indicator Data Variables

MetaTrader 5 Step 8: Create Strategies and Signals for Opening Positions!

This step is crucial for the Expert Advisor. While all other steps are mandatory, without this step, the advisor will not function.

I have included comments in the code to explain each part!

The strategy number must match the one used in previous steps!

  1. Program the code for each strategy and signal individually. It depends on the chosen strategy and indicators. Handling buffers for strategies involves…
  2. Note that in this block, you can specify any strategy.
  3. All the indicators declared in the handles will be loaded into memory and used to build the strategy.
Creating Strategies and Signals

This step can be divided into three substeps:

  1. 1. We need to copy data buffers to our datasets. In the copy parameters, we must specify the line numbers (In our case, these are MACD indicator lines).
  2. We use two lines: MAIN and SIGNAL.
  3. You can read the documentation on the CopyBuffer function.
  4. 2. Programming the strategy. In this case, it’s the intersection of two lines.
  5. Important: The signal for BUY is 1, and for SELL, it is -1.
  6. 3. Here, we record the information that will be displayed in the log when a position is opened based on the signal. Strategy Information.

If you have correctly filled all the handles and buffers, the following should appear on the screen:

Alert(“Congratulations, you’ve completed a lesson demonstrating the programming of your strategy!”);
Alert(“Congratulations! You have completed a lesson demonstrating the programming of your strategy!”);
If you receive an error message, you need to identify and resolve the cause of this error.

Error Codes

Most common errors:

ERR_INDICATOR_UNKNOWN_SYMBOL4801Unknown symbol
ERR_INDICATOR_CANNOT_CREATE4802The indicator cannot be created
ERR_INDICATOR_NO_MEMORY4803Insufficient memory to add an indicator
ERR_INDICATOR_CANNOT_APPLY4804The indicator cannot be applied to another indicator
ERR_INDICATOR_CANNOT_ADD4805Error while adding the indicator
ERR_INDICATOR_DATA_NOT_FOUND4806The requested data was not found
ERR_INDICATOR_WRONG_HANDLE4807Incorrect indicator handle
ERR_INDICATOR_WRONG_PARAMETERS4808Incorrect number of parameters when creating an indicator
ERR_INDICATOR_PARAMETERS_MISSING4809Missing parameters when creating the indicator
ERR_INDICATOR_CUSTOM_NAME4810The first parameter in the array must be the name of the custom indicator
ERR_INDICATOR_PARAMETER_TYPE4811Incorrect parameter type in the array when creating the indicator
ERR_INDICATOR_WRONG_INDEX4812Invalid index of the requested indicator buffer

MetaTrader 5 Step 9: Specify Filters from Your Indicators or Use Your Indicator as a Filter for the Strategy!

The programming code in this step is straightforward and similar to the previous step.

The only difference is that at this stage, you program your indicators as a Filter.

You cannot specify signals using the indicator, but only specify the filter, or vice versa! It all depends on the strategy.

 

MetaTrader 5 Step 10: This is the final step!

// Step 10 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// This is the end of our code. If you have reached this step, then you have created your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, you will receive the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are working for you! 
// 
// Our website: 
// Our store: /shop 
// MQL5 store: https://www.mql5.com/users/vladon/seller 
// 
// 
// This is the end of our code. If you have reached this step, then you have created your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, you will receive the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are working for you! 
// 
// Our website: 
// Our store: /shop 
// MQL5 store: https://www.mql5.com/users/vladon/seller 
// ################################################ ###########################

This indicates that the programming of your strategy is complete.

Good luck and profits to you!

MetaTrader 5 Conclusions and Verification of the Strategy

If you do everything correctly, your strategy will be integrated into the Expert Advisor, and you will be able to trade using my advisor.

Now, we need to test our advisor and strategy.

  1. Load the terminal;
  2. Open a demo account;
  3. Attach the Expert Advisor to the chart;
  4. If all is OK, you will receive a message about the successful addition of the strategy:
    • Successful strategy addition message
  5. Or you will receive an error. In that case, you need to carefully review your code and repeat all the steps!

Checking the Expert Advisor in the Strategy Tester:

  1. Open the terminal;
  2. Open the Strategy Tester;
  3. Choose your Expert Advisor, currency pair, time frame, and date range. Enable Every Tick testing based on real ticks;
    • Strategy Tester settings screenshot
  4. Open the Settings tab;
    • Settings tab screenshot
  5. Select your strategy;
  6. Enable Visualization;
  7. Press START;
  8. A graph should open;
  9. If the Expert Advisor opens positions, you did everything correctly!
    • Expert Advisor opening positions

Programming THE X for MetaTrader 4

You must understand the basic programming rules to write your strategy or add a ready-made strategy for indicators from an existing file (e.g., Expert Advisors from the Internet).

Programming Expert Advisors for MetaTrader 5 is more complex than for MetaTrader 4. However, the MT5 terminal allows you to create more powerful strategies and features a more advanced Strategy Tester.

On the other hand, there are numerous strategies and indicators available for the MetaTrader 4 terminal online. Therefore, you can use the code for MT4!

Another important reminder: Coding a strategy in MT4 is much easier than coding in MT5!

In any case, you should purchase the open code based on the terminal you will be working with.

MetaTrader 4 Step 0: Loading Indicators into Resources

// Step 0 ############################################## ######################
    // This part of the code for programming your strategy in open source
    // This part of the code for programming your strategy in open source
    //
    // To embed the indicator into the Expert Advisor during compilation, you need to load it into the resources of the Expert Advisor
    // To embed the indicator into the Expert Advisor during compilation, you need to load it into the resources of the Expert Advisor
    // ################################################ ####################
    // for example:
    // * #resource "\\ Indicators \\ MACD.ex4"
    // ################################################ ###########################
    

Here, we must add the indicators required by us to the resources.

This will allow us to compile an advisor for the market and prevent unnecessary issues when the compiled Expert Advisor cannot find the desired indicator on another computer!

Rules for writing the indicator path: Use the full folder names, starting with Indicators!

The folder is indicated by \\

For example:

If the path to your indicator looks like this:

C:\ROBO MT4\MQL4\Indicators\Examples\MACD.ex4

Then, the path to this indicator in the programming language is written like this:

“\\Indicators\\Examples\\MACD.ex4”

MetaTrader 4 Step 1: Specify the Signal Name

// Step 1 ############################################## ###################### 
    // This part of the code for programming your strategy in open source 
    // This part of the code for programming your strategy in open source 
    // 
    // Enter the name of your signal after // 
    // Enter the name of your signal after // 
    // ################################################ #################### 
    // for example: 
    // * Custom = 77, // Signal for open source 
    // ################################################ ############################

At this step, we must add our Signal or strategy to the list of possible signals in the advisor.

This allows for convenient management of signals during the Expert Advisor setup phase.

Signal naming example

For example:

  1. You want to name your strategy MY STRATEGY
  2. The strategy number must also be unique. Signals from standard indicators occupy the first 22 numbers! Remember this number for future reference.
  3. The name must also be unique. For example, MYSTRATEGY1

In the end, you should write in the code like this:

MYSTRATEGY1 = 77, // MY STRATEGY

You can also add more strategies and write, for example, like this:

  1. MYSTRATEGY1 = 77, // MY STRATEGY a
  2. MYSTRATEGY2 = 78, // MY STRATEGY b
  3. MYSTRATEGY3 = 79, // MY STRATEGY c

MetaTrader 4 Step 2: Specify the Signal Name for Display on Screen

// Step 2 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Enter the name of your signal, which will be displayed on the screen, after // 
// Enter the name of your signal, which will be displayed on the screen, after // 
// ################################################ #################### 
// for example: 
// * if (i == 77) s1 = "Custom"; 
// ################################################ ###########################

This step serves to display the name of your strategy in our EApadpro EA panel.

There is nothing complicated! But you must use the numbers from the previous step.

Signal name display example

For example:

  1. if (i == 77) s1 = “My1”;
  2. if (i == 78) s1 = “My2”;
  3. if (i == 79) s1 = “My3”;

MetaTrader 4 Step 3: Specify the Filter Name

// Step 3 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Enter the name of your filter after // 
// Enter the name of your filter after // 
// ################################################ #################### 
// for example: 
// * FILTERCustom = 77, // Filter for open source 
// ################################################ ###########################

At this step, we need to add our Filter to the list of possible filters in the Expert Advisor.

This allows for convenient management of filters during the Expert Advisor setup phase.

Usually, the Filter uses the same indicator as the Signal, with the condition that the Filter determines the current position of the Signal, and the Signal confirms the trading action.

Examples of differences between filters and signals

For example:

  1. Do you want to name your Filter MYFILTER?
  2. The number of the filter should also match the number of the strategy (This is done to avoid confusion with standard indicator numbers in the future). Filters occupy the first 22 numbers reserved for standard indicators! Remember this number for future reference.
  3. The name must also be unique. For example, MYFILTER1

In the end, you should write in the code like this:

MYFILTER1 = 77, // MY FILTER

You can also add more filters and write, for example, like this:

  1. MYFILTER1 = 77, // MY FILTER a
  2. MYFILTER2 = 78, // MY FILTER b
  3. MYFILTER3 = 79, // MY FILTER c

MetaTrader 4 Step 4: Specify Indicator or Strategy Parameters in External Variables

// Step 4 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Specify all external variables of your indicator or indicators that will be used in your strategy 
// Specify all external variables of your indicator or indicators that will be used in your strategy 
// ################################################ #################### 
// for example: 
// * input string IndicatorName = "-------- Custom Indicator ----------------"; 
// * input int CUSTOMMAFastPeriod = 1; 
// * input int CUSTOMMASlowPeriod = 100; 
// ################################################ ###########################

At this step, you must enter all external settings of the indicators used in your strategy, which can be changed from the Expert Advisor. This is useful for optimization.

Additionally, you can extract specific parameters of the strategy, such as the levels of line intersections, the limitation of the indicator’s operation based on MAX and MIN prices on the chart, and so on.

You do not need to enter all parameters for the indicators. It is sufficient to include those that you may want to change in the future from the Expert Advisor settings. For all other parameters, you can leave the indicator with its default settings.

External variables setup example

MetaTrader 4 Steps 5, 6, 7: Relax!

// Step 5 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Step 5 is only needed for the MT5 terminal. So at this step, you can relax and have a coffee 
// Step 5 is only necessary for the MT5 terminal. So at this step, you can relax and have a coffee 
// ################################################ ###########################
    
// Step 6 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Step 6 is only needed for the MT5 terminal. So at this step, you can relax and have a snack 
// Step 6 is only necessary for the MT5 terminal. So at this step, you can relax and have a snack 
// ################################################ ###########################
    
// Step 7 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Step 7 is only needed for the MT5 terminal. Take a workout break 
// Step 7 is only necessary for the MT5 terminal. Take a workout break 
// ################################################ ###########################

Note: MetaTrader 4 does not require loading indicators into memory for further work. When the indicator is called again in MT4, the Expert Advisor uses the same handle.

MetaTrader 4 Step 8: Creating Strategies and Signals for Opening Positions

This step is very important for the Expert Advisor. Although all other steps are mandatory, without this step, the advisor will not function.

I have added comments in the code!

The strategy number matches the one from the previous steps!

  1. Programming code for strategy and signal individually. It depends on the chosen strategy and indicators. Setting up strategy buffers…
  2. I want to note that in this block, you can specify any strategy.
  3. All the indicators that we declared in the handles will be loaded into memory and used to build the strategy.
Strategy buffers example

This step can be divided into 2 substeps:

  1. 1. Programming the strategy. In this case, it is the intersection of two lines.
  2. Important: The Signal for BUY is 1, and for SELL, it is -1.
  3. 2. Record the information that will be displayed in the log when a position is opened. Strategy Information

If you receive an error message, you need to identify the cause of the error.

Error Codes

Most common errors:

ERR_INDICATOR_UNKNOWN_SYMBOL4801Unknown symbol
ERR_INDICATOR_CANNOT_CREATE4802The indicator cannot be created
ERR_INDICATOR_NO_MEMORY4803Not enough memory to add an indicator
ERR_INDICATOR_CANNOT_APPLY4804The indicator cannot be applied to another indicator
ERR_INDICATOR_CANNOT_ADD4805Error while adding the indicator
ERR_INDICATOR_DATA_NOT_FOUND4806The requested data was not found
ERR_INDICATOR_WRONG_HANDLE4807Wrong indicator handle
ERR_INDICATOR_WRONG_PARAMETERS4808Incorrect number of parameters when creating an indicator
ERR_INDICATOR_PARAMETERS_MISSING4809Missing parameters when creating the indicator
ERR_INDICATOR_CUSTOM_NAME4810The first parameter in the array must be the name of the custom indicator
ERR_INDICATOR_PARAMETER_TYPE4811Incorrect parameter type in the array when creating the indicator
ERR_INDICATOR_WRONG_INDEX4812Invalid index of the requested indicator buffer

MetaTrader 4 Step 9: Specify Filters from Your Indicators or Use Your Indicator as a Filter for the Strategy

In this step’s code programming, there is nothing complicated, and it is similar to the previous step.

The only difference is that at this stage, you program your indicators as a Filter.

You cannot specify signals using the indicator, but only specify the filter, or vice versa! It all depends on the strategy.

 

MetaTrader 4 Step 10: This is the Final Step!

// Step 10 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// This is the end of our code. If you have reached this step, then you have created your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, you will receive the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are working for you! 
// 
// Our website: 
// Our store: /shop 
// MQL5 store: https://www.mql5.com/users/vladon/seller 
// 
// 
// This is the end of our code. If you have reached this step, then you have created your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, you will receive the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are working for you! 
// 
// Our website: 
// Our store: /shop 
// MQL5 store: https://www.mql5.com/users/vladon/seller 
// ################################################ ###########################

This step was created so that you are not lost when using the search.

This indicates that the programming of your strategy is complete.

Good luck and profits to you!

MetaTrader 4 Conclusions and Strategy Check

If you do everything correctly, your strategy will be integrated into the Expert Advisor, and you will be able to trade using my advisor.

Now, we need to test our advisor and strategy.

  1. Load the terminal;
  2. Open a demo account;
  3. Attach the Expert Advisor to the chart;

Checking the Expert Advisor in the Strategy Tester:

  1. Open the terminal;
  2. Open the Strategy Tester;
  3. Choose your Expert Advisor, currency pair, time frame, and date range. Enable Every Tick testing based on real ticks;
    • Strategy Tester selection screenshot
  4. Open the Settings tab;
    • Strategy Tester settings tab screenshot
  5. Select your strategy;
  6. Enable Visualization;
  7. Press START;
  8. A graph should open;
  9. If the Expert Advisor opens positions, then you did everything correctly!
    • Expert Advisor positions opened screenshot

What Else Can Be Changed in the Expert Advisor?

Of course, you may want to personalize your strategy and give our advisor a unique appearance!

Parameters that you can change at your discretion:

 // Change 1: Version of Expert Advisor // Version of EA
#define versionea "18.008" 
// Change 2: Advisor's logo // LOGO of EA
#define BMPLOGO "Images\\dollar.bmp"
// Change 3: Icon of the Expert Advisor // Icon of EA
// #property icon "\\Images\\dollar.bmp"
// Change 4: Name of the Expert Advisor on the chart // Name of EA on Chart
#define defEANAME "EXP-The X (OS)"
// Change 5: Link to the full instruction // Link to the full instruction
#define linkTOfull "www.expforex.com/publ/4-1-0-166" 
// Change 6: Demo version of the Expert Advisor. Works only on a demo account or on a live account with the USDJPY pair // Demo version of the advisor. Works only on a demo account or on a live account with the USDJPY pair
bool DEMO = false;
    

All other parameters are recommended not to be changed, as this may disrupt the functionality of the Expert Advisor!

Debugging a Strategy

The next step is to test and optimize The X and find your best settings.

Alternatively, debug and upgrade your strategy.

Sometimes, it takes days or weeks. Sometimes, even months.

Forex Market – Risk Notifications! This is a very risky way of earning. Improve your strategy.

Good luck and profit!

Outputting Additional Information in the Strategy Block

This is an optional feature in our open-source code.

You can output any value of any parameter in the EAPADPRO Strategy block.

1. To do this, create a local variable,

e.g., double EAPADPRO_StrategyValue1 = 0; double EAPADPRO_StrategyValue2 = 0;

2. Assign a value to this variable,

for example, assign the value of the ATR indicator (find the line double atr = iATR):

EAPADPRO_StrategyValue1 = atr;
EAPADPRO_StrategyValue2 = atrma;

Full filter code:

3. Next, add the value of the variable to the information output block:

Find the function CreateStrategy() in the code and add a new line:

ArrayAddStrategy("StrategyValue1", DoubleToString(EAPADPRO_StrategyValue1, 5), "", "");
    
ArrayAddStrategy("StrategyValue2", DoubleToString(EAPADPRO_StrategyValue2, 5), "", "");

The first parameter of the function is the name of the variable.

The second parameter of the function is the value of the variable in a convenient format!

Attention! Add an even number of parameters to ensure a neat display on the screen!

Extra Report Pad – 交易者日记。专业分析您的交易账户。实时图表中的 MyFxBook。ExtraReportPad

Extra Report Pad – 交易者日记。专业分析您的交易账户。实时图表中的 MyFxBook。ExtraReportPad

Extra Report Pad – 专业的交易账户分析解决方案 今天,必须同时交易多个货币对。但是交易越多,分析账户盈利能力就越困难。按月分析交易更加困难。更不用说单独计算每笔交易的统计数据了。 我们找到了一个解决方案:我们的面板可以实时分析您的账户,并尽可能详细地编制统计数据。…

Assistant – 最佳免费交易面板,支持持仓并处理真实/虚拟止损 /获利 /跟踪止损 交易

Assistant – 最佳免费交易面板,支持持仓并处理真实/虚拟止损 /获利 /跟踪止损 交易

自动设置止损、获利、跟踪止损、保本水平,启用虚拟止损。 Exp Assistant 将帮助您组织持仓的维护。 此专家顾问将为您的持仓设置所有必要的止损和获利水平。 所有专家顾问操作均通过图表上的控制面板管理。…

MQL 开源模板. 创建智能交易系统的模板

MQL 开源模板. 创建智能交易系统的模板

简介 使用任何指标创建专家顾问(Expert Advisors, EAs)来测试您的策略,确实可以通过使用模板和开源资源来简化。开源的优势之一是可以使用现有的代码来节省时间和精力。 以下是使用来自Expforex.com的MQL 开源模板在仅5分钟内创建EA的分步指南。 使用开源模板创建EA的分步指南 下载开源模板: 访问Expforex.com,导航到开源部分,您可以在那里找到适用于MetaTrader 4 (MT4)和MetaTrader 5 (MT5)的MQL模板。 下载适合您平台(MT4或MT5)并基于您希望使用的指标的EA模板。 理解模板结构: 模板将包括预先编写的代码,处理EA的基本功能,如初始化、开仓和平仓,基于指标的信号。 模板的主要元素包括: …

This post is also available in: English Українська Portuguese Español Deutsch Chinese Русский Français Italiano Türkçe 日本語 한국어


     

    风险警告:


    过去的交易业绩并不保证未来的结果。

    保证金外汇交易具有高风险,可能不适合所有投资者。

    请注意,使用交易机器人涉及巨大风险,您的损失可能超过初始投资。

    请谨慎行事,仔细评估自己的财务状况,并考虑向合格的专业人士寻求建议。

    免责声明

    本网站使用Cookie以提升您的体验。通过使用本网站,您同意我们的 数据保护政策免责声明
    阅读更多