View Single Post
  #3 (permalink)  
Old 03-29-2008, 01:56 PM
mikkom mikkom is offline
Senior Member
 
Join Date: Oct 2007
Posts: 189
mikkom is on a distinguished road
Quote:
Originally Posted by MiniMe View Post
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

Last edited by mikkom; 03-29-2008 at 01:58 PM.
Reply With Quote