Главная
Каталог статей форекс
English instructions and articles

Для того, чтобы использовать все возможности сайта, мы рекомендуем Вам person_add Зарегистрироваться или person Войти

starРейтинг: 5.0/3

date_range Posted: 01.08.2017

date_range Updated: 01.08.2018

remove_red_eyeReviews: 334

dashboardCategory: English instructions and articles

historyHistory versions

computerTerminal: МТ4 и МТ5

cloudYour, program, X:, To, Steps, The, strategy!, 10


Read about The X: 10 steps to program your strategy!

Description

The X: 10 steps to program your strategy!

This is the most common phrase in search queries.

The X is a designer of trading strategies .

We created an advisor that has all the most interesting and necessary functions. And added a block of signals in the form of standard indicators.

It was a project that became very popular. For 5 years we have been working on the algorithm, adding new functions, new indicators. Corrected errors in functions.

This article will help you in programming your strategy. Programming the advisor on indicators. Adding new signals and filters.

Open source

A very frequent question to us was the question:

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

It's no secret that we have an open (source) code of our adviser on sale. This is done for those traders who wish to write their own advisor or to build their signals.

Also often traders buy open source code in order to implement their secret strategy and resell the adviser.

  1. The open code of the adviser The X can be bought in our market of trade advisers .
  2. Open source The X for MetaTrader5
  3. Open source The X for MetaTrader4
  4. By the way, we have many open codes of our advisers. Section: Strategy Advisers (Open source)

Programming advisers on indicators is a laborious process.

We provide programming services for trade advisers . But the process of writing a sales advisor is each time delayed because the customer (the client) has no idea what functions he needs.

The X is a set of blocks and functions for trading on FOREX , which are used all over the world. We have created the functions that are used most often. Thus, the adviser can realize 90% of the needs of each trader.

Naturally, there are unique strategies that should be programmed by experienced programmers.

Such strategies are very rare and require careful preparation. The cost of this work depends on the complexity.

The real value of our advisor

If we start from our article about how much the programmer's work costs , then we can calculate the approximate cost of our trading robot The X:

In our EA, more than 10,000 lines of code. That's not a lot. But due to the fact that we do not write advisers on the PLO. Why ? with the OOP you are not familiar! and you will find it very difficult to deal with the PLO!

So, we will calculate:

  1. Cost of 1 hour of 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 video = $ 10 (The price is taken from the Internet, all the instructions and video I do myself).
  4. Suppose that writing functions and blocks on The X we took more than 1000 hours!
  5. Programming signals by indicators is very easy. Therefore, we assume that it took us 10 hours!

But there are points that can not be fulfilled at once:

  1. Debugging functions, this can take another 1000 hours!
  2. Drawing up instructions, video, promotion, it also takes 1000 hours of time!

Total we have more than 3000 hours of time spent!

If we ordered such an algorithm, we would refuse. This is not reasonable and not profitable.

The total cost of such an adviser (on order) is more than $ 35,000! But our adviser is sold 10 times cheaper !!!!

The cost of our open source is TEN times less!

Such orders are never fulfilled:

  1. Firstly, because the customer will not spend such money.
  2. Secondly, the programmer will not spend so much time programming.

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

Debugging all the blocks and functions requires an extended time.

We are very grateful to our customers who have found mistakes and corrections for 5 years, offered their functions and indicators for the work of the advisor THE X

 

Programming your Forex trading strategy

First of all I want to say that we have updated the code of our adviser. Now it is very easy and commented.

You do not need to delve into the work of all the functions. You do not need it. You can program your strategy in just 10 steps.

We have prepared for you a very convenient way of working with our open source.

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

 

First steps:

  1. Open our source code of the adviser that you bought in our market of advisers;
  2. Press Ctrl + F and you will see the search string;
  3. Enter the name Step - By this word, in our source code, you can navigate and quickly write your strategy.
  4. Each step is commented and provides an example
  5. In order to learn how to program your strategy, you can step-by-step uncomment lines with an asterisk // *

