public bool downloadSMA(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlSMA_Interval.SelectedValue; string period = textboxSMA_Period.Text; string series = ddlSMA_Series.SelectedValue; if (StockApi.getSMA(folderPath, scriptName, day_interval: interval, period: period, seriestype: series, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('SMA data not available for selected script.')</script>"); return(false); } return(true); }
public void ShowGraph(string scriptName) { string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; DataTable scriptData = null; DataTable tempData = null; string expression = ""; string period = ""; string seriesType = ""; string interval = ""; string fromDate = "", toDate = ""; DataRow[] filteredRows = null; if (ViewState["FetchedData"] == null) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolder"] != null) { folderPath = Session["TestDataFolder"].ToString(); } if ((Request.QueryString["period"] != null) && (Request.QueryString["interval"] != null) && (Request.QueryString["seriestype"] != null)) { interval = Request.QueryString["interval"]; period = Request.QueryString["period"].ToString(); seriesType = Request.QueryString["seriestype"].ToString(); scriptData = StockApi.getSMA(folderPath, scriptName, day_interval: interval, period: period, seriestype: seriesType, bIsTestModeOn: bIsTestOn, bSaveData: false); } ViewState["FetchedData"] = scriptData; } else { if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { scriptData = filteredRows.CopyToDataTable(); } } else { scriptData = (DataTable)ViewState["FetchedData"]; } } if (scriptData != null) { ////time,Real Lower Band,Real Middle Band,Real Upper Band /// (chartSMA.Series["seriesSMA"]).XValueMember = "Date"; (chartSMA.Series["seriesSMA"]).XValueType = ChartValueType.Date; (chartSMA.Series["seriesSMA"]).YValueMembers = "SMA"; //(chartSMA.Series["seriesSMA"]).ToolTip = "SMA: Date:#VALX; Value:#VALY"; chartSMA.ChartAreas["chartareaSMA"].AxisX.Title = "Date"; chartSMA.ChartAreas["chartareaSMA"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center; chartSMA.ChartAreas["chartareaSMA"].AxisY.Title = "Value"; chartSMA.ChartAreas["chartareaSMA"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center; //chartSMA.Titles["titleSMA"].Text = $"{"Simple Moving Average - "}{scriptName}"; if (chartSMA.Annotations.Count > 0) { chartSMA.Annotations.Clear(); } chartSMA.DataSource = scriptData; chartSMA.DataBind(); } }
public void ShowGraph(string scriptName) { string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; DataTable ohlcData = null; DataTable sma1Data = null; DataTable sma2Data = null; DataTable tempData = null; string expression = ""; string outputSize = ""; string interval1 = ""; string period1 = ""; string seriestype1 = ""; string interval2 = ""; string period2 = ""; string seriestype2 = ""; string fromDate = "", toDate = ""; DataRow[] filteredRows = null; if (((ViewState["FetchedDataOHLC"] == null) || (ViewState["FetchedDataSMA1"] == null) || (ViewState["FetchedDataSMA2"] == null)) || ((((DataTable)ViewState["FetchedDataOHLC"]).Rows.Count == 0) || (((DataTable)ViewState["FetchedDataSMA1"]).Rows.Count == 0) || (((DataTable)ViewState["FetchedDataSMA2"]).Rows.Count == 0))) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolder"] != null) { folderPath = Session["TestDataFolder"].ToString(); } if (Request.QueryString["size"] != null) { outputSize = Request.QueryString["size"].ToString(); ohlcData = StockApi.getDaily(folderPath, scriptName, outputsize: outputSize, bIsTestModeOn: bIsTestOn, bSaveData: false); ViewState["FetchedDataOHLC"] = ohlcData; } else { ViewState["FetchedDataOHLC"] = null; ohlcData = null; } if ((Request.QueryString["period1"] != null) && (Request.QueryString["interval1"] != null) && (Request.QueryString["seriestype1"] != null)) { interval1 = Request.QueryString["interval1"].ToString(); period1 = Request.QueryString["period1"].ToString(); seriestype1 = Request.QueryString["seriestype1"].ToString(); sma1Data = StockApi.getSMA(folderPath, scriptName, day_interval: interval1, period: period1, seriestype: seriestype1, bIsTestModeOn: bIsTestOn, bSaveData: false); ViewState["FetchedDataSMA1"] = sma1Data; } else { ViewState["FetchedDataSMA1"] = null; sma1Data = null; } if ((Request.QueryString["period2"] != null) && (Request.QueryString["interval2"] != null) && (Request.QueryString["seriestype2"] != null)) { interval2 = Request.QueryString["interval2"].ToString(); period2 = Request.QueryString["period2"].ToString(); seriestype2 = Request.QueryString["seriestype2"].ToString(); sma2Data = StockApi.getSMA(folderPath, scriptName, day_interval: interval2, period: period2, seriestype: seriestype2, bIsTestModeOn: bIsTestOn, bSaveData: false); ViewState["FetchedDataSMA2"] = sma2Data; } else { ViewState["FetchedDataSMA2"] = null; sma2Data = null; } } //else //{ if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedDataOHLC"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { ohlcData = filteredRows.CopyToDataTable(); } tempData.Clear(); tempData = null; tempData = (DataTable)ViewState["FetchedDataSMA1"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { sma1Data = filteredRows.CopyToDataTable(); } tempData.Clear(); tempData = null; tempData = (DataTable)ViewState["FetchedDataSMA2"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { sma2Data = filteredRows.CopyToDataTable(); } } else { ohlcData = (DataTable)ViewState["FetchedDataOHLC"]; sma1Data = (DataTable)ViewState["FetchedDataSMA1"]; sma2Data = (DataTable)ViewState["FetchedDataSMA2"]; } //} if ((ohlcData != null) && (sma1Data != null) && (sma2Data != null)) { showCandleStickGraph(ohlcData); showSMA(sma1Data, "SMA1"); showSMA(sma2Data, "SMA2"); } }