我試著將現股自動交易的腳本拿來用在期貨交易上
編譯出來沒問題
但是回測執行商品卻是失敗的
進場邏輯也是用最簡單的
\\現價>前一分K收盤價,買進1口
出場邏輯
\\以進場價為基準,往上5TICK獲利出場
\\以進場價為基準,往下5TICK停損出場
var:plratio(0),InCondition(False),OutCondition(False);
var: price_change(0);
if barfreq <> "MIN" and barinterval <> 1 then raiseruntimeerror("請使用1分鐘頻率");
//進場
InCondition = close>close[1] ;
if position = 0 and filled = 0 and InCondition then setposition(1);
//以買進價為基準,獲利5檔出場或虧損5檔出場
if position > 0 and filled > 0 then begin
if high >= addspread(filledavgprice, 5) then begin
setposition(0, addspread(filledavgprice, 5), label:="獲利出場");
print("獲利出場", date, time, filledavgprice,addspread(filledavgprice, 5));
end
else if low <= addspread(filledavgprice, -5)then begin
setposition(0, addspread(filledavgprice, -5), label:="虧損出場");
print("虧損出場", date, time, filledavgprice, addspread(filledavgprice, -5));
end;
end;
1 評論