Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to anchor Grid control to chart

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

    How to anchor Grid control to chart

    Hello,

    In my indicator I would like to print bar related information to the chart, and I decided to create a grid control where each column will display the information from the bar above. On each new bar, the grid will receive an additional column. It should look something like this:https://postimg.org/image/phcafc07n/

    I added the grid to the UserControlCollection but the issue which I'm facing is that the grid does not scroll back and forth with the chart. It is anchored to the bottom left corner through Horisontal/VerticalAlignments. Is there a way to achor this grid to the first visible bar or time?

    I also tried to draw just a text instead of grid, but the issue there is that the text is anchored to price and time and I need it on the bottom of the chart (only time/bar anchoring).

    Do you have any suggestions how to achieve this?

    Thank you!

    #2
    Hello deeven,

    The UserControlCollection is overlayed on top of the script and would require you add your own grid to this. This would not be a grid that lines up with the chart, this would be overlayed on top of it as a separate layer.

    Instead, if you want to have intervals at fixed points on the chart that move when you scroll this would all have to be custom rendered (and custom calculated) in OnRender().
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for the quick response. I've tried the RenderTarget.DrawText but the text seems also to be static on specific coordinates on the chart. This the code snipped I used:

      Code:
      // define the point for the text to render
                  SharpDX.Vector2 startPoint = new SharpDX.Vector2(200, 400);
      
                  // construct the text format with desired font family and size
                  SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Arial", 26);
      
                  // construct the rectangleF struct to describe the position and size the text
                  SharpDX.RectangleF rectangleF = new SharpDX.RectangleF(startPoint.X, startPoint.Y, 200, 30);
      
                  // define the brush used for the text
                  SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue);
      
                  // execute the render target text command with desired values
                  RenderTarget.DrawText("I am some text", textFormat, rectangleF, customDXBrush);
      What am I missing here?

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Instead, if you want to have intervals at fixed points on the chart that move when you scroll this would all have to be custom rendered (and custom calculated) in OnRender().
        http://ninjatrader.com/support/helpG.../rendering.htm
        Would you please give me a very simple example?

        Thank you!

        Comment


          #5
          Hello deeven,

          If you have a specific bar you would like to calculate from you can use ChartControl.GetXByBarIndex() and ChartScale.GetYByValue() to covert the bar num and price to x and y values.

          ChartControl.GetXByBarIndex() - http://ninjatrader.com/support/helpG...bybarindex.htm
          ChartScale.GetYByValue() - http://ninjatrader.com/support/helpG...etybyvalue.htm

          Use these x and y values for the rendered object and this will give the updated coordinates of the bar as it moves allowing the rendered object to scroll with the chart.

          I wasn't able to find an easy to follow example so I've created one and attached.
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thank you very much Chelsea! This helps a lot!

            Comment


              #7
              Hello deeven,

              That is intentional.

              Remove '!IsInHitTest' from line 82.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jclose, Today, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,413 views
              0 likes
              Last Post Traderontheroad  
              Started by firefoxforum12, Today, 08:53 PM
              0 responses
              11 views
              0 likes
              Last Post firefoxforum12  
              Started by stafe, Today, 08:34 PM
              0 responses
              11 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by sastrades, 01-31-2024, 10:19 PM
              11 responses
              169 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X