Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Look back

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

    Look back

    Hey all,

    I'm a bit confused as how to do a look back for a period of bars.

    example; say I want to make a plot cycle code,

    if current high is > the Highest high (10 bars back) and down close
    {drawdots}

    How do I reference this in C# to look back at the last 10 bars?

    Thanks in advance.

    #2
    MAX(High, 10)[0] <-- returns the highest high value from the last 10 bars
    MAX(High, 10)[10] <-- returns the highest high value from the 10 bars prior to 10 bars ago.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Make perfect sense. Thanks Josh.

      Comment


        #4
        Code works fine when I state if(Open[0] > Close[0])
        but when I put in the MAX(high,5)[0] nothing plots. I'm confused as to why this does not work out.

        Code:
         {
        	if (High[0]> MAX(High, 5)[0] && Open[0] > Close[0])
        	   {
        		
         DrawDot("My dot" + CurrentBar, true, 0, High[0] + TickSize, Color.Yellow);
                    }
                }

        Comment


          #5
          The current bar High will never be greater than the current bar High, hence no plot. But it can be equal to it.

          Try

          if (High[0]>= MAX(High, 5)[0] && Open[0] > Close[0])

          so High is = to highest high of the bar

          Comment


            #6
            Thanks Velocity

            Works perfect, Just wondering why this statement wouldn't work as well?

            if (High[0]> MAX(High, 5)[1] && Open[0] > Close[0])

            Comment


              #7
              Technically it should work, but if you are going to use an [1] index please be sure that you have enough bars. http://www.ninjatrader-support2.com/...ead.php?t=3170
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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