In total, there are 10 steps in the open code for the adviser to work on your indicators.

We will analyze each step in detail!

Due to the fact that the programming differs in the two versions of the MT4 and MT5 terminals, we will also divide our article into two parts:

 

 

If your version of the advisor THE X for the MT4 terminal, you can immediately go to the programming section of The X for the Metatrader 4 terminal

Programming THE X for MetaTrader 5

You must know the minimum programming rules in order to write your strategy Or ​​add a ready strategy for indicators from the finished file (Expert Advisors from the Internet, for example)

Programming advisors for MetaTrader 5 is more difficult than programming for MetaTrader 4. But the MT5 terminal allows you to create more powerful strategies, and also has a more advanced strategy tester.

In any case, you should buy that open code on which the terminal will work.

MetaTrader 5 Step 0: Step 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
// 
// In order for the indicator to be built into the Expert Advisor during compilation, you need to load it into the resources of the Expert Advisor
// In order for the indicator to be built in 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 are obliged to add the indicators needed by Us to the resources.

This will allow us to compile an advisor for the market, and also save us from unnecessary problems when the compiled adviser suddenly does not find the desired indicator on another computer!

Rules for writing the name of the market: The full name of the folders, starting with Indicators !

The folder is indicated by \\

For example :

If the path to your indicator looks like this:

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

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

"\\ Indicators \\ Examples \\ MACD.ex5"

 

MetaTrader 5 Step 1: Step of specifying 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 of the adviser.

This is done in order to conveniently manage the signals during the expert setup phase.

For example:

  1. You want to name your strategy MY STRATEGY
  2. The strategy number must also be unique. The first 22 numbers are occupied by signals from standard indicators! Remember this figure, we will need it in the future.
  3. The name must also be unique. For example: MYSTRATEGY1

In the end, we 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 with

MetaTrader 5 Step 2: Step to specify the name of the signal to display the name on the 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 for the name of your strategy to be displayed in our panel for the EApadpro EA

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

For example:

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

 

MetaTrader 5 Step 3: Step of specifying 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 of the Expert Advisor.

This is done to make it convenient to manage the filters during the expert setup phase.

Usually: 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 is a fact of the signal. Examples of differences between filters and signals

For example:

  1. You want to name your filter MY FILTER
  2. The number of the filter should also be the same as the number of the strategy (This is done in order not to be confused in the future with figures). The first 22 numbers are occupied by filters from standard indicators! Remember this figure, we will need it in the future.
  3. The name must also be unique. For example: MYFILTER1

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

MYFILTER1 = 77, // MY FILTER

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

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

MetaTrader 5 Step 4: Step to specify the parameters of the indicator or strategy 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 the external variables of your indicator or indicators that will be used in your strategy 
// Write 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 of your strategy, which can be changed from the Expert Advisor. For example, for optimization.

Also here you can take out specific parameters of the strategy. For example, the levels of intersection of lines, the limitation of the indicator's operation on MAX and MIN price on the chart and so on ...

You do not have to enter all the parameters for the indicators. It is enough to make those that you can change in the future from the settings of the Expert Advisor. All other parameters you can leave the indicator by default.

MetaTrader 5 Step 5: The step of creating indicator handles, to load into the Expert Advisor!

// 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 
// 
// You need to create an entry in the array in order for the Expert Advisor to assign the indicator handle when initializing 
// You need to create an entry in the array in order for the Expert Advisor to assign an indicator handle when initializing 
// ################################################ #################### 
// 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 is necessary to ensure that our indicators are loaded 1 time 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 remember the handle of an already open indicator and use it for further work.

Here you need to be very careful. When creating a handle, we must specify all external variables of the indicator and specify 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 read the help on calling indicators through iCustom

