Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a box or line around a specific number of bars.

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

    Drawing a box or line around a specific number of bars.

    Hello,

    I see in the help how to draw horizontal lines, but I would like to draw a box around a specific number of bars (to identify custom patterns) and have that drawing stay with those bars. After searching here I found plenty on drawing horizontal lines, but how would I draw the sides to close it into a box and have it stay on those bars? Maybe I am not searching the right terms. If you could point me to a post that would be great, thank you.

    #2
    Hello HaveGunsWillTravel,

    Thanks for your post.

    If you are wanting to draw a box or rectangle, you could consider using Draw.Rectangle() to draw a rectangle on the chart.

    See this help guide documentation for more information about Draw.Rectangle(): https://ninjatrader.com/support/help..._rectangle.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      [QUOTE=NinjaTrader_BrandonH;n1181140]Hello HaveGunsWillTravel,
      Ha! Go figure, I saw draw line and got saturated on that thinking I need to draw four... Thanks again.

      Comment


        #4
        am struggling...
        Originally posted by NinjaTrader_BrandonH View Post
        Hello HaveGunsWillTravel,

        Thanks for your post.

        If you are wanting to draw a box or rectangle, you could consider using Draw.Rectangle() to draw a rectangle on the chart.

        See this help guide documentation for more information about Draw.Rectangle(): https://ninjatrader.com/support/help..._rectangle.htm

        Let us know if we may assist further.
        Should this be working? i am having some trouble...

        protected override void OnBarUpdate()
        {
        //Want to draw rectangle around these bars if they occur
        if((Close[0] < Close[1]) && (Close[1] < Close[2]) && (Open[0] > Open[1]) && (Open[1] > Open[2]))
        Draw.Rectangle(this, "iii", 2, Low[2] - TickSize, 0, High[0] + TickSize, Brushes.White);
        }
        }

        Comment


          #5
          Hello HaveGunsWillTravel,

          Thanks for your note.

          When the condition to draw the rectangle becomes true, the rectangle will be drawn on the chart.

          I have tested your Draw.Rectangle() method without the condition and the rectangle is drawn on the chart without issue. See the attached example strategy.

          To understand why the script is behaving as it is, such as drawing objects or not drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

          In the script, add prints (outside of any conditions) that print the values of every variable used in every condition along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

          Below is a link to a forum post that demonstrates how to use prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121

          Please let me know if I may further assist
          Attached Files
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            [QUOTE=NinjaTrader_BrandonH;n1181213]Hello HaveGunsWillTravel,

            Thank you! I think I got it working now...

            Comment

            Latest Posts

            Collapse

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