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 traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
||
Started by algospoke, 04-17-2024, 06:40 PM
|
5 responses
46 views
0 likes
|
Last Post Today, 02:36 PM | ||
Started by arvidvanstaey, Today, 02:19 PM
|
1 response
6 views
0 likes
|
Last Post Today, 02:33 PM | ||
Started by mmckinnm, Today, 01:34 PM
|
3 responses
5 views
0 likes
|
Last Post Today, 02:12 PM | ||
Started by f.saeidi, Today, 01:32 PM
|
2 responses
9 views
0 likes
|
Last Post
by f.saeidi
Today, 02:10 PM
|
Comment