使用變數來計算次數

  •   153 
  • 最後發表   Arider  2022 九月 26
Arider 發文於   2022/09/18

您好,

我的寫法和預設情境一直不符,請教您正確的寫法,謝謝!

我有兩個進場條件create1和create2,想一天內,符合這兩個其一情況下,就short一次,最多一天short 兩次,我用了countshort來控制次數,但出現結果仍然在一天內超過2次以上的進場。

var:countshort(0);

countshort = 0;

if create1 and countshort  < 2 then begin

short(1);

countshort += 1;

end;

 

if create2 and countshort  < 2 then begin

short(1);

countshort += 1;

end;

 

if EnterMarketCloseTime(2)  then setposition(0);

我有其他策略會在某些情況下出場,所以filledrecordcount或filled或position不太適用。麻煩針對用變數計算次數這部分教教我,感謝!

排序方式: 標準 | 最新
貓市 發文於   2022/09/19

可以試試看countshort宣告成IntraBarPersist

http://xshelp.xq.com.tw/XSHelp/?HelpName=IntraBarPersist&group=DECLARATION

XQ小幫手 發文於   2022/09/26

Hello Arider,

 

若您有使用逐筆洗價的話,會建議您參考 貓市 的作法,將變數設為 intrabarpersist

運作邏輯細節可以參考函數說明。

 

另外,就小幫手所知,filledrecordcount、filled、position、這些函數都是獨立的數值,不同策略是不會共用的。

所以在A策略運作時,B策略或手動操作的買進賣出是不會影響到A策略的filled和position。

發表回覆
Close