-
Notifications
You must be signed in to change notification settings - Fork 6
Proper Implementation
Install it via Nuget
I strongly recommend that you use Nuget for installation, it will make your life much easier and it allows you to easily update/remove it.
Avoid Calling ShowPopup Continuously
To implement the alert popup on your cBot/indicator properly, ensure to not call the "ShowPopup" method continuously several times as it will cause your cTrader platform to crash. To avoid this situation you can use several methods to check this before calling the "ShowPopup" method.
If you are using it on your indicator, you can use the bar index and the "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 previously used bars. Calling the "ShowPopup" without checking for "IsLastBar" will most probably result in your platform crashing.
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 the latest available version from Nuget package manager.