Strategy number is also needed for us to write this code. If you have several indicators in one strategy, then you need to specify several indicators but with the same number. That the adviser correctly loaded your strategy.

According to our examples above, we need to do this:

 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 specifically specified only two external parameters, I replaced the parameter of this Indicator InpSignalSMA with a default number so that you understand the essence of programming!

By analogy above, you can add several indicators and handles.

If the strategy uses several indicators, then you need to write several indicators.

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; 

 

Also with other strategies that you want to insert into the advisor!

 

MetaTrader 5 Step 6: The step of declaring variables to store the indicator indicators of the strategy!

// 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 
// 
// Declare the variable of the handle array 
// Declare the variable of the handle array 
// ################################################ #################### 
// for example: 
// * int h_custom [6] [12]; 
// * int h_custom2 [6] [12]; 
// ################################################ ###########################

Here we simply indicate the names of our handles that created above!

There is nothing complicated here.

Handles are created in the form of arrays in order to use multicurrency in the EA and use the ability to specify 6 signals or filters at once!

 

MetaTrader 5 Step 7: The step of declaring variables for storing indicator data!

// 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 
// 
// Declare the variable of the array of indicator values 
// Declare the variable of the handle array 
// ################################################ #################### 
// for example: 
// * double custom1_buffer []; 
// * double custom2_buffer []; 
// ################################################ ###########################

Here we simply indicate the names of our data for buffers!

There is nothing complicated here.

In these arrays, data will be stored about the values ​​of the indicator on each bar. If you need to use multiple buffers, you can use several variables.

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

MetaTrader 5 Step 8: The main step in creating strategies and signals for opening positions!

// Step 8 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Here we create our signal to open positions. Fill in the data buffers 
// Here we create our signal for opening positions. Fill in the data buffer 
// ################################################ #################### 
// for example: 
// * if (sigInd == 77) 
// * { 
// 
// Fill the data, 
// We fill in the data 
// 1. 
// * if (CopyBuffer (h_custom [array_tf] [array_symbol], 0,0,3 + OWNSIGNAL_shift, custom1_buffer) <3 + OWNSIGNAL_shift) 
// * {Alert ("CopyBuffer1 ERROR" + custom1_buffer [0] + "NameError =" + GetLastError ()); return (0);} 
// * if (! ArraySetAsSeries (custom1_buffer, true)) 
// * {Alert ("ArraySetAsSeries ERROR"); return (0);} 
// * if (CopyBuffer (h_custom [array_tf] [array_symbol], 1,0,3 + OWNSIGNAL_shift, custom2_buffer) <3 + OWNSIGNAL_shift) 
// * {Alert ("CopyBuffer2 ERROR" + custom2_buffer [0] + "NameError =" + GetLastError ()); return (0);} 
// * if (! ArraySetAsSeries (custom2_buffer, true)) 
// * {Alert ("ArraySetAsSeries ERROR"); return (0);} 
// 
// Here we write our strategy, in this example it's the intersection of two lines, 
// Here we write our strategy, in this example it is the intersection of two lines 
// 2. 
// * if (custom1_buffer [OWNSIGNAL_shift + 1] <custom2_buffer [OWNSIGNAL_shift + 1] && custom1_buffer [OWNSIGNAL_shift]> custom2_buffer [OWNSIGNAL_shift]) 
// * sig = 1; 
// * else if (custom1_buffer [OWNSIGNAL_shift + 1]> custom2_buffer [OWNSIGNAL_shift + 1] && custom1_buffer [OWNSIGNAL_shift] <custom2_buffer [OWNSIGNAL_shift]) 
// * sig = -1; 
// * else sig = 0; 
// 
// We write down the data that will be displayed in the log, when the positions are opened at the signal 
// We write down the data that will be displayed in the log, when you open positions on a signal 
// 3. 
// * InfoAboutSignal = InfoAboutSignal + "" + "sigInd =" + sigInd + "array_tf =" + array_tf + "array_symbol =" + array_symbol + "sig =" + sig + "" + __ FUNCTION __ + "" 
// * + "custom1_buffer [OWNSIGNAL_shift + 1] =" + custom1_buffer [OWNSIGNAL_shift + 1] 
// * + "custom2_buffer [OWNSIGNAL_shift + 1] =" + custom2_buffer [OWNSIGNAL_shift + 1] 
// * + "custom1_buffer [OWNSIGNAL_shift] =" + custom1_buffer [OWNSIGNAL_shift] 
// * + "custom2_buffer [OWNSIGNAL_shift] =" + custom2_buffer [OWNSIGNAL_shift]; 
// // --- return the trading signal 
// * return (sig); 
// *} 
// ################################################ ###########################

