Skip to content

Commit 322891b

Browse files
authored
Merge pull request spotware#11 from spotware/sk/CNT-594-add-samples
CNMT-594 adding samples
2 parents 3eaa6f3 + 63ded1c commit 322891b

File tree

85 files changed

+2924
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2924
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.user
1010
*.userosscache
1111
*.sln.docstates
12+
.vscode
1213

1314
# User-specific files (MonoDevelop/Xamarin Studio)
1415
*.userprefs
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}") = "AlgoRegistry Sample", "AlgoRegistry Sample\AlgoRegistry Sample.csproj", "{8bac843f-c24b-4159-98d3-85a79295c2a2}"
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+
{8bac843f-c24b-4159-98d3-85a79295c2a2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8bac843f-c24b-4159-98d3-85a79295c2a2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8bac843f-c24b-4159-98d3-85a79295c2a2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8bac843f-c24b-4159-98d3-85a79295c2a2}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// -------------------------------------------------------------------------------------------------
2+
//
3+
// This code is a cTrader Algo API example.
4+
//
5+
// This code is intended to be used as a sample and does not guarantee any particular outcome or
6+
// profit of any kind. Use it at your own risk.
7+
//
8+
// This sample uses AlgoRegistry to determine whether the user has installed two custom fictional
9+
// indicators, namely Rapid SMA and Swirling SMA. If the indicators are not installed, the indicator
10+
// displays a message box alerting the user to this fact.
11+
//
12+
// -------------------------------------------------------------------------------------------------
13+
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using cAlgo.API;
20+
using cAlgo.API.Collections;
21+
using cAlgo.API.Indicators;
22+
using cAlgo.API.Internals;
23+
24+
namespace cAlgo
25+
{
26+
[Indicator(AccessRights = AccessRights.None)]
27+
public class AlgoRegistrySample : Indicator
28+
{
29+
30+
protected override void Initialize()
31+
{
32+
// Checking if the user has installed the required indicators
33+
if (!AlgoRegistry.Exists("Rapid SMA") && !AlgoRegistry.Exists("Swirling SMA"))
34+
{
35+
// Showing the message box with the warning
36+
MessageBox.Show("Required indicators are not installed!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
37+
}
38+
else
39+
{
40+
// Adding the indicators to the chart if they are installed
41+
ChartIndicators.Add("Rapid SMA");
42+
ChartIndicators.Add("Swirling SMA");
43+
}
44+
}
45+
46+
public override void Calculate(int index)
47+
{
48+
// Result[index] =
49+
}
50+
}
51+
}
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>
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}") = "ChartIdSample", "ChartIdSample\ChartIdSample.csproj", "{0430294a-0528-4a2d-abcd-fb7937f5f5b9}"
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+
{0430294a-0528-4a2d-abcd-fb7937f5f5b9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0430294a-0528-4a2d-abcd-fb7937f5f5b9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0430294a-0528-4a2d-abcd-fb7937f5f5b9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0430294a-0528-4a2d-abcd-fb7937f5f5b9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// -------------------------------------------------------------------------------------------------
2+
//
3+
// This code is a cTrader Algo API example.
4+
//
5+
// This code is intended to be used as a sample and does not guarantee any particular outcome or
6+
// profit of any kind. Use it at your own risk.
7+
//
8+
// This sample accesses the Chart.Id property of the chart to which it is attached.
9+
// On chart activation/deactivation, the indicator prints the value of Chart.Id to the log.
10+
//
11+
// -------------------------------------------------------------------------------------------------
12+
13+
using System;
14+
using System.Collections.Generic;
15+
using System.Linq;
16+
using System.Text;
17+
using cAlgo.API;
18+
using cAlgo.API.Collections;
19+
using cAlgo.API.Indicators;
20+
using cAlgo.API.Internals;
21+
22+
namespace cAlgo
23+
{
24+
[Indicator(AccessRights = AccessRights.None)]
25+
public class ChartIdSample : Indicator
26+
{
27+
28+
29+
string _currentChartId;
30+
31+
// Getting the Id of the current Chart and
32+
// assigning custom event handlers for the
33+
// Chart.Activated and Chart.Deactivated events
34+
protected override void Initialize()
35+
{
36+
_currentChartId = Chart.Id.ToString();
37+
Chart.Activated += Chart_Activated;
38+
Chart.Deactivated += Chart_Deactivated;
39+
}
40+
41+
42+
private void Chart_Deactivated(ChartActivationChangedEventArgs obj)
43+
{
44+
Print($"Chart with ID {_currentChartId} deactivated!");
45+
}
46+
47+
private void Chart_Activated(ChartActivationChangedEventArgs obj)
48+
{
49+
Print($"Chart with ID {_currentChartId} activated!");
50+
}
51+
52+
public override void Calculate(int index)
53+
{
54+
55+
}
56+
}
57+
}
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>
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}") = "ChartIndicators Sample", "ChartIndicators Sample\ChartIndicators Sample.csproj", "{df63108d-9d7e-435d-b8fb-c2ba3d9289b5}"
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+
{df63108d-9d7e-435d-b8fb-c2ba3d9289b5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{df63108d-9d7e-435d-b8fb-c2ba3d9289b5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{df63108d-9d7e-435d-b8fb-c2ba3d9289b5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{df63108d-9d7e-435d-b8fb-c2ba3d9289b5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// -------------------------------------------------------------------------------------------------
2+
//
3+
// This code is a cTrader Algo API example.
4+
//
5+
// This code is intended to be used as a sample and does not guarantee any particular outcome or
6+
// profit of any kind. Use it at your own risk.
7+
//
8+
// This sample adds two simple moving averages to the chart to which it is attached. The sample
9+
// uses the ADX indicator to determine the line colour of these two moving averages. If ADX > 30,
10+
// the trend is strong, and the SMA lines are green and blue. If ADX <= 30, the trend is week, and
11+
// the SMA lines are orange and purple.
12+
//
13+
// -------------------------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using cAlgo.API;
20+
using cAlgo.API.Collections;
21+
using cAlgo.API.Indicators;
22+
using cAlgo.API.Internals;
23+
24+
namespace cAlgo
25+
{
26+
[Indicator(AccessRights = AccessRights.None)]
27+
public class ChartIndicatorsSample : Indicator
28+
{
29+
// Defining the indicators to be added to the chart
30+
ChartIndicator _saSlow;
31+
ChartIndicator _saFast;
32+
33+
// Defining the indicator to extract the ADX value from
34+
private AverageDirectionalMovementIndexRating _averageDirectionalMovementIndexRating;
35+
36+
37+
protected override void Initialize()
38+
{
39+
// Adding the two SMAs on indicator start
40+
_saSlow = ChartIndicators.Add("Simple Moving Average", "Close", 50);
41+
_saFast = ChartIndicators.Add("Simple Moving Average", "Close", 20);
42+
43+
// Initialising the indicator from which the ADX value will be taken
44+
_averageDirectionalMovementIndexRating = Indicators.AverageDirectionalMovementIndexRating(20);
45+
46+
}
47+
48+
public override void Calculate(int index)
49+
{
50+
// Accessing and comparing the ADX value to 30
51+
if (_averageDirectionalMovementIndexRating.ADX[index] > 30)
52+
{
53+
54+
// Setting the SMA line properties
55+
_saFast.Lines[0].Color = Color.Green;
56+
_saFast.Lines[0].Thickness = 3;
57+
_saSlow.Lines[0].Color = Color.Blue;
58+
_saSlow.Lines[0].Thickness = 3;
59+
} else
60+
{
61+
62+
// Setting the SMA line properties
63+
_saFast.Lines[0].Color = Color.Orange;
64+
_saFast.Lines[0].Thickness = 3;
65+
_saSlow.Lines[0].Color = Color.Purple;
66+
_saSlow.Lines[0].Thickness = 3;
67+
}
68+
}
69+
}
70+
}
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)