Example #1
0
        public override void Populate()
        {
            BarHistory bars    = base.Parameters[0].AsBarHistory;
            int        period1 = base.Parameters[1].AsInt;
            int        period2 = base.Parameters[2].AsInt;

            this.DateTimes = bars.DateTimes;
            int FirstValidValue = Math.Max(period1, period2) + 1;

            if (bars.Count < FirstValidValue)
            {
                return;
            }
            var MLTP       = 2.0 / ((double)period1 + 1.0);
            var MLTP2      = (bars.Close - Lowest.Series(bars.Low, period2) - (Highest.Series(bars.High, period2) - bars.Close)).Abs() / (Highest.Series(bars.High, period2) - Lowest.Series(bars.Low, period2));
            var timeSeries = MLTP * (1.0 + MLTP2);

            for (int i = 0; i < FirstValidValue; i++)
            {
                base[i] = FastSMA.Series(bars.Close, period1)[i];
            }

            for (int j = FirstValidValue; j < bars.Count; j++)
            {
                base.Values[j] = base.Values[j - 1] + timeSeries[j] * (bars.Close[j] - base.Values[j - 1]);
            }
        }
Example #2
0
        //populate
        public override void Populate()
        {
            TimeSeries ds     = Parameters[0].AsTimeSeries;
            Int32      period = Parameters[1].AsInt;
            Boolean    useEMA = Parameters[2].AsBoolean;

            DateTimes = ds.DateTimes;

            if (period <= 0 || ds.Count == 0 || ds.Count < period)
            {
                return;
            }

            var        weight = 2d / (period + 1);
            TimeSeries sma    = FastSMA.Series(ds, period);
            TimeSeries ema    = EMA.Series(ds, period);
            TimeSeries ma     = !useEMA ? sma : ema;

            double mdev   = 0;
            var    exd    = new TimeSeries(DateTimes);
            var    absDif = (ma - ds).Abs();
            var    Rate   = 2 / (double)(period + 1);

            for (int i = 0; i > period; i--)
            {
                mdev += Math.Abs(ma[i] - ds[i]);
            }

            mdev /= period;

            for (int bar = 1; bar < ds.Count; bar++)
            {
                if (bar <= period)
                {
                    exd[bar] = mdev;
                }
                else
                {
                    exd[bar] = absDif[bar] * Rate + exd[bar - 1] * (1.0 - Rate);
                }
            }

            for (int bar = 0; bar < ds.Count; bar++)
            {
                Values[bar] = exd[bar];
            }
        }
Example #3
0
        //populate
        public override void Populate()
        {
            TimeSeries ds         = Parameters[0].AsTimeSeries;
            Int32      period     = Parameters[1].AsInt;
            Double     deviations = Parameters[2].AsDouble;
            Boolean    useEMA     = Parameters[3].AsBoolean;

            DateTimes = ds.DateTimes;

            if (period <= 0 || ds.Count == 0 || ds.Count < period)
            {
                return;
            }

            TimeSeries sma = FastSMA.Series(ds, period);
            TimeSeries ema = EMA.Series(ds, period);
            TimeSeries ma  = !useEMA ? sma : ema;
            ExpDev     exd = new ExpDev(ds, period, useEMA);

            for (int bar = period; bar < ds.Count; bar++)
            {
                Values[bar] = ma[bar] - exd[bar] * deviations;
            }
        }