Topics
22 Apr 2020, 16:44
 1393
 3
Replies

kenneyy_eur
05 Nov 2021, 16:38 ( Updated at: 05 Nov 2021, 16:59 )

RE: I have the same issue with cTrader Desktop 4.1 . Can cTrader tell us what criteria they have used in determining if an indicator has performance issues?

Here is my code

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class KF_GHL_v3 : Indicator
    {
        [Parameter("Period", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter(DefaultValue = "High")]
        public DataSeries SourceH { get; set; }

        [Parameter(DefaultValue = "Low")]
        public DataSeries SourceL { get; set; }

        [Parameter(DefaultValue = "Close")]
        public DataSeries SourceC { get; set; }

        [Parameter("Timeframe", DefaultValue = "Minute5")]
        public TimeFrame Timeframe { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }


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


        private MovingAverage _smaHigh;
        private MovingAverage _smaLow;

        private int Hld, Hlv;
        private Bars bars;

        protected override void Initialize()
        {
            if(this.Timeframe != this.Chart.TimeFrame)
            {
                bars = MarketData.GetBars(Timeframe);

                while (bars.OpenTimes[0] > Bars.OpenTimes[0])
                    bars.LoadMoreHistory();

                SourceH = bars.HighPrices;
                SourceL = bars.LowPrices;
                SourceC = bars.ClosePrices;
            }

            _smaHigh = Indicators.MovingAverage(SourceH, Period, MaType);
            _smaLow =  Indicators.MovingAverage(SourceL, Period, MaType);
        }

        public override void Calculate(int index)
        {
            var index1 = this.Timeframe == this.Chart.TimeFrame ? index : bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (index1 < 1) return;

            double close = SourceC[index1];
            double smaHigh = _smaHigh.Result[index1 - 1];
            double smaLow = _smaLow.Result[index1 - 1];

            if (close > smaHigh)
                Hld = 1;
            else
            {
                if (close < smaLow)
                    Hld = -1;
                else
                    Hld = 0;
            }

            if (Hld != 0) Hlv = Hld;

            switch(Hlv)
            {
                case -1: Result[index] = smaHigh; break;
                case 0: Result[index - 1] = double.NaN; break;
                case 1: Result[index] = smaLow; break;
            }
        }
    }

It is simply plotting a moving average line of a higher timeframe than the current chart.  This is needed when trading!

When this indicator is placed onto a XAUUSD M5 chart and set to the following parameters

Period: 272

MaType: TimeSeries

Timeframe : 15 minutes

Then run back test, that's when the issue occurs

 


@kenneyy_eur

kenneyy_eur
05 Nov 2021, 16:30 ( Updated at: 05 Nov 2021, 16:59 )

RE: I have the same issue with cTrader Desktop 4.1 . CancTrader tell us what criteria they have used in determining if an indicator has performance issues?

PanagiotisCharalampous said:

Hi Justine,

As per the message you receive, some indicators are not appropriately coded and cause serious degradation of performance to cTrader. Unfortunately we cannot allow those indicators to continue running, since they serously affect the stability of the platform. You should reach out to the indicator developer to fix the issue.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class KF_GHL_v3 : Indicator
    {
        [Parameter("Period", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter(DefaultValue = "High")]
        public DataSeries SourceH { get; set; }

        [Parameter(DefaultValue = "Low")]
        public DataSeries SourceL { get; set; }

        [Parameter(DefaultValue = "Close")]
        public DataSeries SourceC { get; set; }

        [Parameter("Timeframe", DefaultValue = "Minute5")]
        public TimeFrame Timeframe { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }


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


        private MovingAverage _smaHigh;
        private MovingAverage _smaLow;

        private int Hld, Hlv;
        private Bars bars;

        protected override void Initialize()
        {
            if(this.Timeframe != this.Chart.TimeFrame)
            {
                bars = MarketData.GetBars(Timeframe);

                while (bars.OpenTimes[0] > Bars.OpenTimes[0])
                    bars.LoadMoreHistory();

                SourceH = bars.HighPrices;
                SourceL = bars.LowPrices;
                SourceC = bars.ClosePrices;
            }

            _smaHigh = Indicators.MovingAverage(SourceH, Period, MaType);
            _smaLow =  Indicators.MovingAverage(SourceL, Period, MaType);
        }

        public override void Calculate(int index)
        {
            var index1 = this.Timeframe == this.Chart.TimeFrame ? index : bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (index1 < 1) return;

            double close = SourceC[index1];
            double smaHigh = _smaHigh.Result[index1 - 1];
            double smaLow = _smaLow.Result[index1 - 1];

            if (close > smaHigh)
                Hld = 1;
            else
            {
                if (close < smaLow)
                    Hld = -1;
                else
                    Hld = 0;
            }

            if (Hld != 0) Hlv = Hld;

            switch(Hlv)
            {
                case -1: Result[index] = smaHigh; break;
                case 0: Result[index - 1] = double.NaN; break;
                case 1: Result[index] = smaLow; break;
            }
        }
    }
}

It is simply plotting a moving average line of a higher timeframe than the current chart.  This is needed when trading!

When this indicator is placed onto a XAUUSD M5 chart and set to the following parameters

Period: 272

MaType: TimeSeries

Timeframe : 15 minutes

Then run back test, that's when the issue occurs


@kenneyy_eur

kenneyy_eur
01 Oct 2021, 21:42

RE: RE:

Uccio said:

PanagiotisCharalampous said:

Hi davewilson347,

Thanks for posting in our forum. There is no such option at the moment.

Best Regards,

Panagiotis

Hi, this feature would be necessary. It becomes impossible to handle indicators when you download just some of them.

I totally agree!!! - MT4/5 has this feature.  Ability to place a set of indicators into a single folder is desperately needed.


@kenneyy_eur

kenneyy_eur
01 Oct 2021, 21:38

RE:

ilive said:

When running CBot for a long time will affect the connection with ctrader, I tried deleting the app and reinstalling it but it's still the same.
Anyone know a way to go back to the beginning? Or do you know any other reason? Thank you very much .

Try reducing the number of for loops in your OnBar() or OnTick() event.  Best to use just 1 for-each / for loop and your bot wont grind to a halt overtime


@kenneyy_eur

kenneyy_eur
22 Apr 2020, 17:53

RE:

PanagiotisCharalampous said:

Hi  again,

I have learnt something new thanks to you. 

My market scanner has to scan over 70 symbols and for each symbol it has to load the bars for 5 timeframes i.e 70 X 5  = 350 iterations = 52 seconds (synchronously)

A lot of time.

Ok, never mind and thanks for your help. I will go digging and find the right way to implement this without the Print line.

Regards

Kenneth

 

 

Hi Kenneth,

It will be empty because that line of code will be executed before the bars are retrieved. That's the whole point of asynchronous execution, to proceed with the execution of the main thread while another task is executed in parallel on the side. Why do you need to use GetBarsAsync() and not just GetBars()?

Best Regards,

Panagiotis 

Join us on Telegram

 


@kenneyy_eur

kenneyy_eur
22 Apr 2020, 17:31 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Hi Panagiotis and thanks for your quick response.

You are able to see something because you added the print line below the collection population line.

If you remove the print line and try accessing the collection below the MarketData.GetBarAsync block. The collection will be empty trust me.

I can add the print line to my code, but i know i need to add the bars to a Task<IEnumerable>  that's where i'm stuck . Once i achieve that, then i'm home and dry.

Deep appreciation for the work you do!

Regards

Kenneth

 

 

 

PanagiotisCharalampous said:

Hi Kenneth,

I am not sure what is the problem. The below seems to be working fine for me

            var lbrs = new List<Bars>();
            MarketData.GetBarsAsync(TimeFrame, Symbol.Name, bars =>
            {
                lbrs.Add(bars);
                Print(lbrs.Count + " Bar collection added");
            });

Best Regards,

Panagiotis 

Join us on Telegram

 


@kenneyy_eur