我看到“已達到訂單限制 (9000)”錯誤

此錯誤代表該策略下的訂單或平倉的交易數量超過了允許的最大數量。

為了避免此錯誤,請將您的策略轉換為Pine Script v6。在v6中,所有超過限制的訂單都會被修整:每個新訂單都會出現在交易清單中,並且超過訂單限制的最舊訂單將被刪除。

或者,您可以透過檢查訂單條件中的時間範圍來限制策略下訂單的日期。以下範例腳本透過檢查目前K線的時間是否在兩個時間戳記之間來建立下單的時間範圍。

//@version=6
strategy("My strategy", overlay = true)

enableFilter = input(true,  "Enable Backtesting Range Filtering")
fromDate     = input.time(timestamp("20 Jul 2023 00:00 +0300"), "Start Date")
toDate       = input.time(timestamp("20 Jul 2099 00:00 +0300"), "End Date")

tradeDateIsAllowed = not enableFilter or (time >= fromDate and time <= toDate)

longCondition =  ta.crossover(ta.sma(close, 14),  ta.sma(close, 28))
shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))

if longCondition and tradeDateIsAllowed
    strategy.entry("Long", strategy.long)

if shortCondition and tradeDateIsAllowed
    strategy.entry("Short", strategy.short)