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

How to retrieve timestamp of bar low?

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

    How to retrieve timestamp of bar low?

    "Time[5]" returns the timestamp of the 5th bar back Close. How to retrieve the timestamp of Low[5]? Idk if there is a timestamp connected with Bar Highs and Bar Lows? What is the cleanest way to handle this? thanks!

    #2
    Each and every bar on the chart has a timestamp associated with it.
    To say the "timestamp of Low[5]" is technically nonsensical.

    If you mean the timestamp of the lowest bar of amongst the 5 most recent
    bars, that can be achieved with this code,

    Code:
    Time[Lowest(5)]
    where the function Lowest returns the BarsAgo index of the bar with the
    lowest Low value within the specified Lookback period.

    Code:
    private int Lowest(int Lookback)
    {
        double lo = Low[0];
        int rc = 0;
    
        for (int BarsAgo = 1, cnt = 0; cnt < Lookback; ++cnt, ++BarsAgo)
        {
            if (Low[BarsAgo) < lo)
            {
                lo = Low[BarsAgo];
                rc = BarsAgo;
            }
        }
    
        return rc;
    }
    Last edited by bltdavid; 04-27-2021, 09:19 PM.

    Comment


      #3
      Originally posted by Kicks.Spin View Post
      is a timestamp connected with Bar Highs and Bar Lows? What is the cleanest way to handle this?
      Are you familiar with the Swing indicator?

      Good reading here.

      The idea you're looking for first requires a "middle-man concept" to find
      those bars with the highest highs and lowest lows. The point is: you need
      some kind of algorithm to return the BarsAgo index value of said bar you're
      looking for.

      Why?
      Because that return value is then used as the index to the Time series.

      I think being more precise with describing the bars you're looking for will
      help us pinpoint the right algorithm which returns the correct 'n' so that
      'Time[n]' in your code gives you the Time of said bar.

      Swing is one way to find values of 'n' to use with 'Time[n]'.

      There are others.

      Comment


        #4
        Hello Kicks.Spin,

        The Timestamps would be contained in the Time series, the Low[5] Close[5] High[5] Open[5] and Time[5] would represent the values of the same bar at 5 bars ago.

        If you wanted the time for Low[5] that would be Time[5].



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

        Comment


          #5
          thanks jesse & bltdavid. Time[Strength] returns the timestamp of the Close value for that bar. My hang up is that i need the timestamp at the lows. i can loop back for the bar i want as bltdavid points out. i'm not connecting the dots for how to code for time stamp of the Low itself. thanks for your patience. - Kicks.Spin

          Comment


            #6
            Hello Kicks.Spin,

            If you know the BarsAgo for the Low you could use that BarsAgo for the Time series to get the time from that bar. If you are using a loop to find a low you could use whatever BarsAgo was found in the loop with Time[BarsAgo]

            There is only 1 time series and that would be Time[x]

            Low[5] would have a timestamp of Time[5] as an example.

            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by Kicks.Spin View Post
              thanks jesse & bltdavid. Time[Strength] returns the timestamp of the Close value for that bar. My hang up is that i need the timestamp at the lows. i can loop back for the bar i want as bltdavid points out. i'm not connecting the dots for how to code for time stamp of the Low itself. thanks for your patience. - Kicks.Spin
              Hmm, let me try a different approach.

              A 5-min bar only has one time associated with it, and that is the
              time the bar closes, which is available in the Time series, and
              accessed by the "BarsAgo index", which is the 'n' in 'Time[n]'.

              The Low series contains the lowest value ever seen by each bar,
              just think visually of a candlestick, you can visualize the Open, High,
              Low, and Close values on each candlestick. Well, those 4 values
              for that candlestick are available in the 4 series, et al.

              But the exact time at which the high value happened, or the exact
              time at which the low value happened, the exactness of that time
              information is lost, because the granularity of a 5 min bar, is well
              5 minutes. When you look at the value of Low[n], all you can say
              is we know the "exact" time that value happened is within the last
              5 minutes of Time[n] -- thus Time[n] is sort of like an approximation.

              [EDIT: more 'true' time discussion]

              We don't automatically know the true exact moment in time (unless
              the Low and Close are the same price, which means the Low was
              found when the bar closed) -- you'd have to do a lot of extra special
              NinjaScript coding to record the exact times within the 5-min bar's
              five minutes of construction to keep track of when the high/low value
              actually occurred.

              My point is, if you want to know at what intermediate time during the
              life of those 5 minutes when the bar was under construction, did the
              lowest value (which eventually becomes the final value that stays
              in Low[n]) -- if you want the precise time this low value happened,
              well, ok -- we know it happened at some point inside that 5 minute
              bar, but are you wanting to know the exact time that this low value
              of the bar happened? Is that what you want?

              If so, that is quite possibly a foolish quest. How so?

              Because let's say the lowest value recorded in the 5 min bar
              was 2:14 mins into the bar. When the bar closed, armed with
              knowing 134 secs into the bar, the value in Low[n] happened,
              how is that useful? Not only that, how is that a trustworthy
              value? You don't if the low value at 134 secs into the bar is
              confirmed and never going to change until the 5 min bar's
              five minutes of construction is completed. So, few people
              care about the exact time at which Low[5] occurred -- most
              people just use Time[5] as a proxy for everything regarding
              when the OHLC values actually occurred, even though
              Time[5] is really just the time at which the bar closed.

              Yes, I see now what you're meaning. Time[5] is giving you
              the exact time at which the value in Close[5] occurred.

              There is no corresponding series is to give you the exact time
              at which Low[5] occurred -- that's just not how candlesticks
              work. Just use Time[5] as a proxy, isn't that good enough?

              EDIT: The forum s/w does not update this post when I try
              to save my edits. Very strange.
              Last edited by bltdavid; 04-30-2021, 09:15 AM.

              Comment


                #8
                Using my example, that's one reason why you might use a lower granularity
                bar type -- such as a 1-min bar instead of the 5-min bar -- because that would
                reduce the amount of time of knowing the "exact" time inside the bar the lowest
                value actually occurred from "somewhere inside last 5 minutes" to "somewhere
                inside last 1 minute".

                If you're coding in NinjaScript, you can certainly add an additional data series,
                say a 1 second series, or even 1 Tick series, and record the exact time the
                highest high value and lowest low values were seen on a per primary bar
                basis.
                Last edited by bltdavid; 04-29-2021, 11:34 AM.

                Comment


                  #9
                  Originally posted by bltdavid View Post
                  you'd have to do a lot of extra work to record the exact times
                  within the 5-min bar's five minutes of construction to keep track
                  of when the high/low occurred.
                  It's not that much extra work, and it's not impossible. But it's
                  certainly extra custom coding (way beyond strategy builder),
                  and is certainly going to require a secondary data series of
                  some acceptable granularity, such as a 1-Second series,
                  or a 1-Tick series.

                  Comment


                    #10
                    thank you bltdavid.
                    i solved this problem of swing duration by calculating it as follows
                    swingduration = closetocloseduration + highbartipadd - lowbartiptimesubtract.

                    closetocloseduration = Math.Abs((Time[CurrentBar - minbarnumber + 1] - Time[Strength + 1]).TotalSeconds)
                    closetocloseduration does not include duration of highbar development from open to high.

                    i solved that problem by calculating the duration of high bar and then estimating time of open to high as follows
                    higbartipadd = ( High[Strength] - Open[Strength] ) / Range()[Strength] * highbarduration.
                    The assumption is bar development from open to high is same as overall bar.

                    closetocloseduration includes extra time in bottom bar from open to low. that is not part of the swing
                    so i solved that problem by estimating duration of bottom bar as
                    lowbartiptimesubtract = ( Open[CurrentBar - minbarnumber] - Low[CurrentBar - minbarnumber] ) / Range()[CurrentBar - minbarnumber]
                    i spot checked the estimations on lower time frame and it is 99+%

                    Thanks to the senior members and moderators for helping new people along! Kicks.Spin

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by trilliantrader, 04-18-2024, 08:16 AM
                    4 responses
                    18 views
                    0 likes
                    Last Post trilliantrader  
                    Started by mgco4you, Today, 09:46 PM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by wzgy0920, Today, 09:53 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post wzgy0920  
                    Started by Rapine Heihei, Today, 08:19 PM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 08:25 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post Rapine Heihei  
                    Working...
                    X