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.

    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 jclose, Today, 09:37 PM
      0 responses
      6 views
      0 likes
      Last Post jclose
      by jclose
       
      Started by WeyldFalcon, 08-07-2020, 06:13 AM
      10 responses
      1,414 views
      0 likes
      Last Post Traderontheroad  
      Started by firefoxforum12, Today, 08:53 PM
      0 responses
      11 views
      0 likes
      Last Post firefoxforum12  
      Started by stafe, Today, 08:34 PM
      0 responses
      11 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by sastrades, 01-31-2024, 10:19 PM
      11 responses
      169 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X