Пример #1
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int iSize = _chartPanel._chartX.RecordCount;

            if (iSize == 0)
            {
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pHigh     = SeriesToField("High", paramStr0 + ".high", iSize);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", iSize);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pHigh);
            pRS.AddField(pLow);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Bands     ta   = new Bands();
            Recordset pInd = ta.PrimeNumberBands(pNav, pHigh, pLow);

            // Output the indicator values
            Clear();

            TwinIndicator sBottom = (TwinIndicator)EnsureSeries(FullName + " Bottom");

            sBottom.SetStrokeColor(StrokeColor.Invert(), false);
            sBottom.SetStrokeThickness(StrokeThickness, false);

            _title = FullName + " Top";

            for (int n = 0; n < iSize; ++n)
            {
                AppendValue(DM.TS(n), pInd.Value("Prime Bands Top", n + 1));
                sBottom.AppendValue(DM.TS(n), pInd.Value("Prime Bands Bottom", n + 1));
            }
            return(_calculateResult = PostCalculate());
        }
Пример #2
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 6 || paramInt1 > size / 2)
            {
                ProcessError("Invalid Periods (min 6) for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }


            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pHigh     = SeriesToField("High", paramStr0 + ".high", size);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", size);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", size);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }
            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Bands     ta   = new Bands();
            Recordset pInd = ta.HighLowBands(pNav, pHigh, pLow, pClose, paramInt1);


            // Output the indicator values
            Clear();

            TwinIndicator sTop = (TwinIndicator)EnsureSeries(FullName + " Top");

            sTop.SetStrokeColor(StrokeColor, false);
            sTop.SetStrokeThickness(StrokeThickness, false);

            TwinIndicator sBottom = (TwinIndicator)EnsureSeries(FullName + " Bottom");

            sBottom.SetStrokeColor(StrokeColor, false);
            sBottom.SetStrokeThickness(StrokeThickness, false);

            for (int n = 0; n < size; ++n)
            {
                double?top;
                double?bottom;
                double?median;
                if (n < paramInt1)
                {
                    top    = null;
                    median = null;
                    bottom = null;
                }
                else
                {
                    top    = pInd.Value("High Low Bands Top", n + 1);
                    median = pInd.Value("High Low Bands Median", n + 1);
                    bottom = pInd.Value("High Low Bands Bottom", n + 1);
                }

                AppendValue(DM.GetTimeStampByIndex(n), median);
                sTop.AppendValue(DM.GetTimeStampByIndex(n), top);
                sBottom.AppendValue(DM.GetTimeStampByIndex(n), bottom);
            }

            return(_calculateResult = PostCalculate());
        }
