订单在设定时间段平仓

楼主  收藏   举报   帖子创建时间:  2019-05-05 14:38 回复:0 关注量:923
该函数可以将订单在事先设置的时间段内平仓。如果不持仓过周末,那么则可以设定订单在周五晚上某个时间段平仓。

  1. if((TimeHour(CurTime()) < StartHour) || (TimeHour(CurTime()) >= EndHour) ||
  2. (DayOfWeek() == KillDay && TimeHour(CurTime()) == KillHour))
  3. {

  4. total = OrdersTotal();
  5. //----
  6. for(cnt = 0; cnt < total; cnt++)
  7. {// 3
  8. OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  9. //----
  10. if(OrderSymbol() == Symbol())
  11. { //4
  12. if(OrderType() == OP_BUY)
  13. { //5
  14. OrderClose(OrderTicket(),Lots,Bid,Slippage,Green);
  15. return(0);
  16. } //5
  17. //----
  18. if(OrderType() == OP_SELL)
  19. { //5
  20. OrderClose(OrderTicket(), Lots, Ask, Slippage, Green);
  21. return(0);
  22. } //5
  23. } //4
  24. } //3
  25. return(0);
  26. }
打赏