策略雷達連續觸發

  •   117 
  • 最後發表   bowen  2024 三月 21
bowen 發文於   2024/03/20

頻率:1K   觸發設定:連續觸發 逐筆洗價

假設訊號:condition1

var:intraBarPersist condition1_bar(0);
if condition1 and currentBar <> condition1_bar then begin condition1_bar = currentBar; ret=1; end;

這樣的寫法,可以在連續觸發的環境下,達成K棒內單次觸發。

現在的問題是,如果再開啟策略之前,condition1已經達成,在開啟策略後,警示紀錄是不會有訊號跑出來,

應該是已經 currentBar = condition1_bar的問題,但我想要的是開啟策略時重新計算,

所以改寫:

var:intraBarPersist condition1_bar(0);
once IsLastBar begin condition1_bar= 0; end;
if condition1 and currentBar <> condition1_bar then begin condition1_bar = currentBar; ret=1; end;

但發現還是不行,求解。

PS:因為很多訊號,才選擇觸發設定:連續觸發,全部寫在一個腳本裡,減少計算。

XS小編 發文於   2024/03/21

 Hello bowen,

 

您可以使用 GetInfo("IsRealTime") 來判斷是否為即時的區間,例如

if GetInfo("IsRealTime") = 1 then begin

    if condition1 and currentBar <> condition1_bar then begin 

        condition1_bar = currentBar; 

        ret=1; 

        end;

    end;

這樣就只有在即時的區間才會運行此段腳本。

 

另外 

if condition1 and currentBar <> condition1_bar then begin 

    condition1_bar = currentBar; 

    ret=1; 

    end;

這種寫法只會受到當根Bar是否有觸發影響,所以換Bar之後currentBar 就會和 condition1_bar 不同。

如果是一分鐘Bar的話影響應該有限。

 

  • 按讚來自於
  • Bowen16
發表回覆
Close