The Pendulum or Swing strategy involves the sequential opening of pending orders with an increased lot size. The core principle…
现成专家与编程/自由职业者的优势。
基于报价速度的剥头皮系统!Ping 和数据中心。
Table of Contents (click to show)
List
- Description
- Open Source
- The Real Value of Our Advisor
- Programming Your Forex Trading Strategy
- Programming THE X for MetaTrader 5
- MetaTrader 5 Step 0: Loading Indicators into Resources!
- MetaTrader 5 Step 1: Specify the Signal Name!
- MetaTrader 5 Step 2: Specify the Signal Display Name!
- MetaTrader 5 Step 3: Specify the Filter Name!
- MetaTrader 5 Step 4: Specify the Parameters of the Indicator or Strategy in External Variables!
- MetaTrader 5 Step 5: Create Indicator Handles to Load into the Expert Advisor!
- MetaTrader 5 Step 6: Declare Variables to Load the Indicator(s) of the Strategy!
- MetaTrader 5 Step 7: Declare Variables for Storing Indicator Data!
- MetaTrader 5 Step 8: Create Strategies and Signals for Opening Positions!
- Error Codes
- MetaTrader 5 Step 9: Specify Filters from Your Indicators or Use Your Indicator as a Filter for the Strategy!
- MetaTrader 5 Step 10: This is the final step!
- MetaTrader 5 Conclusions and Verification of the Strategy
- Programming THE X for MetaTrader 4
- MetaTrader 4 Step 0: Loading Indicators into Resources
- MetaTrader 4 Step 1: Specify the Signal Name
- MetaTrader 4 Step 2: Specify the Signal Name for Display on Screen
- MetaTrader 4 Step 3: Specify the Filter Name
- MetaTrader 4 Step 4: Specify Indicator or Strategy Parameters in External Variables
- MetaTrader 4 Steps 5, 6, 7: Relax!
- MetaTrader 4 Step 8: Creating Strategies and Signals for Opening Positions
- MetaTrader 4 Step 9: Specify Filters from Your Indicators or Use Your Indicator as a Filter for the Strategy
- MetaTrader 4 Step 10: This is the Final Step!
- MetaTrader 4 Conclusions and Strategy Check
- What Else Can Be Changed in the Expert Advisor?
- Debugging a Strategy
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:
- Can I integrate my indicators into an advisor?
- 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.
- The open-source code of the advisor The X can be purchased in our Market of Trade Advisors.
- Open Source The X for MetaTrader 5 (Not available)
- Open Source The X for MetaTrader 4 (Not available)
- By the way, we have many open-source codes for our advisors. Section: Strategy Advisors (Open Source)
- 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:
- The cost of 1 hour of a programmer’s work = $20 when programming functions and algorithms.
- The cost of 1 hour of error correction = $5.
- The cost of writing texts and videos = $10 (This price is based on internet rates; I create all instructions and videos myself).
- Assume that writing functions and blocks for The X took over 1,000 hours!
- Programming signals using indicators is straightforward. Therefore, we assume it took us 10 hours!
However, some aspects cannot be completed immediately:
- Debugging functions can take an additional 1,000 hours!
- 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:
- Firstly, because customers are unwilling to invest such a significant amount of money.
- 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:
- Open the open-source code of the advisor that you purchased from our Market of Advisors;
- Press Ctrl + F to activate the search bar;
- Enter the term Step – This keyword will help you navigate our source code and quickly write your strategy.
- Each step is well-commented and provides an example.
- 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.
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.
For example:
- You want to name your strategy MY STRATEGY
- 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.
- 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:
- MYSTRATEGY1 = 77, // MY STRATEGY a
- MYSTRATEGY2 = 78, // MY STRATEGY b
- 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.
For example:
- if (i == 77) s1 = “My1”;
- if (i == 78) s1 = “My2”;
- 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:
- Do you want to name your Filter MY FILTER?
- 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.
- 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:
- MYFILTER1 = 77, // MY FILTER a
- MYFILTER2 = 78, // MY FILTER b
- 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.
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.
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!
- Program the code for each strategy and signal individually. It depends on the chosen strategy and indicators. Handling buffers for strategies involves…
- Note that in this block, you can specify any strategy.
- All the indicators declared in the handles will be loaded into memory and used to build the strategy.
This step can be divided into three substeps:
- 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).
- We use two lines: MAIN and SIGNAL.
- You can read the documentation on the CopyBuffer function.
- 2. Programming the strategy. In this case, it’s the intersection of two lines.
- Important: The signal for BUY is 1, and for SELL, it is -1.
- 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_SYMBOL | 4801 | Unknown symbol |
ERR_INDICATOR_CANNOT_CREATE | 4802 | The indicator cannot be created |
ERR_INDICATOR_NO_MEMORY | 4803 | Insufficient memory to add an indicator |
ERR_INDICATOR_CANNOT_APPLY | 4804 | The indicator cannot be applied to another indicator |
ERR_INDICATOR_CANNOT_ADD | 4805 | Error while adding the indicator |
ERR_INDICATOR_DATA_NOT_FOUND | 4806 | The requested data was not found |
ERR_INDICATOR_WRONG_HANDLE | 4807 | Incorrect indicator handle |
ERR_INDICATOR_WRONG_PARAMETERS | 4808 | Incorrect number of parameters when creating an indicator |
ERR_INDICATOR_PARAMETERS_MISSING | 4809 | Missing parameters when creating the indicator |
ERR_INDICATOR_CUSTOM_NAME | 4810 | The first parameter in the array must be the name of the custom indicator |
ERR_INDICATOR_PARAMETER_TYPE | 4811 | Incorrect parameter type in the array when creating the indicator |
ERR_INDICATOR_WRONG_INDEX | 4812 | Invalid 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.
- Load the terminal;
- Open a demo account;
- Attach the Expert Advisor to the chart;
- If all is OK, you will receive a message about the successful addition of the strategy:
- 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:
- Open the terminal;
- Open the Strategy Tester;
- Choose your Expert Advisor, currency pair, time frame, and date range. Enable Every Tick testing based on real ticks;
- Open the Settings tab;
- Select your strategy;
- Enable Visualization;
- Press START;
- A graph should open;
- If the Expert Advisor opens positions, you did everything correctly!
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.
For example:
- You want to name your strategy MY STRATEGY
- The strategy number must also be unique. Signals from standard indicators occupy the first 22 numbers! Remember this number for future reference.
- 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:
- MYSTRATEGY1 = 77, // MY STRATEGY a
- MYSTRATEGY2 = 78, // MY STRATEGY b
- 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.
For example:
- if (i == 77) s1 = “My1”;
- if (i == 78) s1 = “My2”;
- 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:
- Do you want to name your Filter MYFILTER?
- 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.
- 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:
- MYFILTER1 = 77, // MY FILTER a
- MYFILTER2 = 78, // MY FILTER b
- 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.
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!
- Programming code for strategy and signal individually. It depends on the chosen strategy and indicators. Setting up strategy buffers…
- I want to note that in this block, you can specify any strategy.
- All the indicators that we declared in the handles will be loaded into memory and used to build the strategy.
This step can be divided into 2 substeps:
- 1. Programming the strategy. In this case, it is the intersection of two lines.
- Important: The Signal for BUY is 1, and for SELL, it is -1.
- 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.
Most common errors:
ERR_INDICATOR_UNKNOWN_SYMBOL | 4801 | Unknown symbol |
ERR_INDICATOR_CANNOT_CREATE | 4802 | The indicator cannot be created |
ERR_INDICATOR_NO_MEMORY | 4803 | Not enough memory to add an indicator |
ERR_INDICATOR_CANNOT_APPLY | 4804 | The indicator cannot be applied to another indicator |
ERR_INDICATOR_CANNOT_ADD | 4805 | Error while adding the indicator |
ERR_INDICATOR_DATA_NOT_FOUND | 4806 | The requested data was not found |
ERR_INDICATOR_WRONG_HANDLE | 4807 | Wrong indicator handle |
ERR_INDICATOR_WRONG_PARAMETERS | 4808 | Incorrect number of parameters when creating an indicator |
ERR_INDICATOR_PARAMETERS_MISSING | 4809 | Missing parameters when creating the indicator |
ERR_INDICATOR_CUSTOM_NAME | 4810 | The first parameter in the array must be the name of the custom indicator |
ERR_INDICATOR_PARAMETER_TYPE | 4811 | Incorrect parameter type in the array when creating the indicator |
ERR_INDICATOR_WRONG_INDEX | 4812 | Invalid 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.
- Load the terminal;
- Open a demo account;
- Attach the Expert Advisor to the chart;
Checking the Expert Advisor in the Strategy Tester:
- Open the terminal;
- Open the Strategy Tester;
- Choose your Expert Advisor, currency pair, time frame, and date range. Enable Every Tick testing based on real ticks;
- Open the Settings tab;
- Select your strategy;
- Enable Visualization;
- Press START;
- A graph should open;
- If the Expert Advisor opens positions, then you did everything correctly!
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!
相关帖子
Duplicator – 在 MetaTrader 终端上复制交易/持仓
Exp-Duplicator 是一个自动化的专家顾问,旨在在您的 MetaTrader 账户上预设次数复制交易和持仓。 它无缝复制所有持仓——无论是手动开启还是由其他 EA 开启的,并允许您增加这些持仓的手数(量)。…
Partial Close and Trailing. Partial closing of positions on rollbacks
Partial Close and Trailing is an EA assistant that closes a portion of a position (i.e., part of the lot)…
Extra Report Pad – 交易者日记。专业分析您的交易账户。实时图表中的 MyFxBook。ExtraReportPad
Extra Report Pad – 专业的交易账户分析解决方案 今天,必须同时交易多个货币对。但是交易越多,分析账户盈利能力就越困难。按月分析交易更加困难。更不用说单独计算每笔交易的统计数据了。 我们找到了一个解决方案:我们的面板可以实时分析您的账户,并尽可能详细地编制统计数据。…
TickSniper 自动化专家顾问用于 MetaTrader。Tick 剥头皮交易者
Exp-TickSniper 是一个快速的 Tick 剥头皮交易者,能够自动为每个货币对单独选择参数。 该 EA 基于近10年的 EA 编程经验开发而成。 该 EA 使用智能跟踪止损进行短期交易,并基于当前货币对数据、报价、规格和点差。…
EAPADPRO LIBRARY – Adding our panel to your EA
EAPADPRO LIBRARY – Enhancing Your Expert Advisor (EA) with Our Information Panel EAPADPRO LIBRARY offers a robust solution for traders looking…
Market Time Pad. Indicator for MetaTrader with trading sessions
The Time Indicator displays the current time across the major world markets and highlights the active trading session. It is easy…
Assistant – 最佳免费交易面板,支持持仓并处理真实/虚拟止损 /获利 /跟踪止损 交易
自动设置止损、获利、跟踪止损、保本水平,启用虚拟止损。 Exp Assistant 将帮助您组织持仓的维护。 此专家顾问将为您的持仓设置所有必要的止损和获利水平。 所有专家顾问操作均通过图表上的控制面板管理。…
The X – 通用外汇专家顾问 (EA) 使用标准指标
通用专家顾问 (EA) 适用于 MetaTrader,功能强大 专家顾问 The X 是 MetaTrader 的多功能交易工具,提供广泛的功能和可定制的设置。 它使用标准指标,并包含内置的策略构建器,允许交易者创建和调整策略以满足他们的需求。…
The xCustomEA Advisor on the PipFinite Trend PRO. Automatic EA
Description An example of programming a strategy for the PipFinite Trend PRO indicator and trading using our universal trading system Exp…
Close Minus by Plus, Closing unprofitable positions by searching and
Closing unprofitable positions by identifying and closing profitable ones. The Expert Advisor (EA) is designed to close unprofitable positions by identifying…
Averager。平均交易头寸。在趋势中和逆趋势中开仓!
平均头寸。利用总利润的通用移动止损功能,在趋势中和逆趋势中开设额外头寸! 该顾问可以在趋势中和逆趋势中开设额外头寸! 包含一系列头寸的平均移动止损! 增加和减少手数。…
MQL 开源模板. 创建智能交易系统的模板
简介 使用任何指标创建专家顾问(Expert Advisors, EAs)来测试您的策略,确实可以通过使用模板和开源资源来简化。开源的优势之一是可以使用现有的代码来节省时间和精力。 以下是使用来自Expforex.com的MQL 开源模板在仅5分钟内创建EA的分步指南。 使用开源模板创建EA的分步指南 下载开源模板: 访问Expforex.com,导航到开源部分,您可以在那里找到适用于MetaTrader 4 (MT4)和MetaTrader 5 (MT5)的MQL模板。 下载适合您平台(MT4或MT5)并基于您希望使用的指标的EA模板。 理解模板结构: 模板将包括预先编写的代码,处理EA的基本功能,如初始化、开仓和平仓,基于指标的信号。 模板的主要元素包括: …
VirtualTradePad (VTP) 交易面板。Trade Pad 可通过图表和键盘一键进行交易
VirtualTradePad 或 VTP – 在 MetaTrader 终端中一键交易的控制面板。用于外汇剥头皮交易和手动交易的程序。…
Tick Hamster 自动交易机器人。无任何额外功能!
Tick Hamster – 具有自动优化功能的专家顾问,适用于 MetaTrader 中的任何交易品种 Tick Hamster 是一款全自动专家顾问(Expert Advisor),专为新手交易员和那些偏好无需设置的用户设计。该交易EA无需手动配置,能够自动优化任何交易品种的所有参数。…
This post is also available in: English Українська Portuguese Español Deutsch Chinese Русский Français Italiano Türkçe 日本語 한국어