C# MSChart 蜡烛图移动平均线图表。错误:公式错误 - 该期间没有足够的数据点
您不能对自己的帖子进行投票 0
我正在尝试根据每日数据创建带有 MA(15) 的股票蜡烛。
我可以使用 OHLC 条创建图表,没有任何问题。
但是,当我开始使用 DataManipulator.FinancialFormula 进行 MA 时,我不断收到“公式错误 - 该期间没有足够的数据点”的错误。
有人可以帮我解决这个问题吗?谢谢
这是代码。
DataSet ds = new DataSet();
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=XXX;Database=Stock;Integrated Security=SSPI;";
connection.Open();
string sql = "Select datestamp, highprice, lowprice,openprice, closeprice from daymarketdata where tickname='GS' and datestamp>'1/1/2011' order by datestamp asc";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sa = new SqlDataAdapter();
sa.SelectCommand = cmd;
sa.Fill(ds, "Cos");
connection.Close();
chart1.Series["Daily"].ChartType = SeriesChartType.Candlestick;
chart1.DataSource = sa;
chart1.DataBind();
chart1.Series["Daily"].XValueMember = "DateStamp";
chart1.Series["Daily"].YValueMembers = "HighPrice, LowPrice, OpenPrice, ClosePrice";
chart1.Series["Daily"].IsXValueIndexed = true;
chart1.Series["Daily"].BorderColor = System.Drawing.Color.Black;
chart1.Series["Daily"].Color = System.Drawing.Color.Black;
chart1.Series["Daily"].CustomProperties = "PriceDownColor=Green, PriceUpColor=Red";
chart1.Series["Daily"].XValueType = ChartValueType.Date;
chart1.ChartAreas[0].AxisY.Minimum = 100;
chart1.ChartAreas[0].AxisY.Maximum = 180;
chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "15", "Daily", "MA");
You cannot vote on your own post
0
I am trying to create a stock candle with MA(15) on daily data.
I can create a chart with OHLC bar without any problem.
But when I started usingDataManipulator.FinancialFormula for MA, I keep getting errors of "Formula error - There are not enough data points for the Period."
Can someone help me out on this? Thanks
Here is the code.
DataSet ds = new DataSet();
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=XXX;Database=Stock;Integrated Security=SSPI;";
connection.Open();
string sql = "Select datestamp, highprice, lowprice,openprice, closeprice from daymarketdata where tickname='GS' and datestamp>'1/1/2011' order by datestamp asc";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sa = new SqlDataAdapter();
sa.SelectCommand = cmd;
sa.Fill(ds, "Cos");
connection.Close();
chart1.Series["Daily"].ChartType = SeriesChartType.Candlestick;
chart1.DataSource = sa;
chart1.DataBind();
chart1.Series["Daily"].XValueMember = "DateStamp";
chart1.Series["Daily"].YValueMembers = "HighPrice, LowPrice, OpenPrice, ClosePrice";
chart1.Series["Daily"].IsXValueIndexed = true;
chart1.Series["Daily"].BorderColor = System.Drawing.Color.Black;
chart1.Series["Daily"].Color = System.Drawing.Color.Black;
chart1.Series["Daily"].CustomProperties = "PriceDownColor=Green, PriceUpColor=Red";
chart1.Series["Daily"].XValueType = ChartValueType.Date;
chart1.ChartAreas[0].AxisY.Minimum = 100;
chart1.ChartAreas[0].AxisY.Maximum = 180;
chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "15", "Daily", "MA");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我已经很老了,但我想我会留下我的贡献,因为我正在与这个问题作斗争。
相同的错误消息和发布的代码实际上为我指明了正确的方向。
我相信在设置 XValueMember 和 YValueMembers 后,chart1.DataBind() 需要移动。像这样:
当 FinancialFormula 被应用时,数据将不会被加载到系列对象中。
不过,您可能会遇到其他问题;)
Although pretty old I thought I leave my contribution since I was struggling with the very
same error message and the posted code actually pointed me in the right direction.
I believe the chart1.DataBind() needs to move after setting XValueMember and YValueMembers. Like so:
by the time the FinancialFormula gets applied the data will not have been loaded into the series object otherwise.
You may run into other issue though ;)
请添加
Chart1.DataManipulator.IsStartFromFirst = True
please add
Chart1.DataManipulator.IsStartFromFirst = True