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

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 cre8able, Today, 03:20 PM
          1 response
          9 views
          0 likes
          Last Post cre8able  
          Started by fiddich, Today, 05:25 PM
          0 responses
          3 views
          0 likes
          Last Post fiddich
          by fiddich
           
          Started by gemify, 11-11-2022, 11:52 AM
          6 responses
          804 views
          2 likes
          Last Post ultls
          by ultls
           
          Started by ScottWalsh, Today, 04:52 PM
          0 responses
          4 views
          0 likes
          Last Post ScottWalsh  
          Started by ScottWalsh, Today, 04:29 PM
          0 responses
          9 views
          0 likes
          Last Post ScottWalsh  
          Working...
          X