예제 #1
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 50)
            {
                return;
            }

            smooth.Set((4 * Median[0] + 3 * Median[1] + 2 * Median[2] + Median[3]) / 10);
            detrender.Set((0.0962 * smooth[0] + 0.5769 * smooth[2] - 0.5769 * smooth[4] - 0.0962 * smooth[6]) * (0.075 * period[1] + .54));

            //InPhase and Quadrature components
            q1.Set((0.0962 * detrender[0] + 0.5769 * detrender[2] - 0.5769 * detrender[4] - 0.0962 * detrender[6]) * (0.075 * period[1] + 0.54));
            i1.Set(detrender[3]);

            //Advance the phase of I1 and Q1 by 90 degrees
            jI.Set((0.0962 * i1[0] + 0.5769 * i1[2] - 0.5769 * i1[4] - 0.0962 * i1[6]) * (0.075 * period[1] + .54));
            jQ.Set((0.0962 * q1[0] + 0.5769 * q1[2] - 0.5769 * q1[4] - 0.0962 * q1[6]) * (0.075 * period[1] + .54));

            //Phasor Addition
            i2.Set(i1[0] - jQ[0]);
            q2.Set(q1[0] + jI[0]);

            //Smooth the I and Q components before applying the discriminator
            i2.Set(0.2 * i2[0] + 0.8 * i2[1]);
            q2.Set(0.2 * q2[0] + 0.8 * q2[1]);

            //Homodyne Discriminator
            re.Set(i2[0] * i2[1] + q2[0] * q2[1]);
            im.Set(i2[0] * q2[1] - q2[0] * i2[1]);
            re.Set(0.2 * re[0] + 0.8 * re[1]);
            im.Set(0.2 * im[0] + 0.8 * im[1]);

            double rad2Deg = 180.0 / (4.0 * Math.Atan(1));

            if (Math.Abs(im[0]) > double.Epsilon && Math.Abs(re[0]) > double.Epsilon)
            {
                period.Set(360 / (Math.Atan(im[0] / re[0]) * rad2Deg));
            }
            if (period[0] > (1.5 * period[1]))
            {
                period.Set(1.5 * period[1]);
            }
            if (period[0] < (0.67 * period[1]))
            {
                period.Set(0.67 * period[1]);
            }
            if (period[0] < 6)
            {
                period.Set(6);
            }
            if (period[0] > 50)
            {
                period.Set(50);
            }

            period.Set(0.2 * period[0] + 0.8 * period[1]);
            smoothPeriod.Set(0.33 * period[0] + 0.67 * smoothPeriod[1]);
            InPhase.Set(i1[0]);
            Quadrature.Set(q1[0]);
        }
예제 #2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (this.CurrentBar < 50)
            {
                return;
            }

            Smooth.Set((4 * Median[0] + 3 * Median[1] + 2 * Median[2] + Median[3]) / 10);
            Detrender.Set((0.0962 * Smooth[0] + 0.5769 * Smooth[2] - 0.5769 * Smooth[4] - 0.0962 * Smooth[6]) * (0.075 * Period[1] + .54));


            //InPhase and Quadrature components
            Q1.Set((0.0962 * Detrender[0] + 0.5769 * Detrender[2] - 0.5769 * Detrender[4] - 0.0962 * Detrender[6]) * (0.075 * Period[1] + 0.54));
            I1.Set(Detrender[3]);

            //Advance the phase of I1 and Q1 by 90 degrees
            jI.Set((0.0962 * I1[0] + 0.5769 * I1[2] - 0.5769 * I1[4] - 0.0962 * I1[6]) * (0.075 * Period[1] + .54));
            jQ.Set((0.0962 * Q1[0] + 0.5769 * Q1[2] - 0.5769 * Q1[4] - 0.0962 * Q1[6]) * (0.075 * Period[1] + .54));

            //Phasor Addition
            I2.Set(I1[0] - jQ[0]);
            Q2.Set(Q1[0] + jI[0]);

            //Smooth the I and Q components before applying the discriminator
            I2.Set(0.2 * I2[0] + 0.8 * I2[1]);
            Q2.Set(0.2 * Q2[0] + 0.8 * Q2[1]);

            //Homodyne Discriminator
            Re.Set(I2[0] * I2[1] + Q2[0] * Q2[1]);
            Im.Set(I2[0] * Q2[1] - Q2[0] * I2[1]);
            Re.Set(0.2 * Re[0] + 0.8 * Re[1]);
            Im.Set(0.2 * Im[0] + 0.8 * Im[1]);

            double rad2Deg = 180.0 / (4.0 * Math.Atan(1));

            if (Im[0] != 0 && Re[0] != 0)
            {
                Period.Set(360 / (Math.Atan(Im[0] / Re[0]) * rad2Deg));
            }

            if (Period[0] > (1.5 * Period[1]))
            {
                Period.Set(1.5 * Period[1]);
            }

            if (Period[0] < (0.67 * Period[1]))
            {
                Period.Set(0.67 * Period[1]);
            }

            if (Period[0] < 6)
            {
                Period.Set(6);
            }

            if (Period[0] > 50)
            {
                Period.Set(50);
            }

            Period.Set(0.2 * Period[0] + 0.8 * Period[1]);
            SmoothPeriod.Set(0.33 * Period[0] + 0.67 * SmoothPeriod[1]);


            InPhase.Set(I1[0]);
            Quadrature.Set(Q1[0]);
        }