• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 mohdhm, Today, 04:37 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by trader14, Yesterday, 08:23 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by bigsurftrader, 02-24-2017, 12:23 AM
        4 responses
        1,162 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by svadukia, Yesterday, 01:56 AM
        2 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by quantrob, Today, 10:24 AM
        1 response
        7 views
        0 likes
        Last Post bltdavid  
        Working...
        X