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:
    Enable your properties to automatically notify a binding source when the property value changes in Windows Presentation Foundation (WPF).


    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, 10:45 AM. Reason: clarification

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by stafe, 04-15-2024, 08:34 PM
              7 responses
              31 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by adeelshahzad, Today, 03:54 AM
              4 responses
              30 views
              0 likes
              Last Post adeelshahzad  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              17 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Working...
              X