为什么这个策略刚买就平仓

老师你好,请问一下我这个编写的代码为什么会在图表上刚买就平仓,明明在平仓条件里加入了BarsSinceEntry > 0。Params Numeric Length1(5); Numeric Length2(20); Numeric ATRMA(20);Vars Series<Numeric> ma1; Series<Numeric> ma2; Global Numeric HHV; Series<Numeric> ATR; Global Bool ret1; Global Bool ret2; Global Numeric oParCl; Global Numeric oParOp; Global Numeric oPosition; Global Numeric oTransition;Events OnBar(ArrayRef<Integer> indexs) { ma1 = AverageFC(c[1],Length1); ma2 = AverageFC(c[1],Length2); PlotNumeric(MA1,ma1); PlotNumeric(MA2,ma2); ATR = AvgTrueRange(ATRMA); ret1 = CrossOver(ma1,ma2); ret2 = CrossUnder(ma1,ma2); Commentary(ret1+IIFString(ret1, True, False)); Commentary(ret2+IIFString(ret2, True, False)); Bool ret = ParabolicSAR(0.02, 0.2, oParCl, oParOp, oPosition, oTransition); If(oPosition == 1) Commentary(多头); If(oPosition == -1) Commentary(空头); If(ret1 And MarketPosition == 0 And Not ret2) {buy(1,O); HHV = o;} If(MarketPosition == 1 And BarsSinceEntry > 0 And Not ret1 And ret2); {Sell(1,O); Commentary(平仓);} If(MarketPosition == 1 And BarsSinceEntry > 0 And oPosition == -1) {Sell(1,O); Commentary(价格下降平仓);} If(MarketPosition == 1 And BarsSinceEntry >0) HHV = Max(HHV,O); If(MarketPosition == 1 And BarsSinceEntry > 0 And Low < HHV - 4* ATR) {Sell(1,HHV - 5* ATR); Commentary(止损);} }

回复:谢谢老师