Skip to main content
A script cannot address a URL: Lipi has no function that calls one. What a script does is raise an alert whose message you build; the destination, including a webhook URL, is set when the alert is created on the chart, outside the script. So the work in the script is to fire an alert on the right bar with the text you want delivered. Quote a JSON message with single quotes, so the double quotes inside it stay plain characters.

alert or alertcondition

Use alert when the message carries a number computed on this bar, as above. Fire it only on a closed bar (barstate.isconfirmed): with one alert per bar, an alert raised on the first tick carries that tick’s price and cannot be taken back (see How to avoid a result that changes after the bar closes). Use alertcondition to offer the user a named condition to set up themselves. alert fires at most once per bar, on realtime bars only, and only when the script runs as an alert; on historical bars it does nothing, so nothing is raised while the script works through history. That is not a fault.

Strategies

A strategy’s orders are simulated and strategy.entry and strategy.exit have no argument for an alert message, so a custom payload comes from alert in the same script (see Webhooks for algo trading and Backtest a crossover):
GoCharting is a charting and analytics tool. This is not investment advice. Trading and investing carry a high risk of loss and are not suitable for everyone. You can lose some or all of your money.

The mistake to avoid

Putting alertcondition in an if to make it conditional. The compiler says: alertcondition() must be called in the global scope. The condition is its first argument; use alert when you need a branch. See Alerts.