这是一个图表交易程序:
ma5:=ma(c,5);
ma10:=ma(c,10);
if cross(ma5,ma10) then
begin
sellshort(1,abs(holding),limitr,c);
buy(holding=0,1,limitr,c);
end
if cross(ma10,ma5) then
begin
sell(1,holding,limitr,c);
buyshort(holding=0,1,limitr.c);
end
正常情况下,如果改为后台应该是这样的:
ma5:=ma(c,5);
ma10:=ma(c,10);
if tholding<=0 and cross(ma5,ma10) then
begin
tsellshort(1,1,lmt,c);
tbuy(1,1,lmt,c);
end
if tholding>=0 and cross(ma10,ma5) then
begin
tsell(1,1,lmt,c);
tbuyshort(1,1,lmt.c);
end
我为了取得这个程序的理论持仓并作为交易条件。后台程序变成这样:
ma5:=ma(c,5);
ma10:=ma(c,10);
if cross(ma5,ma10) then
begin
tsellshort(1,abs(holding),lmt,c);
sellshort(1,abs(holding),limitr,c);
tbuy(holding=0,1,lmt,c);
buy(holding=0,1,limitr,c);
end
if cross(ma10,ma5) then
begin
tsell(1,holding,lmt,c);
sell(1,holding,limitr,c);
tbuyshort(holding=0,1,lmt.c);
buyshort(holding=0,1,limitr,c);
end
这样在后台程序中同时使用图表函数holding,会不会导致其他我没法考虑到的问题。当然在后台启动之前,我会人工调整理论持仓和实际持仓一致。
if cross(ma5,ma10) and holding<0 then
begin
tsellshort(1,abs(holding),lmt,c);
sellshort(1,abs(holding),limitr,c);
tbuy(holding=0,1,lmt,c);
buy(holding=0,1,limitr,c);
end
条件加一个holding<0以及开多时候加个holding>0条件
好的,那么holding 用于后台应该也没有问题吧?
没有问题的, 注意下后台有参与计算k数量,这个和图表上参与计算的数量是一个道理
对于一些跨日策略,你的样本数量不同可能会造成当前holding不同