Пример #3
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int iSize = _chartPanel._chartX.RecordCount;

            if (iSize == 0)
            {
                return(false);
            }

            if (ParamInt(1) < 1 || ParamInt(1) > iSize / 2)
            {
                ProcessError("Invalid Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pOpen     = SeriesToField("Open", paramStr0 + ".open", iSize);

            if (!EnsureField(pOpen, paramStr0 + ".open"))
            {
                return(false);
            }
            Field pHigh = SeriesToField("High", paramStr0 + ".high", iSize);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", iSize);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", iSize);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }
            Field pVolume = SeriesToField("Volume", paramStr0 + ".volume", iSize);

            if (!EnsureField(pVolume, paramStr0 + ".volume"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pOpen);
            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);
            pRS.AddField(pVolume);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Bands     ta   = new Bands();
            Recordset pInd = ta.Keltner(pNav, pRS, ParamInt(1), ParamDbl(2), (IndicatorType)ParamInt(3), FullName);

            string sTopLine    = FullName + " Top";
            string sBottomLine = FullName + " Bottom";

            this._title = sTopLine;

            TwinIndicator indBottomLine = (TwinIndicator)EnsureSeries(sBottomLine);

            indBottomLine.SetStrokeColor(Colors.Blue, false);
            indBottomLine.SetStrokeThickness(StrokeThickness, false);

            ForceLinearChart = true;
            indBottomLine.ForceLinearChart = true;

            // Output the indicator values
            Clear();
            for (int n = 0; n < iSize; ++n)
            {
                AppendValue(DM.TS(n), n < ParamInt(1) + 1 ? null : pInd.Value(sTopLine, n + 1));
                indBottomLine.AppendValue(DM.TS(n), n < ParamInt(1) + 1 ? null : pInd.Value(sBottomLine, n + 1));
            }

            return(_calculateResult = PostCalculate());
        }
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int iSize = _chartPanel._chartX.RecordCount;

            if (iSize == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 1 || paramInt1 > iSize / 2)
            {
                ProcessError("Invalid %K Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            int paramInt2 = ParamInt(2);

            if (paramInt2 < 1 || paramInt2 > iSize / 2)
            {
                ProcessError("Invalid %K Smoothing Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            int paramInt3 = ParamInt(3);

            if (paramInt3 < 1)
            {
                ProcessError("Invalid %K Double Smoothing Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            int paramInt4 = ParamInt(4);

            if (paramInt4 < 1)
            {
                ProcessError("Invalid %D Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pHigh     = SeriesToField("High", paramStr0 + ".high", iSize);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", iSize);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", iSize);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);

            pNav.Recordset_ = pRS;



            // Calculate the indicator
            Index     ta   = new Index();
            Recordset pInd = ta.StochasticMomentumIndex(pNav, pRS, paramInt1, paramInt2, paramInt3,
                                                        paramInt4, (IndicatorType)ParamInt(5),
                                                        (IndicatorType)ParamInt(6));

            // Output the indicator values
            Clear();

            _strokeThickness = 2;
            _strokePattern   = LinePattern.Dot;

            TwinIndicator sPctK = (TwinIndicator)EnsureSeries(FullName + " %K");

            sPctK.SetStrokeColor(Colors.Blue, false);
            sPctK.SetStrokeThickness(_strokeThickness > 1 ? _strokeThickness - 1 : _strokeThickness, false);

            _title = FullName + " %D";

            for (int n = 0; n < iSize; ++n)
            {
                double?pctd = null;
                double?pctk = null;
                if (n >= paramInt1 * 2)
                {
                    pctd = pInd.Value("%D", n + 1);
                    pctk = pInd.Value("%K", n + 1);
                }

                AppendValue(DM.TS(n), pctd);
                sPctK.AppendValue(DM.TS(n), pctk);
            }
            return(_calculateResult = PostCalculate());
        }
Пример #5
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
// Validate
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 1 || paramInt1 > size / 2)
            {
                ProcessError("Invalid Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pOpen     = SeriesToField("Open", paramStr0 + ".open", size);

            if (!EnsureField(pOpen, paramStr0 + ".open"))
            {
                return(false);
            }
            Field pHigh = SeriesToField("High", paramStr0 + ".high", size);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", size);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", size);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pOpen);
            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Oscillator ta   = new Oscillator();
            Recordset  pInd = ta.Aroon(pNav, pRS, paramInt1);


            // Output the indicator values
            Clear();

            TwinIndicator pAroonDown = (TwinIndicator)EnsureSeries(FullName + " Down");

            pAroonDown.SetStrokeThickness(StrokeThickness, false);
            pAroonDown.SetStrokeColor(Colors.Red, false);

            pAroonDown.Clear();
            _title = FullName + " Up";

            for (int n = 0; n < size; ++n)
            {
                double?top;
                double?bottom;
                if (n < paramInt1)
                {
                    top    = null;
                    bottom = null;
                }
                else
                {
                    top    = pInd.Value("Aroon Up", n + 1);
                    bottom = pInd.Value("Aroon Down", n + 1);
                }
                AppendValue(DM.GetTimeStampByIndex(n), top);
                pAroonDown.AppendValue(DM.GetTimeStampByIndex(n), bottom);
            }

            return(_calculateResult = PostCalculate());
        }
Пример #6
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 1 || paramInt1 > size)
            {
                ProcessError("Invalid Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pHigh     = SeriesToField("High", paramStr0 + ".high", size);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", size);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pHigh);
            pRS.AddField(pLow);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Bands     ta   = new Bands();
            Recordset pInd = ta.FractalChaosBands(pNav, pRS, paramInt1);


            // Output the indicator values
            Clear();

            TwinIndicator sHigh = (TwinIndicator)EnsureSeries(FullName + " High");

            sHigh.SetStrokeColor(StrokeColor, false);
            sHigh.SetStrokeThickness(StrokeThickness, false);

            _title = FullName + " Low";

            for (int n = 0; n < size; ++n)
            {
                double?low;
                double?high;
                if (n < paramInt1)
                {
                    high = null;
                    low  = null;
                }
                else
                {
                    high = pInd.Value("Fractal High", n + 1);
                    low  = pInd.Value("Fractal Low", n + 1);
                }
                AppendValue(DM.GetTimeStampByIndex(n), low);
                sHigh.AppendValue(DM.GetTimeStampByIndex(n), high);
            }

            return(_calculateResult = PostCalculate());
        }
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int iSize = _chartPanel._chartX.RecordCount;

            if (iSize == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 1)
            {
                ProcessError("Invalid %K Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            int paramInt2 = ParamInt(2);

            if (paramInt2 < 2 || paramInt2 > iSize / 2)
            {
                ProcessError("Invalid %K Slowing Periods (min 2) for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            int paramInt3 = ParamInt(3);

            if (paramInt3 <= 0 || paramInt3 > iSize / 2)
            {
                ProcessError("Invalid %D Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            IndicatorType param4 = (IndicatorType)ParamInt(4);

            if (param4 < Constants.MA_START || param4 > Constants.MA_END)
            {
                ProcessError("Invalid Moving Average Type for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pHigh     = SeriesToField("High", paramStr0 + ".high", iSize);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", iSize);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", iSize);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Oscillator ta = new Oscillator();

            Recordset pInd = ta.StochasticOscillator(pNav, pRS, paramInt1, paramInt2, paramInt3, param4);


            // Output the indicator values
            Clear();

            TwinIndicator sPctK = (TwinIndicator)EnsureSeries(FullName + " %K");

            sPctK.SetStrokeColor(Colors.Blue, false);
            sPctK.SetStrokeThickness(StrokeThickness, false);

            ForceLinearChart       = true;
            sPctK.ForceLinearChart = true;

            _strokePattern = LinePattern.Dot;
            _title         = FullName + " %D";

            for (int n = 0; n < iSize; ++n)
            {
                double?pctd = n < paramInt3 ? null : pInd.Value("%D", n + 1);
                double?pctk = n < paramInt1 ? null : pInd.Value("%K", n + 1);

                AppendValue(DM.TS(n), pctd);
                sPctK.AppendValue(DM.TS(n), pctk);
            }

            return(_calculateResult = PostCalculate());
        }
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int iSize = _chartPanel._chartX.RecordCount;

            if (iSize == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 1 || paramInt1 > iSize / 2)
            {
                ProcessError("Invalid Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            IndicatorType param2 = (IndicatorType)ParamInt(2);

            if (param2 < Constants.MA_START || param2 > Constants.MA_END)
            {
                ProcessError("Invalid Moving Average Type for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            double paramDbl3 = ParamDbl(3);

            if (paramDbl3 < 0 || paramDbl3 > 100)
            {
                ProcessError("Invalid Band Shift Percentage for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }


            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pSource   = SeriesToField("Source", paramStr0, iSize);

            if (!EnsureField(pSource, paramStr0))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pSource);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Bands     ta   = new Bands();
            Recordset pInd = ta.MovingAverageEnvelope(pNav, pSource, paramInt1, param2, paramDbl3);


            // Output the indicator values
            Clear();

            TwinIndicator sTop = (TwinIndicator)EnsureSeries(FullName + " Top");

            sTop.SetStrokeColor(StrokeColor.Invert(), false);
            sTop.SetStrokeThickness(StrokeThickness, false);

            _title = FullName + " Bottom";

            for (int n = 0; n < iSize; ++n)
            {
                double?top;
                double?bottom;
                if (n < paramInt1 * 2)
                {
                    top    = null;
                    bottom = null;
                }
                else
                {
                    top    = pInd.Value("Envelope Top", n + 1);
                    bottom = pInd.Value("Envelope Bottom", n + 1);
                }
                AppendValue(DM.TS(n), bottom);
                sTop.AppendValue(DM.TS(n), top);
            }

            return(_calculateResult = PostCalculate());
        }
Пример #9
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int iSize = _chartPanel._chartX.RecordCount;

            if (iSize == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);
            int paramInt2 = ParamInt(2);
            int paramInt3 = ParamInt(3);

            if (paramInt1 > 500)
            {
                paramInt1 = 500;
            }
            if (paramInt2 > 500)
            {
                paramInt2 = 500;
            }
            if (paramInt1 < 0)
            {
                paramInt1 = 0;
            }
            if (paramInt2 < 0)
            {
                paramInt2 = 0;
            }
            if (paramInt3 > 500)
            {
                paramInt3 = 500;
            }
            if (paramInt3 < 0)
            {
                paramInt3 = 0;
            }

            if (paramInt1 < 1 || paramInt1 > iSize / 2)
            {
                ProcessError("Invalid Signal Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            if (paramInt2 == paramInt3)
            {
                ProcessError("Signal Periods cannot be the same as Short Cycle", IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pOpen     = SeriesToField("Open", paramStr0 + ".open", iSize);

            if (!EnsureField(pOpen, paramStr0 + ".open"))
            {
                return(false);
            }
            Field pHigh = SeriesToField("High", paramStr0 + ".high", iSize);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", iSize);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", iSize);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pOpen);
            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Oscillator ta   = new Oscillator();
            Recordset  pInd = ta.MACD(pNav, pRS, paramInt3, paramInt1, paramInt2, FullName);


            // Output the indicator values
            Clear();

            TwinIndicator sSignal = (TwinIndicator)EnsureSeries(FullName + " Signal");

            sSignal.SetStrokeColor(Colors.Blue, false);
            sSignal.SetStrokeThickness(StrokeThickness, false);

            ForceLinearChart         = true;
            sSignal.ForceLinearChart = true;

            //_title = "MACD";

            for (int n = 0; n < iSize; ++n)
            {
                AppendValue(DM.TS(n), n < paramInt1 ? null : pInd.Value(FullName, n + 1));
                sSignal.AppendValue(DM.TS(n), n < paramInt1 + paramInt2 ? null : pInd.Value(FullName + "Signal", n + 1));
            }

            return(_calculateResult = PostCalculate());
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override bool TrueAction()
        {
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 > size)
            {
                return(false);
            }

            int paramInt2 = ParamInt(2);

            if (paramInt2 > size)
            {
                return(false);
            }

            int paramInt3 = ParamInt(3);

            if (paramInt3 > size)
            {
                return(false);
            }

            string symbol = ParamStr(0);

            Field pHigh = SeriesToField("High", symbol + ".high", size);

            if (!EnsureField(pHigh, symbol + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", symbol + ".low", size);

            if (!EnsureField(pLow, symbol + ".low"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pHigh);
            pRS.AddField(pLow);

            pNav.Recordset_ = pRS;

            Tasdk.Ichimoku ichimoku = new Tasdk.Ichimoku();
            _calcs = ichimoku.Calc(pNav, pHigh, pLow, paramInt1, paramInt2, paramInt3);

            TwinIndicator baseLine     = (TwinIndicator)EnsureSeries(FullName + " BL");
            TwinIndicator leadingSpanA = (TwinIndicator)EnsureSeries(FullName + "LSA");
            TwinIndicator leadingSpanB = (TwinIndicator)EnsureSeries(FullName + "LSP");
            TwinIndicator lagginSpan   = (TwinIndicator)EnsureSeries(FullName + "LS");

            for (int i = 0; i < size; i++)
            {
                DateTime dt = DM.TS(i);
                AppendValue(dt, i < paramInt1 ? null : _calcs.Value("Conversion Line", i + 1));
                baseLine.AppendValue(dt, i < paramInt2 ? null : _calcs.Value("Base Line", i + 1));
                leadingSpanA.AppendValue(dt, i < paramInt2 ? null : _calcs.Value("Leading Span A", i + 1));
                leadingSpanB.AppendValue(dt, i < paramInt2 ? null : _calcs.Value("Leading Span B", i + 1));
                //lagginSpan.AppendValue(dt, _calcs.Value("Lagging Span"));
            }

            return(true);
        }
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
            // Validate
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            int paramInt1 = ParamInt(1);

            if (paramInt1 < 1 || paramInt1 > size / 2)
            {
                ProcessError("Invalid Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            // Get the data
            string paramStr0 = ParamStr(0);
            Field  pOpen     = SeriesToField("Open", paramStr0 + ".open", size);

            if (!EnsureField(pOpen, paramStr0 + ".open"))
            {
                return(false);
            }
            Field pHigh = SeriesToField("High", paramStr0 + ".high", size);

            if (!EnsureField(pHigh, paramStr0 + ".high"))
            {
                return(false);
            }
            Field pLow = SeriesToField("Low", paramStr0 + ".low", size);

            if (!EnsureField(pLow, paramStr0 + ".low"))
            {
                return(false);
            }
            Field pClose = SeriesToField("Close", paramStr0 + ".close", size);

            if (!EnsureField(pClose, paramStr0 + ".close"))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pOpen);
            pRS.AddField(pHigh);
            pRS.AddField(pLow);
            pRS.AddField(pClose);

            pNav.Recordset_ = pRS;


            // Calculate the indicator
            Oscillator ta   = new Oscillator();
            Recordset  pInd = ta.DirectionalMovementSystem(pNav, pRS, paramInt1);


            // Output the indicator values
            Clear();

            TwinIndicator sDIPlus  = (TwinIndicator)EnsureSeries(FullName + " DI+");
            TwinIndicator sDIMinus = (TwinIndicator)EnsureSeries(FullName + " DI-");

            sDIPlus.SetStrokeColor(Colors.Red, false);
            sDIMinus.SetStrokeColor(Colors.Blue, false);

            _title = "ADX";


            for (int n = 0; n < size; ++n)
            {
                double?adx;
                double?din;
                double?dip;
                if (n < paramInt1)
                {
                    adx = null;
                    dip = null;
                    din = null;
                }
                else
                {
                    adx = pInd.Value("ADX", n + 1);
                    dip = pInd.Value("DI+", n + 1);
                    din = pInd.Value("DI-", n + 1);
                }
                AppendValue(DM.GetTimeStampByIndex(n), adx);
                sDIPlus.AppendValue(DM.GetTimeStampByIndex(n), dip);
                sDIMinus.AppendValue(DM.GetTimeStampByIndex(n), din);
            }

            return(_calculateResult = PostCalculate());
        }
Пример #12
0
        /// <summary>
        /// Action to be executd for calculating indicator
        /// </summary>
        /// <returns>for future usage. Must be ignored at this time.</returns>
        protected override bool TrueAction()
        {
// Validate
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            if (ParamInt(1) < 1 || ParamInt(1) > size / 2)
            {
                ProcessError("Invalid Periods for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            if (ParamInt(2) < 0 || ParamInt(2) > 10)
            {
                ProcessError("Invalid Standard Deviations for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }
            if (ParamInt(3) < (int)Constants.MA_START || ParamInt(3) > (int)Constants.MA_END)
            {
                ProcessError("Invalid Moving Average Type for indicator " + FullName, IndicatorErrorType.ShowErrorMessage);
                return(false);
            }

            Field pSource = SeriesToField("Source", ParamStr(0), size);

            if (!EnsureField(pSource, ParamStr(0)))
            {
                return(false);
            }

            Navigator pNav = new Navigator();
            Recordset pRS  = new Recordset();

            pRS.AddField(pSource);
            pNav.Recordset_ = pRS;

            // Calculate the indicator
            Bands     ta   = new Bands();
            Recordset pInd = ta.BollingerBands(pNav, pSource, ParamInt(1), ParamInt(2), (IndicatorType)ParamInt(3));

            // Output the indicator values
            Clear();
            Series series = _chartPanel._chartX.GetSeriesByName(ParamStr(0));

            TwinIndicator pTop = (TwinIndicator)EnsureSeries(FullName + " Top");

            pTop.SetStrokeColor(StrokeColor, false);
            pTop.SetStrokeThickness(StrokeThickness, false);
            pTop.SetStrokePattern(_strokePattern, false);

            TwinIndicator pBottom = (TwinIndicator)EnsureSeries(FullName + " Bottom");

            pBottom.SetStrokeColor(StrokeColor, false);
            pBottom.SetStrokeThickness(StrokeThickness, false);
            pBottom.SetStrokePattern(_strokePattern, false);

            int paramInt1 = ParamInt(1);

            for (int n = 0; n < size; ++n)
            {
                double?top;
                double?median;
                double?bottom;
                if (n < paramInt1)
                {
                    top    = null;
                    median = null;
                    bottom = null;
                }
                else
                {
                    top    = pInd.Value("Bollinger Band Top", n + 1);
                    median = pInd.Value("Bollinger Band Median", n + 1);
                    bottom = pInd.Value("Bollinger Band Bottom", n + 1);
                }
                AppendValue(series[n].TimeStamp, median);
                pTop.AppendValue(series[n].TimeStamp, top);
                pBottom.AppendValue(series[n].TimeStamp, bottom);
            }

            return(_calculateResult = PostCalculate());
        }