Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to tell the width of a bar?

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

    How to tell the width of a bar?

    How do you get the width one bar takes up? By that I mean the distance from the center of one bar to the center of the next bar. Alternatively, that could be expressed as the actual width of a bar plus the space between bars.

    The closest I have been able to come is ChartControl.GetBarPaintWidth(). That is the actual bar width, but it does not include the spacing between bars.

    ChartControl also has a BarWidth property, but it explicitly states the reported width is not in pixels and suggests using GetBarPaintWidth() instead (the graphics in the two documentations do not look alike). The problem with the BarWidth documentation is that it fails to say what unit the reported bar width is in. It is nice to know it is not pixels, but it would be even nicer to know what units it is in.

    --EV

    #2
    I had an idea after posting this question. The following works. at least assuming that bar spacing is equidistant. (A similar method could be used for non-equidistant bars in the area you care about -- just do it bar-by-bar and sum the results.)
    Code:
    int firstBarPainted = ChartBars.GetBarIdxByTime(cc, cc.FirstTimePainted);
    int barPixels = cc.GetXByBarIndex(ChartBars, firstBarPainted+1) - cc.GetXByBarIndex(ChartBars, firstBarPainted);
    Suggestions for a better solution are welcome. I won't be surprised if there is one, but the above does work.

    --EV
    Last edited by ETFVoyageur; 07-28-2016, 01:29 AM.

    Comment


      #3
      Originally posted by ETFVoyageur View Post
      I had an idea after posting this question. The following works. at least assuming that bar spacing is equidistant. (A similar method could be used for non-equidistant bars in the area you care about -- just do it bar-by-bar and sum the results.)
      Code:
      int firstBarPainted = ChartBars.GetBarIdxByTime(cc, cc.FirstTimePainted);
      int barPixels = cc.GetXByBarIndex(ChartBars, firstBarPainted+1) - cc.GetXByBarIndex(ChartBars, firstBarPainted);
      Suggestions for a better solution are welcome. I won't be surprised if there is one, but the above does work.

      --EV
      Code:
      ChartControl.Properties.BarDistance
      From the documentation:

      ref: http://ninjatrader.com/support/helpG...properties.htm

      Comment


        #4
        First, thank you

        Second, I am embarrassed that I overlooked that

        Third, I am puzzled by the result. I would think that with equidistant bars the result would be an integral number of pixels. My calculation shows 9 pixels, which visual inspection with pixie shows to be correct. The property, however, reports 9.380082 pixels. Why is the property not reporting an integral number of pixels? Are equidistant pixels not truly equidistant, and the property is reporting the average distance?

        --EV
        Last edited by ETFVoyageur; 07-28-2016, 09:37 AM.

        Comment


          #5
          Originally posted by ETFVoyageur View Post
          ...
          Third, I am puzzled by the result. I would think that with equidistant bars the result would be an integral number of pixels. My calculation shows 9 pixels, which visual inspection with pixie shows to be correct. The property, however, reports 9.380082 pixels. Why is the property not reporting an integral number of pixels? Are equidistant pixels not truly equidistant, and the property is reporting the average distance?

          --EV
          Not really. Remember that this new fancy NT is using SharpDX, which is just a .NET wrapper for DirectX, which can, and often uses, subpixel rendering. So, notice that the BarDistance property is a float, not an int. Does pixie show a float or an int? If pixie does not show pixels as floats, you have the answer.

          Comment


            #6
            I did notice that the property is a float, although I did not understand why it should be one. I just assumed it was an implementation detail.

            Pixie is not reporting a number -- I was using its magnifier, which shows the actual pixels painted on the screen, and counting the pixels myself. There were 7 pixels for the candlestick (5 for color, and one on each side for the outline), plus two pixels between candlesticks.

            Silly me -- I thought equidistant pixels would have the same separation between any two candlesticks. I just assumed (oops) that is what the "equal" part of equidistant meant. In fact, looking at several in a row with the magnifier I find that some have two pixels and some have three pixels separation. Literally equidistant they are not.. It would appear that the property is reporting the average distance, which obviously will not match any specific pair of candlesticks.

            I guess that if you care about the exact spacing between any two specific candlesticks, adjacent or not, you have to use my calculation instead of the property. Most times that will not matter, though, and the property will be fine.

            --EV
            Last edited by ETFVoyageur; 07-28-2016, 11:02 AM.

            Comment


              #7
              Equidistant spaces not exactly equidistant is probably because otherwise you might have 1/2 bar at the left edge if the chart does not have the correct amount of pixels due to the width of chart, right margin size, etc?
              eDanny
              NinjaTrader Ecosystem Vendor - Integrity Traders

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by sidlercom80, 10-28-2023, 08:49 AM
              170 responses
              2,271 views
              0 likes
              Last Post sidlercom80  
              Started by Irukandji, Yesterday, 02:53 AM
              2 responses
              17 views
              0 likes
              Last Post Irukandji  
              Started by adeelshahzad, Today, 03:54 AM
              0 responses
              3 views
              0 likes
              Last Post adeelshahzad  
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              3 views
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Working...
              X