How to create a Magic Number array? - page 2

 
7bit:
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.


      I want to have an unique tag like magic number when I place an order. No fix number of orders.

Every new orders is to be treated as a new group and to be managed separately.

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);

Instead of fix 12345, I would like magic number to increment with every new order like 1, then next order 2, then 3, then 4 etc. 

Also the OrderSend is in a function that does not loop. How to do something like that?

Sometime like a dynamic array[i] ???

When I try to close, I could go through OrdersTotal() and every unique magic number array[i] ??? And would close those in the same group when condition is met.

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

can u please show me Where exactly is contained in the order Period(); ?
 
qjol:
can u please show me Where exactly is contained in the order Period(); ?

It's not.

IMHO, if u don't plan on using other experts with this one, and don't plan on giving it away, then u can use the Magic Number for storing anything u want...

 
qjol:

can u please show me Where exactly is contained in the order Period(); ?
What is OrderPeriod()???
 
gordon:

It's not.

IMHO, if u don't plan on using other experts with this one, and don't plan on giving it away, then u can use the Magic Number for storing anything u want...


  Maybe a function to store the incrementing magic number

Before each OrderSend, run the function to find out which magic number is to be assigned next.

 

Any idea how to make a function like this? 

 
johnnybegoode:

Any idea how to make a function like this?

There is a relatively complex example in this article -> http://mqlmagazine.com/mql-programming/object-oriented-trading-an-oop-approach-to-trading/.
 
gordon:
There is a relatively complex example in this article -> http://mqlmagazine.com/mql-programming/object-oriented-trading-an-oop-approach-to-trading/.


Thanks!
That is really complex, any easier method?
 
johnnybegoode:


I would like magic number to increment with every new order like 1, then next order 2, then 3, then 4 etc.

But wouldn't this guarantee that you never have two orders with the same unique number? Your "groups" would consist of only one trade in each group? Did I understand you correctly?

You explained what you want to do (array of MN, etc.) based on what you see as the only solution to the problem but you still did not explain the problem itself, how the trading system is supposed to decide which orders to close and which ones to keep. How would it work if one wanted to trade this manually, maybe is there a publicly available trading system that is similar enough to it to explain the concept, to make clear what type of system this is?

For example "usually" (very often) one tries to close orders that fulfill certain requirements that can be determined from the order itself, for example "oldest order", "x pips profit", "break even", "x pips loss", etc. and the magic number is only used to tell the own trades and the trades from completely different EAs apart.

Could one trade (continue trading) this system manually if one just looked at the chart with already opened orders on it and *without* having IDs written to them?

What is it in your system that you need a single ID from a single order only to decide whether the order should be closed? And why can't you just use the ticket number itself if every order is unique anyways?

Knowing more about this would allow to step back and view the whole thing from a different angle and maybe find a much more elegant and easier solution.

 
7bit:

But wouldn't this guarantee that you never have two orders with the same unique number? Your "groups" would consist of only one trade in each group? Did I understand you correctly?

You explained what you want to do (array of MN, etc.) based on what you see as the only solution to the problem but you still did not explain the problem itself, how the trading system is supposed to decide which orders to close and which ones to keep. How would it work if one wanted to trade this manually, maybe is there a publicly available trading system that is similar enough to it to explain the concept, to make clear what type of system this is?

For example "usually" (very often) one tries to close orders that fulfill certain requirements that can be determined from the order itself, for example "oldest order", "x pips profit", "break even", "x pips loss", etc. and the magic number is only used to tell the own trades and the trades from completely different EAs apart.

Could one trade (continue trading) this system manually if one just looked at the chart with already opened orders on it and *without* having IDs written to them?

What is it in your system that you need a single ID from a single order only to decide whether the order should be closed? And why can't you just use the ticket number itself if every order is unique anyways?

Knowing more about this would allow to step back and view the whole thing from a different angle and maybe find a much more elegant and easier solution.


"But wouldn't this guarantee that you never have two orders with the same unique number"

Yes possible to have 2 or more orders with unique number. Do the increment after the group orders 

 

Jon this function issues unique numbers

//+------------------------------------------------------------------+
//| Function..: SequenceNumber                                       |
//| Purpose...: Generate a sequential number.                        |
//| Returns...: dSeqNum - next sequence number.                      |
//| Notes.....: MT4 keeps the value of the global variable at the    |
//|             client terminal for 4 weeks since the last access.   |                        
//|             Use SequenceNumber() to generate a unique identity   |
//|             for each order (and passed via parameter <magic>     |
//|             number, or converted to a string and passed via the  |
//|             parameter <comment> to the OrderSend() function) as  |
//|             the trade servers of some brokers do modify the      |
//|             ticket number of a pending order when it changes to  |
//|             a market order.                                      |
//|             The same sequence number could, for example, be used |
//|             to identify the two positions of a straddle order.   |
//|             ******************************************************
//|             * If the expert has to close partial lots, then MT4  *
//|             * retains in the new order the contents of the       *
//|             * OrderMagicNumber() but loses OrderComment().       *
//|             ******************************************************
//| Sample....: string sNumber=DoubleToStr(SequenceNumber(),0);      |
//|             if(OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-25*Point,   |
//|                          Ask+25*Point,sNumber,16384,0,Green) > 0)|
//|                OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-25*Point,   |
//|                          Ask+65*Point,sNumber,16384,0,Green);    |
//+------------------------------------------------------------------+
double SequenceNumber() {
  double dSeqNum=1, d;
  string sName="SequenceNumber";

  while(GlobalVariableCheck("Semaphore")) d+=0;
  GlobalVariableSet("Semaphore",1);
  if(GlobalVariableCheck(sName)) dSeqNum=GlobalVariableGet(sName)+1;
  GlobalVariableSet(sName,dSeqNum);
  GlobalVariableDel("Semaphore");
  return(dSeqNum);
}
Reason: