Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
指示器从MQL4转换为C#几乎完成,需要帮助才能完全工作(2个输出中有1个在代码中卡住)_C#_Indicator_Mql4_Code Conversion - Fatal编程技术网

指示器从MQL4转换为C#几乎完成,需要帮助才能完全工作(2个输出中有1个在代码中卡住)

指示器从MQL4转换为C#几乎完成,需要帮助才能完全工作(2个输出中有1个在代码中卡住),c#,indicator,mql4,code-conversion,C#,Indicator,Mql4,Code Conversion,我已将AFIRMA指示器从MQL4转换为C。它正确地输出第一个系列(FIRMA),但第二个系列被卡在代码中的某个地方(ARMA)。你知道是什么原因阻止了它的输出吗?好像卡在什么地方了 谢谢你抽出时间 namespace cAlgo.Indicators { [Indicator(ScalePrecision = 5, AutoRescale = true, IsOverlay = true, AccessRights = AccessRights.None)] public class AFIR

我已将AFIRMA指示器从
MQL4
转换为
C
。它正确地输出第一个系列(FIRMA),但第二个系列被卡在代码中的某个地方(ARMA)。你知道是什么原因阻止了它的输出吗?好像卡在什么地方了

谢谢你抽出时间

namespace cAlgo.Indicators
{
[Indicator(ScalePrecision = 5, AutoRescale = true, IsOverlay = true, AccessRights = AccessRights.None)]
public class AFIRMA : Indicator
{


    [Parameter("Periods", DefaultValue = 12)]
    public int Periods { get; set; }

    [Parameter("Taps", DefaultValue = 25)]
    public int Taps { get; set; }

    [Parameter("Window", DefaultValue = 4)]
    public int Window { get; set; }



    [Output("FIRMA", Color = Colors.Blue, PlotType = PlotType.DiscontinuousLine)]
    public IndicatorDataSeries FIRMA { get; set; }
    [Output("ARMA", Color = Colors.Red, PlotType = PlotType.DiscontinuousLine)]
    public IndicatorDataSeries ARMA { get; set; }


    int n;
    double den;
    double sx6;
    double sx5;
    double sx4;
    double sx3;
    double sx2;
    double wsum;
    double[] w;

    protected override void Initialize()
    {
        //Calculate weights
        Array.Resize(ref w, Taps);
        wsum = 0.0;
        for (int k = 0; k < Taps; k++)
        {
            switch (Window)
            {
                case 1:
                    w[k] = 1.0;
                    break;
                case 2:
                    w[k] = 0.5 - 0.5 * Math.Cos(2.0 * Math.PI * k / Taps);
                    break;
                case 3:
                    w[k] = 0.54 - 0.46 * Math.Cos(2.0 * Math.PI * k / Taps);
                    break;
                case 4:
                    w[k] = 0.42 - 0.5 * Math.Cos(2.0 * Math.PI * k / Taps) + 0.08 * Math.Cos(4.0 * Math.PI * k / Taps);
                    break;
                case 5:
                    w[k] = 0.35875 - 0.48829 * Math.Cos(2.0 * Math.PI * k / Taps) + 0.14128 * Math.Cos(4.0 * Math.PI * k / Taps) - 0.01168 * Math.Cos(6.0 * Math.PI * k / Taps);
                    break;
                default:
                    w[k] = 1;
                    break;
            }
            if (k != Taps / 2.0)
                w[k] = w[k] * Math.Sin(Math.PI * (k - Taps / 2.0) / Periods) / Math.PI / (k - Taps / 2.0);
            wsum += w[k];
        }

        //Calculate sums for the least-squares method
        n = (Taps - 1) / 2;
        sx2 = (2 * n + 1) / 3.0;
        sx3 = n * (n + 1) / 2.0;
        sx4 = sx2 * (3 * n * n + 3 * n - 1) / 5.0;
        sx5 = sx3 * (2 * n * n + 2 * n - 1) / 3.0;
        sx6 = sx2 * (3 * n * n * n * (n + 2) - 3 * n + 1) / 7.0;
        den = sx6 * sx4 / sx5 - sx5;
    }


    public override void Calculate(int index)
    {
        //Calculate FIR MA for all bars except for the last n bars
        for (int i = 0; i <= Bars - Taps; i++)
        {
            FIRMA[i + n] = 0.0;
            for (int k = 0; k < Taps; k++)
                FIRMA[i + n] += MarketSeries.Close[i + k] * w[k] / wsum;

        }

        //Calculate regressive MA for the remaining n bars
        double a0 = FIRMA[n];
        double a1 = FIRMA[n] - FIRMA[n + 1];
        double sx2y = 0.0;
        double sx3y = 0.0;
        for (int i = 0; i <= n; i++)
        {
            sx2y += i * i * MarketSeries.Close[n - i];
            sx3y += i * i * i * MarketSeries.Close[n - i];
        }
        sx2y = 2.0 * sx2y / n / (n + 1);
        sx3y = 2.0 * sx3y / n / (n + 1);
        double p = sx2y - a0 * sx2 - a1 * sx3;
        double q = sx3y - a0 * sx3 - a1 * sx4;
        double a2 = (p * sx6 / sx5 - q) / den;
        double a3 = (q * sx4 / sx5 - p) / den;
        for (int i = 0; i <= n; i++)
        {
            ARMA[n - i] = a0 + i * a1 + i * i * a2 + i * i * i * a3;
            return;
        }
    }


