過度交易 每分鐘都下單

  •   375 
  • 最後發表   YG  2025 五月 21
YG 發文於   2025/05/08

各位好

我的設定是60k的交易頻率,是否是因為設定自動洗價,導致每分鐘都有進出,造成大額的虧損?

 

另外我有設定:每一根60k最多交易4次就出清倉位並停止策略,但似乎沒發揮作用?是否可以給我一些建議,謝謝。

 

if GetInfo("TradeMode") = 1 and Position = 0 and CurrentBar > last_trade_bar and hourly_trade_count < 4 then begin

    if short_condition or ((Time = 084500 or Time = 150000) and short_condition[1] and Time <> last_check_time) then begin

        SetPosition(-1);

        if Filled = -1 then begin

            EntryPriceAvg = FilledAvgPrice; // 使用成交價

        end else begin

            EntryPriceAvg = Close; // 若未成交,暫用收盤價

            Print("Warning: Short entry at ", Time, " no fill, using Close: ", Close);

        end;

        last_trade_bar = CurrentBar;

        hourly_trade_count = hourly_trade_count + 1;

        last_check_time = Time;

        Print("Short entry at ", Time, " Price: ", EntryPriceAvg, " Trade count: ", hourly_trade_count, " Position: ", Position, " Filled: ", Filled);

    end;

end else if hourly_trade_count >= 4 then begin

    SetPosition(0); // 出清倉位

    RaiseRunTimeError("One-hour trade count reaches 4, clearing position and stopping strategy");

 

end;

附加文件

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/05/08

(1)你應該將變數宣告這部份的程式碼也一起貼上來。看起來應該是變數last_check_time沒有用intrabarpersist宣告所造成。

(2)Time <> last_check_time會讓60分K最多只進場一次;所以,hourly_trade_count最多等於1,不可能大於等於4。

(3)不能宣告Entry開頭的變數。

YG 發文於   2025/05/08

 

感謝教授願意撥冗指教

Vars:

    long_condition(false),

    short_condition(false),

    long_exit(false),

    short_exit(false),

    long_stop(false),

    short_stop(false),

    long_tp(false),

    short_tp(false),

    EntryPriceAvg(0),

    last_trade_bar(0),      // 記錄最後交易的 K 棒索引

    hourly_trade_count(0),  // 記錄當前 K 棒交易次數

    current_bar_prev(0),    // 記錄前一根 K 棒索引

    IntraBarPersist last_check_time(0); // 記錄上次補單檢查時間

 

// === 重置交易次數(新 K 棒開始時) ===

if CurrentBar > current_bar_prev then begin

    hourly_trade_count = 0;

    current_bar_prev = CurrentBar;

end;



 

if (long_exit or long_stop or long_tp or short_exit or short_stop or short_tp) and CurrentBar > last_trade_bar and hourly_trade_count < 4 then begin

    SetPosition(0);

    last_trade_bar = CurrentBar;

    hourly_trade_count = hourly_trade_count + 1;

    last_check_time = Time;

    Print("Exit at ", Time, " Price: ", Close, " Trade count: ", hourly_trade_count, " Position: ", Position, " Filled: ", Filled);

end else if hourly_trade_count >= 4 then begin

    SetPosition(0); // 出清倉位

    RaiseRunTimeError("One-hour trade count reaches 4, clearing position and stopping strategy");

end;

 

// === 部位同步檢查 ===

if Position <> Filled then begin

    Print("Warning: Position (", Position, ") does not match Filled (", Filled, ") at ", Time);

 

end;

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

我被搞糊塗了。你最初的程式是進場放空,然後計算次數,這次數是計算加碼次數嗎?若是,則不應該一直setposition(-1),而應寫成setposition(position-1)。你新的程式卻是出場計算次數。到底要的是什麼?你需要先釐清你的進出場邏輯。

YG 發文於   2025/05/08

我只是想計算一小時k裡面他執行了進出場幾次,避免上面的過度交易而已
我這個策略多空都有做

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

請詳述你的進場及出場邏輯。進場可多可空。進場4次,是否是加碼?還是進場1張,平倉後算1次,接著又進場1張,平倉再加1次?

YG 發文於   2025/05/09

我最大倉位一口,進場1口,算1次,平倉多單算1次,接著又進場1口,算1次,平倉再加1次,共四次。

交易次數最大為四

我沒有加碼單,感謝教授

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

試試看這樣是否OK。

if position=0 and hourly_trade_count < 4 and short_condition or ((Time = 084500 or Time = 150000) and short_condition[1]) then
    begin
        SetPosition(-1);
        hourly_trade_count+=1;
    end;
if position <> 0 and (long_exit or long_stop or long_tp or short_exit or short_stop or short_tp) then
    begin
        SetPosition(0);
        if hourly_trade_count=4 
        then RaiseRunTimeError("One-hour trade count reaches 4, clearing position and stopping strategy");
    end;

YG 發文於   2025/05/09

謝謝教授提供資訊,我來更新看看,感恩

XS小編 發文於   2025/05/21

Hello YG,

 

小編補充,您也可以使用 FilledRecordCount 來取得交易次數以此作限制。

舉例來說:

value1 = FilledRecordCount;

condition1 =  FilledRecordCount < value1[1] + 4;

 

這樣condition1就會是限制進場次數要小於上根Bar結束時的次數加四。

發表回覆
Close