GOM drawing OHLC and candlestick code - NinjaTrader Programming | futures io social day trading
futures io futures trading


GOM drawing OHLC and candlestick code
Updated: Views / Replies:2,686 / 4
Created: by tinkerz Attachments:0

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
 
Thread Tools Search this Thread
 

GOM drawing OHLC and candlestick code

  #1 (permalink)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker/Data: Zenfire
Favorite Futures: EMINI
 
Posts: 34 since Feb 2010
Thanks: 0 given, 3 received

GOM drawing OHLC and candlestick code

I am trying to lift the GOM code to produce candlestick and OHLC the indicator window.

So far I have initialized the following functions, but I am not sure about DrawOnPricePanel = false;

The variable for Open High Low and Close I have checked and are working fine.
Highbanddata
Openbanddata
Lowbanddata
Closebanddata

But no plotting

public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)

public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)

I am not sure how these two statements will work as I am not running the GOMindicator class, just the usual :indicator class

So I dont know where to place them to get them to work, any help on this?

It would be nice to do OHLC and candles in the indicator pane, or does one else have code for this?

Thanks

Neil

CalculateOnBarClose = false;
Overlay = false;
PriceTypeSupported = false;
DrawOnPricePanel = false;

 
Code
        public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
        {    
            if (Bars==null)    return;

                if (useplot)
                {
//                    #if NT7
//                        int lastBar        = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
//                        int firstBar    = this.FirstBarIndexPainted;
//                    #else
                        int lastBar        = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
                        int firstBar    = Math.Max((lastBar - ChartControl.BarsPainted) + 1,0);
//                    #endif            
                    min=Double.MaxValue;
                    max=Double.MinValue;
                                                        
                    for(int index=firstBar;index<=lastBar;index++)
                    {        
                        if ((index<=lastcalcbar) && (index >=Math.Max(1,startbar)))
                        {   
                            min=Math.Min(min,Lowbanddata.Get(index));
                            max=Math.Max(max,Highbanddata.Get(index));
                        }
                    }
                }
                
            else
                base.GetMinMaxValues(chartControl, ref  min, ref  max);

        }        
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars==null)    return;

            if (useplot)
            {
//            #if NT7
//                int lastBar        = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
//                int firstBar    = this.FirstBarIndexPainted;
//            #else
                int lastBar        = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
                int firstBar    = Math.Max((lastBar - ChartControl.BarsPainted) + 1,0);
//            #endif
                                
            int barPaintWidth =  ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
            int barwidth=ChartControl.BarWidth;
    
            #if !NT7
                double scalingfactor= (double)bounds.Height/ChartControl.MaxMinusMin(max, min);
            #endif                
            //Color ColorNeutral=Color.FromArgb(255,255-ChartControl.BackColor.R,255-ChartControl.BackColor.G,255-ChartControl.BackColor.B);
            
//            #if NT7
//                Pen outlinePen=ChartControl.ChartStyle.Pen;            
//            #else                
                Pen outlinePen=ChartControl.BarOutlinePen;
//            #endif

            Color ColorNeutral=outlinePen.Color;

            Pen HiLoPen= (Pen)outlinePen.Clone();

            if (EnhanceHL)
                HiLoPen.Width *=2;
                
            SolidBrush drawBrush=new SolidBrush(Color.Transparent);
            SolidBrush neutralBrush=new SolidBrush(ColorNeutral);

            int penSize;        
            if (ChartControl.ChartStyle.ChartStyleType==ChartStyleType.OHLC)
                penSize=Math.Max(0,barwidth-2);
            else if (ChartControl.ChartStyle.ChartStyleType==ChartStyleType.HiLoBars)
                penSize=barwidth;
            else
                penSize=1;
            
            Pen drawPen=new Pen(Color.Transparent,penSize);
            
            int x, yHigh, yClose, yOpen, yLow;    
            int direction;            
            
            //zero line
//            #if NT7
//                int y0=ChartControl.GetYByValue(this,0.0);
//            #else
                int y0=(bounds.Y + bounds.Height) + Convert.ToInt32(min * scalingfactor);
//            #endif        

            
            for(int index=firstBar;index<=lastBar;index++)
            {

                direction=0;
                
                if ((index<=lastcalcbar) && (index >=Math.Max(1,startbar)))
                
                {    
//                    #if NT7 
//                        x=ChartControl.GetXByBarIdx(BarsArray[0],index);
//                        yHigh = ChartControl.GetYByValue(this,Highbanddata.Get(index));
//                        yClose = ChartControl.GetYByValue(this,Closebanddata.Get(index));
//                        yOpen = ChartControl.GetYByValue(this,Openbanddata.Get(index)) ;
//                       yLow = ChartControl.GetYByValue(this,Lowbanddata.Get(index)) ;

//                    #else
                        x=ChartControl.GetXByBarIdx(index);
                        yHigh = (bounds.Y + bounds.Height) - Convert.ToInt32((Highbanddata.Get(index) - min) * scalingfactor);
                        yClose = (bounds.Y + bounds.Height) - Convert.ToInt32((Closebanddata.Get(index) - min)  * scalingfactor);
                        yOpen = (bounds.Y + bounds.Height) - Convert.ToInt32((Openbanddata.Get(index) - min)  * scalingfactor) ;
                        yLow = (bounds.Y + bounds.Height) - Convert.ToInt32((Lowbanddata.Get(index) - min) * scalingfactor) ;
//                    #endif
                                        
                    if (PtType==PaintType.StrongUpDown)                            
                    {
                        if ( Closebanddata.Get(index)<Lowbanddata.Get(index-1) )
                            direction=-1;
                        else if ( Closebanddata.Get(index)>Highbanddata.Get(index-1)  )
                            direction=1;
                    }
                    else if (PtType==PaintType.UpDown)    
                    {
                        if ( Closebanddata.Get(index)<Openbanddata.Get(index) )
                            direction=-1;
                        else if ( Closebanddata.Get(index)>Openbanddata.Get(index)  )
                            direction=1;
                    }                        
                        
                    
                    if (direction==1)
                    {
                        drawPen.Color=ChartControl.UpColor;
                    }
                    else if (direction==-1)
                    {
                        drawPen.Color=ChartControl.DownColor;
                    }
                    else
                    {
                        drawPen.Color=ColorNeutral;
                    }
                            
                    drawBrush.Color=drawPen.Color;    
                                        

                    if ((ChartControl.ChartStyle.ChartStyleType==ChartStyleType.HiLoBars))
                    {    
                        graphics.DrawLine(drawPen,x,yHigh,x,yLow);
                    }
                    
                    else if (ChartControl.ChartStyle.ChartStyleType==ChartStyleType.CandleStick)
                    {                        
                        graphics.DrawLine(HiLoPen,x,yLow,x,yHigh);

                        if (yClose==yOpen)
                            graphics.DrawLine(outlinePen,x-barwidth-outlinePen.Width,yClose,x+barwidth+outlinePen.Width,yClose);
                        
                        else
                        {    
                            
                            graphics.FillRectangle(drawBrush,x-barwidth-outlinePen.Width,Math.Min(yClose,yOpen)+1,2*(barwidth+outlinePen.Width)+1,Math.Abs(yClose-yOpen)-1);
    
                            if (ShowOutline)
                            {    
                            //    graphics.FillRectangle(neutralBrush,x-barwidth-outlinepenwidth,Math.Min(yClose,yOpen)+1,2*(barwidth+outlinepenwidth)+1,Math.Abs(yClose-yOpen)-1);
                            //    graphics.FillRectangle(drawBrush,x-barwidth,Math.Min(yClose,yOpen)+1,2*barwidth+1,Math.Abs(yClose-yOpen)-1);

                            graphics.DrawRectangle(outlinePen,x-barwidth-outlinePen.Width/2,Math.Min(yClose,yOpen),2*(barwidth)+outlinePen.Width+1,Math.Abs(yClose-yOpen));
                            }
                            
                        }
                    }
                        
                    else    
                    {
                        graphics.DrawLine(drawPen,x,yLow+penSize/2,x,yHigh-penSize/2);
                        graphics.DrawLine(drawPen,x,yClose,x+barwidth,yClose);                            
                        graphics.DrawLine(drawPen,x-barwidth,yOpen,x,yOpen);
                    }
                }    
            }    
            }
            else
                base.Plot(graphics,bounds,min, max);
            
        }

