public int GetCandelRangeRoundNormalizerValue(CandelRange candelRange) { switch (candelRange) { case CandelRange.Daily: return(1); case CandelRange.Weekly: return(5); case CandelRange.Monthly: return(20); default: return(0); } }
public override void InitializeFromDataBaseValues(List <Candel> quotes, string param1, string color1, string param2, string color2, string param3, string color3, CandelRange candelRange) { int shortTerm = 0; int.TryParse(param1, out shortTerm); int longTerm = 0; int.TryParse(param2, out longTerm); this.Name = "CMAS"; this.In_Main_Chart = true; this.Data_Source = quotes; this.ShortRounds = shortTerm / base.GetCandelRangeRoundNormalizerValue(candelRange); this.LongRounds = longTerm / base.GetCandelRangeRoundNormalizerValue(candelRange); this.Serie_Color1 = (color1 != null) ? color1 : String.Empty; this.Serie_Color2 = (color2 != null) ? color2 : String.Empty; this.Series = new List <Serie>(); ApplyFormula(); }
public override void InitializeFromDataBaseValues(List <Candel> quotes, string param1, string color1, string param2, string color2, string param3, string color3, CandelRange candelRange) { this.In_Main_Chart = false; this.Name = "OBV"; this.Data_Source = quotes; this.Serie_Color = (color1 != null) ? color1 : String.Empty; this.Series = new List <Serie>(); ApplyFormula(); }
public abstract void InitializeFromDataBaseValues(List <Candel> quotes, string param1, string color1, string param2, string color2, string param3, string color3, CandelRange candelRange);
public static List <Candel> GetSymbolQuotes(int symbol_id, ChartRange chartRange, CandelRange candelRange, string user_type) { DateTime chartMinDate = DateTime.Now; DateTime today = DateTime.Now.Date; switch (chartRange) { case ChartRange.Month: chartMinDate = chartMinDate.AddMonths(-1); break; case ChartRange.ThreeMonths: chartMinDate = chartMinDate.AddMonths(-3); break; case ChartRange.SixMonths: chartMinDate = chartMinDate.AddMonths(-6); break; case ChartRange.Year: chartMinDate = chartMinDate.AddYears(-1); break; case ChartRange.ThreeYears: chartMinDate = chartMinDate.AddYears(-3); break; default: chartMinDate = DateTime.MinValue.AddDays(200); break; } List <Candel> candels = new List <Candel>(); using (ctaDBEntities entities = new ctaDBEntities()) { entities.Database.Connection.Open(); bool createCandel = false; Candel currentCandel = null; DateTime startDate = chartMinDate.AddDays(-200); List <Stock_Quote> quotes = entities.Stock_Quote.Where(s => s.stock_id == symbol_id && (s.date_round > startDate && (user_type != "FREE" || s.date_round < today))).OrderBy(sq => sq.date_round).ToList(); Stock_Quote quote = null; for (int i = 0; i < quotes.Count; i++) { quote = quotes[i]; currentCandel = (currentCandel != null) ? currentCandel : new Candel() { Date = quote.date_round, Open = quote.opening, Close = quote.closing, Minimun = quote.minimun, Maximun = quote.maximun, Volume = (double)quote.volume }; if (candelRange == CandelRange.Daily) { createCandel = true; } else if (candelRange == CandelRange.Weekly) { currentCandel.Minimun = (currentCandel.Minimun > quote.minimun) ? quote.minimun : currentCandel.Minimun; currentCandel.Maximun = (currentCandel.Maximun < quote.maximun) ? quote.maximun : currentCandel.Maximun; if (quote.date_round.DayOfWeek == DayOfWeek.Friday) { currentCandel.Close = quote.closing; currentCandel.Date = quote.date_round; createCandel = true; } } else { currentCandel.Minimun = (currentCandel.Minimun > quote.minimun) ? quote.minimun : currentCandel.Minimun; currentCandel.Maximun = (currentCandel.Maximun < quote.maximun) ? quote.maximun : currentCandel.Maximun; if (currentCandel.Date.Month != quote.date_round.Month) { createCandel = true; i--; } else { currentCandel.Date = quote.date_round; } } if (createCandel || i + 1 == quotes.Count) { currentCandel.Close = quote.closing; currentCandel.Visible = (currentCandel.Date >= chartMinDate.Date); candels.Add(currentCandel); currentCandel = null; createCandel = false; } } entities.Database.Connection.Close(); } return(candels); }
public ActionResult GetSymbolContent(int symbol_id, string main_chart_type, ChartRange chartRange, CandelRange candelRange, int portfolio_id = 0) { SymbolContentModel symbol_content = new SymbolContentModel(portfolio_id, symbol_id); symbol_content.Symbol_Dashboard = DashboardService.GetSymbolDashboard(portfolio_id, symbol_id, chartRange, candelRange, true); object data = symbol_content.GetDataInJSONFormat(main_chart_type); object data_series_main_chart = symbol_content.GetDataSeriesInfoForMainChart(main_chart_type); object data_view_main_chart = symbol_content.GetDataViewInfoForMainChartData(main_chart_type); object volume_chart_view = symbol_content.GetDataViewInfoForVolumeChart(main_chart_type); object date_range_selector_view = symbol_content.GetDataViewInfoForDateRangeSelector(main_chart_type); object[] data_indicators = symbol_content.GetDataInfoForChartIndicators(main_chart_type); object max_data_date = symbol_content.max_date.ToString("r"); object response = new { data = data, series_main_chart = data_series_main_chart, view_main_chart = data_view_main_chart, indicators = data_indicators, date_range_selector_view = date_range_selector_view, max_data_date = max_data_date, volume_chart_view = volume_chart_view }; var jsonResult = Json(response, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); }
public override void InitializeFromDataBaseValues(List <Candel> quotes, string param1, string color1, string param2, string color2, string param3, string color3, CandelRange candelRange) { this.In_Main_Chart = false; int rounds = 0; int.TryParse(param1, out rounds); this.Name = "ROC"; this.Data_Source = quotes; this.Rounds = rounds / base.GetCandelRangeRoundNormalizerValue(candelRange); this.Serie_Color = (color1 != null) ? color1 : String.Empty; this.Serie_Hundred_Color = (color2 != null) ? color2 : String.Empty; this.Series = new List <Serie>(); ApplyFormula(); }
public override void InitializeFromDataBaseValues(List <Candel> quotes, string param1, string color1, string param2, string color2, string param3, string color3, CandelRange candelRange) { int rounds = 0; int.TryParse(param1, out rounds); int overSold = 0; int.TryParse(param2, out overSold); int overBought = 0; int.TryParse(param3, out overBought); this.Name = "Williams R"; this.In_Main_Chart = false; this.Data_Source = quotes; this.Rounds = rounds / base.GetCandelRangeRoundNormalizerValue(candelRange); this.Oversold = overSold; this.Overbought = overBought; this.Serie_Color = (color1 != null) ? color1 : String.Empty; this.Serie_Bounded_Lines_Color = (color2 != null) ? color2 : String.Empty; this.Serie_Average_Color = (color3 != null) ? color3 : String.Empty; ApplyFormula(); }
public override void InitializeFromDataBaseValues(List <Candel> quotes, string param1, string color1, string param2, string color2, string param3, string color3, CandelRange candelRange) { int shortTerm = 0; int.TryParse(param1, out shortTerm); int longTerm = 0; int.TryParse(param2, out longTerm); int averageTerm = 0; int.TryParse(param3, out averageTerm); this.Name = "MACD"; this.In_Main_Chart = false; this.Data_Source = quotes; this.Short_Term = shortTerm / base.GetCandelRangeRoundNormalizerValue(candelRange); this.Long_Term = longTerm / base.GetCandelRangeRoundNormalizerValue(candelRange); this.Average_Term = averageTerm / base.GetCandelRangeRoundNormalizerValue(candelRange); this.Serie_Color = (color1 != null) ? color1 : String.Empty; this.Zero_Serie_Color = (color2 != null) ? color2 : String.Empty; this.Average_Serie_Color = (color3 != null) ? color3 : String.Empty; this.Series = new List <Serie>(); ApplyFormula(); }
public SymbolDashboardModel(int portfolio_id, int symbol_id, string username, ChartRange chartRange, CandelRange candelRange, bool withQuotes) { // TODO: Complete member initialization this.portfolio_id = portfolio_id; this.symbol_id = symbol_id; this.Username = username; this.symbol_content = new SymbolContentModel(portfolio_id, symbol_id); this.symbol_content.Symbol_Dashboard = DashboardService.GetSymbolDashboard(portfolio_id, symbol_id, chartRange, candelRange, withQuotes); this.Indicators = DashboardService.GetIndicatorsDetails(); this.LastTimeSync = StockService.GetLastTimeSynchronized(symbol_id); }
private static ctaCOMMON.Charts.Symbol GetSymbol(int portfolio_id, int symbol_id, ChartRange chartRange, CandelRange candelRange, bool withQuotes) { if (DashBoardCache != null && DashBoardCache.DashboardItems.Count > 0 && false) { var symbol = DashBoardCache.DashboardItems.Where(x => x.Portfolio_Id == portfolio_id) .SelectMany(x => x.Symbols) .Where(x => x.Symbol_ID == symbol_id) .FirstOrDefault(); return(symbol); } else { ctaCOMMON.Charts.Symbol symbol = new ctaCOMMON.Charts.Symbol(); using (ctaDBEntities entities = new ctaDBEntities()) { entities.Database.Connection.Open(); string user_type = (portfolio_id == 0) ? "FREE" : entities.Portfolios.Where(p => p.Id == portfolio_id).Select(p => p.Tenant.Tenant_Type.Name).First(); var stock_entity = entities.Stocks.Where(s => s.Id == symbol_id).First(); symbol.Portfolio_ID = portfolio_id; symbol.Symbol_ID = stock_entity.Id; symbol.Symbol_Name = stock_entity.symbol; symbol.Symbol_Company_Name = stock_entity.name; symbol.Symbol_Market_ID = stock_entity.market_id; symbol.Symbol_Market = stock_entity.Market.name; symbol.Intradiary_Info = QuotesService.GetSymbolIntradiaryInfo(symbol_id); if (withQuotes) { symbol.Quotes = QuotesService.GetSymbolQuotes(symbol.Symbol_ID, chartRange, candelRange, user_type); } entities.Database.Connection.Close(); } return(symbol); } }
private static List <Chart_Indicator> GetSymbolIndicators(ctaCOMMON.Charts.Symbol symbol, int indicatorsCount, bool initializeFromDatabase, CandelRange candelRange, out bool indicatorUpdate) { List <Chart_Indicator> indicators = new List <Chart_Indicator>(); indicatorUpdate = false; using (ctaDBEntities entities = new ctaDBEntities()) { entities.Database.Connection.Open(); var indicators_entities = entities.Portfolio_Stock_Indicator.Where(psi => psi.portfolio_id == symbol.Portfolio_ID && psi.stock_id == symbol.Symbol_ID); if (indicators_entities.Count() != indicatorsCount) { indicatorUpdate = true; foreach (var indicator_entitie in indicators_entities) { Chart_Indicator indicator = Chart_Indicator_Builder.BuildIndicatorInstance(indicator_entitie.Indicator.name); indicator.ID = indicator_entitie.Id; if (initializeFromDatabase) { indicator.InitializeFromDataBaseValues(symbol.Quotes, indicator_entitie.param1, indicator_entitie.color1, indicator_entitie.param2, indicator_entitie.color2, indicator_entitie.param3, indicator_entitie.color3, candelRange); } indicators.Add(indicator); } } entities.Database.Connection.Close(); } return(indicators); }
public static SymbolDashboard GetSymbolDashboard(int portfolio_id, int symbol_id, ChartRange chartRange, CandelRange candelRange, bool withQuotes) { bool indicatorUpdate, shapeUpdate; if (SymbolDashboardCache != null && SymbolDashboardCache.Portfolio_Id == portfolio_id && SymbolDashboardCache.Symbol_Id == symbol_id && false) { var indicators = DashboardService.GetSymbolIndicators(SymbolDashboardCache.Symbol, SymbolDashboardCache.Indicators.Count(), withQuotes, candelRange, out indicatorUpdate); var shapes = DashboardService.GetSymbolShapes(SymbolDashboardCache.Symbol, SymbolDashboardCache.Shapes.Count(), withQuotes, out shapeUpdate); SymbolDashboardCache.Indicators = indicatorUpdate ? indicators : SymbolDashboardCache.Indicators; SymbolDashboardCache.Shapes = shapeUpdate ? shapes : SymbolDashboardCache.Shapes; return(SymbolDashboardCache); } else { SymbolDashboard symbol_dashboard = new SymbolDashboard() { Portfolio_Id = portfolio_id, Symbol_Id = symbol_id }; symbol_dashboard.Symbol = DashboardService.GetSymbol(portfolio_id, symbol_id, chartRange, candelRange, withQuotes); symbol_dashboard.Indicators = DashboardService.GetSymbolIndicators(symbol_dashboard.Symbol, -1, withQuotes, candelRange, out indicatorUpdate); symbol_dashboard.Shapes = DashboardService.GetSymbolShapes(symbol_dashboard.Symbol, -1, withQuotes, out shapeUpdate); SymbolDashboardCache = symbol_dashboard; return(symbol_dashboard); } }