Skip to content

CloudAttribute

Summary

Represents the cloud between the indicator lines.

Signature

1
public class CloudAttribute : Attribute

Namespace

cAlgo.API

Properties

Name Description
FirstLineName { get; } The name of the first indicator line.
SecondLineName { get; } The name of the second indicator line.
Opacity { get; set; } The cloud opacity. Value can be set from 0 (transparent) to 1 (opaque). Values higher than 1 will be set to 1, values below 0 will be set to 0. Opacity is multiplied by the alpha channel of the active color (first or second color). Default opacity value is 0.2.
FirstColor { get; set; } Cloud color when the first line is above the second one. If not specified, the color of the first line is used.
SecondColor { get; set; } Cloud color when the second line is above the first one. If not specified, color of the second line is used.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 using cAlgo.API;
 using cAlgo.API.Indicators;
 using System;
 namespace cAlgo
 {
     // This indicator shows how to use cloud attribute
     [Cloud("Top", "Bottom", Opacity = 0.2)]
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class BollingerBandsMTFCloudSample : Indicator
     {
         private BollingerBands _bollingerBands;
         private Bars _baseBars;
         [Parameter("Base TimeFrame", DefaultValue = "Daily")]
         public TimeFrame BaseTimeFrame { get; set; }
         [Parameter("Source", DefaultValue = DataSeriesType.Close)]
         public DataSeriesType DataSeriesType { get; set; }
         [Parameter("Periods", DefaultValue = 14, MinValue = 0)]
         public int Periods { get; set; }
         [Parameter("Standard Deviation", DefaultValue = 2, MinValue = 0)]
         public double StandardDeviation { get; set; }
         [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
         public MovingAverageType MaType { get; set; }
         [Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
         public IndicatorDataSeries Main { get; set; }
         [Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
         public IndicatorDataSeries Top { get; set; }
         [Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
         public IndicatorDataSeries Bottom { get; set; }
         protected override void Initialize()
         {
             _baseBars = MarketData.GetBars(BaseTimeFrame);
             var baseSeries = GetBaseSeries();
             _bollingerBands = Indicators.BollingerBands(baseSeries, Periods, StandardDeviation, MaType);
         }
         public override void Calculate(int index)
         {
             var baseIndex = _baseBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
             Main[index] = _bollingerBands.Main[baseIndex];
             Top[index] = _bollingerBands.Top[baseIndex];
             Bottom[index] = _bollingerBands.Bottom[baseIndex];
         }
         private DataSeries GetBaseSeries()
         {
             switch (DataSeriesType)
             {
                 case DataSeriesType.Open:
                     return _baseBars.OpenPrices;
                 case DataSeriesType.High:
                     return _baseBars.HighPrices;
                 case DataSeriesType.Low:
                     return _baseBars.LowPrices;
                 case DataSeriesType.Close:
                     return _baseBars.ClosePrices;
                 default:
                     throw new ArgumentOutOfRangeException("DataSeriesType");
             }
         }
     }
     public enum DataSeriesType
     {
         Open,
         High,
         Low,
         Close
     }
 }

Last update: December 7, 2022

Comments