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

About the text format of DrawText method

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

    About the text format of DrawText method

    Dear all,

    I am dealing with a text problem. It is that if a want to display a 3*3 ( or other size)
    string matrix, for example

    string text = "aa b ccc\na bb c\naaa\nbb cc\n"
    while using DrawText method, we will get:

    aa_b_ccc
    a_bb_c
    aaa_bb_cc


    is there any way that we can get:

    aa___b___ccc
    a____bb__c
    aaa__bb__cc


    how to align each column like that?

    Thanks
    Last edited by keven; 02-18-2011, 06:37 PM.

    #2
    keven, not sure I follow - what is the difference exactly in your two examples? Could you please clarify for us?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Oh, sorry, my mistake. the system trim the redundant blanks between the strings automatically.
      let me use _ to replace blank. now the example looks like:

      aa_b_ccc
      a_bb_c
      aaa_bb_cc


      is there any way that we can get:

      aa___b___ccc
      a____bb__c
      aaa__bb__cc


      in other words, how to align the string of each column ?


      Thanks

      Comment


        #4
        Can you not just backpad your strings with spaces to force them to line up?

        Comment


          #5
          but the thing is I don't know the length of each string.

          do we have some method to set the field width of the string ?


          Thanks

          Comment


            #6
            You can align values in a string fairly easily using String.Format(),
            For example, if you want your values to be left padded every 5 spaces (For a,b,c values) you can do something like this:

            String.Format("{0, -5} {1, -5} {2, -5}", a,b,c)

            For Right aligned, use 5 instead of -5. This will work fine for any integer that is 5 characters or less, feel free to adjust to your needs as 5 might be too wide. You can use \n in the Format or string 3 of them together, whichever is more readable to you. I believe that should work as you desire with DrawText().

            edit: I typod (should be 0, 1, 2 like usual in {}) plus here's a full example!
            Code:
            protected override void OnBarUpdate()
            {
                int a = 123;
                int b = 321;
                int c = 12;            
                DrawText("textTag1", String.Format("{0, -5} {1,-5} {2,-5}", a,b,c), 0, Close[0], Color.Red);
                Plot0.Set(Close[0]);
            }
            Last edited by Dexter; 02-18-2011, 07:35 PM.

            Comment


              #7
              Oh, it works !

              Thanks very much for your help Dexter !

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by mishhh, 05-25-2010, 08:54 AM
              19 responses
              6,189 views
              0 likes
              Last Post rene69851  
              Started by gwenael, Today, 09:29 AM
              0 responses
              1 view
              0 likes
              Last Post gwenael
              by gwenael
               
              Started by Karado58, 11-26-2012, 02:57 PM
              8 responses
              14,829 views
              0 likes
              Last Post Option Whisperer  
              Started by Option Whisperer, Today, 09:05 AM
              0 responses
              1 view
              0 likes
              Last Post Option Whisperer  
              Started by cre8able, Yesterday, 01:16 PM
              3 responses
              11 views
              0 likes
              Last Post cre8able  
              Working...
              X