Whitebox Strategy Engine ยป Alerts


Overview

TradingView allows you to get notified whenever something "interesting" happens on a chart. To receive such notifications, you will need to create an "Alert" on the chart with your custom conditions. Whenever the condition becomes true, TradingView will send you a notification, so that you can take action. (open/close positions, etc.)

You can use alerts not only to notify yourself to take action manually but also to send messages to 3rd party trade execution platforms to place trades for you. Using the alerting functionality you can more or less completely automate trading.

On the surface, the alerting functionality looks simple to use. However, from experience, we can tell that it can be one of the main sources of confusion for many traders.

Please note that if you've been using alerts on TradingView before, you may find it confusing how to set up alerts for our strategy scripts. This is because we are using a relatively new method to send alerts from the strategy that allow for much greater customisability, and also it only requires a single alert per chart to fully automate trading.

Types of alerts

Long: Entry

If you enable Long: Entry alerts, an alert will be sent the moment the strategy enters into a long trade.

Long Entry Alert

Long: Exit

If you enable Long: Exit alerts, an alert will be sent the moment the strategy exits from a long trade (in profit or loss). In other words, whenever the trade is closed for whatever reason - be that because of TP / SL was hit, or because an early position closure condition was activated, this alert will be sent.

Long Exit Alert

Short: Entry

If you enable Short: Entry alerts, an alert will be sent the moment the strategy enters into a short trade.

Short Entry Alert

Short: Exit

If you enable Short: Exit alerts, an alert will be sent the moment the strategy exits from a short trade (in profit or loss). In other words, whenever the trade is closed for whatever reason - be that because of TP / SL was hit, or because an early position closure condition was activated, this alert will be sent.

Short Exit Alert

Long: Stop Loss Moved

If you enable Long: Stop Loss Moved alerts, an alert will be sent the moment the strategy moves the stop loss while in a long trade.

Note: Due to the 'max. 15 alerts in 3 minutes' limitation of TradingView, the 'Stop Loss Moved' alert will be sent at most once every 30 seconds. This is to protect your alert from being shut down due to it triggering too frequently.

Long Stop Loss moved

Short: Stop Loss Moved

If you enable Short: Stop Loss Moved alerts, an alert will be sent the moment the strategy moves the stop loss while in a short trade.

Note: Due to the 'max. 15 alerts in 3 minutes' limitation of TradingView, the 'Stop Loss Moved' alert will be sent at most once every 30 seconds. This is to protect your alert from being shut down due to it triggering too frequently.

Short Stop Loss moved

Long: Take Profit Moved

If you enable Long: Take Profit Moved alerts, an alert will be sent the moment the strategy moves the take profit while in a long trade.

Note: Due to the 'max. 15 alerts in 3 minutes' limitation of TradingView, the 'Take Profit Moved' alert will be sent at most once every 30 seconds. This is to protect your alert from being shut down due to it triggering too frequently.

Long Take Profit Moved

Short: Take Profit Moved

If you enable Short: Take Profit Moved alerts, an alert will be sent the moment the strategy moves the take profit while in a short trade.

Note: Due to the 'max. 15 alerts in 3 minutes' limitation of TradingView, the 'Take Profit Moved' alert will be sent at most once every 30 seconds. This is to protect your alert from being shut down due to it triggering too frequently.

Short Take Profit Moved

Long: DCA Order Filled

If you enable Long: DCA Order Filled alerts, an alert will be sent the moment the strategy detects a "DCA order fill" event while in a long trade.

Long DCA Order Filled

Short: DCA Order Filled

If you enable Short: DCA Order Filled alerts, an alert will be sent the moment the strategy detects a "DCA order fill" event while in a short trade.

Short DCA Order Filled

Alert message placeholders

Alert messages can contain dynamic values, such as the price a position was opened at, or the size of the position.

These dynamic values are called alert message placeholders.

