//自动分割法
IT:=INTPART(ABS(HOLDING)/500);
YL:=MOD(ABS(HOLDING),500);
IF IT>0 THEN BEGIN
FOR i=1 to IT DO BEGIN
SELL(开多平 and holding>0,500,LIMITR,开盘多平价);
sell(动态多平1 and holding>0,500,LIMITR,if(ISLASTBAR,(多损位置1)-2*hd,(多损位置1)-1*hd)),colorred;
sell(动态多平2 and holding>0,500,LIMITR,if(ISLASTBAR,(多损位置2)-2*hd,(多损位置2)-1*hd)),colorred;
sell(动态多平3 and holding>0,500,LIMITR,if(ISLASTBAR,(多损位置3)-2*hd,(多损位置3)-1*hd)),colorff00ff;
sell(动态多平4 and holding>0,500,LIMITR,if(ISLASTBAR,llv4-2*hd,llv4-1*hd)),colorred;
SELL(收多平 and holding>0,500,limitr,if(ISLASTBAR,c-2*hd,c-hd));
SELLSHORT(开空平 and holding<0,500,LIMITR,if(ISLASTBAR,o+2*hd,o+hd));
sellshort(动态空平1 and holding<0,500,LIMITR,if(ISLASTBAR,空损位置1+2*hd,空损位置1+1*hd)),colorgreen;
sellshort(动态空平2 and holding<0,500,LIMITR,if(ISLASTBAR,空损位置2+2*hd,空损位置2+1*hd)),colorgreen;
sellshort(动态空平3 and holding<0,500,LIMITR,if(ISLASTBAR,空损位置3+2*hd,空损位置3+1*hd)),colorgreen;
sellshort(动态空平4 and holding<0,500,LIMITR,if(ISLASTBAR,hhv4+2*hd,hhv4+1*hd)),colorff00ff;
SELLSHORT(收空平 and holding<0,500,limitr,if(ISLASTBAR,c+2*hd,c+hd));
end
end
//===================================================================================
IF yl>=0 THEN BEGIN
SELL(开多平 and holding>0,HOLDING,LIMITR,开盘多平价);
sell(动态多平1 and holding>0,holding,LIMITR,if(ISLASTBAR,多损位置1-2*hd,多损位置1-1*hd)),colorred;
sell(动态多平2 and holding>0,holding,LIMITR,if(ISLASTBAR,多损位置2-2*hd,多损位置2-1*hd)),colorred;
sell(动态多平3 and holding>0,holding,LIMITR,if(ISLASTBAR,多损位置3-2*hd,多损位置3-1*hd)),coloryellow;
sell(动态多平4 and holding>0,holding,LIMITR,if(ISLASTBAR,llv4-2*hd,llv4-1*hd)),colorred;
SELL(收多平 and holding>0,holding,limitr,收盘多平价);
sellshort(开空平 and holding<0,HOLDING,LIMITR,开盘空平价);
sellshort(动态空平1 and holding<0,holding,LIMITR,if(ISLASTBAR,空损位置1+2*hd,空损位置1+1*hd)),colorgreen;
sellshort(动态空平2 and holding<0,holding,LIMITR,if(ISLASTBAR,空损位置2+2*hd,空损位置2+1*hd)),coloryellow;
sellshort(动态空平3 and holding<0,holding,LIMITR,if(ISLASTBAR,空损位置3+2*hd,空损位置3+1*hd)),colorgreen;
sellshort(动态空平4 and holding<0,holding,LIMITR,if(ISLASTBAR,hhv4+2*hd,hhv4+1*hd)),colorff00ff;
sellshort(收空平 and holding<0,holding,limitr,收盘空平价);
end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//枚举法
if holding>500 and holding<=1000 then begin
//在总持仓大于500时,分小于等于1000、1500、2000、2500、3000几种情况。
SELL(开多平 ,holding-500,LIMITR,开盘多平价);//当仓位上升一个500档,这里的holding-500中的500递加500
SELL(开多平 ,500,LIMITR,开盘多平价);//当仓位上升一个500档,下一行多出一组相同代码。
sell(动态多平1,holding-500,LIMITR,sp1);
sell(动态多平1 ,500,LIMITR,sp1);
sell(动态多平2,holding-500,LIMITR,sp2);
sell(动态多平2 ,500,LIMITR,sp2);
sell(动态多平3,holding-500,LIMITR,sp3);
sell(动态多平3, 500,LIMITR,sp3);
sell(动态多平4,holding-500,LIMITR,sp4);
sell(动态多平4, 500,LIMITR,sp4);
SELL(收多平 ,holding-500,LIMITR,收盘多平价);
SELL(收多平 ,500,LIMITR,收盘多平价);
end
以上两种写法理应结果一样,但是在历史回测中枚举法多出了一百多万的利润。请问问题出在哪里
sp1,2,3,4对应 多损位置1,2,3,4等值
一个先平500后平29,另一个先平29后平500。顺序不同导致了不同的取整结果
需要多写一句调试语句,看看哪个被不同的取整了
SELL(开多平 ,holding-500,LIMITR,开盘多平价);//当仓位上升一个500档,这里的holding-500中的500递加500
n1:asset;
SELL(开多平 ,500,LIMITR,开盘多平价);//当仓位上升一个500档,下一行多出一组相同代码。
n2:asset;
这两句用来看每一次交易到底盈利了多少,看看是哪次交易的取整不一样