NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 03-20-2010, 03:35 PM   #1
Sleeping Troll
Senior Member
 
Join Date: Mar 2010
Location: Tampa, FL
Posts: 186
Thanks: 0
Thanked 3 times in 1 post
Send a message via Yahoo to Sleeping Troll
Default 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 at 05:09 PM. Reason: Updated code to avoid use of reserved word(s)... Still no joy.
Sleeping Troll is offline  
Reply With Quote
Old 03-20-2010, 04:44 PM   #2
Sleeping Troll
Senior Member
 
Join Date: Mar 2010
Location: Tampa, FL
Posts: 186
Thanks: 0
Thanked 3 times in 1 post
Send a message via Yahoo to Sleeping Troll
Default

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 at 04:50 PM.
Sleeping Troll is offline  
Reply With Quote
Old 03-20-2010, 06:18 PM   #3
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

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
NinjaTrader_Ben is offline  
Reply With Quote
Old 03-22-2010, 11:40 PM   #4
Sleeping Troll
Senior Member
 
Join Date: Mar 2010
Location: Tampa, FL
Posts: 186
Thanks: 0
Thanked 3 times in 1 post
Send a message via Yahoo to Sleeping Troll
Default

Yes, I did... Have not tried the file you provided yet, Will let you know when I do.
Sleeping Troll is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set to an instance of an object molecool Version 7 Beta General Questions & Bug Reports 14 12-02-2009 10:54 AM
Error calling 'OnExecution' - object reference not set to an instance of an object kcsystemtrader Strategy Development 9 05-11-2009 03:11 PM
Error on running optimizer. Object reference not set to an instance of an object. vasily20011 Strategy Analyzer 5 03-09-2009 08:09 AM
Object reference not set to an instance of an object kcsystemtrader Strategy Development 6 02-09-2009 08:32 AM
Error: Object reference not set to an instance of an object. Januson Market Analyzer 1 05-18-2007 12:12 AM


All times are GMT -6. The time now is 12:44 AM.