Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to pass dataSeries or to user-created method?

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

    How to pass dataSeries or to user-created method?

    Howdy.

    I have several series and bar arrays I am manipulating. I will have a function that will do the same thing to these different series, so I'd like to put it in a function.

    I'm just looking for the syntax for passing various series to a generic function/method. How do I modify the function input?

    Code:
    private double MyAddFunction( double myVal1, int myVal2...   BarSeries?, Series<T> )
    {  
        return myVal1 + myVal2;
    }​
    Assuming I wanted to pass it say a created Series<T>, that was initialized in State.DataLoaded like so. This series houses a secondary bar series:
    Code:
    _openPerM2 =new Series<double>(BarsArray[1], MaximumBarsLookBack.Infinite);
    How would you pass the standard Times Array:
    Code:
    Times[1][0] //time of current bar in the secondary series

    Thanks,
    FP

    #2
    Hello,

    Thank you for your post.

    You would pass in the series to the method depending on its type. For example, for a custom Series<double>:

    Code:
    private double myMethod(Series<double> mySeries)
    {
    //do something
    }
    Are you trying to pass the entire Times array or just a single date time? For a single date time, like passing in Times[1][0], you would just specify DateTime as the parameter type.

    Please let us know if you have any further questions.

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Are you trying to pass the entire Times array or just a single date time? For a single date time, like passing in Times[1][0], you would just specify DateTime as the parameter type.

      Please let us know if you have any further questions.
      Thanks for the response!

      But not a single value, but the Bar Series itself. To further explain, this function will be doing the SAME thing on multiple bar series that I have added to my indicator, so I'd like to be able to operate on different bar series that will do the same thing.

      I.e., the function will take the 60-Min bar series I have added, and count back 4 bars. Then that same function, it will take an input of the 30-min bar series, and count back 8 bars.

      So, I'd like to be able to pass WHICH bar series the counting should be done on.

      Does that make sense the way I've explained it?

      Comment


        #4
        Originally posted by forrestang View Post
        Thanks for the response!

        But not a single value, but the Bar Series itself. To further explain, this function will be doing the SAME thing on multiple bar series that I have added to my indicator, so I'd like to be able to operate on different bar series that will do the same thing.

        I.e., the function will take the 60-Min bar series I have added, and count back 4 bars. Then that same function, it will take an input of the 30-min bar series, and count back 8 bars.

        So, I'd like to be able to pass WHICH bar series the counting should be done on.

        Does that make sense the way I've explained it?
        Hi forrestang,

        Is your function in a separate class so you need to pass the series.. doable but CPU code and time expensive.


        Or is this a "Happy Day" scenario where is your function a module outside OBU() but in the same class where it can be called from OBU() with NO NEED to pass any data series you already initialized as normal in OnStateChange()?

        The post just above sound like you may have the Happy Day scenario.

        Hedge

        Comment


          #5
          Hello,

          Please see the attached sample script which demonstrates passing in the Bars object to a custom method using BarsArray.



          If you have any further questions, please let us know.
          Attached Files

          Comment


            #6
            Thanks, that seems to be what I needed, just the syntax for referencing different bar series within a method. Initially, I was just gonna pass a flag in, and then do conditionals to decide which bar series to operate on, but being able to pass in the series is simpler.

            FYI, as to the question above, my code is structured the way yours is, w/the my method being on the same level as OBU().

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            602 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X