示例#1
0
        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;
                    }
                }
            }
        }
        public static void ChangeTime_KLineData(IKLineData_RealTime klineData_RealTime, int date, double time, ITickData_Extend tickData)
        {
            KLinePeriod klinePeriod = klineData_RealTime.Period;
            int         klineIndex  = IndexOfTime(klineData_RealTime, klinePeriod, time, date);
            //if(tickData.TradingDay !=date)
            //    tickData =
            int tickIndex = TimeIndeierUtils.IndexOfTime_Tick(tickData, time, true);

            if (IsPeriodEnd(klineData_RealTime, klineIndex, tickData, tickIndex))
            {
                klineData_RealTime.BarPos = klineIndex;
                klineData_RealTime.ResetCurrentBar();
                return;
            }
            int      startTickIndex = GetStartTickIndex(klineData_RealTime, tickData, klinePeriod, klineIndex);
            KLineBar klineBar       = GetKLineBar(tickData, startTickIndex, tickIndex);

            klineData_RealTime.ChangeCurrentBar(klineBar, klineIndex);
        }
示例#3
0
        private void ForwardKLine(IKLineData_RealTime klineData, bool isBarFinished, bool isBarStart)
        {
            ITickBar tickBar = dataForForward_Code.CurrentTickData;

            if (isBarFinished)
            {
                klineData.ResetCurrentBar();
            }
            else if (isBarStart)
            {
                KLineBar klineBar = KLineUtils.GetKLineBar(tickBar);
                klineData.ChangeCurrentBar(klineBar, klineData.BarPos + 1);
            }
            else
            {
                KLineBar klineBar = KLineUtils.GetKLineBar(klineData, tickBar);
                klineData.ChangeCurrentBar(klineBar);
            }
            dic_KLinePeriod_IsEnd[klineData.Period] = isBarFinished;
        }
示例#4
0
        public bool Forward()
        {
            if (isEnd)
            {
                return(false);
            }

            double prevTime = this.Time;

            foreach (KLinePeriod period in navigateData.ReferedKLinePeriods)
            {
                IKLineData_RealTime klineData = navigateData.GetKLineData(period);
                //主K线最后前进
                if (klineData == mainKLineData)
                {
                    continue;
                }
                ForwardKLineData(klineData);
            }

            ForwardTimeLineData();
            mainKLineData.BarPos++;

            DealTimeInfo();

            //如果是最后一个bar,设置结束标志
            if (mainKLineData.BarPos >= mainKLineData.Length - 1)
            {
                isEnd = true;
            }

            foreach (KLinePeriod period in navigateData.ReferedKLinePeriods)
            {
                IKLineData_RealTime klineData = navigateData.GetKLineData(period);
                if (isEnd)
                {
                    klineData.ResetCurrentBar();
                    dic_KLinePeriod_IsEnd[period] = true;
                }
                else if (klineData.BarPos == klineData.Length - 1)
                {
                    if (isDayEnd)
                    {
                        dic_KLinePeriod_IsEnd[period] = true;
                    }
                    else
                    {
                        dic_KLinePeriod_IsEnd[period] = false;
                    }
                }
                else if (period.PeriodType >= KLineTimeType.DAY)
                {
                    if (period.Equals(KLinePeriod.KLinePeriod_1Day))
                    {
                        if (isDayEnd)
                        {
                            dic_KLinePeriod_IsEnd[period] = true;
                        }
                        else
                        {
                            dic_KLinePeriod_IsEnd[period] = false;
                        }
                    }
                }
                else
                {
                    double nextMainTime  = mainKLineData.Arr_Time[mainKLineData.BarPos + 1];
                    double nextKLineTime = klineData.Arr_Time[klineData.BarPos + 1];
                    if (nextMainTime == nextKLineTime)
                    {
                        dic_KLinePeriod_IsEnd[period] = true;
                    }
                    else
                    {
                        dic_KLinePeriod_IsEnd[period] = false;
                    }
                }
            }
            foreach (string code in dic_Code_DataForward.Keys)
            {
                dic_Code_DataForward[code].Forward();
            }
            if (OnBar != null)
            {
                barFinishedInfos.Clear();
                for (int i = 0; i < navigateData.ReferedKLinePeriods.Count; i++)
                {
                    KLinePeriod period = navigateData.ReferedKLinePeriods[i];
                    if (dic_KLinePeriod_IsEnd[period])
                    {
                        IKLineData_RealTime klineData = navigateData.GetKLineData(period);
                        barFinishedInfos.Add(new ForwardOnbar_Info(klineData, klineData.BarPos));
                    }
                }
                OnBar(this, onBarArgument);
            }
            if (OnRealTimeChanged != null)
            {
                OnRealTimeChanged(this, new RealTimeChangedArgument(prevTime, this.Time, this));
            }


            return(true);
        }