Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable Time

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

    Variable Time

    Hello,

    I would like to draw a line at the open price of a bar at a certain time.
    I would like to give the possibility to the user, to define this time.

    How may I declare a certain hour as a variable ?

    Any idea ?

    Thank you very much for your help.
    Jed

    #2
    You would need to create DateTime variables. It will be just like any other parameter creation, but instead of int or double you create it as DateTime.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank You very much Josh !
      J.

      Comment


        #4
        And, how is the format ?

        How should I declare it to give the user the possibility to define the time ?

        Like that ? :
        Code:
        private DateTime MyTime = 02:00;
        Thank you for your help.
        J.

        Comment


          #5
          private DateTime myTime = new DateTime(09,30,00);

          There are several signatures available. Please use the IntelliSense to find one suitable for your needs.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Hum...

            Apparently, DateTime(09,10,10) is year month day ....
            I would like hour min, like 2h15...
            How can I format that please ?
            Also, it does not appear as a parameter the user can change when applying the indicator on the chart... How to do that ?
            Any idea ?

            Thank you for your help.
            J.

            Comment


              #7
              Use this signature: new DateTime(int year, int month, int day, int hour, int minute, int second)

              Alternatively, you may want to just use TimeSpan instead if you don't care for the date at all. Same idea. new TimeSpan(...)

              You need to create it as a parameter. Please see any of the pre-installed indicators on how to create parameters. Open up the SMA and take a look how its done in the Properties region of the code. The only difference is you are going to use DateTime instead of int.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Like This ? :

                Code:
                        #region Variables
                        
                        private TimeSpan OpenTime = new TimeSpan(09,10,10);
                        
                        #endregion
                Does not seems to work....

                Comment


                  #9
                  What does not work? Please post error messages.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Josh,
                    Nothing appear as a parameter so, the user can't change the time, in general section, when applying the indicator on the chart..

                    Sorry for not being more clear....
                    Thank you for your help
                    J.

                    Comment


                      #11
                      Right jed77. Because you need to create it as a parameter before it will show up. Please open up the SMA indicator and take a look at how its done in the Properties region of the code. All you need to do is mimic that, but change the type from int to TimeSpan or DateTime.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you very much Josh, it is working very well !

                        Now, I want to draw a line at the open price of the bar at my variable "opentime"

                        How do I write that ?
                        Code:
                        if (opentime = opentime)
                                    {
                                        DrawLine("My line" + CurrentBar, 0, 0, 0, 0, Color.Blue);
                                    }
                        Last edited by jed77; 12-01-2008, 05:53 PM.

                        Comment


                          #13
                          jed77,

                          Don't know if this helps but here is how I mark the open on my 5 Min chart by drawing a Ray. You can substitute Line or Horizontal Line. The Time is 24 hour Time (HHMMSS). So 1:30 PM would 133000. Short, sweet, simple.

                          #region Variables
                          private int drawTime= 93500; // Default setting for Time to Draw Ray
                          #endregion

                          protected override void OnBarUpdate()
                          {

                          if (ToTime(Time[0]) == 93500 )
                          DrawRay("930Open", false, 1, Close[1], 0, Close[1], Color.Black, DashStyle.Dash, 3) ;

                          }

                          #region Properties
                          [Description("")]
                          [Category("Parameters")]
                          public int DrawTime
                          {
                          get { return drawTime; }
                          set { drawTime= Math.Max(1, value); }
                          }
                          #endregion

                          Comment


                            #14
                            jed77,

                            You will need to go to google or MSDN to figure out how to work with TimeSpan objects. This is C# and not NinjaScript. We just don't have enough bandwidth to cover everything about it here. Thank you for understanding.

                            TAJTrades' idea works too. Just use ints for simplicity.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you Josh, I understand, no problem !

                              TAJTrades, thank you too, I'll have a look at your code !

                              All the best.

                              J.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              566 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              330 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              547 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              548 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X