Global Variable Help

 

Need help using the following codes.

sxTed:

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

I do not understand the Sample. Why OrderSend > 0, then perform another OrderSend? Please help!

I realized that the Sequence Number will increase with every order and that I could assign it to comment or magic number which is great. The best part is that they remain in the system even after I restart MT4.

However, how do I identify and compare them later?


How each set of orders are placed:

string sNumber=DoubleToStr(SequenceNumber(),0);
int ticket=OrderSend(Symbol(),OP_BUY,LotSize,MarketInfo(Symbol1,MODE_ASK),3,0,0,sNumber,12345,0,Green)
&   ticket=OrderSend(Symbol(),OP_SELL,LotSize,MarketInfo(Symbol2,MODE_ASK),3,0,0,sNumber,12345,0,Red);


i.e. I trade in pair, Order 1 & 2, then Order 3 & 4, and so on....

Order 1 - Sequence #1

Order 2 - Sequence #2

Order 3 - Sequence #3

Order 4 - Sequence #4

Order 5 - Sequence #5

Order 6 - Sequence #6


Now that they have unique sequence number that increment,

How do I select them and compare?

I would like to select and compare

Order 1 & 2, then Order 3 & 4, then Order 5 & 6, and so on ...


Thanks in advance!



avatar
74
johnnybegoode 2010.12.27 23:38edit | delete

... Continued from above reply


Or maybe I could control when the sequence number would increase?

i.e. after each set of orders? Like after 2 orders.

So when selecting and comparing, I could just select orders with the same sequence number.

How to code that?


Thanks!