Why is indicator OnCalculate code executing before OnInit has run and completed?

 

This baffles me.

Here is the IDE with the platform showing behind it, including a cleared Experts tab in its Toolbox:

Here is what I get when I run the debugger (green "play" icon)...

And this is what I see when I click OK to accept the default input parameter value, clearly showing the code paused at the breakpoint on the first line of OnInit...


How can OnCalculate code processing series data run before the indicator even gets the input information required to process the series data?

 

Apparently, launching the debugger leads to the recalculation of another copy of this indicator, which is already attached to some chart.

Try running the debug again, first making sure that you do not have working copies of this indicator at the time of launching the debugger.

Or, as an option (in order not to delete indicators from charts), make a copy of the source code of this indicator (with a different file name) and run debugging on a copy of the indicator, which definitely does not work on any chart

 
I don't use a debugger, but I suspect that running a debugger causes the indicator to be recompiled. And compilation, in turn, leads to removal and re-attachment of all working copies of the indicator
 
Vladislav Boyko #:
I don't use a debugger, but I suspect that running a debugger causes the indicator to be recompiled. And compilation, in turn, leads to removal and re-attachment of all working copies of the indicator

Thank you! I hadn't thought of that. Indeed, it was coming from an instance of the indicator on another chart. I removed it from there and: problem solved.