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 proptradingshop, 03-21-2024, 09:50 AM
|
5 responses
26 views
0 likes
|
Last Post Today, 05:17 AM | ||
Started by MaupinFinche, Today, 05:08 AM
|
0 responses
4 views
0 likes
|
Last Post
by MaupinFinche
Today, 05:08 AM
|
||
Started by Enkidu, Yesterday, 06:40 AM
|
9 responses
35 views
0 likes
|
Last Post
by Enkidu
Yesterday, 01:11 PM
|
||
Started by Mestor, 03-10-2023, 01:50 AM
|
12 responses
309 views
0 likes
|
Last Post
by z.franck
Today, 04:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
32 responses
269 views
0 likes
|
Last Post
by f.saeidi
Yesterday, 06:49 AM
|
Comment