Пример #1
0
        private void UpdateSectorTrendIndex(string sectorName, PriceBarSize priceBarSize)
        {
            Log(new LogMessage("IndexManager", $"Updating Trend Index [{sectorName} {priceBarSize.ToString()} {Settings.Instance.Sector_Trend_Bar_Count}]"));

            //
            // Find existing trend to update, or skip if none is found
            //
            var existingTrendIndex =
                SectorTrends.Find(x => x.IndexName == sectorName &&
                                  x.TrendPriceBarSize == priceBarSize &&
                                  x.IndexSwingpointBarCount == Settings.Instance.Sector_Trend_Bar_Count);

            TrendIndex updateIndexTrend = null;

            //
            // If the index exists, remove from local list, update, and re-add; otherwise create a new one and add
            //
            if (existingTrendIndex == null)
            {
                updateIndexTrend = CreateSectorIndex(sectorName, RefDataManager.Instance.GetAllSecurities(), priceBarSize);

                if (updateIndexTrend != null)
                {
                    SectorTrends.Add(updateIndexTrend);
                }
            }
            else
            {
                SectorTrends.Remove(existingTrendIndex);

                updateIndexTrend = UpdateSectorIndex(existingTrendIndex,
                                                     RefDataManager.Instance.GetAllSecurities().Where(x => x.Sector == sectorName).ToList());

                if (updateIndexTrend != null)
                {
                    SectorTrends.Add(updateIndexTrend);
                }
            }

            //
            // Save to database - this will overwrite an existing trend with the same identifiers
            //
            if (updateIndexTrend != null)
            {
                Database.SetTrendIndex(updateIndexTrend);
            }
        }
Пример #2
0
        private void PopulateSectorTrendIndices(PriceBarSize priceBarSize)
        {
            foreach (string sector in Settings.Instance.MarketSectors)
            {
                Log(new LogMessage("IndexManager", $"Populating Trend Index [{sector} {priceBarSize.ToString()}]"));
                //
                // If a trend with the same identifiers was loaded, find and remove from local list
                //
                var existingTrendIndex =
                    SectorTrends.Find(x => x.IndexName == sector &&
                                      x.TrendPriceBarSize == priceBarSize &&
                                      x.IndexSwingpointBarCount == Settings.Instance.Sector_Trend_Bar_Count);

                if (existingTrendIndex != null)
                {
                    SectorTrends.Remove(existingTrendIndex);
                }

                //
                // Create and add the new trend to the list
                //
                var newTrend = SectorTrends.AddAndReturn(CreateSectorIndex(sector, RefDataManager.Instance.GetAllSecurities(), priceBarSize));

                //
                // Save to database - this will overwrite an existing trend with the same identifiers
                //
                Database.SetTrendIndex(newTrend);
            }

            Log(new LogMessage("IndexManager", $"Trend Index Population Complete"));
        }