INotifications
interface cAlgo.API.Internals
DesktopCLICloud
It is an interface that represents all Notifications.
Environment behaviour
CLI — works differently. PlaySound and ShowPopup do nothing in the CLI; SendEmail sends the email as on desktop.
Cloud — not supported. Nothing is played, sent or shown in the cloud, and no error is reported.
Definition
public interface INotifications
Namespace: cAlgo.API.Internals · Group: Notifications
Examples
using cAlgo.API;
namespace cAlgo
{
// This sample indicator shows how to use API notifications to play sound or send an email
public partial class NotificationsSample : Indicator
{
private int _lastNotifiedBarIndex;
protected override void Initialize()
{
}
public override void Calculate(int index)
{
if (!IsLastBar || _lastNotifiedBarIndex == index) return;
_lastNotifiedBarIndex = index;
if (Bars.Last(1).Close > Bars.Last(1).Open)
{
Notify("Up Bar Closed");
}
else if (Bars.Last(1).Close < Bars.Last(1).Open)
{
Notify("Down Bar Closed");
}
}
private void Notify(string message)
{
if (!string.IsNullOrWhiteSpace(SoundFilePath))
{
Notifications.PlaySound(SoundFilePath);
}
if (!string.IsNullOrWhiteSpace(SenderEmail) && !string.IsNullOrWhiteSpace(ReceiverEmail))
{
Notifications.SendEmail(SenderEmail, ReceiverEmail, "Notification", message);
}
}
}
}
import clr
clr.AddReference("cAlgo.API")
from cAlgo.API import *
class NotificationsSample():
def initialize(self):
self.lastNotifiedBarIndex = 0
def calculate(self, index):
if api.IsLastBar == False or self.lastNotifiedBarIndex == index:
return
self.lastNotifiedBarIndex = index
if api.Bars.Last(1).Close > api.Bars.Last(1).Open:
self.notify("Up Bar Closed")
elif api.Bars.Last(1).Close < api.Bars.Last(1).Open:
self.notify("Down Bar Closed")
def notify(self, message):
if api.SoundFilePath is not None and len(api.SoundFilePath) > 0:
api.Notifications.PlaySound(api.SoundFilePath)
if api.SenderEmail is not None and len(api.SenderEmail) > 0 and api.ReceiverEmail is not None and len(api.ReceiverEmail) > 0:
api.Notifications.SendEmail(api.SenderEmail, api.ReceiverEmail, "Notification", message)
if api.ShowPopup:
api.Notifications.ShowPopup("Notification", message, PopupNotificationState.Success)
{
"AccessRights": "None",
"TimeZone": "UTC",
"IsOverlay": true,
"Parameters": [
{
"Name": "SoundFilePath",
"DisplayName": "Sound File Path",
"Type": "String",
"DefaultValue": "C:\\Windows\\Media\\notify.wav"
},
{
"Name": "SenderEmail",
"DisplayName": "Sender Email",
"Type": "String"
},
{
"Name": "ReceiverEmail",
"DisplayName": "Receiver Email",
"Type": "String"
},
{
"Name": "ShowPopup",
"DisplayName": "Show Popup",
"Type": "Boolean",
"DefaultValue": true
}
]
}