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 bar date when the new daily bar created

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

    get the bar date when the new daily bar created

    Hi,

    Using ninjascript, how do I get the bar date when the new daily bar created? Using Times[0][0] will give me the current data datetime (which I can try to check for the timestamp and add 1 day to get the bar date, but it seems like a hack because these start time can be different/change with other instruments), am I right? In futures, the new daily bar created at 18:00 from the current day, but the actual bar date is next day.
    Last edited by affilife; 02-20-2024, 02:00 PM.

    #2
    Hello affilife,

    Use Calculate.OnEachTick and print Time[0] when IsFirstTickOfBar is true.


    Enable TickReplay for this to also work in historical.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks. I guess I need to add 1 day then, which is a hack because other instrument market hour open the next day

      Comment


        #4
        Hello affilife,

        I'm not quite sure what you mean.

        Do you mean you are using Time[0].AddDays(1) when the previous day bar closes with Calculate.OnBarClose?

        Have you tested my suggestion and found this is not working?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Say right now is 9pm eastern time. Would Time[0] give me today date? Or tomorrow date? If it gives me today date, then it's not the daily bar date because the daily bar date is tomorrow date.

          Comment


            #6
            Hello affilife,

            That depends, what is the instrument (so we know the trading hours), what is the time zone, what is the Calculate property set to, and is TickReplay enabled?

            Let's say the instrument is the ES 03-24. The session in progress at 9:00 PM Central today 2/20/24 would end at 4:00 PM Central tomorrow on Wednesday.
            With Calculate set to OnEachTick or OnPriceChange printing Time[0] at 9:00 PM would return 2/21/24 5:00 PM, the close time of the current session day bar.
            With Calculate set to OnBarClose Time[0] would return 2/20/24 5:00 PM from the previous bar close.​
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you very much for the explanation. I am clear now.

              Comment


                #8
                One question: However when processing historical data, Time[0] would return 2/20/24 5pm when Calculate set to OnEachTick or OnPriceChange. Is that right? This would cause some mixed up because I use the date to write into a file; both historical and realtime.

                Comment


                  #9
                  Hello affilife,

                  With TickReplay enabled (as directed in post # 2) and Calculate set to OnEachTick/OnPriceChange the date returned would be 2/21/24 5:00 PM, the same as it would in real-time.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    so when I run my strategy analyzer, I would need to turn on Tick Replay? Otherwise, the date will off by 1day?

                    Comment


                      #11
                      Hello affilife,

                      Yes, you would need to enabled TickReplay as directed for Calculate to work with OnPriceChange/OnEachTick in historical.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Chelsea. Another question: how do I get playback commission the same as sim101 commission. It's different, which make it hard to do proper comparison.

                        Edit: I was able to make it the same

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by fx.practic, 10-15-2013, 12:53 AM
                        5 responses
                        5,404 views
                        0 likes
                        Last Post Bidder
                        by Bidder
                         
                        Started by Shai Samuel, 07-02-2022, 02:46 PM
                        4 responses
                        95 views
                        0 likes
                        Last Post Bidder
                        by Bidder
                         
                        Started by DJ888, Yesterday, 10:57 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        159 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Yesterday, 09:29 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post Belfortbucks  
                        Working...
                        X