{
//参数设置
L1:=18;
L2:=22;
L3:=13
L0:=4;
R0:=3.4;
}
//成较量均线
volma:=MA(vol,L1);
volma2:=MA(volma,L2);
//开仓判断需要的条件,成交量连增
UPCON:=ref(volma,1)>ref(volma2,1) and ref(volma,2)>ref(volma2,2);
DOWNCON:=ref(volma,1)<ref(volma2,1) and ref(volma,2)<ref(volma2,2);
HL:=MA((HIGH-LOW),L3);
// 止损出场判断条件
LONGSTOP: =IF((UPCON || DOWNCON ||(NOT(UPCON) and NOT(DOWNCON))),OPEN-R0*ref(HL,1),0);
SHORTSTOP:=IF((UPCON || DOWNCON ||(NOT(UPCON) and NOT(DOWNCON))),OPEN+R0*ref(HL,1),0);
//取前四根K线的和,阳柱取1,平,阴柱取-1,求和
b0:=IF(ref(c,1)<=ref(o,1),-1,if(ref(c,1)>ref(o,1),1,0));
b0sum:=SUM(b0,4);//+count(b0=0,4) 平的话就延续向前面取值
//BPK条件与信号
买平开条件:=holding<=0 and UPCON and b0sum=L0;
卖平开条件:=holding>=0 and UPCON and b0sum=0-L0;
IF 买平开条件 THEN BEGIN //买平开
sellshort(holding<0,0,market); //平空
买平开:Buy(holding=0,1,market); //买开
END
IF 卖平开条件 THEN BEGIN //卖平开
sell(holding>0,0,market); //平多
卖平开:buyShort(holding=0,1,MARKET);//卖开;
END
//单个平仓条件
PD:=LOW<=LONGSTOP and holding>0; //平多条件
PK:=HIGH>=SHORTSTOP and holding<0;//平空条件
平空:SELLSHORT(PK ,1,THISCLOSE); //平空信号
平多:SELL(PD ,1,THISCLOSE); //平多信号
这个可以用input函数来处理,可以参照下函数说明。