Any help please. Thanks.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Kate W.NinjaTrader Customer Service
-
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.Kate W.NinjaTrader Customer Service
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
8 responses
58 views
0 likes
|
Last Post
by ETFVoyageur
Today, 11:58 AM
|
||
Started by Taddypole, 04-26-2024, 02:47 PM
|
8 responses
72 views
0 likes
|
Last Post
by eDanny
Today, 11:58 AM
|
||
Started by quicksandatl, Today, 11:11 AM
|
2 responses
6 views
0 likes
|
Last Post
by quicksandatl
Today, 11:53 AM
|
||
Started by GwFutures1988, 10-15-2023, 12:13 AM
|
12 responses
517 views
0 likes
|
Last Post Today, 11:50 AM | ||
Started by DawnTreader, Yesterday, 05:58 PM
|
3 responses
16 views
0 likes
|
Last Post Today, 11:48 AM |
Comment