Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
String Functions on User Parameters
Collapse
X
-
Hello,
Thanks for the note.
You can convert them to string by using interger1.ToString();
However I do not know of any method to turn a string back into an integer. Would suggest not doing this and instead keeping the integers stored as integers for reference when you need it again.
Let me know if I can be of further assistance.BrettNinjaTrader Product Management
-
Use the string functions to split the string, then parse them separately.Originally posted by DenMan View PostI'm considering combining 2 Integer user parameters of "10" and "50" into one String user parameter of "10/50" then using script to split them back into the Integers of "10" & "50". Does NT have methods to do this?
ref: http://msdn.microsoft.com/en-us/library/bb397679.aspx
Comment
-
I'd like a little help on splitting the string. I've tried the following code, but it isn't correct.
privatestring sMI_Periods ="5/1/1/4/2";
string[] sMI_Periods.Split("/");
foreach (string sMI_Period in sMI_Periods)
This looks just like the examples I'v found on the internet, but I'm missing something.
Comment
-
Originally posted by DenMan View PostI'd like a little help on splitting the string. I've tried the following code, but it isn't correct.
privatestring sMI_Periods ="5/1/1/4/2";
string[] sMI_Periods.Split("/");
foreach (string sMI_Period in sMI_Periods)
This looks just like the examples I'v found on the internet, but I'm missing something.
- Your second line does not declare the string array into which you are splitting the initial string.
- A char is not a string of length 1; a char is encased with single quotes, not the double quotes used to encase a string.
- sMI_Periods was declared as a string; you cannot just use it as an Array in line 3.
Code:string sMI_Periods = "5/1/1/4/2"; string[] SplitArray = sMI_Periods.Split('/'); foreach (string sMI_Period in SplitArray) ...Last edited by koganam; 10-20-2011, 06:23 PM.
Comment
-
Thanks for your suggestions! I've decided to use the following script and it's working fine:
privatestring sMI_Prds = "5/1/1/6/2";
privateint sMI_Prd1 = 0;
privateint sMI_Prd2 = 0;
privateint sMI_Prd4 = 0;
privateint sMI_Prd5 = 0;
sMI_Prd1 = Convert.ToInt32(sMI_Prds.Substring(0,1));
sMI_Prd2 = Convert.ToInt32(sMI_Prds.Substring(2,1));
sMI_Prd4 = Convert.ToInt32(sMI_Prds.Substring(6,1));
sMI_Prd5 = Convert.ToInt32(sMI_Prds.Substring(8,1));
Comment
-
A solution that makes assumptions as to the length of the values of the sMI_Prds. You mean you will never use a value of 13 for example? You will always have single digits for the separated values? With your current solution, try making any of the interior values more than one digit long, and you will see the your values become something else, as the "/" come into some of your separated values, giving you some interesting anomalies, if you will. Your first scheme makes no assumptions as to how big the separated values will be: this solution does.Originally posted by DenMan View PostThanks for your suggestions! I've decided to use the following script and it's working fine:
privatestring sMI_Prds = "5/1/1/6/2";
privateint sMI_Prd1 = 0;
privateint sMI_Prd2 = 0;
privateint sMI_Prd4 = 0;
privateint sMI_Prd5 = 0;
sMI_Prd1 = Convert.ToInt32(sMI_Prds.Substring(0,1));
sMI_Prd2 = Convert.ToInt32(sMI_Prds.Substring(2,1));
sMI_Prd4 = Convert.ToInt32(sMI_Prds.Substring(6,1));
sMI_Prd5 = Convert.ToInt32(sMI_Prds.Substring(8,1));
Regardless, you will need some error checking to ensure that you have valid integer values to feed into the other calculations in your indicator. Far simpler is to just pull in integers in the first place.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
639 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
366 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 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
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
572 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment