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 DayTradingDEMON, Today, 09:28 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by helpwanted, Today, 03:06 AM
            2 responses
            22 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by navyguy06, Today, 09:28 AM
            0 responses
            5 views
            0 likes
            Last Post navyguy06  
            Started by rjbtrade1, 11-30-2023, 04:38 PM
            2 responses
            77 views
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Working...
            X