- An event output (
@plot.event) reports that something happened on a bar: a cross, a breakout, a volume spike. Users create an alert on the event by name, for example MACD cross: Bullish cross, instead of building a value condition on a plotted line. - A data output (
@plot.data) carries a number, such as a stop level or the ATR, that users can set value conditions on or put into the alert message, without adding a line to the chart.
Main returns.
Event outputs
Declare an event output with the@plot.event decorator.
Syntax
id: a unique identifier of the output, as for other plots.title: the name users see in the alert dialog. If omitted, theidis used.options: a list of the events this output can report, such as['Bullish cross', 'Bearish cross']. Leave it out for a single event.
Main returns for the output depends on options:
An output with several options
The indicator below plots MACD and its signal line and reports crosses of the two as one event output with two options.event is None on some paths and a string on others, so it needs the Optional[str] annotation. A conditional
expression needs none, so the same output can be written in one line:
A single event
Withoutoptions, the output is one event and Main returns a bool:
Creating an alert on an event
- Add the indicator to the chart and open the alert dialog (see Alerts overview).
- Choose the indicator as the source, then pick the event output by its title, for example MACD cross.
- For an output with options, pick one option, for example Bullish cross, or Any to be notified about every option. A single event has nothing more to choose.
How an event output is encoded
The output is stored as a numeric series, like any other plot:
The alert dialog builds a regular value condition from it: Inside Channel from
k - 0.5 to k + 0.5 for option
k, and Greater Than 0.5 for Any or a single event. You only need these numbers when you read the output
directly, for example through the Platform API, or set a value alert on it yourself.
Because the encoding follows the order of options, adding an option to the end of the list keeps existing alerts
valid, while reordering or removing options changes what they match.
Limitations of event outputs
- Not drawn. An event output never appears on the chart and has no entry on the Style tab or in the Outputs list of the indicator settings. To also show the event, add a marker or a label.
Mainreturns the option name orNone. A string literal that is not one of theoptionsis a compilation error. A string computed at run time that matches no option stops the indicator with an error that names the output and the value.- One option per bar. An output reports at most one option on a bar. If two events can happen on the same bar and users need alerts on both, declare them as separate outputs.
- Options rules.
optionsmust be written as a list literal right in the decorator, not as a module-level constant. It holds 2 to 32 distinct, non-empty string literals, each at most 64 characters, with no leading or trailing spaces. A list with one item is a compilation error: declare a single event instead.
Data outputs
Declare a data output with the@plot.data decorator:
id: a unique identifier of the output. It is also the name used in alert message placeholders.title: the name users see in the alert dialog. If omitted, theidis used.
Main returns a bare number for it (float or int), the same value a line would take. Return nan on bars where
there is no value.
The indicator below draws an EMA and exposes a trailing stop and the ATR as data outputs:
{{cond<N>.main.<id>}} placeholder, for example Stop: {{cond0.main.stop}}, ATR: {{cond0.main.atr}} (see
Variables in alert messages).
Limitations of data outputs
- Not drawn. A data output creates no chart series and has no entry on the Style tab. It shows no value in the status line or on the price scale, and does not affect the chart’s scale.
- Numbers only.
Mainreturns a barefloatorint. Returning aplot.Line(...)object, or passingcolor=ordisplay_options=to@plot.data, is a compilation error. - No fills.
@plot.fillcannot reference a data output or an event output.