/// <summary>
        /// Get stock data of certain data cycle
        /// </summary>
        /// <param name="dc">The data cycle</param>
        /// <returns></returns>
        public Hashtable GetCycleData(DataCycle dc)
        {
            if (dc.CycleBase == DataCycleBase.DAY && dc.Repeat == 1 && !Adjusted)
            {
                return(htData);
            }
            else
            {
                Hashtable htCycle = (Hashtable)htAllCycle[dc.ToString()];
                if (htCycle == null)
                {
                    Hashtable ht;
                    if (DataCycle.CycleBase < DataCycleBase.DAY)
                    {
                        ht = htRealtime;
                    }
                    else
                    {
                        ht = htData;
                    }
                    if (ht == null)
                    {
                        return(ht);
                    }

                    double[] ODATE = (double[])ht["DATE"];
                    if (ODATE == null)
                    {
                        return(null);
                    }

                    int[] NEWDATE = new int[ODATE.Length];

                    int Last = int.MinValue;
                    int j    = -1;
                    int Num;
                    for (int i = 0; i < ODATE.Length; i++)
                    {
                        Num = DataCycle.GetSequence(ODATE[i]);
                        if (Num > Last)
                        {
                            j++;
                        }
                        NEWDATE[i] = j;
                        Last       = Num;
                    }

                    if (ht["CLOSE"] != null)
                    {
                        if (ht["OPEN"] == null)
                        {
                            ht["OPEN"] = ht["CLOSE"];
                        }
                        if (ht["HIGH"] == null)
                        {
                            ht["HIGH"] = ht["CLOSE"];
                        }
                        if (ht["LOW"] == null)
                        {
                            ht["LOW"] = ht["CLOSE"];
                        }
                    }

                    htCycle = new Hashtable();
                    foreach (string s in ht.Keys)
                    {
                        htCycle[s] = new double[j + 1];
                    }

                    bool     NeedAdjust = (Adjusted && ht["ADJCLOSE"] != null && ht["CLOSE"] != null);
                    double[] CLOSE      = (double[])ht["CLOSE"];
                    double[] ADJCLOSE   = (double[])ht["ADJCLOSE"];

                    foreach (string s in ht.Keys)
                    {
                        bool           DoAdjust = NeedAdjust;
                        MergeCycleType mct;
                        try
                        {
                            mct = (MergeCycleType)Enum.Parse(typeof(MergeCycleType), s);
                        }
                        catch
                        {
                            DoAdjust = false;
                            if (s == "VOLUME" || s == "AMOUNT")
                            {
                                mct = MergeCycleType.SUM;
                            }
                            else
                            {
                                mct = MergeCycleType.CLOSE;
                            }
                        }
                        MergeCycle(ODATE, NEWDATE, CLOSE, ADJCLOSE, (double[])ht[s], (double[])htCycle[s], mct, DoAdjust);
                    }
                    htAllCycle[dc.ToString()] = htCycle;
                }
                return(htCycle);
            }
        }
Exemple #2
0
        /// <summary>
        /// Get stock data of certain data cycle
        /// </summary>
        /// <param name="dc">The data cycle</param>
        /// <returns></returns>
        public Hashtable GetCycleData(DataCycle dc)
        {
            if (dc.CycleBase == DataCycleBase.DAY && dc.Repeat == 1 && !Adjusted)
            {
                return(htData);
            }
            else
            {
                dc.WeekAdjust = weekAdjust;
                Hashtable htCycle = (Hashtable)htAllCycle[dc.ToString()];
                if (htCycle == null)
                {
                    if (htData == null)
                    {
                        return(htData);
                    }

                    Hashtable ht = htData;
                    if (intradayInfo != null)
                    {
                        ht = DoExpandMinute(ht);
                    }

                    if (futureBars != 0)
                    {
                        ht = ExpandFutureBars(ht);
                    }

                    if (ht["CLOSE"] != null)
                    {
                        if (ht["OPEN"] == null)
                        {
                            ht["OPEN"] = ht["CLOSE"];
                        }
                        if (ht["HIGH"] == null)
                        {
                            ht["HIGH"] = ht["CLOSE"];
                        }
                        if (ht["LOW"] == null)
                        {
                            ht["LOW"] = ht["CLOSE"];
                        }
                    }

                    double[] ODATE = (double[])ht["DATE"];
                    if (ODATE == null)
                    {
                        return(null);
                    }

                    int[] NEWDATE = new int[ODATE.Length];

                    int Last = int.MinValue;
                    int j    = -1;
                    int Num;
                    for (int i = 0; i < ODATE.Length; i++)
                    {
                        if (DataCycle.CycleBase == DataCycleBase.TICK)
                        {
                            Num = i / DataCycle.Repeat;
                        }
                        else
                        {
                            Num = DataCycle.GetSequence(ODATE[i]);
                        }
                        if (Num > Last)
                        {
                            j++;
                        }
                        NEWDATE[i] = j;
                        Last       = Num;
                    }

                    htCycle = new Hashtable();
                    foreach (string s in ht.Keys)
                    {
                        htCycle[s] = new double[j + 1];
                    }

                    bool     NeedAdjust = (Adjusted && ht["ADJCLOSE"] != null && ht["CLOSE"] != null);
                    double[] CLOSE      = (double[])ht["CLOSE"];
                    double[] ADJCLOSE   = (double[])ht["ADJCLOSE"];

                    foreach (string s in ht.Keys)
                    {
                        bool           DoAdjust = NeedAdjust;
                        MergeCycleType mct;
                        DoAdjust = false;
                        if (htGroupping[s] != null)
                        {
                            mct = (MergeCycleType)htGroupping[s];
                        }
                        else if (s == "DATE")
                        {
                            mct = dateMergeType;                            // MergeCycleType.OPEN;
                        }
                        else if (s == "VOLUME" || s == "AMOUNT")
                        {
                            mct = MergeCycleType.SUM;
                        }
                        else
                        {
                            try
                            {
                                mct      = (MergeCycleType)Enum.Parse(typeof(MergeCycleType), s);
                                DoAdjust = true;
                            }
                            catch
                            {
                                mct = MergeCycleType.CLOSE;
                            }
                        }
                        MergeCycle(ODATE, NEWDATE, CLOSE, ADJCLOSE, (double[])ht[s], (double[])htCycle[s], mct, DoAdjust);
                    }
                    htAllCycle[dc.ToString()] = htCycle;
                }
                return(htCycle);
            }
        }