![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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);
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
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? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
|
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:
|
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Sep 2008
Posts: 543
Thanks: 80
Thanked 187 times in 131 posts
|
|
|
|
|
|
|
#8 | |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
|
Quote:
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. |
|
|
|
|
|
The following user says thank you to sledge for this post: |
|
|
|
#9 |
|
Senior Member
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
|
I am getting numbers from 0-14. It looks as though '0' is really '1' . Is this correct??
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
|
|
|
|
|
|
The following user says thank you to sledge for this post: |
|
|
|
#12 | |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
|
Quote:
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. |
|
|
|
|
|
The following user says thank you to sledge for this post: |
|
|
|
#13 |
|
Senior Member
Join Date: Mar 2012
Posts: 102
Thanks: 29
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#15 |
|
Member
Join Date: Dec 2011
Posts: 43
Thanks: 8
Thanked 2 times in 2 posts
|
awesome idea - many thanks
Thomas |
|
|
|
![]() |
| Tags |
| support |
| Thread Tools | |
| Display Modes | |
|
|
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 |