Пример #1
0
        // Add User Alert Symbols in the Database
        private void GetResultSymbols(long userAlertId)
        {
            string  strategy;
            string  exchange;
            decimal price;
            decimal volume;
            decimal growthDecayRate;
            string  growthDecayTime;
            int     noOfYears;
            decimal correlation30;

            if (userAlertId > 0)
            {
                var userAlerts = from d in db.TrnUserAlerts where d.Id == userAlertId select d;
                if (userAlerts.Any())
                {
                    strategy        = userAlerts.First().Strategy;
                    exchange        = userAlerts.First().Exchange;
                    price           = userAlerts.First().Price;
                    volume          = userAlerts.First().Volume;
                    growthDecayRate = userAlerts.First().GrowthDecayRate;
                    growthDecayTime = userAlerts.First().GrowthDecayTime;
                    noOfYears       = userAlerts.First().NoOfYears;
                    correlation30   = userAlerts.First().Correlation30;

                    var symbols = from d in db.MstSymbols where d.Exchange == "NA" select d;
                    if (strategy == "MED")
                    {
                        // Magenta Early Down
                        symbols = from d in db.MstSymbols
                                  where (exchange == "All" ? true : d.Exchange == exchange) &&
                                  (d.ClosePrice >= price) &&
                                  (d.Exchange == "FOREX" ? true : d.Volume >= volume) &&
                                  (d.NoOfYears >= noOfYears) &&
                                  (d.MACDGrowthDecayRate < 0) &&
                                  (d.EMAGrowthDecayRate < 0)
                                  select d;
                    }
                    else if (strategy == "MEU")
                    {
                        // Magenta Early Up
                        symbols = from d in db.MstSymbols
                                  where (exchange == "All" ? true : d.Exchange == exchange) &&
                                  (d.ClosePrice >= price) &&
                                  (d.Exchange == "FOREX" ? true : d.Volume >= volume) &&
                                  (d.NoOfYears >= noOfYears) &&
                                  (d.MACDGrowthDecayRate >= 0) &&
                                  (d.EMAGrowthDecayRate >= 0)
                                  select d;
                    }
                    else
                    {
                        // Customized
                        symbols = from d in db.MstSymbols
                                  where (exchange == "All" ? true : d.Exchange == exchange) &&
                                  (d.ClosePrice >= price) &&
                                  (d.Exchange == "FOREX" ? true : d.Volume >= volume) &&
                                  (d.NoOfYears >= noOfYears) &&
                                  (d.CorrelationCoefficient30 >= (correlation30 / 100)) &&
                                  (growthDecayTime == "C0" && growthDecayRate >= 0 ? ((d.GrowthDecayRate.Value == null ? 0 : d.GrowthDecayRate.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "C0" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRate.Value == null ? 0 : d.GrowthDecayRate.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "W1" && growthDecayRate >= 0 ? ((d.GrowthDecayRateW1.Value == null ? 0 : d.GrowthDecayRateW1.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "W1" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateW1.Value == null ? 0 : d.GrowthDecayRateW1.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "W2" && growthDecayRate >= 0 ? ((d.GrowthDecayRateW2.Value == null ? 0 : d.GrowthDecayRateW2.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "W2" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateW2.Value == null ? 0 : d.GrowthDecayRateW2.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "W3" && growthDecayRate >= 0 ? ((d.GrowthDecayRateW3.Value == null ? 0 : d.GrowthDecayRateW3.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "W3" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateW3.Value == null ? 0 : d.GrowthDecayRateW3.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "M1" && growthDecayRate >= 0 ? ((d.GrowthDecayRateM1.Value == null ? 0 : d.GrowthDecayRateM1.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "M1" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateM1.Value == null ? 0 : d.GrowthDecayRateM1.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "M2" && growthDecayRate >= 0 ? ((d.GrowthDecayRateM2.Value == null ? 0 : d.GrowthDecayRateM2.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "M2" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateM2.Value == null ? 0 : d.GrowthDecayRateM2.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "M3" && growthDecayRate >= 0 ? ((d.GrowthDecayRateM3.Value == null ? 0 : d.GrowthDecayRateM3.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "M3" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateM3.Value == null ? 0 : d.GrowthDecayRateM3.Value) ? true : false) : true) == true
                                  select d;
                    }

                    // Delete existing data
                    var userAlertSymbols = from d in db.TrnUserAlertSymbols where d.UserAlertId == userAlertId select d;
                    if (userAlertSymbols.Any())
                    {
                        foreach (Data.TrnUserAlertSymbol s in userAlertSymbols)
                        {
                            db.TrnUserAlertSymbols.DeleteOnSubmit(s);
                            db.SubmitChanges();
                        }
                    }

                    if (symbols.Any())
                    {
                        // Add symbols
                        foreach (var s in symbols)
                        {
                            Data.TrnUserAlertSymbol newUserAlertSymbol = new Data.TrnUserAlertSymbol();

                            newUserAlertSymbol.UserAlertId = Convert.ToInt16(userAlertId);
                            newUserAlertSymbol.SymbolId    = s.Id;
                            newUserAlertSymbol.Symbol      = s.Symbol;
                            newUserAlertSymbol.Trend       = "";
                            newUserAlertSymbol.EncodedDate = userAlerts.First().EncodedDate;

                            db.TrnUserAlertSymbols.InsertOnSubmit(newUserAlertSymbol);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }
Пример #2
0
        // Add User Alert Symbols in the Database
        private void GetResultSymbols(long userAlertId)
        {
            bool symbolFilter;
            bool strategyFilter;
            bool macdFilter;
            bool magentaChannelFilter;
            bool seasonalityFilter;
            bool additionalFilter;

            if (userAlertId > 0)
            {
                var userAlerts = from d in db.TrnUserAlerts where d.Id == userAlertId select d;
                if (userAlerts.Any())
                {
                    // Filter symbols
                    List <Data.MstSymbol> symbolResults = new List <Data.MstSymbol>();
                    symbolFilter         = userAlerts.First().SymbolFilter;
                    strategyFilter       = userAlerts.First().StrategyFilter;
                    macdFilter           = userAlerts.First().MACDFilter;
                    magentaChannelFilter = userAlerts.First().MagentaChannelFilter;
                    seasonalityFilter    = userAlerts.First().SeasonalityFilter;
                    additionalFilter     = userAlerts.First().AdditionalFilter;

                    if (symbolFilter == true)
                    {
                        symbolResults = GetResultLevelSymbol(userAlertId);
                        if (strategyFilter == true)
                        {
                            symbolResults = GetResultLevelStrategy(userAlertId, symbolResults);
                        }
                        if (macdFilter == true)
                        {
                            symbolResults = GetResultLevelMACD(userAlertId, symbolResults);
                        }
                        if (magentaChannelFilter == true)
                        {
                            symbolResults = GetResultLevelMagentaChannel(userAlertId, symbolResults);
                        }
                        if (seasonalityFilter == true)
                        {
                            symbolResults = GetResultLevelSeasonality(userAlertId, symbolResults);
                        }
                        if (additionalFilter == true)
                        {
                            symbolResults = GetResultLevelAdditionalFilter(userAlertId, symbolResults);
                        }
                    }

                    // Delete existing data
                    var userAlertSymbols = from d in db.TrnUserAlertSymbols where d.UserAlertId == userAlertId select d;
                    if (userAlertSymbols.Any())
                    {
                        foreach (Data.TrnUserAlertSymbol s in userAlertSymbols)
                        {
                            db.TrnUserAlertSymbols.DeleteOnSubmit(s);
                            db.SubmitChanges();
                        }
                    }

                    // Add symbols
                    if (symbolResults.Any())
                    {
                        foreach (var s in symbolResults)
                        {
                            Data.TrnUserAlertSymbol newUserAlertSymbol = new Data.TrnUserAlertSymbol();

                            newUserAlertSymbol.UserAlertId = Convert.ToInt16(userAlertId);
                            newUserAlertSymbol.SymbolId    = s.Id;
                            newUserAlertSymbol.Symbol      = s.Symbol;
                            newUserAlertSymbol.Trend       = "";
                            newUserAlertSymbol.EncodedDate = userAlerts.First().EncodedDate;

                            db.TrnUserAlertSymbols.InsertOnSubmit(newUserAlertSymbol);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }