如果要經過一定 bar 數後刪單的話,可以用變數紀錄bar的位置來當作條件。
var: intrabarpersist _num(0);
condition1 = 您的進場條件;
if condition1 and position = 0 and filled = 0 then begin
setposition(1);
_num = currentbar;
end;
if position <> filled and (currentbar - _num) > 2 then begin
setposition(filled);
_num = 0;
end;
不在同支K進場的寫法,也是變數紀錄bar的位置來當作條件
var: intrabarpersist _barNum(0)
condition1 = 進場條件;
condition2 = 出場條件;
if condition1 and position = 0 and filled = 0 and _barNum <> currentbar then setposition(1, market);
if condition2 and position = 1 and filled = 1 then begin
setposition(0, market);
_barNum = currentbar;
end;
兩者的變數都是在計算bar的位置,如果將這兩種功能合併,可以只用一個變數即可嗎?還是得用兩個?
2 評論