Quote:
Originally Posted by MiniMe
I need help please,
I am trying to close orders from different currency pairs ( long and short ) but with the same magic number when the profit reach define target " lets say 15 pips" without touching the other orders with different magic number
|
Here is some code that should work
Code:
void closeProfitable(int tpPips, int magic) {
for(i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderMagicNumber() != magic)
continue;
double oAsk = MarketInfo(OrderSymbol(), MODE_ASK);
double oBid = MarketInfo(OrderSymbol(), MODE_BID);
if(OrderType() == OP_BUY &&
oBid > OrderOpenPrice() + tpPips * Point) {
OrderClose(OrderTicket(),OrderLots(),oBid,0);
i--;
}
if(OrderType() == OP_SELL &&
oAsk < OrderOpenPrice() - tpPips * Point) {
OrderClose(OrderTicket(),OrderLots(),oAsk,0);
i--;
}
}
}
ps. that code is not tested, I wrote it to this post directly but it should work