![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 218
Thanks: 0
Thanked 0 times in 0 posts
|
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);
}
}
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.
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
I will forward this to development for review. By chance can you reproduce this?
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> 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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 218
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#5 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> 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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 218
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> This will probably be safer than calling Update() from other than the chart's thread
Definitely
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |