如何使用MS随机指标

时间:2017-07-29 21:28:00

标签: c# .net charts mschart stochastic

我正在绘制一个随机指标,使用包含开放式高低收盘数据的双阵列,调整时间为5,10,15和30分钟。

chart1.DataManipulator.FinancialFormula(FinancialFormula.StochasticIndicator, 
"21,3",
"highPriceArray:Y,lowPriceArray:Y2,closePriceArray:Y4"
, "percentage_K_values:Y,percentage_D_values:Y");

上面的函数是我在MSDN库中使用的函数,

  • 如何将我的OHLC值的双数组转换为时间序列格式,以便我可以将它们输入到此函数并获得%K和%D值作为回报,然后继续绘制图表?< / p>

                openPriceArray[ii] = obj[0];
                highPriceArray[ii] = obj[1];
                lowPriceArray[ii] = obj[2];
                closePriceArray[ii] = obj[3];
    

提前谢谢。

1 个答案:

答案 0 :(得分:3)

此示例代码带有注释,可以帮到您。您也可以参考MSDN Docs

enter image description here

private void Form1_Load(object sender, EventArgs e)
{
    // load your data into a List<DataPoint>
    List<DataPoint> data = GetData();

    /*
     * dp.XValue - DateTime
     * dp.YValues[0] - High
     * dp.YValues[1] - Low
     * dp.YValues[2] - Open
     * dp.YValues[3] - Close
     */

    foreach (DataPoint dp in data)
        chart1.Series[0].Points.Add(dp);

    chart1.ChartAreas[0].AxisY.Maximum = chart1.Series[0].Points.Max(p => p.YValues[0]);
    chart1.ChartAreas[0].AxisY.Minimum = chart1.Series[0].Points.Min(p => p.YValues[1]);

    chart1.DataManipulator.FinancialFormula(FinancialFormula.StochasticIndicator,
    "10,10",
    "HLOC-Price:Y,HLOC-Price:Y2,HLOC-Price:Y4",
    "K-Indicator,D-Indicator");

    /*
     * HLOC-Price - Candlestick Series[0], primary Y-axis
     * K-Indicator - Line Series[1], secondary Y-axis
     * D-Indicator - Line Series[2], secondary Y-axis
     */
}