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

Resetting Default Brushes upon Indicator Removal in NT8

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

    Resetting Default Brushes upon Indicator Removal in NT8

    Hi, I can change the chart background colour and bar colours when my custom indicator loads using ChartControl.Properties.ChartBackground and ChartBars.Properties.ChartStyle.__, but I have 2 questions.

    #1 Is it best to place the code that make the initial colour/brush changes inside OnRender similar to the Help guide example for how to print what the chartbackground colour is?

    #2 When the indicator is removed, how can I code changing the default colours back to the original settings? I tried coding within State.Terminated which works but also gives an "Object reference not set to an instance of an object." I assume I need to instantiate a ChartControl.Properties and ChartBars.Properties but am not sure of correct syntax.

    Thanks in advance.

    #2
    Hello REI140205,

    Thanks for your questions.

    #1 Is it best to place the code that make the initial colour/brush changes inside OnRender similar to the Help guide example for how to print what the chartbackground colour is?
    OnRender may be the best method to observe a change to the chart background at the soonest moment, but you are not required to change or check the chart background in OnRender. I've attached an example that only uses OnStateChange.

    #2 When the indicator is removed, how can I code changing the default colours back to the original settings? I tried coding within State.Terminated which works but also gives an "Object reference not set to an instance of an object." I assume I need to instantiate a ChartControl.Properties and ChartBars.Properties but am not sure of correct syntax.
    You will just need to make sure ChartControl is not null when State == State.Terminated. I also suggest using a bool to let the indicator know it has changed this property. Please see the example attached and the links below for more information on NinjaScript states and life cycle.

    NinjaScript LifeCycle - https://ninjatrader.com/support/help...fecycle_of.htm

    NinjaScript LifeCycle video (publicly available) - https://www.youtube.com/watch?v=gyel...EYKym&index=17

    Let me know if you have any additional questions.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim, it works now --- I needed the bool you suggested. I put a print statement in each State change and was surprised to see the following sequence upon indicator add to a chart and then removal. I was expecting to only see State.Terminated visited once when indicator was removed from chart (I think the errors were triggered during all but the last time State.Terminated code was run).

      Adding indicator to a chart;
      SetDefaults
      SetDefaults
      Terminated
      SetDefaults
      Configure
      DataLoaded
      Historical
      Terminated

      Remove indicator from chart:
      SetDefaults
      SetDefaults
      Terminated
      Terminated
      Terminated

      Comment


        #4
        Hello REI140205,

        Yes, these prints will reflect the lifecycle the indicator goes through when it is cloned. The LifeCycle video and documentation can explain further. The error would likely have been thrown from a part of the cloning process where ChartControl/ChartBars is null in State.Terminated.

        If you have any additional questions, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by futtrader, Today, 01:16 PM
        0 responses
        4 views
        0 likes
        Last Post futtrader  
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,789 views
        0 likes
        Last Post aligator  
        Started by Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        838 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,294 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        13 views
        0 likes
        Last Post Touch-Ups  
        Working...
        X