How can I share variables between two programs (a Strategy and an adjusted Indicator)?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Sharing variables between strategies
Collapse
X
-
Sharing variables between strategies
I created a Strategy that draws an RSI Indicator through the Add function. Rather than using the 30 and 70 thresholds for oversold and overbought I want to use variables (HighThreshold and LowThreshold) that are entered in my strategy. I adjusted the RSI indicator code and am now struggling to have the compiler recognize a variable from my strategy when compiling the adjusted RSI indicator code.
How can I share variables between two programs (a Strategy and an adjusted Indicator)?Tags: None
-
Hello PaulZ,
Thank you for writing in. Please note: Using dynamic values in the Initialize() method of an indicator can lead to unexpected behavior. Please make sure the following code in your adjusted RSI indicator exists:
Code:#region Variables private int lowThreshold = 30; private int highThreshold = 70; #endregionandCode:protected override void Initialize() { //... Add(new Line(System.Drawing.Color.DarkViolet, lowThreshold, "Lower")); Add(new Line(System.Drawing.Color.YellowGreen, highThreshold, "Upper")); //... }
Then when you call your adjusted RSI in your strategy code you would call it with 4 parameters (instead of two) like below:Code:#region Properties //... [Description("LowThreshold")] [GridCategory("Parameters")] public int LowThreshold { get { return lowThreshold; } set { lowThreshold = value; } } [Description("High Threshold")] [GridCategory("Parameters")] public int HighThreshold { get { return highThreshold; } set { highThreshold = value; } } //... #endregion
Please let us know if you have any further questions.Code:protected void override Initialize() { Add(adjustedRSI(14, 3, LowThreshold, HighThreshold)); }Michael M.NinjaTrader Quality Assurance
-
Thank you for your response.
I have inserted the LowThreshold and HighThreshold as additional variables in my AdjustedRSI Indicator as you suggested,. The sequence of my variables and also my properties is now Period, Smooth, LowThreshold, HighThreshold. In the Strategy I call the function as you suggested AdjustedRSI(14,3,LowThreshold,HighThreshold).
For some reason my AdjustedRSI indicator flips the sequence around. When I inspect the "NinjaScript generated code. Neither change nor remove." the following functions is automatically generated: public AdjustedRSI AdjustedRSI(int highThreshold, int lowThreshold, int period, int smooth)
{ return AdjustedRSI(Input, highThreshold, lowThreshold, period, smooth)}
So the sequence of the parameters is different from the sequence as I expect.
As I do not want to alter the auto generated code in this area, how can I alter the sequence of the input parameters of my adjusted indicator so it is in line with the sequence under Region Variables and Region Properties?
Comment
-
Hello PaulZ,
In NinjaTrader 7, the generated NinjaScript will always alphabetize the properties. You can adjust the property names with this in mind if you wish for them to line up exactly with the order you have created in the properties region.
Please let us know if we may be of further assistance.Michael M.NinjaTrader Quality Assurance
Comment
-
Thanks. I adjusted naming for the variables and this works now.
My next issue is that I want to show the RSI Thresholds on a chart. However, for high and low values the Add (new Line....) function draws the threshold lines outside the display range. How can I have the Y-axis (for the RSI indicator) be displayed from 0 to 100?
Comment
-
Hello PaulZ,
To accomplish this you can create a function to adjust the min value and the max value of the panel the indicator is plotted on. Koganam provided an excellent example of this here: http://www.ninjatrader.com/support/f...2&postcount=16
Please let us know if we may be of further assistance.Michael M.NinjaTrader Quality Assurance
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
582 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
338 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment