收盘价模型的收盘提前发单案例
1、原始策略是收盘价模型,ONBARCLOSE的事件机制。2、添加onbaropen的那段代码,即可实现收盘提前N秒发单。双均线收盘价模型的收盘提前5秒发单案例Params Numeric FastLength(5);// 短期指数平均线参数 Numeric SlowLength(20);// 长期指数平均线参数 Vars Series<Numeric> AvgValue1; Series<Numeric> AvgValue2; Events //每根BAR开始的时候设置触发时间点 OnBarOpen(ArrayRef<Integer> indexes) { Numeric advancesec(5); //提前多少秒 Array<Numeric> timePoint; Numeric ret = DateTimeAdd(RealEndDateTime, -1*advancesec); ret = StringToTime(TimeToString(ret)); Print("endtime="+text(RealEndDateTime)+" SetTriggerBarClose:" + Text(ret)); ArrayPushBack(timePoint, ret); SetTriggerBarClose(timePoint); } OnBarClose(ArrayRef<Integer> indexs) { AvgValue1 = AverageFC(Close,FastLength); AvgValue2 = AverageFC(Close,SlowLength); PlotNumeric("MA1",AvgValue1); PlotNumeric("MA2",AvgValue2); If(MarketPosition <>1 && AvgValue1 > AvgValue2) { Buy(0,Close); } If(MarketPosition <>-1 && AvgValue1 < AvgValue2) { SellShort(0,Close); } }