How to use a variable value in alert?

You can use special placeholders to access variable values in alert’s message. For example, you can create an alert on NASDAQ:AAPL and type in a message box: 

{{exchange}}:{{ticker}}, price = {{close}}, volume = {{volume}}

After the alert is triggered, you’ll get corresponding values:

Here is a list of available placeholders:

1. {{ticker}} - ticker of the symbol used in alert (AAPL, BTCUSD, etc.).

2. {{exchange}} - exchange of the symbol used in alert (NASDAQ, NYSE, MOEX, etc). Note that for delayed symbols, the exchange will end with “_DL” or “_DLY.” For example, “NYMEX_DL.”

3. {{close}}, {{open}}, {{high}}, {{low}}, {{time}}, {{volume}} - corresponding values of the bar on which the alert has been triggered. Note that alerts on indicators, non-standard charts and drawings depends on a resolution, while simple price alerts (e.g., price crossing some value) are always calculated on 1-minute bars. {{time}} is in UTC, formatted as yyyy-MM-ddTHH:mm:ssZ. For example, 2019-08-27T09:56:00Z. Other values are fixed-point numbers with a decimal point separating the integral and fractional parts. For example, 1245.25.

4. {{timenow}} - current fire time of the alert, formatted in the same way as {{time}}. Return time to the nearest second, regardless of the resolution.

5. {{plot_0}}, {{plot_1}}, ... {{plot_19}} - corresponding output series of an indicator used in the alert. Note that the plots are numbered from zero. The highest plot ID is 19 (you can access only 20 first output series). Output series are the values of an indicator you can see on a chart. For example, the built-in volume indicator has two output series: Volume and Volume MA. You can create an alert on it and type in a message box something like this:

Volume: {{plot_0}}, Volume average: {{plot_1}}

Placeholders with the "strategy" prefix can only be used in strategy alerts:

6. {{strategy.position_size}} - returns the value of the same keyword in Pine, i.e., the size of the current position.

7. {{strategy.order.action}} - returns the string “buy” or “sell” for the executed order.

8. {{strategy.order.contracts}} - returns the number of contracts of the executed order.

9. {{strategy.order.price}} - returns the price at which the order was executed.

10. {{strategy.order.id}} - returns the ID of the executed order (the string used as the first parameter in one of the function calls generating orders: strategy.entry, strategy.exit or strategy.order).

11. {{strategy.order.comment}} - returns the comment of the executed order (the string used in the comment parameter in one of the function calls generating orders: strategy.entry, strategy.exit or strategy.order). If no comment is specified, then the value of strategy.order.id will be used.

12. {{strategy.order.alert_message}} - returns the value of the alert_message parameter which can be used in the strategy's Pine code when calling one of the functions used to place orders: strategy.entry, strategy.exit or strategy.order. This feature is only supported in Pine v4.

13. {{strategy.market_position}} - returns the current position of the strategy in string form: “long”, “flat”, or “short”.

14. {{strategy.market_position_size}} - returns the size of the current position as an absolute value, i.e. a non-negative number.

15. {{strategy.prev_market_position}} - returns the previous position of the strategy in string form: “long”, “flat”, or “short”.

16. {{strategy.prev_market_position_size}} - returns the size of the previous position as an absolute value, i.e. a non-negative number.

After the alert is triggered, you’ll see the corresponding values:

The same rules apply to scripts written in Pine. Series are counted based on their calling order in the code. See the list of functions below. Their series can be used in notification messages:

  • plot;
  • plotshape;
  • plotchar;
  • plotarrow;
  • plotbar;
  • plotcandle.

If the series argument of such functions contains a Boolean value, 0 or 1 will be substituted in the notification message. Keep in mind that certain functions - plotcandle and plotbar - display 4 series each, and every one of them will be taken into account in the numbering logic.

However, this method of accessing plots is not always convenient. To make things easier, we added support for calling plots using their names. To do this, use the placeholder {{plot("Name")}}, where Name is the name of the series.

For built-in indicators, the only names that are supported are the ones that are used in the English version. In the example with the Volume indicator for accessing series using their names, you would include the following in the message:

Volume: {{plot("Volume")}}, Volume average: {{plot("Volume MA")}}

Similarly, for Pine Script to access the series, you should specify the name from the title argument of the corresponding functions, (supported for all plot functions except plotcandle and plotbar), and the language will no longer matter. If you do not have access to the code, the name can be seen in the style settings.

For example, to access the values of this script:

//@version=4
study("My script")
plot(close, title="series")

Include {{plot("series")}} in the alert message.

The same name is shown in the script settings:

When using several indicators in a single alert, you can refer to the values of the first one - the one indicated in the first drop-down list. See example below.

When an alert includes these settings, you can only refer to the MA values. To access the values of the script “My script,” you need to select it in the first drop-down list.

You can also specify new placeholders in the message argument of the alertcondition function. For example:

//@version=4
study("My script")
alertcondition(close>open, message="price {{ticker}} = {{close}}")

The message from the argument is automatically pulled into the message window in the alert creation dialog.

Please note that when creating an alert with a condition from the alertcondition function, the value substitution will only work for v4 scripts or higher.

Values from triggered alerts can be used together with webhooks by sending variable values from a message to the desired addresses. Or by using external 3rd party apps like TradingView Alerts to MT4/MT5, which already utilizes dynamic values usage. Some syntax use-cases can be found in this example script. This opens up even more possibilities for those of you who use alerts.

Открыть график
Домой Скринер акций Скринер форекс Скринер криптовалют Экономический календарь О проекте Особенности Цены Приведи друга Правила поведения Справочный центр Решения для сайтов и брокеров Виджеты Графики TradingView для сайтов Легкая версия графиков Блог и новости Твиттер
Профиль Настройка профиля Счёт и оплата Ваши друзья Монеты Мои запросы в поддержку Справочный центр Опубликовано идей Подписчики Подписки Личные сообщения Чат Выйти