为了测试采用后台程序化交易的策略,采用了固定轮询的方式,编写如下代码记录输出结果;
(hiAfterEntry 想记录持仓后,该股票的最高价,Lmaxprofit为最高价格减去平均买入价)
debugfile('E:\金融数据分析\TEST.TXT','当前交易股票代码为 : ' +stklabel,0);
if THOLDING >0 and Tenterbars = 0 then
begin
hiAfterEntry := high;
Lmaxprofit := hiafterentry - Tavgenterprice;
end
if THOLDING > 0 and Tenterbars>=1 then
begin
hiAfterEntry := max(hiAfterEntry, high);
Lmaxprofit := hiafterentry - Tavgenterprice;
end
DEBUGFILE('E:\金融数据分析\TEST.TXT','进场价格%.3f',TAVGENTERPRICE);
DEBUGFILE('E:\金融数据分析\TEST.TXT','最高价格%.3f',hiafterentry);
DEBUGFILE('E:\金融数据分析\TEST.TXT','最大利润%.3f',Lmaxprofit);
采用上述代码,进行txt输出 得到
2016-10-12 09:53:22.652 当前交易股票代码为 : 603618
2016-10-12 09:53:22.657 进场价格14.290
2016-10-12 09:53:22.658 最高价格34.380
2016-10-12 09:53:22.658 最大利润20.090
2016-10-12 09:53:22.707 当前交易股票代码为 : 603328
2016-10-12 09:53:22.709 进场价格28.790
2016-10-12 09:53:22.711 最高价格34.380
2016-10-12 09:53:22.711 最大利润5.590
为什么在轮询模式下,策略运行在不同的股票上,定义的最高价格hiafterentry这个变量,输出的却是一样的。这个最高价格,并没有记录到当前轮询的股票的最高价格。
就是在如下的代码中,定义了hiAfterEntry 与Lmaxprofit 这个变量
if THOLDING >0 and Tenterbars = 0 then
begin
hiAfterEntry := high;
Lmaxprofit := hiafterentry - Tavgenterprice;
end
if THOLDING > 0 and Tenterbars>=1 then
begin
hiAfterEntry := max(hiAfterEntry, high);
Lmaxprofit := hiafterentry - Tavgenterprice;
end
当策略运行不同的股票, 这个hiAfterEntry 应该不一样,应该策略再运行每个股票时都记录了本只股票的hiAfterEntry 的值,但是从目前输出的结果看来,
hiAfterEntry := max(hiAfterEntry, high);这条语句中hiAfterEntry在不同股票的轮询过程采用的是同一个值。
管理员,您好,我没有在别的地方定义这两个变量,就是在如下语句中定义了这个变量;
if THOLDING >0 and Tenterbars = 0 then
begin
hiAfterEntry := high;
Lmaxprofit := hiafterentry - Tavgenterprice;
end
if THOLDING > 0 and Tenterbars>=1 then
begin
hiAfterEntry := max(hiAfterEntry, high);
Lmaxprofit := hiafterentry - Tavgenterprice;
end
gloablvariable:hiAfterEntry=0, Lmaxprofit=0;
这两个变量要这样定义,你再试试