Beispiel #1
0
            ///<summary>
            /// Stochastic Momentum Index
            ///</summary>
            ///<param name="pNav">Navigator</param>
            ///<param name="pOHLCV">OHLCV Recordser</param>
            ///<param name="KPeriods">K Periods</param>
            ///<param name="KSmooth">K Smooth</param>
            ///<param name="KDoubleSmooth">K Double Smooth</param>
            ///<param name="DPeriods">D Periods</param>
            ///<param name="MAType">Moving Average Type</param>
            ///<param name="PctD_MAType">%D Movering Average Type</param>
            ///<returns>Recordset</returns>
            public Recordset StochasticMomentumIndex(Navigator pNav, Recordset pOHLCV, int KPeriods, int KSmooth, int KDoubleSmooth,
                                                     int DPeriods, IndicatorType MAType, IndicatorType PctD_MAType)
            {
                MovingAverage MA      = new MovingAverage();
                Recordset     Results = new Recordset();
                General       GN      = new General();
                int           Record;
                double?       Value = 0;

                KSmooth += 1;
                int RecordCount = pNav.RecordCount;

                Field Field1 = new Field(RecordCount, "%K");


                Recordset Temp = GN.HHV(pNav, pOHLCV.GetField("High"), KPeriods, "HHV");
                Field     HHV  = new Field(RecordCount, "HHV");

                Temp.CopyField(HHV, "HHV");

                Temp = GN.LLV(pNav, pOHLCV.GetField("Low"), KPeriods, "LLV");
                Field LLV = new Field(RecordCount, "LLV");

                Temp.CopyField(LLV, "LLV");


                Field HHLL = new Field(RecordCount, "HHLL");

                for (Record = 1; Record != RecordCount + 1; ++Record)
                {
                    Value = HHV.Value(Record) - LLV.Value(Record);
                    HHLL.Value(Record, Value);
                }


                Field CHHLL = new Field(RecordCount, "CHHLL");

                for (Record = 1; Record != RecordCount + 1; ++Record)
                {
                    Value = pOHLCV.Value("Close", Record) - (0.5f * (HHV.Value(Record) + LLV.Value(Record)));
                    CHHLL.Value(Record, Value);
                }

                if (KSmooth > 1)
                {
                    switch (MAType)
                    {
                    case IndicatorType.SimpleMovingAverage:
                        Temp = MA.SimpleMovingAverage(pNav, CHHLL, KSmooth, "CHHLL");
                        break;

                    case IndicatorType.ExponentialMovingAverage:
                        Temp = MA.ExponentialMovingAverage(pNav, CHHLL, KSmooth, "CHHLL");
                        break;

                    case IndicatorType.TimeSeriesMovingAverage:
                        Temp = MA.TimeSeriesMovingAverage(pNav, CHHLL, KSmooth, "CHHLL");
                        break;

                    case IndicatorType.TriangularMovingAverage:
                        Temp = MA.TriangularMovingAverage(pNav, CHHLL, KSmooth, "CHHLL");
                        break;

                    case IndicatorType.VariableMovingAverage:
                        Temp = MA.VariableMovingAverage(pNav, CHHLL, KSmooth, "CHHLL");
                        break;

                    case IndicatorType.WeightedMovingAverage:
                        Temp = MA.WeightedMovingAverage(pNav, CHHLL, KSmooth, "CHHLL");
                        break;

                    case IndicatorType.VIDYA:
                        Temp = MA.VIDYA(pNav, CHHLL, KSmooth, 0.65, "CHHLL");
                        break;
                    }

                    Temp.CopyField(CHHLL, "CHHLL");
                }


                if (KDoubleSmooth > 1)
                {
                    switch (MAType)
                    {
                    case IndicatorType.SimpleMovingAverage:
                        Temp = MA.SimpleMovingAverage(pNav, CHHLL, KDoubleSmooth, "CHHLL");
                        break;

                    case IndicatorType.ExponentialMovingAverage:
                        Temp = MA.ExponentialMovingAverage(pNav, CHHLL, KDoubleSmooth, "CHHLL");
                        break;

                    case IndicatorType.TimeSeriesMovingAverage:
                        Temp = MA.TimeSeriesMovingAverage(pNav, CHHLL, KDoubleSmooth, "CHHLL");
                        break;

                    case IndicatorType.TriangularMovingAverage:
                        Temp = MA.TriangularMovingAverage(pNav, CHHLL, KDoubleSmooth, "CHHLL");
                        break;

                    case IndicatorType.VariableMovingAverage:
                        Temp = MA.VariableMovingAverage(pNav, CHHLL, KDoubleSmooth, "CHHLL");
                        break;

                    case IndicatorType.WeightedMovingAverage:
                        Temp = MA.WeightedMovingAverage(pNav, CHHLL, KDoubleSmooth, "CHHLL");
                        break;

                    case IndicatorType.VIDYA:
                        Temp = MA.VIDYA(pNav, CHHLL, KDoubleSmooth, 0.65, "CHHLL");
                        break;
                    }

                    Temp.CopyField(CHHLL, "CHHLL");
                }

                if (KSmooth > 1)
                {
                    switch (MAType)
                    {
                    case IndicatorType.SimpleMovingAverage:
                        Temp = MA.SimpleMovingAverage(pNav, HHLL, KSmooth, "HHLL");
                        break;

                    case IndicatorType.ExponentialMovingAverage:
                        Temp = MA.ExponentialMovingAverage(pNav, HHLL, KSmooth, "HHLL");
                        break;

                    case IndicatorType.TimeSeriesMovingAverage:
                        Temp = MA.TimeSeriesMovingAverage(pNav, HHLL, KSmooth, "HHLL");
                        break;

                    case IndicatorType.TriangularMovingAverage:
                        Temp = MA.TriangularMovingAverage(pNav, HHLL, KSmooth, "HHLL");
                        break;

                    case IndicatorType.VariableMovingAverage:
                        Temp = MA.VariableMovingAverage(pNav, HHLL, KSmooth, "HHLL");
                        break;

                    case IndicatorType.WeightedMovingAverage:
                        Temp = MA.WeightedMovingAverage(pNav, HHLL, KSmooth, "HHLL");
                        break;

                    case IndicatorType.VIDYA:
                        Temp = MA.VIDYA(pNav, HHLL, KSmooth, 0.65, "HHLL");
                        break;
                    }

                    Temp.CopyField(HHLL, "HHLL");
                }


                if (KDoubleSmooth > 1)
                {
                    switch (MAType)
                    {
                    case IndicatorType.SimpleMovingAverage:
                        Temp = MA.SimpleMovingAverage(pNav, HHLL, KDoubleSmooth, "HHLL");
                        break;

                    case IndicatorType.ExponentialMovingAverage:
                        Temp = MA.ExponentialMovingAverage(pNav, HHLL, KDoubleSmooth, "HHLL");
                        break;

                    case IndicatorType.TimeSeriesMovingAverage:
                        Temp = MA.TimeSeriesMovingAverage(pNav, HHLL, KDoubleSmooth, "HHLL");
                        break;

                    case IndicatorType.TriangularMovingAverage:
                        Temp = MA.TriangularMovingAverage(pNav, HHLL, KDoubleSmooth, "HHLL");
                        break;

                    case IndicatorType.VariableMovingAverage:
                        Temp = MA.VariableMovingAverage(pNav, HHLL, KDoubleSmooth, "HHLL");
                        break;

                    case IndicatorType.WeightedMovingAverage:
                        Temp = MA.WeightedMovingAverage(pNav, HHLL, KDoubleSmooth, "HHLL");
                        break;

                    case IndicatorType.VIDYA:
                        Temp = MA.VIDYA(pNav, HHLL, KDoubleSmooth, 0.65, "HHLL");
                        break;
                    }

                    Temp.CopyField(HHLL, "HHLL");
                }


                for (Record = KPeriods + 1; Record != RecordCount + 1; ++Record)
                {
                    double?a = CHHLL.Value(Record);
                    double?b = (0.5f * HHLL.Value(Record));
                    if (a != b && b != 0)
                    {
                        Value = 100.0f * (a / b);
                    }
                    Field1.Value(Record, Value);
                }


                if (DPeriods > 1)
                {
                    switch (PctD_MAType)
                    {
                    case IndicatorType.SimpleMovingAverage:
                        Temp = MA.SimpleMovingAverage(pNav, Field1, DPeriods, "%D");
                        break;

                    case IndicatorType.ExponentialMovingAverage:
                        Temp = MA.ExponentialMovingAverage(pNav, Field1, DPeriods, "%D");
                        break;

                    case IndicatorType.TimeSeriesMovingAverage:
                        Temp = MA.TimeSeriesMovingAverage(pNav, Field1, DPeriods, "%D");
                        break;

                    case IndicatorType.TriangularMovingAverage:
                        Temp = MA.TriangularMovingAverage(pNav, Field1, DPeriods, "%D");
                        break;

                    case IndicatorType.VariableMovingAverage:
                        Temp = MA.VariableMovingAverage(pNav, Field1, DPeriods, "%D");
                        break;

                    case IndicatorType.WeightedMovingAverage:
                        Temp = MA.WeightedMovingAverage(pNav, Field1, DPeriods, "%D");
                        break;

                    case IndicatorType.VIDYA:
                        Temp = MA.VIDYA(pNav, Field1, DPeriods, 0.65, "%D");
                        break;
                    }

                    Field Field2 = new Field(RecordCount, "%D");
                    Temp.CopyField(Field2, "%D");
                    Results.AddField(Field2);
                }
                Results.AddField(Field1);

                return(Results);
            }