Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple user inputs in one row...

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

    Multiple user inputs in one row...

    Hello,
    I would like create one indicator with multiple user inputs, which will by write in one row and they will be separated dot with comma for example: 46;58;32;44;78

    I need these values assign different variables:

    p1 = 46
    p2 = 58
    p3 = 32
    p4 = 44
    p5 = 78


    How can I rewrite this code because its in only for one input.

    if (State == State.SetDefaults)
    {
    Periods = 46;58;32;44;78
    }


    // my other code...


    #region Properties

    [NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Periods levels", GroupName = "Periods", Order = 0)]
    public int Periods
    { get; set; }

    #endregion

    Thanks...

    #2
    Hello phesi,

    If you wanted to do a comma separated list, that is no longer a number but would be a string. For the property you would need to use string as its type:

    Code:
    [NinjaScriptProperty]
    [Display(Name = "Periods levels", GroupName = "Periods", Order = 0)]
    public string Periods
    { get; set; }
    To parse the list, you can look into C# ways to do this. The easiest is likely using string.Split: https://docs.microsoft.com/en-us/dot...gs-using-split


    I look forward to being of further assistance.

    Comment


      #3
      Great ... i used this function:

      string[] substrings = Periods.Split((';'));
      foreach (var substring in substrings)

      but how to assign individual values (substring) to these variables p(1-5)?

      p1 = 46
      p2 = 58
      p3 = 32
      p4 = 44
      p5 = 78

      Comment


        #4
        Hello phesi,

        You would assign the values just like you have shown. The string you split is now an array so you can use each part of the array.
        You could loop over the array or use it by indexes:
        Code:
        substrings[0]
        substrings[index]
        I look forward to being of further assistance.

        Comment


          #5
          Can you write part of code please? I need these values convert to integers and assignt to p1, p2, p3, p4, p5... next work in integers values is easy for me already... thank you very much

          Comment


            #6
            Hello phesi,

            While I wouldn't be able to just write the code for you, I can point to learning resources for you to learn how to do this. The MSDN link shows how to parse the string into an array and then loop over it which you have done. I had provided an example of how to use the variable from your sample with an index, this is how you access the data once it was split. To add to that with what you provided, it would look similar to p1 = substrings[0];

            For an extended example of parsing/splitting data, you can see the following sample. This is more complex but is complete. The syntax in post #4 would be specifically what you would use to get a value at the index of the array you created, a similar approach is shown in this sample. https://ninjatrader.com/support/help...o_read_fro.htm

            I would also suggest searching online for "C# string.split example" for other more complete examples of how to use Split(). This is not specific to NinjaScript so you can find a lot of tutorials/education information in regard to C# on this topic.



            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            599 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            344 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            558 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            557 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X