老师帮忙看看,开不了仓
Params Numeric length5(5); Numeric length20(20); Vars Series<Numeric> MA5; Series<Numeric> MA20; Events OnBar(ArrayRef<Integer> indexs) { Bool ret; MA5 = AverageFC(Close, length5); MA20 = AverageFC(Close, length20); PlotNumeric("MA5",MA5);// 在当前Bar输出一个数值 PlotNumeric("MA20",MA20); Numeric MinPoint; // 一个最小变动单位,也就是一跳 Numeric MyEntryPrice; // 开仓价格,例中为开仓均价,可设置为某次入场价 Numeric StopLossSet(20); // 止损设置 Numeric MyExitPrice; // 平仓价格 Numeric Share;//手数 Numeric available;// 可用资金 MinPoint = MinMove*PriceScale; MyEntryPrice = AvgEntryPrice; Share= RoundDown (available /( MyEntryPrice*0.15*15),0);//手数=取整(可用资金/(开仓价格*保证金*15)) If(MA5 > MA20) { Buy(Share,close); } else If(MA5 < MA20) { SellShort(Share,close); } If(MarketPosition == 1 And BarsSinceEntry >= 1) // 有多仓的情况 { If(Low <= MyEntryPrice - StopLossSet*MinPoint) // 止损条件表达式 { MyExitPrice = MyEntryPrice - StopLossSet*MinPoint; // 如果该Bar开盘价即跳空触发,则用开盘价代替 If(Open < MyExitPrice) MyExitPrice = Open; Sell(0,MyExitPrice); } } Else If(MarketPosition == -1 And BarsSinceEntry >= 1) // 有空仓的情况 { If(High >= MyEntryPrice + StopLossSet*MinPoint) // 止损条件表达式 { MyExitPrice = MyEntryPrice + StopLossSet*MinPoint; If(Open > MyExitPrice) MyExitPrice = Open ; BuyToCover(0,MyExitPrice); } } }