Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

access strategy data from another class

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

    access strategy data from another class

    I wrote some generic code that I put in another strategy. I just call the constructor directly and use it as a regular class (not a strategy). This works however there are a few minor issues arising from the fact that the utility class doesn't have access to the same data as the strategy. For example, in the utility class I try to draw on the chart but it doesn't work. I try to get Time[0] but it doesn't work. I understand why this doesn't work but I'd like to know if there is a way to make it work? I'd love to be able to draw in my utility class.

    #2
    cunparis,

    Have you tried using the UserDefinedMethods file?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      cunparis,

      Have you tried using the UserDefinedMethods file?
      I didn't know that existed. It sounds better than using a fake strategy. Will I be able to access Close[], Time[], etc. and be able to draw?

      Comment


        #4
        cunparis,

        I have never tried, but I believe you can.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          cunparis,

          I have never tried, but I believe you can.
          I'm trying and I run into a problem.

          I created a base class for all my strategy. I created a log method in this class which will prefix all my Print()s with a timestamp.

          So I made my user defined methods partial class but it cannot access the log method. I tried to make my partial class extend the base class for my strategy but that made a circular reference. I'm at my limit of C# knowledge now (Java doesn't have partial class).

          Maybe instead of putting my log method in the base class I should put it in a partial class too?

          Comment


            #6
            cunparis,

            Please do everything in the partial class. There are two samples in the Help Guide you can check out in regards to UserDefinedMethods.


            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              cunparis,

              Please do everything in the partial class. There are two samples in the Help Guide you can check out in regards to UserDefinedMethods.


              http://www.ninjatrader-support.com/H...6/Sample2.html
              Thanks for the links. I had already read those.

              The only issue remaining is how to version my common code. If I put it in the partial class it's available to all classes. With my base class I version it so I have BaseStrategy1, 2, 3, etc. So I think one has to be careful of putting it into the partial class. other than that I think it's a good solution.

              Comment


                #8
                Unfortunately I just cannot provide you support on trying to put it in the base class.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  I confirm that the partial class can use the Draw methods!

                  Thanks a lot for your help. I'm very happy now.

                  Comment

                  Latest Posts

                  Collapse

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