public class Range: Strategy // Time Filter private DateTime StartDate = DateTime.Now; private DateTime EndDate = DateTime.Now; protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 80) return; if (StartDate >= Times[0][0].Date) return; if (EndDate <= Times[0][0].Date) return; #region Properties [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorTimeEditor")] [Display(Name="Start Date", Description="Decimal Ready", Order=8, GroupName="Range Settings")] public DateTime Start { get { return StartDate; } set { StartDate = value; } } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorTimeEditor")] [Display(Name="End Date", Description="Decimal Ready", Order=9, GroupName="Range Settings")] public DateTime End { get { return EndDate; } set { EndDate = value; } }
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
Starting strategies at specific date and time
Collapse
X
-
Starting strategies at specific date and time
Good evening, I try to backtest results from consolidation ranges and therefore need a start date+time for the strategy. All time filters I found only applied to excluding certain time of days. With my approach the date is correct but I'm missing time and need to add the time filter only for this day not for the following days in consolidation. How do I pull the time from the ChartAnchorTimeEditor and use it together with ">time" && ">date"?
Code:Tags: None
-
Hello MrLotuc,
Thanks for your question.
[PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")] will add a Date/Time picker in the property grid where you can use a calendar to enter a date, and you can enter a time in manually.
To use the time portion in your logic, you can use the TimeOfDay property from the DateTime object. I.E. StartDate.TimeOfDay. You can also consider setting up a time check in the Strategy Builder and using the View Code button to see the resulting syntax.
DateTime objects are general C# concepts so you may find some useful documentation on using DateTime objects with other helpful C# resources. Some publicly available resources are linked below.
C# includes DateTime struct to work with dates and times. To work with date and time in C#, create an object of the DateTime struct using the new keyword.
We look forward to assisting.JimNinjaTrader Customer Service
-
Damn, it was so simple. Thanks for you effort and time
Code:if (Time[0] < StartDate) return; if (Time[0] > EndDate) return; And changed inputs to: [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")] [Display(Name="Start Date", Description="Decimal Ready", Order=8, GroupName="Range Settings")] public DateTime StartDate { get; set; } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")] [Display(Name="End Date", Description="Decimal Ready", Order=9, GroupName="Range Settings")] public DateTime EndDate { get; set; }
Comment
-
The example of setting a Time in the Property Grid is very useful, but it does need a change in behaviour so that the cursor in the Property Editor ("NinjaTrader.Gui.Tools.TimeEditorKey") changes to an arrow rather than remaining as a text entry cursor when moving to the up/down arrows of the editor.
It would also be useful to have an option to specify 24-hour times as opposed to AM/PM times.
Thanks.
Comment
-
Hello jeronymite,
You can type directly into NinjaTrader.Gui.Tools.ChartAnchorTimeEditor and NinjaTrader.Gui.Tools.TimeEditorKey PropertyEditors. However, we cannot input times in 24hr format, regardless of Windows region settings.
We have a feature request pending for 24hr Time PropertyEditors and I have added a vote on your behalf. The ticket ID is SFT-3159. This is an internal number, but for anyone else wishing to have their interest tracked, please let our support staff know that you would like a vote added for this request.
Feature Request Disclaimer
We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing. As such we cannot offer an ETA or promise of fulfillment.
When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.
Release Notes - https://ninjatrader.com/support/help...ease_notes.htmJimNinjaTrader Customer Service
Comment
-
Hello jeronymite,
When you mean "Changes to an arrow" do you mean to get the date picker functionality that we get with NinjaTrader.Gui.Tools.ChartAnchorTimeEditor?
NinjaTrader.Gui.Tools.TimeEditorKey will have up and down arrows to increment the time on the UI control. I would say if you need the date picker functionality, to use NinjaTrader.Gui.Tools.ChartAnchorTimeEditor.
Could you clarify there? Screenshots with drawings showing a mockup of what you are looking for can help too.JimNinjaTrader Customer Service
Comment
-
Thanks jeronymite,
I have never noticed this before. I have opened an internal ticket to request changes.
Internal ticket ID is NTEIGHT-14998. The number for this ID can be found in the Release Notes page of the Help Guide when a change is made to address the matter. The Development team is currently swamped for Release 25 development tasks and this item is scheduled for action for Release 26.
Please note: We cannot offer an ETA on release schedules.
Release Notes - https://ninjatrader.com/support/help...ease_notes.htmLast edited by NinjaTrader_Jim; 08-24-2021, 01:14 PM.JimNinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by helpwanted, Today, 03:06 AM
|
0 responses
3 views
0 likes
|
Last Post
by helpwanted
Today, 03:06 AM
|
||
Started by Brevo, Today, 01:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
384 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
Comment