//月K線圖 public void add_monthly_candlestick_chart() { Debug.error(this, debug_level, "add_monthly_candlestick_chart"); decimal highest_price = 0; decimal lowest_price = 9999; decimal opening_price = 0; decimal closing_price = 0; decimal trade_value = 0; for (DateTime date = start_date; date.Date <= end_date; date = date.AddDays(1)) { string key = date.Year.ToString() + date.Month.ToString("00") + date.Day.ToString("00"); string TWSE_working_date_key = date.Year.ToString() + "/" + date.Month.ToString("00"); string stock_key = security_code.ToString() + key; if (stock_dictionary.TWSE_daily_trading_value.ContainsKey(key))//開盤日 { if (stock_dictionary.stock_daily_trading_value.ContainsKey(stock_key))//該個股有資料 { //取最高價 if (highest_price < decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].highest_price)) { highest_price = decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].highest_price); } //取最低價 if (lowest_price > decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].lowest_price)) { lowest_price = decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].lowest_price); } //取開盤價 if (opening_price == 0)//取第一個值 { opening_price = decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].opening_price); } //取收盤價 closing_price = decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].closing_price);//取最後一個值 //成交價 trade_value = trade_value + decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].trade_value); } } //這個月的最後一天或最後一天結算 if (date.Month != date.AddDays(1).Month || date == DateTime.Today) { candlestick_content child = new candlestick_content(); int working_day = stock_dictionary.TWSE_working_date_information[TWSE_working_date_key].working_days; int non_working_day = stock_dictionary.TWSE_working_date_information[TWSE_working_date_key].non_working_days; if (opening_price != 0) { //開盤 最高 最低 收盤 chart最上面的值 chart最底部的值 child.set_value(stock_key, opening_price, highest_price, lowest_price, closing_price, max_price, min_price); } else//沒取到開盤價 代表載入日期剛好碰到都是假日 { child.set_value(stock_key, 0, 0, 0, 0, max_price, min_price); } child.trade_value = trade_value; child.date = date; child.Width = config.width_of_value_in_chart * working_day + config.width_of_empty_date_in_chart * non_working_day; stackPanel1.Children.Insert(0, child); //歸零 opening_price = 0;//要歸零給下一個月去判斷是否要取值 lowest_price = 9999; highest_price = 0; trade_value = 0; } }//end of loop Debug.error(this, debug_level, "add_monthly_candlestick_chart X"); }
//日K線圖 public void add_daily_candlestick_chart() { Debug.error(this, debug_level, "add_daily_candlestick_chart"); for (DateTime date = start_date; date.Date <= end_date; date = date.AddDays(1)) { string TWSE_key = date.Year.ToString() + date.Month.ToString("00") + date.Day.ToString("00"); string stock_key = security_code.ToString() + TWSE_key; candlestick_content child = new candlestick_content(); if (stock_dictionary.TWSE_daily_trading_value.ContainsKey(TWSE_key) && stock_dictionary.stock_daily_trading_value.ContainsKey(stock_key))//開盤日 and 該個股有資料 { //開盤 最高 最低 收盤 chart最上面的值 chart最底部的值 child.set_value(stock_key, decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].opening_price), decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].highest_price), decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].lowest_price), decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].closing_price), max_price, min_price); child.trade_value = decimal.Parse(stock_dictionary.stock_daily_trading_value[stock_key].trade_value); child.Width = config.width_of_value_in_chart; //判斷是否加入 除權息 增資 減資 事件 string public_subscription_key = date.Year.ToString() + date.Month.ToString("00") + date.Day.ToString("00") + security_code; string capital_reduction_key = date.Year.ToString() + date.Month.ToString("00") + date.Day.ToString("00") + security_code; string DR_announcement_key = security_code + date.Year.ToString() + date.Month.ToString("00") + date.Day.ToString("00"); //除權息 if (stock_dictionary.DR_announcement_dictionary.ContainsKey(DR_announcement_key)) { if (stock_dictionary.DR_announcement_dictionary[DR_announcement_key].XR_or_XD.Contains("息")) { Image img = new Image(); img.Source = new BitmapImage(new Uri(Path.system_image_directory_path + "DR_announcement_XD.png", UriKind.Absolute)); child.stackpanel_stock_event.Children.Add(img); } if (stock_dictionary.DR_announcement_dictionary[DR_announcement_key].XR_or_XD.Contains("權")) { Image img = new Image(); img.Source = new BitmapImage(new Uri(Path.system_image_directory_path + "DR_announcement_XR.png", UriKind.Absolute)); child.stackpanel_stock_event.Children.Add(img); } } //增資 if (stock_dictionary.public_subscription_dictionary.ContainsKey(public_subscription_key)) { Image img = new Image(); img.Source = new BitmapImage(new Uri(Path.system_image_directory_path + "pic_public_subscription.png", UriKind.Absolute)); child.stackpanel_stock_event.Children.Add(img); } //減資 if (stock_dictionary.capital_reduction_dictionary.ContainsKey(capital_reduction_key)) { Image img = new Image(); img.Source = new BitmapImage(new Uri(Path.system_image_directory_path + "pic_capital_reduction.png", UriKind.Absolute)); child.stackpanel_stock_event.Children.Add(img); } } else//非營業日 { child.set_value(stock_key, 0, 0, 0, 0, max_price, min_price); child.Width = config.width_of_empty_date_in_chart; } child.date = date; stackPanel1.Children.Insert(0, child); }//end of loop Debug.error(this, debug_level, "add_daily_candlestick_chart X"); }