input:n1(5,1,100,1),n2(20,1,100,1),report(0,0,1,1);
//需要生成报告时,将参数report设为1
variable:rz1=1;
if barpos()=1 then
begin
if report=1 then
debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',FORMULANAME()&' '&stklabel&' 月度汇总报告 测试日期:%0.f',currentdate+19000000,0);
rz1:=asset();
end;
//一个均线交叉的系统作为例子
ma1:=ma(c,n1);
ma2:=ma(c,n2);
t1:=time>=091500 and time<=144500;
t2:=time>=151000;
sell(holding>0 and (ma1<ma2 or t2),1,thisclose);
sellshort(holding<0 and (ma1>ma2 or t2),1,thisclose);
buy(holding=0 and ma1>ma2 and t1,1,thisclose);
buyshort(holding=0 and ma1<ma2 and t1,1,thisclose);
//生成月统计
rz2:=ref(ASSET(),1) ;
rd:=ref(date,1);
if barpos<>1 and (month<>ref(month,1) or islastbar) then
begin
if report=1 then debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',numtostr((rd+19000000)/100,0)&'收益: %0.f ',rz2-rz1,0);
rz1:=rz2;
end;
input:n1(5,1,100,1),n2(20,1,100,1),report(0,0,1,1); //需要生成报告时,将参数report设为1 variable:rz1=1; if barpos()=1 then begin if report=1 then debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',FORMULANAME()&' '&stklabel&' 月度汇总报告 测试日期:%0.f',currentdate+19000000,0); rz1:=asset(); end; ma1:=ma(c,n1); ma2:=ma(c,n2); t1:=time>=091500 and time<=144500; t2:=time>=151000; sell(holding>0 and (ma1ma2 or t2),1,thisclose); buy(holding=0 and ma1>ma2 and t1,1,thisclose); buyshort(holding=0 and ma11 and (month<>ref(month,1) or islastbar) then begin if report=1 then debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',numtostr((rd+19000000)/100,0)&'收益: %0.f ',rz2-rz1,0); rz1:=rz2; end;
由于金字塔现在的模型测试中没有按月统计的功能,尝试在公式中加入简单的几行代码,实现收益按月统计,统计结果保存在txt文件中,形式如下:
macross_report IF00 月度汇总报告 测试日期:20110831
201004收益: 29940
201005收益: 60780
201006收益: -43680
201007收益: -6060
201008收益: -30420
201009收益: 18720
201010收益: 83760
以此为模板,还可以增加每月交易次数,胜率等数据。
可以在进行回测的时候设置report参数为1,平时在图表上使用时report设为0;
input:n1(5,1,100,1),n2(20,1,100,1),report(0,0,1,1);
//需要生成报告时,将参数report设为1
variable:rz1=1;
if barpos()=1 then
begin
if report=1 then
debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',FORMULANAME()&' '&stklabel&' 月度汇总报告 测试日期:%0.f',currentdate+19000000,0);
rz1:=asset();
end;
//一个均线交叉的系统作为例子
ma1:=ma(c,n1);
ma2:=ma(c,n2);
t1:=time>=091500 and time<=144500;
t2:=time>=151000;
sell(holding>0 and (ma1<ma2 or t2),1,thisclose);
sellshort(holding<0 and (ma1>ma2 or t2),1,thisclose);
buy(holding=0 and ma1>ma2 and t1,1,thisclose);
buyshort(holding=0 and ma1<ma2 and t1,1,thisclose);
//生成月统计
rz2:=ref(ASSET(),1) ;
rd:=ref(date,1);
if barpos<>1 and (month<>ref(month,1) or islastbar) then
begin
if report=1 then debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',numtostr((rd+19000000)/100,0)&'收益: %0.f ',rz2-rz1,0);
rz1:=rz2;
end;
--------------------------------------------------------------------------------
input:n1(5,1,100,1),n2(20,1,100,1),report(0,0,1,1); //需要生成报告时,将参数report设为1 variable:rz1=1; if barpos()=1 then begin if report=1 then debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',FORMULANAME()&' '&stklabel&' 月度汇总报告 测试日期:%0.f',currentdate+19000000,0); rz1:=asset(); end; ma1:=ma(c,n1); ma2:=ma(c,n2); t1:=time>=091500 and time<=144500; t2:=time>=151000; sell(holding>0 and (ma1ma2 or t2),1,thisclose); buy(holding=0 and ma1>ma2 and t1,1,thisclose); buyshort(holding=0 and ma11 and (month<>ref(month,1) or islastbar) then begin if report=1 then debugfile2('C:\Documents and Settings\Administrator\桌面\month.txt',numtostr((rd+19000000)/100,0)&'收益: %0.f ',rz2-rz1,0); rz1:=rz2; end;