Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a1f8d60

Browse files
Merge pull request #23 from spotware/CNT-674-Custom-Window-Plugin-Sample
es/CNT-674--Custom-Window-Plugin-Sample
2 parents d3699f9 + 0529e10 commit a1f8d60

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

‎Plugins/.samples.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
{
3333
"name": "Custom Frame Sample"
3434
},
35+
{
36+
"name": "Custom Window Plugin"
37+
},
3538
{
3639
"name": "IndicatorTitles Sample"
3740
},
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}") = "Custom Window Plugin", "Custom Window Plugin\Custom Window Plugin.csproj", "{65dfd7f6-65ba-4aed-bc96-051f978f3662}"
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+
{65dfd7f6-65ba-4aed-bc96-051f978f3662}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{65dfd7f6-65ba-4aed-bc96-051f978f3662}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{65dfd7f6-65ba-4aed-bc96-051f978f3662}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{65dfd7f6-65ba-4aed-bc96-051f978f3662}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 custom window containing a "Add Take Profit" button, which adds Take Profit to open positions when clicked.
8+
//
9+
// For a detailed tutorial on creating this plugin, watch the video at: [to:do]
10+
//
11+
// -------------------------------------------------------------------------------------------------
12+
13+
14+
using System;
15+
using cAlgo.API;
16+
using cAlgo.API.Collections;
17+
using cAlgo.API.Indicators;
18+
using cAlgo.API.Internals;
19+
20+
namespace cAlgo.Plugins
21+
{
22+
[Plugin(AccessRights = AccessRights.None)]
23+
public class CustomWindowPlugin : Plugin
24+
25+
{
26+
private Button _buttonAddTakeProfit;
27+
private Window _window;
28+
29+
protected override void OnStart()
30+
{
31+
_buttonAddTakeProfit = new Button
32+
{
33+
BackgroundColor = Color.SeaGreen,
34+
Height = 50,
35+
Text = "Add Take Profit"
36+
};
37+
38+
_buttonAddTakeProfit.Click += _buttonAddTakeProfit_Click;
39+
40+
_window = new Window
41+
{
42+
Height = 150,
43+
Width = 150,
44+
Padding = new Thickness(5, 10, 10, 5)
45+
};
46+
47+
_window.Child = _buttonAddTakeProfit;
48+
_window.Show();
49+
}
50+
51+
private void _buttonAddTakeProfit_Click(ButtonClickEventArgs args)
52+
{
53+
foreach (var position in Positions)
54+
{
55+
if (position.TakeProfit is null)
56+
{
57+
position.ModifyTakeProfitPips(20);
58+
}
59+
}
60+
}
61+
62+
protected override void OnStop()
63+
{
64+
// Handle Plugin stop here
65+
}
66+
}
67+
}
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)

AltStyle によって変換されたページ (->オリジナル) /