Download MetaTrader 5

Why define the MAGIC_NUMBER as an integer, not string?

To add comments, please log in or register
thomas2004
259
thomas2004  

I understand little bit why define the MAFIC_NUMBER as an integer, not a string? I think define it as a string is much better than as an integer since you can transform an integer to a string but nit vise verse, right? Besides a string can tell much more than an integer. Right?

Carl Schreiber
Moderator
8361
Carl Schreiber  
thomas2004:
I understand little bit why define the MAFIC_NUMBER as an integer, not a string? I think define it as a string is much better than as an integer since you can transform an integer to a string but nit vise verse, right? Besides a string can tell much more than an integer. Right?

Just accept it, it's the way it is.

Beside that an integer can be sorted easier than a string (with or without capitals, special characters,...) and you have the comment of a position which is a string.

thomas2004
259
thomas2004  

Yes, there is the comment. But can I just use the comment, not the magic number to tell the different orders? Or must I use different magic numbers as well for different order?


... 
string ORDER_COMMENT = EURUSD15M;
...

...
      for(int i=OrdersTotal()-1; i >= 0; i--)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
            if(OrderType()==OP_BUY && OrderComment() == ORDER_COMMENT)
                ...
        }
      }         
...

A string can be understood much better than an integer.

Maybe sorting integers is easier than sorting string. But sorting string is much meaningful than sorting integer.
Emma Schwatson
1667
Emma Schwatson  
thomas2004:

Yes, there is the comment. But can I just use the comment, not the magic number to tell the different orders? Or must I use different magic numbers as well for different order?


A string can be understood much better than an integer.

Maybe sorting integers is easier than sorting string. But sorting string is much meaningful than sorting integer.
The broker server will change the comment for things like sl, tp, close by, etc
whroeder1
17828
whroeder1  
  1. thomas2004: why define the MAFIC_NUMBER as an integer, not a string?
    Because 15+ years ago, someone at Metaquotes defined it that way.

  2. thomas2004: can I just use the comment, not the magic number to tell the different orders?
    1. Not a good idea to use comments, brokers can change comments, including complete replacement.

    2. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
                Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

kypa
777
kypa  

It's defined as integer because otherwise it would have to be called not MAGIC_NUMBER but MAGIC_WORD and people would start writing silly things for it.

There is StringToInteger and StringToCharArray function if you really want to make things complicated though.

Alain Verleyen
Moderator
36405
Alain Verleyen  
kypa:

It's defined as integer because otherwise it would have to be called not MAGIC_NUMBER but MAGIC_WORD and people would start writing silly things for it.

There is StringToInteger and StringToCharArray function if you really want to make things complicated though.

And if it was MAGIC_WORD, people would start to ask why it's not an int or whatever.
Marco vd Heijden
Moderator
6521
Marco vd Heijden  

An integer is a number and will always be a number.

But with a string there are several encoding's for example like 'UTF-8' 'Latin-1' and many more.

Errors are very easy to occur due to incompatibility between types, when these get mixed up for whatever reason.

It should be an int and it should stay an int.

The only type that i ever would consider would be a immutable bytestring but that's simply overkill in this case. 

thomas2004
259
thomas2004  
kypa:

It's defined as integer because otherwise it would have to be called not MAGIC_NUMBER but MAGIC_WORD and people would start writing silly things for it.

There is StringToInteger and StringToCharArray function if you really want to make things complicated though.

Cuold you please convert the "Hello World" to integer? I do want to see what it looks like. :-D

To add comments, please log in or register