Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multiple IDataSeries input for indicator

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

    Multiple IDataSeries input for indicator

    I'm trying to create an indicator A that uses the value of another indicator B together with pricedata like Close[0] etc. Then it can be called in yet another indicator C. So something like this:

    Within indicator C I do this:

    Plot0.Set( A( B( Close, parameter1 ), parameter2 ) );

    The problem is that when I try to do a calculation with Close[0] and the result of indicator B, my indicator A apparently thinks that with Close[0] I'm referring to the value of indicator B instead of the price data. How can I achieve that indicator A sees the price and indicator B as different inputs?

    Btw: I know I can explicitly add a specific instrument in A but I want to make it generic: just use the pricedata from whatever chart/ resolution I'm using, that is the pricedata it should use for both indicator A and indicator B.

    #2
    Hello,

    It sounds like you're going about the right approach. When you place Indicator C onto a chart does it or any of the indicators it gets values from reference a different instrument or time frame?
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by FireFly View Post
      I'm trying to create an indicator A that uses the value of another indicator B together with pricedata like Close[0] etc. Then it can be called in yet another indicator C. So something like this:

      Within indicator C I do this:

      Plot0.Set( A( B( Close, parameter1 ), parameter2 ) );

      The problem is that when I try to do a calculation with Close[0] and the result of indicator B, my indicator A apparently thinks that with Close[0] I'm referring to the value of indicator B instead of the price data. How can I achieve that indicator A sees the price and indicator B as different inputs?

      Btw: I know I can explicitly add a specific instrument in A but I want to make it generic: just use the pricedata from whatever chart/ resolution I'm using, that is the pricedata it should use for both indicator A and indicator B.
      Your declaration shows pretty clearly that you are referring to PriceData as used by Indicator B, and generating an output that is an input for Indicator A. If you want A to read Close as its input, then you must declare Close as an input to A, regardless of whether Close is also an input to B.
      Last edited by koganam; 03-04-2013, 08:28 AM.

      Comment


        #4
        Originally posted by NinjaTrader_Lance View Post
        Hello,

        It sounds like you're going about the right approach. When you place Indicator C onto a chart does it or any of the indicators it gets values from reference a different instrument or time frame?
        No, I have no other references

        Originally posted by koganam View Post
        Your declaration shows pretty clearly that you are referring to PriceData as used by Indicator B, and generating an output that is an input for Indicator A. If you want A to read Close and its input, then you must declare Close as an input to A, regardless of whether Close is also an input to B.
        Yes I think you are right. That is probably what is happening. But how can I declare Close as an input to A along with the existing input (which is indicator B )?

        Comment


          #5
          Originally posted by FireFly View Post
          No, I have no other references



          Yes I think you are right. That is probably what is happening. But how can I declare Close as an input to A along with the existing input (which is indicator B )?
          The same way that you declare all inputs; as part of the parameter list. In your case, the most likely would be:
          Code:
          Plot0.Set( A([COLOR=blue][B]Close,[/B][/COLOR] B( Close, parameter1 ), parameter2 ) );
          as the OHLC input is usually the first in the parameter list.

          Comment


            #6
            Originally posted by koganam View Post
            The same way that you declare all inputs; as part of the parameter list. In your case, the most likely would be:
            Code:
            Plot0.Set( A([COLOR=blue][B]Close,[/B][/COLOR] B( Close, parameter1 ), parameter2 ) );
            as the OHLC input is usually the first in the parameter list.
            I'm still not sure how to do this. Let me make it clear with a very simple example:

            Inside Indicator TestA I have this: Plot0.Set( Input[0] + Close[0] );

            Inside Indicator TestB I have this: Plot0.Set(2*Close[0]);

            Inside Indicator TestC I have this: Plot0.Set( TestA( TestB(Close,2),1)[0] );

            What I wanted to achieve is that B multiplies Close[0] by 2, then indicator A adds Close[0] to this so as a result I should get Close[0]*3 out of indicator C. This isn't happening. I get Close[0]*4 instead because A uses not the Close[0] of the pricedata but the indicator.

            My question is: HOW do I declare the inputs such that indicator A can take both indicator input and price input?

            Comment


              #7
              Originally posted by FireFly View Post
              I'm still not sure how to do this. Let me make it clear with a very simple example:

              Inside Indicator TestA I have this: Plot0.Set( Input[0] + Close[0] );

              Inside Indicator TestB I have this: Plot0.Set(2*Close[0]);

              Inside Indicator TestC I have this: Plot0.Set( TestA( TestB(Close,2),1)[0] );

              What I wanted to achieve is that B multiplies Close[0] by 2, then indicator A adds Close[0] to this so as a result I should get Close[0]*3 out of indicator C. This isn't happening. I get Close[0]*4 instead because A uses not the Close[0] of the pricedata but the indicator.

              My question is: HOW do I declare the inputs such that indicator A can take both indicator input and price input?
              Given what you now write, it would seem that the problem must be in the implementation details in the classes, as on the face of it, you would be getting what you are expecting.

              Do you care to post the test files themselves, so that I can load them and debug? I am really curious why this is not working as expected. Of course, if there are secret details that you would rather not reveal, I understand perfectly.

              Comment


                #8
                Originally posted by koganam View Post
                Given what you now write, it would seem that the problem must be in the implementation details in the classes, as on the face of it, you would be getting what you are expecting.

                Do you care to post the test files themselves, so that I can load them and debug? I am really curious why this is not working as expected. Of course, if there are secret details that you would rather not reveal, I understand perfectly.
                See attached. No secrets, I have created these indicators just to demonstrate my question.

                Btw: empty indicators were created with the wizard and then I just modified the Plot0 line.
                Attached Files

                Comment


                  #9
                  You are writing this correctly however you logic is a little off and it may be due to a misunderstanding of how Input[0] works.

                  Because TestC is the final results let's look at this from TestC's perspective.
                  We start by taking the value of TestB and pass it the closing price. Based on the code it really doesn't matter what values we pass TestB as it will always return the Close[0]*2
                  We then pass that line (inputseries) onto TestA. TestA takes that line which is Input[0] and adds the closing price (of TestB) to that which is doubling the value.

                  If you wanted to pass the Close[0] of TestC to TestA you would have to give TestA an additional input. If you just needed the most recent value you could pass in a double

                  testA would look something like this (would need modification based on goals
                  Code:
                  //Where myInput would be the closing price that you pass to it
                  Plot0.Set( Input[0] + myInput );
                  Let me know if I can further clarify anything
                  LanceNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Lance View Post
                    You are writing this correctly however you logic is a little off and it may be due to a misunderstanding of how Input[0] works.

                    Because TestC is the final results let's look at this from TestC's perspective.
                    We start by taking the value of TestB and pass it the closing price. Based on the code it really doesn't matter what values we pass TestB as it will always return the Close[0]*2
                    We then pass that line (inputseries) onto TestA. TestA takes that line which is Input[0] and adds the closing price (of TestB) to that which is doubling the value.

                    If you wanted to pass the Close[0] of TestC to TestA you would have to give TestA an additional input. If you just needed the most recent value you could pass in a double

                    testA would look something like this (would need modification based on goals
                    Code:
                    //Where myInput would be the closing price that you pass to it
                    Plot0.Set( Input[0] + myInput );
                    Let me know if I can further clarify anything
                    OK, but HOW do I declare the myInput of your example as an input for TestA? I guess I need to add something to Properties? What extra code do I need to put there then in this case? Could you give me an example?

                    Comment


                      #11
                      Originally posted by FireFly View Post
                      OK, but HOW do I declare the myInput of your example as an input for TestA? I guess I need to add something to Properties? What extra code do I need to put there then in this case? Could you give me an example?
                      You already had this in your code as it was generated by the Wizard. I think it was called MyInput0 in yours. There is a private variable and a public that takes the input from the other indicator or user. Look both in your variables section towards the top and in the properties section towards the bottom.

                      You could then have TestC look like this
                      Plot0.Set( TestA( TestB(Close,2),Close[0])[0] );

                      This all being said, it might be simpler to just use functions within TestC to do certain calculations but that will depend on your end goals.
                      LanceNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Lance View Post
                        You already had this in your code as it was generated by the Wizard. I think it was called MyInput0 in yours. There is a private variable and a public that takes the input from the other indicator or user. Look both in your variables section towards the top and in the properties section towards the bottom.

                        You could then have TestC look like this
                        Plot0.Set( TestA( TestB(Close,2),Close[0])[0] );
                        Ah OK! I had always seen the parameters fields of the indicator as something to pass passive parameters like a lookback period but of course there is no reason why you couldn't pass something dynamic like Close[0] in the same way. It works fine now.

                        This all being said, it might be simpler to just use functions within TestC to do certain calculations but that will depend on your end goals.
                        Yes, on the face of it it looks like an overly complicated way to achieve something but I have a good reason to do it in this way and it leads to a very elegant solution to what I wanted to achieve.

                        Thanks to you guys for your help!

                        Comment


                          #13
                          Thanks for the feedback. Good Luck!
                          LanceNinjaTrader Customer Service

                          Comment


                            #14
                            I have a new question related to this. Suppose that in TestA I want to use not Close[0] but (Close[0]-Close[1]). How can I do that?

                            Of course I could do this in TestC:
                            Plot0.Set( TestA( TestB(Close,2),Close[0] - Close[0])[0] );

                            But can I do the calculation ( Close[0]-Close[1] ) inside TestA by passing Close as a DataSeries? How can I do that?

                            So basically I want to have multiple DataSeries as inputs where normally an indicator works on only one.

                            Comment


                              #15
                              You would either need to pass in the two doubles from C as you have (or pass them as two separate inputs)

                              Unfortunately passing a data series as input is not supported and you would need to do a type conversion for it to work with the UI

                              This thread shows how you can expose different series values for access and may be the work around you're looking for



                              Let me know if I can be of further assistance.
                              LanceNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by habeebft, Today, 07:27 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_ChristopherS  
                              Started by AveryFlynn, Today, 04:57 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Max238, Today, 01:28 AM
                              4 responses
                              38 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by r68cervera, Today, 05:29 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by geddyisodin, Today, 05:20 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X