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

OnMarketData using Time

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

    OnMarketData using Time

    Hi,

    I would like to know if it is possible to use the time from OnMarketData events. For example not necessarily times of trades but more so times of bid and or ask updates.

    If the time of the event was between times A & B then "code here".

    I have used times of bars before in OnBarUpdate however not times of OnMarketData events.

    Regards,
    suprsnipes

    #2
    Hi suprsnipes, yes the OnMarketData event args would let you access the event time as well - http://www.ninjatrader.com/support/h...aeventargs.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for the response. Would I need to use something like e.Time? Could you give is a quick example or refer me to a post where someone else has used this method?

      Comment


        #4
        Correct, e.Time would be your event time : you can just amend the helpguide example...

        if (e.MarketDataType == MarketDataType.Last)
        Print("Last = " + e.Price + " " + e.Volume + " " + e.Time);
        else if (e.MarketDataType == MarketDataType.Ask)
        Print("Ask = " + e.Price + " " + e.Volume + " " + e.Time);
        else if (e.MarketDataType == MarketDataType.Bid)
        Print("Bid = " + e.Price + " " + e.Volume + " " + e.Time);
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Apologies Bertrand, if you could help me just a bit more as I am not all that familiar working with these objects.

          I have the following code and would like to know how I could store the e.Time of each bid or ask update event.

          Code:
          if (e.MarketDataType == MarketDataType.Ask)askPrice     = e.Price; 
                      
          if (e.MarketDataType == MarketDataType.Ask)askVol         = e.Volume;
          I tried the following code unsuccessfully;

          Code:
          if (e.MarketDataType == MarketDataType.Ask)askTime         = e.Time;
          Please put me on the right path here.

          Regards,
          suprsnipes

          Comment


            #6
            What is your issue with the code you tried? If it does not compile, what is your askTime defined as? e.Time would be a DateTime object.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Ok thanks for that I was trying to save the bidTime / askTime as a private integar. What I have tried now which has compiled ok is under variables the following;

              Code:
              DateTime bidTime;
              DateTime askTime;
              I have printed each of these where the format looks like this;

              8/04/2013 09:51:00 AM

              What I am trying to do is use just the time portion in something like the code below but don't know how to use just the time in the same format;

              Code:
              if(askTime >= 233000 && askTime <= 235959)

              Comment


                #8
                You can use two approaches - either convert the DateTime to int via ToTime in NinjaScript and then use that resulting int for your compare, or you access .TimeOfDay of your Datetime object -

                Print(askTime.TimeOfDay.ToString());
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by suprsnipes View Post
                  Hi,

                  I would like to know if it is possible to use the time from OnMarketData events. For example not necessarily times of trades but more so times of bid and or ask updates.

                  If the time of the event was between times A & B then "code here".

                  I have used times of bars before in OnBarUpdate however not times of OnMarketData events.

                  Regards,
                  suprsnipes
                  A time, is a time, is a time. It should not matter where the data came from. You want to use a time, you declare a variable as a datastore, and you populate it, then query it.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Yesterday, 06:40 PM
                  2 responses
                  23 views
                  0 likes
                  Last Post algospoke  
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  45 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  21 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  181 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X