Email notifications when indicator has passed a chosen threshold

matttt since: 21 Sep 2012;

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

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 since: 21 Sep 2012;

  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 since: 21 Sep 2012;

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

admin's avatar

admin since: 30 Nov -0001;

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

        }
    }
}



 

TRADERS FIRSTâ„¢

bb1902 since: 09 Feb 2020;

  09 Feb 2020, 16:44
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

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  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

Head of Community Management at cTrader