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 12-06-2008, 11:52 AM   #1
shawnj
Senior Member
 
Join Date: Jan 2005
Location: , ,
Posts: 218
Thanks: 0
Thanked 0 times in 0 posts
Default Help with Exception Logic

Friday, 11 minutes after the open, an hour after starting my indicator, my indicator got an exception message in the Log tab. No unusual events preceeded this exception.
Here is the exact exception message:
"
Error on calling 'OnBarUpdate' method for indicator 'aaMyIndicator' on bar 4685: Index was out of range.
Must be non-negative and less than the size of the collection. Parameter name: index
"

My indictor has CalculateOnBarClose=false (tick-by-tick updating in OnBarUpdate()).

I've structured my OnBarUpdate() code with a try/catch which surrounds all the code in OnBarUpdate(). This is the only try/catch in OnBarUpdate().

Code:
protected override void OnBarUpdate()
{
  try
  {

    //A bunch of code but no other try/catch statements.

  }
  catch(Exception e)
  {
    Print("My Exception Handler.");
    Print(e.Message);
  }
}
The above exception was not caught by my try/catch inside OnBarUpdate().

So can I conclude the code that caused the above exception was not inside OnBarUpdate()? And if this is correct, then what could cause this exception? I do call Update() in another area of the code. I assume Update() eventually causes an OnBarUpdate() event.

If the call to Update() is possibly a contributor to the above exception, are there some conditions that should be checked for before calling Update()?

thanks,
shawnj
Last edited by shawnj; 12-06-2008 at 11:55 AM.
shawnj is offline  
Reply With Quote
Old 12-06-2008, 03:56 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

I will forward this to development for review. By chance can you reproduce this?
NinjaTrader_Ray is offline  
Reply With Quote
Old 12-07-2008, 04:09 AM   #3
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> If the call to Update() is possibly a contributor to the above exception, ...?
Potentially. Unfortunately we are not aware of any details related to the issue you experienced. We would need a reproducible scenario in order to analyze what's going on.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 12-07-2008, 06:47 AM   #4
shawnj
Senior Member
 
Join Date: Jan 2005
Location: , ,
Posts: 218
Thanks: 0
Thanked 0 times in 0 posts
Default

Unfortunately I have not been able to reproduce this error. It has been very intermittent. If I play it back with Market Replay there are no errors. This indicator has lots of "moving parts" .

This has proven to be one of the hardest bugs I've every tried to track down. It would be helpful if from the previously provided information I could be sure that none of the code in the OnBarUpdate() was a contributor to the exception error. It is my understanding that only unhandled exceptions will appear in the Log tab.

For next week's testing, I've wrapped the Update() call with a try/catch. The Update() call is coming from another thread. I'm guessing this has something to do with it.

thanks,
shawnj
Last edited by shawnj; 12-07-2008 at 06:55 AM.
shawnj is offline  
Reply With Quote
Old 12-07-2008, 02:06 PM   #5
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> The Update() call is coming from another thread.
Unfortunately multi-threading is not supported. It may or may not work. You would need to try on your own.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 12-08-2008, 05:15 AM   #6
shawnj
Senior Member
 
Join Date: Jan 2005
Location: , ,
Posts: 218
Thanks: 0
Thanked 0 times in 0 posts
Default

The exception that I originally documented seems to be coming from withing NT and therefore out of my reach. I also can't duplicate it so I realize I'm on my own.

I was calling Update() to just force a screen update (Paint). So far, my attempts to draw on a chart from another thread, either directly with calls to DrawXX() or indirectly with Update() have been problematic.

Studying the BarTime indicator code, I see another way to force a Paint may be to call ChartControl.ChartPanel.Invalidate(). I think I'll try to rig up something with a timer, which should be on the chart thread, and a signaling variable to indicate if Invalidate shoud be called. This will probably be safer than calling Update() from other than the chart's thread.

thanks,
shawnj
shawnj is offline  
Reply With Quote
Old 12-08-2008, 06:21 AM   #7
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> This will probably be safer than calling Update() from other than the chart's thread
Definitely
NinjaTrader_Dierk 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
Reverse Logic (short) question ericadam Strategy Development 3 10-13-2008 08:40 AM
MRO logic question Burga1 Strategy Development 4 04-09-2008 08:56 PM
Ninjascript logic and Live Orders ohowie General Programming 3 01-19-2008 09:10 AM
Order Pending Logic Oli Automated Trading 12 04-02-2007 03:13 AM
Order logic and OnBarUpdate MrBaffalo Strategy Development 2 01-29-2007 04:54 AM


All times are GMT -6. The time now is 10:14 PM.