請問一下,我設定交易達標1.5%就賣出,進場沒有問題,但是出場我回測結果,有符合條件卻一直持有到尾盤,請問是什麼原因? 我最後print的結果,position跟filled一直都是庫存數量,都沒有變0....
我的程式碼如下:
input: keyPrice(10,"關鍵價,需手動設定");
input: amount(100, "每筆交易金額(萬)");
//進場設定
if time>=090500 and time < 132000 and position=0 and filled=0 then
begin
if close cross above keyPrice
then begin
var: order_price(0);{ 預期委託價格 }
var: entry_position (0);{ 換算後數量 }
order_price = AddSpread(Close, 1);
entry_position = (amount * 10000) / (order_price * 1000);
SetPosition(entry_position , market);{ 以市價買入指定數量 }
end;
end;
//出場設定
//停損為2.5%
if Position > 0 and filled > 0 then begin
//開始出場
if close <= filledavgprice * 0.975 then SetPosition(0); { 停損,清空庫存 }
if close >= filledavgprice * 1.015 and position = entry_position then
SetPosition(0, market);//出場,停利1.5%
print("1.5%停利,剩下庫存為Position=",Position,"filled=",filled);
end;

1 評論