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 set EndCap, StartCap in NT8

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

    How to set EndCap, StartCap in NT8

    Hello,

    I wish to modify the NT8 OHLC bars (RenderTarget.DrawLine) to look similar to the "rounded" plots of the Tradeguider platform. I have used EndCap, StartCap, LineCap.Round to make my own in NT7. However I just can't break through the new StrokeStyles etc.
    I tried this:

    Code:
            StrokeStyle myStrokeStyle = new StrokeStyle();
            myStrokeStyle.EndCap = CapStyle.Round;
            myStrokeStyle.StartCap = CapStyle.Round;
    I am getting an error:

    "SharpDX.Direct2D1.StrokeStyle.EndCap" - cannot be assigned to - it is read only.

    I get it, but I don't know how to fix it. Do I have to "Clone" it or something.
    I am not a professional programmer, just a "code hacker" so please be gentle

    #2
    Hello Sim22,

    Thank you for writing in. While I am not aware of any way to directly set the StartCap and EndCap in the usual fashion, you can create a StrokeStyleProperties object and pass it to the StrokeStyle.

    For example:
    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    	//Create a new StrokeStyleProperties
    	SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();
    	ssProps.StartCap = SharpDX.Direct2D1.CapStyle.Round;
    	ssProps.EndCap = SharpDX.Direct2D1.CapStyle.Round;
    	
    	//Create our StrokeStyle using the StrokeStyleProperties
    	SharpDX.Direct2D1.StrokeStyle myStyle = new SharpDX.Direct2D1.StrokeStyle(RenderTarget.Factory, ssProps);
    	
    	//Basic Example of drawing with a StrokeStyle
    	SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(new Point(500, 500).ToVector2(),	(float)(50/2f), (float)(50/2f));
    	RenderTarget.DrawEllipse(ellipse, Brushes.Red.ToDxBrush(RenderTarget), 5, myStyle);
    }
    Please let me know if this does not resolve the issue or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Great.....thank you Michael.

      I had seen similar references elsewhere while searching on the net. I could not get past the ".Factory" reference within StrokeStyle.

      I will test this solution and let you know.

      Thanks again!

      Comment


        #4
        HLC bars VSA ChartStyle

        Yes, some success thank you Michael. Please see image.....

        I basically made a new ChartStyle called "VSAStyle".

        I will be sharing this with the forum once it is complete.

        I have a couple of questions.........

        1. The start/end caps look a bit "pixellated", ie. not very smoothly rounded. Can this be fixed?
        2. How can I set the default "UpBrushDX" to Blue instead of Green?
        3. I made an icon for the toolbar for the new ChartStyle, however I found this didn't work for me:

        Code:
        Icon icon = new Icon(NinjaTrader.Core.Globals.InstallDir + "VSA_Ninja8.ico");
        So I tried this way:



        Code:
        protected override void OnStateChange()
        {[INDENT]BitmapImage myBitmapImage = new BitmapImage(); 
        
        [/INDENT][INDENT]if (State == State.SetDefaults)
        {}
        
        else if (State == State.Configure)
        {
        
                 myBitmapImage.BeginInit();
                 myBitmapImage.UriSource = new Uri(NinjaTrader.Core.Globals.InstallDir + "VSA_Ninja8.jpg");
                 myBitmapImage.EndInit();
        }
        [/INDENT]}
        
        
        
        public override object Icon
                {
                    get 
                    {
                       // Instantiate a Grid on which to place the image
                        Grid myCanvas = new Grid { Height = 16, Width = 16 };
                 
                        // Instantiate an Image to place on the Grid
                        Image image = new Image
                        {
                            Height = 16,
                            Width = 16,
                            Source = myBitmapImage
                        };
                 
                        // Add the image to the Grid
                        myCanvas.Children.Add(image);
                 
                        return myCanvas;
                    }
                }
        This worked just fine. But since I already made a .ico file surely that would eliminate a lot of code?

        Thank you.
        Attached Files

        Comment


          #5
          Hello Sim22,

          I am still checking with the rest of my team to your first question. For your second question you would just use the following in your OnStateChange() method:
          Code:
          if (State == State.SetDefaults)
          {
                  //...Other stuff
          	this.UpBrush = System.Windows.Media.Brushes.Blue;
          }
          To your third question, a .ico file is different than an Icon object in NinjaTrader so you would not be able to accomplish this in this way. I am not sure where you are getting the Icon() method from. I would recommend using the method you are now.

          I will update this post when I have further information.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            Okay, thank you.

            It seemed to me "BrushDX" was read only and could not be set, however "Brush" worked fine.
            I assumed I had to use "BrushDX". I'm still not versed enough between the differences and how they interchange........

            Cheers
            Last edited by Sim22; 10-19-2015, 08:04 PM.

            Comment


              #7
              Problems with SharpDX brushes in ChartStyle

              Michael,

              I have followed your code recommendations below, which worked fine, thank you.

              However, what if I have an EQUAL CLOSE HLC bar that is neither an up or a down bar?
              Basically I want to do this without making a separate paintbar indicator:

              Code:
              TransformBrush(overriddenBrush ?? (closeValue > closeValue1 ? UpBrushDX : (closeValue < closeValue1) ? DownBrushDX : [COLOR=Red]myBrush[/COLOR]), new RectangleF(......);
              RenderTarget.DrawLine(point0, point1, overriddenBrush ?? (closeValue > closeValue1 ? UpBrushDX : (closeValue < closeValue1) ? DownBrushDX : [COLOR=Red]myBrush[/COLOR]), lineWidth, myStyle);
              myBrush is the equal close bar brush.
              I tried making a standard brush then converting to a SharpDX brush. However, "ToDxBrush" does not appear. Is this due to this being a "ChartStyle"?
              I have worked on this for a couple of hours and I only ask if I'm really stuck.

              Thank you.
              Last edited by Sim22; 10-21-2015, 02:47 AM.

              Comment


                #8
                Hello Sim22,

                It sounds like you may be missing a library. Basically to create a new Sharp DX brush in a custom chart style, you could do the following:
                Code:
                #region Using declarations
                //....
                using System.Windows.Media;
                //....
                #endregion
                //...
                public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
                {
                	System.Windows.Media.Brush myBrush = new SolidColorBrush(Colors.Purple);
                	myBrush.ToDxBrush(RenderTarget);
                }
                In response to your earlier question about the smoothing of the StrokeStyle, could you please try the following:
                Code:
                // make sure you do this *before* you draw render the object
                RenderTarget.AntialiasMode  = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
                After setting the AntialiasMode you would draw the shape or whatever with your custom StrokeStyle and it should appear significantly smoother.

                Please let me know if I may be of further assistance.
                Michael M.NinjaTrader Quality Assurance

                Comment


                  #9
                  Smoothing works but ToBrushDX does not

                  Thanks Michael.

                  The smoothing works brilliant. I'm posting an image for anyone following this thread.

                  However the ".ToBrushDX" still does not register. Please see the screenshot.

                  I'm using Beta5.

                  Thank you.
                  Attached Files

                  Comment


                    #10
                    Fixed

                    Okay.... for anyone following this thread:

                    Code:
                    public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
                    {
                             SharpDX.Direct2D1.Brush    equalCloseBrush    = new      SharpDX.Direct2D1.SolidColorBrush(RenderTarget, Color.DarkGray);
                    
                    RenderTarget.DrawLine(point0, point1, (closeValue > closeValue1) ? UpBrushDX : ((closeValue < closeValue1) ? DownBrushDX : equalCloseBrush) , lineWidth);
                    }
                    It is apparently not recommended to use SharpDX to make new brushes but this was the only way it worked for me.

                    Thanks for your help Michael.
                    Attached Files

                    Comment


                      #11
                      Hello Sim22,

                      Thank you for posting your findings. I am always glad to be of assistance. Please enjoy the rest of your weekend!
                      Michael M.NinjaTrader Quality Assurance

                      Comment


                        #12
                        Originally posted by NinjaTrader_MichaelM View Post
                        Hello Sim22,

                        One thing I advise, you should always Dispose() the disposable variables, otherwise NT memory will eventually fire error.


                        in that example, `style` variable and brush needs to be created separately and disposed.

                        thanks.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by trilliantrader, Today, 08:16 AM
                        2 responses
                        6 views
                        0 likes
                        Last Post trilliantrader  
                        Started by samish18, Today, 08:31 AM
                        1 response
                        1 view
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by Creamers, 09-08-2023, 10:26 AM
                        6 responses
                        157 views
                        0 likes
                        Last Post JonyGurt  
                        Started by funk10101, Today, 08:14 AM
                        1 response
                        2 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by bill2023, Yesterday, 08:51 AM
                        3 responses
                        22 views
                        0 likes
                        Last Post bltdavid  
                        Working...
                        X