-
Notifications
You must be signed in to change notification settings - Fork 7
/
adx.aspx.cs
169 lines (147 loc) · 6.61 KB
/
adx.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
namespace Analytics
{
public partial class adx : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["FromDate"] = null;
ViewState["ToDate"] = null;
ViewState["FetchedData"] = null;
}
if (Request.QueryString["script"] != null)
{
ShowGraph(Request.QueryString["script"].ToString());
headingtext.InnerText = "Average directional movement index:" + Request.QueryString["script"].ToString();
if (panelWidth.Value != "" && panelHeight.Value != "")
{
chartADX.Visible = true;
chartADX.Width = int.Parse(panelWidth.Value);
chartADX.Height = int.Parse(panelHeight.Value);
}
}
else
{
Response.Redirect(".\\" + Request.QueryString["parent"].ToString());
}
}
public void ShowGraph(string scriptName)
{
string folderPath = Server.MapPath("~/scriptdata/");
bool bIsTestOn = true;
DataTable scriptData = null;
DataTable tempData = null;
string expression = "";
string interval = "";
string period = "";
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["interval"] != null) && (Request.QueryString["period"] != null))
{
interval = Request.QueryString["interval"];
period = Request.QueryString["period"];
scriptData = StockApi.getADX(folderPath, scriptName, day_interval: interval, period: period,
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
///
(chartADX.Series["seriesADX"]).XValueMember = "Date";
(chartADX.Series["seriesADX"]).XValueType = ChartValueType.Date;
(chartADX.Series["seriesADX"]).YValueMembers = "ADX";
//(chartADX.Series["seriesADX"]).ToolTip = "ADX: Date:#VALX; Value:#VALY";
chartADX.ChartAreas["chartareaADX"].AxisX.Title = "Date";
chartADX.ChartAreas["chartareaADX"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center;
chartADX.ChartAreas["chartareaADX"].AxisY.Title = "Value";
chartADX.ChartAreas["chartareaADX"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center;
//chartADX.Titles["titleADX"].Text = $"{"Average Directional Movement Index- "}{scriptName}";
if (chartADX.Annotations.Count > 0)
chartADX.Annotations.Clear();
chartADX.DataSource = scriptData;
chartADX.DataBind();
}
}
protected void chartADX_Click(object sender, ImageMapEventArgs e)
{
DateTime xDate = System.Convert.ToDateTime(e.PostBackValue.Split(',')[0]);
double lineWidth = xDate.ToOADate();
double lineHeight = System.Convert.ToDouble(e.PostBackValue.Split(',')[1]);
//double lineHeight = -35;
if (chartADX.Annotations.Count > 0)
chartADX.Annotations.Clear();
HorizontalLineAnnotation HA = new HorizontalLineAnnotation();
HA.AxisX = chartADX.ChartAreas[0].AxisX;
HA.AxisY = chartADX.ChartAreas[0].AxisY;
HA.IsSizeAlwaysRelative = false;
HA.AnchorY = lineHeight;
HA.IsInfinitive = true;
HA.ClipToChartArea = chartADX.ChartAreas[0].Name;
HA.LineDashStyle = ChartDashStyle.Dash;
HA.LineColor = Color.Red;
HA.LineWidth = 1;
chartADX.Annotations.Add(HA);
VerticalLineAnnotation VA = new VerticalLineAnnotation();
VA.AxisX = chartADX.ChartAreas[0].AxisX;
VA.AxisY = chartADX.ChartAreas[0].AxisY;
VA.IsSizeAlwaysRelative = false;
VA.AnchorX = lineWidth;
VA.IsInfinitive = true;
VA.ClipToChartArea = chartADX.ChartAreas[0].Name;
VA.LineDashStyle = ChartDashStyle.Dash;
VA.LineColor = Color.Red;
VA.LineWidth = 1;
chartADX.Annotations.Add(VA);
}
protected void buttonShowGraph_Click(object sender, EventArgs e)
{
string fromDate = textboxFromDate.Text;
string toDate = textboxToDate.Text;
string scriptName = Request.QueryString["script"].ToString();
ViewState["FromDate"] = textboxFromDate.Text;
ViewState["ToDate"] = textboxToDate.Text;
ShowGraph(scriptName);
}
}
}