Hi all again! I'm sorry to hassle you with questions that may stupid, but i need your help!
My problem is that i wanted to add an hedging subsystem in my EA (originally from coderguru),
so here is the point:
I have an order X if X goes under (e.g.) 25 pips i open order Y
so if was only one order "y" it is no problem because i can use a counter like this
PHP Code:
//+------------------------------------------------------------------+
//| FUNCTION : NUMBER OF ORDER BASE ON SYMBOL AND MAGIC NUMBER |
//| SOURCE : n/a |
//| MODIFIED : FIREDAVE |
//+------------------------------------------------------------------+
int subTotalTrade()
{
int
cnt,
total = 0;
for(cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber) total++;
}
return(total);
}
//+------------------------------------------------------------------+
//| FUNCTION : OPEN ORDER BASE ON SYMBOL AND MAGIC NUMBER |
//| SOURCE : n/a |
//| MODIFIED : FIREDAVE |
//+------------------------------------------------------------------+
string subCheckOpenTrade()
{
int
cnt = 0;
string
lasttrade = "None";
for(cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY ) lasttrade = "BUY";
if(OrderType()==OP_SELL) lasttrade = "SELL";
}
}
return(lasttrade);
}
and then limit to 1 the open order
like this
PHP Code:
//+------------------------------------------------------------------+
//| NEW TRADE - ENTRY |
//+------------------------------------------------------------------+
if(subTotalTrade()<1 && (BuyCondition || SellCondition ) && AllowEntry)
{
but in this way i can open only one hedging order so what about if
X closes Y still open
X1 goes -25 now i'd like to open Y1 order and i can't!
How can i solve this problem?