• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing Strategy Info from a Custom Indicator

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

    Accessing Strategy Info from a Custom Indicator

    I do a lot of backtesting. As such, I need to keep my strategies in sync with my custom indicators. So, is there a way for an indicator to access values that are produced in a strategy?

    #2
    Hello spottysallrite,

    Thanks for the note.

    Indicators do not have access to the Strategy namespace so directly accessing a value from a Strategy instance is not possible.

    What you can do is use the UserDefinedMethods indicator that contains a static class that can be shared between Strategy and Indicator instances.*

    *Your indicators will need to know when a strategy changes a property in the static class. See the attached example where a strategy changes a property in the static class and an indicator is notified of the change. MYATR is an Indicator and MYMA is a Strategy. Replace your UserDefinedMethods file with the one attached. The folders where these files live is under Documents\NinjaTrader 7\bin\Custom\Indicator and Documents\NinjaTrader 7\bin\Custom\Strategy respectively.

    For more information on Property change events, please see this MSDN page:
    https://docs.microsoft.com/en-us/dot...e-notification

    Please let me know if I may be of any further assistance.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Putting " using NinjaTrader.Strategy; " in the indicator's declarations doesn't solve this problem?

      Comment


        #4
        Hello spottysallrite,

        Thanks for the reply.

        Adding the Strategy namespace will not help because when you reference an indicator in a strategy it is either a one-off call like so:

        Code:
        double value = SMA(14);
        Or you create an instance of it at the class level with its parameters.

        The strategy is not looking at the indicator object on the chart, it makes its own instance. So the problem is that we can not get the instance of the strategy that is running on the chart.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I'm still not quite following. For example, my strategy makes several calls to the indicator during a trading day. At some point the strategy will determine that the trading day is finished, and will proceed to the next one (eg, according to conditions, it might decide that trading should stop at 10:00 AM). The indicator needs to know that that change has been made so it can apply that new date to its own calcs. So, I'm not working with charts and am not using any DataSeries. (Just trying to keep my code simple.)

          Comment


            #6
            The answer you're looking for requires you to understand the NinjaTrader generated code at the bottom of each indicator. Are you expert enough to understand that code?

            If you seek a deeper understanding beyond Chris's (admittedly terse) summary, the answers are right there in that generated code (which support considers very undocumented and rarely discusses in detail -- start searching, I expect you'll find very little -- this is where your expert C# skills must kick-in for a solo effort. ).

            In my opinion, you should proceed to craft your solution from Chris's excellent idea embodied in the sample code he sent you. I mean, that's a rather brilliant use of the UserDefinedMethods.cs file -- perfectly addressing your original question.

            Good luck!

            Comment


              #7
              ChrisL: Works! Thx !
              Last edited by spottysallrite; 06-26-2018, 09:45 AM. Reason: clarification

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by dkbyond, Today, 04:11 PM
              0 responses
              5 views
              0 likes
              Last Post dkbyond
              by dkbyond
               
              Started by markus3500, Today, 03:29 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_EricB  
              Started by bohenriksen, Today, 04:00 AM
              1 response
              21 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by brett0, Today, 12:33 PM
              3 responses
              15 views
              0 likes
              Last Post marcus2300  
              Started by lordvader34, Today, 11:12 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Working...
              X