出場條件不會觸發

  •   272 
  • 最後發表   大A  2025 四月 02
大A 發文於   2025/04/02

執行頻率1分K,未開逐筆洗價,

if barfreq<>"Min"or barinterval<>1 then return;

condition1= trueall(close>close[1],3) and volume>2500;

condition2=volume>2000;

if currenttime>=090000 and currenttime<120000 then begin

if condition1 then begin

if position=0 and filled=0 then begin setposition(-1,market);

end;

if position=-1 and filled=-1 and condition2  

 then begin setposition(0,market);

end;

end;

end;

檢查的時候發現系統對volume的條件只會觸發volume>2500,對volume>2000這個條件不會觸發,請問語法應該怎麼修正?

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

(1)1分鐘頻率之下,volume是1分鐘的成交量。

(2)condition1是連續三根1分K上漲且成交量大於2500。這個條件符合時,會判斷,空手時就進場放空,有空頭部位時且成交量大於2000(能跑到這裡,亦即大於2500,代表大於2000一定成立),就平倉空手。

(3)你的問題不是condition2不會觸發,而是同時也要連續三根1分K上漲才會平倉回補空頭部位。

(4)改成下面的寫法,應該就能解決你的問題。

if barfreq<>"Min"or barinterval<>1 then return;
condition1= trueall(close>close[1],3) and volume>2500;
condition2=volume>2000;
if currenttime>=090000 and currenttime<120000 then 
    begin
        if position=0 and filled=0 and condition1 then 
            setposition(-1,market);
        if position=-1 and filled=-1 and condition2 then 
            setposition(0,market);
    end;

大A 發文於   2025/04/02

感謝教授,已回測成功

發表回覆
Close