Exemple #1
0
        /// <summary>
        /// 日付選択
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CalendarDialogStripButton5_Click(object sender, EventArgs e)
        {
            ActiveMarket.Calendar calendar = new ActiveMarket.Calendar();
            DateTime _date;
            int      _pos;

            if (MyMeigara != null)
            {
                CalendarDialog _CalendarDialog = new CalendarDialog(
                    MyMeigara.GetPriceBeginDate(),
                    MyMeigara.GetPriceEndDate(),
                    MyMeigara.PlotEndDate)
                {
                    StartPosition = FormStartPosition.Manual,
                    Left          = this.Left + 340,
                    Top           = this.Top + 80,
                    Owner         = this
                };
                _CalendarDialog.ShowDialog(this);

                _date = _CalendarDialog.SelectedDate;

                if (_date != DateTime.Parse("0001/01/01"))
                {
                    try {
                        _pos = calendar.DatePosition(_date, -1);
                    } catch {
                        _pos = calendar.DatePosition(_date, 1);
                    }

                    MakeTableAndDraw(_pos);
                }

                _CalendarDialog.Dispose();
            }
        }
Exemple #2
0
        /// <summary>
        /// 株価テーブル作成
        /// </summary>
        /// <param name="plotEnd"></param>
        /// <param name="plotWide"></param>
        public void MakeTable(int plotEnd, int plotWide, ChartScales chartScale, AveSteps aveStep)
        {
            // 株価テーブル作成
            var calendar   = new ActiveMarket.Calendar();
            var _kabukaRow = new KabukaRow();
            int?_datePos   = plotEnd;

            this.PlotWide   = plotWide;
            this.ChartScale = chartScale;
            this.AveStep    = aveStep;
            OwarineList     = new List <Owarine>();

            PriceTable.Clear();

            var cnt = 0;

            while (cnt < this.PlotWide)
            {
                if (_datePos.Value < Price.Begin())
                {
                    break;
                }
                _kabukaRow = GetOneRow(_datePos.Value);
                if (_kabukaRow != null)
                {
                    DataRow row = PriceTable.NewRow();
                    row["StartPos"]  = _kabukaRow.StartPos;
                    row["EndPos"]    = _kabukaRow.EndPos;
                    row["StartDate"] = _kabukaRow.StartDate;
                    row["EndDate"]   = _kabukaRow.EndDate;
                    row["High"]      = _kabukaRow.High;
                    row["Low"]       = _kabukaRow.Low;
                    row["Open"]      = _kabukaRow.Open;
                    row["Close"]     = _kabukaRow.Close;
                    row["Heikin1"]   = 0;
                    row["Heikin2"]   = 0;
                    row["Heikin3"]   = 0;
                    row["Heikin4"]   = 0;
                    row["Heikin5"]   = 0;
                    PriceTable.Rows.Add(row);

                    OwarineList.Add(new Owarine(_kabukaRow.EndPos, _kabukaRow.Close));

                    cnt++;
                }
                _datePos = NextDatePosition(_datePos.Value, Directions.Befor);
                if (!_datePos.HasValue)
                {
                    break;
                }
            }

            // 終値リストの作成(PlotStart以前300件)
            var MaxCount = 300;

            _datePos = OwarineList.Select(n => n.DatePos).Min();
            cnt      = 0;
            for (var i = 0; i < MaxCount; i++)
            {
                _datePos = NextDatePosition(_datePos.Value, Directions.Befor);
                if (!_datePos.HasValue)
                {
                    break;
                }
                OwarineList.Add(new Owarine(_datePos.Value, Price.Close(_datePos.Value)));
            }
            for (var i = 0; i < PtCount; i++)
            {
                for (var j = 0; j < 5; j++)
                {
                    SetHeikin(i, j);
                }
            }
        }
Exemple #3
0
 public DateTime GetPriceEndDate()
 {
     ActiveMarket.Calendar calendar = new ActiveMarket.Calendar();
     return(calendar.Date(Price.End()));
 }
