我找到了这个问题的解决方案。
解决办法在于calc_on_every_tick=true
和下面更新的代码,它对我有用。
我的基本想法是在不同的股票中设置警报,因为警报是同时生成的(我有一些基于时间的标准),在一秒钟内有太多的请求导致订单被拒绝。
下面的代码是这个问题的答案。
下面我计算了柱形图关闭的剩余时间,并为每个警报设置了不同的“i_qtyTimeUnits”,这会导致即使同时生成 100 个警报,警报也会延迟。 5秒的差距不会导致订单取消。
//@version=4
strategy("Strat with time delay", overlay=true,calc_on_every_tick=true)
i_qtyTimeUnits = input(5, "Quantity", minval = 0)
i_timeUnits = input("seconds", "Delay between entries", options = ["seconds", "minutes", "hours", "days", "months", "years"])
int _timeFrom_ = na
_year_ = (i_timeUnits == "year" ? int(i_qtyTimeUnits) : 0)
_month_ =(i_timeUnits == "month" ? int(i_qtyTimeUnits) : 0)
_day_ = (i_timeUnits == "day" ? int(i_qtyTimeUnits) : 0)
_hour_ = (i_timeUnits == "hour" ? int(i_qtyTimeUnits) : 0)
_minute_ = (i_timeUnits == "minute" ? int(i_qtyTimeUnits) : 0)
_second_ = (i_timeUnits == "second" ? int(i_qtyTimeUnits) : 0)
// Return the resulting time in ms Unix time format.
_timeFrom_ := timestamp(_year_, _month_, _day_, _hour_, _minute_, _second_)
// Entry conditions.
ma = sma(close, 5)
goLong = crossover(close, ma)
goShort = crossunder(close , ma)
timeLeft = (time_close - timenow) / 1000
vol=label.new(bar_index, na,text=tostring(timeLeft), color=color.red,style=label.style_labeldown, yloc=yloc.abovebar)
label.delete(vol[1])
if_t=timeLeft<=i_qtyTimeUnits?1:0
vol1=label.new(bar_index[10], na,text=tostring(i_qtyTimeUnits)+'\n '+tostring(if_t), color=color.lime,style=label.style_labelup, yloc=yloc.abovebar)
label.delete(vol1[1])
if goLong and timeLeft<=i_qtyTimeUnits
strategy.entry("Long", strategy.long, comment="Long")
if goShort and timeLeft<=i_qtyTimeUnits
strategy.entry("Short", strategy.short, comment="Short")
plot(ma, "MA", goLong ? color.lime : color.red)