This step is very important for the adviser. Although all other steps are mandatory, otherwise the adviser will not work.

I indicated my comments in the code!

Strategy number is the same as in the first steps!

  1. Programming code for strategy and signal individually. Depends on the chosen strategy and indicators. Getting buffers, strategies ........
  2. I want to note only 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.

This step can be divided into 3 substeps:

  1. 1. We are obliged to copy data buffers to our data sets. In the copying 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 help about the function CopyBuffer
  4. 2. Programming the strategy. In this case it is the intersection of two lines.
  5. Important: The signal for BUY is 1, and for SELL this is -1
  6. 3. Here we record the information that will be displayed in the log when the position is opened. Strategy Information

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

Alert ("Congratulations, you've made a lesson that shows the programming of your strategy!"); 
Alert ("Congratulations! You have done a lesson that shows the programming of your strategy!"); 
If you received an error message, then you need to find out the cause of this error.

 

Error Codes

most common errors:

ERR_INDICATOR_UNKNOWN_SYMBOL

4801

Unknown character

ERR_INDICATOR_CANNOT_CREATE

4802

The indicator can not be created

ERR_INDICATOR_NO_MEMORY

4803

There is not enough memory to add an indicator

ERR_INDICATOR_CANNOT_APPLY

4804

The indicator can not 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

Wrong 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

Wrong type of parameter in the array when creating the indicator

ERR_INDICATOR_WRONG_INDEX

4812

Invalid index of the requested indicator buffer

MetaTrader 5 Step 9: Step to specify the filters from your indicators, or use your indicator as a filter for the strategy!

// Step 9 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Here we create our filter for signal filtering. Fill in the data buffers 
// Here we create our filter for signal filtering. Fill in the data buffers 
// ################################################ #################### 
// for example: 
// * if (sigInd == 77) 
// * { 
// 
// Fill the data, 
// We fill in the data 
// 
// * if (CopyBuffer (h_custom [array_tf] [array_symbol], 0,0,3 + shift, custom1_buffer) <3 + shift) 
// * {Alert ("CopyBuffer1 ERROR" + custom1_buffer [0] + "NameError =" + GetLastError ()); return (0);} 
// * if (! ArraySetAsSeries (custom1_buffer, true)) 
// * {Alert ("ArraySetAsSeries ERROR" + "NameError =" + GetLastError ()); return (0);} 
// * if (CopyBuffer (h_custom [array_tf] [array_symbol], 1,0,3 + shift, custom2_buffer) <3 + shift) 
// * {Alert ("CopyBuffer2 ERROR" + custom2_buffer [0] + "NameError =" + GetLastError ()); return (0);} 
// * if (! ArraySetAsSeries (custom2_buffer, true)) 
// * {Alert ("ArraySetAsSeries ERROR" + "NameError =" + GetLastError ()); return (0);} 
// 
// Here we write our strategy, in this example it's the intersection of two lines, 
// Here we write our strategy, in this example it is the intersection of two lines 
// 
// * if (custom1_buffer [shift]> custom2_buffer [shift]) 
// * sig = 1; 
// * else if (custom1_buffer [shift] <custom2_buffer [shift]) 
// * sig = -1; 
// * else sig = 0; 
// 
// We write down the data that will be displayed in the log, when the positions are opened at the signal 
// We write down the data that will be displayed in the log, when you open positions on a signal 
// 
// * InfoAboutSignal = InfoAboutSignal + "" + "sigInd =" + sigInd + "array_tf =" + array_tf + "array_symbol =" + array_symbol + "sig =" + sig + "" + __ FUNCTION __ + "" 
// * + "custom1_buffer [shift + 1] =" + custom1_buffer [shift + 1] 
// * + "custom2_buffer [shift + 1] =" + custom2_buffer [shift + 1] 
// * + "custom1_buffer [shift] =" + custom1_buffer [shift] 
// * + "custom2_buffer [shift] =" + custom2_buffer [shift]; 
// // --- return the trading signal 
// * return (sig); 
// *}

