0

I have enabled calc_on_every_tick=true due to I want to receive the alert as soon as possible. But in real-time when too many alerts triggered, tradingview stops that related alert with following message: Stopper -- Too many triggering. I have to re-enable it in order to use it again.

I have kept pyramiding as a very high value since I just want to keep receive signal in case the alert is triggered.

As you can see in 1 second multiple alerts might be received, and alert is automatically stopped by the tradingview:

enter image description here

[Q] How can I prevent this from happening while keeping calc_on_every_tick enabled?


From following answer (Tradingview Pine script save close price at time of strategy entry), I have tried followin code piece to let 30 seconds sleep time, which did not work. Still I have receiving alerts one after another in each millisecond.

Example code piece:

//@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
alper
  • 2,919
  • 9
  • 53
  • 102

1 Answers1

1

I find a hack to solve it. My goal was to handle alerts for both buy and sell using strategy rather than setting buy and sell alerts one by one.

I am storing mod of timenow as order quantity, hence I can compare it on the next order. If the difference is 10 (10 seconds) next order will take place.

pinescript code:

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

Please note that this is not made for back-testing.

alper
  • 2,919
  • 9
  • 53
  • 102