Skip to content

Show Popup

Ahmad Noman Musleh edited this page Oct 2, 2019 · 13 revisions

Trigger First Alert

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

using cAlgo.API.Alert;

Then call the "ShowPopup" method on your code:

Notifications.ShowPopup();

And you will see this:

cTrader Alert Popup

The user will be able to change the popup 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 don't have to care about the alert time zone, the user will be able to set the time zone on popup settings.

There are several other overloads of ShowPopup method that you can use based on your needs.

Clone this wiki locally