
All our expert advisors are capable of using magic numbers for assigning to orders, for filtering orders, or for both. Conclusion. A magic number is an order parameter that helps MetaTrader 4 and MQL4 identify orders. A magic number is necessary especially when running different expert advisors and different strategies in the same trading account · Today we will talk about the magic number, which you will find in every EA(expert advisor) in metatrader4 and metatrader5 as well. Many people don't know what this number means and what to do with it. After this article you will find out that it is very simple to use this feature. This is the magic number and where to find it. Actually it's an identifier for each trade Having said that, the period EMA must be below the period EMA or cross below. Utilise the expert advisor magic number best gold scalper ea EMA correctly, with the right time frames and the right security in your crosshairs expert advisor magic number and you have all the fundamentals of an effective swing strategy
Expert advisor magic number | blogger.com
In MQL5 we have a capability to assign a magic number to each pending order, in order to use this information to identify the order. This opens up the vast possibilities of interaction between different Expert Advisors, and the development of even more complex systems.
In this article, I would like to inform the public about the undervalued opportunities of magic number expert advisor Magic number. But before we proceed to the essence of this article's subject, we need to gain a better understanding of what constitutes the Magic number.
What could be magical in a number, which determines which Expert Advisor set it? The "miracles" begin with the opportunities, which developers set lay down into the type ulongwhich is declared by the Magic number.
Type ulong is the longest. If we observe in detail the integer type longwe see that the maximum value of this type is simply phenomenal:. Table 1. Properties of data types long and ulong.
but the type ulong outdid him by combining the magic number expert advisor and negative magic number expert advisor. So, the specified length is huge, but how was it used before? In my experience of working in mql 4, I often noticed the senselessness of coding the Magic number by many developers.
The Magic number was used sensibly, but its coding seemed quiet silly, magic number expert advisor. What can be said about the individuality of the Magic numbersuch Magic is uses by almost half of the developing fraternity. The second half uses the Magic numberandand this is pretty much the complete set.
I want to draw the reader's attention to the fact that it is unlikely that his computer has more than 1, Expert Advisors, so the number will be sufficient to encode the individual name of all your Expert Advisors. The answer is simple: encode them.
What does Wikipidia say about the word code :. The Code - rule algorithmmagic number expert advisor, the comparison for each individual message of a strictly particular combination of symbols characters or signals.
Therefore, we will make the rules. I propose to prescribe in the code of the Magic number, not only the ID of the Expert Advisor, but also the instrument, on which it is running. The fact that the Expert Advisor is running, for example, on EURUSD, does not mean that the Expert Advisor will display an order only on that instrument.
I think this will be enough to create a very complex system. And so let us sum up what we have: what opportunities are we laying down into the system:. And so, the task is set, let us now begin its implementation. Draft the code of the simple Expert Advisor- for example, hold the position in the direction of the Moving. I think that the reader, who decided to parse the Magic number, has already read the article Step-By-Step Guide to Writing an Expert Advisor in MQL5 for Beginnersif not, I highly recommend to do so, since I will not go into details into the creation of the Expert Advisor.
Basically, the Expert Advisor will be opening the position one time, and turn it for all other times. Therefore, we will need the function for opening the position, i. for placing the trading request trading order. Create an auxiliary class, which will calculate the parameters for us for filling the fields of the trading request structure. Run it and make sure that the Expert Advisor does not differ in profitability, but trades exactly in accordance to the specified logic, which is precisely what we need from it.
Figure 1. The work of one Expert Advisor on a single instrument. Now we will try to run this EA, but on different time frames of one instrument for the experiments we have chosen a random instrument, magic number expert advisor, which is Magic number expert advisor o. Figure 2. The conflict of two Expert Advisors on the same instrument on different timeframes. Since both Expert Advisors are running on a single instrument, magic number expert advisor, and the magic number expert advisor doesn't specify the sharing of positions, then both of the Expert Advisors are trying to correct the trading position, depending on the readings of their indicators, and as a consequence of this, - a conflict arises.
The Expert Advisor which is running on M1, is trying to magic number expert advisor the position in the Cell, while its rival seeks to stop it. It is obvious that we need a separate calculation of positions, which is what we will now do. Since in MetaTrader 5 developers have shifted from orders to the consideration of positions, it makes sense to consider in more detail the functions associated with recording positions. Identifiers of the enumerations for the functions of obtaining request of the magic number expert advisor position properties PositionGetDoublePositionGetIntegerand PositionGetString which are given in Tables Table 2.
Identification of the position - this is a unique number that is assigned to each re-opened position and which does not change throughout its life cycle. The turnover of a position does not change its ID. Table 3. Table 4. Identifying an order, transaction, or position can be done without a problem, but it is impossible to lead out a position by a particular Magic number, magic number expert advisor.
Now we will try to eliminate this shortcoming. Let's create analogues of built-in functions, but with identification by the Magic number. Declare a class for working with a virtual position on the Magic number. Since we have the opportunity to work with the OOP, let's also declare our own structure gaining additional practice of writing objectively. In the text above where the code of the CProvision class is givenit was not explained where everything come from and where it further goes, since the development of the Expert Advisor is not the topic of this article.
But we will consider in details the class CPositionVirtualMagic. which is used for accepting the calculations results, such a global declaration within the class, thanks to magic number expert advisor variable of the structurethis structure will be available everywhere, in any method of the class.
These methods are declared as public, and therefore, they will be available through the called class variable, at any place in the program, and are designed for output of the structure values in the requested location. This is also the section where the following method is declared:.
This is the main function of the class, and we shall further focus on its detailed analyses, and in the meantime, I will run ahead of myself and describe the function under the specifier of private access:.
This method produces a ticket record of transactions into the array, magic number expert advisor, which is basically a cycle, and could be described in the called function, but I wanted to reduce the size in order to increase the readability of the code of the function PositionVirtualMagicand so I moved this cycle beyond the function's limits, and demonstrated how to use the specifier of the private access.
So let's go back to the PositionVirtualMagic. This function, at its very beginning, has a one-line calculation of accuracy, to which you need to round the double-value of the volume of the calculated position.
This is needed for making the operation of comparison to zero, otherwise some balance in the 8th digits after the decimal point, will prevent us from equating the value to zero, and will cause an execution error. The position volume is rounded to the minimum step. And if the minimum step is greater than 1, then the rounding is done by the integral part. Next is the cycle whilebut it is used in a new way different from the one in mql4since the verification of the truthful expression is done at the end of the cycle, rather then at the beginning:.
Such approach is used because the expression of truthfulness is computed within the cycle, magic number expert advisor, and at its launch, it is not yet prepared for this verification. The cycle contains the Uploading of the historyI want to draw the attention of the reader to the fact magic number expert advisor this is a magic number expert advisor condition in order to make ensure the work of the built-in functions of working with the history.
I think that I should explain my system of choosing the variable names, magic number expert advisor. The attentive reader should have noticed that the names of the classes are defined by the initial letter "C", this is not required by the syntax and any name can be given, but such a way makes the reading much easier. If the letter "C" appears before the name, we know right away that this magic number expert advisor the name of the class, and if the letter is "S" - then it is a structure.
If the variable takes the value of some built-in function, then I simply change the components of the function's name and obtain the variable name, for example like this:. Simple and readable, we can immediately see what the variable contains. Especially since MetaEditor contains the function for dragging a particular piece of code into a specified location.
Reviewing the code further, we see that after the uploading of the history, follows the call to the function:. with the storage of the number of transactions into the variable. By the same condition, we will be implementing the verification for exiting the cycle, magic number expert advisor. What do we need this verification for? And why can't we simply upload the history and then retrieve the transactions from it?
The issue lays in the fact that during the the work of the Expert Advisors, the history will be requested separately by each EA, and thus if the Expert Advisors are running at different times, magic number expert advisor, then the depth of the history will be different.
And this means that when one Expert Advisor enters the cycle and uploads the history for its period, then before reaching the end of the cycle, it may discover that this history has already been uploaded by the request of another Expert Advisor, and so a verification for authenticity needs to be made. Incidentally, it may not be the best type of verification, but it works.
And so, let's continue. In the cycle we call up the class method, which inputs the ticket values of the transactions into a specially prepared buffer. If there were changes, the system will launch a second cycle, and continue to repeat until the history of tickets is uploaded without any errors and do not forget to put ";" at the end :. Further in the cycle forthe calculation of virtual positions takes place.
If the transaction has successfully passed a series of filters the time of the transaction magic number expert advisor the transaction Magic numbermagic number expert advisor, then its volume increases that portion of the virtual position, the type of which the transaction belongs to.
I want to note that I record the calculations of the virtual positions only from the launch of the Expert Advisor, although other options are possible. Here it should be noted how exactly the position is calculated. By the record book, which we all have been using from immemorial time and to this day, we have expenditure and profit, and the counting of the balance is kept as the difference between these values, the same scheme applies to the calculation of a position: if you open lots, 0.
Time of opening and the difference in levels are categories of profit, but the position you will be holding is 0. This is why we simply summarize all transactions, made by the Expert Advisor on Buy and separately, on Sell, then we compare them and get the general position actually, this is what the rest of the examined function is engaged with. The output of value of the function: if the volume of position is 0, then it is false, otherwise, if the position exists, then it is true:.
Now, having the function of the virtual position, magic number expert advisor, we can easily draw up the code of the Expert Advisor, which will not conflict with its "neighbors". To save up space, magic number expert advisor, I will provide certain parts of the code, which were not laid out above, rather than the entire code itself, magic number expert advisor.
Run the Expert Advisor three times on a single instrument, but with different timeframes, as well as assign different magic numbers each time:.
Figure 3. Let's assign different magic numbers to two identical Expert Advisors, one instrument, different timeframes launch of the first Expert Advisor. Figure 4.
How to use MagicNumber of RobotFX Auto Recovery expert advisor
, time: 2:44How to Use Magic Number in MT4

All our expert advisors are capable of using magic numbers for assigning to orders, for filtering orders, or for both. Conclusion. A magic number is an order parameter that helps MetaTrader 4 and MQL4 identify orders. A magic number is necessary especially when running different expert advisors and different strategies in the same trading account · The expert advisor would open and close trades at random. Setting each EA to use a different magic number prevents the robots from interfering with the others. Magic number facts. The magic number of a manually opened trade is 0. The value of a max number must be between 0 and The MQL programming language calls that last number · Magic number Forex - The Expert Advisors is a free lecture from Algorithmic day trading – Top 10 USDJPY Expert Advisors. Enroll here: blogger.com: Petko Aleksandrov
No comments:
Post a Comment