• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alternating parameters in Ninja

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

    Alternating parameters in Ninja

    Scenario:

    Is there a way to create a user defined parameter using alternating array values in Ninja?
    eg: (2.3, NQ, 1, YM, .5, ES). (number1, Value1, Number2, Value2)

    I know I can use two arrays or lists but didn't know if there was another method available I could use.

    Cheers

    #2
    Hello ct, and thank you for your question. So I may better assist, can you provide a working two array example? This will make it easier to provide the best assistance possible.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      JessicaP

      In a word is a C# "Tuple" supported as a parameter type?

      In a word I am expecting a "no" response.

      Cliff
      Last edited by ct; 01-25-2017, 02:48 PM.

      Comment


        #4
        Thank you for this additional information ct. For reference, I am assuming you are referring to Python tuples (publicly available documentation https://www.tutorialspoint.com/python/python_tuples.htm) and that our question is how we can alternate between different types within a single list.

        Every object in C# descends from an object whose type is "object". So this works.

        Code:
        
                    List<object> tupleExample = new List<object>();
                    tupleExample.Add(2.3);
                    tupleExample.Add(4);
                    tupleExample.Add("five six");
                    SMA sevenEightNine = new SMA();
                    tupleExample.Add(sevenEightNine);
                    foreach(object i in tupleExample)
                    {
                        Print(i.ToString());
                    }
        This said, most people would recommend against ignoring C#'s typing entirely. C# is flexible enough to be treated like Python, but there may be reasons not to take advantage of this. A great reason for this is coding for the web. When coding for e.g. an Android phone app that connects to the cloud, a lot of objects have to be "flattened" out to strings, sent over the internet, and reconstructed in the cloud, or flattened in the cloud and reconstructed on the phone. This can be a pain. Many add-on libraries can pick up on clues from an object's type - doubles work a certain way, dictionaries (and as a Python programmer you may appreciate that C# has a Dictionary class) work a certain way, integers and strings do - and do a lot of the heavy lifting serializing. More advanced libraries like the third party GSON package can even use reflection to automatically name things for us.

        So in fewer words, strong typing saves us writing a lot of code in some environments, and that is one reason why many people code this way. Many coders write in many languages and environments and like to carry conventions between them.

        So, a more strongly typed approach to what you are trying to do would be to create a structure which can hold all of these things, and make a list of them. For example,

        Code:
        struct Node
        {
            double val1;
            int val2;
            string val3;
            Indicator val4;
        }
        You could then create a list of those with List<Node>. Whichever approach you take is up to you as the developer. Please let us know if there are any other ways we can help.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by ct View Post
          JessicaP

          In a word is a C# "Tuple" supported as a parameter type?

          In a word I am expecting a "no" response.

          Cliff
          Tuple is a .NET 4 and above object. It does not exist and cannot be used in .NET 3.5, at which NT7 is targeted

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Leope, Today, 03:15 AM
          0 responses
          6 views
          0 likes
          Last Post Leope
          by Leope
           
          Started by Frook1951, Today, 03:09 AM
          0 responses
          5 views
          0 likes
          Last Post Frook1951  
          Started by unlobotrader, Today, 02:46 AM
          0 responses
          4 views
          0 likes
          Last Post unlobotrader  
          Started by greg6622, Today, 01:26 AM
          0 responses
          3 views
          0 likes
          Last Post greg6622  
          Started by Splex, Today, 12:04 AM
          0 responses
          4 views
          0 likes
          Last Post Splex
          by Splex
           
          Working...
          X