MACD語法問題

  •   292 
  • 最後發表   乾麵  2025 五月 19
乾麵 發文於   2025/05/18

    if oscValue < 0 and difValue > difValue[1] then begin

        setposition(1);

    end

    else if oscValue > 0 and difValue < difValue[1] then begin

        setposition(0);

    end;

 

    if oscValue > 0 and difValue < difValue[1] then begin

        setposition(-1);

    end

    else if oscValue < 0 and difValue > difValue[1] then begin

        setposition(0);

end;

請教前輩,此寫法回測無空單紀錄,是否哪個步驟寫錯請指教 感謝

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/05/18

你沒發覺下面這兩段程式碼都一樣嗎?這樣的話,當然後面的程式碼就沒有機會執行。

else if oscValue > 0 and difValue < difValue[1] then begin

        setposition(0);

    end;

 

    if oscValue > 0 and difValue < difValue[1] then begin

        setposition(-1);

    end

乾麵 發文於   2025/05/18

教授好,請問如果想多空分開的話是否能建議如何處理,還是必須分開兩個腳本

虎科大許教授 發文於   2025/05/18

寫在同一個腳本就可以了,而且你的需求,只需要用兩行指令即可。

if oscValue < 0 and difValue > difValue[1] then setposition(1);
if oscValue > 0 and difValue < difValue[1] then setposition(-1);

乾麵 發文於   2025/05/18

感謝教授指導,回測後發覺策略跟想的有點出入,想辦法優化中 謝謝

虎科大許教授 發文於   2025/05/19

考慮到可能重複下無效單,在下單之前應使用部位控制。

if position<=0 and oscValue < 0 and difValue > difValue[1] then setposition(1);

if position>=0 and oscValue > 0 and difValue < difValue[1] then setposition(-1);

發表回覆
Close