收盘前平仓、延时开仓(代码共享)
实现收盘前平仓、开盘后延时开仓(代码共享)ParamsNumeric ExitCloseSecs(300); //收盘前N秒离场(300秒)Numeric OpenCloseSecs(300); //开盘后N秒交易(300秒)VarsBool EntryTrading; //判断开仓时间段Bool ExitUnTrading; //判断平仓时间段 OnBar(ArrayRef<Integer> indexs) {//开盘前延时开仓时间EntryTrading = DateTimeDiff(Date+Time,TradingCloseDateTime(Symbol, Date+Time)) < OpenCloseSecs;//收盘前平仓时间ExitUnTrading = DateTimeDiff(Date+Time,TradingCloseDateTime(Symbol, Date+Time)) < ExitCloseSecs;//延时开仓 If (ExitUnTrading == False ) { buy(1,0) Commentary("开盘延时开仓"); }//收盘时间平仓 If( ExitUnTrading) { Sell(0 , 0); Commentary("收盘平仓"); } }