请问下述图表,可以改后台吗?
variable:sumwealth=0;
variable:zichan=0;
ma10:=ma(c,5);
ma25:=ma(c,25);
sxf:=0.21/100;//手续费0.21%
手数:=max(0,floor((zichan-ref(zichan,barslast(date=1160315)))/360000));
if holding>0 and ma10<ma25 then begin
sell(1,holding,thisclose);
sumwealth:=sumwealth+holding*c*300*(1-sxf);//卖出时减去交易额
end
if holding<0 and ma10>ma25 then begin
sellshort(1,holding,thisclose);
sumwealth:=sumwealth-holding*c*300*(1+sxf);//买入时加上交易额
end
if holding=0 and ma10>ma25 and 手数>0 then begin
buy(1,手数,thisclose);
sumwealth:=sumwealth-手数*c*300*(1+sxf);
end
if holding=0 and ma10<ma25 and 手数>0 then begin
buyshort(1,手数,thisclose);
sumwealth:=sumwealth+手数*c*300*(1-sxf);
end
zichan:=sumwealth+holding*c*300-abs(holding)*c*300*sxf;
globalvariable:sumwealth=0;
globalvariable:zichan=0;
ma10:=ma(c,5);
ma25:=ma(c,25);
sxf:=0.21/100;//手续费0.21%
手数:=max(0,floor((zichan-ref(zichan,barslast(date=1160315)))/360000));
if tbuyholding(0)>0 and ma10<ma25 then begin
sumwealth:=sumwealth+tbuyholding(0)*c*300*(1-sxf);//卖出时减去交易额
tsell(1,0,mkt);
end
if tsellholding(0)>0 and ma10>ma25 then begin
sumwealth:=sumwealth-tsellholding(0)*c*300*(1+sxf);//买入时加上交易额
tsellshort(1,0,mkt);
end
if tbuyholding(0)=0 and ma10>ma25 and 手数>0 then begin
tbuy(1,手数,mkt);
sumwealth:=sumwealth-手数*c*300*(1+sxf);
end
if tsellholding(0)=0 and ma10<ma25 and 手数>0 then begin
tbuyshort(1,手数,mkt);
sumwealth:=sumwealth+手数*c*300*(1-sxf);
end
if tbuyholding(0)>0 then zichan:=sumwealth+tbuyholding(0)*c*300-tbuyholding(0)*c*300*sxf;
if tsellholding(0)>0 then zichan:=sumwealth+tsellholding(0)*c*300-tsellholding(0)*c*300*sxf;
tbuyholding 指的是当前实际帐户里的当前品种的实际持仓,无法分辨是否当前策略产生的持仓,会把其他策略的单子平调的,有其他的方式代替吗?
实际上,平仓语句里的holding,就是上次开仓数
在后台里能表示上次开仓数就行了
用全局变量,记录每次的开仓手数。
后台全局变量示例如下:
【金字塔使用技巧】----后台轮询,如何记录变量在最后一周期内的最大最小及开盘值
ma5:=ma(c,5);
if islastbar then
begin
//在新一根K线上记录初始化
if barpos>extgbdata('t') then
begin
extgbdataset('FIR',ma5);//记录开盘值
extgbdataset('MAX1',ma5);//记录最大
extgbdataset('MIN1',ma5);//记录最小
extgbdataset('t',barpos);
end
if barpos=extgbdata('t') then
begin
if ma5>extgbdata('MAX1') THEN extgbdataset('MAX1',ma5);
if ma5<extgbdata('MIN1') THEN extgbdataset('MIN1',ma5);
end
end
http://www.weistock.com/bbs/dispbbs.asp?boardid=16&Id=57075
22、如何在后台程序化交易里一个品种的多个策略的交易