Centering chart on the Y axis - NinjaTrader Programming | futures io social day trading
futures io futures trading


Centering chart on the Y axis
Updated: Views / Replies:4,233 / 12
Created: by Adamus 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
 

Centering chart on the Y axis

  #1 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

Centering chart on the Y axis

I want to put a few common mouse-driven tasks that I often do into NinjaScript and execute them with one click on a button.

My most frequent task is to center the price on the Y axis because I use a fixed scale on my charts rather than allowing Ninjatrader to vary the Y axis according to the data shown.

I search all over futures.io (formerly BMT) and NinjaTrader.com/support but I can't find anything conclusive.

So far I'm adding buttons to the chart trader and I've got one button to toggle the executions on and off, and I now need another code snippet to center the price on the Y axis.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Resources;
using System.Windows.Forms;
using System.Collections;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Enter the description of your Indicator here
    /// </summary>
    [Description("Indicator to add chart trader buttons")]
    public class ChartTraderExtra : Indicator
    {
        protected bool Initialized = false;
        private Button toggleTradesButton = null;        
        private Button centrePriceButton = null;        
                        
        public override void Dispose()
        {
            if (Initialized)
            {
                if (ChartControl != null)
                {
                    Panel panel = (Panel) ChartControl.Controls["pnlChartTrader"];
                    if (panel != null 
                        && panel.Controls["ctrChartTraderControl"] != null
                        && toggleTradesButton != null)
                    {
                        Control control = panel.Controls["ctrChartTraderControl"];
                        control.Controls.Remove(toggleTradesButton);
                        control.Controls.Remove(centrePriceButton);
                        toggleTradesButton.Click -= new EventHandler(toggleTrades_Click);
                        centrePriceButton.Click -= new EventHandler(centrePrice_Click);
                    }
                }
            }
        }
        
        protected virtual void OnInitializeBeforeStart()
        {
            CreateChartTraderButtons();
        }
                
        protected override void Initialize()
        {
            Overlay = true;
            CalculateOnBarClose = true;
        }

        
        protected override void OnBarUpdate()
        {
            if (!Initialized)
            {
                OnInitializeBeforeStart();
                Initialized = true;
                Panel panel = (Panel) ChartControl.Controls["pnlChartTrader"];
                if (false // remove "false" for debugging
                    && panel != null 
                    && panel.Controls["ctrChartTraderControl"] != null)
                {
                    Control control = panel.Controls["ctrChartTraderControl"];
                    for (int k = 0; k <= control.Controls.Count - 1; k++)
                    {
                        Control button = control.Controls[k];
                        string msg = button.Name 
                            + " L:" + button.Left
                            + " T:" + button.Top
                            + " H:" + button.Height
                            + " W:" + button.Width;
                        Log(msg, NinjaTrader.Cbi.LogLevel.Alert);
                    }
                }
            }
        }
        
        protected void CreateChartTraderButtons()
        {
            if (ChartControl != null)
            {
                Panel panel = (Panel) ChartControl.Controls["pnlChartTrader"];
                if (panel != null 
                    && panel.Controls["ctrChartTraderControl"] != null)
                {
                    Control control = panel.Controls["ctrChartTraderControl"];
                    toggleTradesButton = new Button();
                    toggleTradesButton.Name = "toggleTrades";
                    toggleTradesButton.Text = "Toggle Trades";
                    toggleTradesButton.Height = 40;
                    toggleTradesButton.Width = 72;
                    toggleTradesButton.Left = 8;
                    toggleTradesButton.Top = 436;
                    toggleTradesButton.Click += new EventHandler(toggleTrades_Click);
                    control.Controls.Add(toggleTradesButton);
                    centrePriceButton = new Button();
                    centrePriceButton.Name = "centrePrice";
                    centrePriceButton.Text = "Centre Price";
                    centrePriceButton.Height = 40;
                    centrePriceButton.Width = 72;
                    centrePriceButton.Left = 88;
                    centrePriceButton.Top = 436;
                    centrePriceButton.Click += new EventHandler(centrePrice_Click);
                    control.Controls.Add(centrePriceButton);
                }
            }
        }
        
        private void toggleTrades_Click(object sender, EventArgs e)
        {
            //Log("toggle trades!", NinjaTrader.Cbi.LogLevel.Alert);
            if (ChartControl.BarsArray[0].BarsData.PlotExecutions ==
                ChartExecutionStyle.DoNotPlot)
            {
                ChartControl.BarsArray[0].BarsData.PlotExecutions = 
                    ChartExecutionStyle.MarkersOnly;
            }
            else if (ChartControl.BarsArray[0].BarsData.PlotExecutions ==
                ChartExecutionStyle.MarkersOnly)
            {
                ChartControl.BarsArray[0].BarsData.PlotExecutions = 
                    ChartExecutionStyle.TextAndMarker;
            }
            else if (ChartControl.BarsArray[0].BarsData.PlotExecutions ==
                ChartExecutionStyle.TextAndMarker)
            {
                ChartControl.BarsArray[0].BarsData.PlotExecutions = 
                    ChartExecutionStyle.DoNotPlot;
            }            
        }    

        private void centrePrice_Click(object sender, EventArgs e)
        {
            Log("centre price! - " + ChartControl.ChartPanel., NinjaTrader.Cbi.LogLevel.Alert);
            
        }    
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private ChartTraderExtra[] cacheChartTraderExtra = null;

        private static ChartTraderExtra checkChartTraderExtra = new ChartTraderExtra();

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public ChartTraderExtra ChartTraderExtra()
        {
            return ChartTraderExtra(Input);
        }

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public ChartTraderExtra ChartTraderExtra(Data.IDataSeries input)
        {
            if (cacheChartTraderExtra != null)
                for (int idx = 0; idx < cacheChartTraderExtra.Length; idx++)
                    if (cacheChartTraderExtra[idx].EqualsInput(input))
                        return cacheChartTraderExtra[idx];

            lock (checkChartTraderExtra)
            {
                if (cacheChartTraderExtra != null)
                    for (int idx = 0; idx < cacheChartTraderExtra.Length; idx++)
                        if (cacheChartTraderExtra[idx].EqualsInput(input))
                            return cacheChartTraderExtra[idx];

                ChartTraderExtra indicator = new ChartTraderExtra();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                Indicators.Add(indicator);
                indicator.SetUp();

                ChartTraderExtra[] tmp = new ChartTraderExtra[cacheChartTraderExtra == null ? 1 : cacheChartTraderExtra.Length + 1];
                if (cacheChartTraderExtra != null)
                    cacheChartTraderExtra.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheChartTraderExtra = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.ChartTraderExtra ChartTraderExtra()
        {
            return _indicator.ChartTraderExtra(Input);
        }

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public Indicator.ChartTraderExtra ChartTraderExtra(Data.IDataSeries input)
        {
            return _indicator.ChartTraderExtra(input);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.ChartTraderExtra ChartTraderExtra()
        {
            return _indicator.ChartTraderExtra(Input);
        }

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public Indicator.ChartTraderExtra ChartTraderExtra(Data.IDataSeries input)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.ChartTraderExtra(input);
        }
    }
}
#endregion

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
The following user says Thank You to Adamus 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)
Elite Member
Des Moines, Iowa
 
