pine-scriptpine-script-v4

how to send some data to specific url when an alert triggered in pine script?


I am familiar with the webhook in pine script. webhook's problem is that does not allowed to send data with post curl.

how can I send some data (multiple float values) to a url when a statement in my indicator is happens ?

thanks in advance


Solution

  • You can definitely send data with the webhook.

    When you define an Alert, you set the Alert name and Message fields. The Alert name is just a string (for you, to differentiate among alerts), but the Message field can contain built-in Pine variables and you can set values to those built-in variables, in your script, runtime. On the Alert creation window there is a text "You can use special placeholders such as {{close}}..." and a question mark, which leads to the documentation.

    Ie.: you can set your own variable (say, al_mes) to a certain value (which can control your app on the other end of the webhook) and when you call strategy.entry() it will accept an alert message field, where you should put in that al_mes variable:

    strategy.entry(id='Above Open', direction=strategy.long, alert_message=al_mes, comment = 'To the Moon')
    

    That alert message value will be put into the built-in variable alert_message which you can place into the alert creation window's Message field as {{strategy.order.alert_message}}.

    When the Alert is triggered, the webhook will be queried with a HTTP POST request and the contents of {{strategy.order.alert_message}} which is equivalent to al_mes will be put into the request as POST DATA.

    This is how 3Commas.io bots work with Tradingview Custom Signal and also this is how you can integrate Tradingview into your workflow by some iPaaS application, like IFTTT, Relay.app, Zapier, etc.