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

EA SUPER TESTER Expert Advisor 用のマルチスレッド テスト プログラム。
EA SUPER TESTER Expert Advisor 用のマルチスレッド テスト プログラム。

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!

AI Sniper。MetaTrader の自動スマートエキスパートアドバイザー。

AI Sniper。MetaTrader の自動スマートエキスパートアドバイザー。

AI Sniper は、MT4 および MT5 ターミナル用に設計されたインテリジェントで自己最適化可能な取引ロボットです。スマートなアルゴリズムと高度な取引戦略を活用して、取引の可能性を最大化します。 取引所および株式市場で15年の経験を持ち、革新的な戦略管理機能、追加のインテリジェント機能、ユーザーフレンドリーなグラフィカルインターフェースを開発しました。…

SafetyLOCK PRO 反対の保留注文を開くことでポジションをロックして保護します。ヘッジをロック

SafetyLOCK PRO 反対の保留注文を開くことでポジションをロックして保護します。ヘッジをロック

SAFETYLOCK:急激な市場反転から取引を保護 金融市場での取引は高リスクを伴い、特に急激な市場反転時にはリスクが高まります。SAFETYLOCKは、既存のポジションに対して自動的に反対の注文を出すことでトレーダーが損失を最小限に抑えるのを助けるユニークなツールです。予期しない市場の動きが取引に影響を与えないことを知り、自信を持って取引を行うことができます。…

TickSniper MetaTrader用自動エキスパートアドバイザー。Tick scalper

TickSniper MetaTrader用自動エキスパートアドバイザー。Tick scalper

Exp-TickSniperは、高速なTickスキャルパーで、各通貨ペアのパラメーターを自動的に選択します。 このEAは、ほぼ10年のEAプログラミング経験に基づいて開発されました。 このEAは、スマートトレーリングストップを使用して短期取引を行い、現在の通貨ペアデータ、その見積もり、仕様、およびスプレッドに基づいています。…

MQLオープンソーステンプレート. エキスパートアドバイザー作成用テンプレート

MQLオープンソーステンプレート. エキスパートアドバイザー作成用テンプレート

概要 エキスパートアドバイザー(EA)を作成し、任意のインジケーターを使用して戦略をテストすることは、テンプレートやオープンソースリソースを利用することで簡素化できます。オープンソースの利点を活用して、効果的な戦略を構築しましょう。 以下は、Expforex.comのMQLオープンソーステンプレートを使用して、わずか5分でEAを作成するためのステップバイステップガイドです。 オープンソーステンプレートを使用したEA作成のステップバイステップガイド オープンソーステンプレートのダウンロード: Expforex.comにアクセスし、オープンソースセクションに移動します。ここでMetaTrader 4 (MT4)およびMetaTrader 5 (MT5)用のMQLテンプレートを見つけることができます。 プラットフォーム(MT4またはMT5)に適したEAテンプレートを、使用したいインジケーターに基づいてダウンロードします。 テンプレート構造の理解: テンプレートには、インジケーターからのシグナルに基づいてポジションの初期化、オープン、クローズなどの基本的なEA機能を処理する事前に記述されたコードが含まれています。 テンプレートの主な要素には以下が含まれます: …

EAPadPRO – 私たちのエキスパート向け情報パネル。エキスパートアドバイザーのダッシュボード

EAPadPRO – 私たちのエキスパート向け情報パネル。エキスパートアドバイザーのダッシュボード

MetaTraderターミナル用のすべてのアドバイザーおよびユーティリティの情報パネル。 当社の取引エキスパートアドバイザーでEAPADPROパネルを管理および使用する基本についての詳細な指示。 当社のユーティリティを便利かつ成功裏に使用するための親しみやすく直感的なユーザーインターフェース。 戦略テスターでも!…

The xCustomEA Advisor on the PipFinite Trend PRO. 自動EA

The xCustomEA Advisor on the PipFinite Trend PRO. 自動EA

明 PipFinite Trend PROインジケーターのストラテジーをプログラムし、当社のユニバーサルトレーディングシステムExp – The xCustomEAを使用して取引する例。 この記事では、PipFinite Trend PROカスタムインジケーターを詳細に分析します。これは、MQL5マーケットからダウンロードされたものです。 インジケーターの操作方法と、当社のエキスパートアドバイザー Exp – The xCustomEAでの呼び出しオプションを分析しましょう。 開始 Exp – The xCustomEA エキスパートアドバイザーを開発する際、ほとんどのユーザーがプログラミングを学ばないことを知っていました! しかし、インジケーターで取引するためにプログラミング知識が必要ですか? 当社のエキスパートアドバイザーの使用を簡単かつ手頃な価格にするために、あらゆる手段を講じました。 インジケーター上でエキスパートアドバイザーをプログラムするのに20分?簡単です! 特に、全体のプログラムコードが長い間問題なく実行されてきた場合はなおさらです。 当社のExp – The xCustomEAの説明書では、ストラテジーのプログラミングの手順を最も明確に記述しています! 最初に使用するインジケーターは偶然ではありません。 実際、MQL5マーケットには多くのMT5およびMT4用インジケーターがあります。 しかし、当社は市場で最も人気のあるインジケーターの一つを選びました。これは1000件のレビューがあり、MT4およびMT5ターミナル向けに配布されています。 インジケーターの作者はシグナルバッファを隠し、これらのバッファ番号も記述しました!インジケーター上でエキスパートアドバイザーを開発する際に非常に重要なことは何でしょうか? PipFinite Trend…

