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 StockTrader88, 03-06-2021, 08:58 AM
              45 responses
              3,992 views
              3 likes
              Last Post johntraderuser2  
              Started by TAJTrades, Today, 09:46 AM
              0 responses
              7 views
              0 likes
              Last Post TAJTrades  
              Started by rhyminkevin, Yesterday, 04:58 PM
              5 responses
              62 views
              0 likes
              Last Post dp8282
              by dp8282
               
              Started by realblubb, Today, 09:28 AM
              0 responses
              8 views
              0 likes
              Last Post realblubb  
              Started by AaronKoRn, Yesterday, 09:49 PM
              1 response
              19 views
              0 likes
              Last Post Rikazkhan007  
              Working...
              X