• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MAX(ED, 0ut)

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

    MAX(ED, 0ut)

    I'm curious about the signature for the MAX() function...

    The documentation for MAX()
    http://ninjatrader.com/support/helpG...aximum_max.htm

    states:

    input
    Indicator source data (?)
    period
    Number of bars used in the calculation

    with a code example of:

    ----- BEGIN -----
    // Prints the highest high value over the last 20 periods
    double value = MAX(High, 20)[0];
    Print("The current MAX value is " + value.ToString());
    ----- END ------


    Specifically the portion of the comment: "last 20 periods"...



    If I wrote MAX(High, 20)[10] does the period parameter always "look back"?
    Ex: From Bar[10] to Bar[30] ?

    Can I slide the period value in different directions / time?
    Ex: using MAX(High, 20)[10] can I get the High from Bar[0] to Bar[20] ?

    Sorry if I'm not making sense...
    In a nutshell: Is the period parameter always (for lack of a better term) retrospective?

    Thank You,
    Robert

    #2
    It sounds correct.

    You probably could have answered your question testing by the time it took you to write this up and for someone to respond...

    Comment


      #3
      Genius! Thanks Sledge!... ;>

      Comment


        #4
        Originally posted by RobVig View Post
        If I wrote MAX(High, 20)[10] does the period parameter always "look back"?
        Ex: From Bar[10] to Bar[30] ?
        [Edit: By the 'period parameter', I presume you mean the '20' passed to MAX as the 2nd argument. Because the '10' is part of the indexer, which is something different.]

        Yes, it always looks back, it cannot look forward. I mean, at the time of calculation, the indicator can only possibly look backwards at previous bars, along with the bar that just closed. It stores its calculated value in slot 0 and life goes on. More bars arrive, but this previously calculated value (is usually) not updated to reflect the arrival of these new bars -- it is an historical value which is now part of the permanent record of the chart -- because, like I said elsewhere, the mutability of values with indexers n > 0 is a feature not used by many indicators.

        Think carefully about what the indexer '[10]' must be doing.

        The value in the DataSeries at indexer '[10]' is the value of MAX(High, 20) from 10 bars ago. Well, at that time, 10 bars ago, when that value was calculated, the MAX indicator found the highest value in the High DataSeries for previous 20 bars, then stuffed that value away into (what was at that time) the slot at indexer '[0]'.

        Now, 10 bars have passed, but that same value in that slot is now historical and has not changed since it was calculated.

        So, yes, you are correct, MAX(High, 20)[10] represents the highest of the 20 bars from Bar [30] to Bar [10] ... notice I used oldest to youngest syntax.

        You could say from Bar [10] to Bar [30], but I've found it helpful to think about Bars in a mindset that maintains a left to right point of view -- it makes life easier for my brain -- the right most edge of the chart is bar creation, aka the current bar -- things always advance left to right on a chart, so to me this is Bar [30] to Bar [10].

        [Actually, it's not. I have not discussed your off-by-one error. When MAX(High, 20) looks back 20 bars, it looks at Bar [19] to Bar [0] because the current bar is always at indexer '[0]' ... just keep this in mind ... the BarsAgo index numbering starts at 0, not 1 ... so MAX(High, 20)[10] is the historical value stored 10 bars ago, which now, 10 bars later, is technically the highest value from Bar [29] to Bar [10]. For the most part, this off-by-1 distinction can be ignored, but when you start coding this stuff, you can't ignore it.]

        Originally posted by RobVig View Post
        Can I slide the period value in different directions / time?
        Of course, as long as there are enough previous bars on the chart to support the previously calculated value you're retrieving ... why not?

        As I mentioned here, don't say 'time', probably better to think in terms of 'age'.

        Originally posted by RobVig View Post
        Ex: using MAX(High, 20)[10] can I get the High from Bar[0] to Bar[20] ?
        Well, no, that example is incorrect. The historical value at indexer [10] could not possibly, at the time it was calculated, have known anything about the future bars now stored at Bar [9] to Bar [0], so your range is off a bit.

        [Edit: If you change the indexer [10] to [0] the range in your sentence is now applicable.]

        To retrieve the highest value for the last 20 bars, aka Bar [19] to Bar[0], you would use indexer '[0]', which is just MAX(High, 20)[0], just like from your first example.

        Originally posted by RobVig View Post
        Sorry if I'm not making sense...
        In a nutshell: Is the period parameter always (for lack of a better term) retrospective?
        Yes, think of the '20' for 'MAX(High, 20)' as the period. It always represents the set size of the historical values to use in the calculation, so the common term is "lookback", but period also works. In fact, "lookback period" is also common.

        [In actuality, the '20' is named to be whatever the author of the MAX indicator wants it to be named. I mean, argument names are the prerogative of the indicator author. But in the case of MAX, yes, it is a lookback period. Most indicators need to accept a period kind of argument, but it's certainly not required.]

        For the '[10]' part of 'MAX(High, 20)[10]', the '[10]' is the indexer and for that you should think "historical". The indexer '[10]' means the previously calculated value 10 bars ago, and that value has not changed, so it is now a "historical" value.

        That is, for EMA(x)[y] we have 'x' as the lookback period and 'y' is the indexer to retrieve the desired historical value of 'EMA(x)'.

        The same applies to MAX(High, x)[y].

        NinjaTrader calls 'y' the BarsAgo index, which makes perfect sense.
        Last edited by bltdavid; 06-08-2016, 04:02 PM. Reason: Added useful links

        Comment


          #5
          Originally posted by bltdavid View Post
          Think carefully about what the indexer '[10]' must be doing.
          What I am trying to point out is the actions taken by the code,

          Code:
          MAX(High, 20)
          vs

          Code:
          MAX(High, 20)[n]
          The addition of the indexer '[n]' means zero to few calculations are happening inside the indicator.

          The indexer '[n]' is a retrieval of a previously calculated value.

          MAX(High, 20) performs the calculation and stores the value at slot 0.

          MAX(High, 20)[n] retrieves a previously calculated value at slot n.

          [While not strictly true, this distinction is a good model for initial understanding, esp for newbies; it can help you when reading & understanding code. When doing actual C# programming, however, the steps required to satisfy the indexer '[n]' are more involved.]

          Comment


            #6
            David,

            Wow again... I'm so clear now and you saved me a heck of a lot of testing.

            Thank You!
            Robert

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Steve L, Today, 10:04 PM
            0 responses
            1 view
            0 likes
            Last Post Steve L
            by Steve L
             
            Started by marianfed, Today, 09:47 PM
            0 responses
            1 view
            0 likes
            Last Post marianfed  
            Started by hir04068, Today, 09:29 PM
            0 responses
            1 view
            0 likes
            Last Post hir04068  
            Started by iq200, 03-11-2018, 07:49 PM
            24 responses
            1,008 views
            0 likes
            Last Post mrlucky1x  
            Started by DavidHP, Today, 08:18 PM
            0 responses
            1 view
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Working...
            X