public DateTime GetPriceEndDate() { ActiveMarket.Calendar calendar = new ActiveMarket.Calendar(); return(calendar.Date(Price.End())); }
public DateTime GetPriceBeginDate() { ActiveMarket.Calendar calendar = new ActiveMarket.Calendar(); return(calendar.Date(Price.Begin())); }
/// <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); } } } }
/// <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); }