Not entering OnBar method
Not entering OnBar method
19 Aug 2014, 13:03
Hi,
I'm using OnBar to do some basic calculations but noticed the bot wasn't entering the method. Typically it would work for the first two consecutive bars max but sometimes would only work once or not at all.
I wrote a simple code that just prints a string on an m1 instance and nothing else just to test it and noticed the same behavior in this simple case. After the first two "here" print outs in the log section nothing happens afterwards.
I also tried adding a Thread.Sleep before the print statement but this made no real difference.
using System; using System.Linq; using System.Threading; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BarTest : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Put your initialization logic here } protected override void OnBar() { // Put your core logic here Thread.Sleep(10000); Print("Here"); } protected override void OnStop() { // Put your deinitialization logic here } } }
Replies
guillermo
19 Aug 2019, 21:24
Hello,
I am having the same problem as described above.
Today I noticed that my robots did not work properly.
The OnBar event waS not triggered on each and every bar.
I have prepared a little test program as follows:
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.WEuropeStandardTime, AccessRights = AccessRights.None)] public class xxx : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { Print("start " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } protected override void OnBar() { Print("onbar " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } } }
The output of this program in EURUSD M2 is as follows:
Time (UTC+2) | Message 19/08/2019 20:04:00.191 | onbar 20:04 19/08/2019 20:02:01.956 | onbar 20:02 19/08/2019 20:00:00.300 | onbar 20:00 19/08/2019 19:54:02.644 | onbar 19:54 19/08/2019 19:46:02.429 | onbar 19:46 19/08/2019 19:42:01.663 | onbar 19:42 19/08/2019 19:38:00.145 | onbar 19:38 19/08/2019 19:34:05.167 | onbar 19:34 19/08/2019 19:28:13.683 | onbar 19:28 19/08/2019 18:58:01.341 | onbar 18:58 19/08/2019 18:54:01.640 | onbar 18:54 19/08/2019 18:48:05.593 | onbar 18:48 19/08/2019 18:46:00.890 | onbar 18:46 19/08/2019 18:44:00.234 | onbar 18:44 19/08/2019 18:40:02.484 | onbar 18:40 19/08/2019 18:32:04.031 | onbar 18:32 19/08/2019 18:24:00.471 | onbar 18:24 19/08/2019 18:16:18.006 | start 18:16 19/08/2019 18:16:17.944 | cBot "xxx" was started successfully for EURUSD, m2.
As you can see many bars are missing.
The same problem happens in M1, M5 and M15. I did not try other timeframes.
Running several instances of the robot in different timeframes,
it seems that when a candle is missing, it is missing in all
timeframes that apply; and when a candle is not missing, it is
not missing in all timeframes that apply.
I have run the program on two different instances of ctrader,
on different computers on different locations. The issue is
present in both instances of ctrader, and it seems that
on both computers the printout is missing the same candles.
I have restarted the ctrader platform and the computer, but the problem is still there.
I have never noticed this issue before today.
Any help would be very much appreciated.
Regards
@guillermo
guillermo
20 Aug 2019, 10:02
In my previous post I forgot to mention that I am using the broker IC Markets.
I left the program running overnight, and this is the printout that I get for M5. Very weird.
Time (UTC+2) | Message 20/08/2019 08:30:00.401 | onbar 22:05 20/08/2019 08:25:00.401 | onbar 22:05 20/08/2019 07:35:01.974 | onbar 22:05 20/08/2019 07:30:03.740 | onbar 22:05 20/08/2019 06:35:01.044 | onbar 22:05 20/08/2019 06:30:04.231 | onbar 22:05 20/08/2019 06:25:00.280 | onbar 22:05 20/08/2019 06:20:07.967 | onbar 22:05 20/08/2019 06:15:00.264 | onbar 22:05 20/08/2019 06:05:02.747 | onbar 22:05 20/08/2019 05:35:00.724 | onbar 22:05 20/08/2019 04:35:03.562 | onbar 22:05 20/08/2019 04:10:11.098 | onbar 22:05 20/08/2019 04:00:01.602 | onbar 22:05 20/08/2019 03:50:00.788 | onbar 22:05 20/08/2019 03:45:00.460 | onbar 22:05 20/08/2019 03:35:04.917 | onbar 22:05 20/08/2019 02:35:00.220 | onbar 22:05 20/08/2019 02:30:00.612 | onbar 22:05 20/08/2019 02:15:03.082 | onbar 22:05 20/08/2019 01:15:04.469 | onbar 22:05 20/08/2019 00:50:01.335 | onbar 22:05 20/08/2019 00:45:01.022 | onbar 22:05 20/08/2019 00:40:03.272 | onbar 22:05 20/08/2019 00:15:00.496 | onbar 22:05 19/08/2019 23:55:00.583 | onbar 22:05 19/08/2019 23:50:04.451 | onbar 22:05 19/08/2019 23:35:06.280 | onbar 22:05 19/08/2019 22:55:01.386 | onbar 22:05 19/08/2019 22:35:00.585 | onbar 22:05 19/08/2019 21:50:00.205 | onbar 21:50 19/08/2019 21:20:01.076 | onbar 21:20 19/08/2019 20:55:03.213 | onbar 20:55 19/08/2019 20:05:00.159 | onbar 20:05 19/08/2019 20:00:00.300 | onbar 20:00 19/08/2019 19:45:03.054 | onbar 19:45 19/08/2019 18:40:02.484 | onbar 18:40 19/08/2019 18:16:19.350 | start 18:15 19/08/2019 18:16:19.334 | cBot "xxx" was started successfully for EURUSD, m5.
This is the printout for M15
Time (UTC+2) | Message 20/08/2019 08:30:00.401 | onbar 6:15 20/08/2019 07:30:03.740 | onbar 6:15 20/08/2019 06:30:04.231 | onbar 6:15 20/08/2019 06:15:00.264 | onbar 6:15 20/08/2019 04:00:01.602 | onbar 2:15 20/08/2019 03:45:00.460 | onbar 2:15 20/08/2019 02:30:00.612 | onbar 2:15 20/08/2019 02:15:03.082 | onbar 2:15 20/08/2019 01:15:04.469 | onbar 1:15 20/08/2019 00:45:01.022 | onbar 0:45 20/08/2019 00:15:00.496 | onbar 0:15 19/08/2019 20:00:00.300 | onbar 20:00 19/08/2019 19:45:03.054 | onbar 19:45 19/08/2019 18:16:20.194 | start 18:15 19/08/2019 18:16:20.194 | cBot "xxx" was started successfully for EURUSD, m15.
@guillermo
alexandervkv
20 Aug 2019, 17:19
I have the same problem last two days. cBot that uses OnBar event does not Buy or Sell on demo accounts.
@alexandervkv
applata86
21 Aug 2019, 09:07
I'm also experiencing this. Why is this still an issue? I though cTrader is a good platform.
It's frustrating that a simple event is sometimes not firing.
@applata86
guillermo
21 Aug 2019, 13:16
This issue occurs when I run the robots on a demo account. On a live account it works fine.
@guillermo
alexandervkv
26 Aug 2019, 10:25
Hi Panagiotis,
Do you know that OnBar method of c Bot doesn't work properly on demo accounts until now?
We can't test cBots that use it.
Do you plan to fix it?
This is the test made on Spotware demo account and the same situation is on other demo accounts:
26/08/2019 08:57:12.848 | Bar Test, EURUSD, m1 | cBot "Bar Test" was started successfully for EURUSD, m1.
26/08/2019 08:58:00.334 | Bar Test, EURUSD, m1 | Here
26/08/2019 09:01:00.032 | Bar Test, EURUSD, m1 | Here
26/08/2019 09:07:00.179 | Bar Test, EURUSD, m1 | Here
26/08/2019 09:09:00.113 | Bar Test, EURUSD, m1 | Here
26/08/2019 09:20:05.125 | Bar Test, EURUSD, m1 | cBot "Bar Test" was stopped for EURUSD, m1.
Regards,
Alexander
@alexandervkv
guillermo
26 Aug 2019, 10:49
This is the workaround I am using until they fix this bug:
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.WEuropeStandardTime, AccessRights = AccessRights.None)] public class xxx : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } private DateTime lastOpenTime; protected override void OnStart() { this.lastOpenTime = MarketSeries.OpenTime.LastValue; Print("start " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } protected override void OnTick() { if (!MarketSeries.OpenTime.LastValue.Equals(this.lastOpenTime)) { myOnBar(); this.lastOpenTime = MarketSeries.OpenTime.LastValue; } } private void myOnBar() //protected override void OnBar() { Print("onbar " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } } }
@guillermo
alexandervkv
26 Aug 2019, 11:12
The question was -
does Spotware plan to fix this bug?
@alexandervkv
PanagiotisCharalampous
26 Aug 2019, 11:16
Hi all,
We are aware of the issue and we will fix it the soonest.
Best Regards,
Panagiotis
@PanagiotisCharalampous
firemyst
02 Sep 2019, 08:43
Same issue happening to me.
Posted here:
https://ctrader.com/forum/calgo-support/21850
@firemyst
firemyst
03 Sep 2019, 08:37
RE:
Panagiotis Charalampous said:
Hi all,
We are aware of the issue and we will fix it the soonest.
Best Regards,
Panagiotis
Given that this has happened at least twice in the last few years according to dates on this thread alone:
1) does SpotWare have any automated testing systems in place? The "OnBar" method is a critical piece of event code unlike some obscure API call that's rarely used. And now, because of this bug which is at least 8 days old, renders a lot of bots that depend on it utterly useless.
2) does SpotWare plan to implement any sort of "critical bug contact list" that people can sign up to? 8+ days is a loooooooooong time to have such a critical issue unresolved, and developers/users of bots that depend on this piece of code should be notified instead of letting their now potentially hazardous code run without their knowing there's a critical bug. At the very least, that would be the socially responsible, "customer service", thing to do.
Thank you.
@firemyst
Spotware
19 Aug 2014, 14:39
We cannot reproduce the issue. Please make sure that you use m1 timeframe.
@Spotware