Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Bar prices in drawing tool?

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

    How to get Bar prices in drawing tool?

    Hello, I'm trying to create a custom Anchored VWAP drawing tool and have gotten to the point of being able to click on the chart and get the bar index of my click. How can I get the Bar prices of that index #? I tried, Bars.GetLow(barNumber) but it gives me an error "An object reference is required for the non-static field method or property 'Bars.GetLow(int)'"

    I need the OHLC prices to calculate VWAP and to anchor the drawing tool to the VWAP value of that bar

    Here is my code for my OneMouseDown() method:
    Code:
    public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
            {
                switch (DrawingState)
                {
                    case DrawingState.Building:
                        if (StartAnchor.IsEditing) // if this is the first click on the chart
                        {
                            dataPoint.CopyDataValues(StartAnchor); // Set the StartAnchor's time and price to the mouse click
                            
                            StartAnchor.IsEditing = false; // Marks the start anchor is placed
                            double doublebarNumber = StartAnchor.SlotIndex; // Get the bar index of the click
                            int barNumber = (int)Math.Round(doublebarNumber); // Convert it to an int cause its a double even though its a whole number
                            Print("Bar # Clicked on: " + barNumber);
                            
                            // Get the low of barNumber (stuck here)
                            //double barLow = ChartBars.Bars.GetLow(barNumber); // Error
                            double barLow = Bars.GetLow(barNumber); // Error "An object reference is required for the non-static field method or property 'Bars.GetLow(int)'"
                            Print("Clicked BarLow: " + barLow);
                            
                        }
                        break;    
                }
            }​
    I also tried to copy and paste the example for Bars.GetLow() which is placed inside the OnRender() method but I get the same error trying to compile that example

    Anyone have a solution? I'm sure someone has done this before.
    Attached Files

    #2
    Hello,

    Thank you for your post.

    Have you used GetAttachedToChartBars() first, then called .GetLow() on the bars object?

    Comment


      #3
      Hi Gaby, that did it, thanks so much!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      547 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      323 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      99 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      543 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      545 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X