启用 calc_on_every_tick 时如何防止 tradingview 由于触发太多而停止警报

How to prevent tradingview to stop alerts due to too many triggering when calc_on_every_tick is enabled

我启用了 calc_on_every_tick=true 因为我想尽快收到警报。但在实时触发太多警报时,tradingview 会停止相关警报并显示以下消息:Stopper -- Too many triggering。我必须重新启用它才能再次使用它。

我将 pyramiding 保持为一个非常高的值,因为我只想保留接收信号以防警报被触发。

如您所见,1 秒内可能会收到多个警报,交易视图会自动停止警报:

[问] 如何在保持 calc_on_every_tick 启用的同时防止这种情况发生?


从下面的答案 (Tradingview Pine script save close price at time of strategy entry) 中,我尝试了下面的代码片段让 30 秒的睡眠时间,但没有用。我仍然在每一毫秒内收到一个接一个的警报。

示例代码片段:

//@version=4
strategy(title="test_strategy",
     shorttitle="test_strategy",
     calc_on_order_fills=false, 
     process_orders_on_close=true, 
     calc_on_every_tick=true, pyramiding=100000)

_timenow = (timenow / 1000)
lastTradeTime = 0
if cond
    if (lastTradeTime == 0)
        strategy.entry("Long", strategy.long, when=window())
        lastTradeTime := _timenow
    else
        if _timenow > lastTradeTime + 30
            strategy.entry("L", strategy.long, when=window())
            lastTradeTime := _timenow

我找到了一个 hack 来解决它。我的目标是使用策略处理 buysell 的警报,而不是一个一个地设置 buysell 警报。

我正在存储 timenow 的 mod 作为订单数量,因此我可以在下一个订单中比较它。如果差值是 10(10 秒),将执行下一个订单。

pinescript代码:

is_long  = (strategy.position_size > 0)
is_short = (strategy.position_size < 0)

SLEEP_SECONDS = 30
_timenow = timenow / 1000
time_mod = _timenow % 1000000000

if buySignal
    if strategy.opentrades[0] == 0 or is_short
        strategy.entry("Long", strategy.long, qty=time_mod, when=window(), alert_message="enter")
    else
        if time_mod > abs(strategy.position_size[0]) + SLEEP_SECONDS
            if strategy.position_size[0] != 0
                // inorder to re-open with new quantity size we have to close previous position.
                strategy.close_all(when=window())
            if strategy.opentrades[0] == 0
                strategy.entry("Long", strategy.long, qty=time_mod, when=window(), alert_message="enter")

if sellSignal
    if strategy.opentrades[0] == 0 or is_long
        strategy.entry("Short", strategy.short, qty=time_mod, when=window(), alert_message="enter")
    else
        if time_mod > abs(strategy.position_size[0]) + SLEEP_SECONDS
            if strategy.position_size[0] != 0
                // inorder to re-open with new quantity size we have to close previous position.
                strategy.close_all(when=window())
            if strategy.opentrades[0] == 0
                strategy.entry("Short", strategy.short, qty=time_mod, when=window(), alert_message="enter")

请注意,这不是为了回测。