CBot backtest shows wrong indicator value!

Created at 07 Oct 2018, 17:35
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CA

cAlgo9

Joined 11.12.2016

CBot backtest shows wrong indicator value!
07 Oct 2018, 17:35


Hi,

I have a simple indicator and a simple CBot. I'm doing backtesting during weekend and just found the value print out from cbot is DIFFERENT from the value if I run it on indicator.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class TEMA : Indicator
    {
        [Output("Triple EMA")]
        public IndicatorDataSeries Tema { get; set; }

        [Parameter("Data Source")]
        public DataSeries DataSource { get; set; }

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

        private ExponentialMovingAverage ema1;
        private ExponentialMovingAverage ema2;
        private ExponentialMovingAverage ema3;

        protected override void Initialize()
        {
            ema1 = Indicators.ExponentialMovingAverage(DataSource, Period);
            ema2 = Indicators.ExponentialMovingAverage(ema1.Result, Period);
            ema3 = Indicators.ExponentialMovingAverage(ema2.Result, Period);
        }

        public override void Calculate(int index)
        {
            Tema[index] = 3 * ema1.Result[index] - 3 * ema2.Result[index] + ema3.Result[index];
            P("In Indicator", MarketSeries.OpenTime.LastValue, Tema[index]);
        }

        void P(params object[] names)
        {
            string result = "";
            for (int i = 0; i < names.Length; i++)
            {
                string v = names[i].ToString();
                if (v.IndexOf(".") > 0)
                    v = v.Substring(0, v.IndexOf(".") + 6);
                result = result + ", " + v;
            }
            Print(result.Substring(1));
        }
    }
}

From the indicator, the very last value is 1.15179

But when I do backtesting, the last value became 1.15224 

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

namespace cAlgo.Robots
{
    [Robot()]
    public class A4 : Robot
    {
        [Parameter()]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 40)]
        public int Period { get; set; }

        TEMA tema;

        protected override void OnStart()
        {
            tema = Indicators.GetIndicator<TEMA>(Source, Period);
        }

        protected override void OnBar()
        {
            P("In CBot", MarketSeries.OpenTime.LastValue, tema.Tema.LastValue);
        }

        void P(params object[] names)
        {
            string result = "";
            for (int i = 0; i < names.Length; i++)
            {
                string v = names[i].ToString();
                if (v.IndexOf(".") > 0)
                    v = v.Substring(0, v.IndexOf(".") + 6);
                result = result + ", " + v;
            }
            Print(result.Substring(1));
        }
    }
}

Could somebody help me please?

Thanks in advance!

 


@cAlgo9
Replies

PanagiotisCharalampous
08 Oct 2018, 10:52

Hi cAlgo9,

Are you sure you are using the same parameters in both cases? In the cBot, the default periods are 40 and in the indicator they are 20.

Best Regards,

Panagiotis


@PanagiotisCharalampous

cAlgo9
09 Oct 2018, 04:54

Thanks Panagiotis!


@cAlgo9