Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 - https://www.ninjatrader.com/support/...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 pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        147 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        5 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        4 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,282 views
        0 likes
        Last Post Leafcutter  
        Working...
        X