Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference not set to an instance of an object

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

    Object reference not set to an instance of an object

    I always have a tough time finding these.
    This is the code that throws the error:

    Code:
              while(CanNumber < CanCount)
                {
                    TOI = Time[0];
                    barsAgo=GetBar(new DateTime(TOI.Year,01,01,00,00,00));
                    SubjBar = HighestBar(High,barsAgo);
                    Canhigh[CanNumber] = Math.Round(High[SubjBar],2);
                    SubjBar = LowestBar(Low,barsAgo);
                    Canlow[CanNumber] = Math.Round(Low[SubjBar],2);
                    Canopen[CanNumber] = Math.Round(Open[barsAgo],2);
                    Canclose[CanNumber] = Math.Round(Close[0],2);
                    CanNumber = CanNumber +1;
                }
    Any ideas?

    P.S.
    Code:
            private int CanCount = 1;
            private int CanNumber = 0;
    Last edited by Sleeping Troll; 03-20-2010, 05:09 PM. Reason: Updated code to avoid use of reserved word(s)... Still no joy.

    #2
    I did stumble upon a nifty way to isolate these errors. Precede each section in question with:
    if (CurrentBar < x)return;
    Use a unique x for each section and the error will tell you which section is throwing the error.

    if (CurrentBar < 1)return;
    while(CanNumber < CanCount)
    {
    if (CurrentBar < 2)return;
    TOI = Time[0];
    if (CurrentBar < 3)return;
    barsAgo=GetBar(new DateTime(TOI.Year,01,01,00,00,00));
    if (CurrentBar < 4)return;
    SubjBar = HighestBar(High,barsAgo);
    if (CurrentBar < 5)return;
    high[CanNumber] = High[SubjBar];
    if (CurrentBar < 6)return;
    SubjBar = LowestBar(Low,barsAgo);
    if (CurrentBar < 7)return;
    low[CanNumber] = Low[SubjBar];
    if (CurrentBar < 8)return;
    open[CanNumber] = Open[barsAgo];
    if (CurrentBar < 9)return;
    close[CanNumber] = Close[0];
    if (CurrentBar < 10)return;
    CanNumber++;
    }

    5 is throwing error...
    Last edited by Sleeping Troll; 03-20-2010, 04:50 PM.

    Comment


      #3
      Hello,

      Did you find the error?

      You also may want to try the try catch block:
      http://www.ninjatrader-support2.com/...ead.php?t=9825
      DenNinjaTrader Customer Service

      Comment


        #4
        Yes, I did... Have not tried the file you provided yet, Will let you know when I do.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JTizz, Today, 01:20 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by omermirza, Today, 12:39 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by mballagan, Today, 01:02 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by larkmail, Today, 12:30 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by Danila, Today, 11:08 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X