Copylot – MetaTrader用の外為取引のコピーソフト。ターミナル間のコピア

Copylot – MetaTrader用の外為取引のコピーソフト。ターミナル間のコピア

MetaTrader用トレードコピア。 あらゆるアカウントから外為の取引、ポジション、オーダーをコピーします。 COPYLOT MT4バージョンの中でMT4-MT4, MT5-MT4の最高のトレードコピアの1つです(またはCOPYLOT MT5バージョンのMT4-MT5, MT5-MT5に対応しています)。 独自のコピーアルゴリズムは、すべての取引をマスターアカウントからクライアントアカウントに正確にコピーします。…

Averager。取引ポジションの平均化。トレンドに逆らっておよびトレンドに沿って取引を開始!

Averager。取引ポジションの平均化。トレンドに逆らっておよびトレンドに沿って取引を開始!

ポジションの平均化。利益の総トレーリングストップ機能を使用して、トレンドに沿っておよびトレンドに逆らって追加ポジションを開設! アドバイザーはトレンドに沿っておよびトレンドに逆らって追加ポジションを開設できます! 一連のポジションに対する平均トレーリングストップを含む! ロットの増減。…

Market Time Pad. MetaTrader用の取引セッション付きインジケーター

Market Time Pad. MetaTrader用の取引セッション付きインジケーター

タイムインジケーターは、主要な世界市場の現在時刻を表示し、アクティブな取引セッションをハイライトします。 使いやすく、チャート上のスペースを最小限に抑えるため、エキスパートアドバイザーやVirtualTradePadなどの他のツールとのシームレスな統合に最適です。…

Close Minus by Plus、利益のあるポジションを検索してクローズすることで損失ポジションをクローズ

Close Minus by Plus、利益のあるポジションを検索してクローズすることで損失ポジションをクローズ

利益のあるポジションを特定してクローズすることで損失ポジションをクローズします。 エキスパートアドバイザー(EA)は、利益のあるポジションを特定してクローズすることで損失ポジションをクローズするように設計されています。…

CLP CloseIfProfitorLoss。トレイリングプロフィットによる総利益または損失の管理。

CLP CloseIfProfitorLoss。トレイリングプロフィットによる総利益または損失の管理。

エキスパートアドバイザー(EA)は、MetaTraderでのポジション管理およびクローズに関する高度な機能を提供し、特に事前に設定された総利益または損失のレベルに達した際に機能します。 利益トレイリング機能が有効になっている場合、EAは利益が増加するにつれて動的にストップレベルを調整して利益を確保します。…

Assistant – 実際の/仮想のストップロス /テイクプロフィット /トレーリングストップ をサポートする最高の無料トレーディングパネル

Assistant – 実際の/仮想のストップロス /テイクプロフィット /トレーリングストップ をサポートする最高の無料トレーディングパネル

ストップロス、テイクプロフィット、トレーリングストップ、ブレイクイーブンレベルの自動設定、仮想ストップの有効化。 Exp Assistant はあなたのポジションのメンテナンスを整理するのに役立ちます。 このエキスパートアドバイザーは、あなたのポジションに必要なすべてのストップロスとテイクプロフィットレベルを設定します。 すべてのエキスパートアドバイザーの操作はチャート上のコントロールパネルから管理されます。…

この記事は次の言語でもご覧いただけます: English Українська Portuguese Español Deutsch Chinese Русский Français Italiano Türkçe 日本語 한국어


     

    リスクの警告


    過去の取引実績は将来の結果を保証するものではない。

    外国為替証拠金取引には高いリスクが伴うため、すべての投資家に適しているとは限りません。

    取引ロボットを使用することはかなりのリスクを伴い、初期投資額以上の損失を被る可能性があることに注意してください。

    慎重に行動し、ご自身の財務状況を慎重に判断し、資格を有する専門家の助言を求めることをご検討ください。

    免責事項

    このウェブサイトは、あなたの体験を向上させるためにクッキーを使用しています。このウェブサイトを利用することで、当社のデータ保護方針および免責事項に同意したことになります。
    続きを読む