Here is a list of the placeholders that you can use in every strategy script:

  • {{open}} - Current bar open price

  • {{high}} - Current bar high price

  • {{low}} - Current bar low price

  • {{close}} - Current bar close price (Note: On a realtime bar the 'close' price is the 'last traded price')

  • {{volume}} - Current bar volume

  • {{stop_loss}} - The price at which the stop loss was placed

  • {{stop_loss_percentage}} - The % difference between the entry price and the stop loss - Note: this is only available in the 3 EMA strategy

  • {{take_profit}} - The price at which the take profit was placed

  • {{take_profit_percentage}} - The % difference between the entry price and the take profit - Note: this is only available in the 3 EMA strategy

  • {{entry_price}} - The price at which the position was opened

  • {{exchange}} - Exchange of the symbol used in alert (NASDAQ, NYSE, BINANCE, etc.)

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

  • {{base}} - Base currency of the symbol used in alert (e.g. for BTC/USD it's BTC)

  • {{quote}} - Quote currency of the symbol used in alert (e.g. for BTC/USD it's USD)

  • {{version}} - The version of the strategy

  • {{datetime}} - The UTC time of firing the alert

  • {{strategy.equity}} - Returns the strategy's equity (which is the sum of the initial capital, net profit, and unrealised profit/loss) at the moment of sending the alert

  • {{strategy.position_size}} - Returns the value of the same keyword in Pine, i.e., the size of the current position (if negative: short, if positive: long, if zero: flat)

  • {{strategy.position_value}} - Returns the value of the position (aka the total exposure). For example buying 1 BTC at 50,000 USD makes the position to have a value of 50,000

  • {{strategy.position_percentage}} - Returns the value of the position expressed as a % of equity. For example buying 1 BTC at 50,000 USD with an equity of 100,000 USD, will return 50

  • {{strategy.position_risk_value}} - Returns the amount that is being risked on a particular trade

  • {{strategy.position_risk_percentage}} - Returns the risk amount as a % of the equity

  • {{strategy.order.action}} - Returns the string "buy" or "sell" for the executed order (Note: only present if position size is not zero)

  • {{strategy.order.contracts}} - Returns the number of contracts of the executed order (it is the absolute value of strategy.position_size)

  • {{strategy.order.price}} - Returns the price at which the order was executed (rounded, it is the rounded value of strategy.position_avg_price)

  • {{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 (it is the absolute value of strategy.position_size)

Some strategies may have strategy specific alert message placeholders. For more info please see the strategy specific documentation page.

How to use these placeholders in alert messages?

Simply open the strategy settings, scroll down to the Alerts section, and input the placeholder in one of the text boxes.

For example, you could type this in the Long: Entry input:

Long entry at {{entry_price}}. Take profit at {{take_profit}}, stop loss at {{stop_loss}}.

To validate whether the message is valid, close the settings dialog, and place the mouse cursor over an alert label. The tooltip of the label will show the evaluated alert message:

Evaluated Alert Message

Alert message expressions

We also have an experimental expression parser built into our alert messaging system which allows you to use simple mathematical expressions in alert messages.

To use an expression you need to surround it with double brackets.

For example if you place this message inside the Entry: Long message box:

Long entry. Take profit is {{take_profit}}. 5% increased take profit is [[ {{take_profit}} * 1.05 ]]

Whenever the strategy opens a long position, you will be sent the following alert:

Alert Message Expressions

Supported operators: +, -, *, /, % (modulus), ^ (exponentiation)

Parentheses are supported as well: [[ (1 + 2) * 3 ]] is nine.

Alert Message Expressions Using Parenthesis

How to set up alerts on strategies

1. Set up the strategy on a chart

Create a brand new chart layout, and add a strategy script to it (e.g. Data Trader - Supertrend strategy).

Rename the chart layout to something that helps you identify this chart later on, for example 1H BTCUSDT, DT-Supertrend alerts.

Rename Chart Layout

Once you have set up the alerts on this chart, please do not change anything on it (including the timeframe, strategy settings, etc.). This is because later on when you need to visualise the alert messages you receive, you can simply open this chart for inspection, without having to remember how you had the strategy configured when you first created the alert.

2. Enable the alerts you are interested in

Open the strategy settings, and scroll down to the Alerts section.

Enable the alerts you wish to receive a notification for (e.g. Long: Entry and Long: Exit), then close the strategy settings window.

3. Create a TradingView alert

OK. Here is where it gets a bit confusing. So far, you have told the strategy the alerts you are interested in receiving (in step 2), however the strategy is only able to send those alerts if you first create a TradingView Alert...

Wait, what? Didn't we enable the alerts already? Now we need to create a "TradingView Alert"? What is going on?

You see, when you toggled the checkboxes next to each "alert" in the strategy settings dialog (e.g. Enable Long: Entry Alert), you merely expressed interest in receiving alerts for those events (i.e. when a long position opens).

But, in order for the strategy to be able to send you those notifications, you need to have a "TradingView Alert" created.

To create a "TradingView Alert" press the "Create Alert" button at the top toolbar:

Create Alert

This should bring up the alert creation dialog.

In the first dropdown select the strategy script (e.g. Data Trader - Supertrend strategy).

Then in the second dropdown select alert() function calls only:

Create Strategy Alert Dialog

It is important that you select alert() function calls only otherwise the alert functionality won't work properly.

What you set the expiration time to depends on how long you wish the alert to be active for. If you are on a Premium TradingView subscription it makes sense to have "Open-ended" selected, which means your alert will keep running forever.

Next, configure the Alert actions. Again, how you set this up depends on how you want to be notified whenever something happens inside the strategy.

Once you are all set up, click on the Create button.

Your alert should be created within a few seconds and it should show up as "Active" in the Alert sidebar:

Alert Sidebar

What happens after you hit the Create button

TradingView creates a clone of your chart with the exact same strategy settings, and activates the alert on it. This "cloned chart" that TradingView is running for you on their servers in the background is "invisible" to you. You cannot open this cloned chart for inspection. This cloned chart has no connection whatsoever to the chart of which you created the alerts from (the one running inside your browser / mobile phone app).

If you change anything on the chart you have open in your browser, that will not affect the alert, as you are changing the configuration of your chart, and not the chart TradingView cloned. You simply cannot edit the strategy configuration within the cloned chart. The only way to change the strategy settings of the alert, if you delete the alert and recreate it with the new settings. Think of your chart as a blueprint TradingView uses to create a new chart on which it sets up the alerts. You cannot change the "concrete" chart that was made out of your blueprint, only the blueprint itself.

If you don't see the same trades taking place on the chart you have running in your browser vs. the cloned chart the alert was set up on, it is very likely because there is a difference in configuration between the two charts.

If you are 100% confident that the chart you are looking at in your browser and the chart TradingView cloned when creating the alert is configured exactly the same, yet the trades that are opened are different (i.e. you receive an entry alert but the trade is not shown on your chart), then that might be a bug.

FAQ

Do I need to keep my computer running for the alerts to work?

No. Alerts are running on TradingView's servers, not on your computer. You are free to turn off your computer whenever you wish, the alerts will continue to function.

Can I edit the alert?

Once you've created an alert, you can only edit the alert's name and notification settings, but not the settings of the strategy.

If you wish to change the strategy settings, you will need to delete the alert and create a brand new one with the new settings.

Changing the settings of the strategy after an alert was created from it will not affect the alert.

Troubleshooting

I set up an alert on a chart. Some time later I received a couple of alert messages. I opened the chart again, but I couldn't see any of those trades having taken place on the chart. Why are the trades I got alerted to are not displayed on the chart I am looking at?

Similar questions:

I set up an alert on a chart. Some time later when I open the chart I can see trades having taken place, but I did not get alerted to all / any of them. Why I am not getting entry alerts?

and

The values I receive in the alerts don't match with those I see on the chart or on the Strategy Tester tab. Does the strategy calculate things differently when it is running inside an alert?

First and foremost, the most important thing to understand is that the chart you are looking at in your browser, and the chart the alert is "executing on", has nothing to do with each other. The closest you can get to trying to visualise the chart the alert is executing on, is by setting up your chart the exact same way it was when you created the alert.

The best way to set up alerts, is to create dedicated charts for them. Please see above.

The next thing you need to be aware of, is that alerts cannot be edited. What does this mean?

  1. You set up the strategy with a set of configuration, let's call it configuration set "X"
  2. You create an alert from your chart, using configuration set "X"
  3. A minute later you realise you made a mistake in the config, so you open the strategy settings and fix it. Now your chart has a configuration set "Y"

If you think that your alert is now running with configuration set "Y", your assumption is not correct.

When you create an alert, its configuration is set in stone. You simply cannot edit it. If you want to change the strategy configuration inside the alert, you must first delete it, and create a new one with your new settings.

Remember that you must keep the "Recalculate after order is filled" and "Recalculate on every tick" checkboxes enabled under Properties, otherwise the alerts will be sent with a delay.

Please also remember that the strategies cannot be used on Heikin Ashi, Renko etc. charts, only on standard candlestick charts.

If you are confident that the chart you are looking at is configured the exact same way as the chart you created the alerts from, yet you don't see the same trades having taken place, then please raise an issue.

Automation

If you would like to automate your trading, please see our dedicated help page on trade automation: Automated Trading

Further reading

To learn more about alerts, please see the following articles from TradingView's help center: