假設我寫了個空方策略,有辦法在xs寫:如果30分鐘內都沒觸發,策略就通知我 今天無標的符合
Hello alexw,
您可以用變數保存腳本剛啟動時的 currenttime 和 策略是否有觸發過,並用 timeadd 來計算30分鐘後的時間。
接下來只要當下時間超過限制就警示。
舉例來說:
var: intraBarPersist sTime(0), intraBarPersist lTime(0), intraBarPersist retRecord(0);
once begin
sTime = currentTime;
lTime = timeadd(sTime, "M", 30);
end;
condition1 = 觸發條件;
if condition1 then retRecord = 1;
if currenttime >= lTime and retRecord = 0 then begin
ret = 1;
retmsg("策略啟動過了30分鐘");
end;
所以原來的 if condition1 then ret=1保留,再加上上面那一段就ok?
Hello alexw,
正確來說,原本的觸發條件應該修改為:
condition1 = 觸發條件;
if condition1 then begin
retRecord = 1;
ret = 1;
end;
retRecord 是紀錄該警示條件是否有被觸發過。
另外需注意,腳本要運作在即時的狀態才可以確保 sTime 取得策略啟動的時間,所以可以加上 GetInfo 來判斷。
所以可以修改為:
once (GetInfo("IsRealTime") = 0) begin
sTime = currentTime;
lTime = timeadd(sTime, "M", 30);
end;
var: intraBarPersist sTime(0), intraBarPersist lTime(0), intraBarPersist retRecord(0);
once begin
sTime = currentTime;
lTime = timeadd(sTime, "M", 5);
end;
condition2 = close<GetField("收盤價","D")[1];
if condition2 then retRecord = 1;
if currenttime >= lTime and retRecord = 0 then condition3= false;
if currenttime >= lTime and retRecord = 1 then condition3= true;
請小幫手 協助判斷 依此撰寫思路,
可否達成 開盤前5分鐘 是跌的狀態?
Hello 散散惹人愛,
lTime 會是策略啟動後第一次運算的時間加上5分鐘。
所以不一定會是開盤後的5分鐘。
另外 retRecord 只要 close<GetField("收盤價","D")[1] 有達成過就會是1,就算是更早以前的資料也是。
小幫手認為有更簡單的寫法,舉例來說如果您使用在1分鐘頻率上的話:
if getfield("Time", "5") = 090000 then condition1 = getfield("Close", "5") < getfield("Close","D")[1];
這樣condition1 就會是當天第一根5分鐘Bar的收盤價是否有小於前日收盤價。

感謝 小幫手的指正,但小幫手的方法可能稍微無法靈活運用
,抱歉一開始說明的不夠清楚。
依照圖示,本想要達成的較為接近這張圖
也就是開盤後 一段時間,可能均是處於跌的狀態【跌幅不限】
忽然之間,上漲 過 開盤價以及 開盤後第一根5分K 高點 綠轉紅的那個買點
例如:
if closeD(0)>OPEND(0) then condition1=true;
var: price_5mh(0);
var: barcount(0);
if date <> date[1] then price_5mh = high else if time < 090500 and price_5mh < high then price_5mh = high;
if time = 090600 then price_5mh = getfield("High", "5");
if closeD(0)> price_5mh then condition2 = true;
if condition1 and condition2 = true then condition3 =true;
StandUP=condition3;
Hello 散散惹人愛,
如果您要開盤前5分鐘的價格不高於當日開盤價的話,只要判斷第一根5分鐘Bar的高點是否有低於等於當日開盤價就可以了。
舉例來說,在1分鐘頻率的狀況下:
if time = 090400 then condition1 = getfield("High", "5") <= getfield("Open","D");
這樣 condition1 在09:05以後就會是當日前5分鐘是否不高於開盤價。
需注意第一根5分鐘Bar會包含當日開盤價,且 XS 的 time 會是 Bar 開始的時間。
若是要確保除了開盤價外的所有價格都低於開盤價的話,那麼就需要比較到Tick頻率的資料,
可以使用 Seqno 判斷有經過多少Tick。
但小幫手不建議這麼作,因為會比較耗效能。
7 評論