• 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

Referencing Multi-Time Series from Indicator

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

    Referencing Multi-Time Series from Indicator

    I have a strategy that has a Primary Time Series and a Secondary Time Series.

    I am calling a custom indcator while I am on the Secondary Time Series of the Strategy.In that indicator I want to reference the Close of the Primary Time Series and the Close of the Secondary Time Series.

    For example, Print ( ToDay(Time[0]) + " " + Closes[0][0] + " " + Close[0]).

    The problem is that Closes[0][0] is giving me the Close of the Secondary Time Series instead of the Primary Time Series.

    I have used the same code in a UserDefinedMethod and it gives me the Primary Close and the Secondary Close. I moved the code to an indicator so that I could plot.

    How do I get the Indicator to reference both the Primary Time Series and the Secondary Time Series?

    #2
    Hello GKPoland,

    Calling an indicator with multiple data series from a strategy with multiple data series is generally discouraged.

    Is the only way this indicator will work is with multiple data series?

    Could the indicator instead be called once using the input series of the primary data series of the strategy and then called again using the input series of the secondary data series of the strategy?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Referencing Multi-Time Series from Indicator

      Only the Strategy has a multi data series. The Indicator only has one data series.

      I was thinking that if I called the indicator from a strategy with two data series, I would be able to reference both data series in the code of the Indicator.

      The calculations in the Indicator need to reference both the Close of the Primary Data Series and the Close of the Secondary Data Series.

      What is confusing to me is that this works when I have the code in a UserDefineMethod and call that method from the Secondary Data Series of the Strategy. I am able to reference the Close of the Primary Data Series with Closes[0][0] and the Close of the Secondary Sata Series with Close[0].

      Comment


        #4
        Hi GKPoland,

        If you are using the UserDefinedMethods.cs file located in Documents\NinjaTrader 7\bin\Custom\Strategy, this would in essence be the same as if the code was added directly to the strategy.

        If you are using the UserDefinedMethods.cs file located in Documents\NinjaTrader 7\bin\Custom\Indicator, this file is for indicators and it would be very surprising if you could reference both data series in this file.

        There are two UserDefinedMethod.cs files. One for indicators, one for strategies. These allow you to write methods that are available to other strategies (if the strategy UserDefinedMethod) or other indicators (if the indicator UserDefinedMethod).


        Regarding using both data series in the script, would it be possible to just write all of the code in the strategy instead of using an indicator? It is not possible to supply multiple input series to a script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I understand that using the UserDefinedMethods.cs file located in Documents\NinjaTrader 7\bin\Custom\Strategy, would in essence be the same as if the code was added directly to the strategy. Call the method and it returns the result of the code. I have used both the UserDefinedMethods.cs file for Stategies and the one for Indicators.

          Since I have some blocks of code that are used both to plot and to determine entries, I wanted to put that code in an Indicator and then reference that Indicator from a Strategy. This would eliminate having to maintain the same block of code in two different UserDefinedMethods.cs files.

          It is possible to just write all of the code in the Strategy instead of using an Indicator, but I was hoping to keep the Strategy code as clean and neat as possible. I will be combining several Indicators in various ways and was hoping to just reference the Indicator from the Strategy and keep most of the code in the Strategy just handling Entries and Exits.

          I think my misunderstanding was thinking that calling an Indicator from a Strategy was the same as calling a method from the Strategy. Is there somewhere in the Help file that explains what takes place behind the scenes when calling an Indicator from a Strategy and when adding an Indicator to a Startegy?

          Comment


            #6
            Originally posted by GKPoland View Post
            I understand that using the UserDefinedMethods.cs file located in Documents\NinjaTrader 7\bin\Custom\Strategy, would in essence be the same as if the code was added directly to the strategy. Call the method and it returns the result of the code. I have used both the UserDefinedMethods.cs file for Stategies and the one for Indicators.

            Since I have some blocks of code that are used both to plot and to determine entries, I wanted to put that code in an Indicator and then reference that Indicator from a Strategy. This would eliminate having to maintain the same block of code in two different UserDefinedMethods.cs files.

            It is possible to just write all of the code in the Strategy instead of using an Indicator, but I was hoping to keep the Strategy code as clean and neat as possible. I will be combining several Indicators in various ways and was hoping to just reference the Indicator from the Strategy and keep most of the code in the Strategy just handling Entries and Exits.

            I think my misunderstanding was thinking that calling an Indicator from a Strategy was the same as calling a method from the Strategy. Is there somewhere in the Help file that explains what takes place behind the scenes when calling an Indicator from a Strategy and when adding an Indicator to a Startegy?
            If you want to call a public method in an Indicator, from outside the class, you must call Update() at he beginning of the method in the Indicator.

            Comment


              #7
              Hi GKPoland,

              Calling an indicator is not like calling a method internal to the Strategy namespace.

              When an indicator is first called, NinjaTrader will have the indicator process all of the historical data up to that point and make calculations and then cache these.

              Moving forward, the indicator will process once per bar.

              Only the Input Series that is passed to the script will be available to the indicator after it is called.

              http://www.ninjatrader.com/support/h...simple_sma.htm

              These will not share the same namespace (or class) and will not be able to pass information back and forth from each other.

              Kognam is correct that a method should have Update() called if you are calling a custom method from within the indicator from outside of the class of that indicator.

              The supported use of calling an indicator from a strategy, is to call the indicator in-line.
              For example:
              double mySMAValue = SMA(19)[0];

              Adding an indicator to a strategy using the Add() command will only add the indicator to a chart for visual purposes. It is not possible to modify the instance of a indicator that has been added to a chart after it has been added. (Meaning that it is not possible to change indicator values for the visual indicator on the chart after as the strategy progresses).
              http://www.ninjatrader.com/support/h...s/nt7/add2.htm

              There is not a page in the help guide that explains what happens internally to NinjaTrader when an indicator is called.
              Last edited by NinjaTrader_ChelseaB; 11-11-2014, 08:21 AM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Ok. Thanks your help. I will use your suggestion and just put all of the code into the Strategy.

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  ...
                  There is not a page in the help guide that explains what happens internally to NinjaTrader when an indicator is called.
                  Chelsea,
                  Just curious, will the Ninjascript documentation be more robust in NT8?
                  Thanks

                  Comment


                    #10
                    Hi EnsoTrader,

                    Originally posted by EnsoTrader View Post
                    Chelsea,
                    Just curious, will the Ninjascript documentation be more robust in NT8?
                    Thanks
                    For the NinjaTrader 8 Help Guide we are planning to create a more robust documentation and providing more educational material and detailed reference samples.

                    We also plan on routine updates to the content of the NinjaTrader 8 Help Guide whereas the NinjaTrader 7 Help Guide is 'static'.

                    We also welcome any suggestions for help guide content from our users if you would like to see something specific detailed.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by stefanrvc, Today, 04:59 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by 7robert, Yesterday, 08:30 PM
                    2 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by pjsmith, Today, 01:13 AM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Started by yukashg, Yesterday, 09:56 PM
                    1 response
                    16 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Started by cutzpr, Yesterday, 09:19 PM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Working...
                    X