Futures Experience: None
Platform: Ninja, TOS
Broker/Data: AMP/CQG, TOS
Favorite Futures: CL, TF, GC
 
madLyfe's Avatar
 
Posts: 1,641 since Feb 2011
Thanks: 9,217 given, 1,011 received



Adamus View Post
I want to put a few common mouse-driven tasks that I often do into NinjaScript and execute them with one click on a button.

My most frequent task is to center the price on the Y axis because I use a fixed scale on my charts rather than allowing Ninjatrader to vary the Y axis according to the data shown.

I search all over futures.io (formerly BMT) and NinjaTrader.com/support but I can't find anything conclusive.

So far I'm adding buttons to the chart trader and I've got one button to toggle the executions on and off, and I now need another code snippet to center the price on the Y axis.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Resources;
using System.Windows.Forms;
using System.Collections;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Enter the description of your Indicator here
    /// </summary>
    [Description("Indicator to add chart trader buttons")]
    public class ChartTraderExtra : Indicator
    {
        protected bool Initialized = false;
        private Button toggleTradesButton = null;        
        private Button centrePriceButton = null;        
                        
        public override void Dispose()
        {
            if (Initialized)
            {
                if (ChartControl != null)
                {
                    Panel panel = (Panel) ChartControl.Controls["pnlChartTrader"];
                    if (panel != null 
                        && panel.Controls["ctrChartTraderControl"] != null
                        && toggleTradesButton != null)
                    {
                        Control control = panel.Controls["ctrChartTraderControl"];
                        control.Controls.Remove(toggleTradesButton);
                        control.Controls.Remove(centrePriceButton);
                        toggleTradesButton.Click -= new EventHandler(toggleTrades_Click);
                        centrePriceButton.Click -= new EventHandler(centrePrice_Click);
                    }
                }
            }
        }
        
        protected virtual void OnInitializeBeforeStart()
        {
            CreateChartTraderButtons();
        }
                
        protected override void Initialize()
        {
            Overlay = true;
            CalculateOnBarClose = true;
        }

        
        protected override void OnBarUpdate()
        {
            if (!Initialized)
            {
                OnInitializeBeforeStart();
                Initialized = true;
                Panel panel = (Panel) ChartControl.Controls["pnlChartTrader"];
                if (false // remove "false" for debugging
                    && panel != null 
                    && panel.Controls["ctrChartTraderControl"] != null)
                {
                    Control control = panel.Controls["ctrChartTraderControl"];
                    for (int k = 0; k <= control.Controls.Count - 1; k++)
                    {
                        Control button = control.Controls[k];
                        string msg = button.Name 
                            + " L:" + button.Left
                            + " T:" + button.Top
                            + " H:" + button.Height
                            + " W:" + button.Width;
                        Log(msg, NinjaTrader.Cbi.LogLevel.Alert);
                    }
                }
            }
        }
        
        protected void CreateChartTraderButtons()
        {
            if (ChartControl != null)
            {
                Panel panel = (Panel) ChartControl.Controls["pnlChartTrader"];
                if (panel != null 
                    && panel.Controls["ctrChartTraderControl"] != null)
                {
                    Control control = panel.Controls["ctrChartTraderControl"];
                    toggleTradesButton = new Button();
                    toggleTradesButton.Name = "toggleTrades";
                    toggleTradesButton.Text = "Toggle Trades";
                    toggleTradesButton.Height = 40;
                    toggleTradesButton.Width = 72;
                    toggleTradesButton.Left = 8;
                    toggleTradesButton.Top = 436;
                    toggleTradesButton.Click += new EventHandler(toggleTrades_Click);
                    control.Controls.Add(toggleTradesButton);
                    centrePriceButton = new Button();
                    centrePriceButton.Name = "centrePrice";
                    centrePriceButton.Text = "Centre Price";
                    centrePriceButton.Height = 40;
                    centrePriceButton.Width = 72;
                    centrePriceButton.Left = 88;
                    centrePriceButton.Top = 436;
                    centrePriceButton.Click += new EventHandler(centrePrice_Click);
                    control.Controls.Add(centrePriceButton);
                }
            }
        }
        
        private void toggleTrades_Click(object sender, EventArgs e)
        {
            //Log("toggle trades!", NinjaTrader.Cbi.LogLevel.Alert);
            if (ChartControl.BarsArray[0].BarsData.PlotExecutions ==
                ChartExecutionStyle.DoNotPlot)
            {
                ChartControl.BarsArray[0].BarsData.PlotExecutions = 
                    ChartExecutionStyle.MarkersOnly;
            }
            else if (ChartControl.BarsArray[0].BarsData.PlotExecutions ==
                ChartExecutionStyle.MarkersOnly)
            {
                ChartControl.BarsArray[0].BarsData.PlotExecutions = 
                    ChartExecutionStyle.TextAndMarker;
            }
            else if (ChartControl.BarsArray[0].BarsData.PlotExecutions ==
                ChartExecutionStyle.TextAndMarker)
            {
                ChartControl.BarsArray[0].BarsData.PlotExecutions = 
                    ChartExecutionStyle.DoNotPlot;
            }            
        }    

        private void centrePrice_Click(object sender, EventArgs e)
        {
            Log("centre price! - " + ChartControl.ChartPanel., NinjaTrader.Cbi.LogLevel.Alert);
            
        }    
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private ChartTraderExtra[] cacheChartTraderExtra = null;

        private static ChartTraderExtra checkChartTraderExtra = new ChartTraderExtra();

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public ChartTraderExtra ChartTraderExtra()
        {
            return ChartTraderExtra(Input);
        }

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public ChartTraderExtra ChartTraderExtra(Data.IDataSeries input)
        {
            if (cacheChartTraderExtra != null)
                for (int idx = 0; idx < cacheChartTraderExtra.Length; idx++)
                    if (cacheChartTraderExtra[idx].EqualsInput(input))
                        return cacheChartTraderExtra[idx];

            lock (checkChartTraderExtra)
            {
                if (cacheChartTraderExtra != null)
                    for (int idx = 0; idx < cacheChartTraderExtra.Length; idx++)
                        if (cacheChartTraderExtra[idx].EqualsInput(input))
                            return cacheChartTraderExtra[idx];

                ChartTraderExtra indicator = new ChartTraderExtra();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                Indicators.Add(indicator);
                indicator.SetUp();

                ChartTraderExtra[] tmp = new ChartTraderExtra[cacheChartTraderExtra == null ? 1 : cacheChartTraderExtra.Length + 1];
                if (cacheChartTraderExtra != null)
                    cacheChartTraderExtra.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheChartTraderExtra = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.ChartTraderExtra ChartTraderExtra()
        {
            return _indicator.ChartTraderExtra(Input);
        }

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public Indicator.ChartTraderExtra ChartTraderExtra(Data.IDataSeries input)
        {
            return _indicator.ChartTraderExtra(input);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.ChartTraderExtra ChartTraderExtra()
        {
            return _indicator.ChartTraderExtra(Input);
        }

        /// <summary>
        /// Indicator to add chart trader buttons
        /// </summary>
        /// <returns></returns>
        public Indicator.ChartTraderExtra ChartTraderExtra(Data.IDataSeries input)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.ChartTraderExtra(input);
        }
    }
}
#endregion

not sure im on the right side of the topic here, but have you checked this work out?

https://futures.io/elite-circle/13209-vertical-scroll-experimental.html

dont believe anything you hear and only half of what you see

¯\_(ツ)_/¯

(╯°□°)╯︵ ┻━┻

Last edited by madLyfe; February 14th, 2012 at 02:59 PM.
Reply With Quote
The following user says Thank You to madLyfe for this post:
 
  #4 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

Man, that is a big piece of programming. The answer's bound to be in there somewhere

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
 
  #5 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

Nope, can't figure it from that. Too much stuff going on to be able to work it out there.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
 
  #6 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

Finally figured it out thanks due to @devdas

 
Code
                            
            this.ChartControl.YAxisRangeTypeRight YAxisRangeType.Fixed;
            
double yAxisSize this.ChartControl.FixedPanelMaxRight 
                
this.ChartControl.FixedPanelMinRight;
            
this.ChartControl.FixedPanelMaxRight Close[0] + (yAxisSize 2);
            
this.ChartControl.FixedPanelMinRight Close[0] - (yAxisSize 2); 

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
The following 5 users say Thank You to Adamus for this post:
 
  #7 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

Still not perfected the indicator yet - I have a slight bug with the code for toggling the show-trades on and off. When I click my button, it executes the script, but sometimes and I haven't figured out when it does and when it doesn't, the chart doesn't change unless I move my mouse over the chart.

If I can get this fixed, it'll be sorted and I can upload the indie to the upload area.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
 
  #8 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

This is the code

This is the code that occasionally doesn't work until I mouse-over the chart:

 
Code
                            
        private void CentrePrice_Click(object senderEventArgs e)
        {
            
this.ChartControl.YAxisRangeTypeRight YAxisRangeType.Fixed;
            
double yAxisSize this.ChartControl.FixedPanelMaxRight 
                
this.ChartControl.FixedPanelMinRight;
            
this.ChartControl.FixedPanelMaxRight 
                
Close[CurrentBar this.LastBarIndexPainted] + (yAxisSize 2);
            
this.ChartControl.FixedPanelMinRight 
                
Close[CurrentBar this.LastBarIndexPainted] - (yAxisSize 2);
        }    

        protected 
override void OnBarUpdate()
        {
            if (!
Initialized)
            {
                
centrePriceButton = new Button();
                
Control control panel.Controls["ctrChartTraderControl"];
                
control.Controls.Add(centrePriceButton);
                
centrePriceButton.Click += new EventHandler(CentrePrice_Click);
                
Initialized true;
             }
        } 
Often it works immediately - sometimes it feels like it needs a tick to come through to work - and sometimes I have to move the mouse over to make it work.

Can anyone offer some good advice?

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
 
  #9 (permalink)
Market Wizard
New Orleans, La (Mardi Gras City)
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Ninjatrader / Optimus Futures / AmpFutures
Favorite Futures: ES / 6E / 6B / CL
 
DavidHP's Avatar
 
Posts: 1,001 since Aug 2009
Thanks: 802 given, 1,367 received


Adamus View Post
Can anyone offer some good advice?

Have you checked THIS thread?
Maybe it can give you some ideas.
It is about setting the chart to a fixed scroll amount.

Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Reply With Quote
The following user says Thank You to DavidHP for this post:
 
  #10 (permalink)
Trading Apprentice
alask
 
Futures Experience: Master
Platform: ninja
 
Posts: 7 since Oct 2009
Thanks: 0 given, 5 received

force it to repaint then it won't wait for mouseover etc



Adamus View Post
This is the code that occasionally doesn't work until I mouse-over the chart:

 
Code
                            
        private void CentrePrice_Click(object senderEventArgs e)

        {
            
this.ChartControl.YAxisRangeTypeRight YAxisRangeType.Fixed;
            
double yAxisSize this.ChartControl.FixedPanelMaxRight 
                
this.ChartControl.FixedPanelMinRight;
            
this.ChartControl.FixedPanelMaxRight 
                
Close[CurrentBar this.LastBarIndexPainted] + (yAxisSize 2);
            
this.ChartControl.FixedPanelMinRight 
                
Close[CurrentBar this.LastBarIndexPainted] - (yAxisSize 2);
        }    

        protected 
override void OnBarUpdate()
        {
            if (!
Initialized)
            {
                
centrePriceButton = new Button();
                
Control control panel.Controls["ctrChartTraderControl"];
                
control.Controls.Add(centrePriceButton);
                
centrePriceButton.Click += new EventHandler(CentrePrice_Click);
                
Initialized true;
             }
        } 
Often it works immediately - sometimes it feels like it needs a tick to come through to work - and sometimes I have to move the mouse over to make it work.

Can anyone offer some good advice?

this works for me

#region Event Handlers
private void centrePrice_Click(object sender, EventArgs e)
{
this.ChartControl.YAxisRangeTypeRight = YAxisRangeType.Fixed;
double yAxisSize = this.ChartControl.FixedPanelMaxRight -
this.ChartControl.FixedPanelMinRight;
this.ChartControl.FixedPanelMaxRight = Close[0] + (yAxisSize / 2);
this.ChartControl.FixedPanelMinRight = Close[0] - (yAxisSize / 2);

// force repaint so we dont have to wait for another event
ChartControl.ChartPanel.Invalidate(); // <<<<<<--------------------

}
#endregion Event Handlers

Reply With Quote
The following 3 users say Thank You to sniffy for this post:

Reply



futures io > > > > > Centering chart on the Y axis

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the time axis (x axis) on Sierra Charts Affliction Sierra Chart 2 September 27th, 2011 01:27 PM
InvestorRT axis label coloring Big Mike Investor/RT 3 August 18th, 2011 07:53 AM
MATLAB Dates on the x - axis jakfourie Matlab, R project and Python 11 June 27th, 2011 03:55 AM
Formatting the Y-Axis Fat Tails NinjaTrader Programming 12 January 26th, 2011 06:32 AM
plot reference axis SARdynamite NinjaTrader Programming 1 July 8th, 2010 08:50 AM


All times are GMT -4. The time now is 11:42 AM.

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-11 in 0.14 seconds with 19 queries on phoenix via your IP 54.82.81.154