我代码是突破前高就多,跌破前高就空,平仓也是这个逻辑,为什么会闪烁啊?有大佬帮忙看看分析一下吗

Params Numeric MA25Length(59); Numeric StopLength(1); Numeric Lots(1); Numeric RangePeriod(2); Numeric RangeRate(0.014); Vars Numeric MinPoint; Series<Numeric> MA25; Series<Numeric> Highest5; Series<Numeric> Lowest5; Bool SendOrderThisBar; Numeric hh; Numeric ll; Numeric amplitude; Bool isRange; Numeric myEntryPrice; Numeric myExitPrice; Events OnBar(ArrayRef<Integer> indexs) { If(BarStatus == 0) { MA25 = InvalidNumeric; Highest5 = InvalidNumeric; Lowest5 = InvalidNumeric; } SendOrderThisBar = False; MinPoint = MinMove * PriceScale; MA25 = AverageFC(Close, MA25Length); Highest5 = HighestFC(High, StopLength); Lowest5 = LowestFC(Low, StopLength); hh = HighestFC(High, RangePeriod); ll = LowestFC(Low, RangePeriod); If(Close[1] > 0) amplitude = (hh - ll) / Close[1]; Else amplitude = 0; isRange = (amplitude < RangeRate); PlotNumeric("MA25", MA25); If(MarketPosition > 0 And !SendOrderThisBar) { If(Low < Lowest5[1]) { myExitPrice = Max(Low, Lowest5[1] - MinPoint); If(myExitPrice > Open) myExitPrice = Open; Sell(0, myExitPrice); SendOrderThisBar = True; } } Else If(MarketPosition < 0 And !SendOrderThisBar) { If(High > Highest5[1]) { myExitPrice = Min(High, Highest5[1] + MinPoint); If(myExitPrice < Open) myExitPrice = Open; BuyToCover(0, myExitPrice); SendOrderThisBar = True; } } If(MarketPosition == 0 And !SendOrderThisBar And !isRange) { If( High > High[1]) { myEntryPrice = Min(High, High[1] + MinPoint); If(myEntryPrice < Open) myEntryPrice = Open; Buy(Lots, myEntryPrice); SendOrderThisBar = True; } Else If( Low < Low[1]) { myEntryPrice = Max(Low, Low[1] - MinPoint); If(myEntryPrice > Open) myEntryPrice = Open; SellShort(Lots, myEntryPrice); SendOrderThisBar = True; } } }为什么会闪烁啊?有大佬帮忙看看分析一下吗?Low High不是不会闪烁吗

我应该是发了评论了不知道为什么被吞了再发一遍。你的开仓条件,开多是突破昨高,开空是突破昨低。那如果同一根bar上,如果先突破昨低了,后来有回升突破了昨高,会怎样?

回复:昨天有个bar线破新低然后买空了,然后又突破新高又开多了,导致来回开仓,我明明设置了一根bar只交易一次,然后我看回测图标里只显示后来的多头开仓,先开仓的空头直接不存在了,但是我实盘持仓多空都在

你的 RangePeriod 可能选的太短了,可能多空条件都会满足。回测的时候因为是逐 bar 进行的,如果你的 High > High[1],肯定会按照上影线打到上轨而开多但不去开空,但是如果实盘的时候,一个 bar 没走完,如果到了开多条件,就会先开多,但是 bar 没走完,marketposition 在这个 Bar 上的状态还没确定,如果在这根 bar 同时满足了开空条件,策略就会开空单,发生闪烁。建议你再加一个条件,确保多空条件不会在一根bar上被同时触发,比如 ma10[1] > ma30[1] 这种,就不会闪烁了。

回复:说错了,你的开空条件写在前面,应该策略会先开空单

回复:不对,你上面的是止损吧,那没说错

回复:没有办法实现一个bar只要操作了一次后续信号就不再触发吗?

回复:你可以用A函数试试,就是get下真实仓库的仓位,A函数是全局变量,每个 tick 就可以赋值一次,一旦写死,就不会开仓了