• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


TEXT object at 90 degrees?

  • Filter
  • Time
  • Show
Clear All
new posts

    TEXT object at 90 degrees?

    I would like to draw a text on the chart at 90 degrees.
    I do not know if NinjaScript allows you to do this.
    For example I can print TEST object with
    PHP Code:
    DrawText("text"false"text in 0 degree"Time[20], Close[20]-100*TickSize10Color.Blue, new Font ("Arial"12FontStyle.Bold), StringAlignment.CenterColor.BlackColor.Yellow5); 

    but.... I want to draw the TEST object at 90 degrees or 45 degrees, as I can do with metaquote language for Metatrader
    Is it possible to do it with NinjaScript C# based?
    If so, how?


    Hello Umberto,

    Thank you for your post.

    This is not possible with the current DrawText object. However, this can be done using custom drawing in the Plot() method.

    Please note that this is not supported programming but you can view a sample of the Plot by going to Tools -> Edit NinjaScript -> Indicator -> Custom Plot Sample

    You can also review the Graphics class from the MSDN article below -
    Cal H.NinjaTrader Customer Service


      In the reported indicator and at the MSDN link I have not found a complete example of how to print a text in X degrees.
      I have not found anything that can be done with a few lines of code ...
      Is it possible that no developer needs to print on a chart a short sentence at 90 or X degrees?
      ... Or perhaps with C #, to be able to print an oblique phrase it is necessary to write dozens of lines of code?
      Last edited by umbertosm; 04-05-2015, 11:56 AM.


        With a custom plot this is pretty easy to do.

        You need to know the (x,y) position of the text on your chart. Then within the custom plot you basically need to follow the steps as shown below

        //Save the current graphics state
        GraphicsState state =  graphics.Save();
        //Translate to desired position on chart
        graphics,TranslateTransform(x, y, MatrixOrder.Append);
        //Draw Text at origin of chart
        graphics.DrawString(text, textFont, textBrush, 0, 0, stringFormat);
        //Restore the graphics state
        It is important to apply rotation first, then translation before drawing the string at the origin.

        I had never done this before (do not know what it is good for ....), but the chart below shows that it is easy to do. All the labels are now shown in 45 degrees, Just for fun.
        Attached Files


          Function to create rotated text at any position and angle

          As Harry stated, if one knows what to do, it is actually relatively easy to create rotated text. Thanks to his suggestions, a function which can be called to place text at a specified location with specified rotation was created. A indicator, dfExampleRotatedText.zip, demonstrating its use is attached.

          HTML Code:
          private StringFormat            stringFormat    = new StringFormat();
          private SolidBrush              textBrush       = new SolidBrush(Color.Black);
          private System.Drawing.Font     textFont        = new Font("Consolas", 10);
          string RotatedText(Graphics gptr, string text, float x, float y, float rot)
              // Function to create rotated text
              // Requires stringFormat, textBrush and textFont to be defined.
              return text;
          Attached Files


            Thanks for the info, but I need to draw a text in a DateTime of a bar, not in an X position or bar number.

            Any idea?

            Thank you


              Hello ninjo,

              These sort of custom rendering implementations are not supported so community input may be your best resource for such applications.

              Custom plotting will need to be given actual coordinates. You may be able to use ChartControl.GetXByTime to get a proper coordinate. Since ChartControl is not documented in NinjaTrader 7, our best advise would be to use Intellisense to see what code is available and to to test and see if you can make use of that code.

              Using Intellisense in the NinjaScript Editor - https://ninjatrader.com/support/help...tellisense.htm

              I'll leave this thread open ended for any community members who can comment further.
              JimNinjaTrader Customer Service


                Thank you Jim.

                Excuse me. I am coding in Ninjatrader 8.
                I want to draw the text with 90º in a determinate bar (not in a X chart possition). Its posible? Thank you


                  Hello ninjo,

                  I've attached an example that demonstrates how you can rotate the RenderTarget, draw some text, and then to rotate the RenderTarget back. There are several items to note when using SharpDX rendering since you will have to dispose of any device dependent resources after each render pass or on RenderTarget changes. We have a SampleCustomRender indicator that demonstrates SharpDX rendering and I've included links to some useful documentation.

                  SharpDX Rendering - https://ninjatrader.com/support/help..._rendering.htm

                  Best Practices for SharpDX Rendering - https://ninjatrader.com/support/help...arpDXResources

                  Rendering to certain bars/prices in NinjaTrader 8 will require referencing the bar by its index, (not a BarsAgo index) with ChartControl.GetXByBarIndex() and to use ChartScale.GetYByValue() to convert a price level to a Y coordinate. It is also recommended to only render what is visible between ChartBars.FromIndex and ChartBars.ToIndex. An example loop is provided in the FromIndex documentation.

                  ChartControl.GetXByBarIndex() - https://ninjatrader.com/support/help...bybarindex.htm

                  ChartScale.GetYByValue() - https://ninjatrader.com/support/help...etybyvalue.htm

                  ChartBars.FromIndex - https://ninjatrader.com/support/help..._fromindex.htm

                  Please let us know if we can be of further assistance.
                  Attached Files
                  JimNinjaTrader Customer Service


                    Hi Jim,
                    Thank you for the script, but this example its the same that dfogg script. The text is fixed to the chart.
                    I need that the text move with the bar series like the Draw.Text() function do.

                    Thank you !


                      Hello Ninja,

                      Custom rendering draws to coordinate space which is what the drawing tools ultimately do. You will need to loop through bar indexes to draw to a certain bar with SharpDX rendering. Please see the ChartControl.GetXByBarIndex() and ChartScale.GetYByValue() linked in my last post to convert bar indexes to coordinates.

                      Please let us know if you have any questions.
                      JimNinjaTrader Customer Service


                        All right Jim, I am goin to try.
                        Thank you very much for all the info.


                        Latest Posts


                        Topics Statistics Last Post
                        Started by ralett, Today, 11:52 AM
                        0 responses
                        Last Post ralett
                        by ralett
                        Started by rtwave, Yesterday, 07:06 PM
                        1 response
                        Last Post NinjaTrader_PaulH  
                        Started by DTSSTS, Today, 11:27 AM
                        1 response
                        Last Post NinjaTrader_ChelseaB  
                        Started by siroya, Today, 10:02 AM
                        2 responses
                        Last Post DTSSTS
                        by DTSSTS
                        Started by pjsmith, Today, 10:50 AM
                        0 responses
                        Last Post pjsmith
                        by pjsmith