OnBar never hit when debugging in Visual Studio
Created at 02 Sep 2019, 08:41
OnBar never hit when debugging in Visual Studio
02 Sep 2019, 08:41
I have run into an interesting issue with cTrader and debugging in Visual Studio.
Code to reproduce is below.
Basically, when I have time timeframes in a bot, the "OnBar" method is never hit when a breakpoint is put to the method's opening curly brace.
See screen capture:
Here's the code to reproduce:
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Timers; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; //Demonstrates bug? with cTrader. //Run on AUDCAD forex pair on M5 timeframe. //OnBar method is never hit when breakpoints are attached; all the other methods are. namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BugBot : Robot { private string _positionLabel = "Bug bot"; private int _lastMinute3 = 0; private MarketSeries _marketSeriesM3; protected override void OnStart() { // <-- put a breakpoint there and it's hit Print("OnStart: Starting \"{0}\"", _positionLabel); _marketSeriesM3 = MarketData.GetSeries(TimeFrame.Minute3); } protected override void OnBar() { // <-- put a breakpoint there and this method is NEVER hit. Print("OnBar hit! {0}", DateTime.Now); } protected override void OnTick() { // <-- put a breakpoint there and it's hit int currentIndexM3 = _marketSeriesM3.Open.Count - 1; Print("OnTick! {0}", currentIndexM3); if (currentIndexM3 > _lastMinute3) { OnBarM3(currentIndexM3); _lastMinute3 = currentIndexM3; } } private void OnBarM3(int x) { // <-- put a breakpoint there and it's hit Print("OnBarM3 hit! {0}", DateTime.Now); } } }
Why is this? IS this because even though I'm running on the M5 timeframe, because I'm calling the market series for the M3 timeframe the OnBar method is ignored?
Thank you.
firemyst
02 Sep 2019, 08:44
Looks like this is an issue with cTrader.
Same issue was reported here which I didn't see earlier.
Sorry for the duplicate post:
https://ctrader.com/forum/calgo-support/3349
@firemyst