Exemple #1
0
        private async Task <bool> ShouldBuy(decimal week52high, decimal avgVol, IEnumerable <StockDataPoint> dataPoints, string symbol)
        {
            var list_dataPoints = dataPoints.ToList();

            if (list_dataPoints == null && list_dataPoints.Count < 2)
            {
                return(false);
            }

            var     currentOldest      = list_dataPoints.Where(x => x.Time.Day == DateTime.Today.Day).Last();
            decimal currentOldestPrice = currentOldest.OpeningPrice;
            bool    firstCheck         = MarketServiceHelper.DailyOldestPrices.TryAdd(symbol, currentOldestPrice); //add oldest price if it doesnt exist already
            var     oldestTime         = currentOldest.Time.TimeOfDay;
            bool    isTodaysOpenValues = oldestTime.Hours == 9 && oldestTime.Minutes < 36;                         //found the damn near open price
            int     indexOfoldest      = list_dataPoints.IndexOf(currentOldest);

            list_dataPoints.RemoveRange(indexOfoldest, (list_dataPoints.Count - 1 - indexOfoldest)); //TODO: check this removes all the yesterday values
            bool trendingUpish = TrendingUp(list_dataPoints.Select(l => l.ClosingPrice).ToArray());

            //Check for 52 week high momentum
            ///is it early and high volume and price above 52 week high and trending up?
            if (isTodaysOpenValues && trendingUpish && list_dataPoints.First().ClosingPrice > week52high && list_dataPoints.First().Volume > avgVol)
            {
                return(true);
            }
            else if (trendingUpish)
            {
                //GET RSI
                var rsiTask   = MarketAPIHelper.GetRSI(symbol);
                var cciTask   = MarketAPIHelper.GetCCI(symbol);
                var aroonTask = MarketAPIHelper.GetAroonOsc(symbol);

                var results = await Task.WhenAll(rsiTask, cciTask, aroonTask);

                decimal smartValue = SmartAlgorithm(results[0], results[1], results[2]);

                return(smartValue >= 60);  //TODO: obvi
            }

            return(false);
        }
Exemple #2
0
        private async Task <Queue <StockInfo> > GetStocksToBuy()
        {
            using (var dbContext = GetDbContext())
            {
                var watchStocks = dbContext.WatchList.Where(x => x.TradeDay.Date == DateTime.Today.Date).ToArray();

                var watchSymbols     = watchStocks.Select(x => x.Symbol);
                int minutesSinceOpen = (DateTime.Now - DateTime.Today.Date.AddHours(8)).Minutes;
                var stockQuotes      = await MarketAPIHelper.GetQuotes(watchSymbols.ToArray());

                var ret = new Queue <StockInfo>(watchStocks.Length);

                foreach (var quote in stockQuotes)
                {
                    var dataPoints = await MarketAPIHelper.GetIntraDayInfo(quote.Symbol, minutesSinceOpen + 1);

                    var watchStock = watchStocks.Where(x => x.Symbol == quote.Symbol).FirstOrDefault();

                    if (await ShouldBuy(watchStock.Week52High, watchStock.AverageVolume, dataPoints, quote.Symbol))
                    {
                        var tempSI = new StockInfo(quote)
                        {
                            Week52High         = watchStock.Week52High,
                            AverageTotalVolume = (double)watchStock.AverageVolume
                        };
                        ret.Enqueue(tempSI);
                    }
                    else
                    {
                        _logger.LogDebug("Deciding not to buy {0} .... yet", quote.Symbol);
                    }
                }

                return(ret);
            }
        }