指標都有訊號,但回測卻都是0,都沒成交

  •   3 
  • 最後發表   灰熊  1小時前
灰熊 發文於   2026/02/27

請問許教授,程式如下,指標都有箭頭買進跟賣出,但回測都沒任何成交,都是0,不知為何,再麻煩教授幫看一下

{

    腳本名稱:Supertrend 跨頻 KD 交易策略 (限定加碼 3 次)

    腳本類別:交易腳本

    建議頻率:60 分鐘 (60M)

}

 

input: 

    _ATR_Len(10, "ATR期數"), 

    _Mult(3.0, "ATR乘數"),

    _ATR_Mode(2, "ATR模式", InputKind:=Dict(["Wilder(RMA)", 1], ["Simple(SMA)", 2])),

    _K_Len(9, "KD-K週期"),

    _D_Len(3, "KD-D週期"),

    _OrderQty(1, "基本買進張數/口數"),

    _MaxAddCount(3, "最高加碼次數"); // 這次新增的限制參數

 

var: 

    _ATR_Val(0), _Src(0), _Up_Basic(0), _Dn_Basic(0),

    _Up_Line(0), _Dn_Line(0), _Trend(1), _ST_Line(0),

    _K(0), _D(0), _RSV(0);

 

// ------------------------------------------------------------

// 1. KD 與 Supertrend 核心邏輯 (維持不變)

// ------------------------------------------------------------

stochastic(_K_Len, _D_Len, _D_Len, _K, _D, _RSV);

 

_Src = (High + Low) / 2;

_ATR_Val = iff(_ATR_Mode = 1, ATR(_ATR_Len), Average(TrueRange, _ATR_Len));

 

_Up_Basic = _Src - (_Mult * _ATR_Val);

_Dn_Basic = _Src + (_Mult * _ATR_Val);

 

if CurrentBar = 1 then begin

    _Up_Line = _Up_Basic; _Dn_Line = _Dn_Basic; _Trend = 1;

end else begin

    if Close[1] > _Up_Line[1] then _Up_Line = MaxList(_Up_Basic, _Up_Line[1]) else _Up_Line = _Up_Basic;

    if Close[1] < _Dn_Line[1] then _Dn_Line = MinList(_Dn_Basic, _Dn_Line[1]) else _Dn_Line = _Dn_Basic;

 

    if _Trend[1] = -1 and Close > _Dn_Line[1] then _Trend = 1

    else if _Trend[1] = 1 and Close < _Up_Line[1] then _Trend = -1

    else _Trend = _Trend[1];

end;

 

_ST_Line = iff(_Trend = 1, _Up_Line, _Dn_Line);

 

// ------------------------------------------------------------

// 2. 交易訊號定義

// ------------------------------------------------------------

 

// 條件 A:首次翻多

condition1 = (_Trend = 1 and _Trend[1] = -1);

 

// 條件 B:回踩支撐加碼

condition2 = (_Trend = 1 and _Trend[1] = 1 and Low <= _ST_Line and Close > _ST_Line);

 

// 條件 C:跌破趨勢出場

condition3 = (Close < _ST_Line);

 

// ------------------------------------------------------------

// 3. 執行下單 (含次數限制邏輯)

// ------------------------------------------------------------

 

// A. 首次進場 (Position 為 0 時)

if Position = 0 and condition1 then begin

    SetPosition(_OrderQty * 1000, Label:="趨勢翻多買進");

end;

 

// B. 限定次數加碼

// 計算邏輯:首買 1 單位 + 加碼 N 單位。所以上限是 (1 + _MaxAddCount) 個單位

// 只有在【已有部位】且【部位尚未達到上限】時才執行加碼

if Position >= (_OrderQty * 1000) 

   and Position < (_OrderQty * (1 + _MaxAddCount) * 1000) 

   and condition2 then begin

    SetPosition(Position + _OrderQty * 1000, Label:="回踩加碼");

end;

 

// C. 全部出場

if Position > 0 and condition3 then begin

    SetPosition(0, Label:="跌破趨勢全平倉");

 

end;

排序方式: 標準 | 最新
虎科大許教授 發文於   2026/02/27

下單數量為何乘以1000?

灰熊 發文於   2026/02/27

1張為1000股

灰熊 發文於   2026/02/27

懂了,1000要拿掉是嗎

 

 

 

虎科大許教授 發文於   2026/02/27

Setposition 第一個參數是張數或口數。單筆下單最多499。

發表回覆
Close