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
Get Bar By Index
Collapse
X
-
Get Bar By Index
Is it possible to obtain a bar object by index from the "Bars" array? I'm wanting to compare a bar classified as a "CandlestickPattern" to a value. I've made a function to so, but I'm having a hard time obtaining the correct bar object. I could pass in the OCHL values but that seems ignorant when the Bar object contains all those values.
Thanks,Tags: None
-
Hello Herrwolf1,
Welcome to the NinjaTrader support forum.
Yes this is certainly possible to retrieve values from a specific index.
In NinjaScript you have two methods of retrieving information about a bar depending on the scope of where you are accessing that data. From OnBarUpdate you generally use the BarsAgo system to retrieve data from a number of Bars from now or the processing bar. When outside the OnBarUpdate context you instead deal with direct bar indexes so both systems are supported in NinjaScript.
When using a price series, indicator, or any Series<T> you will have the GetValueAt method which allows to get a value from a specific index:
for example:
Code:Close.GetValueAt(123);
This would return the Close price for that index. Rather than gathering a bar, you would use the series to retrieve the value.
If you are getting a BarsAgo returned from something you are doing, you can also convert that to an index by subtracting the BarsAgo from the CurrentBar:
Code:CurrentBar - BarsAgo = index of bar
JesseNinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
148 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,283 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment