代码编写止盈问题
老师帮我修改下,我想在多单开仓价盈利达9倍ATR后,最高价回撤3倍ATR止盈。我写不知道哪里不对。 Params Numeric FastLength(5);// 短期指数平均线参数 Numeric SlowLength(20);// 长期指数平均线参数 Numeric len1(250); //ATR周期 Numeric Nzy(9); //ATR止盈倍数 Numeric Nhc(3); //ATR回撤倍数 Vars Series<Numeric> AvgValue1; Series<Numeric> AvgValue2; Numeric myEntryPrice; // 开仓价格 Series<Numeric> preEntryPrice(0); // 前一次开仓的价格 Series<Numeric> atr; Series<Numeric>N; Events OnBar(ArrayRef<Integer> indexs) { AvgValue1 = AverageFC(Close,FastLength); AvgValue2 = AverageFC(Close,SlowLength); PlotNumeric("MA1",AvgValue1); PlotNumeric("MA2",AvgValue2); atr=AvgTrueRange(len1); N=atr[1]; If(MarketPosition <>1 && AvgValue1[1] > AvgValue2[1]) { myEntryPrice = Open; preEntryPrice = myEntryPrice; Buy(0,myEntryPrice); } If(MarketPosition == 1) // 有多仓的情况 { If(H>=preEntryPrice+N*Nzy) { L<=H-N*Nhc; myEntryPrice = Min(H-N*Nhc,O); preEntryPrice = myEntryPrice; BuyToCover(0,myEntryPrice); } } If(MarketPosition <>-1 && AvgValue1[1] < AvgValue2[1]) { SellShort(0,Open); } }