Email notifications when indicator has passed a chosen threshold

Created at 21 Sep 2012, 09:31
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

matttt

Joined 21.09.2012

Email notifications when indicator has passed a chosen threshold
21 Sep 2012, 09:31


Hello forum,

I know that an email can be sent when an indicator has passed a chosen level, i.e +/-100 for CCI or 0 for MACD.

Would the support team (or a forumer) be able to post an exemple of the code needed to use this functionnality with an indicator that has multiple curves (i.e MACD) ?

I think it would be of great help, not only for me, but in general for all new users.

Then up to each user to personalyze it with the indicator and chosen level he/she wants.

Thanks in advance for your help.

Matttt

 

 

 


@matttt
Replies

matttt
21 Sep 2012, 09:40

Email notifications when indicator has passed a chosen threshold

To clarify (sorry) :> Indicator should actually CROSS chosen level for the email to be sent.

i.e on H1 period with the MACD :
if MACD < 0 at 9AM
[...] and MACD > 0 at 10AM
[...] then the email is immediatly sent at 11.00AM
[...] and if it stays above 0 it doesn't send an email until it goes below 0 level.


@matttt

matttt
24 Sep 2012, 16:14

I'm on something else at the moment, but part of the solution may be in the new release of the soft with the command :

Notifications.SendEmail(string from, string to, string subject, string text): Introduced a new method which sends a notification email message from Robots and Indicators. You can change the settings of emails from Email Settings menu item under preferences in both cTrader and cAlgo.

I'll get back when I will have had the time to tackle this point.And if only I manage to make it work indeed ;)


@matttt

admin
24 Sep 2012, 17:23

Hello,

 

Please try this code:

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Levels(0)]
    [Indicator]
    public class macdEmail:Indicator
    {
        private MacdCrossOver _macdCrossOver;
        private bool _emailSent;
        private string _from;
        private string _to;
        private string _subject;
        private string _text;

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }
        
        [Parameter("Period", DefaultValue = 9)]
        public int Period { get; set; }

        [Output("MACD")]
        public IndicatorDataSeries Macd { get; set; }

        protected override void Initialize()
        {
            _macdCrossOver = Indicators.MacdCrossOver(LongCycle, ShortCycle, Period);
            
            // Add your information below
            _from = "sender@...";
            _to = "receiver@...";
            _subject = "Macd Crossover";
            _text = "Crossed above";

        }

        public override void Calculate(int index)
        {
            Macd[index] = _macdCrossOver.MACD[index];

            // Make sure the email will be sent only at RealTime
            if (!IsRealTime)
                return;
            
            if (!_emailSent && _macdCrossOver.MACD[index - 2] < 0 && _macdCrossOver.MACD[index - 1] > 0)
            {                
                Notifications.SendEmail(_from,  _to, _subject, _text);
                Print(_text);
                _emailSent = true;
                return;
            }

            if(_emailSent && _macdCrossOver.MACD[index - 1] > 0 && _macdCrossOver.MACD[index] < 0)
            {
                _text = "crossed below";
                Notifications.SendEmail(_from, _to, _subject, _text);
                Print(_text);
                _emailSent = false;
            }

        }
    }
}



 


@admin

bb1902
09 Feb 2020, 16:44 ( Updated at: 21 Dec 2023, 09:21 )

RE:

admin said:

Hello,

 

Please try this code:

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Levels(0)]
    [Indicator]
    public class macdEmail:Indicator
    {
        private MacdCrossOver _macdCrossOver;
        private bool _emailSent;
        private string _from;
        private string _to;
        private string _subject;
        private string _text;

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }
        
        [Parameter("Period", DefaultValue = 9)]
        public int Period { get; set; }

        [Output("MACD")]
        public IndicatorDataSeries Macd { get; set; }

        protected override void Initialize()
        {
            _macdCrossOver = Indicators.MacdCrossOver(LongCycle, ShortCycle, Period);
            
            // Add your information below
            _from = "sender@...";
            _to = "receiver@...";
            _subject = "Macd Crossover";
            _text = "Crossed above";

        }

        public override void Calculate(int index)
        {
            Macd[index] = _macdCrossOver.MACD[index];

            // Make sure the email will be sent only at RealTime
            if (!IsRealTime)
                return;
            
            if (!_emailSent && _macdCrossOver.MACD[index - 2] < 0 && _macdCrossOver.MACD[index - 1] > 0)
            {                
                Notifications.SendEmail(_from,  _to, _subject, _text);
                Print(_text);
                _emailSent = true;
                return;
            }

            if(_emailSent && _macdCrossOver.MACD[index - 1] > 0 && _macdCrossOver.MACD[index] < 0)
            {
                _text = "crossed below";
                Notifications.SendEmail(_from, _to, _subject, _text);
                Print(_text);
                _emailSent = false;
            }

        }
    }
}


 

 

 

Hi support team,

 

I tried this code:

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Levels(0)]
    [Indicator()]
    public class MACDcrossover : Indicator
    {
        private MacdCrossOver _macdCrossOver;
        private bool _emailSent;
        private string _from;
        private string _to;
        private string _subject;
        private string _text;

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        [Parameter("Period", DefaultValue = 9)]
        public int Period { get; set; }

        [Output("MACD")]
        public IndicatorDataSeries Macd { get; set; }

        protected override void Initialize()
        {
            _macdCrossOver = Indicators.MacdCrossOver(LongCycle, ShortCycle, Period);

            // Add your information below
            _from = "bb1902@gmail.com";
            _to = "bb1902@gmail.com";
            _subject = "Macd Crossover";
            _text = "Crossed above";

        }

        public override void Calculate(int index)
        {
            Macd[index] = _macdCrossOver.MACD[index];

            // Make sure the email will be sent only at RealTime
            if (!IsRealTime)
                return;

            if (!_emailSent && _macdCrossOver.MACD[index - 2] < 0 && _macdCrossOver.MACD[index - 1] > 0)
            {
                Notifications.SendEmail(_from, _to, _subject, _text);
                Print(_text);
                _emailSent = true;
                return;
            }

            if (_emailSent && _macdCrossOver.MACD[index - 1] > 0 && _macdCrossOver.MACD[index] < 0)
            {
                _text = "crossed below";
                Notifications.SendEmail(_from, _to, _subject, _text);
                Print(_text);
                _emailSent = false;
            }

        }
    }

 

image.png

I don't know where wrong is, but ctrader did not send me any notification email, can you help me?

Thank you


@bb1902

PanagiotisCharalampous
10 Feb 2020, 08:53

Hi bb1902,

Go to Settings > Advanced and make sure your email is configured properly.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

nh.zadeh
03 Feb 2023, 14:12 ( Updated at: 21 Dec 2023, 09:23 )

RE:

PanagiotisCharalampous said:

Hi bb1902,

Go to Settings > Advanced and make sure your email is configured properly.

Best Regards,

Panagiotis 

Join us on Telegram

 

Dear Panagiotis 

I set the email as above but I receive 03/02/2023 15:32:47.921 | Failed to send email "Notification". Connection to SMTP server failed

Please advise


@nh.zadeh