Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw same width as BarWidth

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

    Draw same width as BarWidth

    Hi. I'm trying to draw a rectangle in the future (barsAgo = -1) that has same width as the bars. I'm using Draw.Line() rather than Draw.Rectangle().

    Code:
    Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, (int) ChartControl.BarWidth);

    According to the docs ChartControl.BarWidth and the Draw.Line's width parameter both are in pixels. I assumed the drawn line would have similar width to the bars but it doesn't.

    I tried converting application pixels to device pixels--

    Code:
    int devicePixelsWidth    = ChartingExtensions.ConvertToHorizontalPixels(ChartControl.BarWidth, ChartControl.PresentationSource);
    Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, devicePixelsWidth);

    The result didn't change.

    Re-scaling, reloading, whatever the width of the bars, the line is always narrower.

    Click image for larger version

Name:	bars.png
Views:	420
Size:	732 Bytes
ID:	1099709

    #2
    Hello digibob,

    Thank you for your note.

    It appears that the BarWidth parameter is the width in pixels of each side of the bar from the center to the outer edge. There's actually two ways to fix this: First, you can just multiply ChartControl.BarWidth by 2 and that should work:

    Code:
               Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, (int) (ChartControl.BarWidth *2));
    Or, more directly, ChartControl.GetBarPaintWidth() will get you the full bar paint width:

    Code:
                double barPixelWidth = ChartControl.GetBarPaintWidth(ChartControl.BarsArray[0]);
                Draw.Line(this, "rect", false, -1, Open[0], -1, Close[0], Brushes.Cyan, DashStyleHelper.Solid, (int) (barPixelWidth));
    Either one of those options should work for you.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hi Kate. Perfect. Many thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X