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

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:
      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 cre8able, Today, 01:16 PM
        2 responses
        9 views
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        3 responses
        48 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by WHICKED, Today, 12:56 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by WHICKED, Today, 12:45 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X