警示項目與Print數量不符

  •   168 
  • 最後發表   simonwu31  2023 十月 11
simonwu31 發文於   2023/09/25

你好, 我用XS寫了第一分K開盤量警示, 語法如下, 警示觸發後並print出檔案, 但有個問題一直無法克服, 這警示的排程時間為08:55~09:10, 警示上的顯示只有第一個分K的計算, 但Print出來卻有很多檔案, 請問我要怎麼解決這件事, print資料請參考附件

 

 

value3 = average(getfield("Volume", "D")[1], 5); 

Var: Targetfilename("");

 

if date <> date[1] then begin 

value1=0;

end;

 

if time = 090000 and volume <> 0 and value1 = 0 then 

begin 

value1 = volume;

end 

 

else if time = 090200 and volume <> 0 and value1 = 0 then 

begin 

value1 = volume; 

    end; 

  

 

If value1 > value3 * 0.10 

and value1 < value3 * 0.20 

and value3 > 500 

and getinfo("isrealtime")=1 //避免錯誤訊號

 then begin 

ret=1; 

retmsg = "$大量"; 

Targetfilename = Text("D:\XQ\XQ2Line_beta-OpenV\Strategy\",

"$大量"," ",

Symbol," ",

SymbolName," ",

Numtostr(close,2)," ",

Numtostr(GetQuote("當日漲幅%"),1),"% ",

".txt");

 

Print(file(Targetfilename));

ret=1;

end; 

 

附加文件

排序方式: 標準 | 最新
XQ小幫手 發文於   2023/10/04

Hello simonwu31,

 

小幫手這邊不知道您的策略設定所以沒辦法確認,不過該腳本只要條件符合的話每次運算都會print資訊。

如果將策略設為啟動後只觸發一次的話,那麼是可能只顯示一次觸發,但其實腳本運算多次都符合且print的狀況。

您可以考慮用變數紀錄是否有警示過,若有的話則使用 raiseruntimeerror 中斷策略。

simonwu31 發文於   2023/10/04

謝謝小幫手, 請問raiseruntimeerror要怎麼寫, 才能將警示過的股票不要再進行print的動作,

我看不太懂內建函數說明,

是否可請小幫忙幫忙用上面的語法加上raiseruntimeerror給我參考, 謝謝喔

XQ小幫手 發文於   2023/10/11

Hello simonwu31,

 

raiseruntimeerror 是執行到時會直接中斷策略。

所以您的腳本的其中一部份可以修改為

var: intrabarpersist _count(0);

 

if _count > 0 then raiseruntimeerror("已觸發過1次");

 

If value1 > value3 * 0.10 

and value1 < value3 * 0.20 

and value3 > 500 

and getinfo("isrealtime")=1 //避免錯誤訊號

then begin 

retmsg = "$大量"; 

Targetfilename = Text("D:\XQ\XQ2Line_beta-OpenV\Strategy\",

"$大量"," ",

Symbol," ",

SymbolName," ",

Numtostr(close,2)," ",

Numtostr(GetQuote("當日漲幅%"),1),"% ",

".txt");

 

Print(file(Targetfilename));

_count += 1;

ret=1;

end; 

 

這樣 _count 只要觸發過就會增加,而增加後就會因 raiseruntimeerror 而中斷。

 

網站上有教學區,裡面有XS語法的基礎和應用可以閱覽。

發表回覆
Close