In the programming of the code in this step there is nothing complicated and it is similar to the previous step.

The only difference is that at this stage you program your indicators in the role of Filter.

You can not specify signals by the indicator, but specify only 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 made your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, Then you will get the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are trying for you! 
// 
// Our website: https://www.expforex.com 
// Our store: https://www.expforex.com/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 made your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, Then you will get the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are working for you! 
// 
// Our website: https://www.expforex.com 
// Our store: https://www.expforex.com/shop 
// MQL5 store: https://www.mql5.com/users/vladon/seller 
// ################################################ ###########################

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

It indicates that the programming of your strategy is over.

Good luck and profits to you!

 

MetaTrader 5 Conclusions and verification of the strategy.

If you did everything right, then your strategy will be included in the advisor and you will be able to trade it with the help of my advisor.

Now we need to test our advisor and strategy.

  1. Load the terminal;
  2. Open a demo account;
  3. Establish an advisor on the schedule;
  4. If all is OK, you will receive a message about the successful addition of the strategy:
  5. Or you will get an error. Then you need to again carefully look at your code and repeat all the steps!

 

Checking the Expert Advisor in the Strategy Tester:

  1. We open the terminal;
  2. Open the strategy tester;
  3. We choose our expert, currency, TF, date. We check the tick on every tick based on real ticks;
  4. Open the Settings tab;
  5. We choose our strategy;
  6. Turn on Visualization;
  7. Press START;
  8. A graph should open;
  9. If the advisor opens positions, then you did everything right!

 

Programming THE X for MetaTrader 4

You must know the minimum programming rules in order to write your strategy Or ​​add a ready strategy for indicators from the finished file (Expert Advisors from the Internet, for example)

Programming advisors for MetaTrader 5 is more difficult than programming for MetaTrader 4. But the MT5 terminal allows you to create more powerful strategies, and also has a more advanced strategy tester.

On the other hand: There are a lot of strategies and indicators for the MetaTrader 4 terminal on the Internet. Therefore, you can use the code for mt4!

And one more important reminder: The coding strategy in mt4 is much easier than encoding in mt5!

In any case, you should buy that open code on which the terminal will work.

MetaTrader4 Step 0: Step 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
//
// In order for the indicator to be built into the Expert Advisor during compilation, you need to load it into the resources of the Expert Advisor
// In order for the indicator to be built in 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 are obliged to add the indicators needed by Us to the resources.

This will allow us to compile an advisor for the market, and also save us from unnecessary problems when the compiled adviser suddenly does not find the desired indicator on another computer!

Rules for writing the name of the market: The full name of the folders, 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: Step of specifying 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 of the adviser.

This is done in order to conveniently manage the signals during the expert setup phase.

For example:

  1. You want to name your strategy MY STRATEGY
  2. The strategy number must also be unique. The first 22 numbers are occupied by signals from standard indicators! Remember this figure, we will need it in the future.
  3. The name must also be unique. For example: MYSTRATEGY1

