Skip to content

ChartManager

interface cAlgo.API

DesktopCLICloud

Represents the list of all the chart frames.

Environment behaviour

CLI — not supported. Available to plugins only, and plugins cannot run in the CLI.

Cloud — not supported. Available to plugins only, and plugins cannot run in the cloud.

Definition

public interface ChartManager

Namespace: cAlgo.API · Group: Chart

Examples

Example 1

using cAlgo.API;

namespace cAlgo.Plugins;

public partial class Test : Plugin
{
    protected override void OnStart()
    {
        var customFrame = ChartManager.AddCustomFrame("Test");

        var webview = new WebView();

        webview.NavigateAsync("https://ctrader.com/");

        customFrame.Child = webview;
    }
}
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class Test():
    def on_start(self):
        customFrame = api.ChartManager.AddCustomFrame("Test")

        webview = WebView()
        webview.NavigateAsync("https://ctrader.com/")

        customFrame.Child = webview
{
  "AccessRights": "None"
}

Example 2

using cAlgo.API;
using System.Linq;
using System;

namespace cAlgo.Plugins;

public partial class Test : Plugin
{
    protected override void OnStart()
    {
        var addWebViewCustomFrameButton = new Button { Text = "Add WebView Custom Frame" };

        addWebViewCustomFrameButton.Click += args =>
        {
            var customFrame = ChartManager.AddCustomFrame("WebView");

            var webView = new WebView();

            webView.NavigateAsync("https://ctrader.com/");

            customFrame.Child = webView;
        };

        var addAccountInfoCustomFrameButton = new Button { Text = "Add Account Info Custom Frame" };

        addAccountInfoCustomFrameButton.Click += args =>
        {
            var customFrame = ChartManager.AddCustomFrame("Account Info");

            var grid = new Grid(16, 2)
            {
                BackgroundColor = Color.Gold,
                Opacity = 0.6,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };

            var style = new Style();

            style.Set(ControlProperty.Padding, 5);
            style.Set(ControlProperty.Margin, 5);
            style.Set(ControlProperty.FontWeight, FontWeight.ExtraBold);
            style.Set(ControlProperty.BackgroundColor, Color.Black);

            grid.AddChild(new TextBlock { Text = "Account Info", Style = style, HorizontalAlignment = HorizontalAlignment.Center }, 0, 0, 1, 2);

            grid.AddChild(new TextBlock { Text = "Type", Style = style }, 1, 0);
            grid.AddChild(new TextBlock { Text = Account.AccountType.ToString(), Style = style }, 1, 1);

            grid.AddChild(new TextBlock { Text = "Is Live", Style = style }, 2, 0);
            grid.AddChild(new TextBlock { Text = Account.IsLive.ToString(), Style = style }, 2, 1);

            grid.AddChild(new TextBlock { Text = "Balance", Style = style }, 3, 0);
            grid.AddChild(new TextBlock { Text = Account.Balance.ToString(), Style = style }, 3, 1);

            grid.AddChild(new TextBlock { Text = "Broker Name", Style = style }, 4, 0);
            grid.AddChild(new TextBlock { Text = Account.BrokerName, Style = style }, 4, 1);

            grid.AddChild(new TextBlock { Text = "Currency", Style = style }, 5, 0);
            grid.AddChild(new TextBlock { Text = Account.Asset.Name, Style = style }, 5, 1);

            grid.AddChild(new TextBlock { Text = "Number", Style = style }, 6, 0);
            grid.AddChild(new TextBlock { Text = Account.Number.ToString(), Style = style }, 6, 1);

            grid.AddChild(new TextBlock { Text = "Equity", Style = style }, 7, 0);
            grid.AddChild(new TextBlock { Text = Account.Equity.ToString(), Style = style }, 7, 1);

            grid.AddChild(new TextBlock { Text = "Free Margin", Style = style }, 8, 0);
            grid.AddChild(new TextBlock { Text = Account.FreeMargin.ToString(), Style = style }, 8, 1);

            grid.AddChild(new TextBlock { Text = "Margin", Style = style }, 9, 0);
            grid.AddChild(new TextBlock { Text = Account.Margin.ToString(), Style = style }, 9, 1);

            grid.AddChild(new TextBlock { Text = "Margin Level", Style = style }, 10, 0);
            grid.AddChild(new TextBlock { Text = Account.MarginLevel.ToString(), Style = style }, 10, 1);

            grid.AddChild(new TextBlock { Text = "Precise Leverage", Style = style }, 11, 0);
            grid.AddChild(new TextBlock { Text = Account.PreciseLeverage.ToString(), Style = style }, 11, 1);

            grid.AddChild(new TextBlock { Text = "Stop Out Level", Style = style }, 12, 0);
            grid.AddChild(new TextBlock { Text = Account.StopOutLevel.ToString(), Style = style }, 12, 1);

            grid.AddChild(new TextBlock { Text = "Unrealized Gross Profit", Style = style }, 13, 0);
            grid.AddChild(new TextBlock { Text = Account.UnrealizedGrossProfit.ToString(), Style = style }, 13, 1);

            grid.AddChild(new TextBlock { Text = "Unrealized Net Profit", Style = style }, 14, 0);
            grid.AddChild(new TextBlock { Text = Account.UnrealizedNetProfit.ToString(), Style = style }, 14, 1);

            grid.AddChild(new TextBlock { Text = "User Id", Style = style }, 15, 0);
            grid.AddChild(new TextBlock { Text = Account.UserId.ToString(), Style = style }, 15, 1);

            customFrame.Child = grid;
        };

        var addChartFrameButton = new Button { Text = "Add Chart Frame" };

        addChartFrameButton.Click += args =>
        {
            var chartFrame = ChartManager.AddChartFrame(Symbols.First(), TimeFrame.Daily);

            chartFrame.LinkedChartGroup = LinkedChartGroup.A;

            chartFrame.Activate();
        };

        var removeAllCustomFramesButton = new Button {Text = "Remove All Custom Frames"};

        removeAllCustomFramesButton.Click += args =>
        {
            var customFrames = ChartManager.OfType<CustomFrame>().ToArray();

            foreach (var customFrame in customFrames)
            {
                ChartManager.RemoveFrame(customFrame.Id);
            }
        };

        var changeMainChartContainerModeButton = new Button {Text = "Change Main Chart Container Mode"};

        changeMainChartContainerModeButton.Click += args =>
        {
            ChartManager.ChartContainers.MainChartContainer.Mode = (ChartMode)Random.Shared.Next(0, 3);
        };

        var panel = new StackPanel { Orientation = Orientation.Vertical };

        panel.AddChild(addWebViewCustomFrameButton);
        panel.AddChild(addAccountInfoCustomFrameButton);
        panel.AddChild(addChartFrameButton);
        panel.AddChild(removeAllCustomFramesButton);
        panel.AddChild(changeMainChartContainerModeButton);

        var aspBlock = Asp.SymbolTab.AddBlock("Chart Manager Test");

        aspBlock.Child = panel;

        ChartManager.FramesAdded += args => Print($"New frames added, #: {args.AddedFrames.Count()}");
        ChartManager.FramesRemoved += args => Print($"Frames removed, #: {args.RemovedFrames.Count()}");
        ChartManager.ActiveFrameChanged += args => Print($"Active frame changed to: {args.NewFrame.Id}");

        Print($"Current open frames #: {ChartManager.Count}");
        Print($"Current Active frame is {ChartManager.ActiveFrame?.Id}");
    }
}
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class Test():
    def on_start(self):
        addWebViewCustomFrameButton = Button()
        addWebViewCustomFrameButton.Text = "Add WebView Custom Frame"
        addWebViewCustomFrameButton.Click += self.on_add_webview_custom_frame_button_click

        addAccountInfoCustomFrameButton = Button()
        addAccountInfoCustomFrameButton.Text = "Add Account Info Custom Frame"
        addAccountInfoCustomFrameButton.Click += self.on_add_account_info_custom_frame_button_click

        addChartFrameButton = Button()
        addChartFrameButton.Text = "Add Chart Frame"
        addChartFrameButton.Click += self.on_add_chart_frame_button_click

        removeAllCustomFramesButton = Button()
        removeAllCustomFramesButton.Text = "Remove All Custom Frames"
        removeAllCustomFramesButton.Click += self.on_remove_all_custom_frames_button_click

        changeMainChartContainerModeButton = Button()
        changeMainChartContainerModeButton.Text = "Change Main Chart Container Mode"
        changeMainChartContainerModeButton.Click += self.on_change_main_chart_container_mode_button_click

        panel = StackPanel()
        panel.Orientation = Orientation.Vertical

        panel.AddChild(addWebViewCustomFrameButton)
        panel.AddChild(addAccountInfoCustomFrameButton)
        panel.AddChild(addChartFrameButton)
        panel.AddChild(removeAllCustomFramesButton)
        panel.AddChild(changeMainChartContainerModeButton)

        aspBlock = api.Asp.SymbolTab.AddBlock("Chart Manager Test")
        aspBlock.Child = panel

        api.ChartManager.FramesAdded += lambda args: print(f"New frames added, #: {len(args.AddedFrames)}")
        api.ChartManager.FramesRemoved += lambda args: print(f"Frames removed, #: {len(args.RemovedFrames)}")
        api.ChartManager.ActiveFrameChanged += lambda args: print(f"Active frame changed to: {args.NewFrame.Id}")

        print(f"Current open frames #: {api.ChartManager.Count}")
        print(f"Current Active frame is {api.ChartManager.ActiveFrame.Id}")

    def on_add_webview_custom_frame_button_click(self, args):
        customFrame = api.ChartManager.AddCustomFrame("WebView")

        webView = WebView()
        webView.NavigateAsync("https://ctrader.com/")

        customFrame.Child = webView

    def on_add_account_info_custom_frame_button_click(self, args):
        customFrame = api.ChartManager.AddCustomFrame("Account Info")
        grid = Grid(16, 2)
        grid.BackgroundColor = Color.Gold
        grid.Opacity = 0.6
        grid.HorizontalAlignment = HorizontalAlignment.Center
        grid.VerticalAlignment = VerticalAlignment.Center

        self.style = Style()

        self.style.Set(ControlProperty.Padding, 5)
        self.style.Set(ControlProperty.Margin, 5)
        self.style.Set(ControlProperty.FontWeight, FontWeight.ExtraBold)
        self.style.Set(ControlProperty.BackgroundColor, Color.Black)

        headerTextBox = self.getTextBlock("Account Info")
        headerTextBox.HorizontalAlignment = HorizontalAlignment.Center

        grid.AddChild(headerTextBox, 0, 0, 1, 2)
        grid.AddChild(self.getTextBlock("Type"), 1, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.AccountType)), 1, 1)
        grid.AddChild(self.getTextBlock("Is Live"), 2, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.IsLive)), 2, 1)
        grid.AddChild(self.getTextBlock("Balance"), 3, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.Balance)), 3, 1)
        grid.AddChild(self.getTextBlock("Broker Name"), 4, 0)
        grid.AddChild(self.getTextBlock(api.Account.BrokerName), 4, 1)
        grid.AddChild(self.getTextBlock("Currency"), 5, 0)
        grid.AddChild(self.getTextBlock(api.Account.Asset.Name), 5, 1)
        grid.AddChild(self.getTextBlock("Number"), 6, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.Number)), 6, 1)
        grid.AddChild(self.getTextBlock("Equity"), 7, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.Equity)), 7, 1)
        grid.AddChild(self.getTextBlock("Free Margin"), 8, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.FreeMargin)), 8, 1)
        grid.AddChild(self.getTextBlock("Margin"), 9, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.Margin)), 9, 1)
        grid.AddChild(self.getTextBlock("Margin Level"), 10, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.MarginLevel)), 10, 1)
        grid.AddChild(self.getTextBlock("Precise Leverage"), 11, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.PreciseLeverage)), 11, 1)
        grid.AddChild(self.getTextBlock("Stop Out Level"), 12, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.StopOutLevel)), 12, 1)
        grid.AddChild(self.getTextBlock("Unrealized Gross Profit"), 13, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.UnrealizedGrossProfit)), 13, 1)
        grid.AddChild(self.getTextBlock("Unrealized Net Profit"), 14, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.UnrealizedNetProfit)), 14, 1)
        grid.AddChild(self.getTextBlock("User Id"), 15, 0)
        grid.AddChild(self.getTextBlock(str(api.Account.UserId)), 15, 1)

        customFrame.Child = grid

    def getTextBlock(self, text):
        textBlock = TextBlock()
        textBlock.Text = text
        textBlock.Style = self.style
        return textBlock

    def on_add_chart_frame_button_click(self, args):
        chartFrame = api.ChartManager.AddChartFrame(api.Symbols[0], TimeFrame.Daily)
        chartFrame.LinkedChartGroup = LinkedChartGroup.A
        chartFrame.Activate()

    def on_remove_all_custom_frames_button_click(self, args):
        customFrames = [frame for frame in api.ChartManager if isinstance(frame.__implementation__, CustomFrame)]

        for customFrame in customFrames:
            api.ChartManager.RemoveFrame(customFrame.Id)

    def on_change_main_chart_container_mode_button_click(self, args):
        match api.ChartManager.ChartContainers.MainChartContainer.Mode:
            case ChartMode.Single:
                api.ChartManager.ChartContainers.MainChartContainer.Mode = ChartMode.Multi
            case ChartMode.Multi:
                api.ChartManager.ChartContainers.MainChartContainer.Mode = ChartMode.Free
            case _:
                api.ChartManager.ChartContainers.MainChartContainer.Mode = ChartMode.Single
{
  "AccessRights": "None"
}

Methods

Name Description
AddChartFrame 2 overloadsDesktopCLICloudChartFrame Adds a new chart frame to main chart container.
AddCustomFrame 2 overloadsDesktopCLICloudCustomFrame Adds a new custom frame to main chart container.
GetChartFrameDesktopCLICloudChartFrame Gets a chart frame by it is Id.
GetCustomFrameDesktopCLICloudCustomFrame Gets a custom frame by it is Id.
RemoveFrameDesktopCLICloudbool Removes a frame by it is Id.

Properties

Name Description
ActiveChartContainerDesktopCLICloudChartContainer Returns current active chart container if any otherwise null.
ActiveFrameDesktopCLICloudFrame Returns current active frame if any otherwise null.
ChartContainersDesktopCLICloudChartContainers Returns chart containers.
CountDesktopCLICloudint Returns number of all frames.

Events

Name Description
ActiveFrameChangedDesktopCLICloudAction<ActiveFrameChangedEventArgs> Occurs when active frame is changed.
FramesAddedDesktopCLICloudAction<FramesAddedEventArgs> Occurs when new frames are added.
FramesRemovedDesktopCLICloudAction<FramesRemovedEventArgs> Occurs when frames are removed.