10x
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Time[0]
Collapse
X
-
This is causing me a problem with one of my indicators. Maybe you can help me resolve this problem.
I have a indicator which I can set the pit traded hours for plotting of the data. Lets say the ES pit which begins are 09:30 est. If I put 09:30 in the start time on a 1minute chart then it gives an incorrect start time, the plotting starts one minute early, I have to put 0931 as the start time to manually create the offset. On a 5min chart I have to input 0935 as the start time... etc etc. At first I couldnt work out why, the ninja time stamping explains this. Ok, thatīs fine, understood....... but...
What do I need to do to the indicator in the code to auto allow for this "chart timeframe" offset?
At the moment to make the indicator start plotting at the correct time I have to add the number of minutes that equals the time frame of the chart...This is annoying when changing the chart time-frame numerous times daily, I have to change the indicator properties as well every time making this very cumbersome. I have other indicators (like my value area indie) which I can define the start time, and I simply put the exact time into that one, as it should be...
I assume there is some form of "time-chart timeframe offset" that can be written into the indicator?
Thanks for your help.
Comment
-
Originally posted by ScottieDog View PostThis is causing me a problem with one of my indicators. Maybe you can help me resolve this problem.
I have a indicator which I can set the pit traded hours for plotting of the data. Lets say the ES pit which begins are 09:30 est. If I put 09:30 in the start time on a 1minute chart then it gives an incorrect start time, the plotting starts one minute early, I have to put 0931 as the start time to manually create the offset. On a 5min chart I have to input 0935 as the start time... etc etc. At first I couldnt work out why, the ninja time stamping explains this. Ok, thatīs fine, understood....... but...
What do I need to do to the indicator in the code to auto allow for this "chart timeframe" offset?
At the moment to make the indicator start plotting at the correct time I have to add the number of minutes that equals the time frame of the chart...This is annoying when changing the chart time-frame numerous times daily, I have to change the indicator properties as well every time making this very cumbersome. I have other indicators (like my value area indie) which I can define the start time, and I simply put the exact time into that one, as it should be...
I assume there is some form of "time-chart timeframe offset" that can be written into the indicator?
Thanks for your help.
ref: http://www.ninjatrader.com/support/h...barsperiod.htm
Of course, you must remember that the bars period is only fixed if you are using fixed-time bars. I, for example trade off Range Bars, so would not have the problem that you describe. I used fixedperiod bars for targeting, but that is another kettle of fish.
Comment
-
Hi,
It sounds like its an easy fix, but iīve looked at the page you referenced and really have no idea what to do. Can you tell me what code I have to input, and where inside the script?
Comment
-
Originally posted by ScottieDog View PostHi,
It sounds like its an easy fix, but iīve looked at the page you referenced and really have no idea what to do. Can you tell me what code I have to input, and where inside the script?
Comment
-
Hi Koganam,
Here is the code below... Any help appreciated.
I didnīt do it myself, I paid someone to do it and this is what they made of it.. They now decline to fix it.. Maybe he doesnīt know how, heīs certainly not being very friendly about it. I mentioned to him before about the time being 1min off (or the time frame of the chart) and he said "that was normal"...
Code:{ #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 double priordayOpen = 0; private double priordayHigh = 0; private double priordayLow = 0; private double priordayClose = 0; private bool showOpen = true; private bool showHigh = true; private bool showLow = true; private bool showClose = true; #endregion int dayStart = 800; int dayEnd = 2200; int onDay = 0; /// <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, "Prior Close")); Plots[0].Pen.DashStyle = DashStyle.Dash; Plots[3].Pen.DashStyle = DashStyle.Dash; AutoScale = false; Overlay = true; // Plots the indicator on top of price } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (Bars == null) return; if (!Bars.BarsType.IsIntraday) { DrawTextFixed("error msg", "PriorDayOHLC only works on intraday intervals", TextPosition.BottomRight); return; } //if (onDay != Time[0].Day) //{ // if (currentOpen != 0) // { // priordayOpen = currentOpen; // priordayHigh = currentHigh; // priordayLow = currentLow; // priordayClose = currentClose; // if (ShowOpen) PriorOpen.Set(priordayOpen); // if (ShowHigh) PriorHigh.Set(priordayHigh); // if (ShowLow) PriorLow.Set(priordayLow); // if (ShowClose) PriorClose.Set(priordayClose); // } // onDay = Time[0].Day; //} //else //{ //} // If the current data is not the same date as the current bar then its a new session if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || 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) { priordayOpen = currentOpen; priordayHigh = currentHigh; priordayLow = currentLow; priordayClose = currentClose; if (ShowOpen) PriorOpen.Set(priordayOpen); if (ShowHigh) PriorHigh.Set(priordayHigh); if (ShowLow) PriorLow.Set(priordayLow); if (ShowClose) PriorClose.Set(priordayClose); } // Initilize the current day settings to the new days data currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; currentClose = Close[0]; currentDate = Bars.GetTradingDayFromLocal(Time[0]); } else // The current day is the same day { if (ToTime(Time[0]) == dayStart * 100) currentOpen = Open[0]; if (ToTime(Time[0]) > dayStart * 100 && ToTime(Time[0]) < dayEnd * 100) { // Set the current day OHLC values currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); currentClose = Close[0]; } if (ShowOpen) PriorOpen.Set(priordayOpen); if (ShowHigh) PriorHigh.Set(priordayHigh); if (ShowLow) PriorLow.Set(priordayLow); if (ShowClose) PriorClose.Set(priordayClose); } } #region Properties [Description("")] [Category("Parameters")] public int DayStart { get { return dayStart; } set { dayStart = Math.Max(0, value); } } [Description("")] [Category("Parameters")] public int DayStop { get { return dayEnd; } set { dayEnd = Math.Max(1, value); } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorOpen { get { return Values[0]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorHigh { get { return Values[1]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorLow { get { return Values[2]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorClose { get { return Values[3]; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show open")] public bool ShowOpen { get { return showOpen; } set { showOpen = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show high")] public bool ShowHigh { get { return showHigh; } set { showHigh = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show low")] public bool ShowLow { get { return showLow; } set { showLow = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show close")] public bool ShowClose { get { return showClose; } set { showClose = value; } } #endregion } }
Comment
-
Originally posted by ScottieDog View PostHi Koganam,
Here is the code below... Any help appreciated.
I didnīt do it myself, I paid someone to do it and this is what they made of it.. They now decline to fix it.. Maybe he doesnīt know how, heīs certainly not being very friendly about it. I mentioned to him before about the time being 1min off (or the time frame of the chart) and he said "that was normal"...
Code:{ #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 double priordayOpen = 0; private double priordayHigh = 0; private double priordayLow = 0; private double priordayClose = 0; private bool showOpen = true; private bool showHigh = true; private bool showLow = true; private bool showClose = true; #endregion int dayStart = 800; int dayEnd = 2200; int onDay = 0; /// <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, "Prior Close")); Plots[0].Pen.DashStyle = DashStyle.Dash; Plots[3].Pen.DashStyle = DashStyle.Dash; AutoScale = false; Overlay = true; // Plots the indicator on top of price } [COLOR=blue]protected override void OnStartUp()[/COLOR] [COLOR=blue] {[/COLOR] [COLOR=blue] if (BarsPeriod.Id == PeriodType.Minute || BarsPeriod.Id == PeriodType.Second) dayStart += BarsPeriod.Value;[/COLOR] [COLOR=blue] }[/COLOR] /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (Bars == null) return; if (!Bars.BarsType.IsIntraday) { DrawTextFixed("error msg", "PriorDayOHLC only works on intraday intervals", TextPosition.BottomRight); return; } //if (onDay != Time[0].Day) //{ // if (currentOpen != 0) // { // priordayOpen = currentOpen; // priordayHigh = currentHigh; // priordayLow = currentLow; // priordayClose = currentClose; // if (ShowOpen) PriorOpen.Set(priordayOpen); // if (ShowHigh) PriorHigh.Set(priordayHigh); // if (ShowLow) PriorLow.Set(priordayLow); // if (ShowClose) PriorClose.Set(priordayClose); // } // onDay = Time[0].Day; //} //else //{ //} // If the current data is not the same date as the current bar then its a new session if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || 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) { priordayOpen = currentOpen; priordayHigh = currentHigh; priordayLow = currentLow; priordayClose = currentClose; if (ShowOpen) PriorOpen.Set(priordayOpen); if (ShowHigh) PriorHigh.Set(priordayHigh); if (ShowLow) PriorLow.Set(priordayLow); if (ShowClose) PriorClose.Set(priordayClose); } // Initilize the current day settings to the new days data currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; currentClose = Close[0]; currentDate = Bars.GetTradingDayFromLocal(Time[0]); } else // The current day is the same day { if (ToTime(Time[0]) == dayStart * 100) currentOpen = Open[0]; if (ToTime(Time[0]) > dayStart * 100 && ToTime(Time[0]) < dayEnd * 100) { // Set the current day OHLC values currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); currentClose = Close[0]; } if (ShowOpen) PriorOpen.Set(priordayOpen); if (ShowHigh) PriorHigh.Set(priordayHigh); if (ShowLow) PriorLow.Set(priordayLow); if (ShowClose) PriorClose.Set(priordayClose); } } #region Properties [Description("")] [Category("Parameters")] public int DayStart { get { return dayStart; } set { dayStart = Math.Max(0, value); } } [Description("")] [Category("Parameters")] public int DayStop { get { return dayEnd; } set { dayEnd = Math.Max(1, value); } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorOpen { get { return Values[0]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorHigh { get { return Values[1]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorLow { get { return Values[2]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorClose { get { return Values[3]; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show open")] public bool ShowOpen { get { return showOpen; } set { showOpen = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show high")] public bool ShowHigh { get { return showHigh; } set { showHigh = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show low")] public bool ShowLow { get { return showLow; } set { showLow = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show close")] public bool ShowClose { get { return showClose; } set { showClose = value; } } #endregion } }
Comment
-
Thank-you so much Koganam.
That is working for CL no problem. But it wonīt work for ES on a 30min chart, it wont plot the line. When I look inside the indicator parameters it has changed the 930 that I input for "960"...... So thatīs throwing it off.
On the 6E and GC too thereīs an issue. The start time for these is 0820, it plots the line OK on a 20minute chart, but when I change to 30min chart the line disappears?
Thanks for your help so far though. That line of code certainly did the trick for the CL charts on 1, 5 and 30m timeframes.
Comment
-
Originally posted by ScottieDog View PostThank-you so much Koganam.
That is working for CL no problem. But it wonīt work for ES on a 30min chart, it wont plot the line. When I look inside the indicator parameters it has changed the 930 that I input for "960"...... So thatīs throwing it off.
On the 6E and GC too thereīs an issue. The start time for these is 0820, it plots the line OK on a 20minute chart, but when I change to 30min chart the line disappears?
Thanks for your help so far though. That line of code certainly did the trick for the CL charts on 1, 5 and 30m timeframes.
Comment
-
Originally posted by ScottieDog View PostCode:{ #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 double priordayOpen = 0; private double priordayHigh = 0; private double priordayLow = 0; private double priordayClose = 0; private bool showOpen = true; private bool showHigh = true; private bool showLow = true; private bool showClose = true; #endregion int dayStart = 800; int dayEnd = 2200; int onDay = 0; int dayStartAdjusted = 0; [FONT=Courier New][B][COLOR=blue]//Added[/COLOR][/B][/FONT] /// <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, "Prior Close")); Plots[0].Pen.DashStyle = DashStyle.Dash; Plots[3].Pen.DashStyle = DashStyle.Dash; AutoScale = false; Overlay = true; // Plots the indicator on top of price } protected override void OnStartUp() [COLOR=blue][B]//Added[/B][/COLOR] { if (BarsPeriod.Id == PeriodType.Minute || BarsPeriod.Id == PeriodType.Second) { int dsTmp = dayStart * 100; int dsTmpHrs = dsTmp / 10000; int dsTmpMins = (dsTmp - dsTmpHrs * 10000) / 100; int dsTmpSecs = dsTmp - dsTmpHrs * 10000 - dsTmpMins * 100; TimeSpan dsTimeSpan = new TimeSpan(dsTmpHrs, dsTmpMins, dsTmpSecs); TimeSpan dsAddTime = new TimeSpan(0, 0, 0); if (BarsPeriod.Id == PeriodType.Minute) dsAddTime = new TimeSpan(0, BarsPeriod.Value, 0); else if (BarsPeriod.Id == PeriodType.Second) dsAddTime = new TimeSpan(0, 0, BarsPeriod.Value); dsTimeSpan = dsTimeSpan.Add(dsAddTime); dayStartAdjusted = ToTime(Time[0].Date.Add(dsTimeSpan)); } } [COLOR=blue][B]// end Additions [/B][/COLOR] /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (Bars == null) return; if (!Bars.BarsType.IsIntraday) { DrawTextFixed("error msg", "PriorDayOHLC only works on intraday intervals", TextPosition.BottomRight); return; } //if (onDay != Time[0].Day) //{ // if (currentOpen != 0) // { // priordayOpen = currentOpen; // priordayHigh = currentHigh; // priordayLow = currentLow; // priordayClose = currentClose; // if (ShowOpen) PriorOpen.Set(priordayOpen); // if (ShowHigh) PriorHigh.Set(priordayHigh); // if (ShowLow) PriorLow.Set(priordayLow); // if (ShowClose) PriorClose.Set(priordayClose); // } // onDay = Time[0].Day; //} //else //{ //} // If the current data is not the same date as the current bar then its a new session if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || 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) { priordayOpen = currentOpen; priordayHigh = currentHigh; priordayLow = currentLow; priordayClose = currentClose; if (ShowOpen) PriorOpen.Set(priordayOpen); if (ShowHigh) PriorHigh.Set(priordayHigh); if (ShowLow) PriorLow.Set(priordayLow); if (ShowClose) PriorClose.Set(priordayClose); } // Initilize the current day settings to the new days data currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; currentClose = Close[0]; currentDate = Bars.GetTradingDayFromLocal(Time[0]); } else // The current day is the same day { [COLOR=blue][B]// [/B][/COLOR] if (ToTime(Time[0]) == dayStart * 100) currentOpen = Open[0]; [COLOR=blue][B][FONT=Courier New][FONT=Courier New]if[/FONT][/FONT][FONT=Courier New] (ToTime(Time[[/FONT][FONT=Courier New][FONT=Courier New]0[/FONT][/FONT][FONT=Courier New]]) == dayStartAdjusted) currentOpen = Open[[/FONT][FONT=Courier New][FONT=Courier New]0[/FONT][/FONT][/B][/COLOR][FONT=Courier New][COLOR=blue][B]];[/B][/COLOR][/FONT] if (ToTime(Time[0]) > dayStart * 100 && ToTime(Time[0]) < dayEnd * 100) { // Set the current day OHLC values currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); currentClose = Close[0]; } if (ShowOpen) PriorOpen.Set(priordayOpen); if (ShowHigh) PriorHigh.Set(priordayHigh); if (ShowLow) PriorLow.Set(priordayLow); if (ShowClose) PriorClose.Set(priordayClose); } } #region Properties [Description("")] [Category("Parameters")] public int DayStart { get { return dayStart; } set { dayStart = Math.Max(0, value); } } [Description("")] [Category("Parameters")] public int DayStop { get { return dayEnd; } set { dayEnd = Math.Max(1, value); } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorOpen { get { return Values[0]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorHigh { get { return Values[1]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorLow { get { return Values[2]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries PriorClose { get { return Values[3]; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show open")] public bool ShowOpen { get { return showOpen; } set { showOpen = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show high")] public bool ShowHigh { get { return showHigh; } set { showHigh = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show low")] public bool ShowLow { get { return showLow; } set { showLow = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show close")] public bool ShowClose { get { return showClose; } set { showClose = value; } } #endregion } }
Comment
-
Thanks again Koganam, itīs good of you to spend the time helping on this.
Unfortuantely I am getting an error when compiling with those last code additions... its throwing an "expected error" regarding line 78, which is this line...
Code:if (BarsPeriod.Id == PeriodType.Second) dsAddTime = new TimeSpan(0, 0, BarsPeriod.Value);
I really thank you for the effort you are putting in - I donīt want to get you into anything time consuming, I realize these things can be a pain.
Comment
-
Originally posted by ScottieDog View PostThanks again Koganam, itīs good of you to spend the time helping on this.
Unfortuantely I am getting an error when compiling with those last code additions... its throwing an "expected error" regarding line 78, which is this line...
Code:if (BarsPeriod.Id == PeriodType.Second) dsAddTime = new TimeSpan(0, 0, BarsPeriod.Value);
I really thank you for the effort you are putting in - I donīt want to get you into anything time consuming, I realize these things can be a pain.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Aviram Y, Today, 05:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by Aviram Y
Today, 05:29 AM
|
||
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
217 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
Comment