> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to send a webhook when your condition fires

> Raising an alert with the message you want delivered, choosing between alert and alertcondition, and what is set outside the script.

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.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Crossover alert", overlay=true)
fast = talib.sma(close, 10)
slow = talib.sma(close, 30)
fired = talib.crossover(fast, slow)
alertcondition(fired, "Fast crossed above slow", "cross-up")
if fired and barstate.isconfirmed {
    alert('{"event":"cross-up","price":' + str.tostring(close) + '}')
}
plot(fast, title="Fast")
plot(slow, title="Slow")
```

## alert or alertcondition

| | `alert(message)` | `alertcondition(condition, title, message)` |
| - | - | - |
| Where it may be called | anywhere: top level, `if`, function, loop | top level only |
| Message | `series string`, may differ on every bar | `const string`, fixed when the script is compiled |
| What it does | raises an alert when the script runs | declares a condition the user can pick when creating an alert |

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](https://gocharting.com/docs/scripting/how-to/avoid-a-result-that-changes-after-the-bar-closes.md)). 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](https://gocharting.com/docs/scripting/automation/webhooks.md) and [Backtest a crossover](https://gocharting.com/docs/scripting/learn/backtest-a-crossover.md)):

> [!WARNING]
>
> 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.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
strategy("Crossover with alert", overlay=true)
fast = talib.sma(close, 10)
slow = talib.sma(close, 30)
if talib.crossover(fast, slow) and barstate.isconfirmed {
    strategy.entry("Long", strategy.long)
    alert('{"event":"long","price":' + str.tostring(close) + '}')
}
plot(fast, title="Fast")
plot(slow, title="Slow")
```

## 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](https://gocharting.com/docs/scripting/automation/alerts.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.