Chart object not initalised before OnStart()

Created at 30 Aug 2019, 07:28
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!
BU

buccinator

Joined 04.08.2019

Chart object not initalised before OnStart()
30 Aug 2019, 07:28


I have noticed that if you quickly run the bot the Chart object may not be setup in time, might be an idea to not enable the run button before it is so. i am using the below code as a work around at OnStart() entry

 

while (Chart == null)
{
  Thread.Sleep(1);
}

// when Chart is ready for use code below

Chart.ScrollChanged += Chart_ScrollChanged

 

 


@buccinator
Replies

PanagiotisCharalampous
30 Aug 2019, 09:20

Hi buccinator,

Can you provide us exact steps to reproduce this problem?

Best Regards,

Panagiotis


@PanagiotisCharalampous

buccinator
30 Aug 2019, 09:24

as soon as cTrader has loaded, quickly have your mouse over the blue play button for a bot, soon as it turns from greyed blue to deep blue click it. it seems to happen on most of the time on first load of cTrader.


@buccinator

PanagiotisCharalampous
30 Aug 2019, 09:36

Hi buccinator,

Which cBot do you use? What happens exactly? Please provide us with the full source code.

Best Regards,

Panagiotis


@PanagiotisCharalampous

buccinator
30 Aug 2019, 10:08

my bot is over 2700 lines of code and it seems irrelevant as it crashed first line of code at OnStart(). 

i just tried replicating the error in a new template bot with no luck. i tried with lots of parameters and big enums thinking it would somehow change the outcome, it did not.

the workaround i originally posted works so will stick with that, i guess its a heads up if anyone else (somehow) has the same issue.

from memory i believe it was a crashed with "onstart error with null reference exception object not set to an instance of an object".

the first line of code i had in OnStart() was use of the Chart object. sorry i am unable to replicate the issue in a template bot.


@buccinator