OnBarOpened firing every tick
OnBarOpened firing every tick
29 Oct 2020, 09:09
I am using the lastest build of cTrader 3.8 from FxPro.
I have this code in a PivotPointsProvider that I use in multiple algos.
public void Initialise()
{
var pivotTimeFrame = this.GetPivotTimeFrame();
this.pivotData = this.algo.MarketData.GetBars(pivotTimeFrame, this.symbolName);
this.LogDebug("{0} {1}", pivotTimeFrame, this.pivotData.TimeFrame);
this.pivotData.BarOpened += this.HandleBarOpened;
this.CalculatePivotPoints(this.pivotData.Last(1));
}
The host algo is passed into the constructor and referenced via a private field.
After getting the set of bars I specified through the constructor I am wiring up a handler for the BarOpened event on that data, expecting this event to be triggered only when a new bar is added to the pivotData set, which will never be lower than the Daily timeframe.
What actually happens, and I have verified through logging is that the event is triggered on every price tick.
Below is a screenshot of the Log panel from an indicator that uses the provider and logging is showing that the methods used in the HandleBarOpened handler are logging every price tick, despite the fact it is also logging that the timeframe of the pivotData Bars is Daily.
Replies
mpistorius
30 Mar 2021, 18:47
Hi Panagiotis,
This bug can be reproduced with the simplest of bots, and is still present in cTrader 4.0.
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Bug : Robot
{
protected override void OnStart()
{
var bars = MarketData.GetBars(TimeFrame.Hour4, "GBPUSD");
bars.BarOpened += Bars_BarOpened;
}
private void Bars_BarOpened(BarOpenedEventArgs obj)
{
Print("BarOpened called at {0}", Server.Time);
}
}
}
The code above should only produce output on every 4 hour bar, but is executed on every tick instead. This is the log output:
30/03/2021 23:34:22.614 | cBot "Bug" was stopped for GBPUSD, h4.
30/03/2021 23:34:20.583 | BarOpened called at 30/03/2021 3:34:20 PM
30/03/2021 23:34:19.802 | BarOpened called at 30/03/2021 3:34:19 PM
30/03/2021 23:34:19.552 | BarOpened called at 30/03/2021 3:34:19 PM
30/03/2021 23:34:18.708 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:18.520 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:18.427 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:13.880 | BarOpened called at 30/03/2021 3:34:13 PM
30/03/2021 23:34:12.380 | BarOpened called at 30/03/2021 3:34:12 PM
30/03/2021 23:34:12.161 | BarOpened called at 30/03/2021 3:34:12 PM
30/03/2021 23:34:11.786 | BarOpened called at 30/03/2021 3:34:11 PM
30/03/2021 23:34:11.599 | BarOpened called at 30/03/2021 3:34:11 PM
30/03/2021 23:33:57.864 | cBot "Bug" was started successfully for GBPUSD, h4.
This doesn't happen in backtesting, only on a cbot running live. That fact makes it a particularly nasty surprise, which has already cost me real money.
Regards,
Morné
@mpistorius
amusleh
31 Mar 2021, 09:13
RE:
mpistorius said:
Hi Panagiotis,
This bug can be reproduced with the simplest of bots, and is still present in cTrader 4.0.
namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Bug : Robot { protected override void OnStart() { var bars = MarketData.GetBars(TimeFrame.Hour4, "GBPUSD"); bars.BarOpened += Bars_BarOpened; } private void Bars_BarOpened(BarOpenedEventArgs obj) { Print("BarOpened called at {0}", Server.Time); } } }
The code above should only produce output on every 4 hour bar, but is executed on every tick instead. This is the log output:
30/03/2021 23:34:22.614 | cBot "Bug" was stopped for GBPUSD, h4.
30/03/2021 23:34:20.583 | BarOpened called at 30/03/2021 3:34:20 PM
30/03/2021 23:34:19.802 | BarOpened called at 30/03/2021 3:34:19 PM
30/03/2021 23:34:19.552 | BarOpened called at 30/03/2021 3:34:19 PM
30/03/2021 23:34:18.708 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:18.520 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:18.427 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:13.880 | BarOpened called at 30/03/2021 3:34:13 PM
30/03/2021 23:34:12.380 | BarOpened called at 30/03/2021 3:34:12 PM
30/03/2021 23:34:12.161 | BarOpened called at 30/03/2021 3:34:12 PM
30/03/2021 23:34:11.786 | BarOpened called at 30/03/2021 3:34:11 PM
30/03/2021 23:34:11.599 | BarOpened called at 30/03/2021 3:34:11 PM
30/03/2021 23:33:57.864 | cBot "Bug" was started successfully for GBPUSD, h4.
This doesn't happen in backtesting, only on a cbot running live. That fact makes it a particularly nasty surprise, which has already cost me real money.
Regards,
Morné
Hi,
Which broker cTrader you used for the test? I tried on Spotware Beta cTrader and I couldn't replicate the issue.
@amusleh
mpistorius
19 May 2021, 18:06
RE:
amusleh said:
Hi,
We were able to replicate the issue and it will be fixed in future releases, thanks for reporting.
Hi Amusleh,
I just got the 4.0.13 update, but this bug is still present in the latest release...
Regards,
Morné
@mpistorius
PanagiotisCharalampous
30 Oct 2020, 11:57
Hi testpossessed,
Please provide us with a complete indicator code to reproduce the issue.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous