Skip to content

Show Popup

Ahmad Noman Musleh edited this page May 31, 2020 · 13 revisions

Trigger First Alert

After you have installed the library on your cTrader indicator/cBot, you will be able to show the pop-up by calling the "Notifications.ShowPopup" method. However, before that, you must first change the "AccessRights" of your indicator/cBot to "AccessRights.FullAccess" and then add the "cAlgo.API.Alert" using it on top of your indicator/cBot code:

using cAlgo.API.Alert;

After this step call the "ShowPopup" method on your code:

Notifications.ShowPopup();

You will then see this:

cTrader Alert Popup

The user will be able to change the pop-up theme and accent.

Indicator Sample

using cAlgo.API;
using cAlgo.API.Alert;
using System;
using cAlgo.API.Alert.Utility;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class AlertTest : Indicator
    {
        private int _barIndex;

        protected override void Initialize()
        {
            // Setting this allows you to see the alert library error messages on the cTrader logs
            // It's optional
            Logger.Tracer = Print;
        }

        public override void Calculate(int index)
        {
            if (_barIndex != index && IsLastBar)
            {
                _barIndex = index;

                TradeType tradeType = MarketSeries.Close[index - 1] > MarketSeries.Open[index - 1] ? TradeType.Buy : TradeType.Sell;

                Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, tradeType, "AlertTest Indicator", Symbol.Bid, "No comment", Server.Time);
            }
        }
    }
}

cBot Sample

using cAlgo.API;
using cAlgo.API.Alert;
using cAlgo.API.Alert.Utility;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class AlertTester : Robot
    {
        private int _barIndex;

        protected override void OnStart()
        {
            // Optional, if you want to see the alert library logs on cTrader logs tab then set this
            Logger.Tracer = Print;
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {
            int index = MarketSeries.Close.Count - 1;

            if (_barIndex != index)
            {
                _barIndex = index;

                TradeType tradeType = MarketSeries.Close[index - 1] > MarketSeries.Open[index - 1] ? TradeType.Buy : TradeType.Sell;

                Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, tradeType, "AlertTest cBot", Symbol.Bid, "No comment", Server.Time);
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

You do not have to worry about the alert time zone; the user will be able to set the time zone in the pop-up settings.

There are several other overloads of the ShowPopup method that can be used according to your requirements.

Clone this wiki locally