Download MetaTrader 5
To add comments, please log in or register
MQL5 library has more than 1500 apps already. Contribute your own one!
mrgoodprice144
42
mrgoodprice144 2016.04.07 15:27 

I 'm looking a way to close my open order by a certain amount of profit is it possible ?? or do i have to close my open order only when the price is above the orderPrice ?? here is my code that close an open order:

 for(PositionIndex=TotalNumberOfOrders-1; PositionIndex>=0; PositionIndex --)
     {

                                      if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES))

         if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()=="EURUSD" && (ticket1==OP_BUY || ticket2==OP_SELL))//
              
               
                                      if(OrderType()==OP_SELL   )//SELL ORDER On Positif TRADE

                                      if(!OrderClose(ticket2,0.01,Bid-Price*Point ,clrNONE))


                 Print("Order Close failed, order number: ",ticket2," Error: ",GetLastError());
         
                                      if(OrderType()==OP_BUY   )//BUY ORDER On Positif TRADE

                                      if(!OrderClose(ticket1,0.01,Ask+Price*Point,5,clrNONE))
            
          
                 Print("Order Close failed, order number: ",ticket1," Error: ",GetLastError());
            
 
            
     }
sokramm
49
sokramm 2016.04.08 16:44  
Are you asking about a Take Profit order? If you isse an OrderClose request, you have to use current market value. Something different is a Limit order. Not sure what you are asking about...
mrgoodprice144
42
mrgoodprice144 2016.04.08 18:14  
Well let say when my BUY pending order is hit at 1.1373 EURUSD  and i want my EA to close that order at 1.1378 that is what i'm talking about.
whroeder1
13641
whroeder1 2016.04.08 19:11  
These will not work. You can only close an order at current market price.
if(!OrderClose(ticket2,0.01,Bid-Price*Point ,clrNONE))
if(!OrderClose(ticket1,0.01,Ask+Price*Point,5,clrNONE))
i want my EA to close that order at 1.1378
When you open the order, set the TP at that price and it will close itself.
/
To add comments, please log in or register