Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tracking/Highlighting simple patterns

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

    Tracking/Highlighting simple patterns

    Hello,
    I would like to create a simple indicator that can compare the last X candles (for now let's say 3) and draw a rectangle around them (or highlight them in some way) if they meet specific criteria.
    For example:
    Click image for larger version  Name:	Capture.jpg Views:	0 Size:	25.2 KB ID:	1139964
    Above EMA13
    Bar1 above Bar2
    Bar3 above Bar2
    Bar2 1tick or more above EMA13

    Below EMA13
    Bar1 below Bar2
    Bar3 below Bar2
    Bar2 1tick or more below EMA13

    I have the concept of how to compare bars with High[x], Low[x], Open[x], Close[x] but I don't know how to draw a rectangle or highlight.

    Any assistance would be greatly appreciated.

    Thank you in advance for any help

    #2
    Hello WeyldFalcon, thanks for writing in.

    The easiest way to draw a rectangle to the chart will be with the Draw.Rectangle method documented here:

    https://ninjatrader.com/support/help..._rectangle.htm

    The simplest overload for Draw.Rectangle is :
    Draw.Rectangle(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush)

    So to draw the rectangle you will need to define the start bar, the start price, the end bar, and the ending price. The start will be the bottom left of the rectangle and the start will be the top right of the rectangle.

    Please let me know if I can assist any further.

    Comment


      #3
      This seems to draw a rectangle from one bar to another I would like the rectangle to encompass the 3 bars. but the value for the two "x" locations are INTs and based on candle location. Is there a way to draw rectangles around the bars or do I need a different method?

      Comment


        #4
        Hello WeyldFalcon, thanks for your reply.

        Draw.Rectangle is the only method that is needed here. The script must know 4 things before drawing the bar: the starting bar index, the ending bar index, the starting bar price, and the ending bar price. Please test out the method in a test script to draw at the desired levels.

        Please let me know if I can assist any further.

        Comment


          #5
          Hello Chris,
          When I use the Draw.Rectangle and set prices and bar index's this is what I get. Notice how the X coordinates are centered on the center of the bar? I am looking to have them be on either side of the bar so they completely encompass the 3 bars, not just the middle bar and half of the first and second bar. The red arrows is where the rectangle currently is, the blue arrows are where the rectangle should go to. The yellow rectangle encompasses the current bar like I am hoping to encompass the current bar and the 2 bars before it. The Yellow rectangle is an indicator by somebody else that uses RenderTarget.DrawRectangle is that what I need to use if I plan to encompass the 3 candles or am I missing something about Draw.Rectangle?
          Click image for larger version

Name:	Capture.jpg
Views:	263
Size:	9.3 KB
ID:	1140113

          Comment


            #6
            Hello WeyldFalcon, thanks for your reply.

            The rectangle drawn with Draw.Rectangle will always spawn from the middle of the bar because that is where the time stamp resides visually. If you need more precision you would need to employ the OnRender() method and use SharpDX to draw the rectangle. See the SampleCustomRender indicator within the platform for an example on drawing a rectangle at line 173.

            The idea will be to use GetXByBarIndex or GetXByTime to get the x value of the vector, then offset that by a few pixels to surround the entire bar. See also GetYByValue.

            Please let me know if you have any questions on this material.

            Comment


              #7
              Understood thank you.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              579 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 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
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X