Skip to content

Commit 45c6679

Browse files
authored
CNT-731: Add cloud to indicator samples (spotware#30)
* CNT-731: Add cloud to indicator samples * CNT-731: Fixes
1 parent 400565c commit 45c6679

File tree

7 files changed

+164
-0
lines changed

7 files changed

+164
-0
lines changed

Indicators/.samples.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
{
3030
"name": "BarsTickEventArgs Sample"
3131
},
32+
{
33+
"name": "Bollinger Bands Cloud Sample"
34+
},
3235
{
3336
"name": "Bollinger Bands MTF Cloud Sample"
3437
},
@@ -272,6 +275,9 @@
272275
{
273276
"name": "Line Style Sample"
274277
},
278+
{
279+
"name": "MA Cloud Sample"
280+
},
275281
{
276282
"name": "Market Data Sample"
277283
},
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}") = "Bollinger Bands Cloud Sample", "Bollinger Bands Cloud Sample\Bollinger Bands Cloud Sample.csproj", "{d13ce943-9302-455b-9ec2-5e6a99b87f23}"
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+
{d13ce943-9302-455b-9ec2-5e6a99b87f23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{d13ce943-9302-455b-9ec2-5e6a99b87f23}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{d13ce943-9302-455b-9ec2-5e6a99b87f23}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{d13ce943-9302-455b-9ec2-5e6a99b87f23}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 sample indicator draws a cloud between the top and bottom bands of Bollinger Bands.
8+
//
9+
// For a detailed tutorial on creating this indicator, see this video: https://www.youtube.com/watch?v=AWqo0k0Rrag
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
20+
{
21+
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
22+
[Cloud("Top", "Bottom", Opacity = 0.2)]
23+
24+
public class BollingerBandsCloud : Indicator
25+
{
26+
27+
[Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
28+
public IndicatorDataSeries Main { get; set; }
29+
30+
[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
31+
public IndicatorDataSeries Top { get; set; }
32+
33+
[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
34+
public IndicatorDataSeries Bottom { get; set; }
35+
36+
private BollingerBands _bollingerBands;
37+
38+
protected override void Initialize()
39+
{
40+
_bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
41+
}
42+
43+
public override void Calculate(int index)
44+
{
45+
Main[index] = _bollingerBands.Main[index];
46+
Top[index] = _bollingerBands.Top[index];
47+
Bottom[index] = _bollingerBands.Bottom[index];
48+
}
49+
}
50+
}
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}") = "MA Cloud Sample", "MA Cloud Sample\MA Cloud Sample.csproj", "{121fedb8-4ad2-4fd0-80dd-97ee82602d8d}"
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+
{121fedb8-4ad2-4fd0-80dd-97ee82602d8d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{121fedb8-4ad2-4fd0-80dd-97ee82602d8d}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{121fedb8-4ad2-4fd0-80dd-97ee82602d8d}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{121fedb8-4ad2-4fd0-80dd-97ee82602d8d}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 sample indicator draws a green cloud for uptrends and a red cloud for downtrends on a Moving Average (MA) Crossover.
8+
//
9+
// For a detailed tutorial on creating this indicator, see this video: https://www.youtube.com/watch?v=AWqo0k0Rrag
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
20+
{
21+
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
22+
[Cloud("Fast", "Slow", Opacity = 0.2)]
23+
public class MACloud : Indicator
24+
{
25+
[Output("Fast", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
26+
public IndicatorDataSeries Fast { get; set; }
27+
28+
[Output("Slow", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
29+
public IndicatorDataSeries Slow { get; set; }
30+
31+
SimpleMovingAverage _fastMA;
32+
SimpleMovingAverage _slowMA;
33+
34+
protected override void Initialize()
35+
{
36+
_fastMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, 7);
37+
_slowMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, 13);
38+
}
39+
40+
public override void Calculate(int index)
41+
{
42+
Fast[index] = _fastMA.Result[index];
43+
Slow[index] = _slowMA.Result[index];
44+
}
45+
}
46+
}
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)