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

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:
        [FONT=Courier New]
                    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());
                    }[/FONT]
        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:
        [FONT=Courier New]struct Node
        {
            double val1;
            int val2;
            string val3;
            Indicator val4;
        }[/FONT]
        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 Jon17, Today, 04:33 PM
          0 responses
          1 view
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          6 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Started by alifarahani, Today, 09:40 AM
          6 responses
          41 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          20 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Working...
          X