Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Painting with Ninja
Updated March 29, 2017
Top Posters
looks_one
dutchbookmaker
with 7 posts (22 thanks)
looks_two
zeller4
with 1 posts (0 thanks)
looks_3
devdas
with 1 posts (0 thanks)
looks_4
granerito
with 1 posts (0 thanks)
trending_up
9,020 views
thumb_up
22 thanks given
group
5 followers
forum
10 posts
attach_file
7 attachments
Painting with Ninja
May 8th, 2011, 11:18 PM
NYC
Posts: 187 since Dec 2010
Well I'm trying to get into ninja and to learn to override plot. I'm going to post stuff as I go. Hopefully it can help someone else to learn in the future and just incase my machine crashes or something I will have a back up.
All this should work if you create an empty indicator and stick in the plot function.
This first one was just to get a feel for painting/filling rectangles and strings to the screen with Chartcontrol stuff.
You should be able to comment out parts to make it more clear what is what if need be.
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
//int barPaintWidth = base.ChartControl.ChartStyle.GetBarPaintWidth(base.ChartControl.BarWidth);
SolidBrush Brush1 = new SolidBrush(Color.Khaki);
SolidBrush Brush2 = new SolidBrush(Color.Green);
SolidBrush Brush3 = new SolidBrush(Color.Blue);
SolidBrush Brush4 = new SolidBrush(Color.Red);
SolidBrush Brush5 = new SolidBrush(Color.Orange);
SolidBrush Brush6 = new SolidBrush(Color.Yellow);
SolidBrush Brush7 = new SolidBrush(Color.Black);
SolidBrush Brush8 = new SolidBrush(Color.Aqua);
SolidBrush Brush9 = new SolidBrush(Color.White);
graphics.FillRectangle(Brush1,bounds.X ,bounds.Y, 100, 100);
graphics.FillRectangle(Brush2,bounds.X + 100 ,bounds.Y, 100, 100);
graphics.FillRectangle(Brush3,bounds.X + 100 ,bounds.Y + 100, 100, 100);
graphics.FillRectangle(Brush4,bounds.X + 200 ,bounds.Y + 200, 100, 100);
graphics.DrawRectangle(new Pen(Color.Black), bounds.X + 200, bounds.Y + 200, 100, 100);
graphics.FillRectangle(Brush5,bounds.X + 300 ,bounds.Y + 300, 100, 100);
graphics.FillRectangle(Brush6,bounds.X + 400 ,bounds.Y + 400, 100, 100);
graphics.FillRectangle(Brush7,bounds.X + 500 ,bounds.Y + 500, 100, 100);
graphics.FillRectangle(Brush8,bounds.X + 600 ,bounds.Y + 600, 100, 100);
StringFormat stringFormat = new StringFormat();
SolidBrush textBrush = new SolidBrush(Color.Black);
Font textFont = new Font("Arial", 10);
graphics.DrawString( "Brush 3" , textFont, textBrush, bounds.X + 100, bounds.Y + 100);
//graphics.DrawString( "Brush 3" , ChartControl.Font, textBrush, bounds.X, bounds.Y + 100,stringFormat);
graphics.DrawString( "Brush 4" , textFont, textBrush, bounds.X + 200, bounds.Y + 200);
graphics.DrawString( "Brush 6" , textFont, textBrush, bounds.X + 400, bounds.Y + 400);
int Bottom = ChartControl.Bottom;
int Top = ChartControl.Top;
int MarginTop = ChartControl.MarginTop;
int BarMarginRight = ChartControl.BarMarginRight;
int CanvasRight = ChartControl.CanvasRight;
int CanvasLeft = ChartControl.CanvasLeft;
int CanvasTop = ChartControl.CanvasTop;
int CanvasBottom = ChartControl.CanvasBottom;
int BoundsHeight = bounds.Height;
int BoundsBottom = bounds.Bottom;
int First = ChartControl.FirstBarPainted;
graphics.FillRectangle(Brush9,bounds.X + 500 ,bounds.Y + 100, 400, 400);
graphics.DrawRectangle(new Pen(Color.Black), bounds.X + 500, bounds.Y + 100, 400, 400);
graphics.DrawString( "ChartControl.Bottom = " + Bottom , textFont, textBrush, bounds.X + 525, bounds.Y + 125);
graphics.DrawString( "ChartControl.Top = " + Top , textFont, textBrush, bounds.X + 525, bounds.Y + 150);
graphics.DrawString( "ChartControl.MarginTop = " + MarginTop , textFont, textBrush, bounds.X + 525, bounds.Y + 175);
graphics.DrawString( "ChartControl.BarMarginRight = " + BarMarginRight , textFont, textBrush, bounds.X + 525, bounds.Y + 200);
graphics.DrawString( "ChartControl.CanvasRight = " + CanvasRight , textFont, textBrush, bounds.X + 525, bounds.Y + 225);
graphics.DrawString( "ChartControl.CanvasBottom = " + CanvasBottom , textFont, textBrush, bounds.X + 525, bounds.Y + 250);
graphics.DrawString( "ChartControl.CanvasLeft = " + CanvasLeft , textFont, textBrush, bounds.X + 525, bounds.Y + 275);
graphics.DrawString( "ChartControl.CanvasTop = " + CanvasTop , textFont, textBrush, bounds.X + 525, bounds.Y + 300);
graphics.DrawString( "bounds.Height = " + BoundsHeight , textFont, textBrush, bounds.X + 525, bounds.Y + 325);
graphics.DrawString( "bounds.Bottom = " + BoundsBottom , textFont, textBrush, bounds.X + 525, bounds.Y + 350);
graphics.DrawString( "-------------------------------" , textFont, textBrush, bounds.X + 525, bounds.Y + 375);
graphics.DrawString( "ChartControl.FirstBarPainted = " + First , textFont, textBrush, bounds.X + 525, bounds.Y + 400);
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
May 9th, 2011, 12:00 AM
NYC
Posts: 187 since Dec 2010
Needs a little more color..This is using the alpha channel for transparency and making 4 boxes that scale to the chart size.
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
int alpha = 70;
Color red = Color.FromArgb(255, 0, 0);
Color green = Color.FromArgb(0, 255, 0);
Color blue = Color.FromArgb(0, 0, 255);
Color notsure = Color.FromArgb(100, 0, 155);
SolidBrush AlphaBrush1 = new SolidBrush(Color.FromArgb(alpha,red));
SolidBrush AlphaBrush2 = new SolidBrush(Color.FromArgb(alpha,green));
SolidBrush AlphaBrush3 = new SolidBrush(Color.FromArgb(alpha,blue));
SolidBrush AlphaBrush4 = new SolidBrush(Color.FromArgb(alpha,notsure));
graphics.FillRectangle(AlphaBrush1, bounds.X + (ChartControl.CanvasRight / 2) , bounds.Y, ChartControl.CanvasRight / 2, ChartControl.CanvasBottom / 2);
graphics.FillRectangle(AlphaBrush2, bounds.X , bounds.Y, ChartControl.CanvasRight / 2, ChartControl.CanvasBottom / 2);
graphics.FillRectangle(AlphaBrush3, bounds.X , bounds.Y + (ChartControl.CanvasBottom / 2), ChartControl.CanvasRight / 2, ChartControl.CanvasBottom / 2);
graphics.FillRectangle(AlphaBrush4, bounds.X + (ChartControl.CanvasRight / 2) , bounds.Y + (ChartControl.CanvasBottom / 2), ChartControl.CanvasRight / 2, ChartControl.CanvasBottom / 2);
}
May 9th, 2011, 12:42 AM
Al,India
Experience: Advanced
Platform: NinjaTrader
Broker: Z
Trading: NiftyFuture
Posts: 1,562 since Feb 2010
Thanks Given: 1,513
Thanks Received: 1,701
Nice dutchbookmaker,
Its the same way to reach a big goal....making small small steps to complete a big task ( saw your indicator name...."heatmap...).
Keep it up.
Harvest The Moon
Nest The Market
May 9th, 2011, 01:09 AM
NYC
Posts: 187 since Dec 2010
Yea I thought a heatmap might be a fun project to learn with. Made pretty good progress tonight. This code is sloppy as hell though.
Drawing boxes with a loop and changing color with a loop.
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
Color red = Color.FromArgb(255, 0, 0);
Color green = Color.FromArgb(0, 255, 0);
Color blue = Color.FromArgb(0, 0, 255);
int x = bounds.X;
int y = bounds.Y;
int test = 0;
int alpha = 100;
int boxX;
int boxY;
int ycolorchange = 0;
SolidBrush myBrush = new SolidBrush(blue);
int CanvasRightEnd = ChartControl.CanvasRight;
int CanvasBottomEnd = ChartControl.CanvasBottom;
for (boxY = 0; boxY <= CanvasBottomEnd; boxY += 50){
for (boxX = 50; boxX <= CanvasRightEnd; boxX += 50)
{
if(test < 254 && ycolorchange < 254)
myBrush.Color = Color.FromArgb(test, ycolorchange, 255);
graphics.FillRectangle(myBrush,x,bounds.Y + y, 50, 50);
graphics.DrawRectangle(new Pen(Color.Black), x, bounds.Y + y, 50, 50);
test += 10;
x += 50;
}
test = 0;
y += 50;
x = bounds.X;
ycolorchange += 20;
}
}
May 9th, 2011, 08:25 PM
NYC
Posts: 187 since Dec 2010
Modified version of Candle Clear, shows how to draw a simple rectangle using chartcontrol x/y stuff. Just replace the plot in candle clear.
Code
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
// Default plotting in base class.
//base.Plot(graphics, bounds, min, max);
if (base.Bars == null) return;
//if (ChartControl.ChartStyleType.ToString()!="CandleStick") return;
int index = -1;
Exception caughtException;
int barPaintWidth = base.ChartControl.ChartStyle.GetBarPaintWidth(base.ChartControl.BarWidth);
int bars = base.ChartControl.BarsPainted;
while (bars >= 0)
{
index = ((base.ChartControl.LastBarPainted - base.ChartControl.BarsPainted) + 1) + bars;
if (base.ChartControl.ShowBarsRequired || ((index - base.Displacement) >= base.BarsRequired))
{
try
{
double ySize = ChartControl.GetYByValue(this,low.Get(index))- ChartControl.GetYByValue(this,high.Get(index));
int yCast = (int)ySize;
int x1 = (((base.ChartControl.CanvasRight - base.ChartControl.BarMarginRight) - (barPaintWidth / 2)) - ((base.ChartControl.BarsPainted - 1) * base.ChartControl.BarSpace)) + (bars * base.ChartControl.BarSpace);
int y1 = (bounds.Y + bounds.Height) - ((int) (((high.Get(index) - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
int y2 = (bounds.Y + bounds.Height) - ((int) (((close.Get(index) - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
int y3 = (bounds.Y + bounds.Height) - ((int) (((open.Get(index) - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
int y4 = (bounds.Y + bounds.Height) - ((int) (((low.Get(index) - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
graphics.DrawRectangle(new Pen(Color.Black), x1 - ChartControl.BarWidth,y1, ChartControl.BarWidth + (ChartControl.BarSpace / 2), yCast);
y1--;
y2--;
y3--;
y4--;
}
catch (Exception exception) { caughtException = exception; }
}
bars--;
}
}
May 9th, 2011, 09:01 PM
NYC
Posts: 187 since Dec 2010
The holy grail.
Code
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
int X = ChartControl.CanvasRight / 3;
int Y = ChartControl.CanvasBottom / 8;
//http://msdn.microsoft.com/en-us/library/4cy2c290.aspx
//Ellipse
Pen blackPen = new Pen(Color.Black, 3);
SolidBrush redBrush = new SolidBrush(Color.Red);
Rectangle rect = new Rectangle(X,Y, 500,500);
graphics.DrawEllipse(blackPen, rect);
graphics.FillEllipse(redBrush, rect);
Pen blackPen2 = new Pen(Color.Black, 3);
SolidBrush blackBrush = new SolidBrush(Color.Black);
Rectangle rect2 = new Rectangle(X + 140,Y + 80, 70,70);
graphics.DrawEllipse(blackPen, rect2);
graphics.FillEllipse(blackBrush, rect2);
Pen blackPen3 = new Pen(Color.Black, 3);
SolidBrush blackBrush2 = new SolidBrush(Color.Black);
Rectangle rect3 = new Rectangle(X + 290,Y + 80, 70,70);
graphics.DrawEllipse(blackPen3, rect3);
graphics.FillEllipse(blackBrush2, rect3);
Pen blackPen4 = new Pen(Color.Black, 3);
SolidBrush blackBrush3 = new SolidBrush(Color.Black);
Rectangle rect4 = new Rectangle(X + 225,Y + 220, 40,40);
graphics.DrawEllipse(blackPen4, rect4);
graphics.FillEllipse(blackBrush3, rect4);
Pen blackPen5 = new Pen(Color.Black, 3);
SolidBrush blackBrush4 = new SolidBrush(Color.Black);
Rectangle rect5 = new Rectangle(X + 170,Y + 320, 150,150);
graphics.DrawEllipse(blackPen5, rect5);
graphics.FillEllipse(blackBrush4, rect5);
}
May 13th, 2011, 09:07 PM
NYC
Posts: 187 since Dec 2010
Pretty sure I'm about to go down a wrong path and just want to save this code..pretty meaningless in current context .
Code
protected override void Initialize()
{
CalculateOnBarClose = false;
xSeries = new DataSeries(this);
ySeries = new DataSeries(this);
counter = 0;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
ySeries.Set(Close[0]);
xSeries.Set(CurrentBar);
Print("CloseYseries : " + Close[0]);
Print("XseriesBar: " + xSeries[0]);
}
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
int idx = counter;
if (Bars == null || Bars.Instrument == null)
return;
int alpha = 80;
Color blue = Color.FromArgb(0, 0, 255);
SolidBrush AlphaBrush = new SolidBrush(Color.FromArgb(alpha,blue));
int yPos = ChartControl.GetYByValue(this, Close[0]);
int yPos2 = ChartControl.GetYByValue(this, ySeries[0]);
int yPos100 = ChartControl.GetYByValue(this, Close[100]);
int yPos1002 = ChartControl.GetYByValue(this, ySeries[100]);
int lastX = ChartControl.GetXByBarIdx(BarsArray[0], CurrentBar);
graphics.FillRectangle(AlphaBrush, lastX - 40 , yPos2, 40, 40);
graphics.FillRectangle(AlphaBrush, lastX - 20 , yPos2 - 5, 40, 40);
}
May 14th, 2011, 09:54 AM
NYC
Posts: 187 since Dec 2010
ChartControl.GetXByTime looks like it could have some cool uses.
Code
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Last)
{
x = ChartControl.GetXByTime(e.Time);
y = ChartControl.GetYByValue(this,e.Price);
return;
}
}
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
graphics.DrawRectangle(new Pen(Color.Black), x,y, 10, 10);
}
May 29th, 2011, 12:02 AM
Orlando Florida
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404
Hi DutchBookMaker,
Here's an addition or two - you can see I'm also learning but I'm only scabbing things together. Not sure when I'll have a decent breakthrough. This is using the genericoverlay file from the NT support forum. This particular file is using MACD. I'm trying some other inputs as well (I've seen the stochastic and rsi overlays) but want to get up/down coloring to work first.
I haven't been able to get PlotColors[0][0] to work for Rising/Falling conditions. I've tried too many variations to post here. If someone can give a heads up or modify the attached code, I'd appreciate it greatly.
Best Regards,
Kirk
Attached Thumbnails
Attached Files
Elite Membership required to download: genericoverlay_v01.zip
Last Updated on March 29, 2017