Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wrapper Function for Indicators?

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

    Wrapper Function for Indicators?

    Hi all,

    How can I write a wrapper function around a call to an indicator? Some indicators have a lot of inputs, and I call these indicators many times in a strategy. I would like to call the indicator once in a generic function, and then call the function in my strategy.

    I tried this in my strategy, but the compiler complains:

    private DataSeries GetMyIndicatorA ()
    {
    return MyIndicatorA(Input, ParamA, ParamB, ... ParamZ);
    }

    private DataSeries GetMyIndicatorB ()
    {
    return MyIndicatorB(Input, ParamA, ParamB, ... ParamZ);
    }

    and later in the strategy, for example...

    if (CrossBelow(GetMyIndicatorA,GetMyIndicatorB, 1))
    {
    DoStuff();
    }

    I have done this in other languages, but C# is new to me. Or is this a DataSeries type / Ninjatrader thing?

    Any help would be greatly appreciated. I am guessing there is a more sophisticated way to do this, but I am used to this method, and I like to keep things simple.

    Thanks!

    #2
    You can just create an object for your indicator.

    For example, let us say you are using Stochastics.

    In variables:
    Code:
    private Stochastics myStoch;
    In Initialize():
    Code:
    myStoch = Stochastics(7, 14, 3);
    In OnBarUpdate():
    Code:
    if (myStoch.D[0] > 70)
         // Do something;
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Beautiful!

      Thanks, Josh.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      154 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      306 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      244 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      345 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      176 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X