该函数可以将订单在事先设置的时间段内平仓。如果不持仓过周末,那么则可以设定订单在周五晚上某个时间段平仓。
- if((TimeHour(CurTime()) < StartHour) || (TimeHour(CurTime()) >= EndHour) ||
- (DayOfWeek() == KillDay && TimeHour(CurTime()) == KillHour))
- {
-
- total = OrdersTotal();
- //----
- for(cnt = 0; cnt < total; cnt++)
- {// 3
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- //----
- if(OrderSymbol() == Symbol())
- { //4
- if(OrderType() == OP_BUY)
- { //5
- OrderClose(OrderTicket(),Lots,Bid,Slippage,Green);
- return(0);
- } //5
- //----
- if(OrderType() == OP_SELL)
- { //5
- OrderClose(OrderTicket(), Lots, Ask, Slippage, Green);
- return(0);
- } //5
- } //4
- } //3
- return(0);
- }
|