![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
If upon loading an indicator to a chart, OnBarUpdate() starts iterating from the left-most bar, how can I refer the close price of the right-most bar at that stage of the initial iteration?
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
savekad,
Unfortunately this wouldn't be advised here. You can try to use negative indices or something like GetCurrentBid() or GetCurrentAsk() however this is sort of like "peeking" into the future at that point.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
OK, so let's say I create a DS object and store all bars close prices. How do I later, address the last value in the DS object?
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
savekad,
Generally an index of 0 is always the last added element to the series. Values[][] is the array of plots.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
But if I didn't use the Add() method to create a DS object, then how do I address its elements?
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
savekad,
You can use something like this : SMA(41)[0] to access elements of an indicator for example. There is no need to use the Add() method. If you are wanting to instantiate an indicator you can do this as well. IndicatorBase SMA = new SMA(period); Here is a sample that works with instantiated indicators : http://www.ninjatrader.com/support/f...d=4&linkid=535
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
Oh no, I don't want to access elements of some other indicator. In the indicator I am building, I created a DS object which to it I save some close values from bars on the chart. Later in the code, I want to access the values I saved in the aforementioned DS object. How do I do that?
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
savekad,
It would probably be easier to see how you are creating this object. Do you have a code sample?
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
It isn't finished but it goes something like this:
Let's say that I want to draw a ray from all close values that are above the price 1300.00. I create a DataSeries object and code OnBarUpdate() to: if (Close[0] > 1300.00) { dso.Set(Close[0]) } I am left with a DS object that holds values above 1300.00 and their corresponding CurrentBar int, correct? How do I later, draw a ray for those prices, a ray that will start from the relevant bar? This example is quite of a nonsense, I know, but it is simple and will do the trick. |
|
|
|
|
|
#10 | |
|
Senior Member
|
Quote:
You may be overthinking this. If you want to access a member of a DataSeries, just use its index to do so.
|
|
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
So every DSo has access properties? What are they than? And if I have several DS objects that were not created via the Add() method, how do I access their properties? Simply using the full name DataSeriesObject.PropertyName[barsAgo] and it will return the double stored there?
Let me know if I got it right. |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
OK, I just went over the DataSeries Class page again and noticed I can simply access the values by DataSeriesObject[int barAgo] like you said.
I will try continue from here. Thank you both. |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
savekad, if you run into the need to expose internal dataseries of other indicators, please keep this reference in mind - http://www.ninjatrader.com/support/f...ead.php?t=4991
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Current Price Not Equal to Close[0] | dkrumholz | Indicator Development | 1 | 03-09-2011 01:53 PM |
| Making Close[0] == current price | dsraider | Strategy Development | 9 | 06-19-2010 07:08 AM |
| what is the property of current bar's close time? | leontancfa | General Programming | 2 | 08-14-2009 10:41 AM |
| Exit positions on current bar close | forextim | Strategy Development | 1 | 11-12-2008 08:39 AM |
| how to sendmail() with current symbol and close price | tbtrades | Miscellaneous Support | 3 | 10-17-2008 12:28 PM |