Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to find if current bar is highest from last 50?

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

    How to find if current bar is highest from last 50?

    Hello Ninjatrader family,

    I'm trying to draw a line horizontally if current bar is highest of the last 50 bars and vice versa the lowest.

    How do I plot a horizontal line and identify the bar that is the highest and lowest of the last 50 bars?

    #2
    Hello priceisking,

    Thanks for your post.

    To check if the current bar [0] is higher that the previous 50 bars: if (High[0] > MAX(High, 50)[1]) For the other side you would use Low[0] and Min(50)[1]. Note that in both bases the Min and Max need to start at the previous bar [1], if you use [0] then the current high could never be higher than [0] as it would be equal.
    References:



    To identify the high or low bar, you would use HighestBar() and LowestBar(): Please see the help guide for examples.
    References:



    You can use the Draw.HorizontalLine() method which only requires the Y (price) value to draw the line, you do not need the bars ago.
    Reference:


    If you want to draw a line that does not extend backwards and forwards forever but is horizontal, then you would use Draw.Line() where you specify a begin and end price (Y value) that would be the same for a horizontal line but you would need to specify a begin bars ago and end bars ago to draw that line between.
    Reference:

    Comment


      #3
      Thank you Paul. This is great info. Also, quick question regarding the line. Say the following bar became the highest or lowest , how would I remove the line drawn and replace it with the new line withe high/low price?

      Basically what i want to do is draw a horizontal line when bar is the highest and then remove it when it finds the next highest. .. .and vice versa.

      Comment


        #4
        Hello priceisking,

        Thanks for your reply.

        You can automatically move a line by drawing it with new coordinates and using the same tag name. When the same tag name is used, the previous object created is automatically removed first and then the new object would be drawn with your new coordinates. This is a function of all draw objects.

        Comment


          #5
          Great thank you!

          Comment

          Latest Posts

          Collapse

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