Bars Limit

Created at 09 Jun 2020, 21:45
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!
EY

eynt

Joined 08.05.2020

Bars Limit
09 Jun 2020, 21:45


Hello

 

My strategy runs on 1 pip range bar and loads 30 days of data before it starts. After of few days of running live an error was raised (and keeps on happening).

After debugging the cBot it seems that the Bars object has become much much smaller and contains at the time of the error about only 1,000 bars instead of about 350,000 bars.

Does the Bars object has a limit? What could cause such a problem? How do you suggest to overcome the problem?

 

Thank you


@eynt
Replies

PanagiotisCharalampous
10 Jun 2020, 08:26

Hi Yuval,

Please provide more information on how to reproduce this problem.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

eynt
10 Jun 2020, 10:05 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Hi

 

The steps which led me to the problem were a bit complicated however in order to simplify I would use the following steps and hopefully it will give the same results:

1. Create a cBot and save its bars count

OnStart:         _startBarCount = Bars.Count;

2. Make sure the bars count does not go below the initial value

OnTick:          if (Bars.Count  < _startBarCount )  throw new exception("");

3. Run the bot on 1 pip range chart and make sure it loads history for 30 days at least on the Initialize

 

This might take some time even a few days until the problem occurs. Maybe loading more than 30 days will reproduce it faster. I would also use a symbol such has GBPNZD which has a lot of movement.

I'm attaching a debug screenshot. As you can the see the Bars.Count equals to 1068 only, which is impossible value for a 1-pip range chart. Moreover, the RightBar value which is held in one of my indicators and often save the last bar index has the value of 357663 which means the Bars.Count value should be at least that.

Besides knowing if you were able to reproduce the problem, I would like to know if the Bars property has some sort of size limitations?

 

Thanks

 

 

 

 

 


@eynt

PanagiotisCharalampous
10 Jun 2020, 10:15

Hi Yuval,

We will need a complete cBot code to check this further. Regarding your question, there is no limitation for Bars.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eynt
10 Jun 2020, 16:01

RE:

Hello

 

Luckily I was able to reproduce the problem easily using the robot's code at the bottom.

Please run it on a 1-pip range bar, on a live chart as I am not sure if it will work on a back test. I suggest to run it on GBPNZD or even several symbols simultaniously since it might take a few hours before the problem happens.

 

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CatchBug : Robot
    {
        private int _startBarCount;

        protected override void OnStart()
        {
            LoadBars(this.Time.AddDays(-60));

            _startBarCount = Bars.Count;
            
            Print("OnStart " + _startBarCount);
        }

        protected override void OnTick()
        {
            if (Bars.Count < _startBarCount)
            {
                Print("Bug catch. Bars.Count= " + Bars.Count + " _startBarCount= " + _startBarCount);

                throw new Exception("Bug catch. Bars.Count= " + Bars.Count + " _startBarCount= " + _startBarCount);
            }
        }
        public void LoadBars(DateTime requiredStartDate)
        {
            while (Bars.OpenTimes[0] > requiredStartDate)
            {
                int loadedCount = Bars.LoadMoreHistory();

                if (loadedCount == 0)
                    break;
            }
        }
    }
}

 


@eynt

eynt
12 Jun 2020, 18:11

RE: RE:

Hello

 

Were you able to reproduce the problem?


@eynt

PanagiotisCharalampous
16 Jun 2020, 09:46

Hi Yuval,

Yes we did. This can happen when cTrader is disconnected and reconnected. In this case Bars are reloaded. You will need to write some code to anticipate for such cases and load more bars if necessary.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eynt
16 Jun 2020, 09:49

RE:

Thanks 

 

How do I know if the connection was reconnected?

 


@eynt

PanagiotisCharalampous
16 Jun 2020, 09:52

Hi Yuval,

You can subscribe to the Bars.Reloaded event.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eynt
16 Jun 2020, 10:03

RE:

According to what you wrote, upon reconnecting the Bars value (which is one of the most important and basic property there is )is changed. This causes 2 problems:

a. Reloading takes time (and in some cases, a lot of time)

b. All other objects which relies on the original Bars value are now irrelevant and needs to recalculate itself. This can be super complicated (and time consuming).

 

Isn't this issue should be solve on your end and on the even of reconnecting the Bars value should fix itself as if nothing has happened?

 

Thanks


@eynt

PanagiotisCharalampous
16 Jun 2020, 10:07

Hi Yuval,

We do not plan to change this behavior at the moment. The points you raised will not be solved if we load the bars instead of you. It will still take time to load and you will still need to recalculate as you don't know at which point the reconnection takes place and how many bars were missed in the meanwhile. 

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eynt
19 Jun 2020, 08:27

RE:

Hello

 

How do I know if the connection was disconnected?

 


@eynt

PanagiotisCharalampous
19 Jun 2020, 08:53

Hi Yuval,

You can use IsConnected property.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eynt
24 Jun 2020, 06:45

RE:

Thank you

 

How can I check it? When a connection is lost there's no OnTick to check its value

 


@eynt

PanagiotisCharalampous
24 Jun 2020, 08:10

Hi Yuval,

You can use a Timer

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

eynt
24 Jun 2020, 08:14

RE:

Thanks

 

Upon reconnection in a cBot the OnBarsReloaded event is raised and only 1000 bars are loaded in Bars.

What's the behaviour in a custom indicator? How many bars are loaded? Is the initialize is called again? Is there something similar  to the OnBarsReloaded?

 


@eynt