Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsData Disposed Before ChartControl

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    BarsData Disposed Before ChartControl

    I am encountering an exception during OnTerminate. I have set some chart properties, and am trying to restore them when the indicator unloads. Hopefully this pseudo-code explains the basic process:

    Code:
    OnStartUp {
        if (Bars.BarsData.ChartStyle.Pen != default(Pen))
                myColorCached = Bars.BarsData.ChartStyle.Pen.Color;
    }
    
    OnTerminate {
        if (ChartControl != null && ChartControl.IsHandleCreated) {
            if (Bars.BarsData.ChartStyle.Pen != default(Pen)
                    && myColorCached != default(Color))
                Bars.BarsData.ChartStyle.Pen.Color = myColorCached; // Raises sporadically
        }
    }
    Despite all the checks, the indicator will still raise a Parameter Is Not Valid exception on the commented line while reloading a chart (sporadically).

    It appears that the BarsData is being disposed while my code is running. Is there a better way to program this?

    In the actual code, there are more properties being restored, and a few complete before this one throws -- those others include BarsData.ChartStyle.UpColor and DownColor. Something is being disposed while my code is running; and there is no way I can see to check if BarsData is Disposed (and even if there were, since other calls do complete before this one throws, it appears that BarsData is being disposed by another thread before the OnTerminate finishes). Perhaps someone could just confirm that this is possible. On reading this post, I will wrap only the BarsData code in a try-catch and hopefully the ChartControl is remaining valid, but the BarsData is disposing: so therefore I would not leave the chart with my modifications on it when the indicator is unloaded. Thanks in advance.

    #2
    Hello Steevco,

    I believe that if you change these values, that when you reload or take the indicator off the chart, should revert back to the default settings. Is this not the case?

    There is no guarantee that the Bars object will be available in the OnTermination().
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply Cal. Yes: it's just guarded diligence; so it's not stopping progress.

      Just found the exception in what was seemingly "normal" undoing changes made on StartUp, that would not complete in OnTerminate ... Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      161 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      311 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      245 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      350 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      179 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X