-- 作者:smarter
-- 发布时间:2012/4/16 17:00:35
-- 后台交易问题
请问:下列模型, 在后台交易时, TB为什么总是1 ? 如何才能累加? 谢谢!
VARIABLE:tb=0; input:KCS(1,1,100,1),KN(3,1,15,1),M(1,0,30,1);
资产:ASSET,NOAXIS,LINETHICK0; 持仓:HOLDING,LINETHICK0; DP:=MINDIFF;
NN:BARSLAST(DATE>REF(DATE,1)); tt0:=IF(10000*INTPART(CLOSETIME(0)/10000)=CLOSETIME(0),CLOSETIME(0)-5500,CLOSETIME(0)-1500); tt2:=(time>tt0+1500-500);
tb:=VALUEWHEN(tb=Kn,0); BK:=ref(cross(ma(c,5),ma(c,10)),1); SK:=ref(cross(ma(c,10),ma(c,5)),1); BK1:=ref(cross(ma(c,3),ma(c,8)),1); SK1:=ref(cross(ma(c,8),ma(c,3)),1);
tSELLSHORT(BK1 and tholding<0,KCS,lmt,DYNAINFO(21)+M*DP),ALLOWREPEAT; SELLSHORT(BK1 and holding<0,holding,limitr,O+M*DP);
tSELL(SK1 and tholding>0,KCS,lmt,DYNAINFO(20)-M*DP),ALLOWREPEAT; SELL( SK1 and holding>0,holding,limitr,O-M*DP); tb:=VALUEWHEN(tb=Kn,0);
if time>92500 and time<145000 and bk and holding>=0 and not(date>ref(date,1)) and tholding<Kn*KCS then begin tBUY(1,KCS,lmt,DYNAINFO(21)+M*DP),ALLOWREPEAT; tb:=tb+1; SLEEP(250); end BUY(time>92500 and time<145000 and BK and holding>=0 and not(date>ref(date,1)),KN*KCS,limitr,O+M*DP);
if time>92500 and time<145000 and SK and tholding<=0 and not(date>ref(date,1)) and tb<Kn then begin tBUYSHORT(1,KCS,lmt,DYNAINFO(20)-M*DP),ALLOWREPEAT; tb:=tb+1; SLEEP(250); end BUYSHORT(time>92500 and time<145000 and SK and holding<=0 and not(date>ref(date,1)),KN*KCS,limitr,O-M*DP);
if tb=Kn-1 then SLEEP(300);
if tb>0 then begin DEBUGFILE(\'D:\\file001.TXT\',\'TB:\'+NUMTOSTR(tb,1)+\' 虚盈:\'+NUMTOSTR(OPENPROFIT,1)+\' 今持:\'+NUMTOSTR(TODAYHOLDING,0)+\',持仓:\'+NUMTOSTR(THOLDING,0)+\' 定价:\'+NUMTOSTR(C,0)+\'/ \'+NUMTOSTR(C,0)+\' 虚持:\'+NUMTOSTR(HOLDING,0)+\',虚type:\'+NUMTOSTR(TYPE(1),0)+\' type: %.0f\',tTYPE(1)); end tb0:tb; IF tt2 THEN BEGIN tSELL(HOLDING>0,holding,lmt,DYNAINFO(20)-M*DP); tSELLSHORT(HOLDING<0,holding,lmt,DYNAINFO(21)+M*DP); 收多:SELL(HOLDING>0,holding,limitr,C-M*DP); 收空:SELLSHORT(HOLDING<0,holding,limitr,C+M*DP); END
总数: TOTALTRADE,LINETHICK0; 盈利:NUMWINTRADE,LINETHICK0; 胜率:ROUNDS(100*PERCENTWIN,1),LINETHICK0; 连亏:MAXSEQLOSS,LINETHICK0; 连盈:MAXSEQWIN,LINETHICK0;
|
-- 作者:smarter
-- 发布时间:2012/4/17 18:45:04
--
以下是引用admin在2012-4-16 19:50:56的发言:
提供一个简单的思路,再所有多TB变量赋值的地方,都加上DEBUGFILE记录标志,然后看运行的TB变量变化,发现问题的地方,之前的变量再依次进行记录跟踪,很容易就能最后找到问题
GLOBALVARIABLE:tb1=0,tb=0,ts=0; input:KCS(1,1,100,1),KN(3,1,15,1),M(1,0,30,1); 资产:ASSET,NOAXIS,LINETHICK0; 持仓:HOLDING,LINETHICK0; DP:=MINDIFF; tt0:=IF(10000*INTPART(CLOSETIME(0)/10000)=CLOSETIME(0),CLOSETIME(0)-5500,CLOSETIME(0)-1500); tt2:=(time>tt0+1500-500); BK:=ref(cross(ma(c,5),ma(c,10)),1); SK:=ref(cross(ma(c,10),ma(c,5)),1); BK1:=ref(cross(ma(c,3),ma(c,8)),1); SK1:=ref(cross(ma(c,8),ma(c,3)),1);
tSELLSHORT(BK1 and tholding<0,KCS,lmt,DYNAINFO(21)+M*DP),ALLOWREPEAT; SELLSHORT(BK1 and holding<0,holding,limitr,O+M*DP);
tSELL(SK1 and tholding>0,KCS,lmt,DYNAINFO(20)-M*DP),ALLOWREPEAT; SELL(SK1 and holding>0,holding,limitr,O-M*DP);
if time>91500 and bk and holding>=0 and not(date>ref(date,1)) and tb<Kn then begin tBUY(1,KCS,lmt,DYNAINFO(21)+M*DP),ALLOWREPEAT; tb:=tb+1; ts:=ts+1; DEBUGFILE(\'D:\\file005.TXT\',\'多TB:\'+NUMTOSTR(tb,0)+\',持仓:\'+NUMTOSTR(THOLDING,0)+\' 定价:\'+NUMTOSTR(C,2)+\'/ 虚持:\'+NUMTOSTR(HOLDING,0)+\',ts:\'+NUMTOSTR(ts,0)+\' Kn: %.0f\',Kn); SLEEP(250); end if NOT(BK) then begin //DEBUGFILE(\'D:\\file005.TXT\',\' TB=0 :\'+NUMTOSTR(tb,0)+\',持仓:\'+NUMTOSTR(THOLDING,0)+\' 定价:\'+NUMTOSTR(C,2)+\'/ 虚持:\'+NUMTOSTR(HOLDING,0)+\',虚type:\'+NUMTOSTR(TYPE(1),0)+\' Kn: %.0f\',Kn); tb:=0; end BUY(time>91500 and BK and holding>=0 and not(date>ref(date,1)),KN*KCS,limitr,O+M*DP);
if time>91500 and SK and tholding<=0 and not(date>ref(date,1)) and tb1<Kn then begin tBUYSHORT(1,KCS,lmt,DYNAINFO(20)-M*DP),ALLOWREPEAT; tb1:=tb1+1; ts:=ts+1; DEBUGFILE(\'D:\\file005.TXT\',\'空TB1:\'+NUMTOSTR(tb1,0)+\',持仓:\'+NUMTOSTR(THOLDING,0)+\' 定价:\'+NUMTOSTR(C,2)+\'/ 虚持:\'+NUMTOSTR(HOLDING,0)+\',ts:\'+NUMTOSTR(ts,0)+\' Kn: %.0f\',Kn); SLEEP(250); end if NOT(SK) then begin //DEBUGFILE(\'D:\\file005.TXT\',\' TB1=0 :\'+NUMTOSTR(tb,0)+\',持仓:\'+NUMTOSTR(THOLDING,0)+\' 定价:\'+NUMTOSTR(C,2)+\'/ 虚持:\'+NUMTOSTR(HOLDING,0)+\',虚type:\'+NUMTOSTR(TYPE(1),0)+\' Kn: %.0f\',Kn); tb1:=0; end BUYSHORT(time>91500 and SK and holding<=0 and not(date>ref(date,1)),KN*KCS,limitr,O-M*DP); 按您的意思, file005的结果为:
2012-04-17 18:31:05.546 多TB:1,持仓:0 定价:1370.75/ 虚持:0,ts:4753 Kn: 3 2012-04-17 18:31:05.671 多TB:1,持仓:0 定价:1370.75/ 虚持:0,ts:5698 Kn: 3 2012-04-17 18:31:06.234 多TB:1,持仓:0 定价:1370.75/ 虚持:0,ts:5726 Kn: 3 2012-04-17 18:31:06.250 多TB:1,持仓:0 定价:1370.75/ 虚持:0,ts:4781 Kn: 3 2012-04-17 18:31:06.718 多TB:1,持仓:1 定价:1370.75/ 虚持:0,ts:4809 Kn: 3 2012-04-17 18:31:06.937 多TB:1,持仓:1 定价:1370.75/ 虚持:0,ts:5754 Kn: 3 2012-04-17 18:31:07.359 多TB:1,持仓:2 定价:1370.75/ 虚持:0,ts:4837 Kn: 3 2012-04-17 18:31:07.609 多TB:1,持仓:2 定价:1370.75/ 虚持:0,ts:5782 Kn: 3 2012-04-17 18:31:07.921 多TB:1,持仓:3 定价:1370.75/ 虚持:0,ts:4865 Kn: 3 2012-04-17 18:31:08.171 多TB:1,持仓:3 定价:1370.75/ 虚持:0,ts:5810 Kn: 3 2012-04-17 18:31:08.484 多TB:1,持仓:4 定价:1370.75/ 虚持:0,ts:4893 Kn: 3 2012-04-17 18:31:09.234 多TB:1,持仓:4 定价:1370.75/ 虚持:0,ts:4921 Kn: 3 2012-04-17 18:31:09.437 多TB:1,持仓:4 定价:1370.75/ 虚持:0,ts:5838 Kn: 3 2012-04-17 18:31:09.828 多TB:1,持仓:4 定价:1370.75/ 虚持:0,ts:4949 Kn: 3 2012-04-17 18:31:10.437 多TB:1,持仓:6 定价:1370.75/ 虚持:0,ts:4977 Kn: 3 2012-04-17 18:31:10.671 多TB:1,持仓:6 定价:1370.75/ 虚持:0,ts:5866 Kn: 3 2012-04-17 18:31:11.015 多TB:1,持仓:6 定价:1370.75/ 虚持:0,ts:5005 Kn: 3 2012-04-17 18:31:11.625 多TB:1,持仓:7 定价:1370.75/ 虚持:0,ts:5033 Kn: 3 2012-04-17 18:31:11.859 多TB:1,持仓:7 定价:1370.75/ 虚持:0,ts:5894 Kn: 3 2012-04-17 18:31:12.140 多TB:1,持仓:7 定价:1371.00/ 虚持:0,ts:5061 Kn: 3 2012-04-17 18:31:12.390 多TB:1,持仓:7 定价:1371.00/ 虚持:0,ts:5922 Kn: 3 2012-04-17 18:31:12.625 多TB:1,持仓:8 定价:1371.00/ 虚持:0,ts:5089 Kn: 3 2012-04-17 18:31:13.375 多TB:1,持仓:9 定价:1371.00/ 虚持:0,ts:5117 Kn: 3 2012-04-17 18:31:13.625 多TB:1,持仓:9 定价:1371.00/ 虚持:0,ts:5950 Kn: 3 2012-04-17 18:31:14.562 多TB:1,持仓:10 定价:1371.00/ 虚持:0,ts:5145 Kn: 3 2012-04-17 18:31:14.812 多TB:1,持仓:10 定价:1371.00/ 虚持:0,ts:5978 Kn: 3 2012-04-17 18:31:15.109 多TB:1,持仓:10 定价:1371.00/ 虚持:0,ts:5173 Kn: 3 2012-04-17 18:31:15.359 多TB:1,持仓:10 定价:1371.00/ 虚持:0,ts:6006 Kn: 3 2012-04-17 18:31:15.593 多TB:1,持仓:11 定价:1371.00/ 虚持:0,ts:5201 Kn: 3 2012-04-17 18:31:16.375 多TB:1,持仓:12 定价:1371.00/ 虚持:0,ts:5229 Kn: 3 2012-04-17 18:31:16.515 多TB:1,持仓:12 定价:1371.00/ 虚持:0,ts:6034 Kn: 3 2012-04-17 18:31:17.156 多TB:1,持仓:13 定价:1370.75/ 虚持:0,ts:5257 Kn: 3 2012-04-17 18:31:17.406 多TB:1,持仓:13 定价:1370.75/ 虚持:0,ts:6062 Kn: 3 2012-04-17 18:31:17.562 多TB:1,持仓:13 定价:1370.75/ 虚持:0,ts:5285 Kn: 3
请指教! 谢谢!
|