請問條件設定60分K,只會進場一次怎麼寫,下一次進場需要下一根60分K才進場

  •   192 
  • 最後發表   OOwen  2022 二月 21
OOwen 發文於   2022/02/04

小編您好

if filledrecordCount <> 0 and position = 0 then begin

value9  = filledrecordDate(filledrecordCount);

value10 = filledrecordTime(filledrecordCount);

end;

condition21 = (date = value9 and currentTime >= timeAdd(value10,"H",1)) or date <> value9 or (filledRecordCount=0);

 

我目前這樣寫,但用[自動交易回測]還是會有異常,不知道是哪裡錯誤

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/02/08

Hello OOwen,

 

如果您是使用60分鐘頻率,然後1根Bar只能進場一次的話,小幫手會使用 intrabarpersist 的變數來記錄進場的那根 Bar 的時間,如果時間有變化才能夠進場。

舉例來說:

var: intrabarpersist _entry(0);

condition1 = 進場條件...;

condition2 = _entry <> time;

condition3 = 出場條件...;

 

if condition1 and condition2 then begin

    setposition(1, market);

    _entry = time;

    end;

 

if condition2 then setposition(0, market);

這樣每根Bar最多就只會進場一次。

 

另外小幫手測試您的condition21應該也是可以達到類似的效果,不過是要間隔至少60分鐘,而不是下一根Bar。

所以可能會發生 12:40 的時候進場,但下一根Bar(13:00)沒辦法進場的狀況。

想詢問下您的異常指的是怎麼樣的狀況?

OOwen 發文於   2022/02/17

小編您好:

請問

var: intrabarpersist _entry(0);

condition1 = 進場條件...;

condition2 = _entry <> time;

condition3 = 出場條件...;

 

if condition1 and condition2 then begin

    setposition(1, market);

    _entry = time;

    end;

 

if condition2 then setposition(0, market);  <<請問這個出場條件是否應該為condition3而不是condition2

XQ小幫手 發文於   2022/02/21

Hello OOwen,

 

是的。

那部份是出場的語法,所以是要搭配condition3 出場條件才對。

發表回覆
Close