Esempio n. 1
0
        public MACDAreaClass MergeArea(MACDAreaClass A1, MACDAreaClass A2)
        {
            MACDTable tmp = new MACDTable(A1.Data.GetTable());

            tmp.Contact(A2.Data);
            MACDAreaClass ret = new MACDAreaClass(tmp);

            return(ret);
        }
Esempio n. 2
0
        public List <MACDAreaClass> SplitSubMACDAreas()
        {
            var Arr = from n in Data.ItemList
                      orderby n.RowId
                      select n;
            List <MACDAreaClass> ret      = new List <MACDAreaClass>();
            MACDDataItem         firstObj = Arr.First <MACDDataItem>();

            firstObj.Color       = firstObj.MACD > 0 ? MACDColor.Red : MACDColor.Green;
            firstObj.IsAreaStart = true;
            MACDDataItem endObj = Arr.Last <MACDDataItem>();

            endObj.Color     = endObj.MACD > 0 ? MACDColor.Red : MACDColor.Green;
            endObj.IsAreaEnd = true;
            for (int i = 1; i < Len - 1; i++)
            {
                MACDDataItem CurrObj = Arr.ElementAt <MACDDataItem>(i);
                MACDDataItem NextObj = Arr.ElementAt <MACDDataItem>(i + 1);
                MACDDataItem PreObj  = Arr.ElementAt <MACDDataItem>(i - 1);
                if (CurrObj.MACD > 0 && PreObj.MACD <= 0) //MACD上穿0线
                {
                    CurrObj.Color       = MACDColor.Red;
                    CurrObj.IsAreaStart = true;
                    PreObj.Color        = MACDColor.Green;
                    PreObj.IsAreaEnd    = true;
                    continue;
                }
                if (CurrObj.MACD < 0 && PreObj.MACD >= 0) //MACD下穿0线
                {
                    CurrObj.Color       = MACDColor.Green;
                    CurrObj.IsAreaStart = true;
                    PreObj.Color        = MACDColor.Red;
                    PreObj.IsAreaEnd    = true;
                    continue;
                }
            }
            var KeyArr = from n in Arr
                         where n.Color != MACDColor.None
                         select n; //上下穿切换点
            int KeyCnt   = KeyArr.Count <MACDDataItem>();
            var startArr = from Item in KeyArr
                           let begDate = Item.Date
                                         let endDate = 0
                                                       where Item.IsAreaStart = false
                                                                                select new { Item, begDate };
            var endArr = from n in startArr
                         let Item = n.Item
                                    let begDate = n.begDate
                                                  let endDate = n.Item.Date
                                                                where n.Item.IsAreaEnd = false
                                                                                         select new { Item, begDate, endDate };
            int  Keyindex = -1;
            bool Skip     = false;

            foreach (var key in endArr)
            {
                Keyindex++;
                if (Skip)
                {
                    Skip = false;
                    continue;
                }
                var subAreaArr = from n in Arr
                                 where n.Date >= key.begDate
                                 where n.Date <= key.endDate
                                 select n;
                MACDAreaClass subObj = new MACDAreaClass(new MACDTable(subAreaArr as List <MACDDataItem>));
                //subObj.UpDir = subAreaArr.First<MACDDataItem>().Color == MACDColor.Red;
                if (subObj.Len < 3)
                {
                    if (Keyindex > 0 && Keyindex < KeyCnt - 1)
                    {
                        var UnionArea = from n in Arr
                                        where n.Date >= ret[ret.Count - 1].BegT && n.Date <= key.endDate
                                        select n;
                        MACDAreaClass unionAreaObj = new MACDAreaClass(new MACDTable(UnionArea as List <MACDDataItem>));
                        ret[ret.Count - 1] = unionAreaObj;
                        Skip = true;
                        continue;
                    }
                }
                ret.Add(subObj);
            }
            List <MACDAreaClass> lastRes = new List <MACDAreaClass>();

            if (ret.Count > 0)
            {
                lastRes.Add(ret[0]);
            }
            int cnt = 0;

            for (int i = 1; i < ret.Count; i++)
            {
                if (ret[i].UpDir == ret[cnt].UpDir)//方向相同,合并
                {
                    lastRes[lastRes.Count] = this.MergeArea(lastRes[lastRes.Count - 1], ret[i]);
                }
                else
                {
                    cnt++;
                    lastRes.Add(ret[i]);
                }
            }
            return(lastRes);
        }