Discussion of article "The Use of ORDER_MAGIC for Trading with Different Expert Advisors on a Single Instrument"

 

New article The Use of ORDER_MAGIC for Trading with Different Expert Advisors on a Single Instrument is published:

This article considers the questions of information coding, using the magic-identification, as well as the division, assembly, and synchronization of automatic trading of different Expert Advisors. This article will be interesting to beginners, as well as to more experienced traders, because it tackles the question of virtual positions, which can be useful in the implementation of complex systems of synchronization of Expert Advisors and various strategies.

Figure 7. The result is conflict-free trading of three Expert Advisors with different magics

Author: Николай

 

I don't know who or how, I prefer to explicitly specify ID numbers when creating my own enumerations (although it's not necessary).

For example like this:

enum Emagic
{
ENUM_DIGITAL_NAME      = 0, // numeric name of the advisor
ENUM_CODE_INTERACTION  = 1, // interaction code
ENUM_EXPERT_SYMBOL     = 2  // the symbol on which the EA is launched
};

This can also help when migrating from MQL4, for example, this is the enumeration I use to work with orders

//ENUM_MT4_ORDER_TYPE
enum ENUM_MT4_ORDER_TYPE
//Types of trading operations
{
OP_BUY  = 0, //Purchase 
OP_SELL = 1, //Sale 
OP_BUYLIMIT  = 2, // Pending BUY LIMIT order 
OP_SELLLIMIT = 3, //Pending order SELL LIMIT 
OP_BUYSTOP   = 4, //Pending BUY STOP order 
OP_SELLSTOP  = 5  //Pending SELL STOP order 
};

This approach is convenient, because regardless of the position of the identifier in the enumeration, its Code (numeric value will not change)....

Also, this approach is convenient if the enumeration should contain identifiers with a negative value


PS

Very interesting article, thanks to the author...

 
Interesting:

I don't know who or how, I prefer to explicitly specify ID numbers when creating my own enumerations (although it's not necessary).

For example like this:

This can also help when migrating from MQL4, for example, this is the enumeration I use to work with orders

This approach is convenient, because regardless of the position of the identifier in the enumeration, its Code (numeric value will not change)....

Also, this approach is convenient if the enumeration should contain identifiers with a negative value


PS

Very interesting article, thanks to the author...


For me it's not crucial, because when declaring an enumeration the values are assigned in order automatically,

although I agree that your variant is clearer (especially if the enumerations are long, say more than 3-4).

 

With such an approach to the magician it is necessary to write the same instruction for the user - so that the user could clearly know which magicians will be occupied and which ones are free. Users of Expert Advisors use Expert Advisors not only from one developer, and the method is unlikely to be included in the standards, which are used by all Expert Advisor writers. If the terminal developers had divided this ulong into several variables, so that there would be several mages, for example, four two-byte ones.

request.magic
request.id1
request.id2
request.id3

Or at least complete the terminal with a library, so that it could somehow be included in the standards.

SetMagic(Magic,Id1,Id2,Id3) 
 
Integer:

With such an approach to the magician it is necessary to write the same instruction for the user - so that the user could clearly know which magicians will be occupied and which ones are free. Users of Expert Advisors use Expert Advisors not only from one developer, and the method is unlikely to be included in the standards, which are used by all Expert Advisor writers. If the terminal developers had divided this ulong into several variables, so that there would be several mages, for example, four two-byte ones.

Or at least complete the terminal with a library, so that it could somehow be included in the standards.

It is not at all a fact that for the user it is necessary to write the instruction on work with MAGIK, even if so it will not go beyond the description of how MAGIK is formed....

I believe that at the moment this is one of the best articles on trade automation. I will say more - I myself am a supporter of coding MAGIC at a more serious level than 777777 or 555555, even perhaps I prefer to put there more detailed information than say it is done by the author.

But I did not realise to use structures (since the idea of coding has been around since MQL4), although I was probably on the verge of it....

I also do not think it is necessary to "write" in MAGIC any information about symbols on which trade operations are made (this is due to the fact that this information is already stored elsewhere and from the moment of the order and up to the moment of full closing of the position does not change). Also I think it will be enough to allocate the last three digits of the MAGIC (if not to use the security code) to the EXPERT's MARKER (OR MARKER, I won't say how it is in genetic engineering).

This is because in the FIRST of these digits you can encode 9-10 basic classes of experts, and in the remaining two its unique number from the point of view of the user or developer. As a result, you will normally get from 900 to 1000 combinations.

I also prefer an algorithm where the Expert Advisor recognises at least the orders set by the trader and encodes them accordingly.

PS

I don't think it's necessary to be afraid that several EAs will confuse the coded MAGIC, at least I think that with a certain approach it is not as dangerous (and probably probable) as it seems at first glance. Especially it becomes irrelevant if all these experts (even if from different authors) support this methodology of encrypting MAGIC and take into account each other's actions. Ideally, only one expert should trade on this or that pair.....

 

The article gives an example of using codes, and not all digits are used and the coding is obviously with excess,

