forked from spotware/ctrader-algo-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spotware#21 from spotware/es/CNT-638
Add a plugin example from the video.
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
106 changes: 106 additions & 0 deletions
106
Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="cTrader.Automate" Version="*" /> | ||
</ItemGroup> | ||
</Project> |