How can I integrated two strategy in one EA?

 

Hi!

I have two strategy in two EA, but I can't inegrated in one EA, because I can't use the correct OrderSelect(). If i have 2 opened trade (1-1 strategy open 1-1 trade) I don't close 2 tarde. Only one and i have error. Invaild ticket. I use "for" and select all opened trade and use magic number, but if I close 1 trade never close the second. I use one currency and one timeframe. Please help me! Thanks.

 

This code is ok: (close 2 opened trade)

...

...

...

CloseAllOrdB(111);



return(0);

}
}

void CloseAllOrdB(int magic)
{

double MAShort=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
double MALong=iMA(NULL,0,100,0,MODE_SMA,PRICE_CLOSE,0);

RefreshRates();
int total = OrdersTotal();
for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == magic)
if(IsTradeContextBusy()) Sleep(1000);
if(IsTradeContextBusy()) Sleep(2000);



if(OrderType()==OP_BUY){
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);elso=0; time=Time[0];}



}

}

BUT this is not OK! Not close the trade!!!!!! (2 opened trade)

...

...

...

CloseAllOrdB(111);




return(0);

}
}

void CloseAllOrdB(int magic)
{

double MAShort=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
double MALong=iMA(NULL,0,100,0,MODE_SMA,PRICE_CLOSE,0);

RefreshRates();
int total = OrdersTotal();
for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == magic)
if(IsTradeContextBusy()) Sleep(1000);
if(IsTradeContextBusy()) Sleep(2000);



if(OrderType()==OP_BUY && MAShort <= MALong){
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);elso=0; time=Time[0];}



}

}

Why????????? I don't understand this!

 

for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
.

.

.

Change to

for (int cnt = OrdersTotal()-1 ; cnt >= 0 ; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);

 
Thank you so much. I could upload 3 trade allow EA to Championship 2008!
Reason: