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 soon123, Today, 12:18 AM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by space_trader, Today, 12:52 AM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by ybhx0315, Yesterday, 09:06 PM
        0 responses
        15 views
        0 likes
        Last Post ybhx0315  
        Started by parkinsonbr, Yesterday, 08:23 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by fxRichard, Today, 04:35 AM
        2 responses
        14 views
        0 likes
        Last Post fxRichard  
        Working...
        X