本文介绍了如何延迟PINE脚本中生成的警报,如果图表时间框架是10M,是否有人可以帮助将警报延迟n秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一秒内收到太多警报(相同的代码/指标适用于不同的股票/代码),我希望每个警报至少延迟5秒。我曾尝试使用Pinecoders.comhttps://www.pinecoders.com/faq_and_code/#how-can-i-implement-a-time-delay-between-orders提供的此指示器代码来延迟(5秒)我的10M策略,但它不起作用,因为我正在使用10M图表,并且我希望警报延迟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和下面的更新代码,它对我有效。我的基本想法是在不同的股票中设置警报,因为警报是同时生成的(我有一些基于时间的标准)在一秒钟内有太多的请求导致订单被拒绝。以下代码是此问题的答案。

下面我计算了关闭条形图的剩余时间,并为每个警报设置了不同的&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)+'
 '+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)

这篇关于如何延迟PINE脚本中生成的警报,如果图表时间框架是10M,是否有人可以帮助将警报延迟n秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 03:42