//声明参数
input:D20(20,10,60,1);;
input:D10(10,5,30,1);
input:ATRL(13,5,30,1);
input: risk(1,0.5,5,0.1)
//声明变量
VARIABLE:H20:=close;
VARIABLE:L20:=CLOSE;
VARIABLE:H10:=Close;
VARIABLE:L10:=CLOSE;
//VARIABLE :_DEBUG: = 1 ;
//是否输出前台交易指令 (借鉴)
VARIABLE:myenterprice:=0; //初始开仓价格;
VARIABLE:myexitprice:=0;//初始平仓价格
VARIABLE:units:=0;//交易单位
VARIABLE:position:=0;//初始仓位
VARIABLE:sendorderthisbar:=0;
Variable:units:=0;
Variable:tunits:=0;
VARIABLE:jdcond:=0;
VARIABLE:pdcond:=0;
VARIABLE:dzcond:=0;
VARIABLE:jkcond:=0;
VARIABLE:pkcond:=0;
VARIABLE:kzcond:=0;
H20:=ref(HHV(h,20),1);
L20:=ref(LLV(l,20),1);
H10:=ref(HHV(h,10),1);
L10:=ref(LLV(l,10),1);
KD:=c>H20; //开多条件
PD:=c<L10; //平多条件
KK:=c<L20; //开空条件
PK:=c>H10; //平空条件
N:=ma(TR,ATRL);
units:=ASSET*risk*0.01/N;
//建立仓位
if BARPOS=1 then begin
end; //初始化;
if position=0 and BARPOS>D20 and h>l then begin
//建立多头仓位
if KD then BEGIN
myentryprice:=if(open>H20+MINDIFF, open ,H20+MINdiff);
buy(KD,units,LIMITR,myentryprice);
position:=1;
tuntis:=1;
sendoederthisbar:=1;
end;
//建立空头仓位
if KK then begin
myentryprice:=if(open<L20-MINDIFF ,open ,L20-MINDIFF);
BUYSHORT( KK,units,LIMITR,myentryprice);
position:=-1;
tunits:=1;
sendorderthisbar:=1;
end
end
//
jdcond:=( position=1 and BARPOS>D20 and H>l ) ;
if jdcond then begin
//多头加仓
WHILE (h>myentryprice+0.5*N) and tunits<4 do begin
myentryprice:=if(open>myentryprice+0.5*N,open,myentryprice+0.5*N);
myentryprice:=CEILING(myentryprice/MINDIFF)*Mindiff;
buy( (h>myentryprice+0.5*N) and tunits<4 ,units,LIMITR,myentryprice);
position:=1;
tunits:=tunits+1;
sendoederthisbar:=1;
end
//多头离场
pdcond:= pd and sendorderthisbar=0 ;
if pdcond then begin
myexitprice:=if(open<L10-MINDIFF,open,L10-MINDIFF);
sell( pdcond, 0,limitr,myexitprice);
position:=0;
tunits:=0;
end
//多头止损
dzcond:=( low<myentryprice-2*N and position=1 and sendorderthisbar=0)
if dzcond then begin
myexitprice:=if(open<myentryprice-2*N,open,myentryprice-2*N);
myexitprice:=floor(myexitprice/MINDIFF)*mindiff;
sell( dzcond,0,limitr,myexitprice);
position:=0;
tunits:=0;
ENd;
end
//加仓
jkcond:= (position=-1 and BARPOS>d20 and H>l) ;
if jkcond then begin
//空头加仓
WHILE (L<myentryprice-0.5*N) and tunits<4 do begin
myentryprice:=if(open<myentryprice-0.5*N,open,myentryprice-0.5*N);
myentryprice:=floor(myentryprice/MINDIFF)*Mindiff;
buyshort( (L<myentryprice-0.5*N) and tunits<4,units,LIMITR,myentryprice);
position:=-1;
tunits:=tunits+1;
sendoederthisbar:=1;
end
//空头离场
pkcond:= pk and sendorderthisbar=0 ;
if pkcond then begin
myexitrice:=if(open>H10+MINDIFF,open,h10+MINDIFF);
sellshort( pkcond,0,limitr,myexitprice);
position:=0;
tunits:=0;
end
//空头止损
kzcond:=( h>myentryprice+2*N and position=-1 and sendorderthisbar=0)
if kzcond then begin
myexitprice:=if(open>myentryprice+2*N,open,myentryprice+2*N);
myexitprice:=CEILING(myexitprice/MINDIFF)*mindiff;
sellshort( kzcond,0,limitr,myexitprice);
position:=0;
tunits:=0;
ENd;
end
//信号语句排列规则——先平后开
//“费率设置”按钮——用于合理设置模型“费率”,以便在图形上正确输出如下帐户信息:
{
持仓:holding,linethick0;
资产:asset,noaxis;
可用现金:cash(0),linethick0;
}