Option 發表於 18-3-25 15:58

加減碼語法

大家好我現在有4條件,分別是condition1, condition2, condition3 和 condition4 想要 condition1 and condition3 有三口多單condition1 and condition4 有一口多單condition2 and condition4 有一口空單condition2 and condition3 有三口空單請問語法該怎麼撰寫呢?以下是我自己寫的var : MP(0);MP = marketposition*currentcontracts;if MP = 0 then begin
if condition1 and condition3 then buy 3 shares next bar close stop;
if condition1 and condition4 then buy 1 shares next bar close stop;
if condition2 and condition4 then sellshort 1 shares next bar close stop;
if condition2 and condition3 then sellshort 3 shares next bar close stop;
end;

if MP = 3 then begin
if condition1 and condition4 then sell 2 shares next bar close stop;
if condition2 and condition4 then sellshort 1 shares next bar close stop;
if condition2 and condition3 then sellshort 3 shares next bar close stop;
end;

if MP = 1 then begin
if condition1 and condition3 then buy 2 shares next bar close stop;
if condition2 and condition4 then sellshort 1 shares next bar close stop;
if condition2 and condition3 then sellshort 3 shares next bar close stop;
end;

if MP = -1 then begin
if condition1 and condition4 then buy 1 shares next bar close stop;
if condition1 and condition3 then buy 3 shares next bar close stop;
if condition2 and condition3 then sellshort 2 shares next bar close stop;
end;

if MP = -3 then begin
if condition2 and condition4 then buytocover 2 shares next bar close stop;
if condition1 and condition4 then buy 1 shares next bar close stop;
if condition1 and condition3 then buy 3 shares next bar close stop;
end;

回測後發現是不對的,例如原本三口空單時,condition2 and condition4會先出掉兩口變成一口沒錯,但後來遇到condition2 and condition3時,不會再進兩口空單變三口

不知道大家看不看的懂,煩請高手們幫小弟解惑,謝謝

頁: [1]
查看完整版本: 加減碼語法