[PEL] 复制代码
input:n1(5,1,500,1),n2(40,1,1000,1),m(9,2,1000,1),q(0.3,0.01,1,0.01),y(3,1,100,1),n(6,1,300,1);
globalvariable:at:=0;//记录开仓前的总资产
globalvariable:maxp:=0;//开仓后最高价或者最低价
ma5:ma(c,n1);
ma40:ma(c,n2);
kd:ma5>ma40 and h=hhv(h,m);
kk:ma40<ma5 and l=llv(l,m);
atr:"atr.atr"(14);
ss:=tasset*0.3/(n*3*multiplier*atr);
tcd:time>=185800;
//实际运行中这里建议换成dynainfo( 7) 获取最新值
最新价:c;
多持仓:tbuyholdingex('','',2);
空持仓:tsellholdingex('','',2);
多均价:tavgenterpriceex2('','',0);
空均价:tavgenterpriceex2('','',1);
多可用:tbuyholdingex('','',1);
空可用:tsellholdingex('','',1);
if kd and 多可用=0 and tcd then
begin
tbuy(1,ss,mkt);
at:=tasset;
end
if kk and 空可用=0 and tcd then
begin
tbuyshort(1,ss,mkt);
at:=tasset;
end
多均价:=tavgenterpriceex2('','',0);
//持仓后,更新开多后的最高价
if tbuyholdingex('','',1)<>0 then
begin
if maxp=0 then maxp:=多均价;
if 最新价>maxp then begin
maxp:=最新价;
end
end
空均价:=tavgenterpriceex2('','',1);
//持仓后,更新开空后的最低价
if tsellholdingex('','',1)<>0 then
begin
if maxp=0 then maxp:=空均价;
if 最新价<maxp then
begin
maxp:=最新价;
end
end
//从盈利最高价回撤 y倍atr平仓
if (maxp-最新价)>=y*atr and 多可用>0 then
begin
tsell(1,0,mkt);
maxp:=0;
end
if (最新价-maxp)>=y*atr and 空可用>0 then
begin
tsellshort(1,0,mkt);
maxp:=0;
end
//总资产亏损30% 平仓。以开仓时候的资产总值作为基准值来计算浮亏百分百。
if (at-tasset)/at>=q and (多可用>0 or 空可用>0)then
begin
tsell(多可用>0,0,mkt);
tsellshort(空可用>0,0,mkt);
maxp:=0;
end