OrderExpiration with Ordersend...

 
Hello all. I would like to thank all who help people in this forum in advance. My problem is i am trying to set a Buystop order and it should only be active for 8 hours or Until 6:00. I am trying to figure out the Ordersend's Time Expiration area but cannot figure out the correct way. I have looked at other forums where someone sugested Curtime + 8 *3600 or something but taht does not work. It gives me an hour about "green is not a variable" like the time area was not complete or something. I have tried a couple of different ways of doing but am unsuccesful. Also a big bonus would be if this advisor could work with the backtester :). Thank you all very much for your time!



   
   double theHigh;
   int total;
   total = OrdersTotal();
  
   int startHour;
   
   int currentHour;
     
   currentHour = Hour();
   startHour = 9;
   
   
      
   theHigh = High[Highest(NULL,0,MODE_HIGH,15,15)];
   if (total < 1)
      {
         if  (currentHour == startHour) 
            {
               OrderSend(Symbol(),OP_BUYSTOP,1,theHigh+7*Point,3,theHigh,theHigh+14*Point,"Buying",16384,datetime expiration == Hour()+ 8;,Green);
              
            }
      }
 
       
 
Hi Cory,

You can build it using the CurTime() and add the necessary seconds. See the example:

/* ****************************************************************** */
/* DateTime test                                                      */
/* ------------------------------------------------------------------ */
/* Copyright and pricing                                              */
/*                                                                    */
/* This code was developed by coriFX 2005.                            */
/*                                                                    */
/* You can use this code to make money as much as you wish without    */
/* fee. If you have made your first million using my code, I would    */
/* ask you to send me 10%. contact me at { corifx at o2go dot de }.   */
/* I will send you the information for money transfer.                */
/*                                                                    */
/* ****************************************************************** */
extern int hoursToAdd   = 8;
extern int minutesToAdd = 0;

int start() {

    int      timeToAdd = ( hoursToAdd * 3600 ) + ( minutesToAdd * 60 );
    datetime now = CurTime();
    datetime then = now + timeToAdd;
    
    Print( "now: ", TimeToStr( now, TIME_DATE | TIME_MINUTES | TIME_SECONDS ),
           ", timeToAdd: ", timeToAdd, 
           ", then: ", TimeToStr( then, TIME_DATE | TIME_MINUTES | TIME_SECONDS ) );

    return( 0 );
}



regards, cori

 
Cory,

I have never used the expiry parameter in the OrderSend (so thanks cori) but the code below does the job (30 mins in this example). U will also need to test for 18:00.

regards..



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

           if ( ((CurTime()-OrderOpenTime()) > 1800) )   // 1800 is in seconds... 
              {
              OrderDelete(OrderTicket());
              }
       }
Reason: