Replies

Vince
16 Sep 2019, 15:40

Hi Panagiotis,

Thank you for the offer. I have just reset the OS and from what I can see, now everything runs smooth. So there is no need for further investigation.

Thank you for the help!

Best regards,

Vince


@Vince

Vince
16 Sep 2019, 13:41

Were not there yet, but I managed to get Ctrader running.

First I installed Ctrader on a PC i have never installed Ctrader on before and it work perfectly. I could log in, all the chart templates were there. Then I revoked the active session for the desktop I am having problems with. My thinking was that this should prevent Ctrader from automatically logging in. And it did. I could get Ctrader running and it started with the log in screen. But when I then logged in, the software closed itself immediatly.

One step closer, but still not workable.

Vince

 


@Vince

Vince
16 Sep 2019, 12:39

Hi Panagiotis,

Thank you for the quick reply.

The clean installation worked. I am now able to get Ctrader installed.

However, now when the software opens, I get to see the interface and then closes itself before I can interact with the software.

Any thoughts?

Vince


@Vince

Vince
25 Jul 2018, 12:07

Hi Panagiotis,

I understand what you are saying and that is what I am trying to do. The problem I encounter is that the Cbot somehow does not read some of the values of the indicator. Do you have any idea why this is?

For example, if I make a reference to the indicator and only put in the notification sending part, it will produce an error saying that a value does not exist in the current context, see '2)' of my previous reply.

I saw that hibba7rain has a similar question, so I will read your replies on his topic as well and will try implementing your suggestions there as well.

 

Kind regards,

Vince


@Vince

Vince
24 Jul 2018, 23:54

Hi Panagiotis,

I am trying to make the Indicator work as a Cbot. I have tried different things:

1) Only referencing to the Indicator in the Onstart() section. Including the Parameters. This resulted in an error, saying the Parameters do not exist in the current context. 

Error CS0103: The name 'LongPeriod' does not exist in the current context

protected override void OnStart()
        {
            _supertrend = Indicators.GetIndicator<SupertrendCompletenoemail>(LongPeriod, LongMultiplier, ShortPeriod, ShortMultiplier);
        }

So I figured the Cbot needs more info for referencing.

2) I replaced the default Parameter with all Parameters from the Indicator. This resulted in a 'Build succeeded'. I added the check in the OnTick() section that would trigger the Notification. Which resulted in an error, saying _upBufferlong does not exist. Error CS0103: The name '_upBufferlong' does not exist in the current context

protected override void OnTick()
        {
            var sendNotification = false;
            //  Make all your indicator checks here
            //   .
            //   .
            //   .
            var value = MarketSeries.Close;
            if (Functions.HasCrossedAbove(_upBufferlong, value, 1))
            {
                if (sendNotification && !_notificationSent)
                {
                    Notifications.SendEmail("email", "email", "Subject", "Text");
                    _notificationSent = true;
                }
            }
        }

At this point I decided that I would convert the Indicator to the Cbot 1 on 1, that is the whole Initialize() section to the OnStart(), the whole Calculate() section to the OnTick() section, etc. This was partly succesful except I got the error that 'index' does not exist. Because of the OnTick() method, I thought it maybe would not need an [index] reference since it would be calculated according the OnTick() method.

3) I tried to remove the [index] which resulted in an error saying Error CS0029: Cannot implicitly convert type 'double' to 'cAlgo.API.IndicatorDataSeries'.

At this point I would not know what else I could do to make it work and would appreciate some pointers ;) The only thing I could think of is to somehow declare each variable in an earlier stage?? Below you will find the code that I finished with before removing the [index] :

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Supertrend : Robot
    {
        [Parameter(DefaultValue = 50)]
        public int LongPeriod { get; set; }

        [Parameter(DefaultValue = 10.0)]
        public double LongMultiplier { get; set; }

        [Parameter(DefaultValue = 20)]
        public int ShortPeriod { get; set; }

        [Parameter(DefaultValue = 5.0)]
        public double ShortMultiplier { get; set; }

        [Output("UpTrendLong", Color = Colors.Green, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries UpTrendLong { get; set; }

        [Output("DownTrendLong", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries DownTrendLong { get; set; }

        [Output("UpTrendShort", Color = Colors.Green, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries UpTrendShort { get; set; }

        [Output("DownTrendShort", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries DownTrendShort { get; set; }

        private IndicatorDataSeries _upBufferlong;
        private IndicatorDataSeries _downBufferlong;
        private IndicatorDataSeries _upBuffershort;
        private IndicatorDataSeries _downBuffershort;
        private AverageTrueRange _averageTrueRangelong;
        private AverageTrueRange _averageTrueRangeshort;
        private int[] _trendlong;
        private int[] _trendshort;
        private bool _changeofTrendlong;
        private bool _changeofTrendshort;

        private SupertrendCompletenoemail _supertrend;
        private bool _notificationSent;
        protected override void OnStart()
        {
            _supertrend = Indicators.GetIndicator<SupertrendCompletenoemail>(LongPeriod, LongMultiplier, ShortPeriod, ShortMultiplier);
            _trendlong = new int[1];
            _trendshort = new int[1];
            _upBufferlong = CreateDataSeries();
            _downBufferlong = CreateDataSeries();
            _upBuffershort = CreateDataSeries();
            _downBuffershort = CreateDataSeries();
            _averageTrueRangelong = Indicators.AverageTrueRange(LongPeriod, MovingAverageType.WilderSmoothing);
            _averageTrueRangeshort = Indicators.AverageTrueRange(ShortPeriod, MovingAverageType.WilderSmoothing);
        }

        protected override void OnTick()
        {
            var sendNotification = false;
            //  Make all your indicator checks here
            //   .
            //   .
            //   .

            // Init
            {
                UpTrendLong[index] = double.NaN;
                DownTrendLong[index] = double.NaN;
                UpTrendShort[index] = double.NaN;
                DownTrendShort[index] = double.NaN;

                double median = (MarketSeries.High[index] + MarketSeries.Low[index]) / 2;
                double atrlong = _averageTrueRangelong.Result[index];
                double atrshort = _averageTrueRangeshort.Result[index];

                _upBufferlong = median + LongMultiplier * atrlong;
                _downBufferlong[index] = median - LongMultiplier * atrlong;
                _upBuffershort[index] = median + ShortMultiplier * atrshort;
                _downBuffershort[index] = median - ShortMultiplier * atrshort;


                if (index < 1)
                {
                    _trendlong[index] = 1;
                    return;
                }

                Array.Resize(ref _trendlong, _trendlong.Length + 1);

                // Main Logic
                if (MarketSeries.Close[index] > _upBufferlong[index - 1])
                {
                    _trendlong[index] = 1;
                    if (_trendlong[index - 1] == -1)
                        _changeofTrendlong = true;
                }
                else if (MarketSeries.Close[index] < _downBufferlong[index - 1])
                {
                    _trendlong[index] = -1;
                    if (_trendlong[index - 1] == -1)
                        _changeofTrendlong = true;
                }
                else if (_trendlong[index - 1] == 1)
                {
                    _trendlong[index] = 1;
                    _changeofTrendlong = false;
                }
                else if (_trendlong[index - 1] == -1)
                {
                    _trendlong[index] = -1;
                    _changeofTrendlong = false;
                }

                if (_trendlong[index] < 0 && _trendlong[index - 1] > 0)
                    _upBufferlong[index] = median + (LongMultiplier * atrlong);
                else if (_trendlong[index] < 0 && _upBufferlong[index] > _upBufferlong[index - 1])
                    _upBufferlong[index] = _upBufferlong[index - 1];

                if (_trendlong[index] > 0 && _trendlong[index - 1] < 0)
                    _downBufferlong[index] = median - (LongMultiplier * atrlong);
                else if (_trendlong[index] > 0 && _downBufferlong[index] < _downBufferlong[index - 1])
                    _downBufferlong[index] = _downBufferlong[index - 1];

                // Draw Indicator
                if (_trendlong[index] == 1)
                {

                    UpTrendLong[index] = _downBufferlong[index];
                    if (_changeofTrendlong)
                    {
                        UpTrendLong[index - 1] = DownTrendLong[index - 1];
                        _changeofTrendlong = false;
                    }
                }
                else if (_trendlong[index] == -1)
                {

                    DownTrendLong[index] = _upBufferlong[index];
                    if (_changeofTrendlong)
                    {
                        DownTrendLong[index - 1] = UpTrendLong[index - 1];
                        _changeofTrendlong = false;
                    }

                }

                if (index < 1)
                {
                    _trendshort[index] = 1;
                    return;
                }

                Array.Resize(ref _trendshort, _trendshort.Length + 1);

                // Main Logic
                if (MarketSeries.Close[index] > _upBuffershort[index - 1])
                {
                    _trendshort[index] = 1;
                    if (_trendshort[index - 1] == -1)
                        _changeofTrendshort = true;
                }
                else if (MarketSeries.Close[index] < _downBuffershort[index - 1])
                {
                    _trendshort[index] = -1;
                    if (_trendshort[index - 1] == -1)
                        _changeofTrendshort = true;
                }
                else if (_trendshort[index - 1] == 1)
                {
                    _trendshort[index] = 1;
                    _changeofTrendshort = false;
                }
                else if (_trendshort[index - 1] == -1)
                {
                    _trendshort[index] = -1;
                    _changeofTrendshort = false;
                }

                if (_trendshort[index] < 0 && _trendshort[index - 1] > 0)
                    _upBuffershort[index] = median + (ShortMultiplier * atrshort);
                else if (_trendshort[index] < 0 && _upBuffershort[index] > _upBuffershort[index - 1])
                    _upBuffershort[index] = _upBuffershort[index - 1];

                if (_trendshort[index] > 0 && _trendshort[index - 1] < 0)
                    _downBuffershort[index] = median - (ShortMultiplier * atrshort);
                else if (_trendshort[index] > 0 && _downBuffershort[index] < _downBuffershort[index - 1])
                    _downBuffershort[index] = _downBuffershort[index - 1];

                // Draw Indicator
                if (_trendshort[index] == 1)
                {

                    UpTrendShort[index] = _downBuffershort[index];
                    if (_changeofTrendshort)
                    {
                        UpTrendShort[index - 1] = DownTrendShort[index - 1];
                        _changeofTrendshort = false;
                    }
                }
                else if (_trendshort[index] == -1)
                {

                    DownTrendShort[index] = _upBuffershort[index];
                    if (_changeofTrendshort)
                    {
                        DownTrendShort[index - 1] = UpTrendShort[index - 1];
                        _changeofTrendshort = false;
                    }
                }
            }


            if (sendNotification && !_notificationSent)
            {
                Notifications.SendEmail("email", "email", "Subject", "Text");
                _notificationSent = true;
            }

        }
        protected override void OnBar()
        {
            _notificationSent = false;
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Kind regards,

Vince


@Vince

Vince
20 Jul 2018, 16:28

Hi Panagiotis,

Thank you for your swift reply. Below you will find the full code.

Basicly this is a modified version of the Supertrend indicator from spka111 to display the Supertrend, but with different settings. I added a DrawText option to display the High or Low of the closed candle that has crossed the Supertrend, which displays just fine.

I also tried to add a Sendemail option which would notify me of the above described event. This works, but instead of getting just 1 email, it will continue to send emails for every tick during the following period. That is the last problem I am trying to solve: to only send 1 email of the High or Low of the closed candle that has crossed the Supertrend.

Kind Regards,

Vince

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class SupertrendCompleteTestEmail : Indicator
    {
        [Parameter(DefaultValue = 50)]
        public int LongPeriod { get; set; }

        [Parameter(DefaultValue = 10.0)]
        public double LongMultiplier { get; set; }

        [Parameter(DefaultValue = 20)]
        public int ShortPeriod { get; set; }

        [Parameter(DefaultValue = 5.0)]
        public double ShortMultiplier { get; set; }

        [Output("UpTrendLong", Color = Colors.Green, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries UpTrendLong { get; set; }

        [Output("DownTrendLong", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries DownTrendLong { get; set; }

        [Output("UpTrendShort", Color = Colors.Green, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries UpTrendShort { get; set; }

        [Output("DownTrendShort", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries DownTrendShort { get; set; }

        private IndicatorDataSeries _upBufferlong;
        private IndicatorDataSeries _downBufferlong;
        private IndicatorDataSeries _upBuffershort;
        private IndicatorDataSeries _downBuffershort;
        private AverageTrueRange _averageTrueRangelong;
        private AverageTrueRange _averageTrueRangeshort;
        private int[] _trendlong;
        private int[] _trendshort;
        private bool _changeofTrendlong;
        private bool _changeofTrendshort;

        protected override void Initialize()
        {

            _trendlong = new int[1];
            _trendshort = new int[1];
            _upBufferlong = CreateDataSeries();
            _downBufferlong = CreateDataSeries();
            _upBuffershort = CreateDataSeries();
            _downBuffershort = CreateDataSeries();
            _averageTrueRangelong = Indicators.AverageTrueRange(LongPeriod, MovingAverageType.WilderSmoothing);
            _averageTrueRangeshort = Indicators.AverageTrueRange(ShortPeriod, MovingAverageType.WilderSmoothing);
        }

        public override void Calculate(int index)
        {
            // Init
            UpTrendLong[index] = double.NaN;
            DownTrendLong[index] = double.NaN;
            UpTrendShort[index] = double.NaN;
            DownTrendShort[index] = double.NaN;

            double median = (MarketSeries.High[index] + MarketSeries.Low[index]) / 2;
            double atrlong = _averageTrueRangelong.Result[index];
            double atrshort = _averageTrueRangeshort.Result[index];

            _upBufferlong[index] = median + LongMultiplier * atrlong;
            _downBufferlong[index] = median - LongMultiplier * atrlong;
            _upBuffershort[index] = median + ShortMultiplier * atrshort;
            _downBuffershort[index] = median - ShortMultiplier * atrshort;


            if (index < 1)
            {
                _trendlong[index] = 1;
                return;
            }

            Array.Resize(ref _trendlong, _trendlong.Length + 1);

            // Main Logic
            if (MarketSeries.Close[index] > _upBufferlong[index - 1])
            {
                _trendlong[index] = 1;
                if (_trendlong[index - 1] == -1)
                    _changeofTrendlong = true;
            }
            else if (MarketSeries.Close[index] < _downBufferlong[index - 1])
            {
                _trendlong[index] = -1;
                if (_trendlong[index - 1] == -1)
                    _changeofTrendlong = true;
            }
            else if (_trendlong[index - 1] == 1)
            {
                _trendlong[index] = 1;
                _changeofTrendlong = false;
            }
            else if (_trendlong[index - 1] == -1)
            {
                _trendlong[index] = -1;
                _changeofTrendlong = false;
            }

            if (_trendlong[index] < 0 && _trendlong[index - 1] > 0)
                _upBufferlong[index] = median + (LongMultiplier * atrlong);
            else if (_trendlong[index] < 0 && _upBufferlong[index] > _upBufferlong[index - 1])
                _upBufferlong[index] = _upBufferlong[index - 1];

            if (_trendlong[index] > 0 && _trendlong[index - 1] < 0)
                _downBufferlong[index] = median - (LongMultiplier * atrlong);
            else if (_trendlong[index] > 0 && _downBufferlong[index] < _downBufferlong[index - 1])
                _downBufferlong[index] = _downBufferlong[index - 1];

            // Draw Indicator
            if (_trendlong[index] == 1)
            {

                UpTrendLong[index] = _downBufferlong[index];
                if (_changeofTrendlong)
                {
                    UpTrendLong[index - 1] = DownTrendLong[index - 1];
                    _changeofTrendlong = false;
                }
            }
            else if (_trendlong[index] == -1)
            {

                DownTrendLong[index] = _upBufferlong[index];
                if (_changeofTrendlong)
                {
                    DownTrendLong[index - 1] = UpTrendLong[index - 1];
                    _changeofTrendlong = false;
                }

            }

            if (index < 1)
            {
                _trendshort[index] = 1;
                return;
            }

            Array.Resize(ref _trendshort, _trendshort.Length + 1);

            // Main Logic
            if (MarketSeries.Close[index] > _upBuffershort[index - 1])
            {
                _trendshort[index] = 1;
                if (_trendshort[index - 1] == -1)
                    _changeofTrendshort = true;
            }
            else if (MarketSeries.Close[index] < _downBuffershort[index - 1])
            {
                _trendshort[index] = -1;
                if (_trendshort[index - 1] == -1)
                    _changeofTrendshort = true;
            }
            else if (_trendshort[index - 1] == 1)
            {
                _trendshort[index] = 1;
                _changeofTrendshort = false;
            }
            else if (_trendshort[index - 1] == -1)
            {
                _trendshort[index] = -1;
                _changeofTrendshort = false;
            }

            if (_trendshort[index] < 0 && _trendshort[index - 1] > 0)
                _upBuffershort[index] = median + (ShortMultiplier * atrshort);
            else if (_trendshort[index] < 0 && _upBuffershort[index] > _upBuffershort[index - 1])
                _upBuffershort[index] = _upBuffershort[index - 1];

            if (_trendshort[index] > 0 && _trendshort[index - 1] < 0)
                _downBuffershort[index] = median - (ShortMultiplier * atrshort);
            else if (_trendshort[index] > 0 && _downBuffershort[index] < _downBuffershort[index - 1])
                _downBuffershort[index] = _downBuffershort[index - 1];

            // Draw Indicator
            if (_trendshort[index] == 1)
            {

                UpTrendShort[index] = _downBuffershort[index];
                if (_changeofTrendshort)
                {
                    UpTrendShort[index - 1] = DownTrendShort[index - 1];
                    _changeofTrendshort = false;
                }
            }
            else if (_trendshort[index] == -1)
            {

                DownTrendShort[index] = _upBuffershort[index];
                if (_changeofTrendshort)
                {
                    DownTrendShort[index - 1] = UpTrendShort[index - 1];
                    _changeofTrendshort = false;
                }
            }

            // Test Notifications on chart
            {
                var value = MarketSeries.Close[index - 1];
                if (Functions.HasCrossedAbove(_upBufferlong, value, 1))
                {
                    var name = "BuyLong";
                    var high = MarketSeries.High[index - 1];
                    var text = high.ToString();
                    var xPos = index - 1;
                    var yPos = high;
                    var vAlign = VerticalAlignment.Top;
                    var hAlign = HorizontalAlignment.Center;
                    ChartObjects.DrawText(name, text, xPos, yPos, vAlign, hAlign, Colors.Lime);

                    {
                        var highemail = MarketSeries.High[index - 1];
                        var subject = highemail.ToString();
                        Notifications.SendEmail("email", "email", "Buy Long " + Symbol.Code + " " + subject, Symbol.Code + " " + subject);
                    }
                }
            }

            {
                var value = MarketSeries.Close[index - 1];
                if (Functions.HasCrossedBelow(_downBufferlong, value, 1))
                {
                    var name = "SellLong";
                    var low = MarketSeries.Low[index - 1];
                    var text = low.ToString();
                    var xPos = index - 1;
                    var yPos = low;
                    var vAlign = VerticalAlignment.Bottom;
                    var hAlign = HorizontalAlignment.Center;
                    ChartObjects.DrawText(name, text, xPos, yPos, vAlign, hAlign, Colors.PeachPuff);
                    {
                        var lowemail = MarketSeries.Low[index - 1];
                        var subject = lowemail.ToString();
                        Notifications.SendEmail("email", "email", "Buy Long " + Symbol.Code + " " + subject, Symbol.Code + " " + subject);
                    }
                }
            }

            // Test Notifications on chart
            {
                var value = MarketSeries.Close[index - 1];
                if (Functions.HasCrossedAbove(_upBuffershort, value, 1))
                {
                    var name = "BuyShort";
                    var high = MarketSeries.High[index - 1];
                    var text = high.ToString();
                    var xPos = index - 1;
                    var yPos = high;
                    var vAlign = VerticalAlignment.Top;
                    var hAlign = HorizontalAlignment.Center;
                    ChartObjects.DrawText(name, text, xPos, yPos, vAlign, hAlign, Colors.Green);
                    {
                        var highemail = MarketSeries.High[index - 1];
                        var subject = highemail.ToString();
                        Notifications.SendEmail("email", "email", "Buy Long " + Symbol.Code + " " + subject, Symbol.Code + " " + subject);
                    }
                }
            }

            {
                var value = MarketSeries.Close[index - 1];
                if (Functions.HasCrossedBelow(_downBuffershort, value, 1))
                {
                    var name = "SellShort";
                    var low = MarketSeries.Low[index - 1];
                    var text = low.ToString();
                    var xPos = index - 1;
                    var yPos = low;
                    var vAlign = VerticalAlignment.Bottom;
                    var hAlign = HorizontalAlignment.Center;
                    ChartObjects.DrawText(name, text, xPos, yPos, vAlign, hAlign, Colors.Red);
                    {

                        var lowemail = MarketSeries.Low[index - 1];
                        var subject = lowemail.ToString();
                        Notifications.SendEmail("email", "email", "Buy Long " + Symbol.Code + " " + subject, Symbol.Code + " " + subject);
                    }
                }
            }

        }
    }
}

 


@Vince

Vince
05 Jun 2018, 16:20

With me it does apply the template over the current timeframe. I suggest you save the chart(s) as a workspace with template you made for a specific timeframe. You can then open the workspace with all charts, timeframes and templates being opened at the time you saved the workspace.


@Vince

Vince
10 Apr 2018, 09:53

This feature would be very useful for multi time frame trading!


@Vince