From 0995433c8052ad02f07a8a8981d0f1979d347087 Mon Sep 17 00:00:00 2001 From: evgenisedin Date: Thu, 13 Jun 2024 16:20:51 +0300 Subject: [PATCH] Add a plugin example from the video. --- Plugins/.samples.json | 3 + .../Previous Bar Info/Previous Bar Info.sln | 22 ++++ .../Previous Bar Info/Previous Bar Info.cs | 106 ++++++++++++++++++ .../Previous Bar Info.csproj | 9 ++ 4 files changed, 140 insertions(+) create mode 100644 Plugins/Previous Bar Info/Previous Bar Info.sln create mode 100644 Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.cs create mode 100644 Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.csproj diff --git a/Plugins/.samples.json b/Plugins/.samples.json index 4c047ec..5316ff8 100644 --- a/Plugins/.samples.json +++ b/Plugins/.samples.json @@ -47,6 +47,9 @@ { "name": "PositionCurrentPrice Sample" }, + { + "name": "Previous Bar Info" + }, { "name": "SmoothMouseMove Sample" }, diff --git a/Plugins/Previous Bar Info/Previous Bar Info.sln b/Plugins/Previous Bar Info/Previous Bar Info.sln new file mode 100644 index 0000000..86e5502 --- /dev/null +++ b/Plugins/Previous Bar Info/Previous Bar Info.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}") = "Previous Bar Info", "Previous Bar Info\Previous Bar Info.csproj", "{745f073c-3ae0-4138-a7ef-5f56c8c43c40}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.cs b/Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.cs new file mode 100644 index 0000000..52d7806 --- /dev/null +++ b/Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.cs @@ -0,0 +1,106 @@ +// ------------------------------------------------------------------------------------------------- +// +// 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 section to Trade Watch, featuring a two-by-two grid that displays information about the last known bar prices. +// +// For a detailed tutorial on creating this plugin, watch the video at: https://youtu.be/0HB-rdwpMAY +// +// ------------------------------------------------------------------------------------------------- + +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 PreviousBarInfo : Plugin + { + + Bars _bars; + Grid _grid; + TextBlock _lowBlock; + TextBlock _openBlock; + TextBlock _highBlock; + TextBlock _closeBlock; + + protected override void OnStart() + { + var tradeWatchTab = TradeWatch.AddTab("Previous Bar Info"); + tradeWatchTab.IsSelected = true; + + var webView = new WebView(); + tradeWatchTab.Child = webView; + + webView.NavigateAsync("https://ctrader.com/"); + + _grid = new Grid(2, 2) + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + ShowGridLines = true, + Height = 150, + Width = 150, + }; + + _bars = MarketData.GetBars(TimeFrame.Minute, "USDJPY"); + + _lowBlock = new TextBlock + { + Text = "Low:" + _bars.LowPrices.LastValue, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + }; + + _highBlock = new TextBlock + { + Text = "High:" + _bars.HighPrices.LastValue, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + }; + + _closeBlock = new TextBlock + { + Text = "Close:" +_bars.ClosePrices.LastValue, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + }; + + _openBlock = new TextBlock + { + Text = "Open:" + _bars.OpenPrices.LastValue, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + }; + + _grid.AddChild(_lowBlock, 0, 0); + _grid.AddChild(_highBlock, 0, 1); + _grid.AddChild(_openBlock, 1, 0); + _grid.AddChild(_closeBlock, 1, 1); + + tradeWatchTab.Child = _grid; + + _bars.Tick += _bars_Tick; + + + } + + private void _bars_Tick(BarsTickEventArgs obj) + { + _lowBlock.Text = "Low: " +_bars.LowPrices.LastValue.ToString(); + _highBlock.Text = "High: " +_bars.HighPrices.LastValue.ToString(); + _openBlock.Text = "Open: " +_bars.OpenPrices.LastValue.ToString(); + _closeBlock.Text = "Close: " +_bars.ClosePrices.LastValue.ToString(); + } + + protected override void OnStop() + { + // Handle Plugin stop here + } + } +} \ No newline at end of file diff --git a/Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.csproj b/Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.csproj new file mode 100644 index 0000000..51ac844 --- /dev/null +++ b/Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.csproj @@ -0,0 +1,9 @@ + + + net6.0 + + + + + +