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

Drawing object is null...when it isn't

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

    Drawing object is null...when it isn't

    I have the following code in OnBarUpdate:

    if (line1 == null)
    line1 = DrawHorizontalLine("line1", false, 1000.25, Color.Red, DashStyle.Solid, 1);

    if (line1 == null)
    Print("line 1 shouldn't be null...");

    The problem is that line1 DOES get drawn (and the above code is the ONLY place where I actually draw line1), I can see it on the chart at 1000.25, but the Print statement "line1 shouldn't be null..." still gets written to the output window on each tick. I guess I don't understand why this would be happening. Any ideas?

    EDIT: OK, I've tested this some more, and it looks like this doesn't happen when the indicator is manually added to a chart. In that scenario, everything works as expected. But when the indicator is called from a chart (i.e. 'Add(indicator());'), that's when this all happens.


    EDIT #2: Another thing I've noticed is that when I call properties of the indicator from the strategy I've added it to, the properties are ALL either null, or at their default value. For example, I've placed the following line in the indicator's OnBarUpdate:

    double price = Close[0];

    I've then made the variable 'price' publicly accessible (as 'Price'), and when I add the following line to the strategy's OnBarUpdate:

    Print(indicator().Price.ToString());

    Zero is always the value that gets printed, even though it shouldn't be zero.


    EDIT #3: So it looks like this is a problem with my strategy and not with my indicator. I've added other working indicators to this strategy, and the same problem occurs with them -- all properties are at their default values. It's as if the strategy isn't adding the indicator correctly, something like that. I'm not getting any errors at runtime though, and the strategy doesn't disable itself or anything, so I'm not sure how to debug this.
    Last edited by Radical; 10-01-2012, 12:32 AM.

    #2
    Have you restarted/rebooted?

    What is your days to load?

    Have you tried adding your strategy to the strategy tab instead of the chart, or vice versa?

    I guess this would cause an error then? http://www.ninjatrader.com/support/h...zontalline.htm

    Comment


      #3
      Originally posted by sledge View Post
      Have you restarted/rebooted?

      What is your days to load?

      Have you tried adding your strategy to the strategy tab instead of the chart, or vice versa?

      I guess this would cause an error then? http://www.ninjatrader.com/support/h...zontalline.htm
      I haven't rebooted, I'll try that tomorrow. My days to load is the default of 3 for this bar type. I've tried adding to the strategy tab as well as the chart, both produce the same result.

      The weird thing is that no errors get thrown whatsoever. I have references in this strategy to certain parts of this indicator that I know are null (I know this because I check to see if they're null, and Print if they are), but the strategy doesn't throw an error on these lines. Normally I'd get an 'Object reference not set to instance of object' error, but in this case, the lines of code that contain the null references simply don't execute -- no errors.

      EDIT: I rebooted, unfortunately the problem persists.
      Last edited by Radical; 10-01-2012, 01:00 AM.

      Comment


        #4
        Radical, could you please email me or attach the strategy / indicator you're using here and then include on which instrument, timeframe and barstype? It would be expected though that the drawing objects could not be modified from an external script instance.

        For exposing indicator values like your price variable, please see this dedicated sample here for the supported technique to achieve this - http://www.ninjatrader.com/support/f...ead.php?t=4991
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Barry Milan, Yesterday, 10:35 PM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        13 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        12 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        8 views
        0 likes
        Last Post nandhumca  
        Working...
        X