回测未在交易视图中显示 SMA 交叉脚本的任何结果

Backtest not showing any results for a SMA crossover script in tradingview

正在尝试使用 Pine 脚本版本 5 中的以下脚本。脚本中没有错误。但是,它在回测中没有显示任何结果。有人可以帮忙吗?

code 加粗 斜体

quote ****//@version=5

strategy(shorttitle='Long on MA Crossover',title='Long Strategy with MA Crossover', overlay=true, initial_capital = 20000, currency = currency.USD, process_orders_on_close=true, default_qty_type = strategy.cash, default_qty_value = 20000, commission_type=strategy.commission.percent, commission_value=0.075)


//Backtest dates
fromMonth = input.int(defval = 1,    title = "From Month",  minval = 1, maxval = 12)
fromDay   = input.int(defval = 1,    title = "From Day",    minval = 1, maxval = 31)
fromYear  = input.int(defval = 2019, title = "From Year",   minval = 1970)
thruMonth = input.int(defval = 1,    title = "Thru Month",  minval = 1, maxval = 12)
thruDay   = input.int(defval = 1,    title = "Thru Day",    minval = 1, maxval = 31)
thruYear  = input.int(defval = 2112, title = "Thru Year",   minval = 1970)

showDate  = input.bool(defval = true, title = "Show Date Range")

start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false       // create function "within window of time"

len1 = input.int(9, minval=1, title="MA1")
len2 = input.int(50, minval=1, title="MA2")
len3 = input.int(100, minval=1, title="MA3")
len4 = input.int(200, minval=1, title="MA4")

ma1 = ta.sma(close, len1)
ma2 = ta.sma(close, len2)
ma3 = ta.sma(close, len3)
ma4 = ta.sma(close, len4)

Take_profit= ((input (3))/100)

longTakeProfit = strategy.position_avg_price * (1 + Take_profit)

closeLong = close > longTakeProfit or ta.crossover(ma2,ma1)

//Entry 
strategy.entry("buy", strategy.long, limit=close[1], when = ta.crossover(ma1,ma2) and ma2 > ma3 and ma3 > ma4 and window())

//Exit
strategy.close("sell", when = closeLong and window())****

错误在最后一行,strategy.close("sell", when = closeLong and window()) 当您使用 strategy.close() 函数时,您必须提供与 strategy.entry() 函数中相同的交易 ID,您放置了一个未知 ID“卖出”,该 ID 从未用于使用此 ID 进行任何交易。 以下是更新后的代码和工作代码。

//@version=5
strategy(shorttitle='Long on MA Crossover',title='Long Strategy with MA Crossover', overlay=true, initial_capital = 20000, currency = currency.USD, process_orders_on_close=true, default_qty_type = strategy.cash, default_qty_value = 20000, commission_type=strategy.commission.percent, commission_value=0.075)


//Backtest dates
fromMonth = input.int(defval = 1,    title = "From Month",  minval = 1, maxval = 12)
fromDay   = input.int(defval = 1,    title = "From Day",    minval = 1, maxval = 31)
fromYear  = input.int(defval = 2019, title = "From Year",   minval = 1970)
thruMonth = input.int(defval = 1,    title = "Thru Month",  minval = 1, maxval = 12)
thruDay   = input.int(defval = 1,    title = "Thru Day",    minval = 1, maxval = 31)
thruYear  = input.int(defval = 2112, title = "Thru Year",   minval = 1970)

showDate  = input.bool(defval = true, title = "Show Date Range")

start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false       // create function "within window of time"

len1 = input.int(9, minval=1, title="MA1")
len2 = input.int(50, minval=1, title="MA2")
len3 = input.int(100, minval=1, title="MA3")
len4 = input.int(200, minval=1, title="MA4")

ma1 = ta.sma(close, len1)
ma2 = ta.sma(close, len2)
ma3 = ta.sma(close, len3)
ma4 = ta.sma(close, len4)

Take_profit= ((input (3))/100)

longTakeProfit = strategy.position_avg_price * (1 + Take_profit)

closeLong = close > longTakeProfit or ta.crossover(ma2,ma1)

//Entry 
strategy.entry("buy", strategy.long, limit=close[1], when = ta.crossover(ma1,ma2) and ma2 > ma3 and ma3 > ma4 and window())

//Exit
strategy.close("buy", when = closeLong and window())