目前我是用k棒來計算,條件已觸發,但超過幾根k棒還沒進場,則不進場
但試起來 還是沒辦法順利動作 請各位前輩看看下面兩個寫法哪裡出問題
input:in_bar;
var:count_in(0);
condition1=進場條件;
condition2=出場條件;
1.
if FilledAvgPrice <> 0 then
count_in = 0 ;
if condition1 and FilledAvgPrice = 0 then
count_in += 1; //進場條件觸發,還沒買進,每過1根k就+1,以此計算經過幾根k棒
if condition2 and FilledAvgPrice = 0 then
count_in=0; //出場後 k棒計算歸0
if condition1 and FilledAvgPrice = 0 and count_in > in_bar then
setposition(o); //進場條件觸發,還沒進場前,若經過k棒的數量大於設定數量,則不進場
end;
2.
if condition1 and FilledAvgPrice = 0 then
count_in=currentBar; //進場條件觸發,還沒買進,以現在k棒當成第1根k
if condition2 and FilledAvgPrice = 0 then
count_in=0; //出場後 k棒計算歸0
if condition1 and FilledAvgPrice = 0 and currentBar > count_in + in_bar then
setposition(o); //進場條件觸發,還沒進場前,若經過k棒的數量大於設定數量,則不進場
end;
13 評論