If necessary, even these 9 occupied bits can be compressed.

In addition to identification to the magician (those its remaining 9 bits) can also be transferred the state of the balance at the time of placing an order.

Since the balance is unlikely to take more than 6 bits, there is still room for any coding.

 
Urain:

The article gives an example of using codes, and not all digits are used and the coding is obviously with excess,

If necessary, even these 9 occupied bits can be compressed.

In addition to identification to the magician (those its remaining 9 bits) can also be transferred the state of the balance at the time of placing an order.

Since the balance is unlikely to take more than 6 bits, there is still room for any coding.

To all this you should add 1000 or 10000 and subtract it before decoding, so that there is a guaranteed range of magics not occupied by your method.

 
Integer:

To all this should be added 1000 or 10000, and before decoding to subtract, so that there is a guaranteed range of not occupied by your method of magiks.

Well, how to do this painlessly described in the article (just need a little work to expand the range of encryption),

I don't see any problems.

PS the only thin place should not forget to translate the balance into integer otherwise the comma will give glitch, how to do it should be seen on the binding if the account cent then multiply by 100 if such precision is not necessary then the translation into int with trimming.

 
Urain:

Well, how to do it painlessly is described in the article (just need a little tweaking to expand the range of encryption),

I don't see any problems.

PS the only thin place should not forget to translate the balance into integer otherwise comma will give glitch, how to do it should look at the binding if the account is cent then multiply by 100 if such precision is not necessary then the translation into int with clipping.

If there is no problem, give a short and clear instruction, how to guarantee the non-intersection of magics encoded by your system and not encoded.

 
Integer:

If it is not a problem, give a short and clear instruction, how to guarantee the non-intersection of magiks encoded by your system and not encoded.

So that my answer does not look like an excuse I will say at once that this question is not considered but it is allowed.

Here is the maximal value of ulong 18 446 744 073 709 551 615 those 17*10^18 has all free fields. Стоит добавить при кодировании 17 000 000 000 000 000 000 и поставить при декодировании проверку содержит ли 20 и 19 разряд числа 1 и 7 и вы гарантированно определите кодированный ли магик или нет.

//+------------------------------------------------------------------+
//| The function returns a prefabricated magik assembled from the input data ||
//+------------------------------------------------------------------+
ulong Cmagic::SetMagic_request(int digital_name=0,int code_interaction=0)
  {
   if(digital_name>=1000)Print("Advisor's numeric name is incorrectly set (greater than 1000)");
   if(code_interaction>=1000)Print("Incorrect alien-alien identification code set (greater than 1000).");
   mag.digital_name     =digital_name;
   mag.code_interaction =code_interaction;
   mag.expert_symbol    =symbolexpert();
   mag.magicnumber      =17000000000000000000+// вот эта вставка даст 20 разрядов магику
                         mag.digital_name*(int)pow(1000,2)+
                         mag.code_interaction*(int)pow(1000,1)+
                         mag.expert_symbol;
   return(mag.magicnumber);
  }

and in the decoder.

//+------------------------------------------------------------------+
//| The function divides the magik into three parts of three digits ||
//|| and returns the part pointed to by category |
//+------------------------------------------------------------------+
int Cmagic::decodeMagic_result(int category)
  {
   string string_value=(string)mag.magicnumber;
   int rem=(int)MathMod(StringLen(string_value),3);
   if(rem!=0)
     {
      rem=3-rem;
      string srem="0";
      if(rem==2)srem="00";
      string_value=srem+string_value;
     }
   int start_pos=StringLen(string_value)-3*category;
   string value=StringSubstr(string_value,start_pos,3);
   if(StringLen(string_value)!=20)return((int)StringToInteger("0"));//если магика не 20 разрядов значит не кодированный
   return((int)StringToInteger(value));
  }

that's how it is, and don't forget Dimitri that the one who wants to do is looking for an opportunity and the one who doesn't want to do is looking for a reason, I opened a window in your power to make a window or even a door out of it.

By the way, I use this

(int)pow(1000,2)

displacement by digits but nobody forbids to rewrite it through string, just in the article I wanted to show both methods and if possible organically fit (so encoding goes through int and decoding through string).

And in general I wanted to show the possibilities and not to give a black box converter (it is better to give a man a shovel than a bucket of porridge).

PS here said one thing encoded another, ( I have a thunderstorm so that the network is regularly knocked out) encoded check not 1 and 7 in 20 and 19 digits and the presence of these very digits those if the magik 20-digit means used encoding, but you understand the check can be replayed.

 

1.Thanks to the author for the article.
2..What expression (int) means and what value it takes in int DIGITS=(int)-log10(SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP)); if(DIGITS<0)DIGITS=0;
3.Why, during testing, do the expression (int) and SYMBOL_VOLUME_STEP take the values Unknown identifier and how does it affect the result int DIGITS ?
4.How does the interaction code work?
Does the interaction code matter when EAs work on the same instrument, where it is enough to set either identical or different numeric names of EAs.