Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 rbeckmann05, Yesterday, 06:48 PM
      1 response
      12 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Working...
      X