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

  • 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:
    [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.

    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 algospoke, Yesterday, 06:40 PM
2 responses
19 views
0 likes
Last Post algospoke  
Started by ghoul, Today, 06:02 PM
3 responses
14 views
0 likes
Last Post NinjaTrader_Manfred  
Started by jeronymite, 04-12-2024, 04:26 PM
3 responses
45 views
0 likes
Last Post jeronymite  
Started by Barry Milan, Yesterday, 10:35 PM
7 responses
20 views
0 likes
Last Post NinjaTrader_Manfred  
Started by AttiM, 02-14-2024, 05:20 PM
10 responses
181 views
0 likes
Last Post jeronymite  
Working...
X