Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get coordinates of the subwindow and not the whole chart

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

    How to get coordinates of the subwindow and not the whole chart

    I want to draw a "table" in an indicator subwindow, but my coordinates are based on the main chart and not the subwindow chart

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
    
                if (Bars == null || ChartControl == null)
                    return;        
    
                  base.OnRender(chartControl, chartScale);
    
                // Get the render target for the chart
                //SharpDX.Direct2D1.RenderTarget RenderTarget = chartControl.CreateRenderTarget();
    
                // Set the font size and style for the table
                RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
                RenderTarget.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;
                SharpDX.DirectWrite.Factory dwFactory = new SharpDX.DirectWrite.Factory();
                TextFormat textFormat = new TextFormat(dwFactory, "Arial", 8f);
    
                // Set the cell width and height for the table
                float cellWidth = 30f;
                float cellHeight = 10f;
    
                // Set the starting position for the table
                float x = 10f;
                float y = 10f;
                // Draw the table header
                RenderTarget.DrawText("Column 1", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                x += cellWidth;
                RenderTarget.DrawText("Column 2", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                x += cellWidth;
                RenderTarget.DrawText("Column 3", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                x += cellWidth;
                RenderTarget.DrawText("Column 4", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                x += cellWidth;
                RenderTarget.DrawText("Column 5", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                y += cellHeight;
    
                // Draw the table rows
                SharpDX.Direct2D1.Brush myBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, new Color4(0.9f, 0.9f, 0.9f, 1.0f)); // light gray
                for (int i = 1; i <= 21; i++)
                {
                    x = 10f;
                    RenderTarget.FillRectangle(new RectangleF(x, y, cellWidth, cellHeight), myBrush);
                    RenderTarget.DrawText("R" + i.ToString() + "C1", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                    x += cellWidth;
                    RenderTarget.DrawText("R" + i.ToString() + "C2", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                    x += cellWidth;
                    RenderTarget.DrawText("R" + i.ToString() + "C3", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                    x += cellWidth;
                    RenderTarget.DrawText("R" + i.ToString() + "C4", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                    x += cellWidth;
                    RenderTarget.DrawText("R" + i.ToString() + "C5", textFormat, new RectangleF(x, y, cellWidth, cellHeight), Brushes.Red.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap, MeasuringMode.GdiClassic);
                    y += cellHeight;
                }
                myBrush.Dispose();
    
                // Dispose of resources
                textFormat.Dispose();
                dwFactory.Dispose();
                //RenderTarget.Dispose();
            }​
    this is my WIP code that I have been playing with

    but it draws the table in the top left of the whole chart, so I have to pull my subwindow up in order to see the table, I want the table to be fixed to the subwindow, so if I increase the size of the subwindow, it will follow the subwindow

    of course by subwindow I mean IsOverlay=false;


    #2
    Hello LuxSpuzy,

    Your indicator would need to be in that sub panel for OnRender and the methods to get or set values in that sub panel. The OnRender override refers to the panel where the script is applied and the scale being used in the indicators settings.

    The X and Y you are using are not based on the sub panel, you are just using 10 for the x and y. To know the panels bounds and make actual x/y values you need to reference the indicators ChartPanel property: https://ninjatrader.com/support/help...chartpanel.htm

    ChartPanel.X and ChartPanel.Y would be needed to find the panels top left, to find the actual width or height of the panel you would need to add the W and H properties to the X and Y values.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    561 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