Skip to content
ChartTailor
WorkServicesPricingField NotesAbout Start a build
← Pine Discoveries

Strategy alerts are order events, not just indicator alerts with trades

Pine strategy alerts need separate thinking around order fills, alert messages, replay tests, and live execution.

Strategy alerts look like they should be a straightforward extension of indicator alerts. The script places orders, TradingView sends alerts, and the user receives trade events. The details are messier. Strategy alerts can be tied to order events, and order events are about executed or filled orders, not merely the condition that made the script want an order.

I started keeping a note on this because a lot of confusion comes from using indicator-alert intuition on a strategy. The user expects an alert when a condition is true. The strategy alert may fire when an order event occurs. Those are related, but they are not the same thing.

Why this catches people

Where people usually go wrong is defining alert_message only on the orders the user cares about and assuming the alert will ignore the others. Strategy alerts can be configured around order events, and if the alert is listening to order fills, entries and exits need to be handled deliberately. The message field in the Create Alert dialog also matters because {{strategy.order.alert_message}} is how the order’s message is passed through.

Replay testing can add confusion. A strategy may appear to produce a sequence of trades in replay or history, but the live alert cadence depends on calculation settings, order events, and realtime updates. The replay is useful, but it is not the same as a live webhook test.

The Pine bit

I separate three things: the signal condition, the strategy order, and the alert message. The signal condition says the setup exists. The strategy order says what the broker emulator is instructed to do. The alert message says what the outside world receives. Those three layers should not be collapsed into one mental object.

If the strategy sends dynamic order messages, each order-placing call should carry the intended message. The alert dialog should then use the strategy order message placeholder. Without that, the user may get a generic message or a message that does not reflect the order event.

if longEntry
    strategy.entry("L", strategy.long, alert_message = '{"event":"entry_long"}')

if exitNow
    strategy.close("L", alert_message = '{"event":"exit_long"}')

Why it can survive a quick review

This can slip through review because the strategy report gives a clean story after the fact. Entries and exits appear in order. The alert system, however, is concerned with events as they occur. If a strategy recalculates only on bar close, the alert surface is different from an indicator running intrabar. If an order fills later than the condition appeared, the alert belongs to the fill event, not necessarily the first moment the condition became true.

The mismatch is especially important for automation. A webhook receiver usually does not want a philosophical signal. It wants an event it can act on. If entries, exits, partial exits, and reversals are not named cleanly, the receiver may act on the wrong event or act twice.

How I handle it in builds

In strategy builds, I write the alert event names before wiring the orders. entry_long, entry_short, exit_long, exit_short, reduce_long, and reverse_short are different events. Even if the chart displays them in one neat trade, the automation side needs to know exactly what happened.

I test with the exact alert dialog message the user will use. A strategy can have perfect alert_message strings in code and still send the wrong thing if the alert’s message field is not configured to pass them through.

Where this shows up

A good field test is to create separate messages for entry, exit, and reversal, then inspect the actual alert log. If the log shows an entry message when the user expected only exits, the issue is not the text of the message. It is the alert surface the user created and the order events the strategy produced.

I like to simulate duplicate and missing events on the receiver side. Strategy alerts can be clean and still arrive late, be retried, or be processed by a bot with stale position state. A mature automation design assumes the receiver may need to validate state rather than blindly execute every alert.

This is why I prefer event names over prose. A bot can reason about exit_long. It cannot reliably reason about “close this one now please” unless someone writes another parser.

Implementation-wise, I usually add a visible “last event” table while developing. It shows the most recent signal state, order action, and outbound alert event. If those three values disagree, the bug is immediately visible. Without that table, it is easy to stare at the chart marker and forget that the webhook is listening to a different layer.

I remove or hide that table in the final version unless the user wants diagnostics, but it is one of the quickest ways to make strategy-alert behaviour understandable during development.

How I test it

I test strategy behaviour by separating signal, order, fill, and report. A marker proves the signal condition. An order ID proves the strategy instruction. A fill proves the emulator accepted a path. A report proves only the model’s accounting. Those are related, but they are not interchangeable.

When the strategy report is doing real work, I run a conservative variant beside the intended one. If the strategy collapses when same-bar optimism, synthetic prices, or ambiguous fills are reduced, the report is telling me the edge depends on assumptions. That does not automatically kill the idea, but it changes how I would present it.

I make sure the alert messages are boring enough for logs. A dramatic message may look nice in TradingView. A boring event name with stable JSON is easier to reconcile against orders, fills, and receiver state after something goes wrong.

Checks before I trust it

  • Separate signal conditions, strategy orders, and outbound alert messages.
  • Use alert_message on the order calls that need custom messages.
  • Configure the alert dialog to include {{strategy.order.alert_message}} when required.
  • Test entries, exits, partial exits, and reversals separately.
  • Do not assume replay alert behaviour proves live webhook behaviour.

The practical takeaway is that strategy alerts are their own surface. Treating them like indicator alerts with trades attached is how messages become ambiguous.