    private int Bars
    {
        get { return MarketSeries.Close.Count; }
    }

}

}
名称空间cAlgo.Indicators
{
[指示器(ScalePrecision=5,AutoRescale=true,IsOverlay=true,AccessRights=AccessRights.None)]
公共类AFIRMA:指示器
{
[参数(“期间”,默认值=12)]
公共整数周期{get;set;}
[参数(“抽头”,默认值=25)]
公共整数{get;set;}
[参数(“窗口”,默认值=4)]
公共int窗口{get;set;}
[输出(“FIRMA”,Color=Colors.Blue,PlotType=PlotType.continuousline)]
公共指示符数据系列FIRMA{get;set;}
[输出(“ARMA”,颜色=颜色。红色,绘图类型=绘图类型。不连续线)]
公共指示符数据系列ARMA{get;set;}
int n;
双窝;
双sx6;
双sx5;
双sx4;
双sx3;
双sx2;
双wsum;
双[]w;
受保护的覆盖无效初始化()
{
//计算重量
数组。调整大小(参考w,轻敲);
wsum=0.0;
对于(int k=0;k
头部怎么样?

这是一种意图,还是在渐进式、批处理驱动的
CustomIndicator
演算中,使用MQL4 TimeSeries习惯处理反向、前向步进的条数索引数组,存在未纠正的错误残余?

这是一个简单的错误:ARMA循环返回的位置不正确,而循环返回的位置不正确骨灰盒马上就好了

for (int i = 0; i <= n; i++)
    {
        ARMA[n - i] = a0 + i * a1 + i * i * a2 + i * i * i * a3;
        return; // Not here
    }
return; //But here.

用于(int i=0;我希望您能用一组POSACK和NACK数据+结果来完成MCVE,在您看来,这两组数据+测试驱动的正确确认了一个工作和一个不工作的解决方案?感谢您的重新考虑。我希望我提供了所需的所有信息。我怀疑这是一个未更正的结果,AR毫安(红色输出)根本不渲染,如上传的图片所示。感谢您的耐心。我修改了返回,但不幸的是它仍然没有输出。@RyanJ.Markwald ARMA在返回点有什么值?在那里设置一个断点并检查值。代码现在看起来与MQL4相同,我不明白为什么会卡住。是的,没有这就是为什么我发现它也很奇怪。这个数字似乎是它目前的最后一个值。!。@RyanJ.Markwald-Hum这个数字超出了范围。可能是所有的值都超出了范围。如果是,可能是函数中的某个地方有错误,但我看不到。是的,你是对的!我已经用所用变量的所有值更新了帖子。但即使是所以,它应该呈现一些东西,对吗?谢谢你的时间。
namespace cAlgo.Indicators
{
[Indicator(ScalePrecision = 5, AutoRescale = true, IsOverlay = true, AccessRights = AccessRights.None)]
public class AFIRMA: Indicator
{


    [Parameter("Periods", DefaultValue = 15)]
    public int Periods { get; set; }

    [Parameter("Taps", DefaultValue = 31)]
    public int Taps { get; set; }

    [Parameter("Window", DefaultValue = 4)]
    public int Window { get; set; }



    [Output("FIRMA", Color = Colors.Blue, PlotType = PlotType.DiscontinuousLine)]
    public IndicatorDataSeries FIRMA { get; set; }
    [Output("ARMA", Color = Colors.Red, PlotType = PlotType.DiscontinuousLine)]
    public IndicatorDataSeries ARMA { get; set; }


    int n;
    double den;
    double sx6;
    double sx5;
    double sx4;
    double sx3;
    double sx2;
    double wsum;
    double[] w;

    protected override void Initialize()
    {

        //Calculate weights
        Array.Resize(ref w, Taps);
        wsum = 0.0;
        for (int k = 0; k < Taps; k++)
        {
            switch (Window)
            {
                case 1:
                    w[k] = 1.0;
                    break;
                case 2:
                    w[k] = 0.5 - 0.5 * Math.Cos(2.0 * Math.PI * k / Taps);
                    break;
                case 3:
                    w[k] = 0.54 - 0.46 * Math.Cos(2.0 * Math.PI * k / Taps);
                    break;
                case 4:
                    w[k] = 0.42 - 0.5 * Math.Cos(2.0 * Math.PI * k / Taps) + 0.08 * Math.Cos(4.0 * Math.PI * k / Taps);
                    break;
                case 5:
                    w[k] = 0.35875 - 0.48829 * Math.Cos(2.0 * Math.PI * k / Taps) + 0.14128 * Math.Cos(4.0 * Math.PI * k / Taps) - 0.01168 * Math.Cos(6.0 * Math.PI * k / Taps);
                    break;
                default:
                    w[k] = 1;
                    break;
            }
            if (k != Taps / 2.0)
                w[k] = w[k] * Math.Sin(Math.PI * (k - Taps / 2.0) / Periods) / Math.PI / (k - Taps / 2.0);
            wsum += w[k];
        }

        //Calculate sums for the least-squares method
        n = (Taps - 1) / 2;
        sx2 = (2 * n + 1) / 3.0;
        sx3 = n * (n + 1) / 2.0;
        sx4 = sx2 * (3 * n * n + 3 * n - 1) / 5.0;
        sx5 = sx3 * (2 * n * n + 2 * n - 1) / 3.0;
        sx6 = sx2 * (3 * n * n * n * (n + 2) - 3 * n + 1) / 7.0;
        den = sx6 * sx4 / sx5 - sx5;


        //Calculate FIR MA for all bars except for the last n bars
        for (int i = 0; i <= Bars - Taps; i++)
        {
            FIRMA[i + n] = 0.0;
            for (int k = 0; k < Taps; k++)
                FIRMA[i + n] += MarketSeries.Close[i + k] * w[k] / wsum;

        }




    }


    public override void Calculate(int index)
    {
        //Calculate regressive MA for the remaining n bars
        double a0 = FIRMA[index - n];
        double a1 = FIRMA[index - n] - FIRMA[index - n - 1];
        double sx2y = 0.0;
        double sx3y = 0.0;

        for (int i = 0; i <= n; i++)
        {
            sx2y += i * i * MarketSeries.Close[index + i - n];
            sx3y += i * i * i * MarketSeries.Close[index + i - n];
        }
        sx2y = 2.0 * sx2y / n / (n + 1);
        sx3y = 2.0 * sx3y / n / (n + 1);
        double p = sx2y - a0 * sx2 - a1 * sx3;
        double q = sx3y - a0 * sx3 - a1 * sx4;
        double a2 = (p * sx6 / sx5 - q) / den;
        double a3 = (q * sx4 / sx5 - p) / den;

        for (int i = 0; i <= n; i++)
        {
            ARMA[index + i - n] = a0 + i * a1 + i * i * a2 + i * i * i * a3;
            //ChartObjects.DrawText("test", "ARMA: " + ARMA[index + i - n] + "\na0: " + a0 + "\na1: " + a1 + "\na2: " + a2 + "\na3: " + a3 + "\nn: " + n + "\ni: " + i + "\np: " + p + "\nq: " + q + "\nsx2y: " + sx2y + "\nsx3y: " + sx3y + "\nsx2: " + sx2 + "\nsx3: " + sx3 + "\nsx4: " + sx4 + "\nsx5: " + sx5 + "\nsx6: " + sx6 + "\nden: " + den, StaticPosition.TopRight);
        }
    }
    private int Bars
    {
        get { return MarketSeries.Close.Count; }
    }

}

}
for (int i = 0; i <= n; i++)
    {
        ARMA[n - i] = a0 + i * a1 + i * i * a2 + i * i * i * a3;
        return; // Not here
    }
return; //But here.