想請教各位大神能否幫忙寫成xs交易腳本

  •   326 
  • 最後發表   菜鳥韭菜想進步  2025 五月 04
菜鳥韭菜想進步 發文於   2025/05/03

適用小台指期,適用在5分k線上,只要連續3根k棒收盤價高於前面的k棒,第4根k棒在收盤前10秒就進場,出場條件,獲利50點,或是第5根k棒收盤價低於第1根k棒,重複直到收盤為止。

排序方式: 標準 | 最新
菜鳥韭菜想進步 發文於   2025/05/03

附上,目前的碼 

input:

    GainPoint(20, "停利點數"),

    LossPoint(50, "停損點數");

 

vars:

    LongEntry(false),

    ShortEntry(false),

    LongStop(false),

    ShortStop(false),

    EntryPrice(0),

    TradeTime(0),

    TimeOK(false);

 

// 僅支援分鐘線

if barfreq <> "Min" then

    raiseruntimeerror("僅支援分鐘線");

 

// 時間限制(僅 08:45~13:25 可以進場)

TimeOK = (time >= 845 and time <= 1325);

 

// 多單條件:連續三根上漲收盤

LongEntry = close > close[1] and close[1] > close[2] and close[2] > close[3];

 

// 空單條件:連續三根下跌收盤

ShortEntry = close < close[1] and close[1] < close[2] and close[2] < close[3];

 

// 進場:下一根開盤立即市價進場

if position = 0 and TimeOK then begin

    if LongEntry then begin

        setposition(1, market);

        EntryPrice = close;

        TradeTime = barnumber;

        print("進場多單 @", close:1:2, " 時間:", time);

    end;

    if ShortEntry then begin

        setposition(-1, market);

        EntryPrice = close;

        TradeTime = barnumber;

        print("進場空單 @", close:1:2, " 時間:", time);

    end;

end;

 

// 多單出場條件

LongStop = position = 1 and (

    close - EntryPrice >= GainPoint or    // 停利

    (barnumber = TradeTime + 2 and close < close[3]) // 停損(第 5 根收盤 < 第 1 根)

);

 

if LongStop then begin

    setposition(0, market);

    print("平多單 @", close:1:2, " 時間:", time);

end;

 

// 空單出場條件

ShortStop = position = -1 and (

    EntryPrice - close >= GainPoint or    // 停利

    (barnumber = TradeTime + 2 and close > close[3]) // 停損(第 5 根收盤 > 第 1 根)

);

 

if ShortStop then begin

    setposition(0, market);

    print("平空單 @", close:1:2, " 時間:", time);

end;

 

虎科大許教授 發文於   2025/05/03

你的需求比較會困擾初學者的,可能是符合進場條件的下一根K收K前10秒下單。我針對進場的這部份,提供建議的寫法如下。由於收K前只有10秒的時間,若流動性比較差,那10秒期間沒有Tick成交,會有邏輯錯誤,所以建議洗價設定除了逐筆洗價,也應勾選自動洗價(設定每秒鐘洗價一次)。另外,你的程式有一大堆錯誤,例如宣告了系統無法接受的變數名稱,例如EntryPrice、TradeTime,這些名稱都要修改。Print的寫法也是錯誤的。還有TimeOk條件也要修改為TimeOK = (time >= 84500 and time <= 132500);  .....:

input: mySecs(10,"收盤前下單秒數");
var: intraBarPersist TickTime(0);
// 進場:下一根收K前10秒以市價進場
TickTime=GetField("時間", "Tick");
value1=TimeDiff(TickTime,Time,"S");
condition1=value1>=Barinterval*60-mySecs;
if position = 0 and TimeOK then 
    begin
        if LongEntry and condition1 then 
            begin
                setposition(1, market);
                print("進場多單 @", close, " 時間:", time);
            end;
        if ShortEntry and condition1 then 
            begin
                setposition(-1, market);
                print("進場空單 @", close, " 時間:", time);
            end;
    end;

 

菜鳥韭菜想進步 發文於   2025/05/04

感謝許教授,我根據您給的進場這部份,請ai重新寫過後,終於生出一個可以執行的程式碼了!

發表回覆
Close