-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
77 lines (69 loc) · 2.96 KB
/
Form1.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
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
namespace LegendsSamples {
public partial class Form1 : Form {
Series financialSeries;
Series FinancialSeries {
get {
if (financialSeries == null)
financialSeries = chart.GetSeriesByName("AUDUSD Daily");
return financialSeries;
}
}
public Form1() {
InitializeComponent();
InitializeChart();
}
private void Form1_Load(object sender, EventArgs e) {
// Get several required objects.
XYDiagram diagram = chart.Diagram as XYDiagram;
if(diagram == null) return;
FinancialSeriesViewBase view = FinancialSeries.View as FinancialSeriesViewBase;
if(view == null) return;
Indicator macd = view.Indicators.GetElementByName("MACD") as Indicator;
#region #AddAdditionalLegend
// Create a new instance of Legend.
Legend macdLegend = new Legend();
chart.Legends.Add(macdLegend);
// Position it.
macdLegend.DockTarget = diagram.Panes.GetPaneByName("macdPane");
macdLegend.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
macdLegend.AlignmentVertical = LegendAlignmentVertical.Top;
// Assign the data displayed in legend.
macd.Legend = macdLegend;
#endregion #AddAdditionalLegend
}
void InitializeChart() {
FinancialSeries.DataSource = LoadData();
FinancialSeries.ArgumentDataMember = "Argument";
FinancialSeries.ValueDataMembers.AddRange("LowValue", "HighValue", "OpenValue", "CloseValue");
}
List<DataPoint> LoadData() {
List<DataPoint> result = new List<DataPoint>();
StreamReader reader = new StreamReader("Data\\AUDUSDDaily.csv");
while(!reader.EndOfStream) {
string line = reader.ReadLine();
var values = line.Split(',');
var point = new DataPoint();
point.Argument = DateTime.ParseExact(values[0], "yyyy.MM.dd", null);
point.OpenValue = double.Parse(values[1], CultureInfo.InvariantCulture);
point.HighValue = double.Parse(values[2], CultureInfo.InvariantCulture);
point.LowValue = double.Parse(values[3], CultureInfo.InvariantCulture);
point.CloseValue = double.Parse(values[4], CultureInfo.InvariantCulture);
result.Add(point);
}
return result;
}
class DataPoint {
public DateTime Argument { get; set; }
public double LowValue { get; set; }
public double HighValue { get; set; }
public double OpenValue { get; set; }
public double CloseValue { get; set; }
}
}
}