CloudAttribute


Summary

Represents the cloud between the indicator lines.

Syntax

public class CloudAttribute : Attribute

Members

NameTypeSummary
CloudAttribute MethodThe cloud between the indicator lines.
FirstColor PropertyCloud color when the first line is above the second one. If not specified, the color of the first line is used.
FirstLineName PropertyThe name of the first indicator line.
Opacity PropertyThe 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.
SecondColor PropertyCloud color when the second line is above the first one. If not specified, color of the second line is used.
SecondLineName PropertyThe name of the second indicator line.

Example 1

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
    }
}
Reference