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

set begin and end time for indicator

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

    set begin and end time for indicator

    Hi,

    I'm trying to set begin and end time for an indicator.

    In fibonacci retracement under DATA you can set Start and End time.
    I want to be able to do the same with the VWMA or any other indicator.

    I tried GETNEXTBEGINEND http://ninjatrader.com/support/helpG...xtbeginend.htm

    I followed the exemple
    private DateTime sessionBegin;
    private DateTime sessionEnd;

    protected override void OnBarUpdate()
    {
    // On the start of a new session, get the next begin or end session time and its corresponding paired session begin/end time.
    if (Bars.FirstBarOfSession)
    Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);

    Print("Session Start: " + sessionBegin + " Session End: " + sessionEnd);
    }




    It compile but i dont see where in the indicator i can set start and end time.


    Any idea why?


    Frank
    thank you

    #2
    Hello frankduc,

    Thank you for writing in.

    You will need to create custom properties in order to set a begin and end time. Properties are used to let the user specify custom parameters for use in the script.

    Here is a simple example:

    Code:
    private DateTime startDay;
    private DateTime endDay;
    
    private TimeSpan startTime;
    private TimeSpan endTime;
    
    protected override void OnBarUpdate()
    {
         // check to see if the current date and time the indicator is evaluating is more than or equal to the start and less than or equal to the end
         if (Time[0].Date >= startDay && Time[0].TimeOfDay >= startTime && Time[0].Date <= endDay && Time[0].TimeOfDay <= endTime)
              // do something
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public TimeSpan StartTime
    {
        get { return startTime; }
        set { startTime = value; }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public TimeSpan EndTime
    {
        get { return endTime; }
        set { endTime = value; }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public DateTime EndDay
    {
        get { return endDay; }
        set { endDay = value; }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public DateTime StartDay
    {
        get { return startDay; }
        set { startDay = value; }
    }
    You can then specify a start time and end time when adding the indicator to a chart.

    Please, let us know if we may be of further assistance.
    Last edited by NinjaTrader_ZacharyG; 08-30-2016, 11:27 AM.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      parameters period

      There is more programming to do than i thought.

      NT should have precoded that feature inside the parameters period instead.

      Would of been more simple to code.

      Without the manipulation of time and date in the chart i cant manipulate data and program my formulas and that's the most complicated part.

      Need to do some reading.

      Frank
      ty

      Comment


        #4
        Hello frankduc,

        The Period property is a custom property that is used by many of the default scripts.

        If you take a look at the SMA indicator, for example, you'll see that a custom property called Period was created for use with the indicator. This is an int property and you wouldn't be able to pass a date or time to this.

        If you wish for your script to accept date and time parameters, you need to create the properties that accept those parameters.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          "you'll see that a custom property called Period was created for use with the indicator. This is an int property and you wouldn't be able to pass a date or time to this."

          You are refering to that part of the code?:

          #region Variables
          private int period = 14;
          #endregion

          But i can pass a date and time if i refer to your exemple , otherwise how will i be able to manipulate period bars inside the chart to plug formulas?:

          private DateTime startDay; private DateTime endDay; private TimeSpan startTime; private TimeSpan endTime;


          The way i see it i must input the SMA or any indicators into the [Description("")]
          Or maybe i just go it all wrong.

          Comment


            #6
            Hello frankduc,

            That is not a property. That is a variable.

            The Period property is in the Properties region in the code (line 63 for the SMA).

            Originally posted by frankduc View Post
            NT should have precoded that feature inside the parameters period instead.
            The Period property you are referring to is of type int and you would not be able to pass DateTime or TimeSpan objects to this.

            I would highly suggest taking a look at this link for more information about properties in C#: https://msdn.microsoft.com/en-us/library/w86s7x04.aspx

            The example I have provided in my previous post shows how you can create properties to pass user defined dates and times to your indicator to specify a start and end date and time.

            Originally posted by NinjaTrader_ZacharyG View Post
            Code:
            private DateTime startDay;
            private DateTime endDay;
            
            private TimeSpan startTime;
            private TimeSpan endTime;
            
            protected override void OnBarUpdate()
            {
                 // check to see if the current date and time the indicator is evaluating is more than or equal to the start and less than or equal to the end
                 if (Time[0].Date >= startDay && Time[0].TimeOfDay >= startTime && Time[0].Date <= endDay && Time[0].TimeOfDay <= endTime)
                      // do something
            }
            
            [Description("")]
            [GridCategory("Parameters")]
            public TimeSpan StartTime
            {
                get { return startTime; }
                set { startTime = value; }
            }
            
            [Description("")]
            [GridCategory("Parameters")]
            public TimeSpan EndTime
            {
                get { return endTime; }
                set { endTime = value; }
            }
            
            [Description("")]
            [GridCategory("Parameters")]
            public DateTime EndDay
            {
                get { return endDay; }
                set { endDay = value; }
            }
            
            [Description("")]
            [GridCategory("Parameters")]
            public DateTime StartDay
            {
                get { return startDay; }
                set { startDay = value; }
            }
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              I will read in details that msdn link.

              Thank you for your time.

              Comment


                #8
                Hi

                Adding to the above example, I'd like to get the low value from the startTime to a minute later then draw a line from 60 minutes before the startTime to an endTime then remove the line when the endTime is reached. How may I do this?

                Have tried the following without luck:

                TimeSpan minuteTime = startTime + TimeSpan.FromMinutes(1);

                if (Time[0].TimeOfDay >=minuteTime)
                {
                DrawLine("Line1", true, DateTime.Now.Subtract(TimeSpan.FromMinutes(60)), Low[0], DateTime.Now.Add(EndTime-StartTime), Low[0], Color.Yellow, DashStyle.Dash, 2);
                }

                if (Time[0].TimeOfDay >=endTime)
                {
                RemoveDrawObject("Line1");
                }

                Thanks

                Comment


                  #9
                  Originally posted by Slide588 View Post
                  Hi

                  Adding to the above example, I'd like to get the low value from the startTime to a minute later then draw a line from 60 minutes before the startTime to an endTime then remove the line when the endTime is reached. How may I do this?

                  Have tried the following without luck:

                  TimeSpan minuteTime = startTime + TimeSpan.FromMinutes(1);

                  if (Time[0].TimeOfDay >=minuteTime)
                  {
                  DrawLine("Line1", true, DateTime.Now.Subtract(TimeSpan.FromMinutes(60)), Low[0], DateTime.Now.Add(EndTime-StartTime), Low[0], Color.Yellow, DashStyle.Dash, 2);
                  }

                  if (Time[0].TimeOfDay >=endTime)
                  {
                  RemoveDrawObject("Line1");
                  }

                  Thanks
                  check out this open range indicator

                  Comment


                    #10
                    That;s awesome Nkhoi, thanks! Is there a NT8 version?

                    Comment


                      #11
                      Originally posted by Slide588 View Post
                      That;s awesome Nkhoi, thanks! Is there a NT8 version?
                      I ran NT8 conversion on this indicator awhile ago.
                      Attached Files

                      Comment


                        #12
                        Much appreciated, thanks for your help.

                        Comment


                          #13
                          HI

                          I'd like to update this indicator so that it identifies the master instrument and adds time to the Begin and End Time offset from the start of the gold open i.e. I don't want to have to change the BeginTime and EndTime values when looking at a different instrument on the same chart. I've added code to Initialise() for CL which opens 40 minutes after GC. The code compiles but doesn't work. Could you please have a look and let me know how to update.

                          Thanks.
                          Attached Files

                          Comment


                            #14
                            Okay, so the code I added to Initialise() was basically:

                            if (Instrument.MasterInstrument.Name=="CL")
                            {
                            }

                            I want to identify when I'm trading GC, ES or CL and be able to update the opening times. Could you please let me know if this is the correct way to do it.

                            Comment


                              #15
                              Originally posted by Slide588 View Post
                              Okay, so the code I added to Initialise() was basically:

                              if (Instrument.MasterInstrument.Name=="CL")
                              {
                              }

                              I want to identify when I'm trading GC, ES or CL and be able to update the opening times. Could you please let me know if this is the correct way to do it.
                              lots of coding if you don't want to hard code time of each instrument
                              check out how Fattails handle the time problem
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post TraderBCL  
                              Started by martin70, 03-24-2023, 04:58 AM
                              14 responses
                              106 views
                              0 likes
                              Last Post martin70  
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              609 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              471 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Working...
                              X