In the end, we 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 with

MetaTrader 4 Step 2: Step to specify the name of the signal to display the name on the 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 for the name of your strategy to be displayed in our panel for the EApadpro EA

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

For example:

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

 

MetaTrader 4 Step 3: Step of specifying 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 of the Expert Advisor.

This is done to make it convenient to manage the filters during the expert setup phase.

Usually: 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 is a fact of the signal. Examples of differences between filters and signals

For example:

  1. You want to name your filter MY FILTER
  2. The number of the filter should also be the same as the number of the strategy (This is done in order not to be confused in the future with figures). The first 22 numbers are occupied by filters from standard indicators! Remember this figure, we will need it in the future.
  3. The name must also be unique. For example: MYFILTER1

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

MYFILTER1 = 77, // MY FILTER

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

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

MetaTrader 4 Step 4: Step to specify the parameters of the indicator or strategy 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 the external variables of your indicator or indicators that will be used in your strategy 
// Write 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 of your strategy, which can be changed from the Expert Advisor. For example, for optimization.

Also here you can take out specific parameters of the strategy. For example, the levels of intersection of lines, the limitation of the indicator's operation on MAX and MIN price on the chart and so on ...

You do not have to enter all the parameters for the indicators. It is enough to make those that you can change in the future from the settings of the Expert Advisor. All other parameters you can leave the indicator by default.

MetaTrader 4 Step 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 drink coffee 
// Step 5 is only necessary for the MT5 terminal. So at this step you can drink 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 eat sandwiches 
// Step 6 is only needed for the MT5 terminal. So at this step you can eat sandwiches 
// ################################################ ###########################

// 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 needed only for MT5 terminal. Make a workout 
// Step 7 is only necessary for the MT5 terminal. Make a workout 
// ################################################ ###########################

MetaTrader 4 does not require loading of 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: The main step in creating strategies and signals for opening positions!

// Step 8 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Here we create our signal to open positions. Fill in the data buffers 
// Here we create our signal for opening positions. Fill in the data buffer 
// ################################################ #################### 
// for example: 
// * if (sigInd == 77) 
// * { 
// 
// Fill the data, 
// We fill in the data 
// 
// 
// * double CustomMain = iCustom (Symbolt, TF_IndSigToTrade1, ":: Indicators \\ MACD", 0, OWNSIGNAL_shift); 
// * double CustomSig = iCustom (Symbolt, TF_IndSigToTrade1, ":: Indicators \\ MACD", 1, OWNSIGNAL_shift); 
// 
// * double CustomMain2 = iCustom (Symbolt, TF_IndSigToTrade1, ":: Indicators \\ MACD", 0, OWNSIGNAL_shift + 1); 
// * double CustomSig2 = iCustom (Symbolt, TF_IndSigToTrade1, ":: Indicators \\ MACD", 1, OWNSIGNAL_shift + 1); 
// 
// 
// Here we write our strategy, in this example it's the intersection of two lines, 
// Here we write our strategy, in this example it is the intersection of two lines 
// 1. 
// * if (CustomMain> CustomSig && CustomMain2 <CustomSig2) 
// // Buy Signal 
// * Signal = 1; 
// * if (CustomMain <CustomSig && CustomMain2> CustomSig2) 
// // Sell Signal 
// * Signal = -1; // 
// We write down the data that will be displayed in the log, when the positions are opened at the signal 
// We write down the data that will be displayed in the log, when you open positions on a signal 
// 2. 
// * InfoAboutSignal = "InfoAboutSignal sigInd =" + sigInd + "Signal =" + Signal 
// * + "CustomMain =" + CustomMain 
// * + "CustomSig =" + CustomSig 
// * + "CustomMain2 =" + CustomMain2 
// * + "CustomSig2 =" + CustomSig2 
// *; 
// // --- return the trading signal 
// *}

This step is very important for the adviser. Although all other steps are mandatory, otherwise the adviser will not work.

