How to create a Magic Number array? - page 3

 
I would like a separate number for buy orders and sell orders is that possible?
 
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.

How can I find an order by comment & magic number?

I have 15 triggers

i don't want a standard lets say        TP 200  SL 300

each currency pair will have a different TP and SL Depending on statistics of the trigger

if a higher probability trigger comes i want to identify it and take action  

trigger1 eur/usd  100  prob: 94%, usd/jpy 300  prob:74%  eur/jpy 200 prob.100%

if trigger 1 traded for one of the pairs eur/usd  no more trading for that pair for that trigger

i still want to trade for trigger2 trigger3 and (trigger1  just different pair)

 

y not

int MagicNoBuy  = 12345;
int MagicNoSell = 67890;

OrderSend(Symbol(),OP_BUY,1,Ask,......,MagicNoBuy ,.,..);
OrderSend(Symbol(),OP_SELL,1,Bid,......,MagicNoSell,.,..);
 
you don't need separate magic for buy and sell, you can easily filter them with OrderType()
 
7bit:
you don't need separate magic for buy and sell, you can easily filter them with OrderType()


thank you for your help 

 
7bit:
you don't need separate magic for buy and sell, you can easily filter them with OrderType()
and you can filter out the currency pairs with OrderSymbol()
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)             // Only my orders w/
&&  OrderMagicNumber() == Magic.Number          // my magic number
&&  OrderSymbol()      == Symbol() ){           // and period and symbol
 

I use a RANGE of magic numbers, so I can use different SL methods for trades.

e.g. MAGIC_NUMBER_BASE = 1234500

& then use 'offset' of 0-99 to groups my trades by SL type. I then use code like

      if(OrderMagicNumber() < MY_MAGIC_LO || OrderMagicNumber() > MY_MAGIC_HI)

to find my trades (actually that code is to EXCLUDE my trades!)

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

Thanks, I finally get to revisit this thread and is trying this out. 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!

 

... 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!

 
Why not use the unique ticket number you get when you use ordersend()?

Save Theese in an Array[][]


example.


Trade 1
TicketArray [1] [0] = Ticket0;
TicketArray [1] [1] = Ticket1;

Trade 2
TicketArray [2] [0]
TicketArray [2] [1]

Trade 3
TicketArray [3] [0]
TicketArray [3] [1]

... And so on