RangeSataSeries - ranges

Modified on Fri, 04 Aug 2023 at 01:24 PM

The DataSeies, each element of which represents RangeValue, where the minimum and maximum values are set.

Main properties:

  • Color - colour
  • ScaleIt - a flag that regulates the indicator auto-scale
  • Visible - a flag that regulates the DataSeries visibility

Example of the Bollinger Bands indicator that uses this DataSeies

    public class BollingerBands : Indicator

    {

        private readonly RangeDataSeries _band = new RangeDataSeries("BackGround");

        private readonly StdDev _dev = new StdDev();

 

        private readonly SMA _sma = new SMA();

        private decimal _width;

 

        public int Period

        {

            get => _sma.Period;

            set

            {

                if (value <= 0)

                    return;

 

                _sma.Period = _dev.Period = value;

                RecalculateValues();

            }

        }

 

        public decimal Width

        {

            get => _width;

            set

            {

                if (value <= 0)

                    return;

 

                _width = value;

                RecalculateValues();

            }

        }

 

        public BollingerBands()

        {

             ((ValueDataSeries)DataSeries[0]).Color = Colors.Green;

 

            DataSeries.Add(new ValueDataSeries("Up")

            {

                VisualType = VisualMode.Line

            });

            DataSeries.Add(new ValueDataSeries("Down")

            {

                VisualType = VisualMode.Line

            });

 

            DataSeries.Add(_band);

            Period = 10;

            Width = 1;

        }

 

        protected override void OnCalculate(int bar, decimal value)

        {

            var sma = _sma.Calculate(bar, value);

            var dev = _dev.Calculate(bar, value);

 

            this[bar] = sma;

 

            DataSeries[1][bar] = sma + dev * Width;

            DataSeries[2][bar] = sma - dev * Width;

 

            _band[bar].Upper = sma + dev * Width;

            _band[bar].Lower = sma - dev * Width;

        }

    }

 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article