NexusFi: Find Your Edge


Home Menu

 





GOM drawing OHLC and candlestick code


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
 tinkerz 
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: EMINI
Posts: 34 since Feb 2010
Thanks Given: 0
Thanks Received: 3

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 NexusFi?
SEC Chairman Calls for New Golden Age of SEC-CFTC Regula …
Traders Hideout
The May 31 Binary: 60% Trump Declares Iran Ops Over, Onl …
Prediction Markets & Event Contracts
GDP Day: The First Economic Reckoning -- Pahlavi at 6.55 …
Prediction Markets & Event Contracts
CME Raises Energy Futures Margins After Iran-War Volatil …
Commodities
CME Group Fee Schedule Changes Hit All Four Exchanges -- …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 tinkerz 
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: EMINI
Posts: 34 since Feb 2010
Thanks Given: 0
Thanks Received: 3


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
  #4 (permalink)
 tinkerz 
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: EMINI
Posts: 34 since Feb 2010
Thanks Given: 0
Thanks Received: 3

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
  #5 (permalink)
 tinkerz 
UK
 
Experience: Intermediate
Platform: Ninja Trader Tradestation
Broker: Zenfire
Trading: EMINI
Posts: 34 since Feb 2010
Thanks Given: 0
Thanks Received: 3

ok all solved just draw another plot line


Started this thread Reply With Quote




Last Updated on March 8, 2010


© 2026 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 - Downloads - Top
no new posts