Reply With Quote
 
  #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)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker/Data: Zenfire
Favorite Futures: EMINI
 
Posts: 34 since Feb 2010
Thanks: 0 given, 3 received


Ok solved I need to put the bar number in.

One more question, how do i get a simple plotted SMA over the bar if i use plot

protected override void OnMarketDepth(MarketDepthEventArgs e)
{

if (startbar==-1) startbar=CurrentBar;

lastcalcbar=CurrentBar;

Reply With Quote
 
  #4 (permalink)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker/Data: Zenfire
Favorite Futures: EMINI
 
Posts: 34 since Feb 2010
Thanks: 0 given, 3 received

Now last thing, how do I get a simple moving average from the new plot to overlay the candlestick bars, it will no plot ontop of the bars?

Reply With Quote
 
  #5 (permalink)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker/Data: Zenfire
Favorite Futures: EMINI
 
Posts: 34 since Feb 2010
Thanks: 0 given, 3 received

ok all solved just draw another plot line

Reply With Quote

Reply



futures io > > > > > GOM drawing OHLC and candlestick code

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
candlestick reading Rick Reynolds Traders Hideout 6 February 10th, 2016 11:41 PM
Indicator to show total Length of a Candlestick or Bar for NT 7.0 tom_c NinjaTrader 9 June 27th, 2012 10:54 PM
Time remaining code for candlestick chart NJ cattlefitter NinjaTrader 3 July 20th, 2011 06:42 PM
candlestick pattern - need help to code this true777 NinjaTrader Programming 2 December 2nd, 2010 06:42 PM
Candlestick Border Colour yroyal NinjaTrader 1 December 8th, 2009 02:46 AM


All times are GMT -4. The time now is 01:14 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-13 in 0.08 seconds with 19 queries on phoenix via your IP 54.82.79.109