我在将 pine 脚本中的任意变量值添加到 Tradingview 警报时遇到困难。
看起来变量列表受
standard placeholders
限制。它们包括:
{{ticker}} | Ticker (meaning, symbol) of the instrument the alert generated on. For example: AAPL, EURUSD, USOIL, BTCUSD.
{{exchange}}| Exchange or data source of the instrument the alert generated on, such as NASDAQ, OANDA, COINBASE. When we don’t have real-time data for this exchange, its name ends with ‘_DL’ or ‘_DLY’ to signal delayed data. For example: NYMEX_DL and EUREX_DLY.
{{interval}}| Time interval the alert generated on. This is the time frame from the chart on which we made the alert.
{{close}} | Current close price of the bar the alert generated on. This is the latest, most-current price of when the alert fired. Examples include 124.83 and 1.53923.
{{open}} | Open price of the bar the alert generated on, like 33453.30 and 1.00329.
{{high}} | Current high price of the bar the alert generated on, such as 723.30 and 28.000.
{{low}} | Current low price of the bar the alert generated on. For example: 33.83 and 9.015.
{{volume}} | Current volume of the bar the alert generated on. For instance: 228, 4775, and, for a cryptocurrency, 1.15669521.
{{time}} | Opening time of the bar the alert generated on. This time uses the UTC time zone and shows in this format: yyyy-MM-ddTHH:mm:ssZ. For example: 2022-05-03T14:25:00Z.
{{timenow}} | Current and exact time of when the alert generated, in UTC and the yyyy-MM-ddTHH:mm:ssZ format. For example: 2023-07-27T17:38:10Z.
来源是这里。还有:
{{strategy.position_size}} - returns the value of the same keyword in Pine, i.e., the size of the current position.
{{strategy.order.action}} - returns the string “buy” or “sell” for the executed order.
{{strategy.order.contracts}} - returns the number of contracts of the executed order.
{{strategy.order.price}} - returns the price at which the order was executed.
{{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).
{{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.
{{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 and higher.
{{strategy.market_position}} - returns the current position of the strategy in string form: “long”, “flat”, or “short”.
{{strategy.market_position_size}} - returns the size of the current position as an absolute value, i.e. a non-negative number.
{{strategy.prev_market_position}} - returns the previous position of the strategy in string form: “long”, “flat”, or “short”.
{{strategy.prev_market_position_size}} - returns the size of the previous position as an absolute value, i.e. a non-negative number.
来源是这里。
有没有办法将用户定义的变量值传递给警报?
您可以使用
{{strategy.order.alert_message}}
来实现此目的。
例如,您可以使用以下代码:
strategy.entry("Short", strategy.short, alert_message = str.tostring(local_variable))
要设置警报,需要将
"{{strategy.order.alert_message}}"
粘贴到 Tradingview 警报设置编辑器(消息窗口)。
字符串版本的
local_variable
将显示在警报中。