View Full Version : PriorDayOHLC Problem
PrTester
07-15-2007, 04:27 PM
Hi,
I'm trying to use the Prior Day High, Low, & Close to make some math. The method I use is:
PriorDayOHLC().currentHigh[0]
PriorDayOHLC().currentLow[0]
PriorDayOHLC().currentClose[0]
and PriorDayOHLC().currentOpen[0] but when i try to compile the following message appears:
'NinjaTrader.Indicator.PriorDayOHLC.currentHigh' is inaccessible due to its protection level
'NinjaTrader.Indicator.PriorDayOHLC.currentLow' is inaccessible due to its protection level
'NinjaTrader.Indicator.PriorDayOHLC.currentClose' is inaccessible due to its protection level
'NinjaTrader.Indicator.PriorDayOHLC.currentOpen' is inaccessible due to its protection level
any idea?
Thanks
NinjaTrader_Josh
07-15-2007, 04:36 PM
If you are trying to get the previous day's OHLC you should use PriorDayOHLC().PriorHigh[0], PriorDayOHLC().PriorLow[0], etc.
For current day OHL you can use CurrentDayOHL().CurrentLow[0] etc.
PrTester
07-15-2007, 08:31 PM
Solved,
Thanks
NinjaTrader_Josh
07-16-2007, 02:28 PM
I just noticed something interesting with the behavior of PriorDayOHLC().PriorHigh[0] etc. During real-time the PriorDayOHLC updates per tick and after the first tick of the day the values seem to revert to the values of the day prior to the previous day. That's a bit confusing so here is my Output Window entries. This is on a daily chart.
7/13/2007 12:00:00 AM
134.4 <-prior high
128.8 <-prior low
7/16/2007 12:00:00 AM <-first tick of day
133.7
131.31
7/16/2007 12:00:00 AM <-subsequent ticks
134.4
128.8
As you can see the value on the first tick of the day was correct, but as it comes back to the OnBarUpdate() it reverts back to the value of 7/13 which is the high/low of 7/12 despite the date being 7/16.
NinjaTrader_Christian
07-17-2007, 05:50 AM
Hi,
i tried to reproduce the behaviour you got, but didn't succeed. Can you please tell me, which exact steps you take, to get this ? Do you use some custom indicator to reproduce that ?
If yes, please send it to:
christian AT ninjatrader DOT com
Thank you,
Christian
NinjaTrader_Josh
07-17-2007, 10:16 AM
Yes Christian I am using a custom indicator. This is basically all I do in my code to reproduce the error.
Print(Time[0].Date.ToString());
Print(PriorDayOHLC().PriorHigh[0]);
Print(PriorDayOHLC().PriorLow[0]);
prevhigh.Set(PriorDayOHLC().PriorHigh[0]);
prevlow.Set(PriorDayOHLC().PriorLow[0]);
Please note that if I did not do the *.Set on my two plots the PriorDayOHLC() remains correct on incoming ticks.
If my code was Print(Time[0].Date.ToString());
Print(PriorDayOHLC().PriorHigh[0]);
Print(PriorDayOHLC().PriorLow[0]);
This would be my output. 7/16/2007 12:00:00 AM
137.85
134.07
7/17/2007 12:00:00 AM
139.96
137.5
7/17/2007 12:00:00 AM
139.96
137.5 Otherwise the output would be 7/16/2007 12:00:00 AM
137.85
134.07
7/17/2007 12:00:00 AM
139.96
137.5
7/17/2007 12:00:00 AM
137.85
134.07
Let me know if you still need my custom indicator. I am not on my main computer at the moment and don't have access to it.
NinjaTrader_Ray
07-18-2007, 08:59 AM
The PriorDayOHLC should only be used on intraday intevals. We will make a change in NT 6.5 to reflect this.
If you programmatically want to access prior session OHLCV values, please use GetSessionBar().
http://www.ninjatrader-support.com/HelpGuideV6/GetSessionBar.html
There is a known issue with GetSessionBar() that will be resolved in NT 6.0.1000.4.
For plotting prior day OHLC values on a chart, use a 1 period SMA and displace it by a value of 1.
mwyatt
09-13-2007, 11:13 AM
Hacked this together to use 09:30 - 16:15 for the indicator lines (which means will draw the lines on a 24 hour chart, but the lines are based on cash market hours), may run a bit slow, but seems functional. Basically a mod of the current OHLC.
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private DateTime currentDate = Cbi.Globals.MinDate;
private double currentOpen = 0;
private double currentHigh = 0;
private double currentLow = 0;
private double currentClose = 0;
private bool beenHere = false;
private double tempHigh = 0;
private double tempLow = 0;
private bool showOpen = true;
private bool showHigh = true;
private bool showLow = true;
private bool showClose = true;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Hash, "Prior Open"));
Add(new Plot(Color.Green, PlotStyle.Hash, "Prior High"));
Add(new Plot(Color.Red, PlotStyle.Hash, "Prior Low"));
Add(new Plot(Color.Firebrick, PlotStyle.Hash, "GAP"));
Plots[0].Pen.DashStyle = DashStyle.Dash;
Plots[3].Pen.DashStyle = DashStyle.Dash;
AutoScale = false;
CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
Overlay = true; // Plots the indicator on top of price
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
DateTime candleDayClose = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 15, 0, 0);
DateTime yesterdayClose = candleDayClose.AddDays(-1);
int barsAgo = CurrentBar - Bars.GetBar(yesterdayClose);
currentClose = Close[barsAgo];
if (ShowClose) PriorClose.Set(currentClose);
DateTime candleDayOpen = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0, 0);
DateTime yesterdayOpen = candleDayOpen.AddDays(-1);
int barsAgo2 = CurrentBar - Bars.GetBar(yesterdayOpen);
currentOpen = Close[barsAgo2];
if (ShowClose) PriorOpen.Set(currentOpen);
// If the current data is not the same date as the current bar then its a new day
if ( (currentDate != Time[0].AddSeconds(-1).Date || currentOpen == 0))
{
// The current day OHLC values are now the prior days value so set
// them to their respect indicator series for plotting
if (currentOpen != 0)
{
// if (ShowOpen) PriorOpen.Set(currentOpen);
if (ShowHigh) PriorHigh.Set(currentHigh);
if (ShowLow) PriorLow.Set(currentLow);
// if (ShowClose) PriorClose.Set(currentClose);
}
// Initilize the current day settings to the new days data
// currentOpen = Open[0];
currentHigh = High[0];
currentLow = Low[0];
// currentClose = Close[0];
currentDate = Time[0].AddSeconds(-1).Date;
} else {
// Set the prior days values to the prior day so we get a straight line
if (PriorOpen.Count > 1)
{
// if (ShowOpen) PriorOpen.Set(PriorOpen[1]);
if (ShowHigh) PriorHigh.Set(PriorHigh[1]);
if (ShowLow) PriorLow.Set(PriorLow[1]);
// if (ShowClose) PriorClose.Set(PriorClose[1]);
}
}
if(candleDayOpen < Time[0] && Time[0] < candleDayClose)// The current day is the same day within cash hours
{
// Set the current day OHLC values
currentHigh = Math.Max(currentHigh, High[0]);
currentLow = Math.Min(currentLow, Low[0]);
//currentClose = Close[0];
}
}
bobby1001
10-16-2007, 10:52 AM
Can you send me the file? I can't seem to get this to work for me.
Thanks,
Bobby
everington_f
08-03-2011, 05:39 AM
Following on from this how can NT plot on the current daily chart the:
PriorWeekOHLC ?
PriorMonthOHLC ?
Also the OHLC of n days ago. ?
Daily Pivots from N days ago ?
Regards and thx for any input guys.
NinjaTrader_Brett
08-03-2011, 06:31 AM
Hello,
Thanks for the note.
We do not have indicator build into NinjaTrader to do this automatically.
This would need to be custom coded.
You would need to use High[0] and then take the number of bars back you want to check agianst. Then output the Highest value of the High's as your current week OHLC and previous.
You can also use the High[9] Low[9] Close[9] and Open[9] to plot the OHLC of 9 bars back, replace the 9 with the number of days back you want to plot.
Then for the pivots this would need to be manually calculated. Our pivots only work on intraday charts and not on daily chart.
If your not a programmer let me know and I can assist with finding a NinjaScript consultant.
Let me know if I can be of further assistance.
everington_f
08-03-2011, 07:20 AM
Thankyou for the reply. I will code this myself.
Harry
08-05-2011, 02:41 AM
You can use the SessionPivots indicators here:
http://www.ninjatrader.com/support/forum/local_links_search.php?action=show&s=&literal=1&search=SessionPivots&desc=1&keys=1&ents=1
Prior week, month HLC is included and shown with the weekly and monthly pivot indicators. If you look for a n-day rolling pivots indicator, you can find it here.
http://www.bigmiketrading.com/free_downloads/ninjatrader-7/indicators/714-download.html?view
everington_f
08-05-2011, 03:22 AM
You can use the SessionPivots indicators here:
http://www.ninjatrader.com/support/forum/local_links_search.php?action=show&s=&literal=1&search=SessionPivots&desc=1&keys=1&ents=1
Prior week, month HLC is included and shown with the weekly and monthly pivot indicators. If you look for a n-day rolling pivots indicator, you can find it here.
http://www.bigmiketrading.com/free_downloads/ninjatrader-7/indicators/714-download.html?view
Thanks Harry. I notice that the indicator looks at the current week, and current month OHL , I dont think it plots the priorMonth OHLC and PriorWeek OHLC or perhaps I am missing something,
Regards and thanks
Harry
08-05-2011, 03:43 AM
Thanks Harry. I notice that the indicator looks at the current week, and current month OHL , I dont think it plots the priorMonth OHLC and PriorWeek OHLC or perhaps I am missing something,
Regards and thanks
There are six indicators included. The pivots - not the OHL indicators - show the prior month HLC, but not the open of the prior month.