Skip to content

Update .cs files with new versions (+comments) #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 139 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
10fc9e5
Update Accelerator Oscillator Sample.cs
sergikos7 Mar 27, 2025
2f7e310
Update Accumulative Swing Index Sample.cs
sergikos7 Mar 27, 2025
e45547d
Update Add Indicator Sample.cs
sergikos7 Mar 27, 2025
759ea6f
Update AddToChart Sample.cs
sergikos7 Mar 27, 2025
4cc97a7
Update AlgoRegistry Sample.cs
sergikos7 Mar 27, 2025
55ac7c5
Update Alligator Sample.cs
sergikos7 Mar 27, 2025
4f2baed
Update Aroon Sample.cs
sergikos7 Mar 27, 2025
ebe4c4c
Update Average Directional Movement Index Rating Sample.cs
sergikos7 Mar 27, 2025
20d9827
Update Average True Range Sample.cs
sergikos7 Mar 27, 2025
8fdcf10
Update Awesome Oscillator Sample.cs
sergikos7 Mar 27, 2025
0776709
Update BarClosed Example.cs
sergikos7 Mar 27, 2025
01106e1
Update BarOpened Example.cs
sergikos7 Mar 27, 2025
ce747d3
Update BarsHistoryLoadedEventArgs Sample.cs
sergikos7 Mar 27, 2025
11e67ae
Update Bollinger Bands Sample.cs
sergikos7 Mar 27, 2025
ac81be5
Update Center Of Gravity Sample.cs
sergikos7 Mar 27, 2025
55b4eec
Update Chaikin Money Flow Sample.cs
sergikos7 Mar 27, 2025
e9a51ad
Update Chaikin Volatility Sample.cs
sergikos7 Mar 27, 2025
f8108bf
Update ChartId Sample.cs
sergikos7 Mar 27, 2025
f9f286d
Update ChartIndicators Sample.cs
sergikos7 Mar 27, 2025
6539701
Update Close All On Market Close Sample.cs
sergikos7 Mar 27, 2025
a7c8fa8
Update Commodity Channel Index Sample.cs
sergikos7 Mar 27, 2025
fe3d4b3
Update Compilation Robot.cs
sergikos7 Mar 27, 2025
ecd4d84
Update Custom Fitness Functions.cs
sergikos7 Mar 27, 2025
5eb4523
Update CustomHandlers Example.cs
sergikos7 Mar 27, 2025
3804430
Update Cyber Cycle Sample.cs
sergikos7 Mar 27, 2025
630f104
Update Detrended Price Oscillator Sample.cs
sergikos7 Mar 27, 2025
692b22d
Update Directional Movement System Sample.cs
sergikos7 Mar 27, 2025
3381e4d
Update Discord Message Example.cs
sergikos7 Mar 27, 2025
7c07133
Update Donchian Channel Sample.cs
sergikos7 Mar 27, 2025
7a4d8e6
Update Ease Of Movement Sample.cs
sergikos7 Mar 27, 2025
42cf5c3
Update Error Sample.cs
sergikos7 Mar 27, 2025
09031da
Update Exponential Moving Average Sample.cs
sergikos7 Mar 27, 2025
aefe6b1
Update Fractal Chaos Bands Sample.cs
sergikos7 Mar 27, 2025
998b73f
Update Fractals Sample.cs
sergikos7 Mar 27, 2025
5138b5a
Update GetFitnessArgs Sample.cs
sergikos7 Mar 27, 2025
4d3734e
Update Grid.cs
sergikos7 Mar 27, 2025
0a00506
Update High Minus Low Sample.cs
sergikos7 Mar 27, 2025
02e1804
Update Historical Volatility Sample.cs
sergikos7 Mar 27, 2025
34a74bb
Update Hull Moving Average Sample.cs
sergikos7 Mar 27, 2025
9a4b87b
Update Ichimoku Kinko Hyo Sample.cs
sergikos7 Mar 27, 2025
29adef8
Update IndicatorTitles Sample.cs
sergikos7 Mar 27, 2025
bf64ca2
Update Keltner Channels Sample.cs
sergikos7 Mar 27, 2025
0d5a8f9
Update Linear Regression Forecast Sample.cs
sergikos7 Mar 27, 2025
04611cf
Update Linear Regression Intercept Sample.cs
sergikos7 Mar 27, 2025
4b9ca04
Update Linear Regression R Squared Sample.cs
sergikos7 Mar 27, 2025
b7d897b
Update Linear Regression Slope Sample.cs
sergikos7 Mar 27, 2025
e816c08
Update Macd Cross Over Sample.cs
sergikos7 Mar 27, 2025
6e48f9a
Update Macd Histogram Sample.cs
sergikos7 Mar 27, 2025
cc02832
Update Mass Index Sample.cs
sergikos7 Mar 27, 2025
3fc1a99
Update Median Price Sample.cs
sergikos7 Mar 27, 2025
35c301e
Update Momentum Oscillator Sample.cs
sergikos7 Mar 27, 2025
5f4f559
Update Money Flow Index Sample.cs
sergikos7 Mar 27, 2025
8e2ef7f
Update Moving Average Sample.cs
sergikos7 Mar 27, 2025
b2ae6dd
Update On Balance Volume Sample.cs
sergikos7 Mar 27, 2025
5a3497c
Update Parabolic SAR Sample.cs
sergikos7 Mar 27, 2025
5a988f5
Update Partial Close Sample.cs
sergikos7 Mar 27, 2025
2d3e769
Update Patterns Strategy Sample.cs
sergikos7 Mar 27, 2025
5165a0f
Update Pending Order Cancelation Sample.cs
sergikos7 Mar 27, 2025
c7159e0
Update Pending Order Events.cs
sergikos7 Mar 27, 2025
46eeb4e
Update Pending Order Modification Sample.cs
sergikos7 Mar 27, 2025
ab00172
Update Pending Order Placing Sample.cs
sergikos7 Mar 27, 2025
06c2c14
Update PendingOrderCancellationReason Sample.cs
sergikos7 Mar 27, 2025
c5749a4
Update PendingOrders Sample.cs
sergikos7 Mar 27, 2025
b9fd3be
Update Polynomial Regression Channels Sample.cs
sergikos7 Mar 27, 2025
1eb60d7
Update Position Bars Passed Sample.cs
sergikos7 Mar 27, 2025
a5ee0d1
Update Position Closing Sample.cs
sergikos7 Mar 27, 2025
68002d6
Update Position Events Sample.cs
sergikos7 Mar 27, 2025
dcd7961
Update Position Execution Sample.cs
sergikos7 Mar 27, 2025
a5d8905
Update Position Modification Sample.cs
sergikos7 Mar 27, 2025
ba42f94
Update PositionCloseReason Sample.cs
sergikos7 Mar 27, 2025
07a5a0c
Update PositionCurrentPrice Sample.cs
sergikos7 Mar 27, 2025
36c7ef1
Update PositionModifiedEventArgs Sample.cs
sergikos7 Mar 27, 2025
748852f
Update Price Oscillator Sample.cs
sergikos7 Mar 27, 2025
8a580a3
Update Price ROC Sample.cs
sergikos7 Mar 27, 2025
746d5ba
Update Price Volume Trend Sample.cs
sergikos7 Mar 27, 2025
d1d1b4d
Update RSI Reversal Strategy Sample.cs
sergikos7 Mar 27, 2025
8704dbb
Update Rainbow Oscillator Sample.cs
sergikos7 Mar 27, 2025
6d17ee0
Update Range Strategy Example.cs
sergikos7 Mar 27, 2025
eb9bc13
Update RefreshData Sample.cs
sergikos7 Mar 27, 2025
1715321
Update Relative Strength Index Sample.cs
sergikos7 Mar 27, 2025
4526350
Update Simple Moving Average Sample.cs
sergikos7 Mar 27, 2025
1cf84ca
Update Standard Deviation Sample.cs
sergikos7 Mar 27, 2025
a2c3266
Update Start cBot Sample.cs
sergikos7 Mar 27, 2025
bb071dd
Update Stochastic Oscillator Sample.cs
sergikos7 Mar 27, 2025
0477173
Update StopTriggerMethod Sample.cs
sergikos7 Mar 27, 2025
f7a46d3
Update Supertrend Sample.cs
sergikos7 Mar 27, 2025
aba9611
Update Swing Index Sample.cs
sergikos7 Mar 27, 2025
28532b6
Update Time Series Moving Average Sample.cs
sergikos7 Mar 27, 2025
249eead
Update Timer Sample.cs
sergikos7 Mar 27, 2025
7897e00
Update Trade Volume Index Sample.cs
sergikos7 Mar 27, 2025
954382a
Update TradeOperation Sample.cs
sergikos7 Mar 27, 2025
363c10e
Update TradeResult Sample.cs
sergikos7 Mar 27, 2025
4622fe4
Update TradeType Sample.cs
sergikos7 Mar 27, 2025
ae8cab4
Update Triangular Moving Average Sample.cs
sergikos7 Mar 27, 2025
75ed089
Update Trix Sample.cs
sergikos7 Mar 27, 2025
864810e
Update True Range Sample.cs
sergikos7 Mar 27, 2025
3d10ee1
Update Typical Price Sample.cs
sergikos7 Mar 27, 2025
a952ae3
Update Ultimate Oscillator Sample.cs
sergikos7 Mar 27, 2025
6044d41
Update Vertical Horizontal Filter Sample.cs
sergikos7 Mar 27, 2025
e4d134b
Update Vidya Sample.cs
sergikos7 Mar 27, 2025
e352e02
Update Volume Index Sample.cs
sergikos7 Mar 27, 2025
ad35800
Update Volume Oscillator Sample.cs
sergikos7 Mar 27, 2025
5198eeb
Update Volume ROC Sample.cs
sergikos7 Mar 27, 2025
679e9a4
Update Web Sockets Sample.cs
sergikos7 Mar 27, 2025
3ca4433
Update Weighted Close Sample.cs
sergikos7 Mar 27, 2025
b156e67
Update Weighted Moving Average Sample.cs
sergikos7 Mar 27, 2025
4d8c583
Update Welles Wilder Smoothing Sample.cs
sergikos7 Mar 27, 2025
a5df645
Update Williams Accumulation Distribution Sample.cs
sergikos7 Mar 27, 2025
5fd35c0
Update WilliamsPctR Sample.cs
sergikos7 Mar 27, 2025
aeaf06b
Update ASP Section Example.cs
sergikos7 Mar 27, 2025
14da2bf
Update ActiveFrameChanged Sample.cs
sergikos7 Mar 27, 2025
74865b2
Update AlgoStatsControl.cs
sergikos7 Mar 27, 2025
b4d2bc9
Update AlgoStatsControl.cs
sergikos7 Mar 27, 2025
820dca8
Update AlgoRegistry Sample.cs
sergikos7 Mar 27, 2025
d708738
Update AlgoStatsControl.cs
sergikos7 Mar 27, 2025
089181e
Update All placements.cs
sergikos7 Mar 27, 2025
9af3808
Update BacktestingInPlugins Sample.cs
sergikos7 Mar 27, 2025
58fefa5
Update ChartId Sample.cs
sergikos7 Mar 27, 2025
fbc322e
Update ChartIndicators Sample.cs
sergikos7 Mar 27, 2025
d010b5e
Update ChartIndicatorsControl.cs
sergikos7 Mar 27, 2025
1035669
Update ChartRobots Sample.cs
sergikos7 Mar 27, 2025
2f58bc8
Update ChartRobotsControl.cs
sergikos7 Mar 27, 2025
3c41a9b
Update Commands Sample.cs
sergikos7 Mar 27, 2025
5d0ff51
Update CoordinatesConversion Sample.cs
sergikos7 Mar 27, 2025
d187c9c
Update Custom Frame Sample.cs
sergikos7 Mar 27, 2025
ae98d9c
Update Custom Toolbar Button.cs
sergikos7 Mar 27, 2025
ea1ae9e
Update Custom Window Plugin.cs
sergikos7 Mar 27, 2025
c7b0336
Update IndicatorTitles Sample.cs
sergikos7 Mar 27, 2025
f761218
Update Interactive WebView.cs
sergikos7 Mar 27, 2025
d43a698
Update My ASP Example.cs
sergikos7 Mar 27, 2025
96f2fe5
Update My Custom Frame Example.cs
sergikos7 Mar 27, 2025
7bcea03
Update Order by Margin.cs
sergikos7 Mar 27, 2025
ddb769e
Update PositionCurrentPrice Sample.cs
sergikos7 Mar 27, 2025
8fed6fc
Update Previous Bar Info.cs
sergikos7 Mar 27, 2025
3f47409
Update SmoothMouseMove Sample.cs
sergikos7 Mar 27, 2025
af615ee
Update SymbolStatsControl.cs
sergikos7 Mar 27, 2025
1615685
Update TradeControl.cs
sergikos7 Mar 27, 2025
90ce929
Update TradeWatch Tab Sample.cs
sergikos7 Mar 27, 2025
a0417c7
Update WebSocket Sample.cs
sergikos7 Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@
// This code is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// The sample demonstrates how to create and configure a custom block in Active Symbol Panel (ASP)
// using the cTrader Algo API.
//
// -------------------------------------------------------------------------------------------------

