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 03-17-2006, 06:04 PM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
How to close an open order after X hours?

How do I close opened order after "X" hours? I can use expiration=X to close pending orders, but how can I close active positions after X hours that they have been opened. I have multiple simultaneous orders and open positions that open based on stop prices placed at various levels and they are triggered off at various times.

Hope some of the gurus can help me.

Maji
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-17-2006, 10:05 PM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by Maji
How do I close opened order after "X" hours? I can use expiration=X to close pending orders, but how can I close active positions after X hours that they have been opened. I have multiple simultaneous orders and open positions that open based on stop prices placed at various levels and they are triggered off at various times.

Hope some of the gurus can help me.

Maji
You could insert this function into your code.
PHP Code:
extern int MaxHours=3;
int YOUR_MAGIC_NUMBER_VARIABLE_HERE=298374;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   
return(0);
  }
  

void AfterHours(){
   for(
int i=0;i<OrdersTotal();i++){
      if(
OrderSelect(i,SELECT_BY_POS)){
         if(
OrderSymbol()==Symbol() && OrderMagicNumber()== YOUR_MAGIC_NUMBER_VARIABLE_HERE){
            if(
CurTime() - OrderOpenTime() > MaxHours * (60 60) ){
               if(
OrderType()==OP_BUY){
                  
OrderClose(OrderTicket(),OrderLots(),Bid,2,Red);
               }
               if(
OrderType()==OP_SELL){ 
                  
OrderClose(OrderTicket(),OrderLots(),Ask,2,Red);
               }
            }
         }
      }
   }
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
AfterHours();
//----
   
return(0);
  } 
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-18-2006, 01:14 AM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
Thank you very much
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 Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EA to close all open order of GBPJPY hedge4x Expert Advisors - Metatrader 4 3 12-22-2007 02:34 PM
Open/close trade on same bar's close? WNW Expert Advisors - Metatrader 4 2 03-29-2007 05:37 AM
Open a new order !! ammar Expert Advisors - Metatrader 4 14 09-18-2006 05:34 PM
Close All Order when Profit.... FXfish Metatrader 4 1 08-15-2006 03:43 PM


All times are GMT. The time now is 07:53 AM.



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