Пример #1
0
        public static ExtremumGroup FromDto(ExtremumGroupDto dto)
        {
            var extremumGroup = new ExtremumGroup
            {
                ExtremumGroupId    = dto.ExtremumGroupId,
                AssetId            = dto.AssetId,
                TimeframeId        = dto.TimeframeId,
                IsPeak             = dto.IsPeak,
                MasterExtremumId   = dto.MasterExtremumId,
                MasterDateIndex    = dto.MasterDateIndex,
                SlaveExtremumId    = dto.SlaveExtremumId,
                SlaveDateIndex     = dto.SlaveDateIndex,
                StartDateIndex     = dto.StartDateIndex,
                EndDateIndex       = dto.EndDateIndex,
                OCPriceLevel       = dto.OCPriceLevel,
                ExtremumPriceLevel = dto.ExtremumPriceLevel,
                MiddlePriceLevel   = dto.MiddlePriceLevel
            };

            return(extremumGroup);
        }
Пример #2
0
 public bool isOpposite(ExtremumGroup subextremum)
 {
     if (type.IsPeak() && !subextremum.type.IsPeak()) return true;
     if (!type.IsPeak() && subextremum.type.IsPeak()) return true;
     return false;
 }
Пример #3
0
        public List<Trendline> GetTrendlineVariantsForExtremaPair(ExtremumGroup extremum, ExtremumGroup subextremum, DataItem[] items)
        {
            List<Trendline> trendlines = new List<Trendline>();

            /*
             * Jeżeli ekstrema przekazane do tej funkcji są odwrotne (czyli jedno jest wierzchołkiem, a drugie dołkiem),
             * żeby mogły być procesowane pomiędzy nimi musi być co najmniej jedno inne ekstremum.
             */
            if (extremum.isOpposite(subextremum))
            {
                var midextremum = extremaGroups.Where(e => e.master.Price != null && e.master.Date > extremum.master.Date && e.master.Date < subextremum.master.Date && e.type.IsPeak() == extremum.type.IsPeak()).ToArray();
                if (midextremum.Length == 0)
                {
                    return trendlines;
                }
            }

            double extremumLower = extremum.getLower();
            double extremumHigher = extremum.getHigher();
            double extremumStep = extremum.getStep();
            double subextremumLower = subextremum.getLower();
            double subextremumHigher = subextremum.getHigher();
            double subextremumStep = subextremum.getStep();

            for (var a = extremumLower; a <= extremumHigher + (extremumStep / 2); a += extremumStep)
            {
                for (var b = subextremumLower; b <= subextremumHigher + (subextremumStep / 2); b += subextremumStep)
                {
                    var trendline = new Trendline(this.AssetTimeframe, new ValuePoint(extremum.getStartItem(), a), new ValuePoint(subextremum.getEndItem(), b));
                    trendlines.Add(trendline);
                }

            }

            return trendlines;
        }
Пример #4
0
        private bool checkIfExtremaPairValid(ExtremumGroup extremum, ExtremumGroup subextremum)
        {
            if (Math.Abs(extremum.master.Distance(subextremum.master)) > RangeToCheck) return false;

            //Items must have minimum distance between each other.
            if (Math.Abs(extremum.master.Distance(subextremum.master)) < MinDistance) return false;
            if (extremum.type.IsOpposite(subextremum.type) && Math.Abs(extremum.master.Distance(subextremum.master)) < OppositeExtremaMinDistance) return false;

            return true;
        }
Пример #5
0
        public static IEnumerable<ExtremumGroup> GetExtremaGroups(this IEnumerable<DataItem> extrema)
        {
            DataItem[] items = extrema.OrderBy(i => i.Date).ToArray();
            List<ExtremumGroup> list = new List<ExtremumGroup>();

            for (var i = 0; i < items.Length; i++)
            {
                DataItem item = items[i];
                ExtremumGroup group = new ExtremumGroup();
                if (i < items.Length - 1 && items[i + 1].Index - item.Index == 1)
                {
                    if (item.Price.IsExtremumByClosePrice())
                    {
                        group.master = item;
                        group.slave = items[i + 1];
                    }
                    else
                    {
                        group.master = items[i + 1];
                        group.slave = item;
                    }

                    i++;

                }
                else
                {
                    group.master = item;
                }

                group.type = item.Price.IsTrough() ? ExtremumType.TroughByClose : ExtremumType.PeakByClose;
                list.Add(group);

            }

            return list;
        }