实现收盘前平仓、开盘后延时开仓(代码共享)
Params
Numeric ExitCloseSecs(300); //收盘前N秒离场(300秒)
Numeric OpenCloseSecs(300); //开盘后N秒交易(300秒)
Vars
Bool 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("收盘平仓");
}
}
你有什么问题吗