Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I draw a rectangle around the bid and ask low of a volumetric bar?

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

    How do I draw a rectangle around the bid and ask low of a volumetric bar?

    I've tried using the below, but get the red rectangle in the attached image. The yellow is what I would like to see.
    Code:
    Draw.Rectangle(this, "rect" + CurrentBar, 1, Low[0] + 0.125, 0, Low[0] - 0.125, Brushes.Red);
    I also was playing around with SharpDX.RectangleF, but couldn't figure out how to do it with it.
    Code:
    float x = chartControl.GetXByBarIndex(ChartBars, CurrentBar);
    
    SharpDX.RectangleF rectangleF = new SharpDX.RectangleF(x, x, 10, 10);
    SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Blue);
    RenderTarget.DrawRectangle(rectangleF, brush);​
    Attached Files

    #2
    Hello wally,

    Thanks for your note.

    The Draw.Rectangle method is designed to draw a rectangle from the middle of one bar to the middle of the next bar.

    You would need to use SharpDX in OnRender() along with your own custom logic to draw a rectangle in the specific section highlighted in yellow in the screenshot you shared.

    The SampleCustomRender indicator script that comes default with NinjaTrader demonstrates how RenderTarget.DrawRectangle() could be used in a NinjaScript.

    Also, see the help guide documentation linked below for more information.

    Using SharpDX for custom chart rendering: https://ninjatrader.com/support/help..._rendering.htm
    RenderTarget.DrawRectangle(): https://ninjatrader.com/support/help...wrectangle.htm

    Please let me know if I 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
      Thanks. For reference, the below is a snippet of what I ended up doing.

      Code:
                  float close = chartScale.GetYByValue(Bars.GetClose(Bars.Count - 1));
                  float nextCloseTick = chartScale.GetYByValue(Bars.GetClose(Bars.Count - 1) - .25);
                  float barWidth = chartControl.GetBarPaintWidth(chartControl.BarsArray[0]);
                  float height = Convert.ToSingle(close - nextCloseTick);
                  float width = Convert.ToSingle(barWidth - barWidth * .06);
                  float x = chartControl.GetXByBarIndex(ChartBars, CurrentBar) - (width / 2);​
      
                  float x = chartControl.GetXByBarIndex(ChartBars, CurrentBar) - ((width / 2));
                  // Draw Low
                  //float y = Convert.ToSingle(chartScale.GetYByValue(Bars.GetLow(Bars.Count - 1) - .125));
                  // Draw High
                  float y = Convert.ToSingle(chartScale.GetYByValue(Bars.GetHigh(Bars.Count - 1) - .125));
      
                  SharpDX.RectangleF rect = new SharpDX.RectangleF(x, y, width, height);
                  SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Red);​​
      Last edited by walley; 03-18-2023, 07:21 AM.

      Comment


        #4
        The current snippet draws the triangle on the current bar and does not save when a new bar is formed. Is there a way to save the rectangle on the bar when a new bar is formed? I know that tags are included with Draw.Rectangle, but I'm not finding anything similar with SharpDX..

        Comment


          #5
          Hello walley,

          The logic would need to call RenderTarget.DrawRectangle() twice, one for each of the two rectangles.

          You could save these in an array if you want to refer back to these objects after they have been created.

          Below are links to scripts that may give you some ideas.
          This is a conversion of the Realtime Level II/Tick Volume. Please contact the original author for any questions or comments. Update Aug 27th, 2018: Since OnRenderTargetChanged can be called before State.DataLoaded, setting the dxmBrushes["backColor"].MediaBrush here wasn&apos;t working out and was sometimes null. Changed this to now get the chart background color (and text color) from [&#8230;]

          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          572 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
          550 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X