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

ChartControl usage

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

    ChartControl usage

    I have indicators coded that make extensive use of the ChartControl object.
    Those indicators behave as expected when placed on a chart directly.

    However, when coding a strategy and adding those indicators using the AddChartIndicator(myIndicator) command, I am getting null reference exceptions in various places that did not occur when the indicator is on the chart directly. These exceptions are mostly a result of the ChartControl instance being null.

    Some questions:

    1) Is the life cycle of the ChartControl instance of the indicator the same when it is created in the strategy and then added via AddChartIndicator(indicator)?

    2) Is the ChartControl instance provided to the strategy the same one as provided to the indicators that are added via the strategy? Would it work to have the strategy pass in it's ChartControl instance to each indicator so it was available in that moment?

    3) Is there a point in the life cycle of an indicator where the ChartControl instance is guaranteed to be valid? (in terms of the state transitions that occurred when OnStateChange is called).

    4) Are there any differences in the answers to the above questions for NT 7 versus NT 8?

    5) In a strategy, what state is best for calling the AddChartIndicator(indicator) method?


    Thanks,
    Gary

    #2
    Hello,

    Thank you for the questions.

    1, The life cycle is different regarding the chart control, because you are Hosting an indicator using a Strategy its loading path would be slightly different. The easiest way to explain this would be to just Print(State); from the OnStateChange override, also you can print if the ChartControl is null or not to check the differences. In general ChartControl should use a null check as there are places where you can enable the script where there is no chart such as the control center or a backtest.

    2. The instance would be the same as you are still accessing the same Chart, but because you are Hosting an indicator instead of directly applying it, there are different paths it would need to take to become enabled.

    3. In general State.Historical this would be available but again Null checks would be suggested anytime you are using an object which can be null in its lifespan.

    4. There are differences between NT7 and NT8 mainly because of the different states. again the best way to see the actual differences would be to just Print the States out to see the order everything is being executed.


    5. For any NinjaScript code, the best State to use would be the one listed in the helpgude. In this case the state would be State.Configure http://ninjatrader.com/support/helpG...ChartIndicator

    I look forward to being of further assistance .
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by inanazsocial, Today, 01:15 AM
    0 responses
    2 views
    0 likes
    Last Post inanazsocial  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    22 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Started by guillembm, Yesterday, 11:25 AM
    2 responses
    9 views
    0 likes
    Last Post guillembm  
    Started by junkone, 04-21-2024, 07:17 AM
    9 responses
    70 views
    0 likes
    Last Post jeronymite  
    Working...
    X