![]() |
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 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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]; 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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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]; Thank you. |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Not sure what you mean. Which Time, where?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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); What am I doing wrong? The data I am pulling from this study is completely wrong. |
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
GetBar() does NOT return you close prices. GetBar() returns you the bars ago index.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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];
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Not sure what you mean. Charts update whenever the bars update.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Junior Member
Join Date: Sep 2009
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Awesome!! Thanks for the replies.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |