![]() |
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 |
|
Senior Member
|
I am programming (for NT 6.5) a 1-min bar NinjaScript strategy for an instrument that is quite likely to have less than 1 tick per minute during the time period of interest.
Say that in a 10-minute period there a three 1-min periods in which no tick occurs. In relation to the above situation, if I reference Close[10] in my code will this refer to the close of the bar approx 10 minutes ago, or to the close of the bar approx 13 minutes ago (as there were three 1-min bars that had no OHLC, since no ticks occurred during the minute)? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
|
AnotherTrader, NinjaTrader is event not time based, as such if there's no bar there's no Close price for you to 'grab' at that point - it would give you the close price of the bar 13 mins ago then.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
|
OK, thanks.
So, when needing to know how many bars ago correspond with a particular point in time (e.g. say it’s now 13h00 EST, and I want know which bar corresponds to the bar which closed at 12h00 EST), it is not enough to make use of say Close[59] for the closing price of that bar; I guess I’ll need to do something like start a counter at 12h00 EST that updates on each OnBarUpdate, and then use Close[counter] for the bar that closed at 12h00 EST. Is that what you would recommend? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
|
You can use the GetBar() method for this task -
http://www.ninjatrader-support.com/H...V6/GetBar.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
|
OK, thanks.
If the timestamp specifies a time after the first bar and before the last bar, but refers to a time at which no bar exists (for the reason previous, i.e. there were no ticks during that timeframe) what does GetBar() return? |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
|
It would then return the next bar satisfying it - for example I try getting todays 9:02 bar which would not exist in cash session on ES running on EST - so GetBar() returns then the 9:35 bar (on 5 min chart).
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
|
Quote:
The above link references the following example: Code:
// Check that its past 9:45 AM
if (ToTime(Time[0]) >= ToTime(9, 45, 00))
{
// Calculate the bars ago value for the 9 AM bar for the current day
int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0));
// Print out the 9 AM bar closing price
Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
Thanks. |
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
|
You would for example use DateTime.Today.AddDays(-1) for yesterdays date, but you would need to introduce custom logic to cover weekends here.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
|
How is DateTime.Today.AddDays(-1) inserted into the following in the simplest case (ie ignoring weekends and holidays)?
Code:
// Check that its past 9:45 AM
if (ToTime(Time[0]) >= ToTime(9, 45, 00))
{
// Calculate the bars ago value for the 9 AM bar for the current day
int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0));
// Print out the 9 AM bar closing price
Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bars.GetDayBar(1).Time returning null | drolles | General Programming | 9 | 01-18-2011 02:42 AM |
| Plots and Null Value | TAJTrades | General Programming | 2 | 05-12-2009 05:28 AM |
| Bars == NULL | oferr | Strategy Analyzer | 4 | 01-31-2008 07:57 AM |
| Testing for null | zoltran | General Programming | 7 | 11-25-2007 05:09 PM |
| Determining if an indicator value is null | newguy | Indicator Development | 4 | 10-16-2007 04:16 PM |