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);
             }
         }
     }
 }

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 IsRealTime/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");

PlaySound (2 of 2)

Summary

Plays the specified SoundType.

Remarks

This method doesn't work during backtesting and optimization.In indicators, use it with IsRealTime/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);

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");