• 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

How to pass Primary DataSeries to Custom Method

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

    How to pass Primary DataSeries to Custom Method

    Hello--

    I have created a secondary DataSeries (let's call it myDataSeries) and a custom Method that take a DataSeries as one of the parameters (let's call it myMethod(Dataseries targetDataSeries)).

    Some times I want to pass myDataSeries into myMethod by doing this:

    Code:
    myMethod(myDataSeries);
    However, sometimes I just want to pass the primary DataSeries to myMethod. I have attempted to do this with the following code, but I am getting an error:

    Code:
    myMethod(Close);
    What is the proper way to pass the primary DataSeries Close values to a custom Method?

    Thanks,

    Aventeren

    #2
    Hi aventeren,

    You may not need to pass the series.

    Have you tried printing the close of the current bar in the custom method without passing the data series?

    For example:

    protected void myMethod()
    {
    Print(Close[0]);
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi aventeren,

      You may not need to pass the series.

      Have you tried printing the close of the current bar in the custom method without passing the data series?

      For example:

      protected void myMethod()
      {
      Print(Close[0]);
      }
      So if you leave the DataSeries field blank in a custom Method NT knows to use the primary DataSeries?

      Comment


        #4
        Hello aventeren,

        The custom method will use which ever data series you call.

        Have you given this a test?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello aventeren,

          The custom method will use which ever data series you call.

          Have you given this a test?
          I'm hunting errors (this is one of many), so I am not able to test.

          Comment


            #6
            When I attempt to not pass a DataSeries to myMethod by doing this:

            Code:
            myMethod();
            I'm getting a No Overload for myMethod takes 0 arguments error.

            I then go back to trying to pass myMethod the Close DataSeries by doing this:

            Code:
            myMethod(Close);
            But then I get an error that says that I cannot convert from the 'NinjaTrader.Data.IDataSeries' to 'NinjaTrader.Data.DataSeries'. So it looks like Close is an IDataSeries type and the secondary series is defined as a DataSeries type. Is it possible to pass the primary DataSeries Close values as a NinjaTrader.Data.DataSeries type instead of as a .IDataSeries type?

            Comment


              #7
              Hello aventeren,

              The message you got is likely because you have your method set to accept a parameter.

              Try removing this.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello aventeren,

                The message you got is likely because you have your method set to accept a parameter.

                Try removing this.
                So would I have to create a second custom Method to process the secondary DataSeries?

                Comment


                  #9
                  I ended up changing the myMethod parameter to a string called dataseries like this:

                  Code:
                  myMethod(string dataseries)
                  Then when I needed to pass the secondary data series to myMethod is just used:

                  Code:
                  myMethod("secondary");
                  or the following for the primary dataseries:

                  Code:
                  myMethod("primary");
                  Within myMethod, I then ran a bit of logic to determine whether "primary" or "secondary" was passed to "dataseries"--and then based on this I used either Close or myDataSeries as the DataSeries input in the indicator.

                  So I think it's working, but now I need to start tracing values down to make sure everything is happening correctly.

                  Thanks for your help, ChelseaB. You're always right on top of our questions, and I for one appreciate it.

                  All best,

                  Aventeren
                  Last edited by aventeren; 02-27-2014, 08:40 AM.

                  Comment


                    #10
                    Originally posted by aventeren View Post
                    When I attempt to not pass a DataSeries to myMethod by doing this:

                    Code:
                    myMethod();
                    I'm getting a No Overload for myMethod takes 0 arguments error.

                    I then go back to trying to pass myMethod the Close DataSeries by doing this:

                    Code:
                    myMethod(Close);
                    But then I get an error that says that I cannot convert from the 'NinjaTrader.Data.IDataSeries' to 'NinjaTrader.Data.DataSeries'. So it looks like Close is an IDataSeries type and the secondary series is defined as a DataSeries type. Is it possible to pass the primary DataSeries Close values as a NinjaTrader.Data.DataSeries type instead of as a .IDataSeries type?
                    A few ways to resolve your issue come to mind, but the simplest way is simply to duplicate your method, but in the second copy, pass an IDataSeries instead of a DataSeries. The code will know which copy of the method to call, depending on what parameter is passed to it.

                    Comment


                      #11
                      Same Problem with ATR

                      So I ran into the same problem with the ATR indicator. As it turns out, the ATR will only take an IDataSeries parameter input and not a custom DataSeries parameter. Therefore, it doesn't look like we can pass a custom DataSeries (i.e., like myDataSeries below) to ATR.

                      Does anyone have any workarounds for how to pass a secondary DataSeries to a custom method or indicator that only takes an IDataSeries parameter input?

                      Clearly I could just build a custom ATR that would take a DataSeries parameter (instead of an IDataSeries parameter), but man that's going to get difficult when I try and scale into other more complex indicators.

                      Does anyone have any thoughts?
                      Last edited by aventeren; 02-27-2014, 09:53 AM.

                      Comment


                        #12
                        Hi aventeren,

                        I've made a sample to show how to pass a custom data series to the ATR.

                        Follow these steps to import the NinjaScript:
                        1. Download the script to your desktop, keep it in the compressed .zip file.
                        2. From the Control Center window select the menu File > Utilities > Import NinjaScript
                        3. Select the downloaded .zip file
                        4. NinjaTrader will then confirm if the import has been successful.


                        Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.
                        Attached Files
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by aventeren View Post
                          So I ran into the same problem with the ATR indicator. As it turns out, the ATR will only take an IDataSeries parameter input and not a custom DataSeries parameter. Therefore, it doesn't look like we can pass a custom DataSeries (i.e., like myDataSeries below) to ATR.

                          Does anyone have any workarounds for how to pass a secondary DataSeries to a custom method or indicator that only takes an IDataSeries parameter input?

                          Clearly I could just build a custom ATR that would take a DataSeries parameter (instead of an IDataSeries parameter), but man that's going to get difficult when I try and scale into other more complex indicators.

                          Does anyone have any thoughts?
                          What error do you get when you try to pass a DataSeries to the ATR? I do not get any error: that is eminently passable. Maybe if you wrote the instruction that you are using?

                          Did I misunderstand? Are you trying to pass ATR to a method, or a DataSeries to ATR?

                          Comment


                            #14
                            Originally posted by koganam View Post
                            What error do you get when you try to pass a DataSeries to the ATR? I do not get any error: that is eminently passable. Maybe if you wrote the instruction that you are using?

                            Did I misunderstand? Are you trying to pass ATR to a method, or a DataSeries to ATR?
                            I had been trying to pass a DataSeries to ATR. As it turns out I was able to eventually pass a DataSeries to ATR. It must have been something else in my code.

                            Thanks for checking in, koganam. I really appreciate it.

                            Comment


                              #15
                              Can't get Stop Loss to execute; Strategy Attached; Any thoughts?

                              So I took the SampleMA example strategy and modified it as the attached strategy.

                              I first test to see if the cross happened on the primary DataSeries (I'm using a 60 min ES 03-14 chart) by calling a custom EMACross Method, and then if the cross happened within that bar I call a custom Method called FindTriggerPrice that hunts down the actual price that caused the cross to happen--at which point FindTriggerPrice passes the trigger price back into OnBarUpdate.

                              After a trigger price is found, I then pass that trigger price (called "priceOrder") to one of two custom Methods called GoLong and GoShort that set a stop, set a profit target and then enter with a limit order at the trigger price.

                              The stops are set by calling a custom GetStop Method, and the stop is a multiple of ATR, which is also found by calling a custom GetATR Method.

                              The profit targets are also set by a custom GetPT Method, and they are also multiples of ATR, which is also found by calling the custom GetATR Method.

                              I've put in Print statements and DrawTexts at a variety of places to confirm the values being passed to the various Methods and immediately prior to and after key commands. I can get the first order to execute, but for some reason the stop is not being executed, so the first position stays open the entire time. So I'm stuck and need some help.

                              The exact chart I have up is a 60 min ES 03-14 chart on a 24/7 session template that starts on 2.27.14 and extents back 180 days (ie, DataSeries UI settings).

                              Thanks for any help provided. I'm just confused why the stop is not executing correctly.

                              Finally, from a housekeeping perspective, I've known shifted gears from Indicators to Strategy Development, and as such if you'd like to move this thread to Strategy Development that is your call.

                              Thanks,

                              Aventeren
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ct, Today, 01:57 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post ct
                              by ct
                               
                              Started by 7robert, Today, 01:13 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by Newtrader101, Today, 12:52 PM
                              2 responses
                              6 views
                              0 likes
                              Last Post Newtrader101  
                              Started by 7robert, Today, 12:23 PM
                              3 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_Tyler  
                              Started by brownsfan019, Today, 12:52 PM
                              3 responses
                              8 views
                              0 likes
                              Last Post NinjaTrader_Tyler  
                              Working...
                              X