止损,和止盈不执行
Params Numeric length1(1);// 短期指数平均线参数 Numeric length2(5);// 长期指数平均线参数 Numeric length3(1.002);// 小上涨涨幅 Numeric length4(1.006);// 大上涨涨幅 Numeric length5(1.0025);// 破位涨幅 Numeric length7(2500);// 区间高位 Numeric length6(2000);// 区间低位 Numeric length8(35);// 止损点位 Numeric length9(100);// 止盈点位 Numeric length10(1);// 手数 Numeric length11(10);// 加仓间隔点数 Numeric length12(3);// 多头建仓次数 Numeric length13(3);// 多头挂单点数 Numeric length15(16);// 多头挂单点数Varsseries<Numeric> ma1;series<Numeric> ma2;series<Numeric> my_entryprice1;series<Numeric> my_entryprice2;series<Numeric> my_entryprice3;series<Bool> bool_crossover;series<Bool> bool_crossunder;Events OnBar(ArrayRef<Integer> indexs) { ma1 = Average(close, length1); ma2 = Average(close,length2); //PlotNumeric(\"ma1\",ma1); PlotNumeric(\"ma2\",ma2);//金叉 // bool_crossover = ma1[1] <= ma2[1] and ma1 > ma2; // bool_crossunder = ma1[1] >= ma2[1] and ma1 < ma2; bool_crossover = close[1] > ma2[1] and ma2[1] >Low[1] and close[2] < ma2[2] and (close[1]/close[2]) >= length3 and (close[1]/close[2]) <= length4 and length7 > low[2] and low[2] >length6 ;//and (low[2] >length6 and length7 > low[2]) bool_crossunder = close[1] < ma2[1] and close[2] > ma2[2] and (close[2]/close[1]) > length5; //and MarketPosition <> 1 If(bool_crossover and MarketPosition <> 1) { Buy(length10,open-length13); my_entryprice1=open-length13; if(MarketPosition>0 and low< my_entryprice1-length8)//止损条件满足亏1oa0,EntryPrice,my_entryprice-low>1g { sell(0,min(o,my_entryprice1 -length8)); } else if(MarketPosition>0 and high>my_entryprice1+length9)//止盈条件满足亏loa8,EntryPrice,my_entryprice-low> { sell(0,max(o,my_entryprice1 +length9)); } If(bool_crossover and MarketPosition <> 1) { Buy(length10,open-length15); my_entryprice2=open-length15; if(MarketPosition>0 and low< my_entryprice2-length8)//止损条件满足亏1oa0,EntryPrice,my_entryprice-low>1g { sell(0,min(o,my_entryprice2 -length8)); } else if(MarketPosition>0 and high>my_entryprice2+length9)//止盈条件满足亏loa8,EntryPrice,my_entryprice-low> { sell(0,max(o,my_entryprice2 +length9)); } } }Else If(MarketPosition == 1 AND CurrentEntries < length12 AND bool_crossover and High[1]-my_entryprice1 > length11) // 有仓的情况 { Buy(length10,open-length13); my_entryprice3=open-length13; if(MarketPosition>0 and low< my_entryprice3-length8)//止损条件满足亏1oa0,EntryPrice,my_entryprice-low>1g { sell(0,min(o,my_entryprice3 -length8)); }else if(MarketPosition>0 and high>my_entryprice3+length9)//止盈条件满足亏loa8,EntryPrice,my_entryprice-low> {sell(0,max(o,my_entryprice3 +length9)); } } //If(bool_crossunder)//{ // Sell(length10,open[1]);//}}