HELP NEEDED.....

 
if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&& OrderMagicNumber()==MagicNumber21 && OrderProfit() >= 38)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
break;
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
break;
}
}

}


could someone please help me here!? the above code works well but essentially it closes ALL buy or sell orders. I want it to close only the order corresponding to magicnumber 21 and then one other one order with a different magicnumber....how can i accomplish this? i am running multiple ea's and don't want this piece of code closing any other system generated trades. any help would be greatly apprreciated! Thankyou all. daniel

 

Try without this: OrderSelect(i, SELECT_BY_POS);

The first one is all you should need. try with that commented out.

 
circlesquares:

Try without this: OrderSelect(i, SELECT_BY_POS);

The first one is all you should need. try with that commented out.

That did it! ...and I managed to get my other order removed without harming all others...thanks!!! Daniel