I like to pass color as string, e.g. "Blue" to this method, but DrawDiamond() requires 'Color' object. I don't know how to assign a string color to Color object. Can someone please help. I know this is more of a c# question, but I appreciate help in any case
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
Passing color as string to custom DrawDiamond() method
Collapse
X
-
Passing color as string to custom DrawDiamond() method
In developing a new indicator, I need to create a generalized method that simply draws diamond via DrawDiamond().
I like to pass color as string, e.g. "Blue" to this method, but DrawDiamond() requires 'Color' object. I don't know how to assign a string color to Color object. Can someone please help. I know this is more of a c# question, but I appreciate help in any caseLast edited by stevenev1; 02-25-2017, 11:06 AM.Tags: None
-
Jesse, thank you very much for your reply. I don't mind passing a color object, etc. to the method, as long as the method can be parametrised and I don't have to write a new line for each color. I have to do a lot better than this not-good implementation of mine
protected void diamond( string color ) {
string myTag = "tag-" + color + CurrentBar.ToString();
if ( color == "red" )
Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, Brushes.Red);
if ( color == "green" )
Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, Brushes.Green);
}
NT8
Comment
-
Hello,
Thank you for the reply.
In this case, you could use the following syntax:
Code:private void Diamond( Brush color ) { string myTag = "tag-" + color.ToString() + CurrentBar.ToString(); Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, color); } protected override void OnBarUpdate() { Diamond(Brushes.Red); }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
I also found a way to do this, by using a color string. If using this approach, need to make sure to properly capitalize the colors, e.g. "Blue" and not "blue". I think using the object is much better in any case
ref: http://stackoverflow.com/questions/3...ame-in-c-sharp
protected void diamond( string myColor ) {
Type t = typeof(Brushes);
Brush b = (Brush)t.GetProperty( myColor ).GetValue(null, null);
string myTag = "tag-" + myColor + CurrentBar.ToString(); // ( CurrentBar.ToString );
Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, b);
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by yertle, Yesterday, 08:38 AM
|
7 responses
28 views
0 likes
|
Last Post
by yertle
Today, 12:15 AM
|
||
Started by bmartz, 03-12-2024, 06:12 AM
|
2 responses
21 views
0 likes
|
Last Post
by bmartz
Today, 12:11 AM
|
||
Started by funk10101, Today, 12:02 AM
|
0 responses
4 views
0 likes
|
Last Post
by funk10101
Today, 12:02 AM
|
||
Started by gravdigaz6, Yesterday, 11:40 PM
|
1 response
8 views
0 likes
|
Last Post Yesterday, 11:49 PM | ||
Started by MarianApalaghiei, Yesterday, 10:49 PM
|
3 responses
10 views
0 likes
|
Last Post Yesterday, 11:33 PM |
Comment