Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best place for helper classes and extensions in NT8

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

    Best place for helper classes and extensions in NT8

    So in the past what I wound up doing was to create a faux indicator class that I used for utility methods. I had also written a BaseIndicator class from which I inherited my indicators instead of the usual Indicator extension.

    So it was like this:

    NinjaTrader.BaseIndicator -> NinjaTrader.Indicator

    public class FooIndicator : BaseIndicator

    Simple but pretty ugly. My concern was that I wanted to be sure that BaseIndicator and also the faux indicator were being included during packaging. In a perfect world I would want to use utility or helper classes with methods which I can call from anywhere without code replication.

    A good example is a function which determines whether or not an underlying symbol is a forex pair. What I need to do is to pass an instance of my chart or I guess the owner and then pass back whether or not it's a forex symbol. So two issues:

    1) Whatever I use I want to make sure will be packaged if I create a zip file from Ninja.
    2) I need to be able to pass instances of 'something' so that my method can pick up some context (i.e. symbol, interval, Time, etc.).

    Perhaps you guys have already provided a mechanism to plug in external functionality. A regular DLL is possible of course and I have done that in the past. Or I could perhaps just develop in VS and add the classes I need there. My concern there is that those classes may be ignored by the NinjaScript editor/compiler.

    I looked at PlugIns but I'm not certain they are designed for such a purpose. Any input/suggestion as to create a flexible and supportable architecture would be appreciated. I'll be porting a lot of code over and want to take this opportunity to refurbish some of the old ugliness.

    Thanks in advance.
    Last edited by molecool; 05-30-2015, 10:24 AM.

    #2
    Just found this...

    Since I'm six hours ahead of most of you U.S. devs I kept on digging around in the NT8 forum and think I struck gold:



    Only question is how I access those - I just call them as if they were part of my indicator/strategy? Also, I don't see that class in NT8 - where do you guys I put my shared methods? I searched the NT8 forum and cannot find a single entry under 'user defined methods'.

    Thanks in advance.
    Last edited by molecool; 05-30-2015, 10:24 AM.

    Comment


      #3
      Originally posted by molecool View Post
      Since I'm six hours ahead of most of you U.S. devs I kept on digging around in the NT8 forum and think I struck gold:



      Only question is how I access those - I just call them as if they were part of my indicator/strategy? Also, I don't see that class in NT8 - where do you guys I put my shared methods? I searched the NT8 forum and cannot find a single entry under 'user defined methods'.

      Thanks in advance.
      You use a partial class. UserDefinedMethods.cs was itself a partial class.

      Comment


        #4
        Anyone else want to chime in here?

        Comment


          #5
          Originally posted by molecool View Post
          Since I'm six hours ahead of most of you U.S. devs I kept on digging around in the NT8 forum and think I struck gold:



          Only question is how I access those - I just call them as if they were part of my indicator/strategy? Also, I don't see that class in NT8 - where do you guys I put my shared methods? I searched the NT8 forum and cannot find a single entry under 'user defined methods'.

          Thanks in advance.
          I just created a new strategy and changed the class signature to "partial class Strategy". It works. Now all derived strategies have direct access to the helper methods. You can use static or instance methods. Just be mindful that all strategies will inherit these methods so try to keep them lean.

          I was also able to declare a new extension class in the same file and that also worked. Can't believe I just found out about this handy C# feature!

          Comment


            #6
            Originally posted by ganamide View Post
            I just created a new strategy and changed the class signature to "partial class Strategy". It works. Now all derived strategies have direct access to the helper methods. You can use static or instance methods. Just be mindful that all strategies will inherit these methods so try to keep them lean.

            I was also able to declare a new extension class in the same file and that also worked. Can't believe I just found out about this handy C# feature!
            I was considering that but it would be a horrible architecture as it would be shared by all future strategies. Rather I created sub classes which suits me better. Plus I added one utility class for static stuff - seems to compile/run just fine without even having to switch to VisualStudio

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, Yesterday, 02:04 AM
            1 response
            15 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by agclub, 04-21-2024, 08:57 PM
            4 responses
            18 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Irukandji, Today, 04:58 AM
            0 responses
            3 views
            0 likes
            Last Post Irukandji  
            Started by fitspressoburnfat, Today, 04:25 AM
            0 responses
            2 views
            0 likes
            Last Post fitspressoburnfat  
            Started by Skifree, Today, 03:41 AM
            1 response
            4 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Working...
            X