{@type:autotrade}
// 設定建議:1分鐘K、逐筆洗價、讀取500筆
// 商品選擇:FITX* (全盤)
Input: _RangeBar(180, "橫盤K棒數");
Input: _StopLoss(25, "停損點數");
Input: _TP_Offset(55, "第一口加點");
Var: IntrabarPersist HasBrokenBelow(false);
Var: IntrabarPersist TP1_Price(0);
Var: HH(0), LL(0);
// 強制系統讀取足夠的資料,解決回測時間消失的問題
SetTotalBar(_RangeBar + 50);
SetBarBack(_RangeBar);
// 1. 定義 180 根 K 棒高低點 (不含當前這根)
HH = Highest(High[1], _RangeBar);
LL = Lowest(Low[1], _RangeBar);
// 2. 進場邏輯 (無部位時)
if Position = 0 then begin
// 條件:收盤跌破 LL
if Close < LL then HasBrokenBelow = true;
// 條件:曾經跌破 + 站回 LL 之上
if HasBrokenBelow and Close > LL then begin
SetPosition(2, Market, label:="多單2口進場");
HasBrokenBelow = false;
// 第一口停利價:(高+低)/2 + 55 點
TP1_Price = (HH + LL) / 2 + _TP_Offset;
end;
end;
// 3. 持位管理
if Position > 0 then begin
// 第三 & 第四點:停損 25 點 (防守下單位置)
if Close <= FilledAvgPrice - _StopLoss then begin
SetPosition(0, Market, label:="停損防守出場");
// 停損出場後 Position 變 0,程式會自動回到第 2 段重新監控「跌破再收上」
end;
// 第五點:兩口出場機制
// 第一口:達標平倉
if Position = 2 and Close >= TP1_Price then begin
SetPosition(1, Market, label:="第一口停利");
end;
// 第二口:無腦放 (除非觸發停損)
end;
// 跨日重置 (夜盤 15:00 開始時清空紀錄)
if Date <> Date[1] then HasBrokenBelow = false;
請問一下不知道是否是語法有錯,跑回測時只有夜盤的訊號
1 評論