I indicated my comments in the code!

Strategy number is the same as in the first steps!

  1. Programming code for strategy and signal individually. Depends on the chosen strategy and indicators. Getting buffers, strategies ........
  2. I want to note only 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.

This step can be divided into 2 substeps:

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


If you received an error message, then you need to find out the cause of this error.

Error Codes

most common errors:

ERR_INDICATOR_UNKNOWN_SYMBOL

4801

Unknown character

ERR_INDICATOR_CANNOT_CREATE

4802

The indicator can not be created

ERR_INDICATOR_NO_MEMORY

4803

There is not enough memory to add an indicator

ERR_INDICATOR_CANNOT_APPLY

4804

The indicator can not 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

Wrong 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

Wrong type of parameter in the array when creating the indicator

ERR_INDICATOR_WRONG_INDEX

4812

Invalid index of the requested indicator buffer

MetaTrader 4 Step 9: Step to specify the filters from your indicators, or use your indicator as a filter for the strategy!

// Step 9 ############################################## ###################### 
// This part of the code for programming your strategy in open source 
// This part of the code for programming your strategy in open source 
// 
// Here we create our filter for signal filtering. Fill in the data buffers 
// Here we create our filter for signal filtering. Fill in the data buffers 
// ################################################ #################### 
// for example: 
// * if (sigInd == 77) 
// * { 
// 
// Fill the data, 
// We fill in the data 
// 
// 
// * double CustomMain = iCustom (Symbolt, TFTOFILTER, ":: Indicators \\ MACD", MODE_MAIN, shift); 
// * double CustomSig = iCustom (Symbolt, TFTOFILTER, ":: Indicators \\ MACD", MODE_SIGNAL, shift); 
// 
// Here we write our strategy, in this example it's the intersection of two lines, 
// Here we write our strategy, in this example it is the intersection of two lines 
// 
// * if (CustomMain> CustomSig) 
// // Buy Signal 
// * Signal = 1; 
// * if (CustomMain <CustomSig) 
// // Sell Signal 
// * Signal = -1; // 
// We write down the data that will be displayed in the log, when the positions are opened at the signal 
// We write down the data that will be displayed in the log, when you open positions on a signal 
// 
// * InfoAboutSignal = "InfoAboutSignal sigInd =" + sigInd + "Signal =" + Signal 
// * + "CustomMain =" + CustomMain 
// * + "CustomSig =" + CustomSig 
// *; 
// // --- return the trading signal 
// *}

In the programming of the code in this step there is nothing complicated and it is similar to the previous step.

The only difference is that at this stage you program your indicators in the role of Filter.

You can not specify signals by the indicator, but specify only 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 made your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, Then you will get the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are trying for you! 
// 
// Our website: https://www.expforex.com 
// Our store: https://www.expforex.com/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 made your strategy. 
// For example, I entered a secret strategy. If you did everything correctly, Then you will get the result in the form of an alert on the screen! 
// Thank you for choosing our product. We are working for you! 
// 
// Our website: https://www.expforex.com 
// Our store: https://www.expforex.com/shop 
// MQL5 store: https://www.mql5.com/users/vladon/seller 
// ################################################ ###########################

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

It indicates that the programming of your strategy is over.

Good luck and profits to you!

 

MetaTrader 4 Conclusions and strategy check.

If you did everything right, then your strategy will be included in the advisor and you will be able to trade it with the help of my advisor.

Now we need to test our advisor and strategy.

  1. Load the terminal;
  2. Open a demo account;
  3. Establish an advisor on the schedule;

 

Checking the Expert Advisor in the Strategy Tester:

  1. We open the terminal;
  2. Open the strategy tester;
  3. We choose our expert, currency, TF, date. We check the tick on every tick based on real ticks;
  4. Open the Settings tab;
  5. We choose our strategy;
  6. Turn on Visualization;
  7. Press START;
  8. A graph should open;
  9. If the advisor opens positions, then you did everything right!

