C#的MSChart蜡烛棒&安培;移动平均线图。错误:公式错误 - 有没有为周期足够的数据点 [英] C# MSChart Candle Stick & Moving Average Chart. Error: Formula error - There are not enough data points for the Period

查看:1389
本文介绍了C#的MSChart蜡烛棒&安培;移动平均线图。错误:公式错误 - 有没有为周期足够的数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您不能在自己的岗位
投票0



我想创建一个股票蜡烛与日常数据MA(15)。



我可以创建一个没有任何问题OHLC栏的图表。



但是,当我开始为usingDataManipulator.FinancialFormula MA,我不断收到的错误公式错误 - 有没有为周期足够的数据点。



有人能帮助我在这?谢谢



下面是代码。

 的DataSet DS =新的DataSet (); 
SqlConnection的连接=新的SqlConnection();
connection.ConnectionString = @数据源= XXX;数据库=股票;集成安全性= SSPI;;
connection.Open();
字符串SQL =选择日期戳,highprice,lowprice,openprice,closeprice从daymarketdata那里tickname =GS和时间戳>'1/1/2011'按邮戳ASC秩序;

System.Data.SqlClient.SqlCommand CMD =新System.Data.SqlClient.SqlCommand(SQL,连接);
cmd.CommandType = CommandType.Text;

SqlDataAdapter的SA =新的SqlDataAdapter();
sa.SelectCommand = CMD;

sa.Fill(DS,产地来源证);
的Connection.close();
chart1.Series [人民日报] =图表类型SeriesChartType.Candlestick。
chart1.DataSource = SA;
chart1.DataBind();


chart1.Series [人民日报] XValueMember =日期戳。
chart1.Series [人民日报] YValueMembers =HighPrice,LowPrice,OpenPrice,ClosePrice。
chart1.Series [人民日报] IsXValueIndexed = TRUE。

chart1.Series [人民日报] BORDERCOLOR = System.Drawing.Color.Black。
chart1.Series [人民日报]颜色= System.Drawing.Color.Black。
chart1.Series [人民日报] CustomProperties来=PriceDownColor =绿色,PriceUpColor =红。
chart1.Series [人民日报] = XValueType ChartValueType.Date。
chart1.ChartAreas [0] .AxisY.Minimum = 100;
chart1.ChartAreas [0] .AxisY.Maximum = 180;
chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage,十五,人民日报,MA);


解决方案

虽然很老,我想我离开,因为我我的贡献是用非常
同样的错误消息,并且贴出代码居然挣扎我指出了正确的方向。



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



  chart1.Series [人民日报] XValueMember =日期戳; 
chart1.Series [人民日报] YValueMembers =HighPrice,LowPrice,OpenPrice,ClosePrice。
chart1.DataBind();



由当时FinancialFormula被施加的数据将不会被加载到一系列对象,否则。
你可能会碰到另外一个问题,虽然;)


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

解决方案

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

这篇关于C#的MSChart蜡烛棒&安培;移动平均线图。错误:公式错误 - 有没有为周期足够的数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