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

Draw.Triangle null object exception from strategy

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

    Draw.Triangle null object exception from strategy

    Hi,
    an indicator uses Draw.Triangle. When this indicator is used by a strategy and it is not added to the chart via AddChartIndicator, the Draw.Triangle fails with an Exception of null object (not set to an instance).
    By using the following clause inside the indicator I could get the strategy to run the indicator successfully

    Code:
    					if (this.ChartControl != null)
    						Draw.Triangle(t...);
    I had thought the Draw methods would survive any situation without a Chart to draw on. Please advise if this is a bug for every draw method, a bug for just the Triangle, or in fact intended operation that I will need to code around in every project.
    Thanks,
    saltminer

    #2
    Hello saltminer,

    Thanks for writing in.

    The AddChartIndicator() method is only intended to add plots from an indicator to the chart via the strategy. Calculations done using an indicator from a strategy will not show any plots from that indicator unless that indicator is added with AddChartIndicator().

    In the case of drawing objects, they will not be added to the chart when the indicator is added via an indicator and ChartControl would be null. It would also be expected that you check if ChartControl is null before attempting to use draw objects within an indicator if you wish to use the indicator's calculations inside your strategy.

    If you wish to display drawing objects within your chart, when adding the strategy, it is suggested that the drawing object gets added to that strategy or the top level NinjaScript.

    Further reading on AddChartIndicator() and its usage notes, you may reference the documentation here: https://ninjatrader.com/support/help...tindicator.htm

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,
      my actual talking point is the Exception that the indicator causes when trying to draw. I don't recall this in NT7. An indicator that does drawing doesn't cause problems in NT7 if called from a strategy.
      My question is : does NT8 change the rules for this, and should the null test for ChartControl always be implemented as standard procedure in an indicator that draws?

      Thanks,
      saltminer

      Comment


        #4
        Hello saltminer,

        Thanks for your reply.

        Since the drawing objects in NinjaTrader 8 include an owner object, that owner object must be valid for the Draw.Triangle function to work. Since NinjaTrader 7's drawing objects do not use an owner object, they would not display when called from a indicator attached to a strategy and would not show any error because it does not have an owner object.

        Since NinjaTrader 8 does have owner objects, it is advised to add that condition to check if the owner object has access to ChartControl before attempting a Draw Object call.

        Please let me know if you have any other questions.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GLFX005, Today, 03:23 AM
        0 responses
        1 view
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        6 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        12 views
        0 likes
        Last Post TradeForge  
        Started by Waxavi, Today, 02:00 AM
        0 responses
        2 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X