NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript File Sharing > NinjaScript File Sharing Discussion

NinjaScript File Sharing Discussion Discussion for shared NinjaScript files.

Reply
 
Thread Tools Display Modes
Old 03-14-2008, 10:27 PM   #1
wayneFH
Senior Member
 
Join Date: Mar 2008
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
Default 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)

twisted.jpg

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 at 10:30 PM.
wayneFH is offline  
Reply With Quote
Old 03-14-2008, 10:50 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-16-2008, 01:36 PM   #3
wayneFH
Senior Member
 
Join Date: Mar 2008
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
Default

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.

twisted.jpg

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
wayneFH is offline  
Reply With Quote
Old 03-16-2008, 02:35 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-17-2008, 10:26 AM   #5
wayneFH
Senior Member
 
Join Date: Mar 2008
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
Default

I will try to get the GraphicsPath to work.

Thanks for your help.

Sincerely,
Wayne
wayneFH is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Testing OHLC, pivots and session breaks Harry Historical NinjaTrader 6.5 Beta Threads 54 03-27-2008 08:19 AM
Buy on second bar as it breaks first pls help gamblor Strategy Development 7 02-16-2008 08:38 AM


All times are GMT -6. The time now is 07:51 PM.