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 cmoran13, 04-16-2026, 01:02 PM
    0 responses
    51 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    31 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    165 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    100 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    160 views
    2 likes
    Last Post CaptainJack  
    Working...
    X