Skip to content

INotifications

Summary

It is an interface that represents all Notifications.

Signature

1
public abstract interface INotifications

Namespace

cAlgo.API.Internals

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 using cAlgo.API;
 namespace cAlgo
 {
     // This sample indicator shows how to use API notifications to play sound or send an email
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class NotificationsSample : Indicator
     {
         private int _lastNotifiedBarIndex;
         [Parameter("Sound File Path", DefaultValue = "C:\\Windows\\Media\\notify.wav")]
         public string SoundFilePath { get; set; }
         [Parameter("Sender Email")]
         public string SenderEmail { get; set; }
         [Parameter("Receiver Email")]
         public string ReceiverEmail { get; set; }
         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);
             }
         }
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 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):
            # SoundFilePath is a parameter defined in C# file of indicator
         if api.SoundFilePath is not None and len(api.SoundFilePath) > 0:
             api.Notifications.PlaySound(api.SoundFilePath)
            # SenderEmail and ReceiverEmail are parameters defined in C# file of indicator
         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)
            # ShowPopup is a parameter defined in C# file of indicator
         if api.ShowPopup:
             api.Notifications.ShowPopup("Notification", message, PopupNotificationState.Success)

Methods

PlaySound (2)

PlaySound (1 of 2)

Summary

Plays a notification sound.

Remarks

This method doesn't work during backtesting and optimization.In indicators, use it with IsLastBar/IsLastBar, for real-time values.

Signature

1
public abstract void PlaySound(string fileName)

Parameters

Name Type Description
fileName string The sound file path

Return Value

void

Examples

1
 Notifications.PlaySound(@"C:\SampleDestination\SampleSound.mp3");
1
 api.Notifications.PlaySound("C:\SampleDestination\SampleSound.mp3")

PlaySound (2 of 2)

Summary

Plays the specified SoundType.

Remarks

This method doesn't work during backtesting and optimization.In indicators, use it with IsLastBar/IsLastBar, for real-time values.

Signature

1
public abstract void PlaySound(SoundType soundType)

Parameters

Name Type Description
soundType SoundType The SoundType to be played.

Return Value

void

Examples

1
 Notifications.PlaySound(SoundType.PositiveNotification);
1
 api.Notifications.PlaySound(SoundType.PositiveNotification)

See Also

SendEmail

Summary

Sends a notification email message.

Remarks

This method doesn't work during backtesting and optimization.Use correct settings before trying to send an email notification.You can do that in Preferences -> Email Settings

Signature

1
public abstract void SendEmail(string from, string to, string subject, string text)

Parameters

Name Type Description
from string Sender's Address
to string Recipient's Address
subject string Email Subject
text string Email Body

Return Value

void

Examples

1
2
 Notifications.SendEmail("from@email.com", "to@email.com",
             "Email Notification Subject", "Email body");
1
2
 api.Notifications.SendEmail("from@email.com", "to@email.com",
             "Email Notification Subject", "Email body")

ShowPopup

Summary

Shows a popup notification.

Signature

1
public abstract PopupNotification ShowPopup(string caption, string message, PopupNotificationState initialState)

Parameters

Name Type Description
caption string Caption or title.
message string Message or description.
initialState PopupNotificationState Initial state of notification.

Return Value

PopupNotification

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 using cAlgo.API;
 namespace cAlgo.Robots;
 [Robot(AccessRights = AccessRights.None)]
 public class TestExample : Robot
 {
     protected override void OnStart()
     {
         Notifications.ShowPopup("Caption", "Message", PopupNotificationState.Success);
     }
 }
1
2
3
4
5
6
7
8
9
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class Test():
     def on_start(self):
         api.Notifications.ShowPopup("Caption", "Message", PopupNotificationState.Success)