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 NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
79 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
147 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
79 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
52 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
58 views
0 likes
|
Last Post
|

Comment