Create Dataseries which mirrors Source, but with last X values removed?

Created at 07 Apr 2022, 17:23
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

Create Dataseries which mirrors Source, but with last X values removed?
07 Apr 2022, 17:23


I want to create a dataseries, that mirrors the source dataseries. (One that I can call .maximum(10)) on etc.

But I want it to exclude the most recent prices (X bars). The reason is I want to be able to find when price has spiked OUT of a tight range, I can define the range by Source.Maximum(10), and Source.Minimum(10)... but if the price spikes out, the Maximum will increase as well, and so I can't determine if price has spiked out of the range.


@manoj.clsd.kumar@gmail.com
Replies

amusleh
08 Apr 2022, 10:26

Hi,

There is no need to create a new data series for that, you can work on a split of a data series, ex:

        /// <summary>
        /// Returns the minimum value between start and end (inclusive) index in a DataSeries
        /// </summary>
        /// <param name="dataSeries"></param>
        /// <param name="startIndex">Start index Inclusive (Ex: 1)</param>
        /// <param name="endIndex">End index Inclusive (Ex: 10)</param>
        /// <returns>double</returns>
        private double Minimum(DataSeries dataSeries, int startIndex, int endIndex)
        {
            var min = double.PositiveInfinity;

            for (var i = startIndex; i <= endIndex; i++)
            {
                min = Math.Min(dataSeries[i], min);
            }

            return min;
        }


        /// <summary>
        /// Returns the maximum value between start and end (inclusive) index in a DataSeries
        /// </summary>
        /// <param name="dataSeries"></param>
        /// <param name="startIndex">Start index Inclusive (Ex: 1)</param>
        /// <param name="endIndex">End index Inclusive  (Ex: 10)</param>
        /// <returns>double</returns>
        private double Maximum(DataSeries dataSeries, int startIndex, int endIndex)
        {
            var max = double.NegativeInfinity;

            for (var i = startIndex; i <= endIndex; i++)
            {
                max = Math.Max(dataSeries[i], max);
            }

            return max;
        }

 


@amusleh