浮亏加仓价格问题
请问下面加仓的写法是否有问题,加载到图层上,如图 第五次加仓为什么开始都是一样的价格?思路是 如果在【-300,300】区间 按照10点加仓 ,最多加6次仓,即如果在200开多仓1手,浮亏10点,在190开多2手 ,在200平掉全仓 如果在-300以下,300以上 按照上一次开仓位置的浮亏3% 加仓 ---------------------------------------------------------------------Params //此处添加参数 Numeric firststep(0.03); Integer firstTrades(1); Integer ADDstep(10); Integer newprice(0); Numeric KND(0.04); Vars //此处添加变量 Integer Lots; Series<Numeric> FirstPrice; // 第一次开仓价格 Series<Numeric> LastPrice; // 最后一次开仓价格 Numeric myflag; Integer i(1); Numeric MinPoint; // 一个最小变动单位,也就是一跳 Series<Numeric> TakeProfitSet; Series<Numeric> TakeProfitTrades; Series<Numeric> Lastprofitset; Bool FirstbuyEntryCon; Bool FirstshortEntryCon; Events OnBar(ArrayRef<Integer> indexs) { Range[0:DataSourceSize() - 1] { FirstbuyEntryCon = Close[1] < 0; FirstshortEntryCon = Close[1]> 0; MinPoint = MinMove*PriceScale; If(MarketPosition == 0 && FirstbuyEntryCon) //开多仓 { FirstPrice = Open; LastPrice = FirstPrice; Buy( firstTrades,FirstPrice); Commentary(FirstPrice = + Text(FirstPrice)); Commentary(LastPrice = + Text(LastPrice)); } If(MarketPosition > 0) //加仓 平仓 { While(abs(Close[1]) >300 && CurrentEntries <7 && Low <= LastPrice +IntPart( LastPrice*firststep* MinPoint))// 加仓 { LastPrice = LastPrice +IntPart( LastPrice*firststep* MinPoint ); Commentary(LastPrice = + Text(LastPrice)); Buy(Power(2,i),LastPrice); i = i+1 ; } While(abs(Close[1]) <=300 && CurrentEntries <7 && Low <= LastPrice +IntPart( ADDstep* MinPoint))// 加仓 { LastPrice = LastPrice +IntPart( ADDstep* MinPoint ); Commentary(LastPrice = + Text(LastPrice)); Buy(Power(2,i),LastPrice); i = i+1 ; } If(abs(Close[1]) >300 && CurrentEntries > 0 && High >= LastPrice - IntPart( LastPrice*KND* MinPoint)) // 减仓 { LastPrice = LastPrice - IntPart(LastPrice*KND* MinPoint) ; Commentary(LastPrice = + Text(LastPrice)); Sell(0,LastPrice); } If(abs(Close[1]) <= 300 && CurrentEntries > 0 && High >= LastPrice - IntPart( ADDstep* MinPoint)) // 减仓 { LastPrice = LastPrice - IntPart(ADDstep* MinPoint) ; Commentary(LastPrice = + Text(LastPrice)); Sell(0,LastPrice); } } } }