此次依腳本策略下,無任何庫存、進場一次,回測結果日K、1K,逐筆洗價、觸發即判斷成交的六種狀況都與實際不符
如附件
        
        
腳本如下
//先買後賣
if position=0 and filled=0 and opend(0) > closeD(1) and close<>getField("漲停價", "D") then setposition(1,market,label:="買1");//上漲先買
if position=1 and filled=1 and (close >= filledAvgPrice*1.005 or high >= filledAvgPrice+0.5 ) then setposition (0,close,label:="賣1");
//前一日有庫存先賣再買
if position[1]=1 and filled[1]=1 and openD(0) < closeD(1) then begin
setposition(0 ,market,label:="賣2");//下跌先賣
if position=1 and filled=1 and (close <= filledAvgPrice*0.995 or close <= filledAvgPrice-0.5) then
setposition(1,close,label:="買2");
end
else
begin
//無庫存先放空再回補
if position=0 and filled=0 and opend(0) < closed(1) then short(1 ,market,label:="賣3");//下跌先賣
if position=-1 and filled=-1 and (q_bestbid1 <= filledAvgPrice*0.995 or q_bestbid1 <= filledAvgPrice-0.5) then cover(1,q_bestbid1,label:="買3");
end;
Hello xqyi,
您可以參考小幫手在 XS語法 begin end的執行差異? 裡的回覆。
另外小幫手建議您在腳本中加上print並印出交易條件的相關數值,這樣在觀察腳本運作並發現腳本撰寫錯誤之處比較有幫助。
尤其是 position[1] 和 filled[1] 這會是上一根Bar結束時的數值而非上一次運算的數值,這種撰寫法很容易發生理解上的錯誤。
2 評論