That makes 'Out of range errors' so much stranger, then. Please see my other post below, similar with the errors I am talking about in my first post on this thread. How can I possibly get 'Out of range errors' when I have 5 days of data on my chart?
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
Strategy triggering before BarsRequiredToTrade
Collapse
X
-
Right... I think I get where the confusion originates: I thought the 9 bars I set up are the number of bars since I activated the strategy, but from your post it looks like they are the first historical bars from the start of the chart?
That makes 'Out of range errors' so much stranger, then. Please see my other post below, similar with the errors I am talking about in my first post on this thread. How can I possibly get 'Out of range errors' when I have 5 days of data on my chart?
-
Hello itrader46,
I thought the 9 bars I set up are the number of bars since I activated the strategy, but from your post it looks like they are the first historical bars from the start of the chart?
Regarding the other post and errors, I believe it would be good to clarify some of the information there as the error is the same as this post.
You have two different errors listed, the first error with EventHandlerBarsUpdate is not something we have a documented solution or case for. This error will require debugging the script further to isolate what code is causing that to happen so we can figure out how to prevent that.
The other error relating to BarsAgo is a generic error that is produced any time an error occurs based on data usage, this could just be a side effect of the first error. We will need to reduce the test case and find a situation to explore these errors.
One part I want to clarify in the other post:
This would mean that you are referencing an object that is null. This is not the same thing as an index out of range error which would be seen if you are referencing some BarsAgo value before the script processes that many bars.
I suggest debugging the code in your EventHandlerBarsUpdate method by adding prints so you can find out which specific line is creating the "Object reference not set to an instance of an object" error. (The output is hinting that this error is being thrown in your EventHandlerBarsUpdate method.)
I understand that debugging the script can be tedious however you are currently in the best position to see the problem. It would be best if you can try to further isolate a specific test case where we can explore these errors in more detail. The steps to explore the problem are important here because you noted this is pretty random. If you are able to isolate any steps where we can see this even a couple of times that would be helpful to explore the errors further.
I look forward to being of further asisstance.JesseNinjaTrader Customer Service
Comment
-
Having said that, I would have expected the code below to print the first bar on chart (Bar 0), but it doesn't, as you can see below the code
Code:protected override void OnBarUpdate() { // Make sure this strategy does not execute against historical data if (State == State.Historical) return; if (!strategyStart) { Print ("Strategy start bar: " + CurrentBar + " - " + Time[0]); strategyStart = true; }
" Enabling NinjaScript strategy 'ATM2/178978059'
Strategy start bar: 4480 - 21/10/2019 05:01:00 "
Whereas this code produces the prints below,
Code:protected override void OnBarUpdate() { if (!strategyStart) { Print ("Strategy start bar: " + CurrentBar + " - " + Time[0]); strategyStart = true; } // Make sure this strategy does not execute against historical data if (State == State.Historical) return;
" Strategy start bar: 0 - 15/10/2019 23:01:00
Enabling NinjaScript strategy 'ATM2/178978060'
----------
Short condition at: 53.74 - Current Bid: 53.74 - R = 1 - Open: 53.76 - Current Bar: 4483 @ 21/10/2019 05:05:00
Short ATM triggered at: 53.74 Open: 53.76 - Current Bar: 4483 Short order bar = 4483 - 21/10/2019 05:05:00 "
So basically, it looks like the strategy doesn't execute before the " if (State == State.Historical) return; ", just as I expected.
Does that mean that, when you say
Correct your script will process historical data first. 9 bars will be starting from bar 0 of historical data, the error you were seeing is happening farther into the processing past that point.
Does the script actually process historical data, coz I thought it wasn't with ATM strategies?
In that case, the error message is completely ...erroneous to begin with and doesn't offer the slightest bit of hint as to what the issue is.
Regarding those errors, since I added this code (OnBarUpdate), I've never had them anymore. Do you think that would have anything to do with it, or they are just not coming now and they might return again?
Code:else if (State == State.DataLoaded) { T31b0 = T3(Closes[0], 5, 3, 0.7); T32b0 = T3(Closes[0], 8, 3, 0.7); T31b1 = T3(Closes[1], 5, 3, 0.7); T32b1 = T3(Closes[1], 8, 3, 0.7); T31b2 = T3(Closes[2], 5, 3, 0.7); T32b2 = T3(Closes[2], 8, 3, 0.7); T31b0.Plots[0].Brush = Brushes.Transparent; T32b0.Plots[0].Brush = Brushes.Transparent; T31b1.Plots[0].Brush = Brushes.Transparent; T32b1.Plots[0].Brush = Brushes.Transparent; T31b2.Plots[0].Brush = Brushes.Transparent; T32b2.Plots[0].Brush = Brushes.Transparent; AddChartIndicator(T31b0); AddChartIndicator(T32b0); AddChartIndicator(T31b1); AddChartIndicator(T32b1); AddChartIndicator(T31b2); AddChartIndicator(T32b2); protected override void OnBarUpdate() { if (CurrentBars[0] < 9 || CurrentBars[1] < 9 || CurrentBars[2] < 9 /*|| CurrentBars[3] < 9*/) return; if (T31b0 == null || T32b0 == null || T31b1 == null || T32b1 == null || T31b2 == null || T32b2 == null) { T31b0 = T3(Closes[0], 5, 3, 0.7); T32b0 = T3(Closes[0], 8, 3, 0.7); T31b1 = T3(Closes[1], 5, 3, 0.7); T32b1 = T3(Closes[1], 8, 3, 0.7); T31b2 = T3(Closes[2], 5, 3, 0.7); T32b2 = T3(Closes[2], 8, 3, 0.7); }
Last edited by itrader46; 11-14-2019, 12:35 PM.
Comment
-
Hello itrader46,
Having said that, I would have expected the code below to print the first bar on chart (Bar 0), but it doesn't, as you can see below the code
Code:
protected override void OnBarUpdate()
{
// Make sure this strategy does not execute against historical data
if (State == State.Historical)
return;
if (!strategyStart)
{
Print ("Strategy start bar: " + CurrentBar + " - " + Time[0]);
strategyStart = true;
}
Whereas this code produces the prints below,
So basically, it looks like the strategy doesn't execute before the " if (State == State.Historical) return; ", just as I expected.
Does that mean that, when you say
Correct your script will process historical data first. 9 bars will be starting from bar 0 of historical data, the error you were seeing is happening farther into the processing past that point.
that I should never ever get Out of Range exception, unless I set an indicator with a period of over 5000?
In your specific error it was over bar 5000 for that series so it looks like that was farther into processing however that could be just entering realtime after processing historical. I have no context of the test you did to understand the print in contrast to the logic.This is a situation where debugging and finding the combination of steps used and syntax would be needed to further understand the error better.
Does the script actually process historical data, coz I thought it wasn't with ATM strategies?
Regarding those errors, since I added this code (OnBarUpdate), I've never had them anymore. Do you think that would have anything to do with it, or they are just not coming now and they might return again?
Please let me know if I may be of further assistance.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by fitspressoburnfat, Today, 04:25 AM
|
0 responses
2 views
0 likes
|
Last Post Today, 04:25 AM | ||
Started by Skifree, Today, 03:41 AM
|
1 response
4 views
0 likes
|
Last Post
by Skifree
Today, 03:42 AM
|
||
Started by usazencort, Today, 01:16 AM
|
0 responses
1 view
0 likes
|
Last Post
by usazencort
Today, 01:16 AM
|
||
Started by kaywai, 09-01-2023, 08:44 PM
|
5 responses
604 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by xiinteractive, 04-09-2024, 08:08 AM
|
6 responses
23 views
0 likes
|
Last Post Today, 12:31 AM |
Comment