开发者

C# MSChart Candle Stick & Moving Average Chart. Error: Formula error - There are not enough data points for the Period

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

        Syste开发者_如何学Pythonm.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");


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


please add

Chart1.DataManipulator.IsStartFromFirst = True

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