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!
See more
See less

Partner 728x90

Collapse

Serializing DashStyleHelper

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Serializing DashStyleHelper

    Can it be done? Like saving Brushes to keep your default color?

    #2
    Yes. DashStyleHelper serializes normally.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Originally posted by kenz987 View Post
      Can it be done? Like saving Brushes to keep your default color?
      Hello kenz987,

      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
      Emily C.NinjaTrader Customer Service

      Comment


        #4
        Emily, Thank You !!! very much for the sample code... Ken

        Comment


          #5
          OK another question. How do I get the index like "Solid" = 0 etc from an existing Draw.Line, I cant use DrawStyle[0] ??
          Last edited by kenz987; 04-01-2023, 11:02 AM.

          Comment


            #6
            Try typecasting the enum value.

            int Index = (int)DashStyleHelper.Solid;

            Comment


              #7
              Btw, Google is your friend, try simple searches, like this.

              Comment


                #8
                Thanks David, and I did try Google first, but sometimes there are names used in c# that are not available in NT, like I was trying DashStyle , etc Can I do a foreach ( ix in DashStyleHelper.All) or .Count etc
                Last edited by kenz987; 04-01-2023, 12:22 PM.

                Comment


                  #9
                  Try this.

                  Comment


                    #10
                    Originally posted by kenz987 View Post
                    OK another question. How do I get the index like "Solid" = 0 etc from an existing Draw.Line, I cant use DrawStyle[0] ??
                    Hello kenz987,

                    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:
                    myLine dashStyle: Dot
                    I look forward to your reply.
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      I want to pass either the int index or the string "Dot" etc to another indicator, I can do the latter, but if I have an integer how do I convert that back to the "Dot" without a lot of if statements?

                      Comment


                        #12
                        You could employ typecasting.

                        DashStyleHelper style = (DashStyleHelper)index;

                        Comment


                          #13
                          Thanks again David, I tried DashStyleHelper[index] but the compiler said I was using a type as a variable. We didnt have this stuff in Cobol!

                          Comment


                            #14
                            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:

                            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);
                                    }​
                            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.

                            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.
                            Emily C.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank You Emily, I now have what I need. If this was actually in the Help guides it would save lots of everybodys time. As I told David, we didnt have this stuff in Cobol :-)

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ZenCortexCLICK, Today, 04:58 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post ZenCortexCLICK  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              172 responses
                              2,280 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post Irukandji  
                              Started by adeelshahzad, Today, 03:54 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post adeelshahzad  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X