Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help code error

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

    Help code error

    the following code from Help under GetBar() does not compile:


    // Check that its past 9:45 AM
    if (ToTime(Time[0]) >= ToTime(9, 45, 00))
    {
    // Calculate the bars ago value for the 9 AM bar for the current day
    int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2006, 12, 18, 9, 0, 0));

    // Print out the 9 AM bar closing price
    Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
    }

    #2
    Hmm. It compiles fine for me. Could you please inform us as to the error you are receiving preventing the compile? Thanks.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Does compile for strategies but not for indicators. Fixed with next update of NT6.5. Thanks for reporting.

      Comment


        #4
        Thanks.

        Yes...I was trying to compile it in an Indicator.

        Does it return the actual time?...or the bar timestamp?

        The reason I was trying to use it was that I want to do a calculation at 10:00 AM on a 5 min chart. If I check the time using Time.Hour and Time.Minute my calculation takes place at 9:55...i.e. the first tick of the 10:00 bar or 5 mins too early.

        I suppose I could check for the first tick of the 10:05 bar....but thought maybe ToTime would work.

        I need a LastTickOfBar...

        or...maybe use the chart interval?...in efs the code would be GetInterval() to pick up the interval of the chart....what is it in ninjascript please.

        Comment


          #5

          Comment


            #6
            that does not work Dierk

            per my post, I am trying to perform a calculation on the last tick of the 10:00 bar, not when NT starts building the 10:00 bar

            on a 5 min chart, the 10:00 timestamp occurs at the start of the bar which is 09:55:01...not at 10:00:00...because that is how NT builds bars

            I do not want to calculate at 09:55:01

            Comment


              #7
              Sorry I don't follow.

              Comment


                #8
                per NT help...
                Bar Time Stamp
                NinjaTrader stamps a bar with the closing time of the bar. For example, a minute bar with a time of 9:31:00 AM has data from 9:30:00 AM through 9:30:59 AM.

                I want to calculate with data from the last tick of the 9:31:00 bar...i.e. the data at 9:30:59

                If I use Time.Minute or ToTime to check the time of the bar to start my calculation, NT tells me it is 9:31:00 at the start of the bar..i.e. 9:30:00...this is a minute too early. Even ToTime(093100) triggers at 9:30:00 and not at 9:31:00 (because NT timestamps bars with the CLOSING time of the bar)

                Bottom line: I need a function LastTickOfBar to make sure I am getting the data from exactly 9:30:59 and not from the NT timestamp time which is "...the closing time of the bar"

                The best workaround I have so far is to check for the first tick of the 9:32:00 and look back at the prior tick to get the data for the last tick of the 9:31:00 bar

                Comment


                  #9
                  Unfortunately "LastTickOfBar" logic is not supported.

                  Comment


                    #10
                    Unfortunately, for time bars, the only way to know for certain the bar is complete is to read the next tick to see if it has a different CLOSING time stamp. If a “LastTickOfBar” function did exist for time bars, it would have to do the same process and therefore it would be cheating by looking ahead by one tick.

                    Regards,

                    Whitmark
                    whitmark
                    NinjaTrader Ecosystem Vendor - Whitmark Development

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    599 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    345 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    103 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    558 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    558 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X