Topics

Forum Topics not found

Replies

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