From e389a74f1a209777d6efb61c9578cfb6dcce7786 Mon Sep 17 00:00:00 2001 From: Emmanuel Seriki Date: Wed, 19 Jun 2024 12:54:50 +0300 Subject: [PATCH 1/2] CNT-677--Custom-Toolbar-Button-Sample --- Plugins/.samples.json | 3 + .../Custom Toolbar Button.sln | 22 ++++++ .../Custom Toolbar Button.cs | 75 +++++++++++++++++++ .../Custom Toolbar Button.csproj | 9 +++ 4 files changed, 109 insertions(+) create mode 100644 Plugins/Custom Toolbar Button/Custom Toolbar Button.sln create mode 100644 Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs create mode 100644 Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.csproj diff --git a/Plugins/.samples.json b/Plugins/.samples.json index 5316ff8..9d775d5 100644 --- a/Plugins/.samples.json +++ b/Plugins/.samples.json @@ -32,6 +32,9 @@ { "name": "Custom Frame Sample" }, + { + "name": "Custom Toolbar Button" + }, { "name": "IndicatorTitles Sample" }, diff --git a/Plugins/Custom Toolbar Button/Custom Toolbar Button.sln b/Plugins/Custom Toolbar Button/Custom Toolbar Button.sln new file mode 100644 index 0000000..3cfd9ad --- /dev/null +++ b/Plugins/Custom Toolbar Button/Custom Toolbar Button.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Custom Toolbar Button", "Custom Toolbar Button\Custom Toolbar Button.csproj", "{57aed799-0d95-49c7-ae8d-a8765b3052d6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {57aed799-0d95-49c7-ae8d-a8765b3052d6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57aed799-0d95-49c7-ae8d-a8765b3052d6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57aed799-0d95-49c7-ae8d-a8765b3052d6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57aed799-0d95-49c7-ae8d-a8765b3052d6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs b/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs new file mode 100644 index 0000000..160a629 --- /dev/null +++ b/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs @@ -0,0 +1,75 @@ +// ------------------------------------------------------------------------------------------------- +// +// This code is a cTrader Algo API example. +// +// The code is provided as a sample only and does not guarantee any particular outcome or profit of any kind. Use it at your own risk. +// +// This example plugin adds a new button with a pop-up menu to the Chart Toolbar, featuring a "Close All Positions" button that closes open positions when clicked. +// +// For a detailed tutorial on creating this plugin, watch the video at: [to:do] +// +// ------------------------------------------------------------------------------------------------- + +using System; +using cAlgo.API; +using cAlgo.API.Collections; +using cAlgo.API.Indicators; +using cAlgo.API.Internals; + +namespace cAlgo.Plugins +{ + [Plugin(AccessRights = AccessRights.None)] + public class CustomToolbarButton : Plugin + { + protected override void OnStart() + { + var icon = new SvgIcon(@""); + + var command = Commands.Add(CommandType.ChartContainerToolbar, OpenPositions, icon); + command.ToolTip = "Open Positions"; + + Commands.Add(CommandType.ChartContainerToolbar, CloseAllPositions, icon); + } + + private CommandResult CloseAllPositions (CommandArgs args) + { + var buttonStyle = new Style(); + + buttonStyle.Set(ControlProperty.Margin, new Thickness(0, 5, 0, 0)); + buttonStyle.Set(ControlProperty.Width, 150); + + var closePositionsButton = new Button + { + Text = "Close All Positions", + Style = buttonStyle + }; + + closePositionsButton.Click += args => + { + foreach (var position in Positions) + { + position.Close(); + } + }; + + var stackPanel = new StackPanel(); + stackPanel.AddChild(closePositionsButton); + + return new CommandResult(stackPanel); + } + + private void OpenPositions(CommandArgs args) + { + ExecuteMarketOrder(TradeType.Buy, "EURUSD", 1000); + ExecuteMarketOrder(TradeType.Buy, "USDJPY", 1000); + ExecuteMarketOrder(TradeType.Buy, "EURGBP", 1000); + } + + protected override void OnStop() + { + // Handle Plugin stop here + } + } +} \ No newline at end of file diff --git a/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.csproj b/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.csproj new file mode 100644 index 0000000..51ac844 --- /dev/null +++ b/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.csproj @@ -0,0 +1,9 @@ + + + net6.0 + + + + + + From 82d81de59796c8eb94fec92c70567fc72f797b13 Mon Sep 17 00:00:00 2001 From: Emmanuel Seriki Date: Wed, 19 Jun 2024 16:42:01 +0300 Subject: [PATCH 2/2] Fix quotation --- .../Custom Toolbar Button/Custom Toolbar Button.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs b/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs index 160a629..10e3116 100644 --- a/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs +++ b/Plugins/Custom Toolbar Button/Custom Toolbar Button/Custom Toolbar Button.cs @@ -4,7 +4,7 @@ // // The code is provided as a sample only and does not guarantee any particular outcome or profit of any kind. Use it at your own risk. // -// This example plugin adds a new button with a pop-up menu to the Chart Toolbar, featuring a "Close All Positions" button that closes open positions when clicked. +// This example plugin adds a new button with a pop-up menu to the Chart Toolbar, featuring a 'Close All Positions' button that closes open positions when clicked. // // For a detailed tutorial on creating this plugin, watch the video at: [to:do] //