Expiration

 
I wrote this expert that I just can’t get to know how to make the pending order to expire at the same day for each day at certain hour if the market didn’t reach the price that I have set.

extern double Lots = 0.1;
extern double Limits = 35;
extern double TakeProfit = 35;
extern double StopLoss = 25;

int start()
{
int cnt, ticket, total;
int StartHour = TimeHour(CurTime());
int StartMinute = TimeMinute(CurTime());
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}

total=OrdersTotal();
if(total<1)
{
if(AccountFreeMargin()<(100*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if(StartHour == 14 && StartMinute == 25)
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Limits*Point,0,(Ask+Limits*Point)-StopLoss*Point,(Ask+Limits*Point)+TakeProfit*Point,"Buy",0,0,White);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
}
}
 
The OrderSend has a parameter to give the expiration date. it is the one before the color. For calculation see the example in this thread: "OrderExpiration with Ordersend..."

cori
Reason: