Alerts from a TradingView strategy
One message that runs an entire strategy — entries, exits, reversals, scaling — because the strategy tells us where the position was and where it now is.
If your alert comes from a TradingView strategy, this is the short page — because a strategy can tell us what it did, and that means one message does everything.
New here? Read Sending messages to Nixora first; it covers where your webhook address lives and the two switches that must be on before anything trades.
The one message
Put this in the alert's Message box, your webhook address in Webhook URL, and you are done.
A strategy knows how it is positioned, so ONE alert covers entries, exits and reversals.
{"symbol":"{{ticker}}","action":"{{strategy.order.action}}","position":"{{strategy.market_position}}","prev_position":"{{strategy.prev_market_position}}"}
Those {{...}} parts are TradingView placeholders — it replaces them with real values as the alert
fires. You are not naming an instruction. You are reporting where the position was and where it now
is, and we work out the rest.
Set the alert to fire on Order fills only and leave it running. It will keep working as your strategy trades.
What it covers
Every case a strategy can produce, from that single message:
| The strategy went | We do |
|---|---|
| flat → long | open a long |
| flat → short | open a short |
| long → flat | close the long, in full |
| short → flat | close the short, in full |
| long → short | reverse to short |
| short → long | reverse to long |
| long → bigger long | scale in by the difference |
| long → smaller long | close that share of it |
That last pair is worth noticing: if your strategy scales in and out, the size change carries through without you writing anything extra. A position going from 2 units to 1 closes half — not a fixed lot count, a proportion, which is what you want when the same alert feeds accounts of different sizes.
Adding your own rules
The message above uses your strategy's own decisions. If you want a stop, a target or a fixed size applied to every entry, add the fields:
{"symbol":"{{ticker}}","action":"{{strategy.order.action}}","position":"{{strategy.market_position}}","prev_position":"{{strategy.prev_market_position}}","sl_pips":20,"tp_pips":40}
For sizing, prefer a risk-based field over a fixed lot count when more than one account is subscribed — each account then sizes to its own balance:
{"symbol":"{{ticker}}","action":"{{strategy.order.action}}","position":"{{strategy.market_position}}","prev_position":"{{strategy.prev_market_position}}","vol_pct_eq_loss":1}
That risks 1% of each account's equity, and it needs a stop to calculate against. Every sizing and stop option is listed in the Keyword reference.
If your values are computed in Pine
When the stop comes from ATR or the size from your own maths, those numbers only exist while the script runs. Build the message in code instead:
alert('{"symbol":"' + syminfo.ticker + '","action":"' + strategy.order.action + '","position":"' + strategy.market_position + '","prev_position":"' + strategy.prev_market_position + '","sl_price":' + str.tostring(myStop) + '}', alert.freq_once_per_bar_close)
Two things that will trip you up
Both position fields are required. position and prev_position must both be present in this
form. With only one of them we cannot tell what changed, and the alert is refused rather than
guessed at.
They must agree with the action. If action says buy while the transition says the position
went short, that is a contradiction, and a contradiction is refused. This is deliberate: the
alternative is picking one and being wrong half the time.
Both refusals appear in the Journal with the reason, so you are never left wondering.
When you need more than this
Some things a strategy alert cannot express — closing a specific percentage on a signal of your own, cancelling pending orders, switching the account off. Those name the instruction directly, and they are on the next page: Alerts from an indicator or your own code.