我写的止损程序代码在回测的时候不触发什么原因,请老师给指点一下

If(CurrentPosition != 0) { Numeric stopPrice; Bool needStop(False); Numeric triggerPrice; If(CurrentPosition == 1) // 多单止损检查 { // 精确止损价计算(含4位小数) stopPrice = Round(AvgLongPrice * (1 - 0.006),4); // 改进触发逻辑:考虑盘中价格波动 If(Low <= stopPrice) { needStop = True; // 确定实际触发价(考虑跳空情况) triggerPrice = IIF(Open < stopPrice, Open, Min(Close, stopPrice)); triggerPrice = Min(Low, triggerPrice); } }

CurrentPosition 你检查过吗?你代码贴的内容里,一个CurrentPosition 的赋值都没有CurrentPosition ==1 既然你判断这个,那么CurrentPosition 里有过是1吗

If(needStop) { // 优先执行止损 If(CurrentPosition == 1) { Sell(TotalLongLots, triggerPrice); CurrentPosition = 0; TotalLongLots = 0; AvgLongPrice = 0; }