Exemple #4
0
        /// <summary>
        /// 次の位置を取得
        /// </summary>
        /// <param name="datePos"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        private int?NextDatePosition(int datePos, Directions direction)
        {
            var calendar = new ActiveMarket.Calendar();

            DateTime _date = calendar.Date(datePos);
            DateTime _dateLimit;
            int      _datePos;

            if (direction == Directions.Befor)
            {
                // 過去へ
                switch (ChartScale)
                {
                // 週足
                case ChartScales.Weekly:
                    // 前の週の金曜日から遡った開場日
                    _date = _date.AddDays(-1 * ((int)_date.DayOfWeek + 2));
                    if (_date < calendar.Date(Price.Begin()))
                    {
                        return(null);
                    }
                    _datePos = calendar.DatePosition(_date, -1);
                    while (Price.IsClosed(_datePos) != 0)
                    {
                        _datePos--;
                        if (Price.Begin() > _datePos & _datePos > Price.End())
                        {
                            return(null);
                        }
                    }
                    return(_datePos);

                // 月足
                case ChartScales.Monthly:
                    // 前の月の月末から遡った開場日
                    _date = DateTime.Parse(_date.AddMonths(-1).Year.ToString() + "/" +
                                           _date.AddMonths(-1).Month.ToString() + "/" +
                                           DateTime.DaysInMonth(_date.AddMonths(-1).Year, _date.AddMonths(-1).Month).ToString());
                    if (_date < calendar.Date(Price.Begin()))
                    {
                        return(null);
                    }
                    _datePos = calendar.DatePosition(_date, -1);
                    while (Price.IsClosed(_datePos) != 0)
                    {
                        _datePos--;
                        if (Price.Begin() > _datePos | _datePos > Price.End())
                        {
                            return(null);
                        }
                    }
                    return(_datePos);

                // 日足
                default:
                    // 日足の1つ前の開場日
                    do
                    {
                        datePos--;
                        if (datePos < Price.Begin())
                        {
                            return(null);
                        }
                    } while (Price.IsClosed(datePos) != 0);
                    if (Price.Begin() <= datePos & datePos <= Price.End())
                    {
                        return(datePos);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                // 未来へ
                switch (ChartScale)
                {
                // 週足
                case ChartScales.Weekly:
                    // 翌週の月
                    _dateLimit = _date.AddDays(8 - (int)_date.DayOfWeek);
                    if (_dateLimit > calendar.Date(Price.End()))
                    {
                        return(null);
                    }
                    //翌週の金
                    _date    = _date.AddDays(12 - (int)_date.DayOfWeek);
                    _datePos = (_date > calendar.Date(Price.End())) ? Price.End() : calendar.DatePosition(_date, -1);
                    while (Price.IsClosed(_datePos) != 0)
                    {
                        _datePos--;
                        if (Price.Begin() > _datePos & _datePos > Price.End())
                        {
                            return(null);
                        }
                    }
                    if (calendar.Date(_datePos) >= _dateLimit)
                    {
                        return(_datePos);
                    }
                    else
                    {
                        return(NextDatePosition(_datePos, Directions.After));
                    }

                // 月足
                case ChartScales.Monthly:
                    // 次の月の日末日から遡った開場日
                    _dateLimit = DateTime.Parse(_date.AddMonths(1).Year.ToString() + "/" +
                                                _date.AddMonths(1).Month.ToString() + "/1");
                    if (_dateLimit > calendar.Date(Price.End()))
                    {
                        return(null);
                    }
                    _date = DateTime.Parse(_date.AddMonths(1).Year.ToString() + "/" +
                                           _date.AddMonths(1).Month.ToString() + "/" +
                                           DateTime.DaysInMonth(_date.AddMonths(1).Year, _date.AddMonths(1).Month));
                    _datePos = (_date > calendar.Date(Price.End())) ? Price.End() : calendar.DatePosition(_date, -1);

                    while (Price.IsClosed(_datePos) != 0)
                    {
                        _datePos--;
                        if (Price.Begin() > _datePos & _datePos > Price.End())
                        {
                            return(null);
                        }
                    }
                    if (calendar.Date(_datePos) >= _dateLimit)
                    {
                        return(_datePos);
                    }
                    else
                    {
                        return(NextDatePosition(_datePos, Directions.After));
                    }

                // 日足
                default:
                    do
                    {
                        datePos++;
                        if (datePos > Price.End())
                        {
                            break;
                        }
                    } while (Price.IsClosed(datePos) != 0);
                    if (Price.Begin() <= datePos & datePos <= Price.End())
                    {
                        return(datePos);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Exemple #5
0
 public DateTime GetPriceBeginDate()
 {
     ActiveMarket.Calendar calendar = new ActiveMarket.Calendar();
     return(calendar.Date(Price.Begin()));
 }
Exemple #6
0
        /// <summary>
        /// 1単位分のデータを作成
        /// </summary>
        /// <param name="datePos"></param>
        /// <returns>KabukaRowを返す。1日も開場日がなかったら、null</returns>
        private KabukaRow GetOneRow(int datePos)
        {
            var      calendar   = new ActiveMarket.Calendar();
            var      _kabukaRow = new KabukaRow();
            var      _date      = calendar.Date(datePos);
            DateTime _startDate;
            DateTime _endDate;
            int      _startPos;
            int      _endPos;

            // 開始・終了位置決め
            // 週足の場合は、月曜から金曜
            switch (ChartScale)
            {
            case ChartScales.Weekly:
                // 該当日の週の月曜日
                _startDate = _date.AddDays((int)_date.DayOfWeek * -1 + 1);
                if (_startDate < calendar.Date(Price.Begin()))
                {
                    _startDate = calendar.Date(Price.Begin());
                }
                if (_startDate > calendar.Date(Price.End()))
                {
                    return(null);
                }
                // 該当日の週の金曜日
                _endDate = _startDate.AddDays(4);
                if (_endDate > calendar.Date(Price.End()))
                {
                    _endDate = calendar.Date(Price.End());
                }
                if (_endDate < calendar.Date(Price.Begin()))
                {
                    return(null);
                }
                break;

            case ChartScales.Monthly:
                // 月の1日
                _startDate =
                    DateTime.Parse(_date.Year.ToString() + "/" + _date.Month.ToString() + "/1");
                if (_startDate < calendar.Date(Price.Begin()))
                {
                    _startDate = calendar.Date(Price.Begin());
                }
                if (_startDate > calendar.Date(Price.End()))
                {
                    return(null);
                }
                // 月の末日 (翌月の1日前)
                _endDate =
                    DateTime.Parse(_date.Year.ToString() + "/" + _date.Month.ToString() + "/" +
                                   DateTime.DaysInMonth(_date.Year, _date.Month).ToString());
                if (_endDate > calendar.Date(Price.End()))
                {
                    _endDate = calendar.Date(Price.End());
                }
                if (_endDate < calendar.Date(Price.Begin()))
                {
                    return(null);
                }
                break;

            // デフォルトは日足
            default:
                _startDate = _date;
                _endDate   = _date;
                break;
            }

            // 開場日の開始、終了の位置と高値、安値を決める
            _startPos = calendar.DatePosition(_startDate, 1);
            _endPos   = calendar.DatePosition(_endDate, -1);

            _kabukaRow.EndPos = 0;

            for (var i = _startPos; i <= _endPos; i++)
            {
                if (Price.IsClosed(i) == 0)
                {
                    if (_kabukaRow.EndPos == 0)
                    {
                        _kabukaRow.StartPos  = i;
                        _kabukaRow.StartDate = calendar.Date(i);
                        _kabukaRow.EndPos    = i;
                        _kabukaRow.Open      = Price.Open(i);
                        _kabukaRow.High      = Price.High(i);
                        _kabukaRow.Low       = Price.Low(i);
                    }
                    else
                    {
                        _kabukaRow.EndPos = i;
                        _kabukaRow.High   = Math.Max(_kabukaRow.High, Price.High(i));
                        _kabukaRow.Low    = Math.Min(_kabukaRow.Low, Price.Low(i));
                    }
                }
            }

            if (_kabukaRow.EndPos == 0)
            {
                // 一日も開場日がなかった場合,nullが返される
                return(null);
            }

            _kabukaRow.EndDate = calendar.Date(_kabukaRow.EndPos);
            _kabukaRow.Close   = Price.Close(_kabukaRow.EndPos);

            return(_kabukaRow);
        }
Exemple #7
0
        /// <summary>
        /// 株価テーブルを過去、未来へずらす
        /// </summary>
        /// <param name="shift"></param>
        public bool ShiftKabukaTable(int shift)
        {
            var       calendar   = new ActiveMarket.Calendar();
            KabukaRow _kabukaRow = new KabukaRow();
            int?      _datepos;

            if (shift < 0)
            {
                // 過去日付へ1つずらす
                _datepos = NextDatePosition(this.PlotStart.Value, Directions.Befor);
                if (!_datepos.HasValue)
                {
                    return(false);
                }

                var cnt = 0;
                while (cnt < Math.Abs(shift))
                {
                    _kabukaRow = GetOneRow(_datepos.Value);
                    if (_kabukaRow != null)
                    {
                        DataRow row = PriceTable.NewRow();
                        row["StartPos"]  = _kabukaRow.StartPos;
                        row["EndPos"]    = _kabukaRow.EndPos;
                        row["StartDate"] = _kabukaRow.StartDate;
                        row["EndDate"]   = _kabukaRow.EndDate;
                        row["High"]      = _kabukaRow.High;
                        row["Low"]       = _kabukaRow.Low;
                        row["Open"]      = _kabukaRow.Open;
                        row["Close"]     = _kabukaRow.Close;
                        row["Heikin1"]   = 0;
                        row["Heikin2"]   = 0;
                        row["Heikin3"]   = 0;
                        row["Heikin4"]   = 0;
                        row["Heikin5"]   = 0;
                        PriceTable.Rows.RemoveAt(0);
                        PriceTable.Rows.Add(row);

                        // 終値リストを過去日付に1つずらす
                        OwarineList.RemoveAt(0);
                        var _OwarineDatePos = NextDatePosition(
                            ((Owarine)OwarineList[OwarineList.Count - 1]).DatePos, Directions.Befor);
                        if (_OwarineDatePos.HasValue)
                        {
                            OwarineList.Add(new Owarine(_OwarineDatePos.Value, Price.Close(_OwarineDatePos.Value)));
                        }
                        for (var j = 0; j < 5; j++)
                        {
                            SetHeikin(PtCount - 1, j);
                        }

                        cnt++;
                    }
                    _datepos = NextDatePosition(_datepos.Value, Directions.Befor);
                    if (!_datepos.HasValue)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                // 未来日付に1つずらす
                _datepos = NextDatePosition(this.PlotEnd, Directions.After);
                if (!_datepos.HasValue)
                {
                    return(false);
                }

                var cnt = 0;
                while (cnt < Math.Abs(shift))
                {
                    _kabukaRow = GetOneRow(_datepos.Value);
                    if (_kabukaRow != null)
                    {
                        DataRow row = PriceTable.NewRow();
                        row["StartPos"]  = _kabukaRow.StartPos;
                        row["EndPos"]    = _kabukaRow.EndPos;
                        row["StartDate"] = _kabukaRow.StartDate;
                        row["EndDate"]   = _kabukaRow.EndDate;
                        row["High"]      = _kabukaRow.High;
                        row["Low"]       = _kabukaRow.Low;
                        row["Open"]      = _kabukaRow.Open;
                        row["Close"]     = _kabukaRow.Close;
                        row["Heikin1"]   = 0;
                        row["Heikin2"]   = 0;
                        row["Heikin3"]   = 0;
                        row["Heikin4"]   = 0;
                        row["Heikin5"]   = 0;
                        PriceTable.Rows.RemoveAt(PtCount - 1);
                        PriceTable.Rows.InsertAt(row, 0);

                        // 終値を未来日付にずらす
                        OwarineList.RemoveAt(OwarineList.Count - 1);
                        OwarineList.Insert(0, new Owarine(_kabukaRow.EndPos, _kabukaRow.Close));

                        for (var j = 0; j < 5; j++)
                        {
                            SetHeikin(0, j);
                        }


                        cnt++;
                    }
                    _datepos = NextDatePosition(_datepos.Value, Directions.After);
                    if (!_datepos.HasValue)
                    {
                        return(true);
                    }
                }
            }
            return(true);
        }