How to switch to open chart

Created at 03 Nov 2024, 20:04
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
TO

TommyFFX

Joined 07.12.2021

How to switch to open chart
03 Nov 2024, 20:04


Hello,

In a plugin we can 

- open a chart with 
            ChartManager.AddChartFrame(symbol.Name, TimeFrame.Hour)
- change a symbol and timeframe of an active chart
            ChartManager.ActiveFrame.ChartContainer.OfType<ChartFrame>().Select(frame => frame.Chart).Where(c =>
            c.IsActive).FirstOrDefault().TryChangeTimeFrameAndSymbol(symbol, TimeFrame.Hour);

But how do we just switch between open charts or what is the command to bring an open chart to the front or make it Visible ?
Kind Regards

TommyFFX

 


@TommyFFX
Replies

TommyFFX
05 Nov 2024, 00:52

The only solution I Found is to Detach the chart I want to see and Attach it back..
Then I have the option to switch between ChartFrames in code..

but this seems a bit strange..

I'm using a combobox to switch between ChartFrames..

 



        public void OnSymbolComboBox_SelectionChanged(ComboBoxSelectedItemChangedEventArgs e)

        {

                var symbol = string.IsNullOrEmpty(e.SelectedItem) ? null : tms.Symbols.GetSymbol(e.SelectedItem);

                if (symbol != null)

                {

                    var frames = FindAllChartFramesBySymbol(symbol);

                    var chartFrame = frames.FirstOrDefault();

                    if (chartFrame != null)

                    {

                        chartFrame.Detach();

                        chartFrame.Attach();

                    }

                }

        }

        public IEnumerable<ChartFrame> FindAllChartFrames()

        {

            return ChartManager.OfType<ChartFrame>();

        }

        public IEnumerable<ChartFrame> FindAllChartFramesBySymbol(Symbol symbol)

        {

            return FindAllChartFrames().Where(frame => frame.Chart.Symbol == symbol);

        }

 


@TommyFFX

TommyFFX
07 Nov 2024, 22:32

RE: How to switch to open chart

TommyFFX said: 

The only solution I Found is to Detach the chart I want to see and Attach it back..
Then I have the option to switch between ChartFrames in code..

but this seems a bit strange..

I'm using a combobox to switch between ChartFrames..

 



        public void OnSymbolComboBox_SelectionChanged(ComboBoxSelectedItemChangedEventArgs e)

        {

                var symbol = string.IsNullOrEmpty(e.SelectedItem) ? null : tms.Symbols.GetSymbol(e.SelectedItem);

                if (symbol != null)

                {

                    var frames = FindAllChartFramesBySymbol(symbol);

                    var chartFrame = frames.FirstOrDefault();

                    if (chartFrame != null)

                    {

                        chartFrame.Detach();

                        chartFrame.Attach();

                    }

                }

        }

        public IEnumerable<ChartFrame> FindAllChartFrames()

        {

            return ChartManager.OfType<ChartFrame>();

        }

        public IEnumerable<ChartFrame> FindAllChartFramesBySymbol(Symbol symbol)

        {

            return FindAllChartFrames().Where(frame => frame.Chart.Symbol == symbol);

        }

 



Up


@TommyFFX

PanagiotisCharalampous
08 Nov 2024, 06:31

Hi there,

But how do we just switch between open charts or what is the command to bring an open chart to the front or make it Visible ?

There is no such command.

Best regards,

Panagiotis


@PanagiotisCharalampous