Search code examples
pine-scriptpine-script-v5tradingview-apialgorithmic-tradingpine-script-v4

Tradingview Alert to Discord Webhooks timezone conversion


I have this alert with script {"content": "10 min RSI < 50 {{ticker}} SHORT Time ={{timenow}}"} on Trading view.

And I got the discord bot with the alert "10 mins RSI < 50 EURUSD SHORT Time =2023-04-10T16:10:03Z"

The default time for {timenow} on Tradingview is UTC time. How do I change Time =2023-04-10T16:10:03Z to EST time so that Time =2023-04-10T12:10:03Z? Many thanks.


Solution

  • You won't be able to change the timezone in the alert creation dialog, but you can add hidden plots to your script and call them in the required format in the alert creation dialog, for example:

    plot(year(timenow, "America/New_York"), "currYear", display=display.none)
    plot(month(timenow, "America/New_York"), "currMonth", display=display.none)
    plot(dayofmonth(timenow, "America/New_York"), "currDay", display=display.none)
    plot(hour(timenow, "America/New_York"), "currHour", display=display.none)
    plot(minute(timenow, "America/New_York"), "currMinute", display=display.none)
    plot(second(timenow, "America/New_York"), "currSecond", display=display.none)
    

    And use this construction when creating an alert

    Time = {{plot("currYear")}}-{{plot("currMonth")}}-{{plot("currDay")}}T{{plot("currHour")}}:{{plot("currMinute")}}:{{plot("currSecond")}}
    

    Or a more optimal method is to use the alert() function and pass a formatted date as a message to it in a string, example:

    alert(str.tostring(syminfo.tickerid) + " any your text " + str.format_time(timenow, "yyyy-MM-dd HH:mm:ssZ", "America/New_York"))
    

    Note: the alert() function must be called in the code according to the alert condition