Bug / latency of indicators when debugging with visual studio 2017 / 2019 in backtesting

Created at 10 Dec 2019, 23:05
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!
NO

noeyamn

Joined 10.12.2019

Bug / latency of indicators when debugging with visual studio 2017 / 2019 in backtesting
10 Dec 2019, 23:05


Hello,

I have encountered a strange behavior with the exponential moving average and I have seen that with other indicators :

(LastValue / Last(0) / .Result) are returning a value that apparently comes from nowhere in backtesting mode ONLY

-> the same code returns correct values when bot is running on a market

I have set up a very basic bot

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 DebugLast : Robot
    {

        ExponentialMovingAverage EMA;
        protected override void OnStart()
        {
            EMA = Indicators.ExponentialMovingAverage(MarketSeries.Close, 10);
        }

        protected override void OnBar()
        {
        }

        protected override void OnTick()
        {
            var a = EMA.Result.LastValue;
            var b = EMA.Result;
            var c = EMA.Result.Last(0);
            var d = EMA.Result.Last(1);
            var e = EMA.Result.Last(2);
           
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

When placing a breakpoint on the closing bracket of OnTick, this is what happens :

=> Value of a,b,c are the same but does not correspond to what we see on the chart.

In fact the chart shows Last(1) : 1.106777 rounded to 1.10678

And even after the breakpoint, 1.10676357489... will not be present in last(1) or last(2) or on the chart, as we could expect.

Again,this is only happening in backtesting.

BTW, for these captures, I am using EURUSD, m1, 07/11/2019 - 09/12/2019, but the same thing happens with other timeframes

 

Did I do anything wrong or is this a bug ?

 

Regards :-)


@noeyamn
Replies

PanagiotisCharalampous
11 Dec 2019, 08:21

Hi noeyamn,

Shall I assume you are using visual backtesting? If yes, for performance reasons some ticks are skipped by the chart so the indicator displayed on the chart might have these deviations. The correct values are the ones recorded by your cBot.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

noeyamn
11 Dec 2019, 10:49

RE:

PanagiotisCharalampous said:

Hi noeyamn,

Shall I assume you are using visual backtesting? If yes, for performance reasons some ticks are skipped by the chart so the indicator displayed on the chart might have these deviations. The correct values are the ones recorded by your cBot.

Best Regards,

Panagiotis 

Join us on Telegram

First of all, thank you very much for your attention and your answer.

Yes, I am using visual backtesting.

I understand the performance reason, however I have to say that this is really annoying because the analyze produced form an indicator is sometimes diverging from what is visible on the chart.

I generally put the chart on one screen and the bot analyze on an other (I run the interface in a distinct application), and having contradictions between the chart and the bot makes testing dodgy as I can not be sure if the error is from the code or be cause the chart is diverging.

Is there any plan to change that in future versions ?

Any suggestion to manage this ?

Thanks :-)

 


@noeyamn