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

Pull out time code from timeseries

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

    Pull out time code from timeseries

    Say I have a 10 minute chart but I want to pull out the time code of each tick by tick?
    Year Month Day Hour Min Second?


    I have been using this: Time[0].Year + "\t" + Time[0].Month + "\t" + Time[0].Day

    But it stalls on the period intervals.. I don't want to make a tick chart just to get tick updates? there must be a way to pull the timecode out a larger time frame?
    HELP


    #2
    Hello marluv,

    Thanks for your post.

    Time[0] is the close time of the bar. If you are using 10-minute bars then the close time will be on 10-minute intervals.

    To get the tick by tick timestamp you would need to add a 1 tick series to your strategy and print that series with Times[1][0].

    For example:
    Code:
    else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBars[1] < 1) return;
    
                if (BarsInProgress != 1) return;
    
                Print (Times[1][0]);  // prints will be for example: 6/24/2020 9:03:57 AM
            }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      The code started to back fill back to the 18th of the month and froze my computer... LOL how can I have it only backfill today and read realtime?

      Comment


        #4
        Hello marluv,

        The AddDataSeries() will add tick data for as many days as you have specified in the chart.

        You can prevent print historical data by adding this check:

        Code:
        protected override void OnBarUpdate()
                {
                    if (CurrentBars[1] < 1) return;
        
                    if (BarsInProgress != 1) return;
        
        [B]if (State != State.Realtime) return;[/B]
        
                    Print (Times[1][0]);  // prints will be for example: 6/24/2020 9:03:57 AM
                }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Great everything works,


          THANKS

          Comment


            #6
            I noticed on the back fill reload.. these event's don't get called? how do I determine these on the back fill? for that Tick Time series?


            if (e.MarketDataType == MarketDataType.Ask)
            {
            Print("Ask = " + e.Price + " " + e.Volume);
            }
            else if (e.MarketDataType == MarketDataType.Bid)
            {
            Print("Bid = " + e.Price + " " + e.Volume);
            }

            // Print some data to the Output window
            else if (e.MarketDataType == MarketDataType.Last)
            {


            }

            Last edited by marluv; 06-24-2020, 03:33 PM.

            Comment


              #7
              Hello marluv,

              Thanks for your reply.

              Please note that you are asking a question unrelated to the thread topic. For further unrelated questions to the topic, please create a new thread. This will help us all by having organized forums. Thanks for your understanding.

              To answer your question, from the help guide notes on OnMarketData():

              "2.By default, this method is not called on historical data (backtest), however it can be called historically by using TickReplay

              3.If used with TickReplay, please keep in mind Tick Replay ONLY replays the Last market data event, and only stores the best inside bid/ask price at the time of the last trade event. You can think of this as the equivalent of the bid/ask price at the time a trade was reported. As such, historical bid/ask market data events (i..e, bid/ask volume) DO NOT work with Tick Replay. To obtain those values, you need to use a historical bid/ask series separately from TickReplay through OnBarUpdate(). More information can be found under Developing for Tick Replay."


              References:



              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Okay so this requires way more owrk to get done hmmm.

                Let's get back to events for realtime

                if (e.MarketDataType == MarketDataType.Ask)
                {
                Print("Ask = " + e.Price + " " + e.Volume);
                }
                else if (e.MarketDataType == MarketDataType.Bid)
                {
                Print("Bid = " + e.Price + " " + e.Volume);
                }

                // Print some data to the Output window
                else if (e.MarketDataType == MarketDataType.Last)
                {


                }

                ... Are these events called only in realtime? and because I added a TICK time series.. it will be called in realtime per tick update?

                Comment


                  #9
                  The reasons I had to find the timecode was I was having lag in my data... so I was using gettime from the system and I started to notice my bars were all misalign with the correct time and price. I just want to pullout whatever ninja has with the correct time code and prices....

                  Comment


                    #10
                    Hello marluv,

                    Thanks for your reply.

                    Please review the notes (#7) for OnMarketData() as it mentions that OnMarketData() is called after OnBarUpdate().
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by itrader46, Today, 10:22 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post itrader46  
                    Started by NM_eFe, Today, 10:13 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post NM_eFe
                    by NM_eFe
                     
                    Started by hdge4u, Yesterday, 12:23 PM
                    1 response
                    10 views
                    0 likes
                    Last Post hdge4u
                    by hdge4u
                     
                    Started by 1001111, Today, 09:45 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post 1001111
                    by 1001111
                     
                    Started by DTSSTS, 01-28-2024, 12:07 PM
                    11 responses
                    558 views
                    0 likes
                    Last Post bmo111
                    by bmo111
                     
                    Working...
                    X