private bool ForwardToday_MainKLineData() { ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); double nextTickTime = nextTickBar.Time; IKLineData_RealTime klineData = forwardData.GetMainKLineData(); if (dic_KLinePeriod_IsEnd[forwardData.MainKLinePeriod]) { dic_KLinePeriod_IsEnd[forwardData.MainKLinePeriod] = false; } else { int nextKLineIndex = FindNextKLineIndex(klineData, nextTickTime); } //if (nextKLineIndex == klineData.BarPos) //{ // dic_KLinePeriod_IsEnd[period] = false; // klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); //} //else //{ // dic_KLinePeriod_IsEnd[period] = true; // klineData.ChangeCurrentBar(GetKLineBar(nextTickBar), nextKLineIndex); //} return(false); }
private static int IndexOfTime(IKLineData_RealTime klineData, KLinePeriod klinePeriod, double time, int date) { if (klinePeriod.PeriodType == KLineTimeType.DAY) { return(TimeIndeierUtils.IndexOfTime_KLine(klineData.GetKLineData_Original(), date)); } else { int index = TimeIndeierUtils.IndexOfTime_KLine(klineData, time); if (klineData.IsTradingTimeEnd(index)) { double endTime = klineData.GetEndTime(index); if (index >= klineData.Length - 1) { return(index); } double nextStartTime = klineData.Arr_Time[index + 1]; double middleTime = (endTime + nextStartTime) / 2; if (time < middleTime) { return(index); } return(index + 1); } return(index); } }
private void ForwardToday_KLineData(IKLineData_RealTime klineData, KLinePeriod period) { ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); //日线,肯定不会跳到下一个bar if (period.Equals(KLinePeriod.KLinePeriod_1Day)) { dic_KLinePeriod_IsEnd[period] = false; klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); return; } double nextTickTime = nextTickBar.Time; int nextKLineIndex = FindNextKLineIndex(klineData, nextTickTime); if (nextKLineIndex == klineData.BarPos) { dic_KLinePeriod_IsEnd[period] = false; klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); } else { dic_KLinePeriod_IsEnd[period] = true; klineData.ChangeCurrentBar(GetKLineBar(nextTickBar), nextKLineIndex); } }
private int FindNextKLineIndex(IKLineData_RealTime klineData, double time) { int prevBarPos = klineData.BarPos; int barPos = prevBarPos; if (barPos == klineData.Length - 1) { return(barPos); } while (barPos < klineData.Length) { double currentEndTime = GetEndTime(klineData, barPos); if (currentEndTime > time) { return(barPos); } barPos++; } //if (barPos >= klineData.Length) return(barPos - 1); //if (barPos != prevBarPos && klineData.Arr_Time[barPos] != time) // barPos--; //return barPos < 0 ? 0 : barPos; }
private void InitData() { int currentTradingDay = tradingDays[0]; this.currentTickData = dataPackage.GetTickData(currentTradingDay); foreach (KLinePeriod period in dic_Period_KLineData.Keys) { IKLineData_RealTime klineData = dic_Period_KLineData[period]; klineData.ChangeCurrentBar(GetKLineBar(currentTickData)); if (period == forwardPeriod.KlineForwardPeriod) { mainKlineData = klineData; } } //初始化分时线 //int lastTradingDay = dataReader.TradingDayReader.GetPrevTradingDay(currentTradingDay); //IKLineData lastDayklineData = dataReader.KLineDataReader.GetData(code, lastTradingDay, lastTradingDay, KLinePeriod.KLinePeriod_1Day); //if (lastDayklineData.Length == 0) // lastEndPrice = currentTickData.Arr_Price[0]; //else // lastEndPrice = lastDayklineData.End; this.lastEndPrice = dataPackage.GetLastEndPrice(currentTradingDay); if (useTimeLineData) { ITimeLineData timeLineData = dataPackage.GetTimeLineData(currentTradingDay); if (timeLineData != null) { this.currentTimeLineData = new TimeLineData_RealTime(timeLineData); this.currentTimeLineData.ChangeCurrentBar(GetTimeLineBar(currentTickData, lastEndPrice)); } } }
private void ForwardToday() { int prevMainBarPos = mainKlineData.BarPos; foreach (KLinePeriod period in dic_Period_KLineData.Keys) { IKLineData_RealTime klineData = dic_Period_KLineData[period]; ForwardToday_KLineData(klineData, period); } if (useTimeLineData) { ForwardToday_TimeLineData(currentTimeLineData); } currentTickData.BarPos++; if (currentTickData.IsTradingTimeEnd(currentTickData.BarPos)) { this.isTradingTimeEnd = true; } else { this.isTradingTimeEnd = false; } if (currentTickData.IsTradingTimeStart(currentTickData.BarPos)) { this.isTradingTimeStart = true; } else { this.isTradingTimeStart = false; } }
private void IndexKLineData(int mainIndex, double time) { foreach (KLinePeriod period in data.ReferedKLinePeriods) { if (period.Equals(data.MainKLinePeriod)) { continue; } if (period.PeriodType >= KLineTimeType.DAY) { if (period.Period == 1) { IKLineData_Extend mainKlineData = data.GetMainKLineData(); //if (mainKlineData.IsDayEnd(mainIndex)) if (mainKlineData.IsDayStart(mainIndex)) { int currentDayIndex = GetCurrentIndex(period); AddOnBarData(mainIndex - 1, period, currentDayIndex); dic_Period_CurrentIndex[period] = currentDayIndex + 1; } } continue; } IKLineData_RealTime klineData = data.GetKLineData(period); int barIndex = FindBarIndex(klineData, time, GetCurrentIndex(period)); if (barIndex >= klineData.BarPos) { int endBarMainKLineIndex = mainIndex - 1; AddOnBarData(endBarMainKLineIndex, period, barIndex); dic_Period_CurrentIndex[period] = barIndex; } } }
private static void ForwardNextDay_KLine(DataForForward_Code forwardData, IKLineData_RealTime klineData, KLinePeriod period) { ITickBar tickBar = forwardData.CurrentTickData.GetCurrentBar(); int nextbarPos = klineData.BarPos + 1; klineData.ChangeCurrentBar(KLineUtils.GetKLineBar(tickBar), nextbarPos); }
private void ForwardToday() { int prevMainBarPos = mainKlineData.BarPos; foreach (KLinePeriod period in forwardData.ReferedKLinePeriods) { IKLineData_RealTime klineData = forwardData.GetKLineData(period); ForwardToday_KLineData(klineData, period); } ForwardToday_TimeLineData(forwardData.CurrentTimeLineData); ITickData_Extend currentTickData = forwardData.CurrentTickData; currentTickData.BarPos++; if (currentTickData.IsTradingTimeEnd(currentTickData.BarPos)) { this.isTradingTimeEnd = true; } else { this.isTradingTimeEnd = false; } if (currentTickData.IsTradingTimeStart(currentTickData.BarPos)) { this.isTradingTimeStart = true; } else { this.isTradingTimeStart = false; } }
public DataForForward_Code(IDataPackage_Code dataPackage, ForwardReferedPeriods referedPeriods) { this.dataPackage = dataPackage; this.referedPeriods = referedPeriods; this.dic_Period_KLineData = dataPackage.CreateKLineData_RealTimes(referedPeriods.UsedKLinePeriods); this.mainKLinePeriod = referedPeriods.GetMinPeriod(); this.mainKLineData = this.dic_Period_KLineData[mainKLinePeriod]; this.cache_TradingDay = new CacheUtils_TradingDay(dataPackage.GetTradingDays()); }
public static void ForwardNextDay(DataForForward_Code forwardData, int tradingDay) { forwardData.TradingDay = tradingDay; foreach (KLinePeriod period in forwardData.ReferedKLinePeriods) { IKLineData_RealTime klineData = forwardData.GetKLineData(period); ForwardNextDay_KLine(forwardData, klineData, period); } ForwardNextDay_TimeLine(forwardData); }
private double GetEndTime(IKLineData_RealTime klineData, int barPos) { double endTime = klineData.GetEndTime(barPos); if (barPos < klineData.Length - 1 && klineData.IsTradingTimeEnd(barPos)) { endTime = (endTime + klineData.Arr_Time[barPos + 1]) / 2; } return(endTime); }
private void ForwardKLineData(IKLineData_RealTime klineData) { IKLineBar nextMainBar = mainKLineData.GetBar(mainKLineData.BarPos + 1); int currentBarPos = klineData.BarPos; int nextBarPos = currentBarPos + 1; if (nextBarPos >= klineData.Length) { ForwardBar_CurrentPeriod(klineData, nextMainBar); } else { double nextTime = klineData.Arr_Time[nextBarPos]; double nextMainTime = mainKLineData.Arr_Time[mainKLineData.BarPos + 1]; if (nextMainTime >= nextTime) { ForwardBar_NextPeriod(klineData, nextMainBar); } else { ForwardBar_CurrentPeriod(klineData, nextMainBar); } /* * 20171021 ww * 处理回测时非主K线要onbar时时间不对,如下5分钟线 * * 1分钟:20170531.21,3102,3106,3095,3101,135598,0,3992164 * 1分钟:20170531.2101,3102,3103,3096,3096,58762,0,4008012 * 1分钟:20170531.2102,3095,3102,3094,3100,35524,0,4013054 * 1分钟:20170531.2103,3101,3101,3093,3094,35276,0,4023900 * 1分钟:20170531.2104,3094,3102,3094,3101,34660,0,4029194 * 5分钟:20170531.2104,3102,3106,3093,3101,299820,0,402919 * * 正确5分钟线 * 5分钟:20170531.21,3102,3106,3093,3101,299820,0,4029194 */ if (klineData.Period.Equals(KLinePeriod.KLinePeriod_1Day)) { if (mainKLineData.IsDayEnd(mainKLineData.BarPos + 1)) { klineData.ResetCurrentBar(); } } else if (mainKLineData.BarPos < mainKLineData.Length - 2) { double nextMainTime2 = mainKLineData.Arr_Time[mainKLineData.BarPos + 2]; if (nextMainTime2 >= nextTime) { klineData.ResetCurrentBar(); return; } } } }
internal void SetKLineData(KLinePeriod period, IKLineData_RealTime klineData) { if (dic_Period_KLineData.ContainsKey(period)) { dic_Period_KLineData[period] = klineData; } else { dic_Period_KLineData.Add(period, klineData); } }
public static DataForNavigate_Code Create(DataForForward_Code dataForForward) { DataForNavigate_Code dataForNav = new DataForNavigate_Code(dataForForward.DataPackage, dataForForward.Time); foreach (KLinePeriod klinePeriod in dataForForward.ReferedKLinePeriods) { IKLineData_RealTime klineData = dataForForward.GetKLineData(klinePeriod); dataForNav.dic_Period_KLineData.Add(klinePeriod, klineData); } return(dataForNav); }
public DataForward_Code_KLine(IDataCenter dataCenter, IDataPackage_Code dataPackage, ForwardReferedPeriods referedPeriods, ForwardPeriod forwardPeriod) { this.dataCenter = dataCenter; this.navigateData = new DataForForward_Code(dataPackage, referedPeriods); this.navigateData.TradingDay = navigateData.StartDate; this.forwardPeriod = forwardPeriod; this.mainKLineData = this.navigateData.GetKLineData(forwardPeriod.KlineForwardPeriod); this.listenedCodes[0] = mainKLineData.Code; this.onBarArgument = new ForwardOnBarArgument(this.barFinishedInfos, this); InitKLine(); }
public DataNavigate_Code2(IDataPackage_Code dataPackage, DataForForward_Code forwarddata) { this.dataPackage = dataPackage; foreach (KLinePeriod klinePeriod in forwarddata.ReferedKLinePeriods) { IKLineData_RealTime klineData = forwarddata.GetKLineData(klinePeriod); //this.dicNavigateKLine.Add(klinePeriod,new DataNavigate_Code_KLine()) } //dicNavigateKLine //this.NavigateTo(time); }
private static void ForwardNextDay_KLine(DataForForward_Code forwardData, IKLineData_RealTime klineData, KLinePeriod period) { ITickBar tickBar = forwardData.CurrentTickData.GetCurrentBar(); int nextbarPos = klineData.BarPos + 1; //TODO 这样nextday算法还是不够准确 while (!klineData.IsDayStart(nextbarPos)) { nextbarPos = klineData.BarPos + 1; } klineData.ChangeCurrentBar(GetKLineBar(tickBar), nextbarPos); }
private bool IsCurrentTradingTimeEnd() { if (IsPeriodEnd(dataForForward_Code.MainKLinePeriod)) { IKLineData_RealTime mainKlineData = dataForForward_Code.MainKLine; if (mainKlineData.IsTradingPeriodEnd(mainKlineData.BarPos)) { return(true); } } return(false); }
private void Init() { this.onBarArgument = new ForwardOnBarArgument(barFinishedInfos, this); foreach (KLinePeriod period in forwardData.ReferedKLinePeriods) { IKLineData_RealTime klineData = forwardData.GetKLineData(period); if (period.Equals(forwardPeriod.KlineForwardPeriod)) { this.mainKlineData = klineData; } } timer.Elapsed += Timer_Elapsed; timer.AutoReset = true; }
private void InitKLine() { foreach (KLinePeriod period in dic_Period_KLineData.Keys) { IKLineData_RealTime klineData = dic_Period_KLineData[period]; //主K线最后前进 if (klineData == mainKLineData) { dic_KLinePeriod_IsEnd[period] = true; continue; } klineData.ChangeCurrentBar(mainKLineData); } }
private void ForwardToday2() { bool isMainKLineDataEnd = ForwardToday_MainKLineData(); foreach (KLinePeriod period in forwardData.ReferedKLinePeriods) { if (period.Equals(forwardData.MainKLinePeriod)) { continue; } IKLineData_RealTime klineData = forwardData.GetKLineData(period); } //forwardDataIndeier. }
public void ForwardToday(double time) { this.time = time; int prevTickIndex = dataForForward.CurrentTickData.BarPos; ForwardToday_Tick(dataForForward.CurrentTickData, time); foreach (KLinePeriod period in dataForForward.ReferedKLinePeriods) { IKLineData_RealTime klineData = dataForForward.GetKLineData(period); ForwardToday_KLine(klineData, time, dataForForward.CurrentTickData, prevTickIndex); } ForwardToday_TimeLine(dataForForward.CurrentTimeLineData, time, dataForForward.CurrentTickData, prevTickIndex); }
private void InitKLine() { foreach (KLinePeriod period in this.navigateData.ReferedKLinePeriods) { IKLineData_RealTime klineData = this.navigateData.GetKLineData(period); //主K线最后前进 if (klineData == mainKLineData) { dic_KLinePeriod_IsEnd[period] = true; continue; } klineData.ChangeCurrentBar(mainKLineData); } }
private static double GetEndTime(IKLineData_RealTime klineData, int barPos) { if (klineData.Period.PeriodType >= KLineTimeType.DAY) { return(klineData.Time); } double endTime = klineData.GetEndTime(barPos); if (barPos < klineData.Length - 1 && klineData.IsTradingTimeEnd(barPos)) { endTime = (endTime + klineData.Arr_Time[barPos + 1]) / 2; } return(endTime); }
private void ForwardKLine_NextPeriod(IKLineData_RealTime klineData, int newBarPos, ITickBar tickBar) { KLineBar bar = new KLineBar(); bar.Time = tickBar.Time; bar.Start = tickBar.Price; bar.High = tickBar.Price; bar.Low = tickBar.Price; bar.End = tickBar.Price; bar.Money = tickBar.Mount * tickBar.Price; bar.Mount = tickBar.Mount; bar.Hold = tickBar.Hold; klineData.BarPos = newBarPos; klineData.ChangeCurrentBar(bar); }
private void Index() { IKLineData_RealTime mainKLineData = data.GetMainKLineData(); IKLineData_Extend klineData = mainKLineData.GetKLineData_Original(); for (int i = klineData.BarPos + 1; i < klineData.Length; i++) { if (i == klineData.Length - 1) { IndexEndBarPos(); continue; } double time = klineData.Arr_Time[i]; IndexKLineData(i, time); } }
public DataNavigater_Code_KLinePeriod(IDataPackage_Code dataPackage, IList <KLinePeriod> periods, KLinePeriod mainKLinePeriod, bool useTimeLineData) { this.code = dataPackage.Code; this.periods = periods; this.dataPackage = dataPackage; this.dic_Period_KLineData = this.dataPackage.CreateKLineData_RealTimes(periods); this.mainKLineData = this.dic_Period_KLineData[mainKLinePeriod]; this.currentTradingDay = dataPackage.StartDate; this.useTimeLineData = useTimeLineData; if (useTimeLineData) { this.timeLineData = dataPackage.GetTimeLineData(dataPackage.StartDate); } this.forwardPeriod = new ForwardPeriod(false, mainKLineData.Period); this.onBarArgument = new ForwardOnBarArgument(this.barFinishedInfos); InitKLine(); }
private void PrepareData() { this.listenedCodes[0] = this.dataForForward_Code.Code; this.dataForForward_Code.TradingDay = dataPackage.StartDate; this.forwardDataIndeier = new ForwardDataIndeier(dataForForward_Code); this.onBarArgument = new ForwardOnBarArgument(barFinishedInfos, this); foreach (KLinePeriod period in referedPeriods.UsedKLinePeriods) { IKLineData_RealTime klineData = this.dataForForward_Code.GetKLineData(period); klineData.ChangeCurrentBar(KLineUtils.GetKLineBar(dataForForward_Code.CurrentTickData)); } if (dataForForward_Code.UseTimeLineData) { ITimeLineData_RealTime timeLineData = dataForForward_Code.CurrentTimeLineData; timeLineData.ChangeCurrentBar(TimeLineUtils.GetTimeLineBar(dataForForward_Code.CurrentTickData, timeLineData.YesterdayEnd)); } }
private static bool IsPeriodEnd(IKLineData_RealTime klineData_RealTime, int klineIndex, ITickData_Extend tickData, int tickIndex) { if (tickIndex == tickData.Length - 1) { return(true); } double tickTime = tickData.Time; double nextTickTime = tickData.Arr_Time[tickIndex + 1]; if (klineIndex >= klineData_RealTime.Length - 1) { return(false); } double klineTime = klineData_RealTime.Arr_Time[klineIndex + 1]; return(tickTime < klineTime && nextTickTime >= klineTime); }