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

Bar start time

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

    Bar start time

    Hi.

    Can I determine a certain time when new minute bar appear?
    With what time minute chart is syncronised?

    Thanks.

    #2
    Hello blekdzhon,

    I'm not certain what you are asking.

    Are you asking how to print the time of the first tick received after a new bar has opened?

    If so, you will need to set Calculate to .OnEachTick, and set a condition to print when IsFirstTickOfBar is true.

    Below are publicly available links to the help guide.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I need to know at what time the next bar will open.
      Can I get the time when next bar starts?
      For example, On 5 minute chart I have current bar time = 12:25, how can I determine the time when next bar will open? Will it open at 12:25:00?

      Comment


        #4
        Hello blekdzhon,

        Typically, the bar opens right as the previous bar closes.

        Are you asking how to find when the next bar closes based on when the current bar has closed?

        If so, you would need to add 5 minutes to the Time[0].

        You could use an if statement to make sure that the bar type is a minute bar type and use the value to add minutes.

        For example:
        Code:
        if (BarsPeriod.Id == PeriodType.Minute)
        {
        	Print(Time[0].AddMinutes(BarsPeriod.Value));
        }
        Or are you detecting the first tick of a bar, and you are trying to add 5 minutes to the first tick received after a bar has opened?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello blekdzhon,

          Typically, the bar opens right as the previous bar closes.

          Are you asking how to find when the next bar closes based on when the current bar has closed?

          If so, you would need to add 5 minutes to the Time[0].

          You could use an if statement to make sure that the bar type is a minute bar type and use the value to add minutes.

          For example:
          Code:
          if (BarsPeriod.Id == PeriodType.Minute)
          {
              Print(Time[0].AddMinutes(BarsPeriod.Value));
          }
          Or are you detecting the first tick of a bar, and you are trying to add 5 minutes to the first tick received after a bar has opened?
          I'm trying to understand, have NinjaTrader 7 a specific time when new bar starts (on time based charts)

          Or bar appears only with first tick?

          Comment


            #6
            Hello blekdzhon,

            I'm not understanding your inquiry.

            OnBarUpdate will trigger when a bar closes.

            If you want to know when a bar opens, you have to process on each tick and detect the first tick of the bar.

            What are you trying to do in your script?
            Are you trying to trigger actions when the bar closes?
            Or are you trying to trigger actions on the first tick of a new bar when a bar opens?

            By default, OnBarUpdate triggers when a bar has closed.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I want to know exact time when NEXT bar will open.

              I'm developing indicator which calculates time that remaines before the next bar is opened.

              Comment


                #8
                Hello blekdzhon,

                In this case, you would not be detecting when a bar has closed, and instead you would be detecting the first tick of a newly opened bar.

                My previous links in post # were for NinjaTrader 8. I am including the proper links for NinjaTrader 7 below.

                In real-time you can detect this by setting CalculateOnBarClose to false, and then detecting when FirstTickOfBar is true and then adding 5 minutes to the current bar.

                This would only work in real-time as CalculateOnBarClose is always true in historical data.




                Code:
                CalculateOnBarClose = false;
                
                if (Historical)
                return;
                
                if (FirstTickOfBar)
                {
                Print(DateTime.Now.AddMinutes(5);
                }
                You could also add a secondary series of 1 tick, detect when the primary bar closes, and trigger on the first tick of the secondary series after the primary bar has closed. This would also work historically.

                Code:
                bool primaryBarClosed = false;
                
                if (BarsInProgress == 0)
                {
                primaryBarClosed = true;
                }
                
                if (BarsInProgress == 1 && primaryBarClosed == true)
                {
                Print(Times[1][0].AddMinutes(5);
                primaryBarClosed = false;
                }
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Code:
                  CalculateOnBarClose = false;  
                  if (Historical) return;  
                  if (FirstTickOfBar)
                  { 
                  Print(DateTime.Now.AddMinutes(5); 
                  }
                  This code will print Time when CurrentBar appeared plus 5 minutes.

                  It is not the time of the Next Bar open. I checked it.

                  I wrote the following code.

                  Code:
                  if(FirstTickOfBar)
                  {
                  Print("Current Bar Open Time "+DateTime.Now+" Next Bar Open Time     "+DateTime.Now.AddMinutes(Bars.Period.Value));
                  }
                  I got this.

                  Current Bar Open Time 27.12.2017 21:38:05 Next Bar Open Time 27.12.2017 21:39:05
                  Current Bar Open Time 27.12.2017 21:39:35 Next Bar Open Time 27.12.2017 21:40:35
                  Current Bar Open Time 27.12.2017 21:40:08 Next Bar Open Time 27.12.2017 21:41:08
                  As you can see Next Bar Open Time is not equal to Current Bar Open Time in the next line.

                  I tested it on 1 min chart.
                  Last edited by blekdzhon; 12-27-2017, 01:00 PM.

                  Comment


                    #10
                    Hello blekdzhon,

                    A new bar will open after the first tick is received after the close time of the previous bar.

                    It is impossible to know when first tick will be received after a bar has closed (ticks are produced as people make trades). There is no way to know exactly when someone in the world will make the first trade and cause a tick to be sent.

                    You would only be able to estimate this.

                    You are basically trying to predict the future which is not possible.

                    Your own prints are showing you that the first tick of a bar is never at the same time.

                    However, you can add 5 minutes to the time of the first tick of the current bar to estimate when the open of the next bar will be.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you.

                      Comment


                        #12
                        ChelseaB,

                        Can you answer one more question.

                        With what time minute chart is syncronised? Is it syncronised with exchange time or Windows time?

                        Comment


                          #13
                          Hello blekdzhon,

                          NinjaTrader uses your local PC clock to time stamp real-time and historical data as this is received. This will be converted from the time of data provider.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by blekdzhon View Post
                            I'm trying to understand, have NinjaTrader 7 a specific time when new bar starts (on time based charts)

                            Or bar appears only with first tick?
                            Succinctly, yes: the first tick of the new bar, which is the first tick that occurs after the time to close the previous bar, closes the previous bar and opens the new bar. Of course, timewise, this is true only for bars that are based on a fixed time-quantum.

                            For other bar types, the new bar opens with the first tick after the condition is satisfied for the construction of a (previous) bar.
                            Last edited by koganam; 12-28-2017, 10:38 AM.

                            Comment


                              #15
                              Not knowing where your location is, it looks like you are checking bar times late at night when the market is thin. If you see the same problem during regular trading sessions you may have to synchronize your clock more frequently. Try using Dimension 4, search the net for a free download.
                              eDanny
                              NinjaTrader Ecosystem Vendor - Integrity Traders

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by techgetgame, Yesterday, 11:42 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post techgetgame  
                              Started by sephichapdson, Yesterday, 11:36 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post sephichapdson  
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,615 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Yesterday, 05:56 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              20 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Working...
                              X