OnBarClosed issue

Created at 10 Jan 2025, 16:57
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!
EK

ekalyvio

Joined 13.06.2023

OnBarClosed issue
10 Jan 2025, 16:57


Is it possible that the cTrader.Robot is a kind of asynchronous?

eg. The OnBarClosed function is called but at the same time the Bars.LastBar is getting updated and as such it doesn't contain the previous bar closed but it contains the new bar data?

I am having an issue when running my bot via ctrader-cli using a Spotware demo account.

I have something like the following code:

protected override void OnBarClosed()
{
   base.OnBarClosed();
   
   var curBarTime = DateToTimezone(Bars.LastBar.OpenTime);
                                          ^
                                          |
                                          here we have the issue...
…
blah… blah…
}

When accessing the Bars.LastBar it seems like sometimes I am getting the new bar values and not the last (closed bar) values. Anyone knows why this might be happening?

When I back test the cBot on my debugger I don't have such behavior. Also, in the provider I have my live funds I haven't observed something like that. But in a Spotware demo account I see such behavior.

 

Thanks

Efthymios


@ekalyvio