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 abelsheila, 05-14-2025, 07:38 PM
      2 responses
      31 views
      0 likes
      Last Post hglover945  
      Started by nailz420, 05-14-2025, 09:14 AM
      1 response
      57 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by NinjaTrader_Brett, 05-12-2025, 03:19 PM
      0 responses
      327 views
      1 like
      Last Post NinjaTrader_Brett  
      Started by domjabs, 05-12-2025, 01:55 PM
      2 responses
      62 views
      0 likes
      Last Post domjabs
      by domjabs
       
      Started by Morning Cup Of Trades, 05-12-2025, 11:50 AM
      1 response
      81 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Working...
      X