Params Numeric M(35); //计算的周期数 Numeric SS(1); //手数 Numeric TR(5);//跟踪止损比例Vars Series Nop; Series HH1; Series LL1; Series CC1; Series P; Series R1; Series R2; Series R3; Series S1; Series S2; Series S3; Series RM1; Series RM2; Series RM3; Series SM1; Series SM2; Series SM3; Series SY; Series XY; Series LowerAfterEntry; Series HigherAfterEntry; Series Myprice; Series Myprice2; Series bartoday; Series bartoday2; Series Condition1; Series Condition2; Series Condition3; Series Condition4; Series Condition5; Series Condition6; Series T1; Series T2;Events OnBar(ArrayRef indexs) { bartoday=(barssinceToday==0);//今日第一根BAR线 bartoday2=(barssincetoday>0);//大于今日第一根BAR线 If(bartoday) { Nop=Open;//获得今日开盘价 } HH1=HighD(M);//M生意业务日内的最高价 LL1=LowD(M);//M生意业务日内的最低价 CC1=CloseD(M);//M生意业务日内的收盘价 P=(HH1+LL1+CC1)/3;//以上三个价格的均价,中轴线; R1=2*P-LL1;//做第一个初始阻力价; S1=2*P-HH1;//做第一个初始支撑价; R2= P+(R1-S1);//第二个初始阻力价; S2= P-(R1-S1);//第二个初始支撑价; R3= HH1+2*(P-LL1);//第三个初始阻力价; S3= LL1-2*(HH1-P);//第三个初始支撑价; SM1=(P+S1)/2;//第一个区间的支撑; SM2=(S1+S2)/2;//第二份区间的支撑; SM3=(S2+S3)/2;//第三个区间的支撑; RM1=(P+R1)/2;//第一个区间的阻力; RM2=(R1+R2)/2;//第二个区间的阻力; RM3=(R2+R3)/2;//第三个区间的阻力; //设置6个区间,根据日开盘价所在区间所决定使用哪一个区间的上沿下沿作为突破开仓的条件; Condition1 = Nop>P and NopSM2 and NopSM3 and NopRM1 and NopRM2 and NopSY )and SY>0 and SY[1]==SY; //最新价格死叉XY且小于XY,并且XI不能是空值,XY与上一根BAR线相称防止出现假连线 T2 = (CrossUnder(C,XY) or C0 and XY[1]==XY; If((T1[1] and Not(T2[1])) and MarketPosition1 and bartoday2) { Buy(SS,Open); LowerAfterEntry=EntryPrice; } If((T2[1] and Not(T1[1])) and MarketPosition-1 and bartoday2) { SellShort(SS,Open); HigherAfterEntry=EntryPrice; } //纪录多头最低价和空头最高价格 //有多头持仓,刚出场时的本根BAR线的序号 if(MarketPosition==1 and BarsSinceEntry==0) { HigherAfterEntry=HigherafterEntry[1]; LowerAfterEntry=Max(LowerAfterEntry,Low); } //有空头持仓,刚出场时的本根bar线的序号 if(MarketPosition==-1 and BarsSinceEntry==0) { HigherAfterEntry=Min(HigherafterEntry,High); LowerAfterEntry=LowerAfterEntry[1]; } if(MarketPosition0 and BarsSinceEntry>=1) { HigherAfterEntry=Min(HigherafterEntry,High); LowerAfterEntry=Max(LowerAfterEntry,Low); } //跟踪出场 //多头出场线 Myprice=LowerAfterEntry -Open*TR/100; //当持有多头持仓,最新价格跌破出场线吗,同时平仓信号和开仓信号不再同一根BAR线; { if(MarketPosition==1 and Low0) //如果跳空击破,取值最新的bar线的开盘价,若不是则使用出场线价格; Myprice = Min(Myprice,Open); //多头平仓 Sell(0,Myprice); } Myprice2=HigherAfterEntry + Open*TR/100; //空头出场线 if(MarketPosition==-1 and High>=Myprice2 and BarsSinceEntry>0) { Myprice2 = Max(Myprice2,Open); BuyToCover(0,Myprice2); }} |