NexusFi: Find Your Edge


Home Menu

 





Painting with Ninja


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one dutchbookmaker with 7 posts (22 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 zeller4 with 1 posts (0 thanks)
    4. looks_4 devdas with 1 posts (0 thanks)
    1. trending_up 8,989 views
    2. thumb_up 22 thanks given
    3. group 5 followers
    1. forum 10 posts
    2. attach_file 7 attachments




 
Search this Thread

Painting with Ninja

  #1 (permalink)
 dutchbookmaker 
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);
}

Attached Thumbnails
Click image for larger version

Name:	chartcontrol.jpg
Views:	442
Size:	82.2 KB
ID:	38276  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 dutchbookmaker 
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);




}

Attached Thumbnails
Click image for larger version

Name:	alphaboxes.jpg
Views:	273
Size:	150.1 KB
ID:	38277  
Reply With Quote
  #4 (permalink)
 
devdas's Avatar
 devdas 
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
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 dutchbookmaker 
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;


}

}

Attached Thumbnails
Click image for larger version

Name:	heat.jpg
Views:	208
Size:	102.6 KB
ID:	38279  
Reply With Quote
  #6 (permalink)
 dutchbookmaker 
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--;                    
            }
        }

Attached Thumbnails
Click image for larger version

Name:	candleclear.jpg
Views:	425
Size:	77.5 KB
ID:	38332  
Reply With Quote
  #7 (permalink)
 dutchbookmaker 
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);
            
            
            
        }

Attached Thumbnails
Click image for larger version

Name:	useless.jpg
Views:	243
Size:	66.3 KB
ID:	38338  
Reply With Quote
  #8 (permalink)
 dutchbookmaker 
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);
        }

Reply With Quote
  #9 (permalink)
 dutchbookmaker 
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);
        }

Reply With Quote
  #10 (permalink)
 zeller4 
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
Click image for larger version

Name:	6E 06-11 (7 Range)  5_27_2011.jpg
Views:	323
Size:	88.9 KB
ID:	39522  
Attached Files
Elite Membership required to download: genericoverlay_v01.zip
Reply With Quote




Last Updated on March 29, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts