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

Can I get last known tick time?

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

    Can I get last known tick time?

    Hello

    I'm interested in getting time of last tick. Not Time[0], because it gives me truncated to chart period time, but a "real" time, with seconds and milliseconds

    There are very useful methods GetCurrentBid()/GetCurrentAsk(). I wish there was a method like GetCurrentTime()


    Thanks in advance

    #2
    Hello rfsettling,

    Thanks for your post.

    If you run your code with the calculate mode of OnEachTick, Time[0] will provide the time of the last tick. You can test with a print statement such as:
    Print (Time[0].Hour+":"+Time[0].Minute+":"+Time[0].Second+":"+Time[0].Millisecond);
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I tested.

      And what I got (see attachment)

      My code

      Code:
      namespace NinjaTrader.NinjaScript.Strategies
      {
      
          public class MyCustomStrategy : Strategy
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description = @"Enter the description for your new custom Strategy here.";
                      Name = "MyCustomStrategy";
                      Calculate = Calculate.OnEachTick;
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  base.OnBarUpdate();
                  if (State==State.Realtime)
                      Print(Time[0].Hour + ":" + Time[0].Minute + ":" + Time[0].Second + ":" + Time[0].Millisecond);
              }
          }
      }
      Attached Files

      Comment


        #4
        Hello rfsettling,

        Thanks for your reply.

        Correct, on time based bars that would be expected. For time based bars, you could add a tick series and obtain the time of the last tick from the tick series (or any non time based bars).

        Alternatively, you can you can access from OnMarketData, here is an example:

        Code:
        		protected override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
        		{
         			if (marketDataUpdate.MarketDataType == Data.MarketDataType.Last)
        			Print (String.Format("{0:HH:mm:ss:ffff}", marketDataUpdate.Time));
        		}
        Output example:
        08:21:30:9580
        08:21:31:3330
        08:21:31:3330
        08:21:31:8300
        08:21:31:8360
        08:21:32:7350
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello rfsettling,

          Thanks for your reply.

          Correct, on time based bars that would be expected. For time based bars, you could add a tick series and obtain the time of the last tick from the tick series (or any non time based bars).

          Alternatively, you can you can access from OnMarketData, here is an example:

          Code:
           protected override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
          {
          if (marketDataUpdate.MarketDataType == Data.MarketDataType.Last)
          Print (String.Format("{0:HH:mm:ss:ffff}", marketDataUpdate.Time));
          }
          What kind of time it returns: local time / exchange server time?

          Comment


            #6
            Hello curious,

            That depends on the provider being used. You can see a list of providers and if they offer Real-Time Timestamps here: https://ninjatrader.com/support/help...tsub=providers
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Kaledus, Today, 01:29 PM
            0 responses
            3 views
            0 likes
            Last Post Kaledus
            by Kaledus
             
            Started by PaulMohn, Today, 12:36 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by yertle, Yesterday, 08:38 AM
            8 responses
            36 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Started by rdtdale, Today, 01:02 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by alifarahani, Today, 09:40 AM
            3 responses
            18 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X