延迟发单回测有交易信号,实盘模拟的时候不能发出委托单

老师麻烦帮忙看下,这段代码回测的时候有交易信号,但实盘模拟的时候不能发委托单,是错在哪里、该怎样修改呢?

老师,请教一下还有其他延迟发单方法吗?

老师,请问下这个问题有办法解决吗?

问题还没解决,顶上去

老师,我把延迟发单改为定时发单,测试还是只有信号,不能发单,您看下是不是我这样改不行Params Numeric FastLength(20); // 短期指数平均线参数 Numeric SlowLength(80); // 长期指数平均线参数 Numeric StopLevelAdjustment(15); // 止损跳数 Numeric delayTicksParam(2000); // tick 数参数Vars Series<Numeric> AvgValue1(0); // 短期指数平均线 Series<Numeric> AvgValue2(0); // 长期指数平均线 Series<Numeric> VarA; // 记录开仓时特定价格 Bool isScheduledBuy; // 标记是否已安排买入 Bool isScheduledSell; // 标记是否已安排平仓 Numeric scheduledBuyTime; // 记录计划买入的时间 Numeric scheduledSellTime; // 记录计划平仓的时间 Numeric delayCounter; Numeric tickCount; Events OnReady() { SetBackBarMaxCount(1 + FastLength + SlowLength); isScheduledBuy = False; isScheduledSell = False; delayCounter = 0; tickCount = 0; } OnBar(ArrayRef<Integer> indexs) { // 计算短期和长期指数平均线 AvgValue1 = AverageFC(Close, FastLength); AvgValue2 = AverageFC(Close, SlowLength); // PlotNumeric(\"stopLossLevel\", stopLossLevel, 0, RGB(128,0,128)); // PlotNumeric(\"VarA\", VarA, 0, RGB (139,0,0)); // 开仓条件,设置 Enum_Signal_NotSend 标志 if (MarketPosition == 0 && AvgValue1[1] > AvgValue2[1]) { Buy(1, Open, Enum_Signal_NotSend); VarA = Open - StopLevelAdjustment * MinMove * PriceScale; // 记录开仓时开仓价下跌指定跳数的价格 } // 止损条件,设置 Enum_Signal_NotSend 标志 if ((MarketPosition == 1 && Close[1] < VarA[1] && BarsSinceEntry>0) || (MarketPosition == 1 && AvgValue1[1] < AvgValue2[1])) { Sell(1, Open, Enum_Signal_NotSend); } } OnSignal(ArrayRef<Signal> sigs) { Integer i = 0; For i = 0 To GetArraySize(sigs) - 1 { SignalRef sig = sigs[i]; // 检查是否是带有 Enum_Signal_NotSend 标志的买入信号 if (BitHas(sig.flag, Enum_Signal_NotSend) && sig.side == Enum_Buy) { isScheduledBuy = True; scheduledBuyTime = tickCount + delayTicksParam; } // 检查是否是带有 Enum_Signal_NotSend 标志的平仓信号 else if (BitHas(sig.flag, Enum_Signal_NotSend) && sig.side == Enum_Sell) { isScheduledSell = True; scheduledSellTime = tickCount + delayTicksParam; } } // 处理定时发单 if (isScheduledBuy && tickCount >= scheduledBuyTime) { Buy(1, Open); isScheduledBuy = False; } if (isScheduledSell && tickCount >= scheduledSellTime) { Sell(1, Open); isScheduledSell = False; } }

我觉得是逻辑不对,你延迟后设置了一个时间tick数但是signal又不会再触发的这个逻辑在用定时器应该可以

回复:老师,那该怎样改比较好呢?OnSignal收集信号后,再用定时器吗?

老师,这段代码有交易信号,实测不能发委托单有测试吗?

Params Numeric FastLength(20); // 短期指数平均线参数 Numeric SlowLength(80); // 长期指数平均线参数 Numeric StopLevelAdjustment(15); // 止损跳数 Numeric delayTicksParam(2000); // 延迟的 tick 数参数Vars Series<Numeric> AvgValue1(0); // 短期指数平均线 Series<Numeric> AvgValue2(0); // 长期指数平均线 Series<Numeric> VarA; // 记录开仓时特定价格 Bool isScheduledBuy; // 标记是否已安排买入 Bool isScheduledSell; // 标记是否已安排平仓 Numeric scheduledBuyTime; // 记录计划买入的时间 Numeric scheduledSellTime; // 记录计划平仓的时间 Numeric delayCounter; Numeric tickCount; Events OnReady() { SetBackBarMaxCount(1 + FastLength + SlowLength); isScheduledBuy = False; isScheduledSell = False; delayCounter = 0; tickCount = 0; } OnBar(ArrayRef<Integer> indexs) { // 计算短期和长期指数平均线 AvgValue1 = AverageFC(Close, FastLength); AvgValue2 = AverageFC(Close, SlowLength); // 开仓条件,设置 Enum_Signal_NotSend 标志 if (MarketPosition == 0 && AvgValue1[1] > AvgValue2[1]) { Buy(1, Open, Enum_Signal_NotSend); VarA = Open - StopLevelAdjustment * MinMove * PriceScale; // 记录开仓时开仓价下跌指定跳数的价格 } // 止损条件,设置 Enum_Signal_NotSend 标志 if ((MarketPosition == 1 && Close[1] < VarA[1] && BarsSinceEntry>0) || (MarketPosition == 1 && AvgValue1[1] < AvgValue2[1])) { Sell(1, Open, Enum_Signal_NotSend); } } OnSignal(ArrayRef<Signal> sigs) { Integer i = 0; For i = 0 To GetArraySize(sigs) - 1 { SignalRef sig = sigs[i]; // 检查是否是带有 Enum_Signal_NotSend 标志的买入信号 if (BitHas(sig.flag, Enum_Signal_NotSend) && sig.side == Enum_Buy) { isScheduledBuy = True; scheduledBuyTime = tickCount + delayTicksParam; } // 检查是否是带有 Enum_Signal_NotSend 标志的平仓信号 else if (BitHas(sig.flag, Enum_Signal_NotSend) && sig.side == Enum_Sell) { isScheduledSell = True; scheduledSellTime = tickCount + delayTicksParam; } } // 处理延迟计数器 if (isScheduledBuy) { if (tickCount < scheduledBuyTime) { delayCounter = delayCounter + 1; } else if (tickCount >= scheduledBuyTime) { Buy(1, Open); isScheduledBuy = False; delayCounter = 0; } } if (isScheduledSell) { if (tickCount < scheduledSellTime) { delayCounter = delayCounter + 1; } else if (tickCount >= scheduledSellTime) { Sell(1, Open); isScheduledSell = False; delayCounter = 0; } } }

