Indicator Methods (A Scope problem?)

Created at 28 Apr 2015, 21:54
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!
WhiteSage's avatar

WhiteSage

Joined 02.02.2014

Indicator Methods (A Scope problem?)
28 Apr 2015, 21:54


I'm using a library in an indicator, the class variables of the library are declared in the indicator and the instances are created in the 'initialise' section. I have a method in the indicator that does some processing, I only want to call it from the cBot e.g.

myIndicator.myMethod(index);

If the method is called from inside Calculate it works fine, however if the method is called by the cBot I get the following error:

InvalidOperationException: Operation is not valid due to the current state of the object.

Originally instantiating the class in Calculate (even though the variable is part of the indicator) caused a null ref when the method tried to access it. Now I have this error. Whats going on here and how can I make this object accessible here?


@WhiteSage
Replies

WhiteSage
29 Apr 2015, 00:12

It turns out calling myIndicator.Calculate from a bot doesn't execute correctly.

I had a parameter called ENABLE that was set to false by default (to prevent the indicator recalcing all the time), then tried the following:

myIndicator.ENABLE = true;
myIndicator.Calculate(MarketSeries.Open.Count);

But it doesn't fire the method correctly for some reason.


@WhiteSage

Spotware
18 Jun 2015, 17:22

Dear Trader,

Could you please provide more details regarding the issue? (code snippets of the initialize section, etc.)


@Spotware