Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

can I make the indicator period an input parameter

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

    can I make the indicator period an input parameter

    I think what I want to do is simple, but I can't figure out how. I've read through some of the threads on multi-period indicators and still don't know how to do what I want.

    I have a strategy that needs to get triggers from indicators with different timeframes. In one case the 1 Day and the 3 Day. So a simple example is I need the trend direction on both the 1 Day and the 3 Day. If both meet my criteria then I send a trade signal (simple example, not my actual strategy). So if I'm on the 1 Day chart, getting the trend info form the 1 Day is easy. But I also need the trend info on the 3 Day.

    So in a perfect world, I want to make the period an input to my indicator, with the default to use the period of the chart the indicator is on.

    I imagine I want an overloaded indicator. For simplicity, lets assume its an SMA indicator. If I pass 1 parameter, then that parameter is the number of bars. if I pass 3 parameters, the first is the number of bars, and the 2nd is seconds, minutes, hours or days. the 3rd parameter is the number associated with the time period.

    SMA(50,Minute,10) would get me the SMA info for the 50SMA on the 10 Minute chart.
    SMA(50) would get me the SMA info for the 50SMA on whatever chart it was on.

    But I only need to have all the indicator code once. It knows what bar data to use.

    Is this possible?
    Easy?
    Any code out there that can get me started?

    Any help is appreciated

    #2
    Hello cre8able,

    Thank you for the post.

    can I make the indicator period an input parameter
    Yes you can, this is the same concept that the SMA indicator uses. Public indicator properties which are marked with the NinjaScriptProperty attribute will be included in the indicators constructor.

    I have a strategy that needs to get triggers from indicators with different timeframes. In one case the 1 Day and the 3 Day. So a simple example is I need the trend direction on both the 1 Day and the 3 Day. If both meet my criteria then I send a trade signal (simple example, not my actual strategy). So if I'm on the 1 Day chart, getting the trend info form the 1 Day is easy. But I also need the trend info on the 3 Day.
    Adding data series would need to be hard coded in the indicator so 2 indicators would be needed here. A 1 day indicator and a 3 day indicator. The strategy would then use both indicators to use both timeframes. The strategy would also need to add a 1 day and 3 day series because the indicators do. You could then supply any parameters needed to each indicator when calling them.

    So in a perfect world, I want to make the period an input to my indicator, with the default to use the period of the chart the indicator is on.
    Your strategy could supply any period to the indicator that you need, it just could not be used for adding secondary data. You could make a 20 period indicator that adds 1 day data as an example and a second indicator that adds 3 day data and uses the same or a different period.

    I imagine I want an overloaded indicator. For simplicity, lets assume its an SMA indicator. If I pass 1 parameter, then that parameter is the number of bars. if I pass 3 parameters, the first is the number of bars, and the 2nd is seconds, minutes, hours or days. the 3rd parameter is the number associated with the time period.
    adding the NinjaScriptProperty attribute to a public property will allow you to add more inputs to your indicator. https://ninjatrader.com/support/help...ScriptProperty


    SMA(50,Minute,10) would get me the SMA info for the 50SMA on the 10 Minute chart.
    SMA(50) would get me the SMA info for the 50SMA on whatever chart it was on.
    If you are using the SMA or any indicator which uses Input in its code you could just add the secondary series from the strategy and then supply the input to the SMA. For example if your strategy is on a 5 minute and you AddDataSeries a 10 minute secondary:

    Code:
    if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return; 
    double primarySMA = SMA(BarsArray[0], 50)[0];
    double secondarySMA = SMA(BarsArray[1], 50)[0];

    I look forward to being of further assistance.

    Comment


      #3
      got it
      thank you

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      607 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      353 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      560 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      561 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X