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 GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,221 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      9 views
      0 likes
      Last Post FAQtrader  
      Working...
      X