Example #1
0
        private static void CalcIchimokuKijunSen <TQuote>(
            int index, List <TQuote> historyList, IchimokuResult result, int shortSpanPeriod) where TQuote : IQuote
        {
            if (index >= shortSpanPeriod)
            {
                decimal max = 0;
                decimal min = decimal.MaxValue;

                for (int p = index - shortSpanPeriod; p < index; p++)
                {
                    TQuote d = historyList[p];

                    if (d.High > max)
                    {
                        max = d.High;
                    }

                    if (d.Low < min)
                    {
                        min = d.Low;
                    }
                }

                result.KijunSen = (min + max) / 2;
            }
        }
Example #2
0
        private static void CalcIchimokuTenkanSen(
            int index, List <Quote> historyList, IchimokuResult result, int signalPeriod)
        {
            if (index >= signalPeriod)
            {
                decimal max = 0;
                decimal min = decimal.MaxValue;

                for (int p = index - signalPeriod; p < index; p++)
                {
                    Quote d = historyList[p];

                    if (d.High > max)
                    {
                        max = d.High;
                    }

                    if (d.Low < min)
                    {
                        min = d.Low;
                    }
                }

                result.TenkanSen = (min + max) / 2;
            }
        }
Example #3
0
        private static void CalcIchimokuSenkouB(
            int index, List <Quote> historyList, IchimokuResult result, int shortSpanPeriod, int longSpanPeriod)
        {
            if (index >= shortSpanPeriod + longSpanPeriod)
            {
                decimal max = 0;
                decimal min = decimal.MaxValue;

                for (int p = index - shortSpanPeriod - longSpanPeriod;
                     p < index - shortSpanPeriod; p++)
                {
                    Quote d = historyList[p];

                    if (d.High > max)
                    {
                        max = d.High;
                    }

                    if (d.Low < min)
                    {
                        min = d.Low;
                    }
                }

                result.SenkouSpanB = (min + max) / 2;
            }
        }
Example #4
0
        private static void CalcIchimokuKijunSen(
            List <Quote> historyList,
            IchimokuResult result,
            Quote h, int shortSpanPeriod)
        {
            if (h.Index >= shortSpanPeriod)
            {
                decimal max = 0;
                decimal min = decimal.MaxValue;

                for (int p = (int)h.Index - shortSpanPeriod; p < h.Index; p++)
                {
                    Quote d = historyList[p];

                    if (d.High > max)
                    {
                        max = d.High;
                    }

                    if (d.Low < min)
                    {
                        min = d.Low;
                    }
                }

                result.KijunSen = (min + max) / 2;
            }
        }
Example #5
0
        // ICHIMOKU CLOUD
        public static IEnumerable <IchimokuResult> GetIchimoku <TQuote>(
            IEnumerable <TQuote> history,
            int signalPeriod    = 9,
            int shortSpanPeriod = 26,
            int longSpanPeriod  = 52)
            where TQuote : IQuote
        {
            // clean quotes
            List <TQuote> historyList = history.Sort();

            // check parameters
            ValidateIchimoku(history, signalPeriod, shortSpanPeriod, longSpanPeriod);

            // initialize
            List <IchimokuResult> results = new List <IchimokuResult>(historyList.Count);

            // roll through history
            for (int i = 0; i < historyList.Count; i++)
            {
                TQuote h     = historyList[i];
                int    index = i + 1;

                IchimokuResult result = new IchimokuResult
                {
                    Date = h.Date
                };

                // tenkan-sen conversion line
                CalcIchimokuTenkanSen(index, historyList, result, signalPeriod);

                // kijun-sen base line
                CalcIchimokuKijunSen(index, historyList, result, shortSpanPeriod);

                // senkou span A
                if (index >= 2 * shortSpanPeriod)
                {
                    IchimokuResult skq = results[index - shortSpanPeriod - 1];

                    if (skq != null && skq.TenkanSen != null && skq.KijunSen != null)
                    {
                        result.SenkouSpanA = (skq.TenkanSen + skq.KijunSen) / 2;
                    }
                }

                // senkou span B
                CalcIchimokuSenkouB(index, historyList, result, shortSpanPeriod, longSpanPeriod);

                // chikou line
                if (index + shortSpanPeriod <= historyList.Count)
                {
                    result.ChikouSpan = historyList[index + shortSpanPeriod - 1].Close;
                }
                results.Add(result);
            }

            return(results);
        }
Example #6
0
        // ICHIMOKU CLOUD
        public static IEnumerable <IchimokuResult> GetIchimoku(IEnumerable <Quote> history,
                                                               int signalPeriod = 9, int shortSpanPeriod = 26, int longSpanPeriod = 52)
        {
            // clean quotes
            Cleaners.PrepareHistory(history);

            // check parameters
            ValidateIchimoku(history, signalPeriod, shortSpanPeriod, longSpanPeriod);

            // initialize
            List <Quote>          historyList = history.ToList();
            List <IchimokuResult> results     = new List <IchimokuResult>();

            // roll through history
            for (int i = 0; i < historyList.Count; i++)
            {
                Quote h = historyList[i];

                IchimokuResult result = new IchimokuResult
                {
                    Index = (int)h.Index,
                    Date  = h.Date
                };

                // tenkan-sen conversion line
                if (h.Index >= signalPeriod)
                {
                    List <Quote> tenkanPeriod = historyList
                                                .Where(x => x.Index > (h.Index - signalPeriod) && x.Index <= h.Index)
                                                .ToList();

                    decimal max = tenkanPeriod.Select(x => x.High).Max();
                    decimal min = tenkanPeriod.Select(x => x.Low).Min();

                    result.TenkanSen = (min + max) / 2;
                }

                // kijun-sen base line
                if (h.Index >= shortSpanPeriod)
                {
                    List <Quote> kijunPeriod = historyList
                                               .Where(x => x.Index > (h.Index - shortSpanPeriod) && x.Index <= h.Index)
                                               .ToList();

                    decimal max = kijunPeriod.Select(x => x.High).Max();
                    decimal min = kijunPeriod.Select(x => x.Low).Min();

                    result.KijunSen = (min + max) / 2;
                }

                // senkou span A
                if (h.Index >= 2 * shortSpanPeriod)
                {
                    IchimokuResult skq = results[(int)h.Index - shortSpanPeriod - 1];

                    if (skq != null && skq.TenkanSen != null && skq.KijunSen != null)
                    {
                        result.SenkouSpanA = (skq.TenkanSen + skq.KijunSen) / 2;
                    }
                }

                // senkou span B
                if (h.Index >= shortSpanPeriod + longSpanPeriod)
                {
                    List <Quote> senkauPeriod = historyList
                                                .Where(x => x.Index > (h.Index - shortSpanPeriod - longSpanPeriod) &&
                                                       x.Index <= h.Index - shortSpanPeriod)
                                                .ToList();

                    decimal max = senkauPeriod.Select(x => x.High).Max();
                    decimal min = senkauPeriod.Select(x => x.Low).Min();

                    result.SenkauSpanB = (min + max) / 2;
                }

                // chikou line
                if (h.Index + shortSpanPeriod <= historyList.Count)
                {
                    result.ChikouSpan = historyList[(int)h.Index + shortSpanPeriod - 1].Close;
                }
                results.Add(result);
            }

            return(results);
        }