Beispiel #1
0
        public static Result CalculateSlow(double[] inputClose, double[] inputHigh, double[] inputLow, int period, int slow, double?[] outDataK, double?[] outDataD)
        {
            Result res = new Result();

            res.Status = ResultStatus.Success;

            int len = inputClose.Length;

            double[] tmpK = new double[len];
            try
            {
                for (int i = period - 1; i < len; i++)
                {
                    double[] tmpHigh = new double[period];
                    double[] tmpLow  = new double[period];

                    for (int j = 0; j < period; j++)
                    {
                        int bIndex = i - period + 1;

                        tmpHigh[j] = inputHigh[bIndex + j];
                        tmpLow[j]  = inputLow[bIndex + j];
                    }

                    tmpK[i] = GetBasicK(tmpHigh, tmpLow, inputClose[i]);
                }

                SMA.Calculate(tmpK, slow, outDataK);

                double[] outDataK2 = new double[len];

                for (int k = 0; k < len; k++)
                {
                    if (outDataK[k].HasValue)
                    {
                        outDataK2[k] = outDataK[k].Value;
                    }
                }

                SMA.Calculate(outDataK2, slow, outDataD);

                for (int j = 0; j < period; j++)
                {
                    outDataK[j] = null;
                    outDataD[j] = null;
                }
            }
            catch (Exception ex)
            {
                res.Status  = ResultStatus.Fail;
                res.Message = ex.ToString();
                return(res);
            }
            return(res);
        }
Beispiel #2
0
        public static Result Calculate(double[] inputData, int period, double factor, double?[] outMiddle, double?[] outHigh, double?[] outLow)
        {
            Result res = new Result();

            res.Status = ResultStatus.Success;

            int len = inputData.Length;

            double[] sd = new double[len];

            try
            {
                SMA.Calculate(inputData, period, outMiddle);

                for (int i = period - 1; i < len; i++)
                {
                    double[] d = new double[period];

                    for (int j = 0; j < period; j++)
                    {
                        int bIndex = i + 1 - period;

                        d[j] = inputData[bIndex + j];
                    }

                    sd[i] = GenericHelper.StandardDeviation(d);

                    outHigh[i] = outMiddle[i] + factor * sd[i];

                    outLow[i] = outMiddle[i] - factor * sd[i];
                }
            }
            catch (Exception ex)
            {
                res.Status  = ResultStatus.Fail;
                res.Message = ex.ToString();
                return(res);
            }

            return(res);
        }