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

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 stafe, 04-15-2024, 08:34 PM
      9 responses
      41 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by frslvr, 04-11-2024, 07:26 AM
      7 responses
      110 views
      1 like
      Last Post caryc123  
      Started by rocketman7, Today, 09:41 AM
      3 responses
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by traderqz, Today, 09:44 AM
      2 responses
      5 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by rocketman7, Today, 02:12 AM
      7 responses
      31 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X