【问题标题】:How to prevent tradingview to stop alerts due to too many triggering when calc_on_every_tick is enabled如何防止启用 calc_on_every_tick 时因触发过多而导致交易视图停止警报
【发布时间】:2021-06-11 15:54:22
【问题描述】:

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

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

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

[Q]如何在启用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

【问题讨论】:

    标签: pine-script


    【解决方案1】:

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

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

    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")
    

    请注意,这不是为回测而设计的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      相关资源
      最近更新 更多