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 lightsun47, Today, 03:51 PM
      0 responses
      2 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      8 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      41 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      13 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      8 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X