View Single Post
  #6 (permalink)  
Old 03-29-2008, 02:09 PM
mikkom mikkom is offline
Senior Member
 
Join Date: Oct 2007
Posts: 190
mikkom is on a distinguished road
Quote:
Originally Posted by MiniMe View Post
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
Okay now I get your point.. If you don't mind using a big array..

Code:
#define MAX_MAGIC_NUMBER 100 // or whatever

void closeProfitable(int tpPips, int magic) {
   double profit[MAX_MAGIC_NUMBER];
   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) 
           profit[OrderMagicNumber()] += oBid - OrderOpenPrice();
        if(OrderType() == OP_SELL) 
           profit[OrderMagicNumber()] += OrderOpenPrice() - oAsk;

   }
   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(profit[OrderMagicNumber()] >= tpPips*Point) {
            if(OrderType() == OP_BUY) {
               OrderClose(OrderTicket(),OrderLots(),oBid,0);
               i--;               
            }
            if(OrderType() == OP_SELL) {
               OrderClose(OrderTicket(),OrderLots(),oAsk,0);
               i--;               
            }
        }
}
same disclaimers as above, I didn't test this at all
Reply With Quote