Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Serializing DashStyleHelper
Collapse
X
-
Hello kenz987,Originally posted by kenz987 View PostCan it be done? Like saving Brushes to keep your default color?
Thank you for your post.
DashStyleHelper is an enum value, so it should be serialized natively. It is not a type of object, such as TimeSpan or Brush, that requires the [XmlIgnore] attribute for serialization. To demonstrate, I have modified the SampleBrushInput script to include a DashStyleHelper user input that is used to draw a horizontal line. No additional serialization steps are needed for this to work properly, as seen in the properties region.
Please let me know if I may be of further assistance.Attached Files
Comment
-
-
Hello kenz987,Originally posted by kenz987 View PostOK another question. How do I get the index like "Solid" = 0 etc from an existing Draw.Line, I cant use DrawStyle[0] ??
Thank you for your reply.
What are you looking to achieve after getting an index for the dashStyle value from a Line object? You may access the value for DashStyleHelper from the draw object's Stroke as shown in the following snippet:
Code:private NinjaTrader.NinjaScript.DrawingTools.Line myLine; protected override void OnBarUpdate() { if (CurrentBar < 10) return; myLine = Draw.Line(this, "tag", true, 5, Low[5] - 5 * TickSize, 0, High[0] + 5 * TickSize, Brushes.Blue, DashStyleHelper.Dot, 5); Print("myLine dashStyle: " + myLine.Stroke.DashStyleHelper); }
The output shows as:
I look forward to your reply.myLine dashStyle: Dot
Comment
-
-
Hello kenz987,
Thank you for your patience.
Typecasting, which bltdavid has referred to, is a general C# concept and is not specific to NinjaTrader. We do not provide C# programming education services or one on one educational support in the NinjaScript department, so you will need to do outside research to learn more about how it works. That said, I have added to the previously modified sample to show how an int could be used to get a DashStyleHelper enum selection via typecasting and draw another horizontal line. You may test out this sample to try and get a better understanding or to achieve what you desire by converting an int into a DashStyleHelper selection. Here is the sample:
You can test this out, and even change the value for myInt in State.DataLoaded then reload NinjaScript on your chart to see how it will change through different DashStyleHelper dashStyles based on what int is used.Code:private int myInt; protected override void OnStateChange() { else if (State == State.DataLoaded) { myInt = 4; } } protected override void OnBarUpdate() { if(CurrentBar < 5) return; // Use our two user definable brush inputs for the colors of our rectangle. Draw.Rectangle(this, "CustomColorsRectangle", true, 0, High[0], 5, Low[5], BorderBrush, FillBrush, 50); Draw.HorizontalLine(this, "tag", Close[0], BorderBrush, DashStyleSelection, 5); // casting an int to an enum to get a DashStyleHelper dashStyle from myInt DashStyleHelper style = (DashStyleHelper)myInt; // draw a magenta horizontal line above the current bar's high price using the "style" we just created Draw.HorizontalLine(this, "Tag", High[0] + 5 * TickSize, Brushes.Magenta, style, 5); }
It is also important to note that typecasting works differently outside of a compiled assembly vs. inside of a compiled assembly. For more information, please see the following help guide page:
If you require additional assistance, you could also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
Thank you for your time and patience.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
581 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
338 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment