Skip to content

Proper Implementation

Ahmad Noman Musleh edited this page May 29, 2020 · 3 revisions

Install it via Nuget

I strongly recommend you to use Nuget for installation, it makes your life much easier and allows you to easily update/remove it.

Avoid Calling ShowPopup Continuously

To implement the alert popup on your cBot/indicator properly you have to be sure to not call the "ShowPopup" method continuously several times, as it will cause your cTrader platform to crash, to avoid the situation you can use several methods to check before calling the "ShowPopup" method.

If you are using it on your indicator, you can use the bar index and "IsLastBar" property to check if you have called the "ShowPopup" previously for that bar or not, if not then you can call the ShowPopup, example:

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()
        {
        }

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

                Notifications.ShowPopup();
            }
        }
    }
}

As you can see on the code I have used "IsLastBar" to avoid calling "ShowPopup" on historical bars, calling the "ShowPopup" without checking for "IsLastBar" most probably will crash your platform.

For cBots you have to find solutions based on your own scenario, like checking the last time you called "ShowPopup".

Always use latest version

We continuously release new versions that contain bug fixes, tweaks, and sometimes new features, you can easily update to latest available version from Nuget package manager.

Clone this wiki locally