Topics
17 Feb 2021, 14:42
 0
 833
 1
Replies

anders.sjogren
17 Aug 2020, 13:01

Panagiotis,

Thank you very much for your prompt and helpful replay. I am now struggling on to get my cBot up and running.

Best regards

Anders


@anders.sjogren

anders.sjogren
12 Aug 2020, 18:03 ( Updated at: 21 Dec 2023, 09:22 )

More details

Hi Panagiotis,

Thank you very much for your prompt replay. I must apologise if my question was not well specified. My indicator used in the cBot is declared in the code as per some of your provided examples. My problem is, however, that the information provided by my cBot and what appears on your platform is different.

An example shown by the below screen-cuts gives (indicator values):

                 cBot           Platform

09:45        1,176442   1,17643

10:00        1,176642   1,17678

10:15        1,177035   1,17883

 

Not a large difference, but on a quite horizontal part of the curve.

 

I have been building, and testing, a quite promising algorithm based on a few factors, one of them the indicator on-screen values. But the values now provided by my cBot does not give the same result.   

 

Now I ask if there is a way to eliminate this problem. I am not an experienced cTrader-programmer, why I also enclose my cBot and  Indicator code.

Yours faithfully

 

Anders

Live

Backtest (same values)

cBot:

// 

// 2020-08-12

// Version 1.0

// My_Robot_04

//

// Indicator_04 as indicator

// --------------------------------

//

 

using System;

using System.Linq;

using cAlgo.API;

using cAlgo.API.Indicators;

using cAlgo.API.Internals;

using cAlgo.Indicators;

 

namespace cAlgo

{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class My_Robot_04 : Robot

    {

        [Parameter("* Indicator_04 Source", Group = "Indicator_04")]

        public DataSeries Source { get; set; }
        // Always set as close in indicator

 

        public double start_ind;

        public double onbar_ind;

 

        private Indicator_04 abcd;

 

        protected override void OnStart()

        {

            abcd = Indicators.GetIndicator<Indicator_04>(Source, 9, 6, 0.15);

            start_ind = abcd.Result.LastValue;

            Print("OnStart(). Indicator_04 at cBot start: ", start_ind);

        }

 

        protected override void OnTick()

        {

            //

        }

 

        protected override void OnBar()

        {

            onbar_ind = abcd.Result.LastValue;

            Print("New Indicator_04 OnBar(): ", onbar_ind);

        }

    }

}

 

// -----------------------------------------------------------------------

Indicator:

//

// This indicator was downloaded from ctrader.com

// https://ctrader.com/algos/indicators/show/184

//

 

using System;

using cAlgo.API;

 

namespace cAlgo.Indicators

{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]

    public class Indicator_04 : Indicator

    {

        private double[] _aDoubles = new double[1];

 

 

        [Parameter("ALMA Source")]

        public DataSeries Source { get; set; }

 

        [Parameter("Size", DefaultValue = 9, MinValue = 2)]

        public int Size { get; set; }

 

        [Parameter("Sigma", DefaultValue = 6, MinValue = 1)]

        public double Sigma { get; set; }

 

        [Parameter("Offset", DefaultValue = 0.15)]

        public double Offset { get; set; }

 

        [Output("Alma", Color = Colors.Cyan)]

        public IndicatorDataSeries Result { get; set; }

 

        protected override void Initialize()

        {

            Array.Resize(ref _aDoubles, Size);

            ResetWindow();

        }

        public override void Calculate(int index)

        {

            if (index < Size)

                return;

 

            double sum = 0;

            double norm = 0;

 

            for (int i = 0; i < Size; i++)

            {

                // Always set as close

                sum += _aDoubles[i] * MarketSeries.Close[index - i];

                norm += _aDoubles[i];

            }

 

            // Normalize the result

            if (Math.Abs(norm - 0) > double.Epsilon)

                sum /= norm;

 

            // Draw Indicator

            Result[index] = sum;

 

        }

 

        private void ResetWindow()

        {

            var m = Math.Floor(Offset * (Size - 1));

 

            var s = Size / Sigma;

 

            for (int i = 0; i < Size; i++)

            {

                _aDoubles[i] = Math.Exp(-((i - m) * (i - m)) / (2 * s * s));

            }

        }

 

    }

}

 

 

I have also tried .Open, .High and .Low settings in the indicator code row below.

 

               sum += _aDoubles[i] * MarketSeries.Close[index - i];

 

Does not help me. My problem/question still remains.  

 

 

 

 


@anders.sjogren