系统自带模型加止损
老师请把下面的模型加上当前持仓亏损300元立即平仓,谢谢Params Numeric ATRs(3); // 几倍ATR止盈 Numeric ATRLength(10); // ATR周期 Vars Series<Numeric> WAvgPrice; // K线加权均值 Series<Numeric> Resistance; // 阻力线 Series<Numeric> Support; // 支撑线 Numeric ATRVal; // ATR(平均真实波幅) Series<Numeric> myExitPrice; // 开仓BAR根据当时的ATR计算出的止盈价 Events OnBar(ArrayRef<Integer> indexs) { // 计算当前K线的加权均值、阻力线和支撑线 WAvgPrice = (High + Low + (Close * 2)) / 4; Resistance = (WAvgPrice * 2) - Low; Support = (WAvgPrice * 2) - High; // 输出指标 PlotNumeric(\"Resistance\",Resistance[1]); PlotNumeric(\"Support\",Support[1]); // 计算ATR ATRVal = AvgTrueRange(ATRLength); // 开仓 If(MarketPosition == 0 And High >= Resistance[1] + MinMove * PriceScale And Vol > 0) { Buy(0, Max(Open,Resistance[1] + MinMove * PriceScale)); } // 开仓时根据开仓BAR的ATR计算止盈价 If(MarketPosition == 1 And BarsSinceEntry == 0) { myExitPrice = EntryPrice + ATRVal * ATRs; } // 平仓 If(MarketPosition == 1 And BarsSinceEntry > 0 And Vol > 0) { // 止盈出场 If(High >= myExitPrice) { Sell(0, Max(Open,myExitPrice)); Commentary(\"止盈出场\"); } // 反向突破止损出场 Else If(Low <= Support[1] - MinMove * PriceScale) { Sell(0, Min(Open,Support[1] - MinMove * PriceScale)); Commentary(\"反转出场\"); } } }//---------