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

Use named and optional arguments in instantiation methods

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

    Use named and optional arguments in instantiation methods

    Beginning with C# 4, as I understand it, named and optional/default arguments could be used for constructor methods. I've not been able to find a way to use these features in NinjaScript.

    Things I've tried at State == State.DataLoaded. Let's say IndicatorName is an indicator with two arguments:
    Code:
    // Constuctor method is created by NinjaTrader as IndicatorName(string argument1, int argument2), etc.
    
    indie = IndicatorName(); // This would conceivably force all defaults for arguments.  This does not compile.
    
    indie = IndicatorName(argument1: "a string"); // This does not compile.
    
    indie = IndicatorName(argument2: 10, argument1: "a string"); // This compiles and runs successfully, but it's superfluous.
    
    indie = new IndicatorName(); // This compiles but errors at runtime.
    
    indie = new IndicatorName(argument2: 10); // This does not compile: No constructor for IndicatorName takes 1 argument.
    
    indie = new IndicatorName(argument1: "a string", argument2: 10); // This does not compile: No constructor for IndicatorName takes 2 arguments.
    For the second example that compiles, the strategy errors out as soon as it tries to grab values from the indicator (i.e. indie[1]);. NinjaTrader clearly can recognize named arguments and you can put them out of order, as you'd expect, but it does not recognize optional/default arguments, at least how I'm trying to do it. I also tried to modify the constructors with a default value (e.g. IndicatorName(string argument1 = "a string", int argument2)) but the modification is removed upon compilation.

    Is there a way? If not, can this please be added as a feature request?

    Best,
    Caleb
    Last edited by benJephunneh; 02-20-2022, 04:17 PM.

    #2
    Hello Caleb,

    Unfornately, with indicators NinjaTrader will need to generate the constructor overloads. Modifying the code in the region 'NinjaScript generated code. Neither change nor remove.' can cause NinjaTrader to break when constructing the indicator or cause other unexpected behavior.

    I will submit a feature request for the development team to consider allowing indicators with optional method call parameters.
    Once I have a tracking ID for this request I will post this in this thread for future reference.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Chelsea. I'm hopelessly curious, so I tend to ignore "STAY AWAY" messages. In this case, NinjaTrader has always ignored my modifications to the constructor methods, so I gave it another shot.

      Thanks for submitting the feature request.

      Comment


        #4
        Hello benJephunneh,

        Thank you for your reply.

        Chelsea is out of the office today, however, I have added created a feature request on your behalf to support indicators that have optional constructor overload parameters. This request is being tracked under the number SFT-5466.

        As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

        Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          'Preciate it, Kate.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Fitspressorest, Today, 01:38 PM
          0 responses
          2 views
          0 likes
          Last Post Fitspressorest  
          Started by Jonker, Today, 01:19 PM
          0 responses
          1 view
          0 likes
          Last Post Jonker
          by Jonker
           
          Started by futtrader, Today, 01:16 PM
          0 responses
          5 views
          0 likes
          Last Post futtrader  
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,791 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          844 views
          0 likes
          Last Post emuns
          by emuns
           
          Working...
          X