回复:我试下

发错代码了,上面这份没有信号,下面这份才是

建议发完整代码,我可以测试到底能不能下

回复:好的老师Params Numeric BollLength(20); //布林周期 Numeric Offset(2); //标准差倍数 Numeric StopLevelAdjustment(15); // 止损跳数 Numeric delayTicksParam(2000); // 延迟的 tick 数参数 Vars Series<Numeric> UpLine; //上轨定义为序列变量 Series<Numeric> DownLine; //下轨定义为序列变量 Series<Numeric> MidLine; //中间线 Series<Numeric> Band; Series<Numeric> VarA; // 记录开仓时特定价格 Series<Numeric> stopLossLevel;//记录开仓时前一个BAR的最低价 Bool isScheduledBuy; // 标记是否已安排买入 Bool isScheduledSell; // 标记是否已安排平仓 Numeric scheduledBuyTime; // 记录计划买入的时间 Numeric scheduledSellTime; // 记录计划平仓的时间 Numeric delayCounter; Numeric tickCount; // 声明 tickCount 变量 Events OnReady() { // 不再需要设置回溯的最大 Bar 数量 isScheduledBuy = False; isScheduledSell = False; delayCounter = 0; tickCount = 0; } OnBar(ArrayRef<Integer> indexs) { // 计算布林通道相关值 MidLine = AverageFC(Close, BollLength); Band = StandardDev(Close, BollLength, 2); UpLine = MidLine + Offset * Band; DownLine = MidLine - Offset * Band; // 绘制指线 PlotNumeric(\"DownLine\", DownLine); PlotNumeric(\"UpLine\", UpLine, 0, RGB (153,102,0)); PlotNumeric(\"stopLossLevel\", stopLossLevel, 0, RGB(128,0,128)); PlotNumeric(\"VarA\", VarA, 0, RGB (139,0,0)); // 开仓条件,设置 Enum_Signal_NotSend 标志 if (MarketPosition == 0 && Low[1] < DownLine[1] && Close[1] > DownLine[1] && Close[1] > Open[1]) { Buy(1, Open, Enum_Signal_NotSend); VarA = Open - StopLevelAdjustment * MinMove * PriceScale; // 记录开仓时开仓价下跌指定跳数的价格 stopLossLevel = Low[1]; // 记录开仓时前一个 BAR 的最低价 } // 止损条件,设置 Enum_Signal_NotSend 标志 if (MarketPosition == 1 && Close[1] < VarA[1] && BarsSinceEntry>0) { Sell(1, Open, Enum_Signal_NotSend); } } OnSignal(ArrayRef<Signal> sigs) { Print(\"OnSignal:\" + TextArray(sigs)); Integer i = 0; For i = 0 To GetArraySize(sigs) - 1 { SignalRef sig = sigs[i]; // 检查是否是带有 Enum_Signal_NotSend 标志的买入信号 if (BitHas(sig.flag, Enum_Signal_NotSend) && sig.side == Enum_Buy) { isScheduledBuy = True; scheduledBuyTime = tickCount + delayTicksParam; } // 检查是否是带有 Enum_Signal_NotSend 标志的平仓信号 else if (BitHas(sig.flag, Enum_Signal_NotSend) && sig.side == Enum_Sell) { isScheduledSell = True; scheduledSellTime = tickCount + delayTicksParam; } } // 处理延迟计数器 if (isScheduledBuy) { if (tickCount < scheduledBuyTime) { delayCounter = delayCounter + 1; } else if (tickCount >= scheduledBuyTime) { Buy(1, Open); isScheduledBuy = False; delayCounter = 0; } } if (isScheduledSell) { if (tickCount < scheduledSellTime) { delayCounter = delayCounter + 1; } else if (tickCount >= scheduledSellTime) { Sell(1, Open); isScheduledSell = False; delayCounter = 0; } } }