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 09-28-2009, 09:41 PM   #1
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default Reference Daily Close prices on Minute chart

I need to reference Daily Closing prices over the past 4 days to produce a study displayed on the minute chart. I am having a hard time finding this referenced in documentation.

oldseller1848 is offline  
Reply With Quote
Old 09-29-2009, 07:32 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

PriorDayOHLC().PriorClose[0] will give you yesterday's close.

Then you want to use GetBar() to get a bar index of any bar in yesterday to get the prior day's close from yesterday.

Untested code.
Code:
int barsAgo = GetBar(Time[0].AddDays(-1));
dayBeforeYesterdayClose = PriorDayOHLC().PriorClose[barsAgo];
Then you can just keep going back like this to get all 4 days.

You may need some fancier logic on the .AddDays(-1) to accommodate for weekends. You could run some DayOfWeek check. If it is Monday, subtract 3 days to get Friday.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-29-2009, 08:12 AM   #3
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you for the reply. Much closer now. I have the code:

Code:
int barsAgo = GetBar(Time[0].AddDays(0));
double Close0 = PriorDayOHLC().PriorClose[barsAgo];
barsAgo = GetBar(Time[0].AddDays(-1));
double Close1 = PriorDayOHLC().PriorClose[barsAgo];
barsAgo = GetBar(Time[0].AddDays(-2));
double Close2 = PriorDayOHLC().PriorClose[barsAgo];
barsAgo = GetBar(Time[0].AddDays(-3));
double Close3 = PriorDayOHLC().PriorClose[barsAgo];
The vehicle I am using to trade is forex. How can I change the Time from Midnight to 5pm?

Thank you.
oldseller1848 is offline  
Reply With Quote
Old 09-29-2009, 08:54 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Not sure what you mean. Which Time, where?
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-29-2009, 10:03 AM   #5
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Because the Forex trades 24x5, I need closing prices as of the end of the trading day for Forex (which is 5pm). I found something similar, but this is not working either:
Code:
timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 17, 00, 0);
double Close0 = GetBar(timeOfInterest);
timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 1, 17, 00, 0);
double Close1 = GetBar(timeOfInterest);
timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 2, 17, 00, 0);
double Close2 = GetBar(timeOfInterest);

Got this from another post: http://www.ninjatrader-support2.com/...ad.php?t=19176

What am I doing wrong? The data I am pulling from this study is completely wrong.
oldseller1848 is offline  
Reply With Quote
Old 09-29-2009, 10:11 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

GetBar() does NOT return you close prices. GetBar() returns you the bars ago index.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-29-2009, 11:13 AM   #7
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Is there an idiot guide for this? Obviously, I am not getting it.

The original suggested method provided End of Date (11:59pm) prices, where I need 4:59pm or would settle for 5pm prices: Because the Forex trades 24x5, I need closing prices as of the end of the trading day for Forex (which is 5pm). I don't understand why this is difficult for me. Am I the only person who refers to End of Trading day activity for Close prices?
oldseller1848 is offline  
Reply With Quote
Old 09-29-2009, 11:33 AM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

DateTime someTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 17, 00, 00);
barsAgo = GetBar(someTime.AddDays(-1));
double prevClose = PriorDayOHLC().PriorClose[barsAgo];
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-29-2009, 02:59 PM   #9
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Awesome. Now we are grabbing the proper close prices. Now, the problem is the study does not update the graph until 0:00am. I need the chart to update on the close of the trading day.
oldseller1848 is offline  
Reply With Quote
Old 09-29-2009, 03:04 PM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Not sure what you mean. Charts update whenever the bars update.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-29-2009, 04:13 PM   #11
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Please see the study only updates at 0:00 and not at 17:00, when the data is collected as the close. I need the study to adjust at 17:00 when the close is updated.
oldseller1848 is offline  
Reply With Quote
Old 09-30-2009, 04:55 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

The study would 'update' as a new OnBarUpdate() call is processed, this would mean a new bar is closed (with CalculateOnBarClose to 'true') - if you need this update intrabar, try setting the CalculateOnBarClose to false.

http://www.ninjatrader-support.com/H...BarClose1.html
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 09-30-2009, 08:15 PM   #13
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

The problem is the command -1 days is subtracting a calendar day. As soon as the Calendar day is changed on my EST TimeZone, the GetBar command will only then grab the requested Bar.

DateTime someTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 17, 00, 00);
barsAgo = GetBar(someTime.AddDays(-1));
double prevClose = PriorDayOHLC().PriorClose[barsAgo];

I am EST Time Zone and using this command will not work. I need to gather the closing price of the USDJPY at 17:00 EST (or 0:00 London Time) for the last 4 days. At 17:01, my strategy needs to be using the correct closing prices.

How can I get this information?

Can I do a statement?
if DateTime.Now.Hour = 17 then price = close[0]. I would just need to use the dataseries for the strategy.
oldseller1848 is offline  
Reply With Quote
Old 10-01-2009, 06:59 AM   #14
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

Ok, then either store the value as it occurs or convert all times used to the Universal Time format in .NET - http://msdn.microsoft.com/en-us/libr...ersaltime.aspx
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 10-01-2009, 07:06 AM   #15
oldseller1848
Junior Member
 
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Awesome!! Thanks for the replies.
oldseller1848 is offline  
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
Question about 1440 minute chart work around for daily chart erikp Charting 2 06-30-2009 07:46 AM
Daily prices 1 day late? cunparis Strategy Analyzer 5 06-23-2009 07:28 AM
daily close prices are not correct when using IB as datafeed clearpicks Charting 7 03-11-2009 01:11 PM
Minute and Daily Historical Data. Scooter1 Charting 1 12-15-2008 08:00 AM
Conversion of minute charts to daily linwj Charting 6 11-12-2008 08:11 AM


All times are GMT -6. The time now is 06:21 PM.