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 Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,769 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        10 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        7 views
        0 likes
        Last Post rocketman7  
        Working...
        X