Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Paint with Bar Breaks.

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

    How to Paint with Bar Breaks.

    Currently I have an indicator which draws horizontal zones on the hour and it paints the zones light red and light blue. But I don't like the diagonal connection of the painted area. How can I make it break and only draw horizontally? (see attached image)

    Click image for larger version

Name:	twisted.jpg
Views:	1
Size:	35.8 KB
ID:	890358

    I'm using PlotStyle.Hash for the lines and they break on the hour bar nicely rather than ugly diagonal connections.

    But overriding the plot function to paint the space between the bars leaves those with diagonal connections

    Is there any way to paint horizontally up to the boundary between the break bars and then paint the next bar horizontally?

    Here's the overriding plot method.

    Thanks!
    Wayne

    Code:
           public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
            {
                base.Plot(graphics, bounds, min, max);
                if (Bars == null || ChartControl == null)
                    return;
                    
                SolidBrush brushblue = new SolidBrush(Color.FromArgb(60,Color.Blue));
                SolidBrush brushred     = new SolidBrush(Color.FromArgb(60,Color.Red));
                int    barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
                SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
                GraphicsPath path = new GraphicsPath();
                GraphicsPath path2 = new GraphicsPath();
                            
                if(fill)
                {
                    //Color Long Buy Zone
                    for (int seriesCount = 0; seriesCount < 2; seriesCount++)
                    {
                        int    lastX = -1;
                        int    lastY = -1;
                        DataSeries    series = (DataSeries) Values[seriesCount];
                        double val = 0;
                        Gui.Chart.Plot plot = Plots[seriesCount];
        
                        for (int count = 0; count < ChartControl.BarsPainted; count++)
                        {
                            int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count;
                            if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
                                continue;
        
                            val    = series.Get(idx);
                            if (val == 0)
                                continue;
        
                            int            x    = (int) (ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
                                - (ChartControl.BarsPainted - 1) * ChartControl.BarSpace + count * ChartControl.BarSpace) + 1;
                            int            y    = (int) ((bounds.Y + bounds.Height) - ((val - min ) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);
        
                            if (lastX >= 0) 
                            {
                                path.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);
                            }
        
                            lastX    = x;
                            lastY    = y;
                        }
                        path.Reverse();
                    }
                    
                    //Color Short Buy Zone
                    for (int seriesCount = 3; seriesCount < 5; seriesCount++)
                    {
                        int    lastX = -1;
                        int    lastY = -1;
                        DataSeries    series = (DataSeries) Values[seriesCount];
                        double val = 0;
                        Gui.Chart.Plot plot = Plots[seriesCount];
        
                        for (int count = 0; count < ChartControl.BarsPainted; count++)
                        {
                            int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count;
                            if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
                                continue;
        
                            val    = series.Get(idx);
                            if (val == 0)
                                continue;
        
                            int            x    = (int) (ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
                                - (ChartControl.BarsPainted - 1) * ChartControl.BarSpace + count * ChartControl.BarSpace) + 1;
                            int            y    = (int) ((bounds.Y + bounds.Height) - ((val - min ) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);
        
                            if (lastX >= 0) 
                            {
                                path2.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);
                            }
        
                            lastX    = x;
                            lastY    = y;
                        }
                        path2.Reverse();
                        
                    }
                }
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.SmoothingMode = oldSmoothingMode;
                graphics.FillPath(brushblue, path);
                graphics.FillPath(brushred, path2);
            }
    Last edited by wayneFH; 03-14-2008, 10:30 PM.

    #2
    Instead of using the Plot override script you have there try using DrawRegion(). Make distinct regions and only paint where you want. See if that works out
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Josh. But how can I get the shading to fill to the ends of the horizontal lines? Here's an image of the results of using DrawRegion().
      NOTE: You will see I also tried DrawRectangle() with exactly the same results.

      Click image for larger version

Name:	twisted.jpg
Views:	1
Size:	35.2 KB
ID:	848747

      So the DrawRegion() and DrawRectangle() function draw from the center to center of bars. But the horizontal lines draw from the boundary between bars.

      How can I make the paint fit exactly with the line? Any ideas?

      Sincerely,
      Wayne

      Comment


        #4
        Unfortunately this is beyond the level we can support. To do what you want you will have to do the Plot() override method. A hint would be that you need to go through the code you took from the TRO Buy Zone indicator and work out the GraphicsPath part.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I will try to get the GraphicsPath to work.

          Thanks for your help.

          Sincerely,
          Wayne

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          4 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Started by samish18, Yesterday, 08:31 AM
          2 responses
          9 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by Mestor, 03-10-2023, 01:50 AM
          16 responses
          391 views
          0 likes
          Last Post z.franck  
          Working...
          X