Thread: Extend MQL!!
View Single Post
  #3 (permalink)  
Old 03-08-2006, 06:22 PM
Nicholishen's Avatar
Nicholishen Nicholishen is offline
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by 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);



...
...
}

Very Cool...Thanks!
Reply With Quote