XQ新手 ,請問小編 我想設置當我平倉後10-15分鐘內不再繼續交易 避免追單的情況 請問該怎麼寫 還是有高手 求帶
平倉後 ,10分鐘內不交易
- 141
- 最後發表 金融市場新手 2022 二月 28
Hello 金融市場新手,
簡單的方式是您可以設變數紀錄出場後經過的Bar數,如果您是使用1分鐘Bar的話就是經過10根才可以再交易。
舉例來說:
var: count(10);
count += 1;
condition1 = 進場條件...;
condition2 = count >= 10;
condition3 = position = 0 and filled = 0;
if condition1 and condition2 and condition3 then setposition(1, market);
condition4 = 出場條件...;
condition5 = position <> 0 and filled <> 0;
if condition4 and condition5 then begin
setposition(0, market);
count = 0;
end;
這樣count在每次出場後就會被重置,要過10根Bar才能夠再度進場。
另外一種方法是您使用交易函數取得最後一筆平倉交易的時間加上10分鐘,然後再和當下時間相比:
if position = 0 and filled = 0 then begin
if FilledRecordCount = 0 then condition1 = True
else if currenttime >= timeadd(FilledRecordTime(FilledRecordCount), "M", 10) then condition1 = True
else condition1 = False;
end;
這樣condition1 就會在部位庫存為0時計算距離上一筆交易是否有過10分鐘,超過才會交易。
網站上有教學區,裡面有XS語法的基礎與應用可供閱覽。
感謝小編
2 評論