Table of Contents

Alerts

An indicator raises an alert with AddAlert: the platform plays a sound, shows a popup notification and adds a line to the alerts window.

AddAlert(string soundFile, string instrument, string message, Color background, Color foreground)
AddAlert(string soundFile, string message)
Parameter Meaning
soundFile The name of a platform alert sound without the extension, for example "alert1" (the default sound of the built-in indicators); an unknown name plays the default sound
instrument The instrument name shown in the alerts window
message The text
background, foreground The colors of the line (System.Windows.Media.Color)

The short overload uses the default colors and the instrument of the indicator. Two more overloads take a last parameter: DateTime time sets the time of the alert, bool showPopup = false adds the alert without the popup.

Raise alerts for the live bar only: OnCalculate runs over the whole history too, and a condition that was true in the past would produce one alert per historical bar. The example alerts at the first bar of every new session:

using System.Windows.Media;

using ATAS.Indicators;

namespace ATAS.Docs.Samples.ChartIndicators;

public class NewSessionAlertIndicator : Indicator
{
    private int _lastAlertBar = -1;

    protected override void OnCalculate(int bar, decimal value)
    {
        // true for the first bar of a session (and for bar 0); IsNewWeek and IsNewMonth work the same way
        if (!IsNewSession(bar) || bar == _lastAlertBar)
            return;

        _lastAlertBar = bar;

        // Alerts only for the live bar: the history would produce one alert per past session
        if (bar != CurrentBar - 1)
            return;

        var instrument = InstrumentInfo?.Instrument ?? "";
        AddAlert("alert1", instrument, "New session", Colors.Black, Colors.White);
    }
}