• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TEXT object at 90 degrees?

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

    TEXT object at 90 degrees?

    hello,
    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?

    thanks,
    Umberto

    #2
    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 -
    https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      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.

      Comment


        #4
        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

        Code:
        //Save the current graphics state
        GraphicsState state =  graphics.Save();
        graphics.ResetTransForm();
        //Rotate
        graphics.RotateTransform(angle);
        //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
        graphics.Restore(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

        Comment


          #5
          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.
              gptr.TranslateTransform(x,y);
              gptr.RotateTransform(rot);
              gptr.DrawString(text,textFont,textBrush,0,0,stringFormat);
              gptr.ResetTransform();
              return text;
          }
          Attached Files

          Comment


            #6
            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

            Comment


              #7
              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

              Comment


                #8
                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


                Comment


                  #9
                  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

                  Comment


                    #10
                    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 !

                    Comment


                      #11
                      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

                      Comment


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

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ArchakovDenis, Today, 03:32 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post ArchakovDenis  
                        Started by Botan626, Today, 01:22 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_JoshG  
                        Started by bdelorm, Today, 12:46 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_PatrickG  
                        Started by JulieV, Yesterday, 04:41 PM
                        2 responses
                        32 views
                        0 likes
                        Last Post JulieV
                        by JulieV
                         
                        Started by YakusaTrader, Yesterday, 04:30 PM
                        1 response
                        15 views
                        0 likes
                        Last Post NinjaTrader_PaulH  
                        Working...
                        X