private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);



                int nearestDayNum = _arg.NearDaysNum;
                int riseNum       = _arg.NRiseNum;

                var dayDataList = await helper.GetDayData(stockId, nearestDayNum, _arg.BaseDate);


                if (dayDataList.Count > 0)
                {
                    //对数据进行处理
                    for (int i = 0; i < dayDataList.Count - riseNum + 1; i++)
                    {
                        int j = 0;
                        for (; j < riseNum; j++)
                        {
                            if (dayDataList[dayDataList.Count - 1 - (i + j)].Close <= dayDataList[dayDataList.Count - 1 - (i + j)].Open)
                            {
                                //不符合连涨条件
                                break;
                            }
                        }

                        if (j == riseNum)
                        {
                            //符合条件,不需要再检索
                            //加入
                            dayData = dayDataList[dayDataList.Count - 1 - i];
                            break;
                        }
                    }
                }
                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
Exemple #2
0
        private async Task <RealTimeData> Filter(string stockId)
        {
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <BlogContext>();

                var helper = new Utils.Utility(db);

                float   low     = _arg.ZhangFuLow;
                float   high    = _arg.ZhangFuHigh;
                int     numcnt  = _arg.CircleDaysNum;
                DayData dayData = null;



                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //单独只使用涨跌幅,不需要复权

                if (dayDataList.Count == numcnt)
                {
                    float mul = 1;
                    for (int i = 0; i < dayDataList.Count; i++)
                    {
                        var fudu = dayDataList[i].ZhangDieFu;
                        if (fudu != null)
                        {
                            mul *= (1 + fudu.Value / 100f);
                        }
                    }


                    if (low / 100f <= mul - 1 && mul - 1 <= high / 100f)
                    {
                        dayData = dayDataList[0];
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var  helper  = new Utils.Utility(db);
                bool fitFlag = false;

                int objIndex = _arg.StockIdList.IndexOf(stockId);

                DateTime startDate = _arg.DateList[objIndex];
                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, startDate, _arg.BaseDate);


                if (dayDataList.Count > 0)
                {
                    //使用成交量,需要复权
                    //复权,会改变dayDataList中的数据
                    await Utils.CalcData.FuQuan(db, stockId, dayDataList);

                    //
                    //获取均线数据
                    var closePrice = (from ii in dayDataList
                                      select ii.Close).Max();

                    if (closePrice != 0)
                    {
                        var startItem = dayDataList.LastOrDefault();
                        dayData            = startItem;
                        dayData.ZhangDieFu = (closePrice - startItem.Close) / startItem.Close * 100;

                        fitFlag = true;
                    }
                }


                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (fitFlag)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                int numcnt = _arg.CircleDaysNum + _arg.NearDaysNum;

                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);

                bool fitFlag = false;

                if (dayDataList.Count == numcnt)
                {
                    for (int j = 0; j < _arg.NearDaysNum; j++)
                    {
                        DayData current = dayDataList[_arg.NearDaysNum - 1 - j];

                        if (current.ZhangDieFu >= _arg.ZhangFu)
                        {
                            float sum = 0;

                            //对数据进行处理,当日的不处理
                            for (int i = 0; i < _arg.CircleDaysNum; i++)
                            {
                                sum += dayDataList[dayDataList.Count - 1 - (i + j)].Volume;
                            }
                            float avrage = sum / _arg.CircleDaysNum;

                            //判断突破的时间

                            if (current.Volume >= avrage * _arg.VolTimesNum)
                            {
                                dayData = current;//满足要求
                                fitFlag = true;

                                break;
                            }
                        }
                    }
                }

                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (fitFlag)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
Exemple #5
0
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, _arg.CircleDaysNum + _arg.NearDaysNum, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);


                int breakIndex = 0;

                if (dayDataList.Count == _arg.CircleDaysNum + _arg.NearDaysNum)
                {
                    //求出最近的最高价格,收盘
                    int   i             = 0;
                    float maxClosePrice = 0;
                    for (; i < _arg.NearDaysNum; i++)
                    {
                        float current = dayDataList[i].Close;
                        if (current > maxClosePrice)
                        {
                            maxClosePrice = current;
                            breakIndex    = i;
                        }
                    }

                    //如果不是严格模式
                    if (!_arg.StrictMode)
                    {
                        //如果收盘价高于收盘价,最高价高于最高价,就排除邻近的一根日线

                        var nearItem = dayDataList[breakIndex + 1];

                        if (dayDataList[breakIndex].Close >= nearItem.Close &&
                            dayDataList[breakIndex].High > nearItem.High)
                        {
                            bool allMatch = false;
                            for (int tempj = i + 1; tempj < dayDataList.Count; tempj++)
                            {
                                if (dayDataList[tempj].High > nearItem.Close)
                                {
                                    allMatch = true;
                                    break;
                                }
                            }
                            if (allMatch)
                            {
                                i++;
                            }
                        }
                    }


                    //求出之前的最高的盘中最高价格
                    float previousMaxHigh = 0;

                    for (; i < dayDataList.Count - _arg.NearDaysNum; i++)
                    {
                        float current = dayDataList[i].High;
                        if (current > previousMaxHigh)
                        {
                            previousMaxHigh = current;
                        }
                    }

                    //符合回调条件的点
                    bool match = false;
                    if (maxClosePrice > previousMaxHigh)
                    {
                        for (i = 0; i < _arg.CircleDaysNum; i++)
                        {
                            //从最早的数据开始遍历
                            var listItem = dayDataList[dayDataList.Count - 1 - i];
                            if (listItem.High >= previousMaxHigh)
                            {
                                //寻找到高点

                                //后面的最低价格
                                float suffixMinLow = float.MaxValue;

                                //寻找后续最低点
                                for (int j = i + 1; j < _arg.CircleDaysNum; j++)
                                {
                                    float current = dayDataList[dayDataList.Count - 1 - j].Low;
                                    if (current < suffixMinLow)
                                    {
                                        suffixMinLow = current;
                                    }
                                }

                                float fudu = (listItem.High - suffixMinLow) / listItem.High;

                                if (fudu >= _arg.HuiTiaoFuDuLow / 100f && fudu <= _arg.HuiTiaoFuDuHigh / 100f)
                                {
                                    //符合回调幅度的高点
                                    match = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (match)
                    {
                        //符合条件
                        dayData = dayDataList[breakIndex];
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                int numcnt = _arg.RecentDaysNum
                             + _arg.MaxDaysNumDownAvgBeforeTwice +
                             +_arg.MaxDaysNumUpAvgAfterFirst
                             + _arg.MinDaysNumDownAvgBeforeFirst
                             + _arg.AvgDays;

                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);

                bool fitFlag = false;

                if (dayDataList.Count == numcnt)
                {
                    //
                    //获取均线数据
                    var closeList = (from ii in dayDataList
                                     select ii.Close).ToList();

                    var maArray    = Utils.CalcData.Average(closeList, _arg.AvgDays);
                    int gobleIndex = 0;
                    //满足条件的flag
                    for (; gobleIndex < _arg.RecentDaysNum; gobleIndex++)
                    {
                        var current = dayDataList[gobleIndex];

                        if (current.Close >= maArray[gobleIndex] &&
                            dayDataList[gobleIndex + 1].Close < maArray[gobleIndex + 1])
                        {
                            //满足本阶段条件
                            fitFlag = true;
                            dayData = current;
                            break;
                        }
                    }

                    if (fitFlag)
                    {
                        //重新设置标记
                        //检查在均线之下是否超过最大天数
                        fitFlag = false;
                        int startIndex = gobleIndex + 1;                                     //之前的处理前一个数据时,并没有移动索引
                        int bianjie    = startIndex + _arg.MaxDaysNumDownAvgBeforeTwice + 1; //往前再弄一天
                        for (gobleIndex = startIndex; gobleIndex < bianjie; gobleIndex++)
                        {
                            var current = dayDataList[gobleIndex];
                            if (current.Close >= maArray[gobleIndex])
                            {
                                fitFlag = true;
                                break;
                            }
                        }
                    }


                    if (fitFlag)
                    {
                        //重新设置标记
                        //检查在均线之上是否超过最大天数
                        fitFlag = false;
                        int startIndex = gobleIndex;                                      // //之前的处理前一个数据时,移动了索引
                        int bianjie    = startIndex + _arg.MaxDaysNumUpAvgAfterFirst + 1; //刚好全部都在均线上,然后再往前一天在均线下了
                        for (gobleIndex = startIndex; gobleIndex < bianjie; gobleIndex++)
                        {
                            var current = dayDataList[gobleIndex];
                            if (current.Close < maArray[gobleIndex])
                            {
                                //在指定数量内逆序后,第一次出现低于均线

                                //满足本阶段条件
                                fitFlag = true;
                                break;
                            }
                        }

                        if (gobleIndex - startIndex < _arg.MinDaysNumUpAvgAfterFirst)
                        {
                            //在均线之上的天数少于要求。
                            fitFlag = false;
                        }
                    }

                    if (fitFlag)
                    {
                        int exceptCnt = 0;
                        fitFlag = false;
                        int startIndex = gobleIndex;                                         //之前的处理前一个数据时,移动了索引
                        int bianjie    = startIndex + _arg.MinDaysNumDownAvgBeforeFirst - 1; //这里是满足性检查,不是数据变化检查,上一个检查必定有一个处于均线之下
                        for (gobleIndex = startIndex; gobleIndex < bianjie; gobleIndex++)
                        {
                            //进一步判读之前的是否是在均线之下
                            var current = dayDataList[gobleIndex];
                            if (current.Close >= maArray[gobleIndex])
                            {
                                //不满足条件
                                exceptCnt++;
                                if (exceptCnt > _arg.MaxDaysNumUpAvgBeforeFirst)
                                {
                                    fitFlag = false;
                                    break;
                                }
                            }
                        }
                        if (exceptCnt <= _arg.MaxDaysNumUpAvgBeforeFirst)
                        {
                            fitFlag = true;
                        }
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (fitFlag)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
Exemple #7
0
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);
                int numcnt = _arg.CircleDaysNum + _arg.NearDaysNum;
                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);



                if (dayDataList.Count == numcnt)
                {
                    //求出最近的最高价格,收盘
                    int   i = 0;
                    float maxClosePriceInNearDays = 0;
                    for (; i < _arg.NearDaysNum; i++)
                    {
                        float current = dayDataList[i].Close;
                        if (current > maxClosePriceInNearDays)
                        {
                            maxClosePriceInNearDays = current;
                        }
                    }

                    //求出之前的最高的盘中最高价格
                    float maxHighInPreviousDays = 0;

                    for (; i < dayDataList.Count - _arg.NearDaysNum; i++)
                    {
                        float current = dayDataList[i].High;
                        if (current > maxHighInPreviousDays)
                        {
                            maxHighInPreviousDays = current;
                        }
                    }

                    //符合回调条件的点
                    bool match = false;
                    if (maxClosePriceInNearDays <= maxHighInPreviousDays &&
                        (maxHighInPreviousDays - maxClosePriceInNearDays) / maxClosePriceInNearDays * 100 < _arg.XiangchaLv
                        )
                    {
                        for (i = 0; i < _arg.CircleDaysNum; i++)
                        {
                            //从最早的数据开始遍历
                            var listItem = dayDataList[dayDataList.Count - 1 - i];
                            if (listItem.High >= maxHighInPreviousDays)
                            {
                                //寻找到高点

                                //后面的最低价格
                                float suffixMinLow = float.MaxValue;

                                //寻找后续最低点
                                for (int j = i + 1; j < _arg.CircleDaysNum; j++)
                                {
                                    float current = dayDataList[dayDataList.Count - 1 - j].Low;
                                    if (current < suffixMinLow)
                                    {
                                        suffixMinLow = current;
                                    }
                                }

                                float fudu = (listItem.High - suffixMinLow) / listItem.High;

                                if (fudu >= _arg.HuiTiaoFuDuLow / 100f && fudu <= _arg.HuiTiaoFuDuHigh / 100f)
                                {
                                    //符合回调幅度的高点
                                    match = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (match)
                    {
                        //符合条件
                        dayData = dayDataList[0];
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                int numcnt = 1 + _arg.NearDaysNum;
                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);



                if (dayDataList.Count == numcnt)
                {
                    //符合回调条件的点
                    bool match = false;

                    int matchIndex = -1;

                    for (int i = 0; i < _arg.NearDaysNum; i++)
                    {
                        //从最早的数据开始遍历
                        int currentIndex     = dayDataList.Count - 1 - i - 1; //要跳过第一个数据
                        var currentListItem  = dayDataList[currentIndex];
                        var previousListItem = dayDataList[currentIndex + 1]; //是倒序。
                        if (currentListItem.Low > previousListItem.High &&
                            (currentListItem.Low - previousListItem.Close) / previousListItem.Close > _arg.GapPercent / 100.0 &&
                            currentListItem.Close > currentListItem.Open &&     //真阳线
                            currentListItem.ZhangDieFu <= _arg.LimitPercent
                            )
                        {
                            //满足跳空条件

                            //后面的最低价格
                            float suffixMinLow = float.MaxValue;

                            //寻找后续最低点
                            for (int j = i; j < _arg.NearDaysNum; j++)
                            {
                                var   temp    = dayDataList[dayDataList.Count - 1 - j - 1];
                                float current = temp.Low;
                                if (current < suffixMinLow)
                                {
                                    suffixMinLow = current;
                                }
                            }



                            if (suffixMinLow > previousListItem.High)
                            {
                                //符合回调幅度的高点
                                match      = true;
                                matchIndex = currentIndex;
                                break;
                            }
                        }
                    }
                    if (match)
                    {
                        //符合条件
                        dayData = dayDataList[matchIndex];
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                int numcnt = _arg.UpDaysNum + _arg.NearDaysNum + _arg.AvgDays;

                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);

                bool fitFlag = false;

                if (dayDataList.Count == numcnt)
                {
                    //
                    //获取均线数据
                    var closeList = (from ii in dayDataList
                                     select ii.Close).ToList();

                    var maArray = Utils.CalcData.Average(closeList, _arg.AvgDays);

                    //满足条件的flag
                    //对数据进行处理,当日的不处理
                    for (int i = 0; i < _arg.UpDaysNum; i++)
                    {
                        var current = dayDataList[i];

                        if (current.Close > maArray[i])
                        {
                            //不满足条件
                            fitFlag = true;
                            dayData = current;
                            break;
                        }
                    }
                    if (fitFlag)
                    {
                        int exceptCnt = 0;
                        for (int j = 0; j < _arg.NearDaysNum; j++)
                        {
                            //进一步判读之前的是否是在均线之下
                            var temp = dayDataList[j + _arg.UpDaysNum];
                            if (temp.Close >= maArray[j + _arg.UpDaysNum])
                            {
                                //不满足条件
                                exceptCnt++;
                                if (exceptCnt > _arg.ExceptionNum)
                                {
                                    fitFlag = false;
                                    break;
                                }
                            }
                        }
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (fitFlag)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <BlogContext>();

                var helper = new Utils.Utility(db);



                int   nearestDayNum = _arg.NearDaysNum;
                int   riseNum       = _arg.NRiseNum;
                float volumePercent = _arg.VolumePercent;

                var dayDataList = await helper.GetDayData(stockId, nearestDayNum, _arg.BaseDate);

                if (dayDataList.Count > 0)
                {
                    //对数据进行处理
                    for (int i = 0; i < dayDataList.Count - riseNum + 1; i++)
                    {
                        int j = 0;
                        for (; j < riseNum - 1; j++)
                        {
                            int index = dayDataList.Count - 1 - (i + j);
                            if (dayDataList[index].Volume < dayDataList[index - 1].Volume)
                            {
                                //不符合连续缩量
                                break;
                            }
                        }

                        if (j == riseNum - 1)
                        {
                            //符合条件
                            //再判断成交量
                            int index = dayDataList.Count - 1 - (i + j);

                            if (dayDataList[index].Volume <= dayDataList[index + riseNum - 1].Volume * volumePercent / 100f)
                            {
                                //加入
                                dayData = dayDataList[dayDataList.Count - 1 - i];
                                break;
                            }
                        }
                    }
                }


                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
Exemple #11
0
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, _arg.CircleDaysNum + _arg.NearDaysNum, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);



                int breakIndex = 0;
                if (dayDataList.Count == _arg.CircleDaysNum + _arg.NearDaysNum)
                {
                    var query = from item in dayDataList
                                select(item.Open + item.Close) / 2;

                    var midPrices = query.ToArray();

                    //求出最近的最高中阶
                    int   i = 0;
                    float maxMiddlePrice = 0;
                    for (; i < _arg.NearDaysNum; i++)
                    {
                        float current = midPrices[i];
                        if (current > maxMiddlePrice)
                        {
                            maxMiddlePrice = current;
                            breakIndex     = i;
                        }
                    }

                    //求出之前的最高的盘中最高价格
                    float previousMaxMiddle = 0;

                    for (; i < midPrices.Count() - _arg.NearDaysNum; i++)
                    {
                        float current = midPrices[i];
                        if (current > previousMaxMiddle)
                        {
                            previousMaxMiddle = current;
                        }
                    }

                    //符合回调条件的点
                    bool match = false;
                    if (maxMiddlePrice > previousMaxMiddle)
                    {
                        for (i = 0; i < _arg.CircleDaysNum; i++)
                        {
                            //从最早的数据开始遍历
                            var listItem = midPrices[midPrices.Count() - 1 - i];
                            if (listItem >= previousMaxMiddle)
                            {
                                //寻找到了高点

                                //后面的最低价格
                                float suffixMinLow = float.MaxValue;

                                //寻找后续最低点
                                for (int j = i + 1; j < _arg.CircleDaysNum; j++)
                                {
                                    float current = midPrices[midPrices.Count() - 1 - j];
                                    if (current < suffixMinLow)
                                    {
                                        suffixMinLow = current;
                                    }
                                }

                                float fudu = (listItem - suffixMinLow) / listItem;

                                if (fudu >= _arg.HuiTiaoFuDuLow / 100f && fudu <= _arg.HuiTiaoFuDuHigh / 100f)
                                {
                                    //符合回调幅度的高点
                                    match = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (match)
                    {
                        //符合条件
                        dayData = dayDataList[breakIndex];
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (dayData != null)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }
        private async Task <RealTimeData> Filter(string stockId)
        {
            DayData dayData = null;


            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <StockContext>();

                var helper = new Utils.Utility(db);

                const int minDataCntForIteration = 130;

                int numcnt = _arg.UpDaysNum + _arg.NearDaysNum + _arg.AvgDays;
                if (numcnt < minDataCntForIteration)
                {
                    numcnt = minDataCntForIteration;
                }

                //当天的数据算一个
                var dayDataList = await helper.GetDayData(stockId, numcnt, _arg.BaseDate);

                //使用成交量,需要复权
                //复权,会改变dayDataList中的数据
                await Utils.CalcData.FuQuan(db, stockId, dayDataList);

                bool fitFlag = false;

                if (dayDataList.Count == numcnt)
                {
                    //
                    //获取均线数据
                    var closeList = (from ii in dayDataList
                                     select ii.Close).ToList();

                    var macd = Utils.CalcData.MACD(closeList);
                    var diff = macd.diff;
                    var dea  = macd.dea;



                    //从0开始是对齐的,因为是采用的时间逆序,后面的数据可能有缺失 。


                    //满足条件的flag
                    //对数据进行处理,当日的不处理
                    for (int i = 0; i < _arg.UpDaysNum; i++)
                    {
                        var current = dayDataList[i];

                        if (diff[i] >= _arg.LowDiff && dea[i] >= _arg.LowDea)
                        {
                            //不满足条件
                            fitFlag = true;
                            dayData = current;
                            break;
                        }
                    }
                    if (fitFlag)
                    {
                        int exceptCnt = 0;
                        for (int j = 0; j < _arg.NearDaysNum; j++)
                        {
                            //进一步判读之前的是否是在diff,dea都大于0
                            //var temp = dayDataList[j + _arg.UpDaysNum];
                            //if (temp.Close >= maArray[j + _arg.UpDaysNum])
                            int index = j + _arg.UpDaysNum;
                            if (diff[j] >= _arg.PreLowDiff && dea[j] >= _arg.PreLowDea)
                            {
                                //满足条件
                                exceptCnt++;
                                if (exceptCnt > _arg.ExceptionNum)
                                {
                                    fitFlag = false;
                                    break;
                                }
                            }
                        }
                    }
                }



                //如果是null,表示不符合筛选条件

                RealTimeData real = null;
                if (fitFlag)
                {
                    real = await helper.ConvertDayToReal(dayData);
                }

                return(real);
            }
        }