Skip to content

ChartManager

Summary

Represents the list of all the chart frames.

Signature

1
public abstract interface ChartManager

Namespace

cAlgo.API

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 using cAlgo.API;
 namespace cAlgo.Plugins;
 [Plugin(AccessRights = AccessRights.None)]
 public class Test : Plugin
 {
     protected override void OnStart()
     {
         var customFrame = ChartManager.AddCustomFrame("Test");
         var webview = new WebView();
         webview.NavigateAsync("https://ctrader.com/");
         customFrame.Child = webview;
     }
 }
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
 using cAlgo.API;
 using System.Linq;
 using System;
 namespace cAlgo.Plugins;
 [Plugin(AccessRights = AccessRights.None)]
 public 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}");
     }
 }
1
2
3
4
5
6
7
8
9
 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
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
 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

Methods

GetChartFrame

Summary

Gets a chart frame by it is Id.

Signature

1
public abstract ChartFrame GetChartFrame(string frameId)

Parameters

Name Type Description
frameId string Frame Id

Return Value

ChartFrame

GetCustomFrame

Summary

Gets a custom frame by it is Id.

Signature

1
public abstract CustomFrame GetCustomFrame(string frameId)

Parameters

Name Type Description
frameId string Frame Id

Return Value

CustomFrame

RemoveFrame

Summary

Removes a frame by it is Id.

Signature

1
public abstract bool RemoveFrame(string frameId)

Parameters

Name Type Description
frameId string Frame Id

Return Value

bool

AddChartFrame (2)

AddChartFrame (1 of 2)

Summary

Adds a new chart frame to main chart container.

Signature

1
public abstract ChartFrame AddChartFrame(string symbolName, TimeFrame timeFrame)

Parameters

Name Type Description
symbolName string Symbol name
timeFrame TimeFrame Timeframe

Return Value

ChartFrame

AddChartFrame (2 of 2)

Summary

Adds a new chart frame to target chart container.

Signature

1
public abstract ChartFrame AddChartFrame(string symbolName, TimeFrame timeFrame, ChartContainer targetChartContainer)

Parameters

Name Type Description
symbolName string Symbol name
timeFrame TimeFrame Timeframe
targetChartContainer ChartContainer Target chart container

Return Value

ChartFrame

AddCustomFrame (2)

AddCustomFrame (1 of 2)

Summary

Adds a new custom frame to main chart container.

Signature

1
public abstract CustomFrame AddCustomFrame(string title)

Parameters

Name Type Description
title string Custom frame title.

Return Value

CustomFrame

AddCustomFrame (2 of 2)

Summary

Adds a new custom frame to target chart container.

Signature

1
public abstract CustomFrame AddCustomFrame(string title, ChartContainer targetChartContainer)

Parameters

Name Type Description
title string Custom frame title.
targetChartContainer ChartContainer Target chart container

Return Value

CustomFrame

Properties

Count

Summary

Returns number of all frames.

Signature

1
public abstract int Count {get;}

Return Value

int

ChartContainers

Summary

Returns chart containers.

Signature

1
public abstract ChartContainers ChartContainers {get;}

Return Value

ChartContainers

ActiveFrame

Summary

Returns current active frame if any otherwise null.

Signature

1
public abstract Frame ActiveFrame {get;}

Return Value

Frame

ActiveChartContainer

Summary

Returns current active chart container if any otherwise null.

Signature

1
public abstract ChartContainer ActiveChartContainer {get;}

Return Value

ChartContainer

Events

FramesAdded

Summary

Occurs when new frames are added.

Signature

1
public abstract event Action<FramesAddedEventArgs> FramesAdded;

FramesRemoved

Summary

Occurs when frames are removed.

Signature

1
public abstract event Action<FramesRemovedEventArgs> FramesRemoved;

ActiveFrameChanged

Summary

Occurs when active frame is changed.

Signature

1
public abstract event Action<ActiveFrameChangedEventArgs> ActiveFrameChanged;