为啥一根bar上还能反复开平2次 怎么杜绝

老师好,我是指令价模型 1)为啥一根bar上还能反复开平2次 代码在图片下面 2)请问一根bar上开仓/平仓只能一次 除了用 and BarsSinceEntry>0 还可以用什么方法呢 // 多单开仓条件:均线多头排列(MA5≥MA10≥MA20)且放量 If(MarketPosition <> 1 and high>=max(ma3,max(ma1,ma2)) and condition1 and condition2) // 版本5为均线多头排列 high>=ma1 and ma1 >= ma2 and ma2 >= ma3 { myEntryPrice = max(open,max(ma3,max(ma1,ma2))); buy(lots, myEntryPrice); // 新增:开仓原因细化(放量+ADX条件) Commentary("多单进场: 因ma1(" + Text(ma1) + ") ≥ ma2(" + Text(ma2) + ") ≥ ma3(" + Text(ma3) + "), 且放量(vol=" + Text(vol) + "),且ADX值(" + Text(oADX) + ") > 前值(" + Text(oADX[1]) + ")"); Commentary("开仓价公式: myEntryPrice = open(" + Text(myEntryPrice) + ")"); } // 空单开仓条件:均线空头排列(MA5≤MA10≤MA20)且放量 If(MarketPosition <> -1 and low<=min(ma3,min(ma1,ma2)) and condition1 and condition2) // 版本5为均线多头排列 low<=ma1 and ma1<= ma2 and ma2 <= ma3 { myEntryPrice = min(open,min(ma3,min(ma1,ma2))); sellshort(lots, myEntryPrice); // 新增:开仓原因细化(放量+ADX条件) Commentary("空单进场: 因ma1(" + Text(ma1) + ") ≤ ma2(" + Text(ma2) + ") ≤ ma3(" + Text(ma3) + "), 且放量(vol=" + Text(vol) + "),且ADX值(" + Text(oADX) + ") > 前值(" + Text(oADX[1]) + ")"); } // 多单平仓条件:价格跌破2条均线最小值时平仓 If(MarketPosition == 1 and low <= Min(ma1, ma2)) //and BarsSinceEntry>0 奇怪 加了这个业绩差些 但是不加业绩更好 但存在一根bar上开盘就平仓的情况 { myExitPrice = Min(open, Min(ma1, ma2)); // 平仓价取open和2条均线最小值中的较小值 sell(lots, myExitPrice); // 使用计算后的价格平仓 Profit = myExitPrice - myEntryPrice; Commentary("多单平仓原因: low(" + Text(low) + ") ≤ Min(ma3(" + Text(ma3) + "), Min(ma1(" + Text(ma1) + "), ma2(" + Text(ma2) + "))) = " + Text(Min(ma3, Min(ma1, ma2)))); } // 空单平仓条件:价格突破2条均线最大值时平仓 If(MarketPosition == -1 and high >= Max(ma1, ma2)) //and BarsSinceEntry>0 { myExitPrice = Max(open, Max(ma1, ma2)); // 平仓价取open和2条均线最大值中的较大值 buytocover(lots, myExitPrice); // 使用计算后的价格平仓 Profit = myEntryPrice - myExitPrice; Commentary("空单平仓原因: high(" + Text(high) + ") ≥ Max(ma3(" + Text(ma3) + "), Max(ma1(" + Text(ma1) + "), ma2(" + Text(ma2) + "))) = " + Text(Max(ma3, Max(ma1, ma2)))); }

你先满足开多又满足了开空自己赋值变量作为开关都可以搞定

回复:谢谢