![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
|
I want toaddcode to a Ninja Script so that a different background color can be drawn between say an Upper and Lower Bollinger band. Apparently this can be done by over riding the Plot method with a custom drawing using native .Net graphics classes.
If anyone knows how to do this and is happy to share could you please post a few lines of sample code which shows the underlying instruction syntax necessary to achieve the desired result. Many thanks |
|
|
|
|
|
#2 | |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 109
Thanks: 0
Thanked 0 times in 0 posts
|
I'm a beginner with C#, and I wanted the same thing. I could not figure how to do it with .Net graphics so I settled for using NinjaScript to draw rectangles.
Quote:
|
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
|
Thankyou for the post tquinn - will give what you suggest a try......
|
|
|
|
|
|
#4 |
|
Junior Member
Join Date: May 2006
Location: Certified NinjaScript Consultant, ,
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
Hi
Try this Code:
SolidBrush brush = new SolidBrush(Color.Gray);
int barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
GraphicsPath path = new GraphicsPath();
for (int seriesIndex = 0; seriesIndex < 2; seriesIndex++)
{
int lastX = -1;
int lastY = -1;
DataSeries series = (DataSeries) Values[seriesIndex];
double val = 0;
Gui.Chart.Plot plot = Plots[seriesIndex];
for (int barIndex = 0; barIndex < ChartControl.BarsPainted; barIndex++)
{
int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + barIndex;
if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
continue;
val = series.Get(idx);
int x = (int) (ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
- (ChartControl.BarsPainted - 1) * ChartControl.BarSpace + barIndex * ChartControl.BarSpace) + 1;
int y = (int) ((bounds.Y + bounds.Height) - ((val - min ) / (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();
}
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillPath(brush, path);
graphics.SmoothingMode = oldSmoothingMode;
Final http://fin-alg.com/ |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 109
Thanks: 0
Thanked 0 times in 0 posts
|
Muly,
I'm not good enough with C# to use this. I placed it in OnBarUpdate() and it produced a bunch of compile errors. I'm sure it is my lack of C# skills. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
|
Wow,
Well beyond my skills too! Thanks heaps for posting this Muly.Iattempt to get it working... Cheers |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: May 2006
Location: Certified NinjaScript Consultant, ,
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
Hi
the post bellow is the code for the Plot function Code:
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max) Final http://fin-alg.com/ |
|
|
|
|
|
#8 | |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 109
Thanks: 0
Thanked 0 times in 0 posts
|
Muly,
It is good to get a lesson on how much there is to learn about a new programmimg language. If I understand your code, it is plotting vertical lines between Values[0] and Values[1]. So I've created only those 2 Values. This is what I have so far, but it still will not compile. Errors about "using directives" and "assemble references", things I know nothing about. Quote:
|
|
|
|
|
|
|
#9 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Please paste in error messages. They likely are not related to Muly's code. Likely your NT installation is screwed up.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: May 2006
Location: Certified NinjaScript Consultant, ,
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
Probebly the using directive is missing some here is my
Code:
using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; using System.Xml.Serialization; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; Muly Final http://fin-alg.com/ |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 109
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks all,
I was missing " using System.Drawing.Drawing2D;", Muly's code runs fine now. Now I need to learn how to put the Colored area behind the price bars, and maybe change the opacity. I'll save this lesson for a later day. I need to get back to Mastering NinjaScript before I wander too far off track, into the world of C# and .NET. Thanks again |
|
|
|
|
|
#12 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Tom,
Just curious: "using System.Drawing.Drawing2D;" should be part of the code generated by the indicator wizard. Do you know why it was not there? Thanks
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|