View Single Post
  #4 (permalink)  
Old 04-27-2008, 01:19 PM
faizalperu faizalperu is offline
Junior Member
 
Join Date: Jan 2008
Posts: 3
faizalperu is on a distinguished road
Quote:
Originally Posted by firedave View Post
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
i've been searching for this code.....thanks firedave.

i have a small request....how to make the ea to stop trading when take profit is reached and start trading again next day.

thanks
Reply With Quote