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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      127 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      72 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      112 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      109 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      88 views
      0 likes
      Last Post CarlTrading  
      Working...
      X