Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MAX and MIN Question

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

    MAX and MIN Question

    Just a quick question, if I wanted the strategy to close a position based on the close of the bar in relation to the last 5 bars, is this the proper use of MAX & MIN?

    if (Close[0] > MAX(High, 5)[0])
    {
    ExitShort("", "");
    }

    It compiles, but it doesn't work properly

    Also, if I wanted to use the last price, not the close, what is the code for last traded price?

    Thanks
    C

    #2
    Hi Canuck,

    That's the right idea but that particular statement will never trigger true. Close [0] cannot be greater than the highest high of last 5 bars since the bars you're looking at include it.

    Alternatives:
    if (Close[0] >= MAX(High, 5)[0]) //Checks if the close is greater than or equal to highest high in last 5 bars.

    if (Close[0] > MAX(High, 5)[1]) //Starts evaluating the 5-bar highest high starting at one bar prior to the close.

    Last price is Close[0] when CalculateOnBarClose = false.
    Last edited by NinjaTrader_RyanM1; 12-16-2010, 10:09 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan, that sounds exactly what I'm looking for!

      Comment


        #4
        Hi RyanM

        If CalculateOnBarClose = true and if I want to check that

        -the bar PRIOR to the last closed bar is green (bullish candle) OR
        -that the last closed bar has a high that is <= the high of the prior bar

        would the following code snippet be correct?

        Thanks

        if ((Open[1]>=Close[1]) || (High[0] <= MAX(High, 1)[0]))
        {
        BoolFlagLong = true;
        }

        Comment


          #5
          Hi laocoon,

          The first condition matches your description. For your second condition, you can use:
          Close[0] <= High[1]

          High[0] and MAX(High, 1)[0] will be the same value.
          Last edited by NinjaTrader_RyanM1; 12-20-2010, 04:30 PM.
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

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