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 mjairg, 07-20-2023, 11:57 PM
        3 responses
        213 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        544 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        12 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X