该函数在到达设定时间后执行平仓。过滤条件:货币对、订单类型、平仓开始时间。
- total=OrdersTotal();
- for(cnt=0;cnt<total;cnt++)
- {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- if(OrderType()<=OP_SELL && // check for opened position
- OrderSymbol()==Symbol()) // check for symbol
- {
- if(OrderType()==OP_BUY) // long position is opened
- {
- // should it be closed?
- if(total>0 && Hour()==22 && Minute()>45)
- {
- OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
- return(0); // exit
- }
- }
- else // go to short position
- {
- // should it be closed?
- if(total>0 && Hour()==22 && Minute()>45)
- {
- OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
- return(0); // exit
- }
- }
- }
- }
|