Newbie question RE datetime expiration

 

Hi,

Just a quick question, I am trying to add an expiration time on a buy script. I have added the line extern datetime Expiration = 0; to my script which is ok but is there a way i can make the order expire at 9.00pm on the day that the order was placed rather than having to manually input the date and time every time when i launch the script?


Thanks in advance guys any info would be greatly appreciated.


Paul

 
You compute 9PM
   #define HR2400 86400 // PERIOD_D1 * 60 = 24 * 3600
int    time(datetime when=0){
   return int((when == 0) ? TimeCurrent() : when) % HR2400;  }
datetime   date(datetime when=0){
   return ((when == 0) ? TimeCurrent() : when) - time(when); }
/////////
datetime bod = date();   // Midnight
#define HR2100 75600     // 9PM = 2100
datetime expiration = bod + HR2100;
 

Hi, Thanks for the reply.

You will have to forgive me as this is the first time i am trying to mess with scripting, I downloaded the following script and added the following line extern datetime Expiration = 0; this gave me the option to set an expiry for the order which i had to set manually each time when i ran the script

how would I add the code you gave me so it would have a default expiration time of 21.00?


thanks again!


Paul

//+------------------------------------------------------------------+
//|                                              Buy  with SL and TP |
//|                               Copyright © 2008, smjones          |
//|                                               sjcoinc            |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, smjones"
#property link      "sjcoinc2000@yahoo.com"


#property show_inputs

extern int    NumberOfOrders = 1;
extern bool   UseActualSlTp = true;
extern double StopLossPrice = 0.0000;
extern double TakeProfitPrice = 0.0000;
extern string Note="0 in Entry field means Market Order Buy";
extern double Entry = 0.0000;
extern bool   MicroOrdersAllowed = true;
extern bool   MiniOrdersAllowed = true;

extern bool   UseMoneyMgmt = true;
extern double RiskPercent = 1;
extern double Lots = 1;
extern double StopLoss = 0;
extern double TakeProfit = 0;
extern datetime Expiration = 0;

extern string Comments = "Buy Script";



//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  { 
  double Risk = RiskPercent / 100;
  int OrdersizeAllowed = 0;
  int Mode = OP_BUYSTOP;
  if (Ask > Entry && Entry > 0) Mode = OP_BUYLIMIT; 
  if (Entry == 0)  {Entry = Ask; Mode = OP_BUY;}
  double SLB = Entry - StopLoss*Point, TPB = Entry + TakeProfit*Point;

  if (UseActualSlTp)
      {
         StopLoss = (Entry-StopLossPrice)/Point;
         SLB = StopLossPrice;
         TPB = TakeProfitPrice;    
      }
  if (MiniOrdersAllowed) OrdersizeAllowed=1;
  if (MicroOrdersAllowed) OrdersizeAllowed=2;        
  if (UseMoneyMgmt)  
      Lots = NormalizeDouble( AccountBalance()*Risk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),OrdersizeAllowed);       

  if ((Lots < 0.01&&MicroOrdersAllowed) || (Lots < 0.1&&MiniOrdersAllowed&&MicroOrdersAllowed==false))
      {
         Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");
      } 

  if(Lots > 0)
  for (int i=0;i<NumberOfOrders;i++)
      {
         OrderSend(Symbol(),Mode, Lots, Entry, 2,SLB , TPB, Comments, 0, NULL, LimeGreen);
      }

           
   return(0);
  }
//+------------------------------------------------------------------+
 
paulpeno: how would I add the code you gave me so it would have a default expiration time of 21.00?
Cut and paste.