Category Other  Published on 25/06/2020

SwitchSymbol

Description

The fastest way to switch between favourite symbols.
Symbols list can be set with input parameter separated by comma.

[Update]
Added position parameter
 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SwitchSymbol : Indicator
    {
        [Parameter("Symbols", DefaultValue = "EURUSD, GBPUSD, USDJPY, AUDUSD")]
        public string SymbolsText { get; set; }

        [Parameter()]
        public Position Position { get; set; }

        protected override void Initialize()
        {
            var symbolNames = SymbolsText.Split(new[] 
            {
                ','
            }).Select(s => s.Trim()).Where(s => string.IsNullOrWhiteSpace(s) == false).ToArray();

            var verticalAlignment = (Position == Position.TopLeft || Position == Position.TopRight) ? VerticalAlignment.Top : VerticalAlignment.Bottom;
            var horizontalAlignment = (Position == Position.TopLeft || Position == Position.BottomLeft) ? HorizontalAlignment.Left : HorizontalAlignment.Right;

            var stackPanel = new StackPanel 
            {
                VerticalAlignment = verticalAlignment,
                HorizontalAlignment = horizontalAlignment,
                Margin = 8,
                Orientation = Orientation.Vertical
            };

            foreach (var symbolName in symbolNames)
            {
                var button = new Button 
                {
                    Text = symbolName,
                    Margin = 2,
                    IsEnabled = symbolName != SymbolName,
                    FontSize = 9
                };
                button.Click += Button_Click;
                stackPanel.AddChild(button);
            }

            Chart.AddControl(stackPanel);
        }

        private void Button_Click(ButtonClickEventArgs obj)
        {
            var symbolName = obj.Button.Text;
            Chart.TryChangeTimeFrameAndSymbol(TimeFrame, symbolName);
        }

        public override void Calculate(int index)
        {
        }
    }

    public enum Position
    {
        TopLeft,
        TopRight,
        BottomLeft,
        BottomRight
    }
}


bart1's avatar
bart1

Joined on 03.08.2017

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: SwitchSymbol.algo
  • Rating: 5
  • Installs: 2512
Comments
Log in to add a comment.
DA
davidiesis · 1 year ago

Thank you, it's a very useful tool.

With the latest platform update (4.2.18), the indicator has lost some compatibility. Its graphical interface disappears for a few seconds every time the chart is switched.

 

bart1's avatar
bart1 · 3 years ago

New indicator with symbols and periods
https://ctrader.com/algos/indicators/show/2562

bart1's avatar
bart1 · 4 years ago

It just needs on chart location changing option.

Added

RE
Rechnungen · 4 years ago

So easy and so usefull! 

ND
ndman.sk · 4 years ago

Cool gadget, thank you.
It just needs on chart location changing option.

LA
lab.4N25 · 4 years ago

NON funziona...

Symposium's avatar
Symposium · 4 years ago

This is a great utility for Ctrader, I can display a column of 28 crosses plus oil and metals on a 43" Monitor which requires me to only have 1 or 2 Charts open..... Very creative utility.

jani's avatar
jani · 4 years ago

Great Script, thanks a lot! This is really helping as cTrader has quite a bit memory leakage and seems not to be able to handle well multiple (over 12 or so) open charts without crashing.