//策略:恒温器系统
//类型:中长期通道突破
//版本:1.0
//修订时间:2012.11.6
//Designed By Rogarz
//中间变量
input:m(50,5,300,30),N(1.25,0.1,10,0.1),ss(1,1,100,1),k1(0.5,0.1,1,0.1),k2(0.75,0.1,1,0.1);
variable:A:=0;//0表示仓位是在趋势模式下下单 1表示在震荡模式下下单
MID : MA(CLOSE,M);//布林中轨
UPPER:MID + N*STD(CLOSE,M);//布林上轨
LOWER:MID - N*STD(CLOSE,M);//布林下轨
今开:=callstock(stklabel,vtopen,6,0);
CMI:=abs(close-ref(close,29))/(hhv(high,30)-LLV(L,30))*100;//0-100 取值越大,说明趋势越强,CMI<20震荡模式,反之为趋势
关键价:(high+low+close)/3;//关键价的计算,国外常称作中枢价格(pivot point)
ATR10:=ma(tr,10);
3日均低价:=ma(L,3);
3日均高价:=ma(h,3);
手数:=ss;
//交易条件
if C<关键价 then begin
趋买市开多平空条件:=C>max(今开+k1*ATR10,3日均低价);
趋买市开空平多条件:=C<min(今开-k2*ATR10,3日均高价);
end
if c>关键价 then begin
趋卖市开多平空条件:=C>max(今开+k2*atr10,3日均低价);
趋卖市开空平多条件:=C<min(今开-k1*atr10,3日均高价);
end
趋势开多条件:=c>upper;
趋势开空条件:=c<lower;
趋势平多条件:=c<mid;
趋势平空条件:=c>mid;
震荡多单平仓条件:=c<=enterprice-3*atr10;
震荡空单平仓条件:=c>=enterprice+3*ATR10;
//交易系统
if cmi<20 then begin {震荡模式}
if C<关键价 then begin
趋买市平空:SL1234short(趋买市开多平空条件 and holding<=0,手数,market);
趋买市平多:SL1234(趋买市开空平多条件 and holding>=0,手数,market);
趋买市开多:aY1234(趋买市开多平空条件 and holding<=0,手数,market);
趋买市开空:aY1234short(趋买市开空平多条件 and holding>=0,手数,market);
A:=1;
end
if c>关键价 then begin
趋卖市平空:SL1234short(趋卖市开多平空条件 and holding<=0,手数,market);
趋卖市平多:SL1234(趋卖市开空平多条件 and holding>=0,手数,market);
趋卖市开多:aY1234(趋卖市开多平空条件 and holding<=0,手数,market);
趋卖市开空:aY1234short(趋卖市开空平多条件 and holding>=0,手数,market);
a:=1;
end
ENd
if cmi>=20 then BEGIN {趋势模式}
if a:=1 then begin //趋势模式下 原震荡模式下 仓位处理
震荡多单平仓:SL1234(震荡多单平仓条件 and holding>0,手数,market);
震荡空单平仓:SL1234short(震荡空单平仓条件 and holding<0,手数,market);
a:=0;
end
if a:=0 then begin
趋势平空:SL1234short(趋势平空条件 and holding<0,手数,market);
趋势平多:SL1234(趋势平多条件 and holding>0,手数,market);
趋势开多:aY1234(趋势开多条件 and holding<=0,手数,market);
趋势开空:aY1234short(趋势开空条件 and holding>=0,手数,market);
A:=0;
end
ENd
//注意先平后开原则