Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2006, 05:13 AM
Junior Member
 
Join Date: Mar 2006
Posts: 7
Chewbaca is on a distinguished road
Question TakeProfit & Stop Trading

How would you code a routine that would say the following;

If TakeProfit reaches 50 pips

Close the order

Stop trading
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2006, 05:36 AM
firedave's Avatar
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 05:46 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-16-2006, 06:02 AM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 693
Kalenzo is on a distinguished road
Ye, this is the main rule

Bid-OrderOpenPrice()>=Point*TP
OrderOpenPrice()-Ask>=Point*TP


Good code
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-27-2008, 12:19 PM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Place order with no takeprofit cardio Setup Questions 2 01-30-2006 05:32 PM


All times are GMT. The time now is 12:16 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.