I have a button on the chart that runs a function that loops through all the data on the chart runs some calculations and then refreshes the plot. This problem occurs on both the minute and tick charts for ES.
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
When to use negative index
Collapse
X
-
When to use negative index
I have an indicator that keeps getting messed up because the barsAgo index keeps switching from negative to positive. When do I need a negative barsAgo index and when do I need a positive one? ie: Opens[0][1234] or Opens[0][-1234]
I have a button on the chart that runs a function that loops through all the data on the chart runs some calculations and then refreshes the plot. This problem occurs on both the minute and tick charts for ES.
Tags: None
-
Hello,
Calonio is correct. There are cases in which you would want to use a negative bar index, but it would be rare.
It would probably be more clear to explain when you would not want to use it. You should not use a negative barsAgo index when you are referring to any collection, such as a list, array, or data in a DataSeries object. For any collection that contains data, there will not be any data at a negative index.
However, if you are setting up a drawing object, or doing something other than referring to a collection, then using a negative bar index can work.
In your case, since you are looping through data series, you will not want to use a negative barsAgo index. You might consider simply looping from 0 to CurrentBar. 0 would represent the current bar, and the number returned by CurrentBar should refer to the first bar in the series when used as a bar index (for example, if CurrentBar was 200, then passing CurrentBar in as a barsAgo index would give you 200 bars ago).
Please let me know if I can assist further.Dave I.NinjaTrader Product Management
Comment
-
Did you see the picture I sent? I don't want to use a negative index, but when I use a positive one ninjatrader is throwing an error.
Opens[0].Count = 3312
i = 3291
Opens[0][i] => throws an error
Opens[0][-i] = 2100.5 => this is a real value...i don't understand why this object needs a negative index to return a value. Why does this occur?
Comment
-
Originally posted by habibalex View PostI have an indicator that keeps getting messed up because the barsAgo index keeps switching from negative to positive. When do I need a negative barsAgo index and when do I need a positive one? ie: Opens[0][1234] or Opens[0][-1234]
I have a button on the chart that runs a function that loops through all the data on the chart runs some calculations and then refreshes the plot. This problem occurs on both the minute and tick charts for ES.
http://screencast.com/t/ZdlulKQwxjXo
Comment
-
Originally posted by habibalex View Posti = 3921; //this is a positive number
Opens[0][3291] => throws an error, why is a positive number that is less than the size of the series throwing an error?
Opens[0][-3921] => this is equal to 2100.5, why is -3291 returning a value?
No matter how it occurs, if your code is trying to pass a negative calculated index, then your code needs to be corrected to never try to pass a negative index into a collection.
Comment
-
kognam please look at the picture again. http://screencast.com/t/ZdlulKQwxjXo
The Watch tab clearly shows that i = 3291.
3291 is a positive number, ie it is greater than 0. -1 * 3291 =-3291 which is a negative number.
In the picture it clearly shows that
i = 3291
Opens[0][-i] = Opens[0][-1 * 3291] = Opens[0][-3291] => 2100.5
Comment
-
Originally posted by habibalex View Postkognam please look at the picture again. http://screencast.com/t/ZdlulKQwxjXo
The Watch tab clearly shows that i = 3291.
3291 is a positive number, ie it is greater than 0. -1 * 3291 =-3291 which is a negative number.
In the picture it clearly shows that
i = 3291
Opens[0][-i] = Opens[0][-1 * 3291] = Opens[0][-3291] => 2100.5
At this stage you probably are going to have to disclose the details of DayObject. That means that I will have to bow out, so that if you choose to do so, you can deal with NinjaTrader directly. Your code looks involved enough that I have to presume that you would not want to share it with an anonymous stranger on a forum.
Comment
-
Once more question, please, about using negative index:
Can we use Open[-1], Close[-1], High[-1] and Low[-1] to access non-completed bar when CalculateOnBarClose = true?
(I need it to set correct StopLoss).
In Watch window of Visual Studio, on MarketReplay connection I can see correct OHLC values with [-1] index.
One only embarrassing me - debugger, also, show some prices with [-2] index too.Last edited by fx.practic; 05-29-2017, 04:32 PM.
Comment
-
Originally posted by fx.practic View PostOnce more question, please, about using negative index:
Can we use Open[-1], Close[-1], High[-1] and Low[-1] to access non-completed bar when CalculateOnBarClose = true?
(I need it to set correct StopLoss).
In Watch window of Visual Studio, on MarketReplay connection I can see correct OHLC values with [-1] index.
One only embarrassing me - debugger, also, show some prices with [-2] index too.
Thank you for your post.
You can use the negative index in your example.
Please let me know if you have any questions.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by carnitron, Today, 08:42 PM
|
0 responses
2 views
0 likes
|
Last Post
by carnitron
Today, 08:42 PM
|
||
Started by strategist007, Today, 07:51 PM
|
0 responses
3 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,969 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
5 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
Comment