Announcement

Collapse
No announcement yet.

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.

        Comment


          #5
          'Preciate it, Kate.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          71 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          143 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X