COCO研究院

 找回密碼
 註冊
搜索
查看: 2738|回復: 0

[教學] 加減碼語法

[複製鏈接]
發表於 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時,不會再進兩口空單變三口

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

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-11-25 09:49

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |