Is it possible to create a magic number array?
yes
ex. I am going to make 5 orders and each order has an unique magic number.
int magicArray = { 1, 3, 5, 7, 9 };
if(OrderMagicNumber() == magicArray[3]) { // that refer to be 7 in this example
Is it possible to create a magic number array?
yes
ex. I am going to make 5 orders and each order has an unique magic number.
int magicArray = { 1, 3, 5, 7, 9 };
if(OrderMagicNumber() == magicArray[3]) { // that refer to be 7 in this example
Thanks!
How do I OrderSend every new order with unique magic number array? Will it work this way? magicArray[x] instead of 12345?
OrderSend is in a function and not in a loop. How would it know how to assign new magic number with each new order. Is it just by adding x++ after OrderSend?
Do I need to initialize a global array?
How to do a dynamic array, as I don't know how many orders there will be eventually?
int magicArray[x]; ... int ticket=OrderSend(Symbol(),OP_BUY,LotSize,MarketInfo(Symbol(),MODE_ASK),3,0,0,"My EA",magicArray[x],0,Green); x++;
Why do you want to assign each order a different magic number in the first place? Magic numbers are meant for grouping trades that belong together and the whole point is that you will have one magic for many trades (that belong together).
You should not use them for things they are not meant for. Other EAs use them to identify their own trades. We just recently had a thread here where one EA whose author tried to be super smart and abused the magic for some kind of counter started to interfere with other EA's trades and produced a loss of $5000 dollar in only one night for the innocent victim who bought this EA by entering an open-close-open-close-"fight" over the same trade. The EA did silently start to change its assigned magic number for no obvious reason and without notice until the conflict happened. A magic number is expected to stay constant!
If you need a unique number for *each* trade then just use the ticket number.
Why do you want to assign each order a different magic number in the first place? Magic numbers are meant for grouping trades that belong together and the whole point is that you will have one magic for many trades (that belong together).
You should not use them for things they are not meant for. Other EAs use them to identify their own trades. We just recently had a thread here where one EA whose author tried to be super smart and abused the magic for some kind of counter started to interfere with other EA's trades and produced a loss of $5000 dollar in only one night for the innocent victim who bought this EA by entering an open-close-open-close-"fight" over the same trade. The EA did silently start to change its assigned magic number for no obvious reason and without notice until the conflict happened. A magic number is expected to stay constant!
If you need a unique number for *each* trade then just use the ticket number.
Thanks, exactly I need to group my orders that belong together
int ticket=OrderSend(Symbol(),OP_BUY,LotSize,MarketInfo(Symbol(),MODE_ASK),3,0,0,"My EA",12345,0,Green) & ticket=OrderSend(Symbol(),OP_BUY,LotSize,MarketInfo(Symbol(),MODE_ASK),3,0,0,"My EA",12345,0,Green);I open in 2 pairs, I would like to open 2 pairs then close 2 pairs. Having an unique magic number could help me open and close the related 2 pairs. I do not want to close the wrong pair.
idea: you could use always the same magic number as usual to make it compatible with everything else that uses magic numbers but also combine it with the comment string by including a number in the comment that is unique to each pair of trades. You could then find the other trade of each pair of trades by simply looking for a trade with the same magic and comment.
Thanks!
Basically I need an unique tag to every order (2 pairs each) and so that I could close them at the same time.
I do not want to close the wrong pair.
If not magic number, how could I to add this unique comment to every order?
Would I need some kind of dynamic array?
There are many combinations you can use
for example if you open them in a different minute you can use
OrderMagicNumber() == Minute();
And if you open them in a different hour you can use
OrderMagicNumber() == Hour();
Or if you open them on a different TM you can use
OrderMagicNumber() == Period();
There are many combinations you can use
for example if you open them in a different minute you can use
And if you open them in a different hour you can use
Or if you open them on a different TM you can use
There are many combinations you can use
for example if you open them in a different minute you can use
And if you open them in a different hour you can use
Or if you open them on a different TM you can use
Thanks! but if I have orders made in the same minute or time frame, it may close the wrong order. I need unique tag, like magic number.
I need to know how to assign a new magic number to each new orders then compare all orders to find them when closing.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is it possible to create a magic number array?
ex. I am going to make 5 orders and each order has an unique magic number.
Instead of 12345, maybe OrderMagic [x][0] for each new order make? How to do that?Then when closing, I will go through every order and close specific order with its unique magic number?
Instead of 12345, how do I go through every unique magic number in the array?
Thanks in advance!