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 kevinenergy, 02-17-2023, 12:42 PM
              117 responses
              2,766 views
              1 like
              Last Post jculp
              by jculp
               
              Started by Mongo, Today, 11:05 AM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by SightCareAubetter, Today, 12:55 PM
              0 responses
              4 views
              0 likes
              Last Post SightCareAubetter  
              Started by traderqz, Today, 12:06 AM
              8 responses
              16 views
              0 likes
              Last Post traderqz  
              Started by SightCareAubetter, Today, 12:50 PM
              0 responses
              2 views
              0 likes
              Last Post SightCareAubetter  
              Working...
              X