View Single Post
  #1 (permalink)  
Old 03-29-2008, 01:18 PM
MiniMe's Avatar
MiniMe MiniMe is offline
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,082
MiniMe is on a distinguished road
Red face Close orders with magic number at certain profit

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

so I wrote this code to check open trades and count the profit on trades with magic number 111
PHP Code:
//+------------------------------------------------------------------+
//|  check profitable positions with magic 111                       |
//+------------------------------------------------------------------+
for(cnt=OrdersTotal();cnt>=0;cnt--)
      {
         
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
         if( 
OrderMagicNumber()==111 )
            {
               if(
OrderType()==OP_BUY)
                  {
                     
CurrentProfitB+=Bid-OrderOpenPrice() ;
                  }
//if(OrderType()==OP_BUY)
               
if(OrderType()==OP_SELL)
                  {
                     
CurrentProfitS+=OrderOpenPrice()-Ask;
                 }
//if(OrderType()==OP_SELL)
            
//if( OrderSymbol()==Symbol1 && OrderMagicNumber()==111 ) 
          
CurrentProfit=CurrentProfitB+CurrentProfitS;    
       }
// for(cnt=OrdersTotal();cnt>=0;cnt--)        

//====================== 
then I check if we make profit
PHP Code:
// Did we make a profit
//======================
if(profit>&& CurrentProfit>=(profit*Point))
  {
   while(
true)
     {
      
CloseAllOrd(111);               
     }
//while
  
}//if(profit>0 && CurrentProfit>=(profit*Point)) 
if we make a profit I call the function CloseAllOrd
PHP Code:
//+------------------------------------------------------------------+
//|                              Close all                           |
//+------------------------------------------------------------------+
void CloseAllOrd(int magic)
{
      
RefreshRates();
      
int total  OrdersTotal();
      for (
int cnt cnt total cnt++)
      {
         
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
         if (
OrderMagicNumber() == magic)
         if(
IsTradeContextBusy()) Sleep(1000);
         if(
IsTradeContextBusy()) Sleep(2000);
         
            if(
OrderType()==OP_BUY)
             
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White);
            if(
OrderType()==OP_SELL)   
             
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White);
      } 


however this will only close EURUSD after it reach 1 pip of profit sometimes 2

I need to close all orders( different currency pairs ) with magic number 111 at lets say 15 pips of profit , without touching other orders

can someone please help me
__________________
Risk comes from not knowing what you're doing
Be fearful when others are greedy and greedy when others are fearfulWarren Buffett
Reply With Quote