C# MSChart 蜡烛图移动平均线图表。错误:公式错误 - 该期间没有足够的数据点

发布于 2024-12-02 06:06:44 字数 1766 浏览 1 评论 0原文

您不能对自己的帖子进行投票 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲娇萝莉攻 2024-12-09 06:06:44

虽然我已经很老了,但我想我会留下我的贡献,因为我正在与这个问题作斗争。
相同的错误消息和发布的代码实际上为我指明了正确的方向。

我相信在设置 XValueMember 和 YValueMembers 后,chart1.DataBind() 需要移动。像这样:

    chart1.Series["Daily"].XValueMember = "DateStamp";
    chart1.Series["Daily"].YValueMembers = "HighPrice, LowPrice, OpenPrice, ClosePrice";   
    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:

    chart1.Series["Daily"].XValueMember = "DateStamp";
    chart1.Series["Daily"].YValueMembers = "HighPrice, LowPrice, OpenPrice, ClosePrice";   
    chart1.DataBind();

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 ;)

彻夜缠绵 2024-12-09 06:06:44

请添加

Chart1.DataManipulator.IsStartFromFirst = True

please add

Chart1.DataManipulator.IsStartFromFirst = True

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文