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

Parameterless constructor mandatory? Connect own DLL to NT8

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

    Parameterless constructor mandatory? Connect own DLL to NT8

    Hey there :-)
    I have two questions:
    1. I want to create something like a class for scanner-objects. My design includes an calculation-auto-start for every new object, so it must be impossible to create an instance without initial parameters in the constructor to avoid a crash or exceptions. But the compiler don't let me go without the addition of a parameterless constructor. Any idea how to fix that?

    2. I want to create some dll-libaries with calculation routines and analyzers in VS. How can I manage to include them with full access to T-Series data for their instances? I'm asking because I don't know how works NT internally and how looks to possibility to crash something :-)

    With best regards
    Uwe
    Last edited by Uwe1981; 09-17-2020, 04:59 AM.

    #2
    Hello Uwe,

    You have an indicator or strategy that you want to remove the parameters from?
    Do not use the [NinjaScriptProperty] attribute tag and this will remove the input from the parameters.


    With a custom class method it would not be possible to initialize a Series<T> object internally as this would need to be constructed by the indicator or strategy.

    Instead, supply the indicator or strategy instance, or supply the Series<> object from the indicator or strategy to the method call, and this will allow you to use any Series<T> initialized within the indicator or strategy in the external class.

    Below is a link to the help guide. See the section 'Partial Classes'.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea and thank you for your answer. My first questions is about the constructor chaining. I will try to explain: I have created an indicator, for example ABC with a constructer like this: public ABC(int a, int b) {.....}
      As you can see, the constructor requires two parameters for the initialization, which must not be missing during the
      instantiation. Now the problem is that ninjatrader doesn't let me compile it like that and demands the implementation of an additional, parameterless standard constructor (public ABC() {}). My question: Why...? The point behind the parameterization when creating an instance is that the object is ready to run. The instance of an SMA must also be initialized directly when it is instantiated.
      Also, I don't want the possibility to instantiate my indicator without passing parameters, since it starts to execute some methods automatically after it is created and reads his working parameters from the properties. I hope I have been able to explain my problem to some extent :-)
      Last edited by Uwe1981; 09-17-2020, 01:25 PM.

      Comment


        #4
        Additional question: If I want to use my own structs, delegates/events, enums, controller-classes, etc -> where should I store these custom cs.files? Is it necessary, that every class/struct/event is declared as a new indicator...? Can't I just copy such self-created classes into the file system with reference to the indicator namespace? Or does every class need to have the code automatically generated by ninja at the end of the class?

        Comment


          #5
          Hello Uwe1981, thanks for your reply.

          I have created an indicator, for example ABC with a constructer like this: public ABC(int a, int b) {.....}
          A custom constructor is not possible for any Indicator/Strategy type. NinjaTrader handles all of the object construction by means of a factory. This is what the "NinjaScript generated code" section is for. We never actually call "new Indicator()" anywhere because NinjaTrader handles that for us when we add an indicator to our charts.

          You can have your own data structures in a .cs file, place it in the Documents\NinjaTrader 8\bin\Custom\AddOns and make your data structures a member of the NinjaTrader.NinjaScript namespace. I have a related example here:



          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            We never actually call "new Indicator()" anywhere
            Ok, in that case: How I have to code if I need for example 5 or 10 instances of an "support-indicator" at the same time, where everyone has to work with another timeframe and different parameters...? In C# I would do this with the new-operator.

            Comment


              #7
              Hello Uwe1981, thanks for your reply.

              The most straight forward way of doing this would be to simply make a new version of the indicator if a parameter needs to change. We don't recommend using any further inheritance past the Indicator class because NinjaScript is already based on a complex inheritance system, and we don't have control over NinjaScript object initialization. Another option would be to save the various sets of parameters in their own classes (in some .cs file) and instantiate the needed class in the indicator.

              Kind regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by OllieFeraher, 05-09-2024, 11:14 AM
              6 responses
              19 views
              0 likes
              Last Post OllieFeraher  
              Started by PaulMohn, 05-02-2024, 06:59 PM
              2 responses
              42 views
              0 likes
              Last Post PaulMohn  
              Started by ETFVoyageur, Today, 02:10 AM
              0 responses
              10 views
              0 likes
              Last Post ETFVoyageur  
              Started by rayyyu12, Today, 12:47 AM
              0 responses
              8 views
              0 likes
              Last Post rayyyu12  
              Started by ETFVoyageur, 05-07-2024, 07:05 PM
              17 responses
              137 views
              0 likes
              Last Post ETFVoyageur  
              Working...
              X