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 rhyminkevin, Today, 04:58 PM
          4 responses
          52 views
          0 likes
          Last Post dp8282
          by dp8282
           
          Started by iceman2018, Today, 05:07 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          50 views
          0 likes
          Last Post futtrader  
          Working...
          X