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

Get the real time DateTime of the last bar in replay data connections

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

    Get the real time DateTime of the last bar in replay data connections

    I am testing in Replay data:

    The next line return the DateTime of the last bar open.... (Ex: 21/11/2018 20:35:00 )

    Code:
    ChartBars.Bars.GetTime(ChartBars.ToIndex)
    How can I get the real time of the updating bar in replay? (Ex: 21/11/2018 20:36:18)

    Thank you
    Last edited by ninjo; 04-02-2019, 01:06 PM.

    #2
    Hello ninjo,

    Thank you for the post.

    Generally, you would need to use Time[0] to get the current timeof the updating bar, I understand you have used "updating bar" in place of the "building bar" or rightmost bar, is this correct?

    This will also depend on the Calculate setting you have used, if you are using OnBarClose the building bar is excluded from calculations. If you are instead using OnEachTick or PriceChange Time[0] represents the building bars last time in realtime. In cases where you use OnBarClose, you may need to use OnMarketData to access the live price opposed to a closed bars price.

    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_Jesse; 11-26-2018, 08:15 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Use Time[0]?

      Comment


        #4
        Thank you Jesse and sledge

        I tried with TIme[0] but the TIme returned was the minute and :00 seconds during all the bar.

        Output example:

        27/11/2018 21:27:00
        27/11/2018 21:27:00
        27/11/2018 21:27:00
        27/11/2018 21:27:00
        27/11/2018 21:27:00
        27/11/2018 21:28:00
        27/11/2018 21:28:00
        27/11/2018 21:28:00
        ....

        I seted in "State.SetDefaults" the "Calculate = Calculate.OnEachTick;"

        How could I get the "real" time of the bar in each bar changes?

        Comment


          #5
          Hello ninjo,

          It sounds like the print is doing what it should and outputting the expected result. The Time[0] you printed is the "real" time of the bar. If you are using a 1 minute bar the Time you are seeing would represent the bar close times. If you are using a 1 minute bar type there is no granularity to have second intervals reported, you would need to use a bars type with more granularity for that to happen.

          Because you are using OnEachTick, the very last print will be the building bars time. In realtime, you will see this value repeated as you have shown:

          27/11/2018 21:28:00
          27/11/2018 21:28:00
          27/11/2018 21:28:00

          Are you trying to do something other than getting the Bars time stamp like the last ticks timestamp?


          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thank you Jesse,

            I want something like:

            27/11/2018 21:28:00
            27/11/2018 21:28:01
            27/11/2018 21:28:03
            27/11/2018 21:28:06
            27/11/2018 21:28:07
            27/11/2018 21:28:09
            ....

            How could I get the las tick timestamp?

            Thank you again

            Comment


              #7
              Hello ninjo,

              Thank you for your response.

              You could add a 1 Tick series to your script and pull it's Time, or you could use OnMarketData() and pull the time from the MarketDataEventArgs if it is the MarketDataType.Last, or just pull the DateTime.Now when OnBarUpdate() is called.
              Please let me know if you have any questions.

              Comment


                #8
                Hi Patrick, thank you!

                Yes, I tried with DateTime.Now, but when the script is working with Replay Data, the DateTime.Now returned is the time of real time clock instead the real time of the bar moving

                How could I get the exactly time of each movement of a bar in Replay Data connection?



                Comment


                  #9
                  Hello ninjo,

                  Thank you for your response.

                  The Bar Timer indicator has a great example of how to do that in it's code.

                  You would use Cbi.Connection.PlaybackConnection.Now.

                  Please let me know if you have any questions.

                  Comment


                    #10
                    Please. Could you help me with some working code example or the NT official documentation?
                    I cant found the "PlaybackConnection" in the NT8 guide and the use of "Cbi.Connection.PlaybackConnection.Now" return errors on Output window.

                    Thank you

                    Comment


                      #11
                      Ok. I think I've got it with the OnMarketData Function:


                      Code:
                      DateTime dtBarUniversal;
                      
                      protected override void OnMarketData(MarketDataEventArgs marketDataUpdate){
                      
                          dtBarUniversal = marketDataUpdate.Time.ToUniversalTime();
                          DateTime datetimeNow = TimeZoneInfo.ConvertTime(dtBarUniversal, TimeZoneInfo.Local);
                      
                          Print(datetimeNow + " // Real Bar Time for any connection");            
                      
                      }

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by judysamnt7, 03-13-2023, 09:11 AM
                      4 responses
                      59 views
                      0 likes
                      Last Post DynamicTest  
                      Started by ScottWalsh, Today, 06:52 PM
                      4 responses
                      36 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by olisav57, Today, 07:39 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post olisav57  
                      Started by trilliantrader, Today, 03:01 PM
                      2 responses
                      22 views
                      0 likes
                      Last Post helpwanted  
                      Started by cre8able, Today, 07:24 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post cre8able  
                      Working...
                      X