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 Aramunno, Yesterday, 10:11 PM
        2 responses
        14 views
        0 likes
        Last Post Aramunno  
        Started by sdauteuil, Yesterday, 09:38 PM
        0 responses
        4 views
        0 likes
        Last Post sdauteuil  
        Started by fscabrera03, Yesterday, 09:23 PM
        0 responses
        7 views
        0 likes
        Last Post fscabrera03  
        Started by WeyldFalcon, Yesterday, 07:03 PM
        0 responses
        7 views
        0 likes
        Last Post WeyldFalcon  
        Started by Seastragg, Yesterday, 04:01 PM
        3 responses
        38 views
        0 likes
        Last Post Seastragg  
        Working...
        X