Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

LastBarOfSession

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

    LastBarOfSession

    I'd like to close my position on the last bar of the session but I think

    IsLastBarOfSession

    refers to the Daily Settlement Time and DAX still has 5 hours to go before the end of the session.

    Would I need an input variable if so what type to represent 21:00:00 (DAX close in the UK)?

    then create TimeSpan EndTime = new TimeSpan(21, 00, 00); then

    if(Time[0] == EndTime)
    //end of session

    or are there easier ways?

    #2
    Hello delTik, and thank you for your question.

    IsLastBarOfSession actually does refer to the last bar of the session (defined in Tools -> Trading Hours), not the settlement time. If you are seeing this become true despite it not being toward the end of the session, please let us know so we can investigate further.

    Please let us know if we can help with anything else.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by delTik View Post
      I'd like to close my position on the last bar of the session but I think

      IsLastBarOfSession

      refers to the Daily Settlement Time and DAX still has 5 hours to go before the end of the session.

      Would I need an input variable if so what type to represent 21:00:00 (DAX close in the UK)?

      then create TimeSpan EndTime = new TimeSpan(21, 00, 00); then

      if(Time[0] == EndTime)
      //end of session

      or are there easier ways?
      You can use the IsExitOnCloseStrategy = true and define the number of seconds from close you would like this logic to take place.





      Also, if you have Calculate set to Calculate.OnBarClose, IsLastBarOfSession would not be true until the bar has actually closed and might be too late for your logic. It would be true immediately on Calculate.OnPriceChange/OnEachTick before the bar closes.
      MatthewNinjaTrader Product Management

      Comment


        #4
        thanks, yes I understand now.

        probably doing something but could someone look at the attached and tell me why it prints on each tick?
        Attached Files
        Last edited by delTik; 09-14-2016, 11:57 AM.

        Comment


          #5
          Hello delTik,

          The following change should ensure you only print exactly once per session. If this is not successful or we can help in any other way please let us know.

          Code:
          [FONT=Courier New]            if (Bars.IsLastBarOfSession && IsFirstTickOfBar)[/FONT]
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            ok will give it a try but it was printing out on each tick on a bar that wasn't the last bar of the session?

            Comment


              #7
              Hello, and thank you for your report. This behavior was confirmed on our end. We will be investigating this further. Please keep an eye on the NinjaTrader 8 Release Notes page for updates and bugfixes.



              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                ok thanks. Meanwhile what's the best way to do something like ....

                Code:
                		protected override void OnBarUpdate()
                		{
                			//if (Bars.IsLastBarOfSession)
                			//{
                			if (IsFirstTickOfBar && isSessionEndBar("21:00:00"))
                			{
                				++tmp;
                				Print(tmp.ToString()+","+"Session Ended"+","+Time[0].ToString());
                			}
                			//}
                		}
                		
                		public bool isSessionEndBar(string se)
                		{
                			try 
                			{
                      			TimeSpan tsSessionEnd = TimeSpan.Parse(se);
                				if (Time[0].TimeOfDay >= tsSessionEnd)
                					return true;
                	   		}
                   			catch (FormatException) 
                			{
                				Print( String.Format("Format error {0}", se) );
                   			}
                   			return false;
                		}
                Last edited by delTik; 09-15-2016, 06:22 AM.

                Comment


                  #9
                  For time input variables, I prefer using integers as inputs, and then using the ToTime() and ToDay() methods,




                  You can deconstruct a user input integer into year, month, day, and another into hour, minute, seconds, like this :

                  Code:
                  [FONT=Courier New]int year = (userDate / 10000) % 1000000;
                  int month = (userDate / 100) % 10000;
                  int day = (userDate / 1) % 100;
                  int hour = (userTime / 10000) % 1000000;
                  int minute = (userTime / 100) % 10000;
                  int second = (userTime / 1) % 100;[/FONT]
                  Alternately, if the above approach would be difficult to explain to an end user, you can construct a ToTime and ToDay compatible integer like this :

                  Code:
                  [FONT=Courier New]
                  int userDate = ((userYear % 100) * 10000) + ((userMonth % 100) * 100) + ((userDay % 100) * 1);
                  int userTime = ((userHour % 100) * 10000) + ((userMinute % 100) * 100) + ((userSecond % 100) * 1);[/FONT]
                  Remember that times are on a 24 hour clock and are typically in the Eastern or Local time zones.

                  Please let us know if there are any other ways we can help.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    ok thanks.

                    could you request both IsLastBarOfSession anf IsFirstBarOfSession be checked?

                    Comment


                      #11
                      Our teams responsible have been made aware of this thread, so any information we add to this thread is automatically made available to everyone investigating this issue.
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        ok great.

                        another temporary option is to use:

                        if (State == State.SetDefaults)
                        {
                        tsSessionEndBar = new TimeSpan(21,0,0);
                        }

                        //properties
                        [Display(ResourceType = typeof(Custom.Resource), Name = "Session End Bar", GroupName = "NinjaScriptParameters", Order = 0)]
                        public TimeSpan tsSessionEndBar
                        { get; set; }

                        Comment


                          #13
                          Hello DelTik,

                          I have an update on the IsLastBarOfSession behavior we were reviewing before. I am including a quote from the help guide.

                          Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/?islastbarofsession.htm
                          Notes:
                          ...
                          When running Calculate.OnEachTick / OnPriceChange, this property will always return true on the most current real-time bar since it is the last bar that is updating in the trading session. If you need to find a bar which coincides with the session end time, please use the SessionIterator.ActualSessionEnd.
                          I believe this clears up the situation we were observing. Please let us know if there are any other ways we can help.
                          Last edited by NinjaTrader_JessicaP; 09-16-2016, 12:46 PM.
                          Jessica P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by judysamnt7, 03-13-2023, 09:11 AM
                          4 responses
                          57 views
                          0 likes
                          Last Post DynamicTest  
                          Started by ScottWalsh, Today, 06:52 PM
                          4 responses
                          36 views
                          0 likes
                          Last Post ScottWalsh  
                          Started by olisav57, Today, 07:39 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post olisav57  
                          Started by trilliantrader, Today, 03:01 PM
                          2 responses
                          19 views
                          0 likes
                          Last Post helpwanted  
                          Started by cre8able, Today, 07:24 PM
                          0 responses
                          9 views
                          0 likes
                          Last Post cre8able  
                          Working...
                          X