예제 #1
0
        public override void ApplyTo(StockSerie stockSerie)
        {
            int period = Math.Min((int)this.parameters[0], stockSerie.Count - 1);
            int inputSmoothing = (int)this.parameters[1];
            int smoothing = (int)this.parameters[2];
            FloatSerie erSerie = stockSerie.CalculateER(period, inputSmoothing).CalculateEMA(smoothing);
            this.series[0] = erSerie;
            this.Series[0].Name = this.Name;

            this.CreateEventSeries(stockSerie.Count);

            float overbought = (float)this.parameters[3];
            float oversold = -overbought;

            bool isOverSold = false;
            bool isOverBought = false;

            for (int i = period; i < stockSerie.Count; i++)
            {
                this.eventSeries[0][i] = erSerie[i] > 0;
                this.eventSeries[1][i] = erSerie[i] < 0;
                this.eventSeries[2][i] = erSerie[i] > 0 && erSerie[i - 1] < 0;
                this.eventSeries[3][i] = erSerie[i] < 0 && erSerie[i - 1] > 0;

                isOverSold = erSerie[i] <= oversold;
                isOverBought = erSerie[i] >= overbought;
                this.eventSeries[4][i] = isOverBought;
                this.eventSeries[5][i] = isOverSold;
                this.eventSeries[6][i] = (!isOverSold) && this.eventSeries[3][i - 1];
                this.eventSeries[7][i] = (!isOverBought) && this.eventSeries[2][i - 1];
            }
        }