Limit Opening Orders per Pair

 
I've got an EA that I am trading on 4 pair. I know by using OrderTotal I can restrict the number of orders opened at a give time, so I have it setup so only 1 order can be opened at a time. How can I set it up so that 1 order can be opened PER PAIR?
 
I imagine I would use . Search open orders for OrderSymbol and if there is more than 0 found quit.
 
mixtermind wrote >>
I've got an EA that I am trading on 4 pair. I know by using OrderTotal I can restrict the number of orders opened at a give time, so I have it setup so only 1 order can be opened at a time. How can I set it up so that 1 order can be opened PER PAIR?

show your code

inkuumba

 
void fbuy (string path)
{
int total=OrdersTotal();
if(total<1)
{
int ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Ask-30*Point,Ask+15*Point,"Buy",255,0,Green);
if(ticket<1)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
return;
}
OrderPrint();
}
}

return(0);

}
 

Each EA will be unique for each pair, so can I check if OrderSymbol = eurusd or something.


What I've got from the library is this:


if(OrderSelect(12, SELECT_BY_POS)==true)
Print("symbol of order #", OrderTicket(), " is ", OrderSymbol());
else
Print("OrderSelect failed error code is",GetLastError());


This searches a single order, how do you search ALL orders?

 

Basically I need a one or two liner that will search all open buy orders:

OP_BUY0Long position

for the current symbol (the symbol for the chart the EA is currently on) and then output this as a number.


The following code does something similar, which will help in future development, but not quite right. This code will search all long positions and then perform some action on them. I'm not looking to do anything with the orders just check to see if there are any there.

int pos;
for (pos=0; pos=OP_BUY)
{
// order proves to be long; we will check the instrument
if (OrderSymbol()==Symbol())
{
// perform some actions with the order
// ...
}
}
}
else
Print("Error ", GetLastError(), " at selecting order number ", pos);
 
This code is taken from Stairs_Pack_v2 in the repository.

int
GetOrdersCount(int MagicNumber = -1, int Type = -1, string symb = "")
{
int count = 0;

for(int i = 0; i < OrdersTotal(); i++)
{
// already closed
if(OrderSelect(i, SELECT_BY_POS) == false) continue;
// not current symbol
if(OrderSymbol() != Symbol() && symb == "") continue;
// not specified symbol
if(OrderSymbol() != symb && symb != "" && symb != "all") continue;
// order was opened in another way
if(OrderMagicNumber() != MagicNumber && MagicNumber != -1) continue;

if(OrderType() == Type || Type == -1)
{
count++;
}
}

return (count);
}

void Check()
{
string name = Symbol() + StartLots;

if (!GlobalVariableCheck(CloseAll))
{
GlobalVariableSet(CloseAll, EMPTY_VALUE);
}
else
{
double value = GlobalVariableGet(CloseAll);

if (value == 1)
{
if (GetOrdersCount(Magic) > 0)
{
CloseSells(Magic, Slippage);
CloseBuys(Magic, Slippage);
DeletePending(Magic);
}
RefreshRates();

if (GetOrdersCount(Magic, -1, "all") == 0)
{
GlobalVariableSet(CloseAll, EMPTY_VALUE);
}
else
{
return;
}
}
}


 

I ended up with this, let me know if it looks ok. I'm going to try it once trading commences.


int GetOrdersCount(int Type = -1)
{
int count = 0;

for(int i = 0; i < OrdersTotal(); i++)
{
// already closed
if(OrderSelect(i, SELECT_BY_POS) == false) continue;
// not current symbol
if(OrderSymbol() != Symbol()) continue;

if(OrderType() == Type || Type == -1)
{
count++;
}
}

return (count);
}


int start()
{
//----

if (GetOrdersCount() == 0)
{
//Do whatever
}
return(0);
}

Reason: