如何延迟在pine脚本中生成的警报,如果图表时间框架是10m,有人可以帮助延迟警报n秒数吗?



我在一秒钟内收到太多警报(相同的代码/指标应用于不同的股票/符号),我想延迟每个警报至少5秒。我已经尝试使用pinecoders.com https://www.pinecoders.com/faq_and_code/#how-can-i-implement-a-time-delay-between-orders提供的这个指标代码来延迟(5秒)到我的10m策略,但它不工作因为我使用10米的图表,我想让警报延迟5秒。

谁能帮忙把警报延迟1-5秒?@e2e4谢谢你的回复,我想在更高的时间框架内测试(即使有不一致)。包含代码的链接被设计为只在酒吧之间给延迟,但我想延迟5秒时,蜡烛关闭后。我尝试了以下代码

//@version=4
strategy("Strat with time delay", overlay=true)
i_qtyTimeUnits  = - input(5, "Quantity", minval = 0)
i_timeUnits     = input("seconds", "Delay ", 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 = close > ma?1:0
goShort = close < ma?1:0
// Time delay filter
var float lastTradeTime = na
if nz(change(goLong), time)
// An order has been executed; save the bar's time.
lastTradeTime := timenow
var float lastTradeTime_s = na
if nz(change(goShort), time)
// An order has been executed; save the bar's time.
lastTradeTime_s := timenow
delayElapsed_long = timenow > (lastTradeTime+_timeFrom_)
delayElapsed_short = timenow >  (lastTradeTime_s+_timeFrom_)
if goLong==1 and delayElapsed_long and barstate.isconfirmed
strategy.entry("Long", strategy.long, comment="Long")
if goShort==1 and delayElapsed_short and barstate.isconfirmed
strategy.entry("Short", strategy.short, comment="Short")
plot(ma, "MA", goLong ? color.lime : color.red)

我只是想延迟警报5秒。但是上面的代码似乎不起作用。请帮助。

我有办法解决这个问题了。解决方案在于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)

最新更新