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

Date time as input variables

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

    Date time as input variables

    If I want to use a date and a time as an input variable, under what 'class' do I declare them, and in what format do I input them?
    Thx.

    #2
    Hawk Arps,

    I am happy to assist you.

    DateTime is the class for dates.

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


    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Hawk Arps View Post
      If I want to use a date and a time as an input variable, under what 'class' do I declare them, and in what format do I input them?
      Thx.
      "Date" is a DateTime variable.
      If by "time", you mean a time of day, sans the date, that will be a TimeSpan variable.
      Last edited by koganam; 01-08-2012, 06:41 PM.

      Comment


        #4
        Does this mean that if I want to declare a date and a time input variable and default them to 6:30 AM Sept. 1, 2011 I would use the following code?
        (within Variables)
        new DateTime StartDate=2011,09,01;
        new DateTime StartTime=06:30:00;

        Comment


          #5
          Originally posted by Hawk Arps View Post
          Does this mean that if I want to declare a date and a time input variable and default them to 6:30 AM Sept. 1, 2011 I would use the following code?
          (within Variables)
          new DateTime StartDate=2011,09,01;
          new DateTime StartTime=06:30:00;
          No. StartTime, as you have declared it, should be a TimeSpan variable.

          It should be properly declared as:

          Code:
          TimeSpan StartTime = new TimeSpan(6, 30, 00);
          Of course, you can always make a blank declaration, then assign it later.
          Last edited by koganam; 01-10-2012, 01:33 AM.

          Comment


            #6
            Thank you for your help... But I'm still pretty confused on how to declare a date (ie: Sept,1,2011) as an input and how to compare the current bar date to that date in the code. Everything I'm trying is getting compiler error code CS0120. Obviously I'm still pretty low on the learning curve...

            Comment


              #7
              Hawk Arps,

              Please find attached an indicator that uses datetime as input.

              Please let me know if I may assist further.
              Attached Files
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Thank you...the code helped; however, I could not get the indicator to plot any lines.

                Comment


                  #9
                  Did you enter appropriate dates / times for the chart you're running on? Any errors in your log tab as you run the code posted?

                  Thanks,
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Would that code work better for you?

                    Thanks,
                    Attached Files
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      I see... this indicator only works in real time. If I want to mark past times I assume I would change the DateTime.Now in the code DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day..... to Time[0].Date

                      Again thanks for the help. I'm slowly getting it (I think).

                      Comment


                        #12
                        Excellent!

                        Correct.

                        -Brett

                        Comment


                          #13
                          Hello NT,

                          I'm resurrecting this really old thread because it is somewhat close to what I'm trying to do. Hawk Arps was trying to mark out past dates. Bertrand gave him an indicator called DatetimeVerticalLines.cs. Hawk Arps was able to catch on how to mark past dates, but I'm still lost. Here is where the thread left off:

                          I see... this indicator only works in real time. If I want to mark past times I assume I would change the DateTime.Now in the code DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day..... to Time[0].Date

                          Again thanks for the help. I'm slowly getting it (I think).
                          I would appreciate if anyone can show me how to put the vertical line on a past date, for example, July 19, 2017.

                          Thanks
                          Gennaker

                          Comment


                            #14
                            Hello Gennaker,

                            Thank you for the follow up.

                            You may use this constructor to specify a date to draw a line:

                            DrawVerticalLine(string tag, DateTime time, Color color, DashStyle dashStyle, int width)[/CODE]

                            Exemplar:

                            Code:
                            DrawVerticalLine("My Line", new DateTime(2017, 7, 19, 12, 0, 0), Color.Red, DashStyle.Solid, 2);
                            This will Draw a vertical line on July 19th 2017 at 12PM.

                            More on DrawVerticalLine() here:


                            Please let us know if we may be of any further assistance.
                            Chris L.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            168 responses
                            2,262 views
                            0 likes
                            Last Post sidlercom80  
                            Started by Barry Milan, Yesterday, 10:35 PM
                            3 responses
                            10 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by WeyldFalcon, 12-10-2020, 06:48 PM
                            14 responses
                            1,429 views
                            0 likes
                            Last Post Handclap0241  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            41 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X