• 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

  • koganam
    replied
    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

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    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.

    Leave a comment:


  • ct
    replied
    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.

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    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.

    Leave a comment:


  • ct
    started a topic Alternating parameters in Ninja

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by ahm1992, Today, 04:56 PM
0 responses
10 views
0 likes
Last Post ahm1992
by ahm1992
 
Started by countjoemoney, Today, 01:16 PM
0 responses
10 views
0 likes
Last Post countjoemoney  
Started by fx.practic, Today, 12:59 PM
0 responses
7 views
0 likes
Last Post fx.practic  
Started by TheNomadicAspie, Today, 12:07 PM
0 responses
8 views
0 likes
Last Post TheNomadicAspie  
Started by alcorr247, Today, 12:04 PM
0 responses
9 views
0 likes
Last Post alcorr247  
Working...
X