using cAlgo.API;

namespace cAlgo.Plugins
{
// Declare the class as a plugin without requiring special access permissions.
[Plugin(AccessRights = AccessRights.None)]
public class ASPSectionExample : Plugin
{
// This method is triggered when the plugin starts.
protected override void OnStart()
{
var block = Asp.SymbolTab.AddBlock("My title");
block.Index = 2;
block.Height = 500;
block.IsExpanded = true;
var block = Asp.SymbolTab.AddBlock("My title"); // Add a custom block to the ASP under the Symbol tab.

block.Index = 2; // Set the position index of the block in the panel.
block.Height = 500; // Define the height of the block in pixels.
block.IsExpanded = true; // Make the block expanded by default.

var webView = new WebView();
block.Child = webView;
var webView = new WebView(); // Create a WebView control to display a webpage.
block.Child = webView; // Adding the WebView as a child element to the block.

webView.NavigateAsync("https://ctrader.com/");
webView.NavigateAsync("https://ctrader.com/"); // Navigate the WebView to the cTrader website.
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
// This code is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// This sample adds a new block into the ASP. The block displays the percentage difference between
// the current price of a symbol its price a month ago; the symbol is taken from the currently active
// chart frame. This is achieved by handling the ChartManager.ActiveFrameChanged event.
// The sample adds a new block into Active Symbol Panel (ASP). The block displays the percentage
// difference between the current price of a symbol its price a month ago; the symbol is taken from
// the currently active chart frame. This is achieved by handling the ChartManager.ActiveFrameChanged
// event.
//
// -------------------------------------------------------------------------------------------------

Expand All @@ -19,19 +20,19 @@

namespace cAlgo.Plugins
{
// Declare the class as a plugin without requiring special access permissions.
[Plugin(AccessRights = AccessRights.None)]
public class ActiveFrameChangedSample : Plugin
{

// Declaring the necessary UI elements
// Declare the necessary UI elements.
private Grid _grid;
private TextBlock _percentageTextBlock;
private Frame _activeFrame;

// This method is triggered when the plugin starts.
protected override void OnStart()
{
// Initialising the grid and the TextBlock
// displaying the percentage difference
// Initialise the grid and the TextBlock displaying the percentage difference.
_grid = new Grid(1, 1);
_percentageTextBlock = new TextBlock
{
Expand All @@ -40,38 +41,36 @@ protected override void OnStart()
Text = "Monthly change: ",
};

_grid.AddChild(_percentageTextBlock, 0, 0);
_grid.AddChild(_percentageTextBlock, 0, 0); // Add the TextBlock to the grid at row 0, column 0.

// Initialising a new block inside the ASP
// and adding the grid as a child
// Initialise a new block inside the ASP tab and add the grid as a child.
var block = Asp.SymbolTab.AddBlock("Monthly Change Plugin");

block.Child = _grid;

// Attaching a custom handler to the
// ActiveFrameChanged event
// Attach a custom handler to the ActiveFrameChanged event.
ChartManager.ActiveFrameChanged += ChartManager_ActiveFrameChanged;

}

// This method is triggered whenever the active frame changes in the chart manager.
private void ChartManager_ActiveFrameChanged(ActiveFrameChangedEventArgs obj)
{
// Check if the new frame is a ChartFrame.
if (obj.NewFrame is ChartFrame)
{
// Casting the Frame into a ChartFrame
// Cast the Frame into a ChartFrame.
var newChartFrame = obj.NewFrame as ChartFrame;

// Attaining market data for the symbol for which
// the currently active ChartFrame is opened
// Attain market data for the symbol for which the currently active ChartFrame is opened.
var dailySeries = MarketData.GetBars(TimeFrame.Daily, newChartFrame.Symbol.Name);

// Calculating the monthly change and displaying it
// inside the TextBlock
// Calculate the monthly change and display it inside the TextBlock.
double monthlyChange = (newChartFrame.Symbol.Bid - dailySeries.ClosePrices[dailySeries.ClosePrices.Count - 30]) / 100;
_percentageTextBlock.Text = $"Monthly change: {monthlyChange}";
_percentageTextBlock.Text = $"Monthly change: {monthlyChange}"; // Update the TextBlock with the calculated change.
}
}


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
// This code is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// This sample adds a trade watch tab, and uses AlgoRegistry API to show stats about installed algo types.
// The sample adds a trade watch tab and uses Algo Registry API to show stats about installed algo types.
//
// -------------------------------------------------------------------------------------------------

using cAlgo.API;

namespace cAlgo.Plugins
{
// Declare the class as a plugin without requiring special access permissions.
[Plugin(AccessRights = AccessRights.None)]
public class AlgoRegistrySample : Plugin
{
// This method is triggered when the plugin starts.
protected override void OnStart()
{
var tradeWatchTab = TradeWatch.AddTab("Algo Registry");
var tradeWatchTab = TradeWatch.AddTab("Algo Registry"); // Add a new tab to the Trade Watch section, named "Algo Registry".

var panel = new StackPanel
var panel = new StackPanel // Initialise a StackPanel to hold UI elements.
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
Orientation = Orientation.Horizontal, // Set the panel orientation to horizontal.
HorizontalAlignment = HorizontalAlignment.Center, // Centre the panel within its parent container horizontally.
};

panel.AddChild(new AlgoStatsControl(AlgoRegistry) {Margin = 10, VerticalAlignment = VerticalAlignment.Top});
panel.AddChild(new AlgoTypeInfoControl(AlgoRegistry) {Margin = 10, VerticalAlignment = VerticalAlignment.Top});
panel.AddChild(new AlgoStatsControl(AlgoRegistry) {Margin = 10, VerticalAlignment = VerticalAlignment.Top}); // Add the AlgoStatsControl to the panel with a margin and top vertical alignment.
panel.AddChild(new AlgoTypeInfoControl(AlgoRegistry) {Margin = 10, VerticalAlignment = VerticalAlignment.Top}); // Add the AlgoTypeInfoControl to the panel with a margin and top vertical alignment.

tradeWatchTab.Child = panel;
tradeWatchTab.Child = panel; // Set the StackPanel containing the controls as the content of the "Algo Registry" tab in the Trade Watch section.
}
}
}
}
98 changes: 54 additions & 44 deletions Plugins/AlgoRegistry Sample/AlgoRegistry Sample/AlgoStatsControl.cs
Original file line number Diff line number Diff line change
@@ -1,84 +1,94 @@
using System.Linq;
// -------------------------------------------------------------------------------------------------
//
// This code is a cTrader Algo API example.
//
// This code is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// The sample creates a custom control that displays statistics about registered algorithms in the
// platform. It shows counts for total algos, custom indicators, standard indicators, cBots and
// plugins. The statistics dynamically update when algo types are installed or deleted.
//
// -------------------------------------------------------------------------------------------------


using System.Linq;
using cAlgo.API;

namespace cAlgo.Plugins;

public class AlgoStatsControl: CustomControl
{
private const string FontFamily = "Calibri";
private const string FontFamily = "Calibri"; // Define a constant for the font family used in the UI.
private readonly AlgoRegistry _algoRegistry; // Hold a reference to the Algo Registry for accessing algorithm data.

private readonly AlgoRegistry _algoRegistry;
private readonly TextBlock _algosCountTextBlock;
private readonly TextBlock _customIndicatorsCountTextBlock;
private readonly TextBlock _standardIndicatorsCountTextBlock;
private readonly TextBlock _botsCountTextBlock;
private readonly TextBlock _pluginsCountTextBlock;
private readonly TextBlock _algosCountTextBlock; // TextBlock to display the total number of algorithms.
private readonly TextBlock _customIndicatorsCountTextBlock; // Number of custom indicators.
private readonly TextBlock _standardIndicatorsCountTextBlock; // Number of standard indicators.
private readonly TextBlock _botsCountTextBlock; // Number of cBots.
private readonly TextBlock _pluginsCountTextBlock; // Number of plugins.

// This method initialises the control that displays stats for installed algorithms, including cBots, custom indicators and plugins.
public AlgoStatsControl(AlgoRegistry algoRegistry)
{
_algoRegistry = algoRegistry;

var panel = new Grid(6, 2);

var titleTextBlock = GetTextBlock("Algo Stats");

titleTextBlock.HorizontalAlignment = HorizontalAlignment.Center;

panel.AddChild(titleTextBlock, 0, 0, 1, 2);
_algoRegistry = algoRegistry; // Assign the provided Algo Registry instance to the private field.

panel.AddChild(GetTextBlock("Algos #"), 1, 0);

_algosCountTextBlock = GetTextBlock();
var panel = new Grid(6, 2); // Create a grid with 6 rows and 2 columns for organising UI elements.
var titleTextBlock = GetTextBlock("Algo Stats"); // Create a title TextBlock with the text "Algo Stats".
titleTextBlock.HorizontalAlignment = HorizontalAlignment.Center; // Centre the title horizontally.
panel.AddChild(titleTextBlock, 0, 0, 1, 2); // Add the title to the first row, spanning both columns.

panel.AddChild(_algosCountTextBlock, 1, 1);
// Add a label and its corresponding TextBlock for "Algos #" to the grid.
panel.AddChild(GetTextBlock("Algos #"), 1, 0); // Add a label and its corresponding TextBlock for "Algos #" to the grid.
_algosCountTextBlock = GetTextBlock(); // Create a TextBlock to display the total algorithm count.
panel.AddChild(_algosCountTextBlock, 1, 1); // Add the TextBlock to the grid.

// Add a label and TextBlock for "Standard Indicators #".
panel.AddChild(GetTextBlock("Standard Indicators #"), 2, 0);

_standardIndicatorsCountTextBlock = GetTextBlock();

panel.AddChild(_standardIndicatorsCountTextBlock, 2, 1);

// Add a label and TextBlock for "Custom Indicators #".
panel.AddChild(GetTextBlock("Custom Indicators #"), 3, 0);

_customIndicatorsCountTextBlock = GetTextBlock();

panel.AddChild(_customIndicatorsCountTextBlock, 3, 1);

// Add a label and TextBlock for "cBots #".
panel.AddChild(GetTextBlock("cBots #"), 4, 0);

_botsCountTextBlock = GetTextBlock();

panel.AddChild(_botsCountTextBlock, 4, 1);

// Add a label and TextBlock for "Plugins #".
panel.AddChild(GetTextBlock("Plugins #"), 5, 0);

_pluginsCountTextBlock = GetTextBlock();

panel.AddChild(_pluginsCountTextBlock, 5, 1);

AddChild(panel);
AddChild(panel); // Add the grid containing all UI elements to the control.

Populate();
Populate(); // Populate the TextBlocks with the initial statistics.

_algoRegistry.AlgoTypeInstalled += _ => Populate();
_algoRegistry.AlgoTypeDeleted += _ => Populate();
// Subscribe to events to update statistics when an algorithm type is installed or deleted.
_algoRegistry.AlgoTypeInstalled += _ => Populate(); // Call Populate() on algorithm installation.
_algoRegistry.AlgoTypeDeleted += _ => Populate(); // Call Populate() on algorithm deletion.
}

// This method updates the statistics displayed in the TextBlocks.
private void Populate()
{
_algosCountTextBlock.Text = _algoRegistry.Count.ToString();
_botsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.Robot).ToString();
_customIndicatorsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.CustomIndicator).ToString();
_standardIndicatorsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.StandardIndicator).ToString();
_pluginsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.Plugin).ToString();
_algosCountTextBlock.Text = _algoRegistry.Count.ToString(); // Set the total algorithm count.
_botsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.Robot).ToString(); // Count cBots.
_customIndicatorsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.CustomIndicator).ToString(); // Count custom indicators.
_standardIndicatorsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.StandardIndicator).ToString(); // Count standard indicators.
_pluginsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.Plugin).ToString(); // Count plugins.
}

// This method creates and returns a new TextBlock with optional text.
private TextBlock GetTextBlock(string text = null) => new()
{
Margin = 3,
FontSize = 20,
FontWeight = FontWeight.Bold,
FontFamily = FontFamily,
Text = text
Margin = 3, // Set a margin around the TextBlock for spacing.
FontSize = 20, // Set the font size to 20.
FontWeight = FontWeight.Bold, // Set the font weight to bold.
FontFamily = FontFamily, // Use the defined font family.
Text = text // Set the text content, if provided.
};
}
}
Loading