Skip to content

Commit e11a175

Browse files
authored
Merge pull request spotware#21 from spotware/es/CNT-638
Add a plugin example from the video.
2 parents 7f794b8 + 0995433 commit e11a175

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

Plugins/.samples.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
{
4848
"name": "PositionCurrentPrice Sample"
4949
},
50+
{
51+
"name": "Previous Bar Info"
52+
},
5053
{
5154
"name": "SmoothMouseMove Sample"
5255
},
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Previous Bar Info", "Previous Bar Info\Previous Bar Info.csproj", "{745f073c-3ae0-4138-a7ef-5f56c8c43c40}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// -------------------------------------------------------------------------------------------------
2+
//
3+
// This code is a cTrader Algo API example.
4+
//
5+
// 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.
6+
//
7+
// 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.
8+
//
9+
// For a detailed tutorial on creating this plugin, watch the video at: https://youtu.be/0HB-rdwpMAY
10+
//
11+
// -------------------------------------------------------------------------------------------------
12+
13+
using System;
14+
using cAlgo.API;
15+
using cAlgo.API.Collections;
16+
using cAlgo.API.Indicators;
17+
using cAlgo.API.Internals;
18+
19+
namespace cAlgo.Plugins
20+
{
21+
[Plugin(AccessRights = AccessRights.None)]
22+
public class PreviousBarInfo : Plugin
23+
{
24+
25+
Bars _bars;
26+
Grid _grid;
27+
TextBlock _lowBlock;
28+
TextBlock _openBlock;
29+
TextBlock _highBlock;
30+
TextBlock _closeBlock;
31+
32+
protected override void OnStart()
33+
{
34+
var tradeWatchTab = TradeWatch.AddTab("Previous Bar Info");
35+
tradeWatchTab.IsSelected = true;
36+
37+
var webView = new WebView();
38+
tradeWatchTab.Child = webView;
39+
40+
webView.NavigateAsync("https://ctrader.com/");
41+
42+
_grid = new Grid(2, 2)
43+
{
44+
HorizontalAlignment = HorizontalAlignment.Center,
45+
VerticalAlignment = VerticalAlignment.Center,
46+
ShowGridLines = true,
47+
Height = 150,
48+
Width = 150,
49+
};
50+
51+
_bars = MarketData.GetBars(TimeFrame.Minute, "USDJPY");
52+
53+
_lowBlock = new TextBlock
54+
{
55+
Text = "Low:" + _bars.LowPrices.LastValue,
56+
HorizontalAlignment = HorizontalAlignment.Center,
57+
VerticalAlignment = VerticalAlignment.Center,
58+
};
59+
60+
_highBlock = new TextBlock
61+
{
62+
Text = "High:" + _bars.HighPrices.LastValue,
63+
HorizontalAlignment = HorizontalAlignment.Center,
64+
VerticalAlignment = VerticalAlignment.Center,
65+
};
66+
67+
_closeBlock = new TextBlock
68+
{
69+
Text = "Close:" +_bars.ClosePrices.LastValue,
70+
HorizontalAlignment = HorizontalAlignment.Center,
71+
VerticalAlignment = VerticalAlignment.Center,
72+
};
73+
74+
_openBlock = new TextBlock
75+
{
76+
Text = "Open:" + _bars.OpenPrices.LastValue,
77+
HorizontalAlignment = HorizontalAlignment.Center,
78+
VerticalAlignment = VerticalAlignment.Center,
79+
};
80+
81+
_grid.AddChild(_lowBlock, 0, 0);
82+
_grid.AddChild(_highBlock, 0, 1);
83+
_grid.AddChild(_openBlock, 1, 0);
84+
_grid.AddChild(_closeBlock, 1, 1);
85+
86+
tradeWatchTab.Child = _grid;
87+
88+
_bars.Tick += _bars_Tick;
89+
90+
91+
}
92+
93+
private void _bars_Tick(BarsTickEventArgs obj)
94+
{
95+
_lowBlock.Text = "Low: " +_bars.LowPrices.LastValue.ToString();
96+
_highBlock.Text = "High: " +_bars.HighPrices.LastValue.ToString();
97+
_openBlock.Text = "Open: " +_bars.OpenPrices.LastValue.ToString();
98+
_closeBlock.Text = "Close: " +_bars.ClosePrices.LastValue.ToString();
99+
}
100+
101+
protected override void OnStop()
102+
{
103+
// Handle Plugin stop here
104+
}
105+
}
106+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="cTrader.Automate" Version="*" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)