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

Time[0].Milisecond problem

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

    Time[0].Milisecond problem

    Hello, please help to solve a problem. I'm trying to calculate the time of formation of each new bar in milliseconds.

    Prescribed the following

    T = Time[0].Millisecond;
    Plot0.Set(T);

    But the value is still 0

    If we change to Time[0].Second, then everything is fine although above 59 is not considered. But I need to count in milliseconds and no limit. Please help me to solve this problem.

    #2
    Originally posted by Kovalev View Post
    Hello, please help to solve a problem. I'm trying to calculate the time of formation of each new bar in milliseconds.

    Prescribed the following

    T = Time[0].Millisecond;
    Plot0.Set(T);

    But the value is still 0

    If we change to Time[0].Second, then everything is fine although above 59 is not considered. But I need to count in milliseconds and no limit. Please help me to solve this problem.
    What you have written shows an instant in time, and a component of that instance.

    You have to use the correct syntax, and the correct calculation. That only way to tell how much time has elapsed in anything is to subtract the start time from the end time, so specifying a single Time is a non-starter.

    Most likely what you seek is: (Time[0] - Time[1]).TotalMilliseconds as your value.

    Comment


      #3
      Hello Kovalev,

      Thanks for your post.

      Time[0] will represent the timestamp of the bar and would not necessarily represent the time of the tick. We would only see a millisecond value for bars that have millisecond granularity in the bar timestamps.

      NinjaTrader 7 does not offer millisecond granularity for time and tick based bar timestamps, but NinjaTrader 8 does have this granularity for tick based bar timestamps.

      Although cumbersome, you could accomplish this in NinjaTrader 7 by using timers to measure the time between each tick (or as long as needed) and accumulate the total time in milliseconds. An example on using timers can be found below.

      Sample Custom Events (Timer example) - https://ninjatrader.com/support/help...to_output_.htm

      Please let us know if there is anything else we can do to help.
      JimNinjaTrader Customer Service

      Comment


        #4
        NinjaTrader_Jim, koganam, thank you very much guys, you helped me so much

        Comment


          #5
          Guys, there was another related question
          for example, I have two values A and B

          if (Open[0] < Close [0] && Open[1] > Close [1]) A;
          if (Open[0] > Close [0] && Open[1] < Close [1]) B;

          I need to calculate how many seconds have passed between these two conditions, that is, for example,
          T = (B - A).TotalSeconds;

          but how do I map variables A and B to DateTime?

          Comment


            #6
            Hello Kovalev,

            You could make your own DateTime variables and assign these variables a value based on your conditions. Time[0] will still represent the timestamp of the developing bar and not the actual tick, so you may wish to monitor DateTime.Now with CalculateOnBarClose=false to get the current time for the iterating tick. Keep in mind, when you subtract two DateTime objects, you get a TimeSpan.

            Here is an example that shows two DateTime variables being assigned DateTime.Now, having 30 seconds added to the first DateTime variable, and then the difference between the two DateTime objects printed in the output window.
            Code:
            private DateTime A, B;
            protected override void OnBarUpdate()
            {
            	A = B = DateTime.Now;
            	A = A.AddSeconds(30);
            	Print((A - B).TotalSeconds);
            }
            I've included a link to a reference sample for manipulating DateTime objects. Since DateTime objects are a general C# concept, there are lots of external resources that could be referenced for further demonstrations.

            Manipulating DateTime objects example - https://ninjatrader.com/support/help...me_objects.htm

            Please let me know if you have any additional questions.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            388 views
            0 likes
            Last Post z.franck  
            Started by rtwave, 04-12-2024, 09:30 AM
            4 responses
            31 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by yertle, Yesterday, 08:38 AM
            7 responses
            29 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by bmartz, 03-12-2024, 06:12 AM
            2 responses
            22 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by funk10101, Today, 12:02 AM
            0 responses
            7 views
            0 likes
            Last Post funk10101  
            Working...
            X