NexusFi: Find Your Edge


Home Menu

 





Centering chart on the Y axis


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Adamus with 7 posts (9 thanks)
    2. looks_two sniffy with 2 posts (5 thanks)
    3. looks_3 ThatManFromTexas with 1 posts (0 thanks)
    4. looks_4 madLyfe with 1 posts (1 thanks)
      Best Posters
    1. looks_one sniffy with 2.5 thanks per post
    2. looks_two Adamus with 1.3 thanks per post
    3. looks_3 madLyfe with 1 thanks per post
    4. looks_4 DavidHP with 1 thanks per post
    1. trending_up 7,809 views
    2. thumb_up 16 thanks given
    3. group 9 followers
    1. forum 12 posts
    2. attach_file 0 attachments




 
Search this Thread

Centering chart on the Y axis

  #1 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

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.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Build trailing stop for micro index(s)
Psychology and Money Management
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #3 (permalink)
 
madLyfe's Avatar
 madLyfe 
Des Moines, Iowa
 
Experience: None
Platform: Ninja, TOS
Broker: AMP/CQG, TOS
Trading: CL, TF, GC
Posts: 1,641 since Feb 2011
Thanks Given: 9,220
Thanks Received: 1,020



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 nexusfi.com (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?


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

¯\_(ツ)_/¯

(╯°□°)╯︵ ┻━┻
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

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.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

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.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #6 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

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.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

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.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #8 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

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.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #9 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,609 since Aug 2009
Thanks Given: 11,328
Thanks Received: 2,743


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 ! ! !
Follow me on Twitter Reply With Quote
Thanked by:
  #10 (permalink)
sniffy
alask
 
Posts: 7 since Oct 2009
Thanks Given: 0
Thanks Received: 5



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
Thanked by:




Last Updated on April 11, 2012


© 2024 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 - Privacy Policy - Downloads - Top
no new posts