GOM drawing OHLC and candlestick code - futures io
futures io futures trading



GOM drawing OHLC and candlestick code


Discussion in NinjaTrader

Updated
    1. trending_up 3,842 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

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

 
Search this Thread
 

GOM drawing OHLC and candlestick code

(login for full post details)
  #1 (permalink)
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: EMINI
 
Posts: 34 since Feb 2010
Thanks: 0 given, 3 received

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);
            
        }

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
ZigZag with Depth and Backstep
EasyLanguage Programming
Can the Magnet Tool Affect Chart Orders In Overcharts Ha …
Platforms and Indicators
Indicators for pair trading MES and M2K
Platforms and Indicators
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
Learning By Example [Request]
NinjaTrader
 
 
(login for full post details)
  #3 (permalink)
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: 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;

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: 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?

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: EMINI
 
Posts: 34 since Feb 2010
Thanks: 0 given, 3 received

ok all solved just draw another plot line

Started this thread Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > GOM drawing OHLC and candlestick code


Last Updated on March 8, 2010


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 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