Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Passing a value to an indicator

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

    Passing a value to an indicator

    Is it possible in NinjaScript to pass a value into an indicator for the indicator to use in its logic? If so, how is this done?

    #2
    Hello,

    Yes this is possible to do, an example of this would be the SMA indicator that requires a Period.

    For this, an easy example is actually to view the SMA indicators code to see how this is done.

    Please go to Tools -> Edit NinjaScript -> Indicator -> SMA

    Once the code is open, there are a few parts you need to make a parameter.

    The first place to look is the variables section, look for the line:

    Code:
    private int		period	= 14;
    This is the private variable for the period which defines its default value and is a place holder.

    Now look near the bottom in the Properties section for the following:

    Code:
    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    	get { return period; }
    	set { period = Math.Max(1, value); }
    }
    This is a public property which will be in the ( ) of the indicator when you call it.

    Now in the code for this indicator anywhere you need to use the period input, you would use Period

    From a strategy you would call this indicator by name or IndicatorName(13) the 13 would be a period because now this has a Period input.

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    600 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
    558 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