Yes, you can do that in the Initialize method, however, please note that the initialize method only gets called when you add the script to a chart. You would need to remove and add the script back from the dialog window.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Add horizontal lines to indicator in strategy script
Collapse
X
-
Alexstox,
Correct, when you add another indicator to a strategy or any other script, it will create a new instance of that indicator in which you will need to pass through values for the indicator.
You can create variables that will be the default to pass through the MyIndicator()Cal H.NinjaTrader Customer Service
Comment
-
Can be these variables from MyIndicator? Not to set them in script? And how to implement this in strategy, where I call this indicator?Originally posted by NinjaTrader_Cal View PostAlexstox,
Correct, when you add another indicator to a strategy or any other script, it will create a new instance of that indicator in which you will need to pass through values for the indicator.
You can create variables that will be the default to pass through the MyIndicator()
Comment
-
So, if there are var1, var2, var3 in MyIndicator, these variables should be in strategy script in Variables region and in MyIndicator(var1, var2, var3)?!Originally posted by NinjaTrader_Cal View PostAlexstox,
You will need to pass values through values for the MyIndicator() in order for the instance to know what values to create it and calculate the indicator.
Comment
-
Alexstox,
No, that is not what I'm saying.
Let's try a different look.
When you add, say, an SMA() to the strategy you need to pass a value through the () in order for the SMA to know what to calculate with.
I.E. SMA(12)
However, you can create a variable that you can pass through the SMA instead so that you have more control over it rather than having to open the script back and forth to adjust the value.
http://www.ninjatrader.com/ninjatrader/nt7/setup.exeCal H.NinjaTrader Customer Service
Comment
-
Comment
-
1) So, how to script thisOriginally posted by NinjaTrader_Cal View PostAlexstox,
Yes, you can do that in the Initialize method, however, please note that the initialize method only gets called when you add the script to a chart. You would need to remove and add the script back from the dialog window.
2) If I change the instrument (MSFT to MMM) in the chart, will this reload Initialize() method and will Initialize() see the change of instrument?Code:if([B][U]instrument==MSFT[/U][/B]) do something
3) how to scriptCode:If([B][U]instrument==futures or stocks[/U][/B]) do smth
Comment
-
Alexstox,
This does not reload the initialize() method as this is only called when the indicator is first applied to the chart.
You would need to do this in OnStartUp() method -
http://www.ninjatrader.com/support/h...onstartup2.htmCal H.NinjaTrader Customer Service
Comment
-
There is no default constructor: you must use the full calling signature. That is, all inputs that are exposed as a GridCategory or listed as a Category("Parameters"), must be included on the calling line.Originally posted by alexstox View PostI will check this. Thanks.
May I use IF() in Initialize()? For example, to filter ADD() only for some instruments?
And how to check what instrument now is using in strategy or indicator?Code:if(instrument==MSFT) do something
2) When I tried to call for MyIndicator() in strategy, this caused an error because strategy required MyIndicator(1var, 2var, 3var). That's why I asked about how to call MyIndicator as default just MyIndicator()?
Comment
-
calling line is Indicator(1,2,3)?Originally posted by koganam View PostThere is no default constructor: you must use the full calling signature. That is, all inputs that are exposed as a GridCategory or listed as a Category("Parameters"), must be included on the calling line.
What is GridCategory?
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
624 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
359 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
562 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
567 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment