HippoEngine en = new HippoEngine();
en.DataType = DataSourceType.Excel;
en.Query = "select * from [삼성전자2$]";
en.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`C:\삼성전자2.xlsx`;Extended Properties=`Excel 12.0;HDR=YES`";
SeriesList sList = en.GetSeriesListOfStock(DataSourceType.Excel, "Date", "Start", "Close", "Low", "High");
sList.AxisFactor.YAxis.Direction = AxisDirection.Right;
sList.AxisFactor.YAxis.IsZeroStartScale = false;
sList.GraphArea.Grid.IsBackGridColor = false;
sList.AxisFactor.AxisItems.Add(new Axis(AxisType.Ytype));
sList.AxisFactor.AxisItems[0].Decimalpoint = 0;
// MACD
sList.SeriesCollection.Add(new Series());
sList.SeriesCollection[1].ChartType = ChartType.Line;
sList.SeriesCollection[1].Points.Width = 0;
sList.SeriesCollection[1].Line.LineWidth = 2;
sList.SeriesCollection[1].SeriesColor = Color.Gray;
sList.SeriesCollection[1].AxisIndex = 1;
// Signal
sList.SeriesCollection.Add(new Series());
sList.SeriesCollection[2].ChartType = ChartType.Line;
sList.SeriesCollection[2].Points.Width = 0;
sList.SeriesCollection[2].Line.LineWidth = 2;
sList.SeriesCollection[2].SeriesColor = Color.Red;
sList.SeriesCollection[2].AxisIndex = 1;
// Oscilator
sList.SeriesCollection.Add(new Series());
sList.SeriesCollection[3].ChartType = ChartType.Column;
sList.SeriesCollection[3].SeriesColor = Color.SkyBlue;
sList.SeriesCollection[3].AxisIndex = 1;
int nCnt = sList.SeriesCollection[0].items.Count;
double EP12 = 0.15384615;
double EP26 = 0.07407407;
double EP9 = 0.2;
double preClose12 = 0;
double preClose26 = 0;
double preClose9 = 0;
// 12일선, 26일선
SortedListSeriesItem> items12 = new SortedListSeriesItem>();
SortedListSeriesItem> items26 = new SortedListSeriesItem>();
// 12, 26일 지수이동평균선 구하기
for(int i = 0; i < nCnt; i++)
{
SeriesItem item12 = new SeriesItem();
item12.Name = sList.SeriesCollection[0].items[i].Name;
try
{
double close = sList.SeriesCollection[0].items[i].YValue;
double exMV = close * EP12 + preClose12 * (1 - EP12);
item12.YValue = exMV;
preClose12 = exMV;
}
catch
{
item12.YValue = double.NaN;
}
items12.Add(i, item12);
SeriesItem item26 = new SeriesItem();
item26.Name = sList.SeriesCollection[0].items[i].Name;
try
{
double close = sList.SeriesCollection[0].items[i].YValue;
double exMV = close * EP26 + preClose26 * (1 - EP26);
item26.YValue = exMV;
preClose26 = exMV;
}
catch
{
item26.YValue = double.NaN;
}
items26.Add(i, item26);
}
//MACD
for(int i = 0; i < nCnt; i++)
{
SeriesItem itemMACD = new SeriesItem();
try
{
itemMACD.YValue = items12[i].YValue - items26[i].YValue;
}
catch
{
itemMACD.YValue = double.NaN;
}
sList.SeriesCollection[1].items.Add(itemMACD);
SeriesItem item9 = new SeriesItem();
try
{
double close = sList.SeriesCollection[1].items[i].YValue;
double exMV = close * EP9 + preClose9 * (1 - EP9);
item9.YValue = exMV;
preClose9 = exMV;
}
catch
{
item9.YValue = double.NaN;
}
sList.SeriesCollection[2].items.Add(item9);
SeriesItem itemOSC = new SeriesItem();
try
{
itemOSC.YValue = sList.SeriesCollection[1].items[i].YValue - sList.SeriesCollection[2].items[i].YValue;
if (itemOSC.YValue > 0)
{
itemOSC.ItemColor = Color.Red;
}
else
{
itemOSC.ItemColor = Color.SkyBlue;
}
}
catch { itemOSC.YValue = double.NaN; }
sList.SeriesCollection[3].items.Add(itemOSC);
}
this.hHippoChart1.Designer.InnerBackColor = Color.FromArgb(214, 226, 239);
this.hHippoChart1.Titles.Label.Text = "히포차트 주식 - MACD, Signal, Oscilator";
this.hHippoChart1.LegendBox.Visible = false;
this.hHippoChart1.SeriesListDictionary.Add(sList);
this.hHippoChart1.DrawChart();
Dim en As New. HippoEngine()
en.DataType = DataSourceType.Excel
en.Query = "select * from [삼성전자2$]"
en.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`C:\삼성전자2.xlsx`;Extended Properties=`Excel 12.0;HDR=YES`"
Dim sList As SeriesList = en.GetSeriesListOfStock(DataSourceType.Excel, "Date", "Start", "Close", "Low", "High")
sList.AxisFactor.YAxis.Direction = AxisDirection.Right
sList.AxisFactor.YAxis.IsZeroStartScale = False
sList.GraphArea.Grid.IsBackGridColor = False
sList.AxisFactor.AxisItems.Add(New Axis(AxisType.Ytype))
sList.AxisFactor.AxisItems(0).Decimalpoint = 0
` MACD
sList.SeriesCollection.Add(New Series())
sList.SeriesCollection(1).ChartType = ChartType.Line
sList.SeriesCollection(1).Points.Width = 0
sList.SeriesCollection(1).Line.LineWidth = 2
sList.SeriesCollection(1).SeriesColor = Color.Gray
sList.SeriesCollection(1).AxisIndex = 1
` Signal
sList.SeriesCollection.Add(New Series())
sList.SeriesCollection(2).ChartType = ChartType.Line
sList.SeriesCollection(2).Points.Width = 0
sList.SeriesCollection(2).Line.LineWidth = 2
sList.SeriesCollection(2).SeriesColor = Color.Red
sList.SeriesCollection(2).AxisIndex = 1
` Oscilator
sList.SeriesCollection.Add(New Series())
sList.SeriesCollection(3).ChartType = ChartType.Column
sList.SeriesCollection(3).SeriesColor = Color.SkyBlue
sList.SeriesCollection(3).AxisIndex = 1
Dim nCnt As Integer = sList.SeriesCollection(0).items.Count
Dim EP12 As Double = 0.15384615
Dim EP26 As Double = 0.07407407
Dim EP9 As Double = 0.2
Dim preClose12 As Double = 0
Dim preClose26 As Double = 0
Dim preClose9 As Double = 0
` 12일선, 26일선
Dim items12 As New. SortedList(Of Integer, SeriesItem)()
Dim items26 As New. SortedList(Of Integer, SeriesItem)()
` 12, 26일 지수이동평균선 구하기
For i As Integer = 0 To nCnt - 1
Dim item12 As New. SeriesItem()
item12.Name = sList.SeriesCollection(0).items(i).Name
Try
Dim close As Double = sList.SeriesCollection(0).items(i).YValue
Dim exMV As Double = close * EP12 + preClose12 * (1 - EP12)
item12.YValue = exMV
preClose12 = exMV
Catch
item12.YValue = Double.NaN
End Try
items12.Add(i, item12)
Dim item26 As New. SeriesItem()
item26.Name = sList.SeriesCollection(0).items(i).Name
Try
Dim close As Double = sList.SeriesCollection(0).items(i).YValue
Dim exMV As Double = close * EP26 + preClose26 * (1 - EP26)
item26.YValue = exMV
preClose26 = exMV
Catch
item26.YValue = Double.NaN
End Try
items26.Add(i, item26)
Next
`MACD
For i As Integer = 0 To nCnt - 1
Dim itemMACD As New. SeriesItem()
Try
itemMACD.YValue = items12(i).YValue - items26(i).YValue
Catch
itemMACD.YValue = Double.NaN
End Try
sList.SeriesCollection(1).items.Add(itemMACD)
Dim item9 As New. SeriesItem()
Try
Dim close As Double = sList.SeriesCollection(1).items(i).YValue
Dim exMV As Double = close * EP9 + preClose9 * (1 - EP9)
item9.YValue = exMV
preClose9 = exMV
Catch
item9.YValue = Double.NaN
End Try
sList.SeriesCollection(2).items.Add(item9)
Dim itemOSC As New. SeriesItem()
Try
itemOSC.YValue = sList.SeriesCollection(1).items(i).YValue - sList.SeriesCollection(2).items(i).YValue
If itemOSC.YValue > 0 Then
itemOSC.ItemColor = Color.Red
Else
itemOSC.ItemColor = Color.SkyBlue
End If
Catch
itemOSC.YValue = Double.NaN
End Try
sList.SeriesCollection(3).items.Add(itemOSC)
Next
Me.hHippoChart1.Designer.InnerBackColor = Color.FromArgb(214, 226, 239)
Me.hHippoChart1.Titles.Label.Text = "히포차트 주식 - MACD, Signal, Oscilator"
Me.hHippoChart1.LegendBox.Visible = False
Me.hHippoChart1.SeriesListDictionary.Add(sList)
Me.hHippoChart1.DrawChart()