How to create a Magic Number array?

To add comments, please log in or register
Chee Chua
745
Chee Chua  

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.

int ticket=OrderSend(Symbol(),OP_BUY,LotSize,MarketInfo(Symbol(),MODE_ASK),3,0,0,"My EA",12345,0,Green) 
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?

for (int i=0; i<OrdersTotal(); i+=1)
{
           if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
           {
                     if (OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == 12345)

Instead of 12345, how do I go through every unique magic number in the array?

 

Thanks in advance!  

Ray
2646
Ray  

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

Chee Chua
745
Chee Chua  
phy:

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++;
bernd
989
bernd  

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.

Chee Chua
745
Chee Chua  
7bit:

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.
bernd
989
bernd  
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.
Chee Chua
745
Chee Chua  
7bit:
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? 

qjol
3196
qjol  

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();
bernd
989
bernd  
qjol:

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

please don't recommend such nonsense. The magic number is not meant to store values that are already contained in the order itself.
Chee Chua
745
Chee Chua  
qjol:

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. 

bernd
989
bernd  
please describe roughly what your EA will do. how many different types of orders that need to be managed separately are there. Maybe your problem is not a problem at all if we know what you are actually trying to achieve.
To add comments, please log in or register