I'm writing some indicator and have the following situation. The user imports the some required indicator in Ninja Trader. Then enter this indicator name in one of the parameters defined as string in my indicator. In my indicator code, I have a string variable with the name of another indicator. How I can call this another indicator if I have his name in string variable? If anyone can, please give an example, please.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Call custom indicator, when name in string
Collapse
X
-
Call custom indicator, when name in string
Hello!
I'm writing some indicator and have the following situation. The user imports the some required indicator in Ninja Trader. Then enter this indicator name in one of the parameters defined as string in my indicator. In my indicator code, I have a string variable with the name of another indicator. How I can call this another indicator if I have his name in string variable? If anyone can, please give an example, please.Tags: None
-
HotBird,
The best way to do this is to create a switch or a bunch of if / if else statements comparing an input string to something you expect then executing different code based on what the input string is.
For example :
Code:double value; if( inputString == "EMA") { value = EMA(period)[0]; } else if ( inputString == "SMA") { value = SMA(period)[0] } //etc,
Theres also other ways of comparing strings but I chose the simplest example. See the following link for more information.
Learn how to compare and order string values, with or without case, with or without culture specific ordering.
Please let me know if I may assist further.Adam P.NinjaTrader Customer Service
-
I have read many forums for C #. I found that this problem can be solved through reflection.
Like this.
Code:using System; using System.Reflection; static class Methods { public static void Inform(string parameter) { Console.WriteLine("Inform:parameter={0}", parameter); } } class Program { static void Main() { // Name of the method we want to call. string name = "Inform"; // Call it with each of these parameters sequentially. string[] parameters = { "Sam", "Perls" }; // Get MethodInfo. Type type = typeof(Methods); MethodInfo info = type.GetMethod(name); // Loop over parameters. foreach (string parameter in parameters) { info.Invoke(null, new object[] { parameter }); } } }
Comment
-
HotBird,
NinjaTrader uses C# so anything you can do with C# will work in NinjaTrader as long as you remain within the context of its engineering (i.e. namespaces, etc.). If you are already aware of a method to do this, it should work. However, unfortunately this level of coding is unsupported.
Please let me know if I may assist further.Adam P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
57 views
0 likes
|
Last Post
by DynamicTest
Today, 08:25 PM
|
||
Started by ScottWalsh, Today, 06:52 PM
|
4 responses
36 views
0 likes
|
Last Post
by ScottWalsh
Today, 07:40 PM
|
||
Started by olisav57, Today, 07:39 PM
|
0 responses
7 views
0 likes
|
Last Post
by olisav57
Today, 07:39 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
2 responses
19 views
0 likes
|
Last Post
by helpwanted
Today, 07:25 PM
|
||
Started by cre8able, Today, 07:24 PM
|
0 responses
9 views
0 likes
|
Last Post
by cre8able
Today, 07:24 PM
|
Comment