Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting a bar index and closing price to SharpDX vector.

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

    Converting a bar index and closing price to SharpDX vector.

    Hello.

    I've been jumping around in the documentation and playing around in my editor for about 2 hours trying to convert a bar index and closing price into a SharpDX vector coordinate but can't seem to get it to work.

    So I am wanting to use the rightmost bar that will work with scrolling, so I got the index via:
    Code:
    ChartBars.ToIndex
    I was able to get the closing price of that bar via:
    Code:
    Close.GetValueAt(ChartBars.ToIndex
    I see that I can find the bar index n-bars to the left of the right most bar via:
    Code:
    ChartBars.ToIndex-3
    I am wanting to get a position on the canvas, the SharpDX vectors. Just to get a vector for a start point, I tried:
    Code:
    float startX =  chartControl.GetXByBarIndex(ChartBars,ChartBars.ToIndex);
    float startY =  chartScale.GetYByValue(ChartBars.ToIndex);
    The above would just give me one point on the chart, but I am unsure if this is correct?

    Is there a preferred, simple way of converting a bar index, and a price to a vector?

    #2
    Had an epiphany, figured it out while sitting on the toilet. When I was printing out the vectors I thought I was printing, I realized that the bar index I was printing was changing, but the canvas point I was printing was not. I initially was thinking that something was wrong... but that they in fact should be moving as I scroll the chart... because I was printing a fixed location using the ToIndex. If all that sounds confusing... you can see the 2 vectors created below, and it in fact does what I want it to.

    This simply gives me the XY position of the right most bar on the chart, along with the position 5 bars prior to that value.

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    if (ChartBars != null)
     {
        float startX = chartControl.GetXByBarIndex(ChartBars,ChartBars.To Index-5);
        float startY = chartScale.GetYByValue(Close.GetValueAt(ChartBars. ToIndex));
    
        float endX = chartControl.GetXByBarIndex(ChartBars,ChartBars.To Index);
        float endY = chartScale.GetYByValue(Close.GetValueAt(ChartBars. ToIndex));
     }
    }
    Last edited by forrestang; 12-20-2020, 09:50 AM.

    Comment

    Latest Posts

    Collapse

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