Painting with Ninja - NinjaTrader Programming | futures io social day trading
futures io futures trading


Painting with Ninja
Updated: Views / Replies:4,021 / 10
Created: by dutchbookmaker Attachments:7

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 7  
 
Thread Tools Search this Thread
 

Painting with Ninja

  #1 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received

Painting with Ninja

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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
Painting with Ninja-chartcontrol.jpg  
Reply With Quote
The following 7 users say Thank You to dutchbookmaker for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received


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
Painting with Ninja-alphaboxes.jpg  
Reply With Quote
The following 5 users say Thank You to dutchbookmaker for this post:
 
  #4 (permalink)
 Vendor: www.edevaay.com 
Al,India
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: RKG
Favorite Futures: NiftyFuture
 
devdas's Avatar
 
Posts: 1,547 since Feb 2010
Thanks: 1,460 given, 1,661 received

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
Reply With Quote
 
  #5 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received

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
Painting with Ninja-heat.jpg  
Reply With Quote
The following 3 users say Thank You to dutchbookmaker for this post:
 
  #6 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received

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
Painting with Ninja-candleclear.jpg  
Reply With Quote
The following 3 users say Thank You to dutchbookmaker for this post:
 
  #7 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received

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
Painting with Ninja-useless.jpg  
Reply With Quote
The following 2 users say Thank You to dutchbookmaker for this post:
 
  #8 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received

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
The following user says Thank You to dutchbookmaker for this post:
 
  #9 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: None
Platform: graph paper and pencil
Favorite Futures: harp
 
dutchbookmaker's Avatar
 
Posts: 187 since Dec 2010
Thanks: 9 given, 107 received

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
The following user says Thank You to dutchbookmaker for this post:
 
  #10 (permalink)
Elite Member
Florida
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: CL, NQ, NG
 
Posts: 456 since Jun 2009
Thanks: 1,359 given, 383 received


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
Painting with Ninja-6e-06-11-7-range-5_27_2011.jpg  
Attached Files
Register to download File Type: zip genericoverlay_v01.zip (3.8 KB, 39 views)
Reply With Quote

Reply



futures io > > > > > Painting with Ninja

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toggle Indicator Painting in Ninja? drmartell NinjaTrader 16 July 1st, 2012 10:43 PM
Switching Fin.Alg TPO Market profile from Ninja 6.5 to ninja 7 MadManmos Trading Reviews and Vendors 19 August 23rd, 2011 09:15 AM
Why do markers stop painting even tho no compile errors Saroj NinjaTrader Programming 4 August 14th, 2009 06:37 PM
Why only the last few instances of the marker painting? Saroj NinjaTrader Programming 1 August 13th, 2009 01:56 AM
Arrows Painting 2 bars back Saroj NinjaTrader 0 June 12th, 2009 04:12 PM


All times are GMT -4. The time now is 08:53 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-16 in 0.15 seconds with 20 queries on phoenix via your IP 54.160.245.121