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]);
        			}

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by harr5754, Today, 07:36 AM
        1 response
        10 views
        0 likes
        Last Post bltdavid  
        Started by Orion1504, Today, 11:59 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by z3trader, Today, 11:50 AM
        5 responses
        24 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by Mykro, Today, 11:20 AM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by RedDuke, Today, 10:49 AM
        2 responses
        7 views
        0 likes
        Last Post RedDuke
        by RedDuke
         
        Working...
        X