What is and how to set the magic number at EA's ? - page 2

 
edfiuza:

Eduardo,

The "magic" number can be any number you choose. Simply put it's used within an EA to identify trades that belong (were opened by) that EA. It can be ANY number you choose. The main concern with choosing your magic is that you want it to be unique for each and every implementation of the EA. If you hard code the number in the EA lets say 50000, then each chart you attach the EA to will have the same magic number, and each will not be able to find its own trades. To overcome this, problem I would simply add the charts time frame to it like this:

int thisEA=50000;

mymagicnum=thisEA+Period();


But this will not be unique once you start attaching the EA to different currency pairs. Better yet, assign a number to each currency pair you will ever trade for example eurusd=1000, audusd=2000, etc. I dont know if somehwere in MQL each currency pair already has a number assigned to it. If they do then someone else can clarify for us and this code will be much simplified. Assuming you will be trading from multiple EAs on the same Pairs and Time Frames, again I would assign each EA a unique number. Then you would have code that looks something like this:


int thisEA=50000;

if (Symbol() == "EURUSD") {mymagicnum= thisEA+1000+Period();}

if (Symbol() == "AUDUSD") {mymagicnum= thisEA+2000+Period();}

..................

Now you will have a unique magic number for all trades made by each EA for each time period and each currency.


 

Hi All,

 

How i can use some magicnumbers into an EA only?

 

Pls help the way!

 

The magic number is your reference of the order you send (the ticket number is the broker's reference).

So set the magic number in OrderSend() and if you loop through the (closed or open) orders you get it by OrderMagicNumber().

It is an integer so you are free to choose -2'147'483'648 to 2'147'483'647.

Common use is that EAs do have individual magic numbers so that they identify their own positions.

 
hanhtran.qt: How i can use some magicnumbers into an EA only?

Read the following post for some extra guidance: https://www.mql5.com/en/forum/159315

 
thank for your topic. Magic number is same ID of Order Send per 1 pair currency. I think so.
 
Hello everyone. I am using EA where set Magic number as 123. But during trading I cant see this number on my opened positions or closed operations. Is this problem with my MT4 ?
 
Nargiz Ravanova:
Hello everyone. I am using EA where set Magic number as 123. But during trading I cant see this number on my opened positions or closed operations. Is this problem with my MT4 ?

You can get it by selecting the order and then calling for OrderMagicNumber().

 
Marco vd Heijden:

You can get it by selecting the order and then calling for OrderMagicNumber().

I know about ordermagic number, I am asking where to check physically magic number, my ea opening and closing positions but I cant find magic number on MT4.
 
You don't. It's only used in code.
Reason: