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;
// 20일 이동평균선
sList.SeriesCollection.Add(new Series());
sList.SeriesCollection[1].ChartType = ChartType.Line;
sList.SeriesCollection[1].Points.Width = 0;
sList.SeriesCollection[1].Line.LineWidth = 2;
// 볼린저밴드 top
sList.SeriesCollection.Add(new Series());
sList.SeriesCollection[2].ChartType = ChartType.Line;
sList.SeriesCollection[2].Points.Width = 0;
sList.SeriesCollection[2].Line.LineWidth = 2;
// 볼린저밴드 bottom
sList.SeriesCollection.Add(new Series());
sList.SeriesCollection[3].ChartType = ChartType.Line;
sList.SeriesCollection[3].Points.Width = 0;
sList.SeriesCollection[3].Line.LineWidth = 2;
int nCnt = sList.SeriesCollection[0].items.Count;
for(int i = 0; i < nCnt; i++)
{
SeriesItem item20 = new SeriesItem();
item20.Name = sList.SeriesCollection[0].items[i].Name;
// 볼린저밴드 상한선
SeriesItem itemBB = new SeriesItem();
itemBB.Name = sList.SeriesCollection[0].items[i].Name;
// 볼린저밴드 하한선
SeriesItem itemBB2 = new SeriesItem();
itemBB2.Name = sList.SeriesCollection[0].items[i].Name;
try
{
double sum = 0;
for(int a = 0; a < 20; a++)
{
sum += sList.SeriesCollection[0].items[i - a].YValue;
}
double avg = sum / 20;
double SD_sum = 0;
// 표준편차
double SD = 0;
// 분산
double Variance = 0;
for(int a = 0; a < 20; a++)
{
SD_sum += Math.Pow(sList.SeriesCollection[0].items[i - a].YValue - avg, 2);
}
Variance = SD_sum / 20;
SD = Math.Sqrt(Variance);
item20.YValue = sum / 20;
itemBB.YValue = item20.YValue + SD * 2;
itemBB2.YValue = item20.YValue - SD * 2;
}
catch
{
item20.YValue = double.NaN;
itemBB.YValue = double.NaN;
itemBB2.YValue = double.NaN;
}
sList.SeriesCollection[1].items.Add(item20);
sList.SeriesCollection[2].items.Add(itemBB);
sList.SeriesCollection[3].items.Add(itemBB2);
}
this.hHippoChart1.Designer.InnerBackColor = Color.FromArgb(214, 226, 239);
this.hHippoChart1.Titles.Label.Text = "히포차트 주식 - 볼린저밴드";
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
` 20일 이동평균선
sList.SeriesCollection.Add(New Series())
sList.SeriesCollection(1).ChartType = ChartType.Line
sList.SeriesCollection(1).Points.Width = 0
sList.SeriesCollection(1).Line.LineWidth = 2
` 볼린저밴드 top
sList.SeriesCollection.Add(New Series())
sList.SeriesCollection(2).ChartType = ChartType.Line
sList.SeriesCollection(2).Points.Width = 0
sList.SeriesCollection(2).Line.LineWidth = 2
` 볼린저밴드 bottom
sList.SeriesCollection.Add(New Series())
sList.SeriesCollection(3).ChartType = ChartType.Line
sList.SeriesCollection(3).Points.Width = 0
sList.SeriesCollection(3).Line.LineWidth = 2
Dim nCnt As Integer = sList.SeriesCollection(0).items.Count
For i As Integer = 0 To nCnt - 1
Dim item20 As New. SeriesItem()
item20.Name = sList.SeriesCollection(0).items(i).Name
` 볼린저밴드 상한선
Dim itemBB As New. SeriesItem()
itemBB.Name = sList.SeriesCollection(0).items(i).Name
` 볼린저밴드 하한선
Dim itemBB2 As New. SeriesItem()
itemBB2.Name = sList.SeriesCollection(0).items(i).Name
Try
Dim sum As Double = 0
For a As Integer = 0 To 19
sum += sList.SeriesCollection(0).items(i - a).YValue
Next
Dim avg As Double = sum / 20
Dim SD_sum As Double = 0
` 표준편차
Dim SD As Double = 0
` 분산
Dim Variance As Double = 0
For a As Integer = 0 To 19
SD_sum += Math.Pow(sList.SeriesCollection(0).items(i - a).YValue - avg, 2)
Next
Variance = SD_sum / 20
SD = Math.Sqrt(Variance)
item20.YValue = sum / 20
itemBB.YValue = item20.YValue + SD * 2
itemBB2.YValue = item20.YValue - SD * 2
Catch
item20.YValue = Double.NaN
itemBB.YValue = Double.NaN
itemBB2.YValue = Double.NaN
End Try
sList.SeriesCollection(1).items.Add(item20)
sList.SeriesCollection(2).items.Add(itemBB)
sList.SeriesCollection(3).items.Add(itemBB2)
Next
Me.hHippoChart1.Designer.InnerBackColor = Color.FromArgb(214, 226, 239)
Me.hHippoChart1.Titles.Label.Text = "히포차트 주식 - 볼린저밴드"
Me.hHippoChart1.LegendBox.Visible = False
Me.hHippoChart1.SeriesListDictionary.Add(sList)
Me.hHippoChart1.DrawChart()