Strategy Alerts

Important note

Using strategy alerts to automate trading can lead to unexpected results if you don’t take into account the limits inherent to how strategies behave. Automatic strategy alerts can be very useful to trade in real markets, but just like the autopilot mode of an aircraft, they should be kept under close watch. If you are going to be using alerts for real trading, please take these points into consideration:

  • Strategies are more susceptible to repainting than indicators because the broker emulator makes assumptions about price movement to simulate orders on historical bars. In realtime (or forward testing) however, streaming tick updates can be used as a source if the strategy is configured as such. If that is the case, you must be aware of the fact that simulated strategy orders on historical bars (arrows on the chart) may not behave the same way in realtime. 
  • The engine managing strategy alerts is not connected to your broker or exchange, and therefore cannot synchronize orders and/or positions. If the strategy and your broker are no longer in synch, unpredictable results and potential losses may occur. For example, an order executed on the chart may not be executed by your broker. This could lead to a situation where your strategy appears to have closed a losing position when in reality, the losing position is still open and the market is moving against you. Another example of potential loss would be a situation where on the broker’s side, you are holding a short position (when selling) while your strategy is holding a long position (when buying). The strategy may then send a sell order to close a long position when in reality, your short position on the broker’s side will increase. 
  • An alert will be stopped if it triggers too often. This will occur if it triggers more than 15 times in 3 minutes.

When do strategy alerts trigger?

Strategy alerts trigger when the strategy executes an order, which does not necessarily correspond to the time when that order is placed.

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

Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out