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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            15 responses
            3,268 views
            0 likes
            Last Post xiinteractive  
            Started by Tim-c, Today, 02:10 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            2 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            50 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            10 responses
            401 views
            1 like
            Last Post beobast
            by beobast
             
            Working...
            X