NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-29-2012, 10:11 AM   #1
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default Absolute current close

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?
savekad is offline  
Reply With Quote
Old 07-29-2012, 11:03 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-29-2012, 02:36 PM   #3
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default

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?
savekad is offline  
Reply With Quote
Old 07-29-2012, 03:08 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

savekad,

Generally an index of 0 is always the last added element to the series. Values[][] is the array of plots.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-29-2012, 04:14 PM   #5
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default

But if I didn't use the Add() method to create a DS object, then how do I address its elements?
savekad is offline  
Reply With Quote
Old 07-29-2012, 04:20 PM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-29-2012, 04:39 PM   #7
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default

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?
savekad is offline  
Reply With Quote
Old 07-29-2012, 05:17 PM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

savekad,

It would probably be easier to see how you are creating this object. Do you have a code sample?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-29-2012, 06:33 PM   #9
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default

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.
savekad is offline  
Reply With Quote
Old 07-29-2012, 07:00 PM   #10
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,198
Thanks: 24
Thanked 1,224 times in 995 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by savekad View Post
But if I didn't use the Add() method to create a DS object, then how do I address its elements?
A DataSeries is an object with properties .It has nothing to do with how it was created. The DataSeries elements are indexed backwards, 0 being the most recent, and increasing monotonically into the past until the number of entries in the DataSeries equals the number of bars on the chart.

You may be overthinking this. If you want to access a member of a DataSeries, just use its index to do so.
koganam is offline  
Reply With Quote
Old 07-30-2012, 12:49 AM   #11
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default

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.
savekad is offline  
Reply With Quote
Old 07-30-2012, 02:39 AM   #12
savekad
Senior Member
 
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
Default

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.
savekad is offline  
Reply With Quote
Old 07-30-2012, 04:01 AM   #13
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

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
NinjaTrader_Bertrand is online now  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 07:01 AM.