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!
See more
See less

Partner 728x90

Collapse

Starting strategies at specific date and time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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"?Click image for larger version

Name:	cd289285-fd02-4ac7-a55b-f592735aec2b.jpg
Views:	1011
Size:	170.0 KB
ID:	1122488

    Code:
    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; }
    }

    #2
    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.

    Here is a detailed tutorial on C# DateTime class and how to work with dates and times using C#.

    Represents an instant in time, typically expressed as a date and time of day.


    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      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


        #4
        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.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment


          #5
          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.htm
          JimNinjaTrader Customer Service

          Comment


            #6
            Thanks, Jim. ... And the cursor change?

            Thanks.
            Multi-Dimensional Managed Trading
            jeronymite
            NinjaTrader Ecosystem Vendor - Mizpah Software

            Comment


              #7
              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


                #8
                Hi Jim,

                In the NinjaTrader.Gui.Tools.TimeEditorKey, hover over the up/down arrows. The cursor is a text entry cursor, not some form of pointer (e.g. arrow) cursor.

                Thanks.
                Multi-Dimensional Managed Trading
                jeronymite
                NinjaTrader Ecosystem Vendor - Mizpah Software

                Comment


                  #9
                  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.htm
                  Last edited by NinjaTrader_Jim; 08-24-2021, 01:14 PM.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, Jim. Much appreciated.
                    Multi-Dimensional Managed Trading
                    jeronymite
                    NinjaTrader Ecosystem Vendor - Mizpah Software

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by helpwanted, Today, 03:06 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post helpwanted  
                    Started by Brevo, Today, 01:45 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Brevo
                    by Brevo
                     
                    Started by aussugardefender, Today, 01:07 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post aussugardefender  
                    Started by pvincent, 06-23-2022, 12:53 PM
                    14 responses
                    242 views
                    0 likes
                    Last Post Nyman
                    by Nyman
                     
                    Started by TraderG23, 12-08-2023, 07:56 AM
                    9 responses
                    384 views
                    1 like
                    Last Post Gavini
                    by Gavini
                     
                    Working...
                    X