[PEL] 复制代码
input:zj(20000,1,1000000,1);
下单资金量:=zj;
marginratio:=taccount(41);//多头保证金比率. 这个要把合约信息设置里面的费率设置正确,否则函数取到的值可能是不对的。
bzj:=close*multiplier*marginratio;//一手保证金占用
ss1:=intpart(下单资金量/(bzj));//根据资金zj计算的开仓手数,注意这个计算结果可能是0 需要在开仓时候判断下
variable:index:=1;
VARIABLE:ct:=0;//加仓次数
初始开仓条件:barpos=1;
if 初始开仓条件 and holding=0 then
begin
buy(ss1>0,ss1,marketr);
end
firstp:valuewhen(openbar=0,enterprice);//首次入场的开仓价
if time= 185500 and ct<50 then
begin
//如果ss1是0 说明资金不足了
尾盘加仓:buy(ss1>0,ss1,marketr);
ct:=ct+1;
end
if c/firstp>=(1+index*0.001) and c>enterprice and holding>0 and ct<50 then
begin
index:=index+1;
加仓:buy(ss1>0,ss1,marketr);
ct:=ct+1;
end
if holding=0 then begin
index:=1;
ct:=0;end