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

How to set Session Start & Session End via strategy parameters?

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

    How to set Session Start & Session End via strategy parameters?

    Hello,

    Pardon for a silly question:

    In my strategy, I need to use my custom session begin / session end, in order to get Exit On Close and Exit On Close Seconds behaviours automatically.

    How do I do that?

    I mean if I have 2 DateTime parameters SessionStart and SessionEnd set by user, what are my next steps?

    Thanks.

    #2
    Hello alex.nt,
    You can use the GetNextbeginEnd method to get the session begin and end time. Please refer to our help guide to know more


    If you want to filter trading hours to a specific time then you can refer to this sample code which demonstrates it
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Joydeep View Post
      Hello alex.nt,
      You can use the GetNextbeginEnd method to get the session begin and end time. Please refer to our help guide to know more


      If you want to filter trading hours to a specific time then you can refer to this sample code which demonstrates it
      http://ninjatrader.com/support/forum...ead.php?t=3226

      Is there a chance someone can insert that GetNextbeginEnd in the SMA indicator or any other indicator so I can see how it functions and what it prints out, I can't get it to work.

      thanks

      Comment


        #4
        Originally posted by 35trader View Post
        Is there a chance someone can insert that GetNextbeginEnd in the SMA indicator or any other indicator so I can see how it functions and what it prints out, I can't get it to work.

        thanks

        Ok got the GetNextBeginEnd to print out, but it shows 12 am to 12 am, where I thought it would have read the session period in the Data Series chosen.
        How do you get it to see the session period from the Data Series?

        Comment


          #5
          Hello 35trader,
          The GetNextBeginEnd will only return the session time of the session template. It wont return any specific time for any data series.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Joydeep View Post
            Hello 35trader,
            The GetNextBeginEnd will only return the session time of the session template. It wont return any specific time for any data series.
            In the Data series parameters, it is using a Session Template from the Session Manager. If it does not retrieve this then what good is it? you say it returns the session time of the session template, well where does one get the session time to read? it has to be hard coded into the script?

            thanks

            Comment


              #7
              Hello 35trader,
              Get GetNextBeginEnd will retrieve the begin and the end time of the session template.

              To assist you further may I know what session template you are using.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Joydeep View Post
                Hello 35trader,
                Get GetNextBeginEnd will retrieve the begin and the end time of the session template.

                To assist you further may I know what session template you are using.

                One sets the Session Template in the Session Manager, and picks the one required for the sysmbol they are charting, so if this is not the Session Template GetNextBeginEnd is looking at, then where is the Session Template it is looking at?

                For your example use:

                US Equities RTH (setup in the Session Manager) 9:30 am to 4:00 pm and picked when one wants to plot a chart.

                thanks

                Comment


                  #9
                  Hello 35trader,
                  The GetNextBeginEnd will follow the session template as defined by the primary data series.
                  Right click on the chart
                  • In the context menu click on Data Series...
                  • In the Data Series dialog set the field session template as per your desire.


                  For example if I set the session template to CME US Index Futures RTH, and use the below code then I get the print out as
                  Start Date = 07:30:00 End Date= 14:15:00
                  Code:
                  DateTime sd;
                  DateTime ed;
                  Bars.Session.GetNextBeginEnd(Bars, 0, out sd, out ed);
                  Print("Start Date = " + sd.ToString("HH:mm:ss") + " End Date= "   + ed.ToString("HH:mm:ss"));
                  My PC timezone is set at MST.
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Ok great got that functioning and that is what I expected it to do.

                    Now if one chooses a session template that is not open as of now, why in the output window does it keep updating the session data displayed? is that the clock refreshing to keep seeing if the session time has started? can one control that clock if this is the case?

                    many thanks

                    Comment


                      #11
                      Hello 35trader,
                      To assist you further may I know
                      • On what instrument you are testing the code.
                      • What session template you are using to test the code.


                      I look forward to assisting you further.
                      JoydeepNinjaTrader Customer Service

                      Comment


                        #12
                        Take any equity symbol and use regular market session, but I can't see how this has anything to do with my previous question.

                        so use SU and 9:30 to 4:00 pm and review my last question.

                        Now if one chooses a session template that is not open as of now, why in the output window does it keep updating the session data displayed? is that the clock refreshing to keep seeing if the session time has started? can one control that clock if this is the case?

                        thanks

                        Comment


                          #13
                          Hello 35trader,
                          The code is being processed in the historical bars, and not in realtime.

                          if you place the below code then can you get the prints.
                          Code:
                          protected override void OnBarUpdate()
                          {
                          	if (Historical) return;
                                  //rest of the codes
                          }
                          JoydeepNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Joydeep View Post
                            Hello 35trader,
                            The code is being processed in the historical bars, and not in realtime.

                            if you place the below code then can you get the prints.
                            Code:
                            protected override void OnBarUpdate()
                            {
                                if (Historical) return;
                                    //rest of the codes
                            }

                            I'm not really sure what your implying above.

                            What I'm saying is if one populates a chart and its prior to the session time choosen, and the following is // out:

                            //if (Bars.FirstBarOfSession)

                            then in the output window it continues to populate the session time that you have chossen, but its not open yet. So is there a internal clock continuing to look at the session time to see if its open?

                            When I remove the // from the if statemant, then it stops looking and stops re populating the session time over and over in the window.

                            So if one has 9:30 am 29 minutes from now as a session start, how does it know the session has started? when 9:30:01 arrives?

                            Comment


                              #15
                              Hello 35trader,
                              To assist you further may I know,
                              1. What code you are using
                              2. What results you are getting
                              3. What result you are expecting.


                              I look forward to assisting you further.
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Kaledus, Today, 01:29 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by PaulMohn, Today, 12:36 PM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by yertle, Yesterday, 08:38 AM
                              8 responses
                              36 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by rdtdale, Today, 01:02 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by alifarahani, Today, 09:40 AM
                              3 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X