• 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

Set start date and time programmically

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

    Set start date and time programmically

    I have a moving average and I would like to have it start measuring the average at the beginning of the previous day's session start.

    I can manually change this each time I start the day but would like to have this done each day when I start NT.

    Does anyone know of the correct way to reference this and set the start date/time so that it updates each day?

    The set time code is below:
    Code:
           #region Variables
                private string startString = @"8:30";   // Default setting for Time
    	    private DateTime startTime;
            #endregion
    
    protected override void OnStartUp() 
        {
    	  /* interpret the start time */		
           if(DateTime.TryParse(startString, out startTime)) 
             {
    	  startString = startTime.ToString();	
    	  } 
           else 
             {
              startString = DateTime.Now.ToString();	
    	 }
        }

    #2
    Hi David, for your indicator you could directly access the session begin time from the applied template through this NinjaScript method - http://www.ninjatrader.com/support/h...xtbeginend.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      That function gives the NEXT session begin time.

      I need PREVIOUS days or times.

      Is there a way to get a time of maybe 17:00 for two days previous?
      i.e if the current trading day is 1/9/2015 set the time in the indicator to 1/6/2015 17:00:00

      Thanks

      Comment


        #4
        Hello DavidHP,

        Thank you for your response.

        The following code would set the moving average plot to two days ago based on your PC's time. While this would work if the current session is today's date, it would not work in the case that the last session was a day or two ago from your PC clock time.
        Code:
        			DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 30, 0);
        			if(Time[0] >= today.AddDays(-2))
        			{
        				Value.Set(SMA(14)[0]);
        			}
        Patrick H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jeremy83846, Today, 01:44 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by PageNotFound404, Today, 01:53 PM
        0 responses
        5 views
        0 likes
        Last Post PageNotFound404  
        Started by Captain_Qwark, Today, 10:55 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by kmpc1, Today, 11:03 AM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by jransom, Today, 09:08 AM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X