What else can be changed in the adviser?

Of course, you want to personalize your strategy and give our adviser a different look!

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 graph // Name of EA on Graph
#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. Work only on a demo account or on a live account on a pair USDJPY // Demo version of the advisor. Work only on a demo account or on a live account on a pair USDJPY
bool DEMO = false;

 

All other parameters I recommend not to change because you can break the work of the Expert Advisor!

 

Debugging a strategy

The next step is that you will test and optimize The X and look for your best settings. Or debug and upgrade your strategy

Sometimes it takes days and weeks. Sometimes even months.

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

Good luck and profit!

 

Output of additional information in the Strategy block

This is an optional option in our open source code.

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

1. To do this, you need to create a local variable,

eg   double EAPADPRO_StrategyValue1 = 0; double EAPADPRO_StrategyValue2 = 0;

2. Assign the value of 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:

 if (sigInd == 18)
 {

 // + ----------------------------------------------- ------------------- +
 double atrma = iMA (Symbolt, TFTOFILTER, ATR_MA_period, 0, MODE_SMA, ATRprice, shift);
 double atrma2 = iMA (Symbolt, TFTOFILTER, ATR_MA_period, 0, MODE_SMA, ATRprice, shift + 1);
 double atr = iATR (Symbolt, TFTOFILTER, ATR_period, shift);

 if (atrma> atrma2 + atr * ATR_MULTIPLIER) // Buy Signal
 Signal = 1;
 if (atrma <atrma2-atr * ATR_MULTIPLIER) // Sell Signal
 Signal = 2;
 EAPADPRO_StrategyValue1 = atr;
 EAPADPRO_StrategyValue2 = atrma ;
 InfoAboutSignal = "InfoAboutSignal FILTER sigInd =" + sigInd + "Signal =" + Signal
 + "atr =" + atr
 + "atrma =" + atrma
 + "atrma2 =" + atrma
 ;
 } 

 

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

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

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

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

The first parameter of the function = The name of the variable

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

Attention! Add an even number of parameters so that it's beautiful on the screen!

 

 

The X: 10 steps to program your strategy!_1
Здесь можно скачать The X: 10 steps to program your strategy!
Купить The X: 10 steps to program your strategy! можно здесь - Прочитать о The X: 10 steps to program your strategy! можно здесь - Обсуждение The X: 10 steps to program your strategy! - стейты, отзывы, комментарии - Отзывы о The X: 10 steps to program your strategy! - Настройки к The X: 10 steps to program your strategy! - Мониторинг The X: 10 steps to program your strategy! - Download The X: 10 steps to program your strategy! - Buy The X: 10 steps to program your strategy! - Read about The X: 10 steps to program your strategy! - Discusion of The X: 10 steps to program your strategy! - Comments of The X: 10 steps to program your strategy! - Settings The X: 10 steps to program your strategy! - Monitoring The X: 10 steps to program your strategy! - The X: 10 steps to program your strategy! скачать бесплатно - The X: 10 steps to program your strategy! ключ - The X: 10 steps to program your strategy! открытый код - The X: 10 steps to program your strategy! скачать
-
Читать The X: 10 steps to program your strategy!
0 $

This is the most common phrase in search queries.

The X is a designer of trading strategies .

We created an advisor that has all the most interesting and necessary functions. And added a block of signals in the form of standard indicators.

It was a project that became very popular. For 5 years we have been working on the algorithm, adding new functions, new indicators. Corrected errors in functions.

This article will help you in programming your strategy. Programming the advisor on indicators. Adding new signals and filters.

English instructions and articles FinanceApplication Windows 01.08.2018
5 3
Expforex Идеи для Форекс https://www.expforex.com/1NEWDESIGN/NEWLOGO/LOGONEW.png expforex@meta.ua Украина expforex2