• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compute Start and End day session time

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

    Compute Start and End day session time

    Hi
    Suppose I have I have in a variable of type DateTimecalled TradeTime. This variable holds the time of a trade in the market in my time zone.
    I have two variables of type DateTime called StartDaySessionTime and EndDaySessionTime. StartDaySessionTime will hold the time in which the day session of the "MastInstrument" of the chart starts in the same date as the date of TradeTime.
    EndDaySessionTime will hold the time in which the day session of the "MastInstrument" of the chart ends in the same date as the date of TradeTime.

    This should be made based on the Session time as defined in the system ( which might be in different time zone) .
    How do I compute StartDaySessionTime and EndDaySessionTime ??

    #2
    Hello doron,

    Thank you for your post.

    You can use DateTime.UtcNow to get a standardized time for your objects. To pull the session begin and end for the date you need you would create a sessionIterator and then call the values from there.

    For example:
    Code:
    private SessionIterator sessionIterator;
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= "";
    				Name										= "Example1511892";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= true;
    			}
    			else if (State == State.Historical)
    			{
    				sessionIterator = new SessionIterator(Bars);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			DateTime myTime = DateTime.UtcNow;
    			
    			sessionIterator.GetNextSession(myTime, true);
    			
    			DateTime StartDaySessionTime	= sessionIterator.ActualSessionBegin;
    			DateTime EndDaySessionTime		= sessionIterator.ActualSessionEnd;
    		}
    Please visit the following link to review the information on sessionIterator: http://ninjatrader.com/support/helpG...oniterator.htm

    Please let me know if you have any questions.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      A problem with the example is that it uses sessionIterator.GetNextSession in OnBarUpdate(). Of course this should be fine but the documentation as of RC2 says not
      Warning: This method is resource intensive and should ONLY be reserved for situations when calculations would be limited to a few specific use cases. For example, calling this method for each bar in the OnBarUpdate() method would NOT be recommended.
      If the implementation of GetNextSession is really so resource intensive then it should be fixed. I wrote a class in NT7 that provided similar functionalty to SessionIterator and it was not resource intensive. Perhaps the developers are not using DateTimeOffset.
      Please improve the implementation and remove the warning from documentation. To be honest SessionIterator is not much use if we are not supposed to use it each bar.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by matthewbartlett, Today, 01:22 AM
      2 responses
      12 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by thomaspartyof10, Today, 02:33 AM
      1 response
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by manueldecastro, Yesterday, 12:57 AM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by ArmKnuckle, Today, 01:59 AM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Started by seppyr, Today, 01:53 AM
      1 response
      18 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X