Strategy Alerts

How do I create strategy alerts?

To create a strategy alert, you can:

  • Use the “Add Alert” button on the “Strategy Tester” panel: 
  • Use the strategy's drop-down menu: 
  • Select your strategy from the Create Alert dialog:

How do strategy alerts work?

When an alert is created for a strategy, a copy of the strategy is created on our servers. This copy then runs independently from the chart's strategy in your browser, and changes to your chart's strategy will have no effect on the operation of its copy running on our servers. For any change to your chart strategy's settings to be reflected in the alert's behavior, you will need to delete the previous alert and create a new one.

How does the strategy run on the servers?

After calculating on history, the strategy moves to realtime calculations. When an order placed by the strategy is executed by the broker emulator, an alert is triggered. Notifications are sent each time an order is executed, until the alert reaches its expiration date.

Notifications are not sent for orders on historical bars. Alerts are only triggered for orders executed in realtime.

More than one notification can be issued in the same bar, but as mentioned above, the alert will be stopped if it triggers more than 15 times in 3 minutes.

You can use placeholders to build your alert's notification message. They will be replaced by their corresponding value when the alert triggers. A placeholder is defined by using one of the following keywords surrounded by double curly brackets, e.g., {{strategy.position_size}}:

  • 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.

You can find more information on placeholders here.