Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

String Functions on User Parameters

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

    String Functions on User Parameters

    I'm considering combining 2 Integer user parameters of "10" and "50" into one String user parameter of "10/50" then using script to split them back into the Integers of "10" & "50". Does NT have methods to do this?

    #2
    Hello,

    Thanks for the note.

    You can convert them to string by using interger1.ToString();

    However I do not know of any method to turn a string back into an integer. Would suggest not doing this and instead keeping the integers stored as integers for reference when you need it again.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Originally posted by DenMan View Post
      I'm considering combining 2 Integer user parameters of "10" and "50" into one String user parameter of "10/50" then using script to split them back into the Integers of "10" & "50". Does NT have methods to do this?
      Use the string functions to split the string, then parse them separately.

      ref: http://msdn.microsoft.com/en-us/library/bb397679.aspx

      Comment


        #4
        I'd like a little help on splitting the string. I've tried the following code, but it isn't correct.

        privatestring sMI_Periods ="5/1/1/4/2";

        string[] sMI_Periods.Split("/");
        foreach (string sMI_Period in sMI_Periods)

        This looks just like the examples I'v found on the internet, but I'm missing something.

        Comment


          #5
          Originally posted by DenMan View Post
          I'd like a little help on splitting the string. I've tried the following code, but it isn't correct.

          privatestring sMI_Periods ="5/1/1/4/2";

          string[] sMI_Periods.Split("/");
          foreach (string sMI_Period in sMI_Periods)

          This looks just like the examples I'v found on the internet, but I'm missing something.
          1. Your second line does not declare the string array into which you are splitting the initial string.
          2. A char is not a string of length 1; a char is encased with single quotes, not the double quotes used to encase a string.
          3. sMI_Periods was declared as a string; you cannot just use it as an Array in line 3.

          Code:
          string sMI_Periods = "5/1/1/4/2";
          
          string[] SplitArray = sMI_Periods.Split('/');
          foreach (string sMI_Period in SplitArray) ...
          Last edited by koganam; 10-20-2011, 06:23 PM.

          Comment


            #6
            Thanks for your suggestions! I've decided to use the following script and it's working fine:

            privatestring sMI_Prds = "5/1/1/6/2";
            privateint sMI_Prd1 = 0;
            privateint sMI_Prd2 = 0;
            privateint sMI_Prd4 = 0;
            privateint sMI_Prd5 = 0;

            sMI_Prd1 = Convert.ToInt32(sMI_Prds.Substring(0,1));
            sMI_Prd2 = Convert.ToInt32(sMI_Prds.Substring(
            2,1));
            sMI_Prd4 = Convert.ToInt32(sMI_Prds.Substring(
            6,1));
            sMI_Prd5 = Convert.ToInt32(sMI_Prds.Substring(
            8,1));

            Comment


              #7
              Originally posted by DenMan View Post
              Thanks for your suggestions! I've decided to use the following script and it's working fine:

              privatestring sMI_Prds = "5/1/1/6/2";
              privateint sMI_Prd1 = 0;
              privateint sMI_Prd2 = 0;
              privateint sMI_Prd4 = 0;
              privateint sMI_Prd5 = 0;

              sMI_Prd1 = Convert.ToInt32(sMI_Prds.Substring(0,1));
              sMI_Prd2 = Convert.ToInt32(sMI_Prds.Substring(
              2,1));
              sMI_Prd4 = Convert.ToInt32(sMI_Prds.Substring(
              6,1));
              sMI_Prd5 = Convert.ToInt32(sMI_Prds.Substring(
              8,1));
              A solution that makes assumptions as to the length of the values of the sMI_Prds. You mean you will never use a value of 13 for example? You will always have single digits for the separated values? With your current solution, try making any of the interior values more than one digit long, and you will see the your values become something else, as the "/" come into some of your separated values, giving you some interesting anomalies, if you will. Your first scheme makes no assumptions as to how big the separated values will be: this solution does.

              Regardless, you will need some error checking to ensure that you have valid integer values to feed into the other calculations in your indicator. Far simpler is to just pull in integers in the first place.

              Comment


                #8
                Thanks k for the concerns and suggestions!! I really appreciate your support!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X