[PEL] 复制代码
//中间变量
input:m(50,5,300,30),n(1.25,0.1,10,0.1),ss(1,1,10000,1),k1(0.5,0.1,1,0.1),k2(0.75,0.1,1,0.1);
//0表示仓位是在趋势模式下下单 1表示在震荡模式下下单
globalvariable:flag:=0;
mid : ma(close,m);//布林中轨
upper:mid + n*std(close,m);//布林上轨
lower:mid - n*std(close,m);//布林下轨
今开:=callstock(stklabel,vtopen,6,0);
//0-100 取值越大,说明趋势越强,cmi<20震荡模式,反之为趋势
cmi:=abs(close-ref(close,29))/(hhv(high,30)-llv(l,30))*100;
//关键价的计算,国外常称作中枢价格(pivot point)
关键价:(high+low+close)/3;
atr10:=ma(tr,10);
3日均低价:=ma(l,3);
3日均高价:=ma(h,3);
手数:=ss;
//交易条件
趋买市开多平空条件:=c>max(今开+k1*atr10,3日均低价);
趋买市开空平多条件:=c<min(今开-k2*atr10,3日均高价);
趋卖市开多平空条件:=c>max(今开+k2*atr10,3日均低价);
趋卖市开空平多条件:=c<min(今开-k1*atr10,3日均高价);
趋势开多条件:=c>upper;
趋势开空条件:=c<lower;
趋势平多条件:=c<mid;
趋势平空条件:=c>mid;
震荡多单平仓条件:=c<=tenterprice-3*atr10;
震荡空单平仓条件:=c>=tenterprice+3*atr10;
多持仓:tbuyholdingex('','',2);
空持仓:tsellholdingex('','',2);
//交易系统
if cmi<20 then begin {震荡模式}
if c<关键价 and 趋买市开多平空条件=1 then begin
趋买市平空:tsellshort(空持仓>0,手数,mkt);
趋买市开多:tbuy(多持仓=0,手数,mkt);
flag:=1;
end
if c<关键价 and 趋买市开空平多条件=1 then begin
趋买市平多:tsell(多持仓>0,手数,mkt);
趋买市开空:tbuyshort(空持仓=0,手数,mkt);
flag:=1;
end
if c>关键价 and 趋卖市开多平空条件=1 then begin
趋卖市平空:tsellshort(趋卖市开多平空条件 and 空持仓>0,手数,mkt);
趋卖市开多:tbuy(趋卖市开多平空条件 and 多持仓=0,手数,mkt);
flag:=1;
end
if c>关键价 and 趋卖市开空平多条件=1 then begin
趋卖市平多:tsell(多持仓>0,手数,mkt);
趋卖市开空:tbuyshort(空持仓=0,手数,mkt);
flag:=1;
end
end
if cmi>=20 then begin {趋势模式}
//处理原震荡模式下持有的仓位
if flag=1 and (震荡多单平仓条件=1 or 震荡空单平仓条件=1) then begin
震荡多单平仓:tsell(多持仓>0,手数,mkt);
震荡空单平仓:tsellshort(空持仓>0,手数,mkt);
flag:=0;
end
if flag=0 then begin
趋势平空:tsellshort(趋势平空条件 and 空持仓>0,手数,mkt);
趋势平多:tsell(趋势平多条件 and 多持仓>0,手数,mkt);
趋势开多:tbuy(趋势开多条件 and 多持仓>=0,手数,mkt);
趋势开空:tbuyshort(趋势开空条件 and 空持仓>=0,手数,mkt);
end
end