Your interactive trading laboratory!
 • 
16 users online

error msg: Object reference not set...

Occasionally, I do something funky in my C# code and get the following error:

Execute Exception (TQQQ,10) Object reference not set to an instance of an object.

Is there a way to improve the error reporting for this type of message so that it can point me into the code where this problem is happening?

Attachment

Cancel

Responses

I did find the problem in this case, where my code was trying to close a position that didn't exist, so it just needed an extra test before closing it.

But it was a lot of hunt and comment and if/else-ing to find it, where a reported line number could really help. Doing this may be problematic... the code compiles fine, but the error just shows up during runtime late, after the backtest seems to conclude. It sure can be a pain to track down.

I did find the problem in this case, where my code was trying to close a position that didn't exist, so it just needed an extra test before closing it. But it was a lot of hunt and comment and if/else-ing to find it, where a reported line number could really help. Doing this may be problematic... the code compiles fine, but the error just shows up during runtime late, after the backtest seems to conclude. It sure can be a pain to track down.

We can definitely improve the error reporting in this case and will work to do so in other situations as they are reported as well!

We can definitely improve the error reporting in this case and will work to do so in other situations as they are reported as well!

:-) thanks glitch ps. i'm really liking Qstudio. the real test is out-of-sample ahead of me, but I think it's upping my game a good bit.

:-) thanks glitch ps. i'm really liking Qstudio. the real test is out-of-sample ahead of me, but I think it's upping my game a good bit.

Ping! Glitch, could you make this into a Feature Request please? It's biting me again and again. It seems I can't make that change myself by editing the post.

Ping! Glitch, could you make this into a Feature Request please? It's biting me again and again. It seems I can't make that change myself by editing the post.

I'm curious, but wouldn't adding the exception handling to your code do the trick?

I'm curious, but wouldn't adding the exception handling to your code do the trick?

Hi bitfool, I already added the exception handling in ClosePosition to handle that case. I'd be happy to help you troubleshoot but I'd need a copy of the code that's causing a problem. You can email it to info@quantacula.com and I can take a look.

Hi bitfool, I already added the exception handling in ClosePosition to handle that case. I'd be happy to help you troubleshoot but I'd need a copy of the code that's causing a problem. You can email it to info@quantacula.com and I can take a look.

Glitch - I did find the issue, I was trying to populate a Dictionary without properly initializing it. Like:

  1. At the end of the code: private Dictionary<String, String> blahDict;
  2. Then in Initialize(): blahDict.Add("jim, "ballyhoo");
  3. Without also first doing this: blahDict = new Dictionary<String, String>();

Unfortunately for me, trying to compile #1 and #2 without #3 compiles without a hitch, and the only sign that anything is wrong is after running through everything and throwing those per symbol exceptions like:

Execute Exception (AAPL) Object reference not set to an instance of an object.

Glitch - I did find the issue, I was trying to populate a Dictionary without properly initializing it. Like: 1. At the end of the code: private Dictionary<String, String> blahDict; 2. Then in Initialize(): blahDict.Add("jim, "ballyhoo"); 3. Without also first doing this: blahDict = new Dictionary<String, String>(); Unfortunately for me, trying to compile #1 and #2 without #3 compiles without a hitch, and the only sign that anything is wrong is after running through everything and throwing those per symbol exceptions like: Execute Exception (AAPL) Object reference not set to an instance of an object.

Great news, I was able to extract the line number from the exception trace! This functionality will be in Q182.

Great news, I was able to extract the line number from the exception trace! This functionality will be in Q182.

That will help bigly, G.

That will help bigly, G.
Forum Tips

Please sign in if you want to participate in our forum.

Our forum uses Markdown syntax to format posts.

To embed code snippets, enclose them in [CODE][/CODE] tags.