Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help with OnRender

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

    help with OnRender

    I'd like to be able to fill in seamless rectangles for individual prices/bars on the chart. But no matter how I define the cells I get overlaps and/or gaps which vary depending on the chart scaling.

    I'm attaching basic code; I've tried a number of modifications of cellWidth and cellHeight but haven't found anything that works and allows dynamic scaling. (The problem is much more visible when opacity is set below 100%.)

    Is there a way to do this someone could show me?

    Code:
    		protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
    			
                if(Bars == null || Bars.Instrument == null || IsInHitTest)
    				return;
    
    			int		firstBarPainted 	= ChartBars.FromIndex;
    			int		lastBarPainted		= ChartBars.ToIndex;
    
    			double	tickSize			= Bars.Instrument.MasterInstrument.TickSize;
    			double highPrice 			= chartScale.MaxValue;
    			double lowPrice 			= chartScale.MinValue;
    			
    			float cellWidth = chartControl.GetXByBarIndex(ChartBars, lastBarPainted) - chartControl.GetXByBarIndex(ChartBars, lastBarPainted-1) ;
    			float cellHeight = chartScale.GetYByValue(highPrice) - chartScale.GetYByValue(highPrice - TickSize);
    			
    			for (int i = firstBarPainted; i <= lastBarPainted; i ++ )
    			{
    				float xpos = chartControl.GetXByBarIndex(ChartBars, i);
    				for (double p = highPrice; p >= lowPrice; p -= tickSize)
    				{	
    					RenderTarget.FillRectangle(new RectangleF(xpos , chartScale.GetYByValue(p), cellWidth, cellHeight), Brushes.Gray.ToDxBrush(RenderTarget));		
    				}
    				
    			}
    
    			
    		}
    Last edited by palinuro; 01-07-2016, 10:43 PM.

    #2
    Hello,

    I wanted to check, I have attached two images as I was unsure what outcome you were trying to get specifically. The two images seemed like the most logical outcome from the code provided, could you tell me if I have understood correctly and if either image matches your end goal?

    If not could you provide a more clear description or an image that demonstrates the end result you want? a drawing on top of a chart would be fine if needed.

    The two samples are very similar, the only difference is the first is aligned left with the center of the bar, the second is minus half the distance from the prior bar up to plus half distance to the next bar.

    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for the response, Jesse. I should have included pics.

      Here are 4 images with different chart scalings, all with the code above but with opacity set to half in order to show the overlapping as well as the gaps.

      The appearance varies depending on the scale, but I would like it to be seamless - or if that is impossible, at least consistent. As is, there are sometimes vertical gaps, sometimes vertical overlaps, sometimes horizontal gaps, sometimes horizontal overlaps, and various mixes of these.
      Attached Files

      Comment


        #4
        Hello,

        I just wanted to check as the image is slightly confusing on what specifically is the focus.

        Can you tell me, are the grid lines on or is this the effect you are talking about?

        Specifically in the first image, it looks to be a grid but is this instead the space between the rectangles?

        In the following images, would that also be the white lines either vertical in some images or horizontal in the others?

        If so this may be due to the values being used. I see that you are rounding to a tick size which may or may not be the cause. Can you first confirm if I am looking at the correct lines in the image?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          There are no grid lines on; all the lines are created as byproducts of the code. (Except the black lines, which are from the cursor.).

          Both the white lines (gaps) and the darker blue lines (images 2 and 4, overlap only visible when opacity is set below 100%) , both vertical and horizontal. They appear, disappear and change as I change the x and y chart scaling.

          Thanks for looking into this.

          Comment


            #6
            Hello,

            I wanted to follow up on this item.

            I have attached a different sample that plots a Grid on the visible area of the chart.

            NinjaTrader_Matthew was kind enough to provide a good example of plotting Lines on the TickSize Prices and accounting for scaling with OnRender. This should cover the price calculations for your Vertical portion of the script, regarding how you want the rectangles horizontally this should provide enough of a framework to modify to your needs.


            I look forward to being of further assistance.
            Attached Files
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse and Matthew,

              but I don't think drawing accurate gridlines is the problem, I can do that.

              Filling rectangles on the basis of those gridlines results in the rectangles having edge gaps and/or overlaps, depending on the x/y scaling.

              I made a quick modification of your code to fill rectangles (see attached) and got the same result as I had previously.

              Perhaps there's something else I can do with the single x-y cell width and height - but it seems like it's a problem with translating the rendering from the NT calculations to the individual pixels on the screen, since with the result varies so much with scaling.
              Attached Files
              Last edited by palinuro; 01-18-2016, 11:00 PM.

              Comment


                #8
                (Bump.)

                Any other ideas for fixing this?

                Comment


                  #9
                  I think I may have found a solution to this problem.

                  http://ninjatrader.com/support/forum...982#post461982

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by PaulMohn, Today, 12:36 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post PaulMohn  
                  Started by Conceptzx, 10-11-2022, 06:38 AM
                  2 responses
                  53 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Started by Kaledus, Today, 01:29 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Kaledus
                  by Kaledus
                   
                  Started by yertle, Yesterday, 08:38 AM
                  8 responses
                  37 views
                  0 likes
                  Last Post ryjoga
                  by ryjoga
                   
                  Started by rdtdale, Today, 01:02 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Working...
                  X