Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to specify Dash Style for plot in custom indicator (Ninja Trader 8)

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

    How to specify Dash Style for plot in custom indicator (Ninja Trader 8)

    Hi there, I've been struggling to specify the Dash Style for a plot in my custom indicator.

    The indicator is currently working, but I can't seem to customize the dash style for any particular line/plot.

    This is my current code that works:

    AddPlot(Brushes.White, "Ema1");
    Plots[0].Width = 1.4F;

    But I'm trying to add a specified Dash Style (Dot)

    This is the code I came up with for that:

    AddPlot(Brushes.White, "Ema1");
    Plots[0].Width = 1.4F;
    Plots[0].Pen.DashStyle = DashStyle.Dot;


    After compiling, this is the error message I receive for that code:
    System.Windows.Media.DashStyle' does not contain a definition for 'Dot'

    Any help would be much appreciated since I'm fairly new to coding.
    Thanks in advance

    #2
    Hello RoswellTrader,

    Welcome to the NinjaTrader forums!

    The DashStyleHelper is part of the Stroke property.




    You could use

    AddPlot(new Stroke(Brushes.Blue, DashStyleHelper.Dot, 1.4f), PlotStyle.Line, "Ema1");

    Or set the dashStyleHelper after

    Plots[0].Stroke.DashStyleHelper = DashStyleHelper.Dot;
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      Thanks so much for the quick response, so happy to be a part of the Ninja Trader forums!

      Using your feedback, I modified the code to:

      AddPlot(new Stroke(Brushes.White, DashStyleHelper.Dot, 1.4f), PlotStyle.Line, "Ema1");

      And received these error messages:

      "The type or namespace name 'Stroke' could not be found (are you missing a using directive or an assembly reference?)"

      "The name 'DashStyleHelper does not exist in the current context"


      I've tried several variations based on suggestions and official documentation, but I'm still facing challenges with the "Dash Style" coding.

      Is there possibly a specific reference or library that I need to include in order for the DashStyleHelper code to work?

      Thanks

      Comment


        #4
        Hello RoswellTrader,

        May I confirm this is an indicator created in the NinjaScript Editor?

        Have you modified or removed the using statements at the top?

        Attached is an exported test script showing the code compiles.
        DashStyleHelperTest_NT8.zip
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes, my custom indicator has been created in the NinjaScript editor.

          I've modified my working code from this:
          AddPlot(Brushes.White, "Ema1");
          Plots[0].Width = 1.4F;

          To this, using your suggestions:
          AddPlot(new Stroke(Brushes.White, DashStyleHelper.Dot, 1.4f), PlotStyle.Line, "Ema1");

          And received these error messages:
          "The type or namespace name 'Stroke' could not be found (are you missing a using directive or an assembly reference?)"
          "The name 'DashStyleHelper does not exist in the current context"


          That's why I'm curious if I'm maybe missing a library, tool, or piece of software to allow your suggested code to work.​​

          I'm going to have a look at the "DashStyleHelperTest_NT8.zip​" now. Thanks

          Comment


            #6
            Hello RoswellTrader,

            Have you modified or removed the using statements at the top?

            If you have modified these, copy and paste the using statements from the provided test script, or create a new indicator in the NinjaScript Editor to get the default using statements.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              So sorry, I'm confused on which statements you are referring to.

              I'm fairly new to working with code so I apologize in advance for any misunderstandings.

              I have imported your "DashStyleHelperTest_NT8.zip​"​ code into Ninja Script and pressed F5 to compile.
              Last edited by RoswellTrader; 08-21-2023, 09:55 AM.

              Comment


                #8
                Hello RoswellTrader,

                What is the name of the file with the error in your screenshot? (The name of the file with the error is in the errors in the NinjaScript File column.

                I don't think the example I provided you has an error, I think the error is in a different file.

                The using directives are by default in the '#region Using declarations' at the top of the script. Using directives are added to avoid long fully qualified namespace paths.

                using NinjaTrader.Gui;

                Below is a link to the Microsoft documentation on the 'using' directive.
                The `using` directive imports types from a namespace, or creates an alias for a given type. Using directives enable you to use simple names for types instead of the fully qualified type name.


                As well as a link to a 3rd party educational site found through a google search.


                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Oh yes sorry! The error message I was receiving was from my custom indicator, not your "DashStyleHelperTest_NT8.zip​"​ code​.

                  I took your advice and applied the correct "using declarations" at the top of the script and the Dash Styles seem to be working perfectly now!

                  I can't thank you enough for all your help, and I apologize for my uneducated questions on code lol!

                  Thanks for putting up with a noob like me, your help has been life-changing!
                  Last edited by RoswellTrader; 08-21-2023, 10:16 AM.

                  Comment


                    #10
                    Hi, Chelsea.
                    Now I have one question.

                    You mentioned like this;
                    Code:
                    Plots[0].Stroke.DashStyleHelper = DashStyleHelper.Dot;
                    This is correct?
                    I can't find Stroke.DashStyleHelper. Instead I found StrokeStyle but I am not sure to use this.
                    Can you lead me?

                    Thanks.

                    Comment


                      #11
                      Hello truepenny,

                      Thank you for your post.

                      Can you explain what you mean by you "can't find" Stroke.DashStyleHelper?

                      Are you getting a compile error mentioning Stroke.DashStyleHelper? If so, please post a screenshot of the full compile error along with the line of code referenced in the error.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      577 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      334 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      553 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      551 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X