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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
45 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
21 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
31 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
50 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
42 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment