v3.7 Bugs found after update from Marketseries to Bars

Created at 20 Feb 2020, 08:59
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!
EO

eofe

Joined 18.06.2019

v3.7 Bugs found after update from Marketseries to Bars
20 Feb 2020, 08:59


Hi,

After I update from Marketseries to Bars, the market data I received is sometimes unreliable. It happens 1-2 times a week and is hard to replicate.

For example, If i run this code at the same time everyday (2300 GMT),

Bars bars = MarketData.GetBars(TimeFrame.Daily, "EURGBP");
Print("bars.HighPrices.Last(1): " + bars.HighPrices.Last(1));

Sometimes, ctrader will return high price of bars.HighPrices.Last(1) but sometimes it will return high price of the day before i.e. bars.HighPrices.Last(2).

However, if I add bars.LoadMoreHistory(); before the print code. it seems to fix the problem. I am still testing this workaround.

I have also tried RefreshData(); but it doesn't help much.

 

Is there a way to ensure the bars are updated with the current bar and have completed loading before continuing to the next line of code? I never has this problem when I was using Maketseries.


@eofe
Replies

PanagiotisCharalampous
20 Feb 2020, 09:46

Hi eofe,

Can I have the exact cBot code you are using to determine what the problem might be?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

eofe
21 Feb 2020, 11:35

After further testing, I realised the problem was usually caused during the first multi symbol variable initiation. I updated the code to initialise bars in onstart instead of onbar and it seems to fix the problem. Will monitor next week.

Is there a difference in how ctrader initialise bars vs marketseries? Maybe one is Async while the other one is not?

Or maybe the proxy lag from 2ms to 80ms could have caused it.


@eofe

srubtsov
21 Feb 2020, 12:15

Use the exact time to get today's bar is not so good way, because a bar can be not created yet, bar creates exactly after the first tick in the bar. So the best way here to use BarOpened event.

protected override void OnStart()
{
    Bars eurgbpDailyBars = MarketData.GetBars(TimeFrame.Daily, "EURGBP");
    eurgbpDailyBars.BarOpened += OnEurgbpDailyBarOpened;
}

private void OnEurgbpDailyBarOpened(BarOpenedEventArgs args)
{
    Print("HighPrices.Last(1): " + args.Bars.HighPrices.Last(1));
}

 

 

@srubtsov

eofe
21 Feb 2020, 12:21

RE:

srubtsov said:

Use the exact time to get today's bar is not so good way, because a bar can be not created yet, bar creates exactly after the first tick in the bar. So the best way here to use BarOpened event.

protected override void OnStart()
{
    Bars eurgbpDailyBars = MarketData.GetBars(TimeFrame.Daily, "EURGBP");
    eurgbpDailyBars.BarOpened += OnEurgbpDailyBarOpened;
}

private void OnEurgbpDailyBarOpened(BarOpenedEventArgs args)
{
    Print("HighPrices.Last(1): " + args.Bars.HighPrices.Last(1));
}

 

 

Will explore your suggestion, thank you.


@eofe