**pengie:**

Before I start, I want to say this is a great forum and I wish to make my first contribution .

I noticed a lot of programmers are using OrdersTotal() to get the total number of orders in order to determine whether to open a new position or not. However, I feel that most of us may be running multiple EAs so using OrdersTotal() will actually prevent different EAs from working simultaneously. So I have written a short library with a few useful functions. If EA programmers use this library, multiple EAs will be able to co-exist.

The library contains the following functions:

**int CountOrdersIfMagic(int magicNumber);**

Get the total number of orders in the system with this magic number

**int CountOrdersIfMode(int cmd);**

Get the total number of orders in the system with this type of the operation. E.g. CountOrdersIfMode(OP_BUY) will get the total number of BUY orders in the system.

**int CountOrdersIfSymbol(string symbol);**

Get the total number of orders in the system with this symbol pair. E.g. CountOrdersIfMode("EURUSD") will get the total number of orders in the system for the EUR/USD pair.

**int CountOrders(string symbol="", int magicNumber=-1, int cmd=-1);**

This is the general function to get the total number of which fulfils the three given conditions. If the default value is used for a certain condition, that condition will not be used as a restricting condition for the CountOrders function.

**int GetFirstTicketByMagic(int magicNumber);**

**int GetFirstTicketByMode(int cmd);**

**int GetFirstTicketBySymbol(string symbol);**

**int GetFirstTicket(string symbol="", int magicNumber=-1, int cmd=-1);**

**int GetNextTicket();**

This series of GetFirstTickets and GetNextTicket function is to enable the programmer to iterate through all tickets which fulfils the different conditions. For example, if I want to iterate through all orders which have a certain magic number, 12345, I will do the following:

for (int ticket=GetFirstTicketByMagic(12345); ticket!=0; ticket=GetNextTicket())

{

OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);}...

...

Thanks a lot Pengie.

Before I start, I want to say this is a great forum and I wish to make my first contribution .

I noticed a lot of programmers are using OrdersTotal() to get the total number of orders in order to determine whether to open a new position or not. However, I feel that most of us may be running multiple EAs so using OrdersTotal() will actually prevent different EAs from working simultaneously. So I have written a short library with a few useful functions. If EA programmers use this library, multiple EAs will be able to co-exist.

The library contains the following functions:

int CountOrdersIfMagic(int magicNumber);Get the total number of orders in the system with this magic number

int CountOrdersIfMode(int cmd);Get the total number of orders in the system with this type of the operation. E.g. CountOrdersIfMode(OP_BUY) will get the total number of BUY orders in the system.

int CountOrdersIfSymbol(string symbol);Get the total number of orders in the system with this symbol pair. E.g. CountOrdersIfMode("EURUSD") will get the total number of orders in the system for the EUR/USD pair.

int CountOrders(string symbol="", int magicNumber=-1, int cmd=-1);This is the general function to get the total number of which fulfils the three given conditions. If the default value is used for a certain condition, that condition will not be used as a restricting condition for the CountOrders function.

int GetFirstTicketByMagic(int magicNumber);int GetFirstTicketByMode(int cmd);int GetFirstTicketBySymbol(string symbol);int GetFirstTicket(string symbol="", int magicNumber=-1, int cmd=-1);int GetNextTicket();This series of GetFirstTickets and GetNextTicket function is to enable the programmer to iterate through all tickets which fulfils the different conditions. For example, if I want to iterate through all orders which have a certain magic number, 12345, I will do the following:

for (int ticket=GetFirstTicketByMagic(12345); ticket!=0; ticket=GetNextTicket())

{

}

int GenerateMagicNumber(int seed, string symbol, int timeFrame);Generate a unique magic number based on a given seed, symbol and timeframe. The seed should preferrably not exceed 9999. E.g. int magic = GenerateMagicNumber(1234, Symbol(), Period());

string GenerateComment(string EAName, int timeFrame);Generate a unique comment based on the EA name and timeframe. E.g. string comment = GenerateComment("MyEA", Period());

---Updated on 9 March 2006 GMT 0100h.

Fixed some minor bugs

---Updated on 9 March 2006 GMT 0900h.

Added two new functions, GenerateMagicNumber and GenerateComment

---Todo list

Add functions for MM and TrailingStops.

Files: