My indicator need to execute long running function (~3000 ms) on Bar 0 in OnBarUpdate (OBU). If that function in OBU has finished then upon indicator termination there is a need to execute another long running function in State.Terminated. When indicator is added to the charts while data feed has already been connected, no issues were observed. Problems start on NT8 startup with 10 and more charts using that indicator and brokers connecting on startup. State.Terminated appears during an execution of OBU (I’ve used 3 brokers: Kinetic, FXCM and Continuum)
After studying the posts
https://ninjatrader.com/support/foru...ck+termination
https://ninjatrader.com/support/foru...ination&page=3
the Lock was implemented in OBU and in State.Terminated. This has resolved an issue with startup of NT8, but has created another one: On exit from NT8 or on connection recovery after connection loss State.Terminated is not called for some of the charts.
Moreover, in some situations (when function’s running time is increased), State.Terminated of some indicators is not even finished.
An indicator, demonstrating that behavior is in attachment.
Changing both long running functions to be executed in the separate task or even in separate thread are is not helping.
In attempts to find the resolution, I’ve added AddOn with OnWindowDestroyed, printing out titles of windows to be closed and again, some Charts (including ControlCenter window) were missing from the logs
protected override void OnWindowDestroyed (Window cWindow) { if (cWindow == null) { return; } Log ("TestNT8AddOn :: OnWindowDestroyed : Destroying window. State = " + State.ToString() + " Title = " + cWindow.Title + " Window count = " + Globals.AllWindows.Count, LogLevel.Information); }
It looks so that chart threads are terminated based on timeout (approximately 2000 - 3000 ms) without waiting for the end of State.Terminated results or even without calling some.
From all above, there are few questions:
1. What is the correct way to execute long running tasks in OnBarUpdate and State.Terminated to avoid all mentioned above problems?
2. Is that a correct behavior of NT8 to terminate an application prior to the completeness of State.Terminated of all charts with an indicators?
3. If this is a correct behavior , is there any way to increase the termination timeout (if it does exist) from AddOn or Indicator itself?
Thank you in advance and
GmA
Comment