Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MAX Function

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

    MAX Function

    I have gone over the help section and for the life of me, I don't understand how to use MAX and MIN. Please help.

    Here is the data:
    Bar# Open High Low Close
    0
    447.6 448.9 447.4 448.9
    1
    449.0 449.3 447.8 447.8
    2
    447.7 448.2 446.7 446.7

    j=CurrentBar-0;//0 is simply the first bar in the above data
    sw = File.AppendText(@FilePath);
    if(dExp.WCCIDirection[j] == 1)//1 = Long and -1 = Short
    sw.Write(","+Close[0]+","+MAX(High,j-1)+",,");//LONG
    else
    sw.Write(","+Close[0]+","+MIN(Low,j-1)+",,");//SHORT
    sw.Flush();
    sw.Close();

    The trade is Long and this triggers @ 447.4 in the middle of bar #2 having made its high for the bar, so j==2 and I would expect to get:

    ,447.4,449.3,, emphasis added, High of bars 1 and 2 (j-1 bars back)

    what I get is:

    ,447.4,MAX(High,1),, what happened to my double?


    If I substitute MAX(High,j-1)[0] I get:

    ,447.4,448.2,, Just I would expect (high of current bar)

    If I substitute MAX(High,j-1)[1] I get:

    ,447.4,449.3,, Just what I would expect (high of previous bar)

    and [2] returns 448.9, what I would expect.

    Please help.

    Snap
    Last edited by snaphook; 02-03-2009, 05:10 PM.

    #2
    Hi Snap, not sure I follow - so it seems to work as expected when you access the method with an index value like MAX(High,j-1)[0]? This is important to return a double value from it.

    Comment


      #3
      Exactly. When used with an index value it returns the lowest Low or the highest High of that Bar. I'm not sure how valuable that is because High[1] also returns the highest High of that bar, but that is another matter.

      If I simply use MAX(High,j-1) I expect to get the highest High of the past j-1 bars, however, it actually prints the MAX(High,1) characters, the 1 being the value of j-1.

      The example shows that using a [0] index I should get the highest High from the 0th bar (current bar) to the j-1 bar back (1 back), but I can't seem to get that. It returns the value of the current bar.

      Comment


        #4
        I think I figured out I am doing wrong. For others that may be as dense as I am,

        MAX(High,2)[0] considers the current bar [0] to be the 1st bar back and the [1th] bar to be the 2nd bar back. So the above will retrieve the highest High for the current and previous bar, not 2 bars back from the current bar.

        Comment


          #5
          Great you got it figured out, this will also depend on your CalculateOnBarClose setting - http://www.ninjatrader-support.com/H...BarClose1.html

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          152 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          89 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          133 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          127 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          107 views
          0 likes
          Last Post CarlTrading  
          Working...
          X