Пример #1
0
        void Init()
        {
            if (this.Data == null)
            {
                return;
            }
            Len  = Data.Count;
            BegT = Data[0].Date;
            MACDDataItem LastItem = Data[Len - 1 < 0?0:(Len - 1)];

            EndT  = LastItem.Date;
            UpDir = false;
            for (int i = 0; i < Len; i++)//初始化该区初始方向
            {
                decimal vMacd = Data[Len - i].MACD;
                if (vMacd == 0)
                {
                    continue;
                }
                UpDir = vMacd > 0;
                break;
            }
            Summ         = Data.MACDs.Sum();
            MaxinMACD    = UpDir ? Data.MACDs.Max() : Data.MACDs.Min();
            MaxinPrice   = UpDir ? Data.Highs.Max() : Data.Lows.Min();
            MaxinClose   = UpDir ? Data.Closes.Max() : Data.Closes.Min();
            MaxinOCPrice = UpDir ? Math.Max(Data.Opens.Max(), Data.Closes.Max()) : Math.Min(Data.Opens.Min(), Data.Closes.Min());
        }
Пример #2
0
 public new MACDDataItem this[int rowid]
 {
     get
     {
         MACDDataItem item = new MACDDataItem(this.Table.Rows[rowid]);
         item.RowId = rowid;
         return(item);
     }
 }
Пример #3
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);
        }