Announcement

Collapse
No announcement yet.

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

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by vantojo, Today, 01:39 PM
        0 responses
        15 views
        0 likes
        Last Post vantojo
        by vantojo
         
        Started by Rubens_2020, Today, 01:48 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by kempotrader, Today, 01:34 PM
        1 response
        23 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by bc24fl, Today, 01:50 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by bosajin, 01-21-2021, 09:15 AM
        7 responses
        60 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Working...
        X