
03-29-2008, 02:02 PM
|
 |
Senior Member
|
|
Join Date: Nov 2006
Location: Montréal
Posts: 1,172
|
|
Yes but that would close trades on profit , I am looking at the combined trades menaing that EURUSD could be in 30pips+ and USDCHF could be in -15 pips so I look at the overall profit of trades with magic number 111 if the total profit from all those trades reach 15 pips I close all orders of magic number 111 only at combined profit of 15 pips
Quote:
Originally Posted by mikkom
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
|
__________________
“Risk comes from not knowing what you're doing”
“Never argue with an idiot. They drag you down to their level then beat you with experience”
|