View Single Post
  #2 (permalink)  
Old 04-16-2006, 06:36 AM
firedave's Avatar
firedave firedave is offline
Senior Member
 
Join Date: Nov 2005
Location: Jakarta, Indonesia
Posts: 416
firedave is on a distinguished road
Exclamation

Hi Chewbaca, maybe you could try something like this :

Code:
extern int
         TP             = 50,
         magic          = 1234,
         Sleeping       = 1800000; // 30 x 60 x 1000
bool 
         AllowTrade     = true;

int init()
{
   return (0);
}

int deinit()
{
   return (0);
}

int start()
{
   int cnt;
         
   if(!AllowTrade)
   {
      // after reach TP, it will wait for 30 minutes before the EA start to active again
      if(Sleeping>0)
      {
         Sleep(Sleeping);
         AllowTrade=true;
         return(0);
      }
      
      // if Sleeping set to 0, it will stop the EA for doing other command after reach TP
      return(0);
   }

   for(cnt=0;cnt<OrdersTotal();cnt++)
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

      if(OrderType()<=OP_SELL &&
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==magic)
      {
         if(OrderType()==OP_BUY)   // buy position is opened   
         {
            if(Bid-OrderOpenPrice()>=Point*TP)
            {
               OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
               AllowTrade=false;
               return(0);

            }
         }            
         if(OrderType()==OP_SELL)   // sell position is opened   
         {
            if(OrderOpenPrice()-Ask>=Point*TP)
            {
               OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
               AllowTrade=false;
               return(0);
            }
         }
      }
   }

// put your entry etc. here
//
//
//-------------

   return (0);
}
Don't set TP for your entry and let this code close the trade for you if the TP reach. Hope this help
__________________
David Michael H
"Trader helps traders with sincerity, honesty and integrity"

Last edited by firedave; 04-16-2006 at 06:46 AM.
Reply With Quote