Any help please. Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Error on calling "OnBarUpdate" method on bar0
Collapse
X
-
Error on calling "OnBarUpdate" method on bar0
I created a strategy using strategy builder. But when I backtest, I get this error message: Error on calling "OnBarUpdate" method on bar0: Index was outside of the array.
Any help please. Thanks.Tags: None
-
Hello AdeptistJune,
Thank you for your post.
I'd like to take a look at the strategy and see why it may be throwing that error. You can export the strategy from Tools > Export > NinjaScript Add-on. Do not check the box to export as a compiled assembly or I will not be able to review the logic. Please attach the resulting .Zip file to your reply.
Thanks in advance; I look forward to assisting you further.
-
Thanks so much. I attached the file as instructedAttached Files
Comment
-
Hello AdeptistJune,
Thank you for your reply.
Your problem isn't the strategy itself, it's the indicators it calls.
All 5 indicators need to look back at least 1 and up to 5 bars in order to calculate. If you don't tell the script to wait to calculate until you have at least the largest lookback number of bars, you'll get an error when the strategy tries to call the indicator.
This is an easy fix, however, you just need to add a current bar check at the top of OnBarUpdate in each indicator, like seen below:
protected override void OnBarUpdate()
{
// don't start processing until 5 bars are available to look back at
if(CurrentBar < 5)
return;
Value[0] = Close[5] - Close[4];
}
You'll need to adjust all of the indicators to add a CurrentBar check like the bolded code above and then you should be able to run the strategy without an error.
Please let us know if we may be of further assistance to you.
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
89 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
135 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
68 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
119 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
69 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Comment