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

Draw.TextFixed() Multiple Instances

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

    Draw.TextFixed() Multiple Instances

    Hello,

    I want to display a few lines of text fixed in the top left corner of my chart window.

    I achieved this using the TextFixed() method and it is working fine as long as I am using it only once. Otherwise it will overlap the previous text.

    Is it possible to append text there or just draw the text below?

    Thanks in advance!

    Update: Achieved it by appending to one string and printing TextFixed() once. Anyway I wanted to print those lines in different colors which is not possible with my solution.

    Hope somebody knows how to do it!
    Attached Files
    Last edited by KlsKln; 08-09-2018, 03:50 AM.

    #2
    Hello KlsKln,

    Thanks for your post and welcome to the NinjaTrader forum!

    You can achieve your goals (multiple lines, multiple colors) by using certain escape characters (\n) to create a new line in the text and two (or more) instances of Draw.TextFixed(). I've attached a working example script to demonstrate the multiple lines ( I used 4 lines). With the example indicator, you can select any of the 5 locations and the lines will be created in order. I've also attached an example of the output.

    With this example, you can change the different method overloads to set/change the color/font (one per line) as needed.
    DrawTextFixedExample.zip
    Attached Files
    Last edited by NinjaTrader_BrandonH; 05-03-2023, 01:51 PM.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello KlsKln,

      Thanks for your post and welcome to the NinjaTrader forum!

      You can achieve your goals (multiple lines, multiple colors) by using certain escape characters (\n) to create a new line in the text and two (or more) instances of Draw.TextFixed(). I've attached a working example script to demonstrate the multiple lines ( I used 4 lines). With the example indicator, you can select any of the 5 locations and the lines will be created in order. I've also attached an example of the output.

      With this example, you can change the different method overloads to set/change the color/font (one per line) as needed.
      Hello Paul,
      thank you very much for your help and providing me an example! I tried it before with \n, but with no success. Now it worked after watching your example.

      Comment


        #4
        Hello, I just would like to confirm that it is ok to call Draw.TextFixed every time OnBarUpdate() is called. I think it should be fine, I'm just trying to track down a potential memory leak and want to know if this is safe, thanks

        Comment


          #5
          NinjaCustomer,

          You can call Draw.TextFixed every time OnBarUpdate() is called. The main considerations there would be the bar period and how much data was loaded on the chart.
          Josh G.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_PaulH View Post
            Hello KlsKln,

            Thanks for your post and welcome to the NinjaTrader forum!

            You can achieve your goals (multiple lines, multiple colors) by using certain escape characters (\n) to create a new line in the text and two (or more) instances of Draw.TextFixed(). I've attached a working example script to demonstrate the multiple lines ( I used 4 lines). With the example indicator, you can select any of the 5 locations and the lines will be created in order. I've also attached an example of the output.

            With this example, you can change the different method overloads to set/change the color/font (one per line) as needed.
            Please can you share the mentioned example indicator. I am trying get 5 lines printed on the chart, with an additional logic where, when a new line is added to the bottom the first top line needs to be deleted so that there are always latest 5 lines shown on the chart. If your example can denote that it would be great. Note all the 5 lines are different color.

            Comment


              #7
              Hello amul_shail2020,

              Paul's example is attached to post #2. If you do not see this attachment, please try clearing your browser cache.

              Paul's example demonstrates four lines, but you can quickly see how you can add a fifth line.

              Your logic would need to keep track of 5 strings for each line, where before you update one string with new content, you shift the strings over so the string for line 4 gets assigned to line 5's string, the string for line 3 gets assigned to line 4's string, and so forth until you need to update string 1 with new content.

              When looking over the example, please also reference the Draw.TextFixed documentation to see the additional overloads you can use, and how you can set a desired Brush to color each line of text.

              https://ninjatrader.com/support/help..._textfixed.htm

              If you are new to programming, the post below may help to give further direction to learn NinjaScript and C#.

              https://ninjatrader.com/support/foru...pts#post786040

              We look forward to assisting.
              Attached Files
              JimNinjaTrader Customer Service

              Comment


                #8
                Thanks NinjaTrader_Jim.
                I found it and was able to code the logic so that only 10 latest text lines are displayed on the chart.

                I had to use List array to store the 10 values and once I reach the 10th value in the List array I removed the top entry from the List arrary -

                private List<string> drwline = new List<string>(); //List array
                dspstrtxt = "EXAMPLE TEXT FOR EACH LINE " ; // Example text for
                drwline.Add(dspstrtxt); // Adding the line text to drwline list object

                cntlines++; // count how many line I am adding to the array.
                if(cntlines>=10){drwline.RemoveAt(0); } // Only last 10 lines to shown so remove the 1st line i.e. element from array, when new line is added

                Once I have each line text stored into the List array I used the following logic to draw them on the chart.

                #region Draw text lines on chart
                int index = 0;
                foreach (string value in drwline)
                {
                string nsbrk = new String('\n', index); // This will add the number of line breaks so that each line prints separately on next line.
                // Print("Line value of text = " + value + " nsbrk times = " + index + " TAG TEXT =" + dspstrtag + index);
                RemoveDrawObject(dspstrtag+index); // since this is keeping latest 10 lines make sure to remove the previous drawn object.
                Draw.TextFixed(this, dspstrtag+index, value + nsbrk, TextPosition.BottomRight, Brushes.Orange, new SimpleFont("Small Fonts", 15), Brushes.Transparent, Brushes.Transparent, 0);
                index++;
                }
                #endregion
                The above works as expected. I am sharing so that it will help someone if they every need to code something similar thing.

                Comment


                  #9
                  Originally posted by NinjaTrader_PaulH View Post
                  Hello KlsKln,

                  Thanks for your post and welcome to the NinjaTrader forum!

                  You can achieve your goals (multiple lines, multiple colors) by using certain escape characters (\n) to create a new line in the text and two (or more) instances of Draw.TextFixed(). I've attached a working example script to demonstrate the multiple lines ( I used 4 lines). With the example indicator, you can select any of the 5 locations and the lines will be created in order. I've also attached an example of the output.

                  With this example, you can change the different method overloads to set/change the color/font (one per line) as needed.
                  Does anyone have a copy of the sample script/code that Paul mentions in his post?
                  It would be very much appreciated if they could respond with it attached or do an inline paste in a response....

                  There does not appear any information anywhere else on how to get Draw.Textfixed to draw multiple lines of text and its details I need to assist with an indicator I am working on.
                  Any help much appreciated.

                  --
                  Andrew

                  FYI....
                  There does not appear to be any download link to grab the code and all the screen shots in the thread showing it is there do not translate through when viewing the post.

                  Comment


                    #10
                    Hello andrew-NT888,

                    Welcome to the NinjaTrader forums!

                    You will need to complete the forum registration process, by clicking the link sent to your email used for your forum user, before you will be able to download the file attached to post # 2.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello andrew-NT888,

                      Welcome to the NinjaTrader forums!

                      You will need to complete the forum registration process, by clicking the link sent to your email used for your forum user, before you will be able to download the file attached to post # 2.
                      HI Chelsea,

                      Much appreciate for you responding, warm welcome and details for steps to receive the script.

                      I went looking through the registered email account and cannot find an email to complete for the registration process.
                      Is it possible to trigger the system to resend it to me?

                      Thanks
                      Andrew

                      Comment


                        #12
                        Hi Andrew,

                        I'm not able to send that myself, and I've sent a request for our IT to resend this. Unfortunately, I haven't got a response for this just yet.
                        I appreciate your patience while I find a technician to resend this for you.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Andrew,

                          Our IT has stated that your forum account is registered.

                          May I confirm you are still unable to download the file attached to post # 2?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_ChelseaB View Post
                            Hello Andrew,

                            Our IT has stated that your forum account is registered.

                            May I confirm you are still unable to download the file attached to post # 2?
                            Hi Chelsea

                            Many thanks for organising my access to the forum so I can access the sample code files, very much appreciated!!!

                            I can confirm I have access to the file and have downloaded it!


                            Andrew

                            Comment


                              #15
                              Hi

                              Having looked at the same code, which was helpful, however I am still not there with achieving the outcome I am wanting for the indicator I have developed.

                              I am wanting to use Daw.TextedFixed to draw two text boxes in the top right of the chart.
                              I would like for the outcome to look like the image on the left as below, however, the code produces the outcome shown in the image on the right.


                              The code segment that creates the two text boxes is posted below.
                              The code will have logic added to fill the background colour of the two text boxes.
                              The two text boxes may have different coloured backgrounds at times and other times they may have the same colour (as determined by the indicator).

                              Any help would be much appreciated.


                              Andrew

                              Text myText1 = Draw.TextFixed(this, "5-minTF", "5-min" , TextPosition.TopRight);
                              Text myText2 = Draw.TextFixed(this, "15-minTF", "\n15-min", TextPosition.TopRight);


                              myText1.OutlineStroke.Brush = Brushes.Black;
                              myText1.OutlineStroke.DashStyleHelper = DashStyleHelper.Solid;
                              myText1.OutlineStroke.Width = 1;
                              //myText1.AreaBrush = FiveMinuteColour;

                              myText2.OutlineStroke.Brush = Brushes.Black;
                              myText2.OutlineStroke.DashStyleHelper = DashStyleHelper.Solid;
                              myText2.OutlineStroke.Width = 1;
                              //myText2.AreaBrush = FifteenMinuteColour;



                              Click image for larger version

Name:	image.png
Views:	28
Size:	42.9 KB
ID:	1298727

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gravdigaz6, Yesterday, 11:40 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by MarianApalaghiei, Yesterday, 10:49 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by XXtrader, Yesterday, 11:30 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post XXtrader  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              28 views
                              0 likes
                              Last Post love2code2trade  
                              Started by funk10101, Yesterday, 09:43 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post funk10101  
                              Working...
                              X