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 rocketman7, Today, 01:00 AM
        0 responses
        1 view
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        2 responses
        74 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        193 views
        0 likes
        Last Post Hasadafa  
        Working...
        X