NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-28-2012, 03:04 PM   #1
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Exclamation yesterdays H/L bar number

Hi,
Is there any possibility to get the bar number of a 5min chart , that made yesterdays High or Low? I'd like to draw S/R levels from these bars for the current day.

I have already H/L price of the prior day but can not figure out how to get the bar numbers, that made the H/L.

Cheers
Thomas
td_910 is offline  
Reply With Quote
Old 06-28-2012, 03:16 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Thomas,
There is built in method HighestBar() that returns the number of bars since the high occurred.

This snippet below should work for you, but it uses unsupported property LastBarOfSession and only works historically.

Code:
#region Variables
private int myBarsAgo;
#endregion
	
if (Bars.LastBarOfSession)
myBarsAgo = HighestBar(High, Bars.BarsSinceSession);
			
Print(myBarsAgo);
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-28-2012, 04:15 PM   #3
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Default

This was always my problem with HighestBar function. It's unable to work with an index value [int barsAgo]. Even Metatrader had a function supporting this.
I need to draw this using live data, as it draws HLC lines from Y on the current days chart.

As a workaround I may use Most Recent Occurence (MRO) to find the bar number.
int barsAgo = MRO(delegate {return High[0] == Bars.GetDayBar(1).High;}, 1, Bars.BarsSinceSession+81);

But if you have sessions with less than 81 bars this wouldn't work.

Any suggestions for this?
td_910 is offline  
Reply With Quote
Old 06-29-2012, 07:53 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Yeah, I can see how indexing on HighestBar would make this much easier, will add as a suggestion. Yours should work as well. I would also check into modifying PriorDayOHLC() to see if you can custom track a bars ago value there.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-19-2012, 05:28 PM   #5
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

Will this work? (I have not tested, only compiled it).

In Variables:

public DataSeries x;


In OnBarUpdate():

x.Set (Closes[0][1]); //I don't think this would work in initialize?

Print ( HighestBar (x,15) );

If anyone proves this out, please reply.




Quote:
Originally Posted by td_910 View Post
This was always my problem with HighestBar function. It's unable to work with an index value [int barsAgo]. Even Metatrader had a function supporting this.
I need to draw this using live data, as it draws HLC lines from Y on the current days chart.

As a workaround I may use Most Recent Occurence (MRO) to find the bar number.
int barsAgo = MRO(delegate {return High[0] == Bars.GetDayBar(1).High;}, 1, Bars.BarsSinceSession+81);

But if you have sessions with less than 81 bars this wouldn't work.

Any suggestions for this?
sledge is offline  
Reply With Quote
The following 2 users say thank you to sledge for this post:
Old 08-19-2012, 06:55 PM   #6
dukeb
Senior Member
 
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
Default

Sledge,
X has not been instantiated. I get 'Object not set to an instance of the object'.
I tried to instantiate x but am too unfamiliar with the environment.
Duke
dukeb is offline  
Reply With Quote
Old 08-19-2012, 07:04 PM   #7
Radical
Senior Member
 
Join Date: Sep 2008
Posts: 543
Thanks: 80
Thanked 187 times in 131 posts
Default

Quote:
Originally Posted by dukeb View Post
Sledge,
X has not been instantiated. I get 'Object not set to an instance of the object'.
I tried to instantiate x but am too unfamiliar with the environment.
Duke
In Initialize() try adding

x = new DataSeries(this);

then it seems like sledge's method should work!
Radical is offline  
Reply With Quote
The following 3 users say thank you to Radical for this post:
Old 08-19-2012, 07:10 PM   #8
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

Quote:
Originally Posted by Radical View Post
In Initialize() try adding

x = new DataSeries(this);

then it seems like sledge's method should work!

OMG! lol

I was about ready to say it was going to fail, because I Close[0][1] is a double, not a dataseries. LOL.

But now this is what we were doing the other week in the DataSeries example and using .Dispose().

haha, I got lucky on this one.

But we are making a data series, one off.
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 08-19-2012, 07:13 PM   #9
dukeb
Senior Member
 
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
Default

I am getting numbers from 0-14. It looks as though '0' is really '1' . Is this correct??
dukeb is offline  
Reply With Quote
Old 08-19-2012, 07:14 PM   #10
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

Quote:
Originally Posted by dukeb View Post
I am getting numbers from 0-14. It looks as though '0' is really '1' . Is this correct??
Yes, add 1.

Print ( HighestBar (x,15)+1 );
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 08-19-2012, 07:18 PM   #11
dukeb
Senior Member
 
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
Default

Incredible ...
You have made my day, week month ...
I can't thank you enough ... great work!!!
Duke
dukeb is offline  
Reply With Quote
The following user says thank you to dukeb for this post:
Old 08-19-2012, 07:21 PM   #12
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

Quote:
Originally Posted by dukeb View Post
Incredible ...
You have made my day, week month ...
I can't thank you enough ... great work!!!
Duke
I just thought about it. The +1 works on the Closes[0] series.

The x (or whatever you decide to call it), won't need it. It's just a copy of a DataSeries that we have built that is 1 bar behind.
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 08-23-2012, 05:37 PM   #13
dukeb
Senior Member
 
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
Default

Sledge,
I have the following two lines of code.
Since you used a set statement to populate the object..
I assume you would use a get statement to assign the contents.
I have tried a number of possibilities using intellisense. None seem to compile.
This compiles but returns wrong information.

objHighBarsAgoNumber.Set (Closes[
0][1]);
HighBarsAgoNumber = (HighestBar (objHighBarsAgoNumber,
30)+1); <<<<
Thoughts?
Thanks,
Duke
dukeb is offline  
Reply With Quote
Old 08-23-2012, 07:30 PM   #14
dukeb
Senior Member
 
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
Default

Never mind --- I have found the problem...
dukeb is offline  
Reply With Quote
The following user says thank you to dukeb for this post:
Old 08-25-2012, 01:28 PM   #15
td_910
Member
 
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
Thumbs up awesome idea - many thanks

awesome idea - many thanks

Thomas
td_910 is offline  
Reply With Quote
Reply

Tags
support

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
CurrentBar: Flag to note when bar number first increments to next bar tonyh General Programming 2 05-09-2011 11:45 AM
Yesterdays data showing on todays date hunter Charting 15 01-20-2011 04:23 AM
Bar Number gviand General Programming 3 12-02-2010 01:56 AM
yesterdays ohlc code snippet diffused General Programming 3 12-18-2008 07:03 AM
Bar index from the session or plot bar number on an intraday chart eneratom General Programming 1 02-27-2008 06:48 AM


All times are GMT -6. The time now is 10:14 PM.