Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Should new classes derive from Strategy?

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

    Should new classes derive from Strategy?

    Hello,

    I'm tryingto intoduce some additional C# class structure into my strategy.

    It appears that BarsArray[] and Times[] are protected members of StrategyBase? So any class that does not derive from StrategyBase can not access them. Or are they public?

    So my question is:Should "helper" classes also derive from Strategy in order to have access to BarsArray[] and Times[]? Is it OK to instantiate a Strategy within a Strategy, or will bad things happen?

    What I'm trying to do with my code base is refactor it to make use of the State design pattern from Gamma, Helm et al. This willentailthe creation of many additional classes into the script which will all require access to BarsArray[] and Times[]

    Any thoughts? Am I missing something?

    Thanks,

    Jim

    #2
    imported post

    Hi Jim,

    Unfortunately we are not in a position to support anything outside of what is currently documented in the Help Guide. Emedding strategies within strategies is for sure outside this scope. I highly suggest not to do this since you could run into issues even if you tried. This level of programming crosses the border into our our overall framework. The intention is over time to expose more of the under the hood capabilities.

    Thanks for your understanding on this.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Ok, I was kinda afraid that was gonna be the answer.... And yes I understand, I've done enterprise class software for many years.

      So, if I'm gonna port my 250KLOC EasyLanguage codebase over. It needs to go into a single class if the code is gonna touch BarsArray or Time. But if the code has no need to access BarsArray or Time I'm free to create additional classes as long as they are nested withinthe singlederived Strategy class. Is that correct?

      Best Regards,

      Jim

      Comment


        #4
        imported post

        FYI: Most if not all class that implement IDataSeries such as Time, price series etc... must only be accessed from within the context of the OnBarUpdate() method.

        Yes you can nest additional classes within the base strategy class, no issues there all, standard C# programming is your guideline.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          Great. Got it. Thanks for the help.

          And one more thing as long as I have your attention... You really need a File->SaveAs and File->Read in the NinjaScript editor for script version control purposes.



          Jim

          Comment


            #6
            imported post

            Well, spent the remainder of the afternoon and evening playing with some high level class structure to try and bring together a design approach for my system port.

            I *do* understand why y'all want to keep those two class members as protected. Especially in Beta. But, IMO,it does have the side-effect of turning what could bea *really* elegant solution upside down.

            I'm more of aC++ guy then C#. (still searching for that "friend class" definition in C#)But, if there is a way to keep those two class members as externally namespace private, but internally namespace public, then it seems to me that responsibility for "being a good citizen" is on the shoulders of the strategy developer (who should be a NinjaTrader friend )and you all don't have to worry about somebody loading a rouge dll.

            I do not want to come across as railing against you. I realy think NinjaTrader is on to something here. It's just when I see something that is sooooooo close to solvingmany ofthe problems I've been dealing with on TradeStation with bubblegum and baling twine-I get a little excited.

            FWIW - my two cents.

            Jim

            Comment


              #7
              Guidelines for nested classes

              Originally posted by NinjaTrader_Ray View Post
              FYI: Most if not all class that implement IDataSeries such as Time, price series etc... must only be accessed from within the context of the OnBarUpdate() method.

              Yes you can nest additional classes within the base strategy class, no issues there all, standard C# programming is your guideline.

              Ray
              Hi Ray,

              I have been looking for some guidelines on how to build nested classes inside a strategy. This thread is just about the only one I found which touches on it.

              But not being much of a C# proggie, I will need you to explain the points discussed in this thread a bit more :
              • I can build nested classes in strategies, but theses classes should not be derived from NT's strategy class? Is that right? Is that what you meant by a strategy within a strategy?
              • The Dataseries classes used in the Strategy class are completely off limits? Any others? The MarketPositions? Methods? i.e GetProfitLoss(), the various Order entries (EnterLong(), etc.)
              • I noticed that if I derived a class from Strategy, the code compiles, but fails during execution. It complains about not having a constructor, or a badly formed one. Are there specific guidelines about constructors in classes nested in strategies?
              Cheers

              Comment


                #8
                Unfortunately we are unable to provide support any other strategy model than the one generated by the strategy wizard.

                May be the community can contribute?!?

                Comment


                  #9
                  Originally posted by maskiepop View Post
                  Hi Ray,

                  I have been looking for some guidelines on how to build nested classes inside a strategy. This thread is just about the only one I found which touches on it.

                  But not being much of a C# proggie, I will need you to explain the points discussed in this thread a bit more :
                  • I can build nested classes in strategies, but theses classes should not be derived from NT's strategy class? Is that right? Is that what you meant by a strategy within a strategy?
                  • The Dataseries classes used in the Strategy class are completely off limits? Any others? The MarketPositions? Methods? i.e GetProfitLoss(), the various Order entries (EnterLong(), etc.)
                  • I noticed that if I derived a class from Strategy, the code compiles, but fails during execution. It complains about not having a constructor, or a badly formed one. Are there specific guidelines about constructors in classes nested in strategies?
                  Cheers
                  What exactly are you trying to do? Run multiple logical strategies in one NT strategy instance?

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  599 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  344 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  558 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  557 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X