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

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:
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Great thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          1 response
          7 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          7 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          5 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          385 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X