Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Passing a value to an indicator
Collapse
X
-
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:
This is the private variable for the period which defines its default value and is a place holder.Code:private int period = 14;
Now look near the bottom in the Properties section for the following:
This is a public property which will be in the ( ) of the indicator when you call it.Code:[Description("Numbers of bars used for calculations")] [GridCategory("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } }
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.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
83 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
45 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
65 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
68 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
57 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment