'TradingView alerts: how to setup a delay?

I'm reading a lot about it but can't find a way.

I have a strategy doing like

strategy.close("SELL", alert_message=closeShort_msg)
strategy.entry("BUY", etc.

And I wish to delay the second signal, so to be sure the first one gets executed.

Can someone tell me why this method doesn't produce any trades? Strategy says "nothing to display".

 t1 = time
 strategy.close("SELL", alert_message=closeShort_msg)
 if time >= (t1+2000)
     strategy.entry("BUY", etc.

I also tried with

timenow

but nothing changed.



Solution 1:[1]

I think your order of execution is good and should function correctly within Tradingview backtester. However, if you want to add a delay because your API is not executing the second signal because it happens to receive the second signal before the first one then what you can do is add a delay to second signal that Tradingview sends to the API.

e.g.

strategy.close("SELL", alert_message=closeShort_msg)

strategy.entry("BUY", etc).

alert('{  "message_type": "bot",  "bot_id": xxxxxxx,  "email_token": "xxxxxx",  "delay_seconds": 10}', alert.freq_all)

This should add a 10 seconds delay for the API to execute the strategy.entry signal.

Hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P