예제 #1
0
        public static IchimokuItem Ichimoku(this IEnumerable <ICandle> candles, int?conversionLinePeriod = null, int?baseLinePeriod = null, int?laggingSpanPeriods = null, int?displacement = null)
        {
            conversionLinePeriod = conversionLinePeriod ?? 20;
            baseLinePeriod       = baseLinePeriod ?? 60;
            laggingSpanPeriods   = laggingSpanPeriods ?? 120;
            displacement         = displacement ?? 30;

            IIndicatorOptions options  = new IchimokuOptions(conversionLinePeriod.Value, baseLinePeriod.Value, laggingSpanPeriods.Value, displacement.Value);
            Ichimoku          ichimoku = new Ichimoku();

            return((IchimokuItem)ichimoku.Get(candles, options));
        }
예제 #2
0
        public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null)
        {
            try
            {
                IchimokuOptions config = options != null ? (IchimokuOptions)options.Options : new IchimokuOptions(20, 60, 120, 30);

                List <decimal> highs  = source.Select(x => x.High).ToList();
                List <decimal> lows   = source.Select(x => x.Low).ToList();
                List <decimal> closes = source.Select(x => x.Close).ToList();

                var ichi = new IchimokuItem
                {
                    TenkanSen   = Donchian(source, config.ConversionLinePeriod, highs, lows),
                    KijunSen    = Donchian(source, config.BaseLinePeriod, highs, lows),
                    SenkouSpanB = Donchian(source, config.LaggingSpanPeriods, highs, lows),
                    SenkouSpanA = new List <decimal?>()
                };


                // SenkouSpanA is calculated...
                for (int i = 0; i < ichi.TenkanSen.Count; i++)
                {
                    if (ichi.TenkanSen[i].HasValue && ichi.KijunSen[i].HasValue)
                    {
                        ichi.SenkouSpanA.Add((ichi.TenkanSen[i].Value + ichi.KijunSen[i].Value) / 2);
                    }
                    else
                    {
                        ichi.SenkouSpanA.Add(null);
                    }
                }

                // Add the displacement for the cloud
                for (int i = 0; i < config.Displacement; i++)
                {
                    ichi.SenkouSpanA.Insert(0, null);
                    ichi.SenkouSpanB.Insert(0, null);
                }

                // Add the ChikouSpan
                ichi.ChikouSpan = new List <decimal?>();

                // Add the displacement for the lagging span
                var displacedCloses = closes.Skip(config.Displacement).ToList();

                for (int i = 0; i < closes.Count; i++)
                {
                    if (i < closes.Count - config.Displacement)
                    {
                        ichi.ChikouSpan.Add(displacedCloses[i]);
                    }
                    else
                    {
                        ichi.ChikouSpan.Add(null);
                    }
                }

                return(ichi);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not calculate ichimoku cloud");
            }
        }