diff --git a/Plugins/.samples.json b/Plugins/.samples.json index 5316ff8..0be45ac 100644 --- a/Plugins/.samples.json +++ b/Plugins/.samples.json @@ -32,6 +32,9 @@ { "name": "Custom Frame Sample" }, + { + "name": "Custom Window Plugin" + }, { "name": "IndicatorTitles Sample" }, diff --git a/Plugins/Custom Window Plugin/Custom Window Plugin.sln b/Plugins/Custom Window Plugin/Custom Window Plugin.sln new file mode 100644 index 0000000..32dca25 --- /dev/null +++ b/Plugins/Custom Window Plugin/Custom Window Plugin.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 Window Plugin", "Custom Window Plugin\Custom Window Plugin.csproj", "{65dfd7f6-65ba-4aed-bc96-051f978f3662}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {65dfd7f6-65ba-4aed-bc96-051f978f3662}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65dfd7f6-65ba-4aed-bc96-051f978f3662}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65dfd7f6-65ba-4aed-bc96-051f978f3662}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65dfd7f6-65ba-4aed-bc96-051f978f3662}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Plugins/Custom Window Plugin/Custom Window Plugin/Custom Window Plugin.cs b/Plugins/Custom Window Plugin/Custom Window Plugin/Custom Window Plugin.cs new file mode 100644 index 0000000..61b7ff5 --- /dev/null +++ b/Plugins/Custom Window Plugin/Custom Window Plugin/Custom Window Plugin.cs @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------------------------------- +// +// 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 custom window containing a "Add Take Profit" button, which adds Take Profit to 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 CustomWindowPlugin : Plugin + + { + private Button _buttonAddTakeProfit; + private Window _window; + + protected override void OnStart() + { + _buttonAddTakeProfit = new Button + { + BackgroundColor = Color.SeaGreen, + Height = 50, + Text = "Add Take Profit" + }; + + _buttonAddTakeProfit.Click += _buttonAddTakeProfit_Click; + + _window = new Window + { + Height = 150, + Width = 150, + Padding = new Thickness(5, 10, 10, 5) + }; + + _window.Child = _buttonAddTakeProfit; + _window.Show(); + } + + private void _buttonAddTakeProfit_Click(ButtonClickEventArgs args) + { + foreach (var position in Positions) + { + if (position.TakeProfit is null) + { + position.ModifyTakeProfitPips(20); + } + } + } + + protected override void OnStop() + { + // Handle Plugin stop here + } + } +} \ No newline at end of file diff --git a/Plugins/Custom Window Plugin/Custom Window Plugin/Custom Window Plugin.csproj b/Plugins/Custom Window Plugin/Custom Window Plugin/Custom Window Plugin.csproj new file mode 100644 index 0000000..51ac844 --- /dev/null +++ b/Plugins/Custom Window Plugin/Custom Window Plugin/Custom Window Plugin.csproj @@ -0,0 +1,9 @@ + + + net6.0 + + + + + +