你的M手也是通过策略计算出来的,那每次买卖都是以M为准的,那holding的值与你的M的值应该是相等的。你是需要M值一但发生变,不管我的开平仓条件是否满足,就进行相应的调整仓位?
可以参考下如下代码:
if M<>HOLDING THEN
begin
if M>0 and holding>0 then
begin
if M>holding then buy(1,m-holding,market);
if m<holding then sell(1,holding-m,market);
end
if M<0 and holding<0 then
begin
if abs(M)>abs(holding) then buyshort(1,abs(M)-abs(holding),market);
if abs(M)<abs(holding) then sellshort(1,abs(M)-abs(holding),market);
end
if M>0 and holding<0 then
begin
SELLSHORT(1,holding,MARKET);
buy(1,M,MARKET);
end
if M<0 and holding>0 then
begin
SELL(1,holding,MARKET);
buyshort(1,abs(M),MARKET);
end
end