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

How to Draw dashed line NT 8

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

    How to Draw dashed line NT 8

    I want to draw dashed lines using but cannot find a working example.
    Reference points to Stroke class but it is not a recognized class. Under NT7 I used DashStyle to draw dashed lines.

    #2
    Hello afshinmoshrefi,

    When using Draw.Line(), a DashStyleHelper can be used.

    For example:
    Code:
    Draw.Line(this, "lineTag", true, 10, Low[10] - 3 * TickSize, 0, High[0] + 3 * TickSize, Brushes.Blue, [B]DashStyleHelper.Dash[/B], 2);
    Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I need to use : RenderTarget.DrawLine

      I need to use RenderTarget.DrawLine

      This is the format in the docs :

      RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle)

      However StrokeStyle isn't a recognized class.

      The example below copied from the documents is incomplete and does not work:




      Vector2 point0 = new Vector2();
      Vector2 point1 = new Vector2();

      point0.X = point0X;
      point0.Y = point0Y;
      point1.X = point1X;
      point1.Y = point1Y;

      RenderTarget.DrawLine(point0, point1, Stroke.BrushDX, Stroke.Width, Stroke.StrokeStyle);

      Comment


        #4
        Hello afshinmoshrefi,

        It appears you are trying to get values from a type and not from an object.

        Stroke is a type.

        Try making a new stroke object and getting the values from that.

        Code:
        Stroke aStroke = new Stroke(Brushes.Blue, DashStyleHelper.Dash, 2);
        RenderTarget.DrawLine(point0, point1, aStroke.BrushDX, aStroke.Width, aStroke.StrokeStyle);
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          getting memory corruption error

          Just tried your lines inside OnRender in a test indicator - attached

          SharpDX.Vector2 pp1 = new SharpDX.Vector2(0, chartScale.GetYByValue(2135));
          SharpDX.Vector2 pp2 = new SharpDX.Vector2(1300, chartScale.GetYByValue(2135));

          Stroke aStroke = new Stroke(Brushes.Blue, DashStyleHelper.Dash, 2);
          RenderTarget.DrawLine(pp1, pp2, aStroke.BrushDX, aStroke.Width, aStroke.StrokeStyle);

          It compiles but gets the following run time error:

          Visual Studio shows the following :

          An exception of type 'System.AccessViolationException' occurred in SharpDX.Direct2D1.dll but was not handled in user code

          Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
          Attached Files

          Comment


            #6
            Originally posted by afshinmoshrefi View Post
            Just tried your lines inside OnRender in a test indicator - attached

            SharpDX.Vector2 pp1 = new SharpDX.Vector2(0, chartScale.GetYByValue(2135));
            SharpDX.Vector2 pp2 = new SharpDX.Vector2(1300, chartScale.GetYByValue(2135));

            Stroke aStroke = new Stroke(Brushes.Blue, DashStyleHelper.Dash, 2);
            RenderTarget.DrawLine(pp1, pp2, aStroke.BrushDX, aStroke.Width, aStroke.StrokeStyle);

            It compiles but gets the following run time error:

            Visual Studio shows the following :

            An exception of type 'System.AccessViolationException' occurred in SharpDX.Direct2D1.dll but was not handled in user code

            Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
            Make sure to set the RenderTarget property before using the stroke

            Code:
            Stroke aStroke = new Stroke(Brushes.Blue, DashStyleHelper.Dash, 2);
            
            aStroke.RenderTarget = RenderTarget;
            
            RenderTarget.DrawLine(pp1, pp2, aStroke.BrushDX, aStroke.Width, aStroke.StrokeStyle);
            Last edited by NinjaTrader_Matthew; 11-15-2016, 03:45 PM.
            MatthewNinjaTrader Product Management

            Comment


              #7
              It worked

              Thank you. That worked.
              Is creating Stroke object the only way to draw a dashed line using RenderTarget.DrawLine?

              Comment


                #8
                Originally posted by afshinmoshrefi View Post
                Thank you. That worked.
                Is creating Stroke object the only way to draw a dashed line using RenderTarget.DrawLine?
                You do not need to use the NinjaTrader.Gui.Stroke.

                You can use your own Direct2D1.StrokeStyle



                Attached is an example of creating a custom sharpdx StrokeStyle object using a StrokeStyleProperties struct.
                Attached Files
                MatthewNinjaTrader Product Management

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by funk10101, Today, 12:02 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by GLFX005, Today, 03:23 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by nandhumca, Yesterday, 03:41 PM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by The_Sec, Yesterday, 03:37 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by vecnopus, Today, 06:15 AM
                0 responses
                1 view
                0 likes
                Last Post vecnopus  
                Working...
                X