In my EA, I use the following line of code to register its Magic Number:
The function has no return value, so is there a generic method to check whether a Magic Number is already in use? I'm looking to block an EA from loading if the Magic Number already exists.
Thanks
As @Yashar Seyyedin said, you'd have to somehow communicate with other EAs running, so you'd have to control the code for all the other EAs.
Alternatively, you could loop through the order history and check the magic numbers using HistoryOrderGetInteger(ticket, ORDER_MAGIC). If the EA has ever made a trade with that magic number, that would tell you. Wouldn't prevent it from using the same one as a running one that's never traded, but it's a lot better than nothing.
Also, you could randomly generate your magic number - the odds of duplicating any one number would be 1 in 2,147,483,647.
As @Yashar Seyyedin said, you'd have to somehow communicate with other EAs running, so you'd have to control the code for all the other EAs.
Alternatively, you could loop through the order history and check the magic numbers using HistoryOrderGetInteger(ticket, ORDER_MAGIC). If the EA has ever made a trade with that magic number, that would tell you. Wouldn't prevent it from using the same one as a running one that's never traded, but it's a lot better than nothing.
Also, you could randomly generate your magic number - the odds of duplicating any one number would be 1 in 2,147,483,647.
Thanks for the info - I guess that checking history would only work if the EA with the existing magic number had made some trades. I'll take a look at using a random number.
Thanks - it is a shame that the command doesn't warn on duplicate magic numbers. I'll check out globals.
Which defeat the purpose of using a magic number. What if I want to use the EA with different parameters on the same symbol/timeframe ?
Thanks - it is a shame that the command doesn't warn on duplicate magic numbers. I'll check out globals.
"A shame" is really exaggerated.
It's a simple system which put the responsibility on the final user. If the coder want to have so control and add features on it, it can become tricky.
However it could be a lot better with an integrated management by the platform, but it's not the path the developers took. It's a choice, not a shame.
"A shame" is really exaggerated.
It's a simple system which put the responsibility on the final user. If the coder want to have so control and add features on it, it can become tricky.
However it could be a lot better with an integrated management by the platform, but it's not the path the developers took. It's a choice, not a shame.
I think you've misinterpreted my use of the word "shame" - its not intended as a criticism - if I were to rephrase my comment, I'd say "it would be nice if......"
It is what it is, and I'll implement something to satisfy my requirement.
Might want to add the EA name (either input or hard-coded variable) as input for that CRC as well, as you might have other EAs running on the same symbol and timeframe.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In my EA, I use the following line of code to register its Magic Number:
The function has no return value, so is there a generic method to check whether a Magic Number is already in use? I'm looking to block an EA from loading if the Magic Number already exists.
Thanks