/// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int      iEntryHour   = (int)IndParam.NumParam[0].Value;
            int      iEntryMinute = (int)IndParam.NumParam[1].Value;
            TimeSpan tsEntryHour  = new TimeSpan(iEntryHour, iEntryMinute, 0);

            // Calculation
            int iFirstBar = 1;

            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adBars[iBar] = Time[iBar].TimeOfDay == tsEntryHour ? Open[iBar] : 0;
            }

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "Entry hour";
            Component[0].DataType      = IndComponentType.OpenPrice;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            return;
        }
Пример #2
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Calculation
            int iFirstBar = 2;

            double[] adIB = new double[Bars];

            for (int iBar = 2; iBar < Bars; iBar++)
            {
                adIB[iBar] = ((High[iBar - 1] < High[iBar - 2]) && (Low[iBar - 1] > Low[iBar - 2])) ? 1 : 0;
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Allow long entry";
            Component[0].DataType  = IndComponentType.AllowOpenLong;
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adIB;

            Component[1]           = new IndicatorComp();
            Component[1].CompName  = "Allow short entry";
            Component[1].DataType  = IndComponentType.AllowOpenShort;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = adIB;

            return;
        }
Пример #3
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            double minGap = Point * IndParam.NumParam[0].Value;

            // Calculating
            int firstBar = 1;

            double[] longSignals  = new double[Bars];
            double[] shortSignals = new double[Bars];

            if (IndParam.ListParam[0].Text == "Positive gap")
            {
                for (int bar = firstBar; bar < Bars; bar++)
                {
                    if (Open[bar] > Close[bar - 1] + minGap)
                    {
                        longSignals[bar] = 1;
                    }
                    if (Open[bar] < Close[bar - 1] - minGap)
                    {
                        shortSignals[bar] = 1;
                    }
                }
            }

            if (IndParam.ListParam[0].Text == "Negative gap")
            {
                for (int bar = firstBar; bar < Bars; bar++)
                {
                    if (Open[bar] < Close[bar - 1] - minGap)
                    {
                        longSignals[bar] = 1;
                    }
                    if (Open[bar] > Close[bar - 1] + minGap)
                    {
                        shortSignals[bar] = 1;
                    }
                }
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Allow long entry";
            Component[0].DataType  = IndComponentType.AllowOpenLong;
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = firstBar;
            Component[0].Value     = longSignals;

            Component[1]           = new IndicatorComp();
            Component[1].CompName  = "Allow short entry";
            Component[1].DataType  = IndComponentType.AllowOpenShort;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = firstBar;
            Component[1].Value     = shortSignals;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Calculation
            double[] adClosePrice = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
                if (Time[iBar - 1].Day != Time[iBar].Day)
                    adClosePrice[iBar - 1] = Close[iBar - 1];

            // Check the last bar
            TimeSpan tsBarClosing = Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int)Period, 0));
            TimeSpan tsDayClosing = new TimeSpan(24, 0, 0);
            if (tsBarClosing == tsDayClosing)
                adClosePrice[Bars - 1] = Close[Bars - 1];

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Closing price of the day";
            Component[0].DataType  = IndComponentType.ClosePrice;
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = 2;
            Component[0].Value     = adClosePrice;

            return;
        }
Пример #5
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int      iFromHour   = (int)IndParam.NumParam[0].Value;
            int      iFromMin    = (int)IndParam.NumParam[1].Value;
            int      iUntilHour  = (int)IndParam.NumParam[2].Value;
            int      iUntilMin   = (int)IndParam.NumParam[3].Value;
            TimeSpan tsFromTime  = new TimeSpan(iFromHour, iFromMin, 0);
            TimeSpan tsUntilTime = new TimeSpan(iUntilHour, iUntilMin, 0);

            // Calculation
            int iFirstBar = 1;

            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (tsFromTime < tsUntilTime)
                {
                    adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime &&
                                   Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0;
                }
                else if (tsFromTime > tsUntilTime)
                {
                    adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime ||
                                   Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0;
                }
                else
                {
                    adBars[iBar] = 1;
                }
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "Is long entry allowed";
            Component[0].DataType      = IndComponentType.AllowOpenLong;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            Component[1]               = new IndicatorComp();
            Component[1].CompName      = "Is short entry allowed";
            Component[1].DataType      = IndComponentType.AllowOpenShort;
            Component[1].ChartType     = IndChartType.NoChart;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar      = iFirstBar;
            Component[1].Value         = adBars;

            return;
        }
Пример #6
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Calculation

            int    iPeriod = (int)IndParam.NumParam[1].Value;
            double p1      = (double)IndParam.NumParam[0].Value;

            p1 = p1 / 100;

            int iFirstBar = 1;

            double[] up1   = new double[Bars];
            double[] down1 = new double[Bars];
            double   point = (Digits == 5 || Digits == 3) ? 10 * Point : Point;



            for (int iBar = 6; iBar < Bars; iBar++)
            {
                if (Math.Abs(Close[iBar - iPeriod] - Open[iBar - iPeriod]) >= (High[iBar - iPeriod] - Low[iBar - iPeriod]) * p1)
                {
                    if (Close[iBar - iPeriod] > Open[iBar - iPeriod])
                    {
                        up1[iBar] = 1;
                    }

                    else
                    {
                        down1[iBar] = 1;
                    }
                }
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Allow long entry";
            Component[0].DataType  = IndComponentType.AllowOpenLong;
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = up1;

            Component[1]           = new IndicatorComp();
            Component[1].CompName  = "Allow short entry";
            Component[1].DataType  = IndComponentType.AllowOpenShort;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = down1;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            DayOfWeek dowFromDay  = (DayOfWeek)IndParam.ListParam[1].Index;
            DayOfWeek dowUntilDay = (DayOfWeek)IndParam.ListParam[2].Index;

            // Calculation
            int iFirstBar = 1;

            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (dowFromDay < dowUntilDay)
                {
                    adBars[iBar] = Time[iBar].DayOfWeek >= dowFromDay &&
                                   Time[iBar].DayOfWeek < dowUntilDay ? 1 : 0;
                }
                else if (dowFromDay > dowUntilDay)
                {
                    adBars[iBar] = Time[iBar].DayOfWeek >= dowFromDay ||
                                   Time[iBar].DayOfWeek < dowUntilDay ? 1 : 0;
                }
                else
                {
                    adBars[iBar] = 1;
                }
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "Allow long entry";
            Component[0].DataType      = IndComponentType.AllowOpenLong;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            Component[1]               = new IndicatorComp();
            Component[1].CompName      = "Allow short entry";
            Component[1].DataType      = IndComponentType.AllowOpenShort;
            Component[1].ChartType     = IndChartType.NoChart;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar      = iFirstBar;
            Component[1].Value         = adBars;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int firstBar = 4;

            double[] longSignals  = new double[Bars];
            double[] shortSignals = new double[Bars];

            for (int bar = firstBar; bar < Bars; bar++)
            {
                // Long trade
                if (Close[bar - 3] < Open[bar - 3] &&                 // Candle 1 is black
                    Low[bar - 2] < Low[bar - 3] &&                    // Candle 2 has lower low than candle 1
                    Close[bar - 1] > Open[bar - 1] &&                 // Candle 3 is white
                    Low[bar - 1] > Low[bar - 2] &&                    // Candle 3 has higher low than candle 2
                    Close[bar - 1] > Open[bar - 3])                   // Candle 3 closes above candle 1 open
                {
                    longSignals[bar] = 1;
                }

                // Short trade
                if (Close[bar - 3] > Open[bar - 3] &&                 // Candle 1 is white
                    High[bar - 2] > High[bar - 3] &&                  // Candle 2 has higher high than candle 1
                    Close[bar - 1] < Open[bar - 1] &&                 // Candle 3 is black
                    High[bar - 1] < High[bar - 2] &&                  // Candle 3 has lower high than candle 2
                    Close[bar - 1] < Open[bar - 3])                   // Candle 3 closes below candle 1 open
                {
                    shortSignals[bar] = 1;
                }
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Allow long entry";
            Component[0].DataType  = IndComponentType.AllowOpenLong;
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = firstBar;
            Component[0].Value     = longSignals;

            Component[1]           = new IndicatorComp();
            Component[1].CompName  = "Allow short entry";
            Component[1].DataType  = IndComponentType.AllowOpenShort;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = firstBar;
            Component[1].Value     = shortSignals;

            return;
        }
Пример #9
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int      iExitHour  = (int)IndParam.NumParam[0].Value;
            TimeSpan tsExitHour = new TimeSpan(iExitHour, 0, 0);

            // Calculation
            int iFirstBar = 1;

            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (Time[iBar - 1].DayOfYear == Time[iBar].DayOfYear &&
                    Time[iBar - 1].TimeOfDay < tsExitHour &&
                    Time[iBar].TimeOfDay >= tsExitHour)
                {
                    adBars[iBar - 1] = Close[iBar - 1];
                }
                else if (Time[iBar - 1].DayOfYear != Time[iBar].DayOfYear &&
                         Time[iBar - 1].TimeOfDay < tsExitHour)
                {
                    adBars[iBar - 1] = Close[iBar - 1];
                }
                else
                {
                    adBars[iBar] = 0;
                }
            }

            // Check the last bar
            if (Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int)Period, 0)) == tsExitHour)
            {
                adBars[Bars - 1] = Close[Bars - 1];
            }

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "Exit hour";
            Component[0].DataType      = IndComponentType.ClosePrice;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            return;
        }
Пример #10
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int      period   = (int)IndParam.NumParam[0].Value;
            int      multipl  = (int)IndParam.NumParam[1].Value;
            int      prev     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar = period + 2;

            double[] ATR = new double[Bars];

            for (int bar = 1; bar < Bars; bar++)
            {
                ATR[bar] = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);
            }

            ATR = MovingAverage(period, 0, maMethod, ATR);

            double[] ATRStop = new double[Bars];
            double   pip     = (Digits == 5 || Digits == 3) ? 10 * Point : Point;
            double   minStop = 5 * pip;

            for (int bar = firstBar; bar < Bars - prev; bar++)
            {
                ATRStop[bar + prev] = Math.Max(ATR[bar] * multipl, minStop);
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "ATR Stop margin";
            Component[0].DataType      = IndComponentType.IndicatorValue;
            Component[0].FirstBar      = firstBar;
            Component[0].ShowInDynInfo = false;
            Component[0].Value         = ATRStop;

            Component[1]               = new IndicatorComp();
            Component[1].CompName      = "ATR Stop for the transferred position";
            Component[1].DataType      = IndComponentType.Other;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar      = firstBar;
            Component[1].Value         = new double[Bars];

            return;
        }
Пример #11
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            int nExit = (int)IndParam.NumParam[0].Value;

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "N Bars Exit (" + nExit.ToString() + ")";
            Component[0].DataType      = IndComponentType.ForceClose;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = true;
            Component[0].FirstBar      = 1;
            Component[0].Value         = new double[Bars];
            return;
        }
Пример #12
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            int nExit = (int)IndParam.NumParam[0].Value;

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "N Bars Exit (" + nExit.ToString() + ")";
            Component[0].DataType      = IndComponentType.ForceClose;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = true;
            Component[0].FirstBar      = 1;
            Component[0].Value         = new double[Bars];
            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Calculation
            int iFirstBar = 1;

            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = 0; iBar < Bars - 1; iBar++)
            {
                if (Time[iBar].DayOfWeek > DayOfWeek.Wednesday &&
                    Time[iBar + 1].DayOfWeek < DayOfWeek.Wednesday)
                {
                    adBars[iBar] = Close[iBar];
                }
                else
                {
                    adBars[iBar] = 0;
                }
            }

            // Check the last bar
            TimeSpan tsBarClosing = Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int)Period, 0));
            TimeSpan tsDayClosing = new TimeSpan(24, 0, 0);

            if (Time[Bars - 1].DayOfWeek == DayOfWeek.Friday && tsBarClosing == tsDayClosing)
            {
                adBars[Bars - 1] = Close[Bars - 1];
            }

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "Week Closing";
            Component[0].DataType      = IndComponentType.ClosePrice;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            return;
        }
Пример #14
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iPERCENT = (int)IndParam.NumParam[0].Value;


            // Calculation
            int iFirstBar = 1;

            double[] doji  = new double[Bars];
            double   point = (Digits == 5 || Digits == 3) ? 10 * Point : Point;


            for (int iBar = 1; iBar < Bars; iBar++)
            {
                if (Math.Abs(Close[iBar - 1] - Open[iBar - 1]) < iPERCENT * 0.01 * (High[iBar - 1] - Low[iBar - 1]))
                {
                    doji[iBar] = 1;
                }
            }



            // Saving the components
            Component = new IndicatorComp[2];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Allow long entry";
            Component[0].DataType  = IndComponentType.AllowOpenLong;
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = doji;

            Component[1]           = new IndicatorComp();
            Component[1].CompName  = "Allow short entry";
            Component[1].DataType  = IndComponentType.AllowOpenShort;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = doji;

            return;
        }
Пример #15
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int      iFromDay    = (int)IndParam.ListParam[1].Index;
            int      iFromHour   = (int)IndParam.NumParam[0].Value;
            int      iFromMin    = (int)IndParam.NumParam[1].Value;
            int      iUntilDay   = (int)IndParam.ListParam[2].Index;
            int      iUntilHour  = (int)IndParam.NumParam[2].Value;
            int      iUntilMin   = (int)IndParam.NumParam[3].Value;
            TimeSpan tsFromTime  = new TimeSpan(iFromDay, iFromHour, iFromMin, 0);
            TimeSpan tsUntilTime = new TimeSpan(iUntilDay, iUntilHour, iUntilMin, 0);



            // Calculation
            int iFirstBar = 1;

            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                TimeSpan tsBar = new TimeSpan((int)Date[iBar].DayOfWeek, Date[iBar].Hour, Date[iBar].Minute, 0);
                adBars[iBar] = tsBar >= tsFromTime &&
                               tsBar < tsUntilTime      ? 1 : 0;
            }

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0]               = new IndicatorComp();
            Component[0].CompName      = "Force close position";
            Component[0].DataType      = IndComponentType.ForceClose;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;


            return;
        }
        /// <summary>
        /// Returns a copy
        /// </summary>
        public IndicatorComp Clone()
        {
            IndicatorComp icomp = new IndicatorComp();

            icomp.compName           = compName;
            icomp.dataType           = dataType;
            icomp.chartType          = chartType;
            icomp.chartColor         = chartColor;
            icomp.firstBar           = firstBar;
            icomp.prvs               = prvs;
            icomp.isDynInfo          = isDynInfo;
            icomp.posPriceDependence = posPriceDependence;

            if (adValue != null)
            {
                icomp.adValue = new double[adValue.Length];
                adValue.CopyTo(icomp.adValue, 0);
            }

            return(icomp);
        }
Пример #17
0
        /// <summary>
        /// Returns a copy.
        /// </summary>
        public IndicatorComp Clone()
        {
            var indicatorComp = new IndicatorComp
            {
                CompName           = CompName,
                DataType           = DataType,
                ChartType          = ChartType,
                ChartColor         = ChartColor,
                FirstBar           = FirstBar,
                UsePreviousBar     = UsePreviousBar,
                ShowInDynInfo      = ShowInDynInfo,
                PosPriceDependence = PosPriceDependence
            };


            if (Value != null)
            {
                indicatorComp.Value = new double[Value.Length];
                Value.CopyTo(indicatorComp.Value, 0);
            }

            return(indicatorComp);
        }
Пример #18
0
 /// <summary>
 /// The default constructor
 /// </summary>
 protected Indicator()
 {
     ExitFilterShortDescription = "Not defined";
     EntryFilterShortDescription = "Not defined";
     ExitFilterLongDescription = "Not defined";
     EntryFilterLongDescription = "Not defined";
     ExitPointShortDescription = "Not defined";
     ExitPointLongDescription = "Not defined";
     EntryPointShortDescription = "Not defined";
     EntryPointLongDescription = "Not defined";
     IndicatorName = string.Empty;
     PossibleSlots = SlotTypes.NotDefined;
     SeparatedChart = false;
     SeparatedChartMinValue = double.MaxValue;
     SeparatedChartMaxValue = double.MinValue;
     IsDescreteValues = false;
     CustomIndicator = false;
     WarningMessage = string.Empty;
     AllowClosingFilters = false;
     SpecialValues = new double[] {};
     IndParam = new IndicatorParam();
     Component = new IndicatorComp[] {};
 }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod)IndParam.ListParam[1].Index;
            int iPeriod1 = (int)IndParam.NumParam[0].Value;
            int iPeriod2 = (int)IndParam.NumParam[1].Value;
            int iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod1 + iPeriod2 + 2;
            double[] adIndicator1 = new double[Bars];
            double[] adIndicator2 = new double[Bars];
            double[] adOscllator  = new double[Bars];

            // ---------------------------------------------------------
            Average_True_Range ATR1 = new Average_True_Range(slotType);
            ATR1.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            ATR1.IndParam.NumParam[0].Value     = IndParam.NumParam[0].Value;
            ATR1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            ATR1.Calculate(slotType);

            Average_True_Range ATR2 = new Average_True_Range(slotType);
            ATR2.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            ATR2.IndParam.NumParam[0].Value     = IndParam.NumParam[1].Value;
            ATR2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            ATR2.Calculate(slotType);

            adIndicator1 = ATR1.Component[0].Value;
            adIndicator2 = ATR2.Component[0].Value;
            // ----------------------------------------------------------

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Histogram";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adOscllator;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Oscillator rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The Oscillator falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The Oscillator is higher than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    break;

                case "The Oscillator is lower than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    break;

                case "The Oscillator crosses the zero line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    break;

                case "The Oscillator crosses the zero line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    break;

                case "The Oscillator changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The Oscillator changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            NoDirectionOscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, ref Component[1], indLogic);
            Component[2].Value = Component[1].Value;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int period = (int)IndParam.NumParam[0].Value;
            int prev = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar = period + 2;

            double[] DIPos = new double[Bars];
            double[] DINeg = new double[Bars];

            for (int bar = 1; bar < Bars; bar++)
            {
                double trueRange = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);

                if (trueRange < Point)
                    trueRange = Point;

                double deltaHigh = High[bar] - High[bar - 1];
                double deltaLow  = Low[bar - 1] - Low[bar];

                if (deltaHigh > 0 && deltaHigh > deltaLow)
                    DIPos[bar] = 100 * deltaHigh / trueRange;
                else
                    DIPos[bar] = 0;

                if (deltaLow > 0 && deltaLow > deltaHigh)
                    DINeg[bar] = 100 * deltaLow / trueRange;
                else
                    DINeg[bar] = 0;
            }

            double[] ADIPos = MovingAverage(period, 0, maMethod, DIPos);
            double[] ADINeg = MovingAverage(period, 0, maMethod, DINeg);

            double[] ADIOsc = new double[Bars];

            for (int bar = 0; bar < Bars; bar++)
                ADIOsc[bar] = ADIPos[bar] - ADINeg[bar];

            // Saving the components
            Component = new IndicatorComp[4];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "The ADI+";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Green;
            Component[0].FirstBar   = firstBar;
            Component[0].Value      = ADIPos;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "The ADI-";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Red;
            Component[1].FirstBar   = firstBar;
            Component[1].Value      = ADINeg;

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = firstBar;
            Component[2].Value     = new double[Bars];

            Component[3] = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = firstBar;
            Component[3].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[2].CompName = "Is long entry allowed";
                Component[3].DataType = IndComponentType.AllowOpenShort;
                Component[3].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[2].CompName = "Close out long position";
                Component[3].DataType = IndComponentType.ForceCloseShort;
                Component[3].CompName = "Close out short position";
            }

            switch (IndParam.ListParam[0].Text)
            {
                case "The ADI+ rises":
                    OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises);
                    break;

                case "The ADI+ falls":
                    OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls);
                    break;

                case "The ADI- rises":
                    OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises);
                    break;

                case "The ADI- falls":
                    OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls);
                    break;

                case "The ADI+ is higher than ADI-":
                    OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_higher_than_the_level_line);
                    break;

                case "The ADI+ is lower than ADI-":
                    OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_lower_than_the_level_line);
                    break;

                case "The ADI+ crosses the ADI- line upward":
                    OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_upward);
                    break;

                case "The ADI+ crosses the ADI- line downward":
                    OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_downward);
                    break;

                case "The ADI+ changes its direction upward":
                    OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward);
                    break;

                case "The ADI+ changes its direction downward":
                    OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward);
                    break;

                case "The ADI- changes its direction upward":
                    OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward);
                    break;

                case "The ADI- changes its direction downward":
                    OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward);
                    break;

                default:
                    break;
            }

            return;
        }
Пример #21
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod1 = (MAMethod)IndParam.ListParam[1].Index;
            MAMethod  maMethod2 = (MAMethod)IndParam.ListParam[2].Index;
            BasePrice price     = (BasePrice)IndParam.ListParam[3].Index;
            int       iPeriod1  = (int)IndParam.NumParam[0].Value;
            int       iPeriod2  = (int)IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod1 + iPeriod2 + 1;

            double[] adPrice = Price(price);
            double[] adMA    = MovingAverage(iPeriod1, 0, maMethod1, adPrice);
            double[] adMAPr  = new double[Bars];

            for (int iBar = 0; iBar < Bars; iBar++)
            {
                adMAPr[iBar] = adPrice[iBar] - adMA[iBar];
            }

            double[] adDO = MovingAverage(iPeriod2, 0, maMethod2, adMAPr);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Detrended Oscillator";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.LightSeaGreen;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adDO;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The Detrended Oscillator rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

            case "The Detrended Oscillator falls":
                indLogic = IndicatorLogic.The_indicator_falls;
                break;

            case "The Detrended Oscillator is higher than the zero line":
                indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                break;

            case "The Detrended Oscillator is lower than the zero line":
                indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                break;

            case "The Detrended Oscillator crosses the zero line upward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                break;

            case "The Detrended Oscillator crosses the zero line downward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                break;

            case "The Detrended Oscillator changes its direction upward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                break;

            case "The Detrended Oscillator changes its direction downward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adDO, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #22
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int period = (int)IndParam.NumParam[0].Value;
            double level = IndParam.NumParam[1].Value;
            int prev = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar = 2 * period + 2;

            double[] DIPos = new double[Bars];
            double[] DINeg = new double[Bars];

            for (int bar = 1; bar < Bars; bar++)
            {
                double trueRange = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);

                if (trueRange < Point)
                    trueRange = Point;

                double deltaHigh = High[bar] - High[bar - 1];
                double deltaLow  = Low[bar - 1] - Low[bar];

                if (deltaHigh > 0 && deltaHigh > deltaLow)
                    DIPos[bar] = 100 * deltaHigh / trueRange;
                else
                    DIPos[bar] = 0;

                if (deltaLow > 0 && deltaLow > deltaHigh)
                    DINeg[bar] = 100 * deltaLow / trueRange;
                else
                    DINeg[bar] = 0;
            }

            double[] ADIPos = MovingAverage(period, 0, maMethod, DIPos);
            double[] ADINeg = MovingAverage(period, 0, maMethod, DINeg);

            double[] DX = new double[Bars];

            for (int bar = 0; bar < Bars; bar++)
            {
                if (ADIPos[bar] + ADINeg[bar] == 0)
                    DX[bar] = 0;
                else
                    DX[bar] = 100 * Math.Abs((ADIPos[bar] - ADINeg[bar]) / (ADIPos[bar] + ADINeg[bar]));
            }

            double[] ADX = MovingAverage(period, 0, maMethod, DX);

            // Saving the components
            Component = new IndicatorComp[5];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "ADX";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = firstBar;
            Component[0].Value      = ADX;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "ADI+";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Green;
            Component[1].FirstBar   = firstBar;
            Component[1].Value      = ADIPos;

            Component[2] = new IndicatorComp();
            Component[2].CompName   = "ADI-";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Line;
            Component[2].ChartColor = Color.Red;
            Component[2].FirstBar   = firstBar;
            Component[2].Value      = ADINeg;

            Component[3] = new IndicatorComp();
            Component[3].ChartType  = IndChartType.NoChart;
            Component[3].FirstBar   = firstBar;
            Component[3].Value      = new double[Bars];

            Component[4] = new IndicatorComp();
            Component[4].ChartType  = IndChartType.NoChart;
            Component[4].FirstBar   = firstBar;
            Component[4].Value      = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[3].DataType = IndComponentType.AllowOpenLong;
                Component[3].CompName = "Is long entry allowed";
                Component[4].DataType = IndComponentType.AllowOpenShort;
                Component[4].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[3].DataType = IndComponentType.ForceCloseLong;
                Component[3].CompName = "Close out long position";
                Component[4].DataType = IndComponentType.ForceCloseShort;
                Component[4].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic logicRule;

            switch (IndParam.ListParam[0].Text)
            {
                case "The ADX rises":
                    logicRule = IndicatorLogic.The_indicator_rises;
                    break;

                case "The ADX falls":
                    logicRule = IndicatorLogic.The_indicator_falls;
                    break;

                case "The ADX is higher than the Level line":
                    logicRule = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ADX is lower than the Level line":
                    logicRule = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ADX crosses the Level line upward":
                    logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ADX crosses the Level line downward":
                    logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ADX changes its direction upward":
                    logicRule = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The ADX changes its direction downward":
                    logicRule = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    logicRule = IndicatorLogic.It_does_not_act_as_a_filter;
                    break;
            }

            // ADX rises equal signals in both directions!
            NoDirectionOscillatorLogic(firstBar, prev, ADX, level, ref Component[3], logicRule);
            Component[4].Value = Component[3].Value;

            return;
        }
Пример #23
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int      iPeriod  = (int)IndParam.NumParam[0].Value;
            double   dLevel   = IndParam.NumParam[1].Value;
            int      iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + 2;

            double[] adDeMax    = new double[Bars];
            double[] adDeMin    = new double[Bars];
            double[] adDeMarker = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adDeMax[iBar] = High[iBar] > High[iBar - 1] ? High[iBar] - High[iBar - 1] : 0;
                adDeMin[iBar] = Low[iBar] < Low[iBar - 1]  ? Low[iBar - 1] - Low[iBar]  : 0;
            }

            double[] adDeMaxMA = MovingAverage(iPeriod, 0, maMethod, adDeMax);
            double[] adDeMinMA = MovingAverage(iPeriod, 0, maMethod, adDeMin);

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (adDeMaxMA[iBar] + adDeMinMA[iBar] == 0)
                {
                    adDeMarker[iBar] = 0;
                }
                else
                {
                    adDeMarker[iBar] = adDeMaxMA[iBar] / (adDeMaxMA[iBar] + adDeMinMA[iBar]);
                }
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "DeMarker";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.RoyalBlue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adDeMarker;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The DeMarker rises":
                indLogic      = IndicatorLogic.The_indicator_rises;
                SpecialValues = new double[1] {
                    0.5
                };
                break;

            case "The DeMarker falls":
                indLogic      = IndicatorLogic.The_indicator_falls;
                SpecialValues = new double[1] {
                    0.5
                };
                break;

            case "The DeMarker is higher than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                SpecialValues = new double[2] {
                    dLevel, 1 - dLevel
                };
                break;

            case "The DeMarker is lower than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                SpecialValues = new double[2] {
                    dLevel, 1 - dLevel
                };
                break;

            case "The DeMarker crosses the Level line upward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                SpecialValues = new double[2] {
                    dLevel, 1 - dLevel
                };
                break;

            case "The DeMarker crosses the Level line downward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                SpecialValues = new double[2] {
                    dLevel, 1 - dLevel
                };
                break;

            case "The DeMarker changes its direction upward":
                indLogic      = IndicatorLogic.The_indicator_changes_its_direction_upward;
                SpecialValues = new double[1] {
                    0.5
                };
                break;

            case "The DeMarker changes its direction downward":
                indLogic      = IndicatorLogic.The_indicator_changes_its_direction_downward;
                SpecialValues = new double[1] {
                    0.5
                };
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adDeMarker, dLevel, 1 - dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            int       iSmooth   = (int)IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            double[] adBasePrice = Price(basePrice);
            double[] adMA        = new double[Bars];
            int      iFirstBar   = iPeriod + iSmooth + 1 + iPrvs;

            // Calculating Chande Momentum Oscillator
            double[] adCMO1    = new double[Bars];
            double[] adCMO2    = new double[Bars];
            double[] adCMO1Sum = new double[Bars];
            double[] adCMO2Sum = new double[Bars];
            double[] adCMO     = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adCMO1[iBar] = 0;
                adCMO2[iBar] = 0;
                if (adBasePrice[iBar] > adBasePrice[iBar - 1])
                {
                    adCMO1[iBar] = adBasePrice[iBar] - adBasePrice[iBar - 1];
                }
                if (adBasePrice[iBar] < adBasePrice[iBar - 1])
                {
                    adCMO2[iBar] = adBasePrice[iBar - 1] - adBasePrice[iBar];
                }
            }

            for (int iBar = 0; iBar < iPeriod; iBar++)
            {
                adCMO1Sum[iPeriod - 1] += adCMO1[iBar];
                adCMO2Sum[iPeriod - 1] += adCMO2[iBar];
            }

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                adCMO1Sum[iBar] = adCMO1Sum[iBar - 1] + adCMO1[iBar] - adCMO1[iBar - iPeriod];
                adCMO2Sum[iBar] = adCMO2Sum[iBar - 1] + adCMO2[iBar] - adCMO2[iBar - iPeriod];

                if (adCMO1Sum[iBar] + adCMO2Sum[iBar] == 0)
                {
                    adCMO[iBar] = 100;
                }
                else
                {
                    adCMO[iBar] = 100 * (adCMO1Sum[iBar] - adCMO2Sum[iBar]) / (adCMO1Sum[iBar] + adCMO2Sum[iBar]);
                }
            }

            double SC = 2.0 / (iSmooth + 1);

            for (int iBar = 0; iBar < iPeriod; iBar++)
            {
                adMA[iBar] = adBasePrice[iBar];
            }

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                double dAbsCMO = Math.Abs(adCMO[iBar]) / 100;
                adMA[iBar] = SC * dAbsCMO * adBasePrice[iBar] + (1 - SC * dAbsCMO) * adMA[iBar - 1];
            }

            // Saving the components
            if (slotType == SlotTypes.Open || slotType == SlotTypes.Close)
            {
                Component = new IndicatorComp[2];

                Component[1]       = new IndicatorComp();
                Component[1].Value = new double[Bars];

                for (int iBar = 2; iBar < Bars; iBar++)
                {                                                            // Covers the cases when the price can pass through the MA without a signal
                    double dValue   = adMA[iBar - iPrvs];                    // Current value
                    double dValue1  = adMA[iBar - iPrvs - 1];                // Previous value
                    double dTempVal = dValue;
                    if ((dValue1 > High[iBar - 1] && dValue < Open[iBar]) || // It jumps below the current bar
                        (dValue1 <Low[iBar - 1] && dValue> Open[iBar]) ||    // It jumps above the current bar
                        (Close[iBar - 1] < dValue && dValue < Open[iBar]) || // Positive gap
                        (Close[iBar - 1] > dValue && dValue > Open[iBar]))   // Negative gap
                    {
                        dTempVal = Open[iBar];
                    }
                    Component[1].Value[iBar] = dTempVal;
                }
            }
            else
            {
                Component = new IndicatorComp[3];

                Component[1]           = new IndicatorComp();
                Component[1].ChartType = IndChartType.NoChart;
                Component[1].FirstBar  = iFirstBar;
                Component[1].Value     = new double[Bars];

                Component[2]           = new IndicatorComp();
                Component[2].ChartType = IndChartType.NoChart;
                Component[2].FirstBar  = iFirstBar;
                Component[2].Value     = new double[Bars];
            }

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "MA Value";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Red;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMA;

            if (slotType == SlotTypes.Open)
            {
                Component[1].CompName = "Position opening price";
                Component[1].DataType = IndComponentType.OpenPrice;
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[1].CompName = "Position closing price";
                Component[1].DataType = IndComponentType.ClosePrice;
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
            {
                switch (IndParam.ListParam[0].Text)
                {
                case "The Vidya Moving Average rises":
                    IndicatorRisesLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The Vidya Moving Average falls":
                    IndicatorFallsLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens above the Vidya Moving Average":
                    BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens below the Vidya Moving Average":
                    BarOpensBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens above the Vidya Moving Average after opening below it":
                    BarOpensAboveIndicatorAfterOpeningBelowLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens below the Vidya Moving Average after opening above it":
                    BarOpensBelowIndicatorAfterOpeningAboveLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The position opens above the Vidya Moving Average":
                    Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower;
                    Component[0].UsePreviousBar     = iPrvs;
                    Component[1].DataType           = IndComponentType.Other;
                    Component[1].ShowInDynInfo      = false;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    break;

                case "The position opens below the Vidya Moving Average":
                    Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher;
                    Component[0].UsePreviousBar     = iPrvs;
                    Component[1].DataType           = IndComponentType.Other;
                    Component[1].ShowInDynInfo      = false;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    break;

                case "The bar closes below the Vidya Moving Average":
                    BarClosesBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar closes above the Vidya Moving Average":
                    BarClosesAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                default:
                    break;
                }
            }

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod1 = (MAMethod)IndParam.ListParam[1].Index;
            MAMethod  maMethod2 = (MAMethod)IndParam.ListParam[2].Index;
            BasePrice price     = (BasePrice)IndParam.ListParam[3].Index;
            int iPeriod1  = (int)IndParam.NumParam[0].Value;
            int iPeriod2  = (int)IndParam.NumParam[1].Value;
            int iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod1 + iPeriod2 + 1;

            double[] adPrice = Price(price);
            double[] adMA    = MovingAverage(iPeriod1, 0, maMethod1, adPrice);
            double[] adMAPr  = new double[Bars];

            for (int iBar = 0; iBar < Bars; iBar++)
            {
                adMAPr[iBar] = adPrice[iBar] - adMA[iBar];
            }

            double[] adDO = MovingAverage(iPeriod2, 0, maMethod2, adMAPr);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Detrended Oscillator";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.LightSeaGreen;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adDO;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Detrended Oscillator rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The Detrended Oscillator falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The Detrended Oscillator is higher than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    break;

                case "The Detrended Oscillator is lower than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    break;

                case "The Detrended Oscillator crosses the zero line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    break;

                case "The Detrended Oscillator crosses the zero line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    break;

                case "The Detrended Oscillator changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The Detrended Oscillator changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adDO, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int    iPeriod = (int)IndParam.NumParam[0].Value;
            double dLevel  = IndParam.NumParam[1].Value;
            int    iPrvs   = IndParam.CheckParam[0].Checked ? 1 : 0;

            int iFirstBar = iPeriod + iPrvs;

            // Calculating Money Flow
            double[] adMF  = new double[Bars];
            for (int iBar = 1; iBar < Bars; iBar++)
            {
                double dAVG  = (High[iBar] + Low[iBar] + Close[iBar]) / 3;
                double dAVG1 = (High[iBar - 1] + Low[iBar - 1] + Close[iBar - 1]) / 3;
                if (dAVG > dAVG1)
                    adMF[iBar] = adMF[iBar - 1] + dAVG * Volume[iBar];
                else if (dAVG < dAVG1)
                    adMF[iBar] = adMF[iBar - 1] - dAVG * Volume[iBar];
                else
                    adMF[iBar] = adMF[iBar - 1];
            }

            // Calculating Money Flow Index
            double[] adMFI = new double[Bars];
            for (int iBar = iPeriod + 1; iBar < Bars; iBar++)
            {
                double dPMF = 0;
                double dNMF = 0;
                for (int index = 0; index < iPeriod; index++)
                {
                    if (adMF[iBar - index] > adMF[iBar - index - 1])
                        dPMF += adMF[iBar - index] - adMF[iBar - index - 1];
                    if (adMF[iBar - index] < adMF[iBar - index - 1])
                        dNMF += adMF[iBar - index - 1] - adMF[iBar - index];
                }
                if (dNMF == 0)
                    adMFI[iBar] = 100.0;
                else
                    adMFI[iBar] = 100.0 - (100.0 / (1.0 + (dPMF / dNMF)));
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Money Flow Index";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMFI;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The MFI rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    SpecialValues = new double[1] { 50 };
                    break;

                case "The MFI falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    SpecialValues = new double[1] { 50 };
                    break;

                case "The MFI is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The MFI is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The MFI crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The MFI crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The MFI changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    SpecialValues = new double[1] { 50 };
                    break;

                case "The MFI changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    SpecialValues = new double[1] { 50 };
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adMFI, dLevel, 100 - dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod       = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice price          = BasePrice.Close;
            int       nMA            = (int)IndParam.NumParam[0].Value;
            int       iATRPeriod     = (int)IndParam.NumParam[1].Value;
            int       iATRMultiplier = (int)IndParam.NumParam[3].Value;
            int       iPrvs          = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            double[] adMA      = MovingAverage(nMA, 0, maMethod, Price(price));
            double[] adATR     = new double[Bars];
            double[] adUpBand  = new double[Bars];
            double[] adDnBand  = new double[Bars];

            int iFirstBar = (int)Math.Max(nMA, iATRPeriod) + iPrvs + 2;

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adATR[iBar] = Math.Max(Math.Abs(High[iBar] - Close[iBar - 1]), Math.Abs(Close[iBar - 1] - Low[iBar]));
                adATR[iBar] = Math.Max(Math.Abs(High[iBar] - Low[iBar]), adATR[iBar]);
            }

            adATR = MovingAverage(iATRPeriod, 0, maMethod, adATR);

            for (int iBar = nMA; iBar < Bars; iBar++)
            {
                adUpBand[iBar] = adMA[iBar] + adATR[iBar] * iATRMultiplier;
                adDnBand[iBar] = adMA[iBar] - adATR[iBar] * iATRMultiplier;
            }

            // Saving the components
            Component = new IndicatorComp[5];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Upper Band";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adUpBand;

            Component[1]            = new IndicatorComp();
            Component[1].CompName   = "Moving Average";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Gold;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adMA;

            Component[2]            = new IndicatorComp();
            Component[2].CompName   = "Lower Band";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Line;
            Component[2].ChartColor = Color.Blue;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = adDnBand;

            Component[3] = new IndicatorComp();
            Component[3].ChartType  = IndChartType.NoChart;
            Component[3].FirstBar   = iFirstBar;
            Component[3].Value      = new double[Bars];

            Component[4] = new IndicatorComp();
            Component[4].ChartType  = IndChartType.NoChart;
            Component[4].FirstBar   = iFirstBar;
            Component[4].Value      = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.Open)
            {
                Component[3].DataType = IndComponentType.OpenLongPrice;
                Component[3].CompName = "Long position entry price";
                Component[4].DataType = IndComponentType.OpenShortPrice;
                Component[4].CompName = "Short position entry price";
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[3].DataType = IndComponentType.AllowOpenLong;
                Component[3].CompName = "Is long entry allowed";
                Component[4].DataType = IndComponentType.AllowOpenShort;
                Component[4].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[3].DataType = IndComponentType.CloseLongPrice;
                Component[3].CompName = "Long position closing price";
                Component[4].DataType = IndComponentType.CloseShortPrice;
                Component[4].CompName = "Short position closing price";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[3].DataType = IndComponentType.ForceCloseLong;
                Component[3].CompName = "Close out long position";
                Component[4].DataType = IndComponentType.ForceCloseShort;
                Component[4].CompName = "Close out short position";
            }

            if (slotType == SlotTypes.Open || slotType == SlotTypes.Close)
            {
                if (nMA > 1)
                {
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {   // Covers the cases when the price can pass through the band without a signal.
                        double dOpen = Open[iBar]; // Current open price

                        // Upper band
                        double dValueUp   = adUpBand[iBar - iPrvs];     // Current value
                        double dValueUp1  = adUpBand[iBar - iPrvs - 1]; // Previous value
                        double dTempValUp = dValueUp;

                        if ((dValueUp1 > High[iBar - 1] && dValueUp < dOpen) || // The Open price jumps above the indicator
                            (dValueUp1 < Low[iBar -  1] && dValueUp > dOpen) || // The Open price jumps below the indicator
                            (Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Open price is in a positive gap
                            (Close[iBar - 1] > dValueUp && dValueUp > dOpen))   // The Open price is in a negative gap
                            dTempValUp = dOpen; // The entry/exit level is moved to Open price

                        // Lower band
                        double dValueDown   = adDnBand[iBar - iPrvs];     // Current value
                        double dValueDown1  = adDnBand[iBar - iPrvs - 1]; // Previous value
                        double dTempValDown = dValueDown;

                        if ((dValueDown1 > High[iBar - 1] && dValueDown < dOpen) || // The Open price jumps above the indicator
                            (dValueDown1 < Low[iBar  - 1] && dValueDown > dOpen) || // The Open price jumps below the indicator
                            (Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Open price is in a positive gap
                            (Close[iBar - 1] > dValueDown && dValueDown > dOpen))   // The Open price is in a negative gap
                            dTempValDown = dOpen; // The entry/exit level is moved to Open price

                        if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
                            IndParam.ListParam[0].Text == "Exit long at the Upper Band")
                        {
                            Component[3].Value[iBar] = dTempValUp;
                            Component[4].Value[iBar] = dTempValDown;
                        }
                        else
                        {
                            Component[3].Value[iBar] = dTempValDown;
                            Component[4].Value[iBar] = dTempValUp;
                        }
                    }
                }
                else
                {
                    for (int iBar = 2; iBar < Bars; iBar++)
                    {
                        if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
                            IndParam.ListParam[0].Text == "Exit long at the Upper Band")
                        {
                            Component[3].Value[iBar] = adUpBand[iBar - iPrvs];
                            Component[4].Value[iBar] = adDnBand[iBar - iPrvs];
                        }
                        else
                        {
                            Component[3].Value[iBar] = adDnBand[iBar - iPrvs];
                            Component[4].Value[iBar] = adUpBand[iBar - iPrvs];
                        }
                    }
                }
            }
            else
            {
                switch (IndParam.ListParam[0].Text)
                {
                    case "The bar opens below the Upper Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band);
                        break;

                    case "The bar opens above the Upper Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band);
                        break;

                    case "The bar opens below the Lower Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band);
                        break;

                    case "The bar opens above the Lower Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band);
                        break;

                    case "The bar opens below the Upper Band after opening above it":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it);
                        break;

                    case "The bar opens above the Upper Band after opening below it":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it);
                        break;

                    case "The bar opens below the Lower Band after opening above it":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it);
                        break;

                    case "The bar opens above the Lower Band after opening below it":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it);
                        break;

                    case "The position opens above the Upper Band":
                        Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                        Component[2].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                        Component[0].UsePreviousBar = iPrvs;
                        Component[2].UsePreviousBar = iPrvs;
                        Component[3].DataType = IndComponentType.Other;
                        Component[4].DataType = IndComponentType.Other;
                        Component[3].ShowInDynInfo = false;
                        Component[4].ShowInDynInfo = false;
                        break;

                    case "The position opens below the Upper Band":
                        Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
                        Component[2].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
                        Component[0].UsePreviousBar = iPrvs;
                        Component[2].UsePreviousBar = iPrvs;
                        Component[3].DataType = IndComponentType.Other;
                        Component[4].DataType = IndComponentType.Other;
                        Component[3].ShowInDynInfo = false;
                        Component[4].ShowInDynInfo = false;
                        break;

                    case "The position opens above the Lower Band":
                        Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                        Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                        Component[0].UsePreviousBar = iPrvs;
                        Component[2].UsePreviousBar = iPrvs;
                        Component[3].DataType = IndComponentType.Other;
                        Component[4].DataType = IndComponentType.Other;
                        Component[3].ShowInDynInfo = false;
                        Component[4].ShowInDynInfo = false;
                        break;

                    case "The position opens below the Lower Band":
                        Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
                        Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
                        Component[0].UsePreviousBar = iPrvs;
                        Component[2].UsePreviousBar = iPrvs;
                        Component[3].DataType = IndComponentType.Other;
                        Component[4].DataType = IndComponentType.Other;
                        Component[3].ShowInDynInfo = false;
                        Component[4].ShowInDynInfo = false;
                        break;

                    case "The bar closes below the Upper Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Upper_Band);
                        break;

                    case "The bar closes above the Upper Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Upper_Band);
                        break;

                    case "The bar closes below the Lower Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Lower_Band);
                        break;

                    case "The bar closes above the Lower Band":
                        BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Lower_Band);
                        break;

                    default:
                        break;
                }
            }

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iStepBack = (IndParam.ListParam[0].Text == "There is a NR4 formation" ? 3 : 6);
            int iFirstBar = iStepBack + iPrvs;
            double[] adNR    = new double[Bars];
            double[] adRange = new double[Bars];

            for (int iBar = 0; iBar < Bars; iBar++)
            {
                adRange[iBar] = High[iBar] - Low[iBar];
                adNR[iBar] = 0;
            }

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                bool bNarrowRange = true;
                for (int i = 1; i <= iStepBack; i++)
                    if (adRange[iBar - i - iPrvs] <= adRange[iBar - iPrvs])
                    {
                        bNarrowRange = false;
                        break;
                    }

                if (bNarrowRange) adNR[iBar] = 1;
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Bar Range";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = new double[Bars];
            for (int i = 0; i < Bars; i++)
                Component[0].Value[i] = (double)Math.Round(adRange[i] / Point);

            Component[1] = new IndicatorComp();
            Component[1].CompName  = "Allow long entry";
            Component[1].DataType  = IndComponentType.AllowOpenLong;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = adNR;

            Component[2] = new IndicatorComp();
            Component[2].CompName  = "Allow short entry";
            Component[2].DataType  = IndComponentType.AllowOpenShort;
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = adNR;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iYear  = (int)IndParam.NumParam[0].Value;
            int iMonth = (int)IndParam.NumParam[1].Value;
            DateTime dtKeyDate = new DateTime(iYear, iMonth, 1);

            // Calculation
            int iFirstBar = 0;
            double[] adBars = new double[Bars];

            // Calculation of the logic.
            switch (IndParam.ListParam[0].Text)
            {
                case "Do not open positions after":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                        if (Time[iBar] < dtKeyDate)
                            adBars[iBar] = 1;

                    break;

                case "Do not open positions before":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        if (Time[iBar] >= dtKeyDate)
                        {
                            iFirstBar = iBar;
                            break;
                        }
                    }

                    iFirstBar = (int)Math.Min(iFirstBar, Bars - Configs.MIN_BARS);

                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        adBars[iBar] = 1;
                    }

                    break;

                default:
                    break;
            }

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "Allow Open Long";
            Component[0].DataType      = IndComponentType.AllowOpenLong;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            Component[1] = new IndicatorComp();
            Component[1].CompName      = "Allow Open Short";
            Component[1].DataType      = IndComponentType.AllowOpenShort;
            Component[1].ChartType     = IndChartType.NoChart;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar      = iFirstBar;
            Component[1].Value         = adBars;

            return;
        }
Пример #30
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iEntryHour   = (int)IndParam.NumParam[0].Value;
            int iEntryMinute = (int)IndParam.NumParam[1].Value;
            TimeSpan tsEntryHour = new TimeSpan(iEntryHour, iEntryMinute, 0);

            // Calculation
            int iFirstBar = 1;
            double[] adBars = new double[Bars];

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adBars[iBar] = Time[iBar].TimeOfDay == tsEntryHour ? Open[iBar] : 0;
            }

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "Entry hour";
            Component[0].DataType      = IndComponentType.OpenPrice;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            int iTenkan = (int)IndParam.NumParam[0].Value;
            int iKijun  = (int)IndParam.NumParam[2].Value;
            int iSenkou = (int)IndParam.NumParam[4].Value;
            int iPrvs   = IndParam.CheckParam[0].Checked ? 1 : 0;

            double[] adMedianPrice = Price(BasePrice.Median);

            int iFirstBar = 1 + iKijun + iSenkou;

            double[] adTenkanSen = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                double dHighestHigh = double.MinValue;
                double dLowestLow   = double.MaxValue;
                for (int i = 0; i < iTenkan; i++)
                {
                    if (High[iBar - i] > dHighestHigh)
                        dHighestHigh = High[iBar - i];
                    if (Low[iBar - i] < dLowestLow)
                        dLowestLow = Low[iBar - i];
                }
                adTenkanSen[iBar] = (dHighestHigh + dLowestLow) / 2;
            }

            double[] adKijunSen = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                double dHighestHigh = double.MinValue;
                double dLowestLow   = double.MaxValue;
                for (int i = 0; i < iKijun; i++)
                {
                    if (High[iBar - i] > dHighestHigh)
                        dHighestHigh = High[iBar - i];
                    if (Low[iBar - i] < dLowestLow)
                        dLowestLow = Low[iBar - i];
                }
                adKijunSen[iBar] = (dHighestHigh + dLowestLow) / 2;
            }

            double[] adChikouSpan  = new double[Bars];
            for (int iBar = 0; iBar < Bars - iKijun; iBar++)
            {
                adChikouSpan[iBar] = Close[iBar + iKijun];
            }

            double[] adSenkouSpanA  = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++)
            {
                adSenkouSpanA[iBar + iKijun] = (adTenkanSen[iBar] + adKijunSen[iBar]) / 2;
            }

            double[] adSenkouSpanB  = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++)
            {
                double dHighestHigh = double.MinValue;
                double dLowestLow   = double.MaxValue;
                for (int i = 0; i < iSenkou; i++)
                {
                    if (High[iBar - i] > dHighestHigh)
                        dHighestHigh = High[iBar - i];
                    if (Low[iBar - i] < dLowestLow)
                        dLowestLow = Low[iBar - i];
                }
                adSenkouSpanB[iBar + iKijun] = (dHighestHigh + dLowestLow) / 2;
            }

            // Saving the components
            if (slotType == SlotTypes.OpenFilter)
                Component = new IndicatorComp[7];
            else
                Component = new IndicatorComp[6];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Tenkan Sen";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Red;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adTenkanSen;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Kijun Sen";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Blue;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adKijunSen;

            Component[2] = new IndicatorComp();
            Component[2].CompName   = "Chikou Span";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Line;
            Component[2].ChartColor = Color.Green;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = adChikouSpan;

            Component[3] = new IndicatorComp();
            Component[3].CompName   = "Senkou Span A";
            Component[3].DataType   = IndComponentType.IndicatorValue;
            Component[3].ChartType  = IndChartType.CloudUp;
            Component[3].ChartColor = Color.SandyBrown;
            Component[3].FirstBar   = iFirstBar;
            Component[3].Value      = adSenkouSpanA;

            Component[4] = new IndicatorComp();
            Component[4].CompName   = "Senkou Span B";
            Component[4].DataType   = IndComponentType.IndicatorValue;
            Component[4].ChartType  = IndChartType.CloudDown;
            Component[4].ChartColor = Color.Thistle;
            Component[4].FirstBar   = iFirstBar;
            Component[4].Value      = adSenkouSpanB;

            Component[5] = new IndicatorComp();
            Component[5].FirstBar = iFirstBar;
            Component[5].Value    = new double[Bars];
            Component[5].DataType = IndComponentType.Other;

            if (slotType == SlotTypes.OpenFilter)
            {
                Component[5].CompName = "Is long entry allowed";
                Component[5].DataType = IndComponentType.AllowOpenLong;

                Component[6] = new IndicatorComp();
                Component[6].FirstBar = iFirstBar;
                Component[6].Value    = new double[Bars];
                Component[6].CompName = "Is short entry allowed";
                Component[6].DataType = IndComponentType.AllowOpenShort;
            }

            switch (IndParam.ListParam[0].Text)
            {
                case "Enter the market at the Tenkan Sen":
                    Component[5].CompName  = "Tenkan Sen entry price";
                    Component[5].DataType  = IndComponentType.OpenPrice;
                    Component[5].ChartType = IndChartType.NoChart;
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs];
                    }
                    break;
                case "Enter the market at the Kijun Sen":
                    Component[5].CompName  = "Kijun Sen entry price";
                    Component[5].DataType  = IndComponentType.OpenPrice;
                    Component[5].ChartType = IndChartType.NoChart;
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adKijunSen[iBar - iPrvs];
                    }
                    break;
                case "Exit the market at the Tenkan Sen":
                    Component[5].CompName  = "Tenkan Sen exit price";
                    Component[5].DataType  = IndComponentType.ClosePrice;
                    Component[5].ChartType = IndChartType.NoChart;
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs];
                    }
                    break;
                case "Exit the market at the Kijun Sen":
                    Component[5].CompName  = "Kijun Sen exit price";
                    Component[5].DataType  = IndComponentType.ClosePrice;
                    Component[5].ChartType = IndChartType.NoChart;
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adKijunSen[iBar - iPrvs];
                    }
                    break;
                case "The Tenkan Sen rises":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > adTenkanSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < adTenkanSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0;
                    }
                    break;
                case "The Kijun Sen rises":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > adKijunSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < adKijunSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0;
                    }
                    break;
                case "The Tenkan Sen is higher than the Kijun Sen":
                    IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]);
                    break;
                case "The Tenkan Sen crosses the Kijun Sen upward":
                    IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]);
                    break;
                case "The bar opens above the Tenkan Sen":
                    BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, ref Component[5], ref Component[6]);
                    break;
                case "The bar opens above the Kijun Sen":
                    BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adKijunSen, ref Component[5], ref Component[6]);
                    break;
                case "The Chikou Span is above the closing price":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] > Close[iBar - iKijun - iPrvs] + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] < Close[iBar - iKijun - iPrvs] - Sigma() ? 1 : 0;
                    }
                    break;

                case "The position opens above the Kumo":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
                        Component[6].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
                    }
                    Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                    Component[5].DataType = IndComponentType.Other;
                    Component[5].UsePreviousBar = iPrvs;
                    Component[5].ShowInDynInfo  = false;

                    Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                    Component[6].DataType = IndComponentType.Other;
                    Component[6].UsePreviousBar = iPrvs;
                    Component[6].ShowInDynInfo  = false;
                    break;

                case "The position opens inside or above the Kumo":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
                        Component[6].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
                    }
                    Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                    Component[5].DataType = IndComponentType.Other;
                    Component[5].UsePreviousBar = iPrvs;
                    Component[5].ShowInDynInfo  = false;

                    Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                    Component[6].DataType = IndComponentType.Other;
                    Component[6].UsePreviousBar = iPrvs;
                    Component[6].ShowInDynInfo  = false;
                    break;

                case "The Tenkan Sen is above the Kumo":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
                    }
                    break;

                case "The Tenkan Sen is inside or above the Kumo":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
                    }
                    break;

                case "The Kijun Sen is above the Kumo":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
                    }
                    break;

                case "The Kijun Sen is inside or above the Kumo":
                    for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
                    {
                        Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
                        Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
                    }
                    break;

                case "The Senkou Span A is higher than the Senkou Span B":
                    IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]);
                    break;

                case "The Senkou Span A crosses the Senkou Span B upward":
                    IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]);
                    break;

                default:
                    break;
            }

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int iPeriod  = (int)IndParam.NumParam[0].Value;
            int iSmooth  = (int)IndParam.NumParam[1].Value;
            int iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            double[] adBasePrice = Price(basePrice);
            double[] adMA = new double[Bars];
            int iFirstBar = iPeriod + iSmooth + 1 + iPrvs;

            // Calculating Chande Momentum Oscillator
            double[] adCMO1      = new double[Bars];
            double[] adCMO2      = new double[Bars];
            double[] adCMO1Sum   = new double[Bars];
            double[] adCMO2Sum   = new double[Bars];
            double[] adCMO       = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adCMO1[iBar] = 0;
                adCMO2[iBar] = 0;
                if (adBasePrice[iBar] > adBasePrice[iBar - 1])
                    adCMO1[iBar] = adBasePrice[iBar] - adBasePrice[iBar - 1];
                if (adBasePrice[iBar] < adBasePrice[iBar - 1])
                    adCMO2[iBar] = adBasePrice[iBar - 1] - adBasePrice[iBar];
            }

            for (int iBar = 0; iBar < iPeriod; iBar++)
            {
                adCMO1Sum[iPeriod - 1] += adCMO1[iBar];
                adCMO2Sum[iPeriod - 1] += adCMO2[iBar];
            }

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                adCMO1Sum[iBar] = adCMO1Sum[iBar - 1] + adCMO1[iBar] - adCMO1[iBar - iPeriod];
                adCMO2Sum[iBar] = adCMO2Sum[iBar - 1] + adCMO2[iBar] - adCMO2[iBar - iPeriod];

                if (adCMO1Sum[iBar] + adCMO2Sum[iBar] == 0)
                    adCMO[iBar] = 100;
                else
                    adCMO[iBar] = 100 * (adCMO1Sum[iBar] - adCMO2Sum[iBar]) / (adCMO1Sum[iBar] + adCMO2Sum[iBar]);
            }

            double SC = 2.0 / (iSmooth + 1);

            for (int iBar = 0; iBar < iPeriod; iBar++)
                adMA[iBar] = adBasePrice[iBar];

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                double dAbsCMO = Math.Abs(adCMO[iBar]) / 100;
                adMA[iBar] = SC * dAbsCMO * adBasePrice[iBar] + (1 - SC * dAbsCMO) * adMA[iBar - 1];
            }

            // Saving the components
            if (slotType == SlotTypes.Open || slotType == SlotTypes.Close)
            {
                Component = new IndicatorComp[2];

                Component[1] = new IndicatorComp();
                Component[1].Value = new double[Bars];

                for (int iBar = 2; iBar < Bars; iBar++)
                {   // Covers the cases when the price can pass through the MA without a signal
                    double dValue   = adMA[iBar - iPrvs];     // Current value
                    double dValue1  = adMA[iBar - iPrvs - 1]; // Previous value
                    double dTempVal = dValue;
                    if ((dValue1 > High[iBar - 1] && dValue < Open[iBar]) || // It jumps below the current bar
                        (dValue1 < Low[iBar - 1]  && dValue > Open[iBar]) || // It jumps above the current bar
                        (Close[iBar - 1] < dValue && dValue < Open[iBar]) || // Positive gap
                        (Close[iBar - 1] > dValue && dValue > Open[iBar]))   // Negative gap
                        dTempVal = Open[iBar];
                    Component[1].Value[iBar] = dTempVal;
                }
            }
            else
            {
                Component = new IndicatorComp[3];

                Component[1] = new IndicatorComp();
                Component[1].ChartType = IndChartType.NoChart;
                Component[1].FirstBar  = iFirstBar;
                Component[1].Value     = new double[Bars];

                Component[2] = new IndicatorComp();
                Component[2].ChartType = IndChartType.NoChart;
                Component[2].FirstBar  = iFirstBar;
                Component[2].Value     = new double[Bars];
            }

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "MA Value";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Red;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMA;

            if (slotType == SlotTypes.Open)
            {
                Component[1].CompName = "Position opening price";
                Component[1].DataType = IndComponentType.OpenPrice;
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[1].CompName = "Position closing price";
                Component[1].DataType = IndComponentType.ClosePrice;
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
            {
                switch (IndParam.ListParam[0].Text)
                {
                    case "The Vidya Moving Average rises":
                        IndicatorRisesLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The Vidya Moving Average falls":
                        IndicatorFallsLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The bar opens above the Vidya Moving Average":
                        BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The bar opens below the Vidya Moving Average":
                        BarOpensBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The bar opens above the Vidya Moving Average after opening below it":
                        BarOpensAboveIndicatorAfterOpeningBelowLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The bar opens below the Vidya Moving Average after opening above it":
                        BarOpensBelowIndicatorAfterOpeningAboveLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The position opens above the Vidya Moving Average":
                        Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower;
                        Component[0].UsePreviousBar     = iPrvs;
                        Component[1].DataType           = IndComponentType.Other;
                        Component[1].ShowInDynInfo      = false;
                        Component[2].DataType           = IndComponentType.Other;
                        Component[2].ShowInDynInfo      = false;
                        break;

                    case "The position opens below the Vidya Moving Average":
                        Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher;
                        Component[0].UsePreviousBar     = iPrvs;
                        Component[1].DataType           = IndComponentType.Other;
                        Component[1].ShowInDynInfo      = false;
                        Component[2].DataType           = IndComponentType.Other;
                        Component[2].ShowInDynInfo      = false;
                        break;

                    case "The bar closes below the Vidya Moving Average":
                        BarClosesBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    case "The bar closes above the Vidya Moving Average":
                        BarClosesAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                        break;

                    default:
                        break;
                }
            }

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            MAMethod  slMethod  = (MAMethod )IndParam.ListParam[3].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       nSlow     = (int)IndParam.NumParam[0].Value;
            int       nFast     = (int)IndParam.NumParam[1].Value;
            int       nSignal   = (int)IndParam.NumParam[2].Value;
            double    dLevel    = IndParam.NumParam[3].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = nSlow + nFast + 2;

            double[] adMASlow = MovingAverage(nSlow, 0, maMethod, Price(basePrice));
            double[] adMAFast = MovingAverage(nFast, 0, maMethod, Price(basePrice));

            double[] adMACD = new double[Bars];

            for (int iBar = nSlow - 1; iBar < Bars; iBar++)
                adMACD[iBar] = adMAFast[iBar] - adMASlow[iBar];

            double[] maSignalLine = MovingAverage(nSignal, 0, slMethod, adMACD);

            // adHistogram reprezents the MACD oscillator
            double[] adHistogram = new double[Bars];
            for (int iBar = nSlow + nSignal - 1; iBar < Bars; iBar++)
                adHistogram[iBar] = adMACD[iBar] - maSignalLine[iBar];

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "OsMA";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Histogram;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adHistogram;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The OsMA rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The OsMA falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The OsMA is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, - dLevel };
                    break;

                case "The OsMA is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, - dLevel };
                    break;

                case "The OsMA crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, - dLevel };
                    break;

                case "The OsMA crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, - dLevel };
                    break;

                case "The OsMA changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The OsMA changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adHistogram, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int iK     = (int)IndParam.NumParam[0].Value;
            int iDFast = (int)IndParam.NumParam[1].Value;
            int iDSlow = (int)IndParam.NumParam[2].Value;
            int iLevel = (int)IndParam.NumParam[3].Value;
            int iPrvs  = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iK + iDFast + iDSlow + 3;

            double[] adHighs = new double[Bars];
            double[] adLows  = new double[Bars];
            for (int iBar = 0; iBar < iK; iBar++)
            {
                double dMin = double.MaxValue;
                double dMax = double.MinValue;
                for (int i = 0; i < iBar; i++)
                {
                    if (High[iBar - i] > dMax) dMax = High[iBar - i];
                    if (Low[iBar  - i] < dMin) dMin = Low[iBar  - i];
                }
                adHighs[iBar] = dMax;
                adLows[iBar]  = dMin;
            }
            adHighs[0] = High[0];
            adLows[0]  = Low[0];

            for (int iBar = iK; iBar < Bars; iBar++)
            {
                double dMin = double.MaxValue;
                double dMax = double.MinValue;
                for (int i = 0; i < iK; i++)
                {
                    if (High[iBar - i] > dMax) dMax = High[iBar - i];
                    if (Low[iBar  - i] < dMin) dMin = Low[iBar  - i];
                }
                adHighs[iBar] = dMax;
                adLows[iBar]  = dMin;
            }

            double[] adK = new double[Bars];
            for (int iBar = iK; iBar < Bars; iBar++)
            {
                if (adHighs[iBar] == adLows[iBar])
                    adK[iBar] = 50;
                else
                    adK[iBar] = 100 * (Close[iBar] - adLows[iBar]) / (adHighs[iBar] - adLows[iBar]);
            }

            double[] adDFast = new double[Bars];
            for (int iBar = iDFast; iBar < Bars; iBar++)
            {
                double dSumHigh = 0;
                double dSumLow  = 0;
                for (int i = 0; i < iDFast; i++)
                {
                    dSumLow  += Close[iBar - i]   - adLows[iBar - i];
                    dSumHigh += adHighs[iBar - i] - adLows[iBar - i];
                }
                if (dSumHigh == 0)
                    adDFast[iBar] = 100;
                else
                    adDFast[iBar] = 100 * dSumLow / dSumHigh;
            }

            double[] adDSlow = MovingAverage(iDSlow, 0, maMethod, adDFast);

            // Saving the components
            Component = new IndicatorComp[5];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "%K";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Brown;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adK;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Fast %D";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Gold;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adDFast;

            Component[2] = new IndicatorComp();
            Component[2].CompName   = "Slow %D";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Line;
            Component[2].ChartColor = Color.Blue;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = adDSlow;

            Component[3] = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            Component[4] = new IndicatorComp();
            Component[4].ChartType = IndChartType.NoChart;
            Component[4].FirstBar  = iFirstBar;
            Component[4].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[3].DataType = IndComponentType.AllowOpenLong;
                Component[3].CompName = "Is long entry allowed";
                Component[4].DataType = IndComponentType.AllowOpenShort;
                Component[4].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[3].DataType = IndComponentType.ForceCloseLong;
                Component[3].CompName = "Close out long position";
                Component[4].DataType = IndComponentType.ForceCloseShort;
                Component[4].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            if (IndParam.ListParam[0].Text == "The %K crosses the Slow %D upward")
            {
                SpecialValues = new double[1] { 50 };
                IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs,adK, adDSlow, ref Component[3], ref Component[4]);
                return;
            }
            else if (IndParam.ListParam[0].Text == "The %K crosses the Slow %D downward")
            {
                SpecialValues = new double[1] { 50 };
                IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adK, adDSlow, ref Component[3], ref Component[4]);
                return;
            }
            else if (IndParam.ListParam[0].Text == "The %K is higher than the Slow %D")
            {
                SpecialValues = new double[1] { 50 };
                IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adK, adDSlow, ref Component[3], ref Component[4]);
                return;
            }
            else if (IndParam.ListParam[0].Text == "The %K is lower than the Slow %D")
            {
                SpecialValues = new double[1] { 50 };
                IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar, iPrvs, adK, adDSlow, ref Component[3], ref Component[4]);
                return;
            }
            else
            {
                switch (IndParam.ListParam[0].Text)
                {
                    case "The Slow %D rises":
                        indLogic = IndicatorLogic.The_indicator_rises;
                        SpecialValues = new double[1] { 50 };
                        break;

                    case "The Slow %D falls":
                        indLogic = IndicatorLogic.The_indicator_falls;
                        SpecialValues = new double[1] { 50 };
                        break;

                    case "The Slow %D is higher than the Level line":
                        indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                        SpecialValues = new double[2] { iLevel, 100 - iLevel };
                        break;

                    case "The Slow %D is lower than the Level line":
                        indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                        SpecialValues = new double[2] { iLevel, 100 - iLevel };
                        break;

                    case "The Slow %D crosses the Level line upward":
                        indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                        SpecialValues = new double[2] { iLevel, 100 - iLevel };
                        break;

                    case "The Slow %D crosses the Level line downward":
                        indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                        SpecialValues = new double[2] { iLevel, 100 - iLevel };
                        break;

                    case "The Slow %D changes its direction upward":
                        indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                        SpecialValues = new double[1] { 50 };
                        break;

                    case "The Slow %D changes its direction downward":
                        indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                        SpecialValues = new double[1] { 50 };
                        break;

                    default:
                        break;
                }

                OscillatorLogic(iFirstBar, iPrvs, adDSlow, iLevel, 100 - iLevel, ref Component[3], ref Component[4], indLogic);
            }

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice = (BasePrice)IndParam.ListParam[1].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            double    dLevel    = IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int      iFirstBar   = iPeriod + 2;
            double[] adBasePrice = Price(basePrice);
            double[] adUp        = new double[Bars];
            double[] adDown      = new double[Bars];
            double[] adAroon     = new double[Bars];

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                double dHighestHigh = double.MinValue;
                double dLowestLow   = double.MaxValue;
                for (int i = 0; i < iPeriod; i++)
                {
                    int iBaseBar = iBar - iPeriod + 1 + i;
                    if (adBasePrice[iBaseBar] > dHighestHigh)
                    {
                        dHighestHigh = adBasePrice[iBaseBar];
                        adUp[iBar] = 100.0 * i / (iPeriod - 1);
                    }
                    if (adBasePrice[iBaseBar] < dLowestLow)
                    {
                        dLowestLow = adBasePrice[iBaseBar];
                        adDown[iBar] = 100.0 * i / (iPeriod - 1);
                    }
                }
            }

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adAroon[iBar] = adUp[iBar] - adDown[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[5];

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Aroon Histogram";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adAroon;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Aroon Up";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Green;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adUp;

            Component[2] = new IndicatorComp();
            Component[2].CompName   = "Aroon Down";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Line;
            Component[2].ChartColor = Color.Red;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = adDown;

            Component[3] = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            Component[4] = new IndicatorComp();
            Component[4].ChartType = IndChartType.NoChart;
            Component[4].FirstBar  = iFirstBar;
            Component[4].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[3].DataType = IndComponentType.AllowOpenLong;
                Component[3].CompName = "Is long entry allowed";
                Component[4].DataType = IndComponentType.AllowOpenShort;
                Component[4].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[3].DataType = IndComponentType.ForceCloseLong;
                Component[3].CompName = "Close out long position";
                Component[4].DataType = IndComponentType.ForceCloseShort;
                Component[4].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Aroon Histogram rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The Aroon Histogram falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The Aroon Histogram is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Aroon Histogram is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Aroon Histogram crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Aroon Histogram crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Aroon Histogram changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The Aroon Histogram changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    SpecialValues = new double[1] { 0 };
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adAroon, dLevel, -dLevel, ref Component[3], ref Component[4], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iPeriod = (int)IndParam.NumParam[0].Value;
            int iShift  = (int)IndParam.NumParam[1].Value;
            int iPrvs   = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            double[] adUpBand = new double[Bars];
            double[] adDnBand = new double[Bars];

            int iFirstBar = iPeriod + iShift + iPrvs + 2;

            for (int iBar = iFirstBar; iBar < Bars - iShift; iBar++)
            {
                double dMax = double.MinValue;
                double dMin = double.MaxValue;
                for (int i = 0; i < iPeriod; i++)
                {
                    if (High[iBar - i] > dMax)
                    {
                        dMax = High[iBar - i];
                    }
                    if (Low[iBar - i] < dMin)
                    {
                        dMin = Low[iBar - i];
                    }
                }
                adUpBand[iBar + iShift] = dMax;
                adDnBand[iBar + iShift] = dMin;
            }

            // Saving the components
            Component = new IndicatorComp[4];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Upper Band";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adUpBand;

            Component[1]            = new IndicatorComp();
            Component[1].CompName   = "Lower Band";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Blue;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adDnBand;

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            Component[3]           = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            // Sets the Component's type.
            if (slotType == SlotTypes.Open)
            {
                Component[2].DataType = IndComponentType.OpenLongPrice;
                Component[2].CompName = "Long position entry price";
                Component[3].DataType = IndComponentType.OpenShortPrice;
                Component[3].CompName = "Short position entry price";
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[2].CompName = "Is long entry allowed";
                Component[3].DataType = IndComponentType.AllowOpenShort;
                Component[3].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[2].DataType = IndComponentType.CloseLongPrice;
                Component[2].CompName = "Long position closing price";
                Component[3].DataType = IndComponentType.CloseShortPrice;
                Component[3].CompName = "Short position closing price";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[2].CompName = "Close out long position";
                Component[3].DataType = IndComponentType.ForceCloseShort;
                Component[3].CompName = "Close out short position";
            }

            if (slotType == SlotTypes.Open || slotType == SlotTypes.Close)
            {
                if (iPeriod > 1)
                {
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {                              // Covers the cases when the price can pass through the band without a signal.
                        double dOpen = Open[iBar]; // Current open price

                        // Upper band
                        double dValueUp   = adUpBand[iBar - iPrvs];     // Current value
                        double dValueUp1  = adUpBand[iBar - iPrvs - 1]; // Previous value
                        double dTempValUp = dValueUp;

                        if ((dValueUp1 > High[iBar - 1] && dValueUp < dOpen) || // The Open price jumps above the indicator
                            (dValueUp1 <Low[iBar - 1] && dValueUp> dOpen) ||    // The Open price jumps below the indicator
                            (Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Open price is in a positive gap
                            (Close[iBar - 1] > dValueUp && dValueUp > dOpen))   // The Open price is in a negative gap
                        {
                            dTempValUp = dOpen;                                 // The entry/exit level is moved to Open price
                        }
                        // Lower band
                        double dValueDown   = adDnBand[iBar - iPrvs];     // Current value
                        double dValueDown1  = adDnBand[iBar - iPrvs - 1]; // Previous value
                        double dTempValDown = dValueDown;

                        if ((dValueDown1 > High[iBar - 1] && dValueDown < dOpen) || // The Open price jumps above the indicator
                            (dValueDown1 <Low[iBar - 1] && dValueDown> dOpen) ||    // The Open price jumps below the indicator
                            (Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Open price is in a positive gap
                            (Close[iBar - 1] > dValueDown && dValueDown > dOpen))   // The Open price is in a negative gap
                        {
                            dTempValDown = dOpen;                                   // The entry/exit level is moved to Open price
                        }
                        if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
                            IndParam.ListParam[0].Text == "Exit long at the Upper Band")
                        {
                            Component[2].Value[iBar] = dTempValUp;
                            Component[3].Value[iBar] = dTempValDown;
                        }
                        else
                        {
                            Component[2].Value[iBar] = dTempValDown;
                            Component[3].Value[iBar] = dTempValUp;
                        }
                    }
                }
                else
                {
                    for (int iBar = 2; iBar < Bars; iBar++)
                    {
                        if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
                            IndParam.ListParam[0].Text == "Exit long at the Upper Band")
                        {
                            Component[2].Value[iBar] = adUpBand[iBar - iPrvs];
                            Component[3].Value[iBar] = adDnBand[iBar - iPrvs];
                        }
                        else
                        {
                            Component[2].Value[iBar] = adDnBand[iBar - iPrvs];
                            Component[3].Value[iBar] = adUpBand[iBar - iPrvs];
                        }
                    }
                }
            }
            else
            {
                switch (IndParam.ListParam[0].Text)
                {
                case "The bar opens below the Upper Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band);
                    break;

                case "The bar opens above the Upper Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band);
                    break;

                case "The bar opens below the Lower Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band);
                    break;

                case "The bar opens above the Lower Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band);
                    break;

                case "The bar opens below the Upper Band after opening above it":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it);
                    break;

                case "The bar opens above the Upper Band after opening below it":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it);
                    break;

                case "The bar opens below the Lower Band after opening above it":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it);
                    break;

                case "The bar opens above the Lower Band after opening below it":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it);
                    break;

                case "The position opens above the Upper Band":
                    Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                    Component[1].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                    Component[0].UsePreviousBar     = iPrvs;
                    Component[1].UsePreviousBar     = iPrvs;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[3].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    Component[3].ShowInDynInfo      = false;
                    break;

                case "The position opens below the Upper Band":
                    Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
                    Component[1].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
                    Component[0].UsePreviousBar     = iPrvs;
                    Component[1].UsePreviousBar     = iPrvs;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[3].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    Component[3].ShowInDynInfo      = false;
                    break;

                case "The position opens above the Lower Band":
                    Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                    Component[1].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                    Component[0].UsePreviousBar     = iPrvs;
                    Component[1].UsePreviousBar     = iPrvs;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[3].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    Component[3].ShowInDynInfo      = false;
                    break;

                case "The position opens below the Lower Band":
                    Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
                    Component[1].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
                    Component[0].UsePreviousBar     = iPrvs;
                    Component[1].UsePreviousBar     = iPrvs;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[3].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    Component[3].ShowInDynInfo      = false;
                    break;

                case "The bar closes below the Upper Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band);
                    break;

                case "The bar closes above the Upper Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band);
                    break;

                case "The bar closes below the Lower Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band);
                    break;

                case "The bar closes above the Lower Band":
                    BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band);
                    break;

                default:
                    break;
                }
            }

            return;
        }
Пример #37
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod1  = (int)IndParam.NumParam[0].Value;
            int       iPeriod2  = (int)IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod1 + iPeriod2 + 2;

            double[] adIndicator1 = new double[Bars];
            double[] adIndicator2 = new double[Bars];
            double[] adOscllator  = new double[Bars];

// ---------------------------------------------------------
            RSI rsi1 = new RSI(slotType);

            rsi1.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            rsi1.IndParam.ListParam[2].Index    = IndParam.ListParam[2].Index;
            rsi1.IndParam.NumParam[0].Value     = IndParam.NumParam[0].Value;
            rsi1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            rsi1.Calculate(slotType);

            RSI rsi2 = new RSI(slotType);

            rsi2.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            rsi2.IndParam.ListParam[2].Index    = IndParam.ListParam[2].Index;
            rsi2.IndParam.NumParam[0].Value     = IndParam.NumParam[1].Value;
            rsi2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            rsi2.Calculate(slotType);

            adIndicator1 = rsi1.Component[0].Value;
            adIndicator2 = rsi2.Component[0].Value;
// ----------------------------------------------------------

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Oscillator";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adOscllator;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The Oscillator rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

            case "The Oscillator falls":
                indLogic = IndicatorLogic.The_indicator_falls;
                break;

            case "The Oscillator is higher than the zero line":
                indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                break;

            case "The Oscillator is lower than the zero line":
                indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                break;

            case "The Oscillator crosses the zero line upward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                break;

            case "The Oscillator crosses the zero line downward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                break;

            case "The Oscillator changes its direction upward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                break;

            case "The Oscillator changes its direction downward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Returns a copy.
        /// </summary>
        public IndicatorComp Clone()
        {
            var indicatorComp = new IndicatorComp
                                    {
                                        CompName = CompName,
                                        DataType = DataType,
                                        ChartType = ChartType,
                                        ChartColor = ChartColor,
                                        FirstBar = FirstBar,
                                        UsePreviousBar = UsePreviousBar,
                                        ShowInDynInfo = ShowInDynInfo,
                                        PosPriceDependence = PosPriceDependence
                                    };

            if (Value != null)
            {
                indicatorComp.Value = new double[Value.Length];
                Value.CopyTo(indicatorComp.Value, 0);
            }

            return indicatorComp;
        }
Пример #39
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int      iPeriod  = (int)IndParam.NumParam[0].Value;
            double   dLevel   = IndParam.NumParam[1].Value;
            int      iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int      iFirstBar  = iPeriod + 2;
            double[] adDeMax    = new double[Bars];
            double[] adDeMin    = new double[Bars];
            double[] adDeMarker = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adDeMax[iBar] = High[iBar] > High[iBar - 1] ? High[iBar] - High[iBar - 1] : 0;
                adDeMin[iBar] = Low[iBar]  < Low[iBar - 1]  ? Low[iBar - 1]  - Low[iBar]  : 0;
            }

            double[] adDeMaxMA = MovingAverage(iPeriod, 0, maMethod, adDeMax);
            double[] adDeMinMA = MovingAverage(iPeriod, 0, maMethod, adDeMin);

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (adDeMaxMA[iBar] + adDeMinMA[iBar] == 0)
                    adDeMarker[iBar] = 0;
                else
                    adDeMarker[iBar] = adDeMaxMA[iBar] / (adDeMaxMA[iBar] + adDeMinMA[iBar]);
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "DeMarker";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.RoyalBlue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adDeMarker;

            Component[1]            = new IndicatorComp();
            Component[1].ChartType  = IndChartType.NoChart;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = new double[Bars];

            Component[2]            = new IndicatorComp();
            Component[2].ChartType  = IndChartType.NoChart;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The DeMarker rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    SpecialValues = new double[1] { 0.5 };
                    break;

                case "The DeMarker falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    SpecialValues = new double[1] { 0.5 };
                    break;

                case "The DeMarker is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, 1 - dLevel };
                    break;

                case "The DeMarker is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, 1 - dLevel };
                    break;

                case "The DeMarker crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, 1 - dLevel };
                    break;

                case "The DeMarker crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, 1 - dLevel };
                    break;

                case "The DeMarker changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    SpecialValues = new double[1] { 0.5 };
                    break;

                case "The DeMarker changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    SpecialValues = new double[1] { 0.5 };
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adDeMarker, dLevel, 1 - dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            MACD MACD1 = new MACD(slotType);
            MACD1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            MACD1.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index;
            MACD1.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index;
            MACD1.IndParam.NumParam[0].Value  = IndParam.NumParam[0].Value;
            MACD1.IndParam.NumParam[1].Value  = IndParam.NumParam[2].Value;
            MACD1.IndParam.NumParam[2].Value  = IndParam.NumParam[4].Value;
            MACD1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            MACD1.Calculate(slotType);

            MACD MACD2 = new MACD(slotType);
            MACD2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            MACD2.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index;
            MACD2.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index;
            MACD2.IndParam.NumParam[0].Value  = IndParam.NumParam[1].Value;
            MACD2.IndParam.NumParam[1].Value  = IndParam.NumParam[3].Value;
            MACD2.IndParam.NumParam[2].Value  = IndParam.NumParam[5].Value;
            MACD2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            MACD2.Calculate(slotType);

            // Calculation
            int iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;
            int iPeriod1 = (int)IndParam.NumParam[0].Value;
            int iPeriod2 = (int)IndParam.NumParam[1].Value;
            int iFirstBar = iPeriod1 + iPeriod2 + 2;
            double[] adIndicator1 = new double[Bars];
            double[] adIndicator2 = new double[Bars];

            if (IndParam.ListParam[4].Index == 0)
            {
                adIndicator1 = MACD1.Component[0].Value;
                adIndicator2 = MACD2.Component[0].Value;
            }
            else if (IndParam.ListParam[4].Index == 1)
            {
                adIndicator1 = MACD1.Component[1].Value;
                adIndicator2 = MACD2.Component[1].Value;
            }
            else
            {
                adIndicator1 = MACD1.Component[2].Value;
                adIndicator2 = MACD2.Component[2].Value;
            }

            double[] adOscllator  = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
                adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar];

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Oscillator";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adOscllator;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Oscillator of MACD rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The Oscillator of MACD falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The Oscillator of MACD is higher than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    break;

                case "The Oscillator of MACD is lower than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    break;

                case "The Oscillator of MACD crosses the zero line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    break;

                case "The Oscillator of MACD crosses the zero line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    break;

                case "The Oscillator of MACD changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The Oscillator of MACD changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int period = (int)IndParam.NumParam[0].Value;
            double level = Point * IndParam.NumParam[1].Value;
            int prev = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar = period + 2;

            double[] ATR = new double[Bars];

            for (int bar = 1; bar < Bars; bar++)
                ATR[bar] = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);

            ATR = MovingAverage(period, 0, maMethod, ATR);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Average True Range";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = firstBar;
            Component[0].Value      = ATR;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = firstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = firstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The ATR rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The ATR falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The ATR is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ATR is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ATR crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ATR crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[1] { level };
                    break;

                case "The ATR changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The ATR changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            // ATR rises equal signals in both directions!
            NoDirectionOscillatorLogic(firstBar, prev, ATR, level, ref Component[1], indLogic);
            Component[2].Value = Component[1].Value;

            return;
        }
Пример #42
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            double    dLevel    = IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int      iFirstBar   = iPeriod + 2;
            double[] adBasePrice = Price(basePrice);
            double[] adPos       = new double[Bars];
            double[] adNeg       = new double[Bars];
            double[] adRSI       = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                if (adBasePrice[iBar] > adBasePrice[iBar - 1]) adPos[iBar] = adBasePrice[iBar] - adBasePrice[iBar - 1];
                if (adBasePrice[iBar] < adBasePrice[iBar - 1]) adNeg[iBar] = adBasePrice[iBar - 1] - adBasePrice[iBar];
            }

            double[] adPosMA = MovingAverage(iPeriod, 0, maMethod, adPos);
            double[] adNegMA = MovingAverage(iPeriod, 0, maMethod, adNeg);

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (adNegMA[iBar] == 0)
                    adRSI[iBar] = 100;
                else
                    adRSI[iBar] = 100 - (100 / (1 + adPosMA[iBar] / adNegMA[iBar]));
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "RSI";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.RoyalBlue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adRSI;

            Component[1] = new IndicatorComp();
            Component[1].ChartType  = IndChartType.NoChart;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType  = IndChartType.NoChart;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The RSI rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    SpecialValues = new double[1] { 50 };
                    break;

                case "The RSI falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    SpecialValues = new double[1] { 50 };
                    break;

                case "The RSI is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The RSI is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The RSI crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The RSI crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, 100 - dLevel };
                    break;

                case "The RSI changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    SpecialValues = new double[1] { 50 };
                    break;

                case "The RSI changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    SpecialValues = new double[1] { 50 };
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adRSI, dLevel, 100 - dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #43
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       nSlow     = (int)IndParam.NumParam[0].Value;
            int       nFast     = (int)IndParam.NumParam[1].Value;
            double    dLevel    = IndParam.NumParam[3].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = nSlow + 2;

            double[] adMASlow = MovingAverage(nSlow, 0, maMethod, Price(basePrice));
            double[] adMAFast = MovingAverage(nFast, 0, maMethod, Price(basePrice));
            double[] adAO     = new double[Bars];

            for (int iBar = nSlow - 1; iBar < Bars; iBar++)
            {
                adAO[iBar] = adMAFast[iBar] - adMASlow[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "AO";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adAO;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indicatorLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The AO rises":
                indicatorLogic = IndicatorLogic.The_indicator_rises;
                SpecialValues  = new double[1] {
                    0
                };
                break;

            case "The AO falls":
                indicatorLogic = IndicatorLogic.The_indicator_falls;
                SpecialValues  = new double[1] {
                    0
                };
                break;

            case "The AO is higher than the Level line":
                indicatorLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                SpecialValues  = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The AO is lower than the Level line":
                indicatorLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                SpecialValues  = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The AO crosses the Level line upward":
                indicatorLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                SpecialValues  = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The AO crosses the Level line downward":
                indicatorLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                SpecialValues  = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The AO changes its direction upward":
                indicatorLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                SpecialValues  = new double[1] {
                    0
                };
                break;

            case "The AO changes its direction downward":
                indicatorLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                SpecialValues  = new double[1] {
                    0
                };
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adAO, dLevel, -dLevel, ref Component[1], ref Component[2], indicatorLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int      iPeriod  = (int)IndParam.NumParam[0].Value;
            int      iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + 2;

            double[] adBOP = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                if (High[iBar] - Low[iBar] > Point)
                    adBOP[iBar] = (Close[iBar] - Open[iBar]) / (High[iBar] - Low[iBar]);
                else
                    adBOP[iBar] = 0;
            }

            adBOP = MovingAverage(iPeriod, 0, maMethod, adBOP);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Balance of Power";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adBOP;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Balance of Power rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The Balance of Power falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The Balance of Power is higher than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    break;

                case "The Balance of Power is lower than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    break;

                case "The Balance of Power crosses the zero line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    break;

                case "The Balance of Power crosses the zero line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    break;

                case "The Balance of Power changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The Balance of Power changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adBOP, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #45
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice    = (BasePrice)IndParam.ListParam[1].Index;
            MAMethod  fastMAMethod = (MAMethod )IndParam.ListParam[3].Index;
            MAMethod  slowMAMethod = (MAMethod )IndParam.ListParam[4].Index;
            int       iNFastMA     = (int)IndParam.NumParam[0].Value;
            int       iNSlowMA     = (int)IndParam.NumParam[1].Value;
            int       iSFastMA     = (int)IndParam.NumParam[2].Value;
            int       iSSlowMA     = (int)IndParam.NumParam[3].Value;
            int       iPrvs        = IndParam.CheckParam[0].Checked ? 1 : 0;

            string[] saColors   = new string[] { "Blue", "Black", "Red", "Green", "Yellow", "Orange" };
            string   sFastColor = saColors[(int)IndParam.NumParam[4].Value];
            string   sSlowColor = saColors[(int)IndParam.NumParam[5].Value];

            // Convert to Higher Time Frame ---------------------------------------------
            DataPeriods htfPeriod = DataPeriods.week;

            double[] hfOpen   = new double[Bars];
            double[] hfClose  = new double[Bars];
            double[] hfHigh   = new double[Bars];
            double[] hfLow    = new double[Bars];
            double[] hfVolume = new double[Bars];
            double[] hfPrice  = new double[Bars];
            int[]    hIndex   = new int[Bars];
            int      iFrame;
            int      hBars;


            switch (IndParam.ListParam[2].Index)
            {
            case 1: htfPeriod = DataPeriods.min5; break;

            case 2: htfPeriod = DataPeriods.min15; break;

            case 3: htfPeriod = DataPeriods.min30; break;

            case 4: htfPeriod = DataPeriods.hour1; break;

            case 5: htfPeriod = DataPeriods.hour4; break;

            case 6: htfPeriod = DataPeriods.day; break;

            case 7: htfPeriod = DataPeriods.week; break;
            }
            int err1 = HigherTimeFrame(Period, htfPeriod, out hIndex, out hBars, out iFrame, out hfHigh, out hfLow, out hfOpen, out hfClose, out hfVolume);
            int err2 = HigherBasePrice(basePrice, hBars, hfHigh, hfLow, hfOpen, hfClose, out hfPrice);

            if (err1 == 1)
            {
                return;
            }
            //-----------------------------------------------------------------------

            // Calculation

            int iFirstBar = (int)Math.Max(iNFastMA + iSFastMA, iNSlowMA + iSSlowMA) + 2;

            double[] adMAFast       = MovingAverage(iNFastMA, iSFastMA, fastMAMethod, hfPrice);
            double[] adMASlow       = MovingAverage(iNSlowMA, iSSlowMA, slowMAMethod, hfPrice);
            double[] adMAOscillator = new double[Bars];

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adMAOscillator[iBar] = adMAFast[iBar] - adMASlow[iBar];
            }

            // Convert to Current Time Frame ----------------------------------------------
/// start WTF modfication 2 version 4
            // do in 3 blocks for adMAFast, adMASlow, to draw on chart, and adMAOscillator for signals
            // copy of wider time frame array of values
            double[] hadMAFast = new double[Bars];
            adMAFast.CopyTo(hadMAFast, 0);
            int err3 = CurrentTimeFrame(hIndex, hBars, ref adMAFast);

            // if any error, return out of calculation and indicator fails silently
            if (err3 == 1)
            {
                return;
            }
            // copy of wider time frame array of values
            double[] hadMASlow = new double[Bars];
            adMASlow.CopyTo(hadMASlow, 0);
            err3 = CurrentTimeFrame(hIndex, hBars, ref adMASlow);
            // if any error, return out of calculation and indicator fails silently
            if (err3 == 1)
            {
                return;
            }
            // copy of wider time frame array of values
            double[] hadMAOscillator = new double[Bars];
            adMAOscillator.CopyTo(hadMAOscillator, 0);
            err3 = CurrentTimeFrame(hIndex, hBars, ref adMAOscillator);
            // if any error, return out of calculation and indicator fails silently
            if (err3 == 1)
            {
                return;
            }
/// end WTF modfication 2 version 4
            //-----------------------------------------------------------------------------


            // Saving the components
            Component = new IndicatorComp[4];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Fast Moving Average";
            Component[0].ChartColor = Color.FromName(sFastColor);
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMAFast;

            Component[1]            = new IndicatorComp();
            Component[1].CompName   = "Slow Moving Average";
            Component[1].ChartColor = Color.FromName(sSlowColor);
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adMASlow;

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            Component[3]           = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[2].CompName = "Is long entry allowed";
                Component[3].DataType = IndComponentType.AllowOpenShort;
                Component[3].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[2].CompName = "Close out long position";
                Component[3].DataType = IndComponentType.ForceCloseShort;
                Component[3].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The Fast MA crosses the Slow MA upward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                break;

            case "The Fast MA crosses the Slow MA downward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                break;

            case "The Fast MA is higher than the Slow MA":
                indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                break;

            case "The Fast MA is lower than the Slow MA":
                indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                break;

            case "Draw only, no entry or exit signals":
                Component[2].CompName = "Visual Only";
                Component[2].DataType = IndComponentType.NotDefined;
                Component[3].CompName = "Visual Only";
                Component[3].DataType = IndComponentType.NotDefined;
                break;

            default:
                break;
            }

/// start WTF modfication 3 version 4

            // back up Bars value, reset to hBars, for performance improvement in indicator logic function
            int mtfBars = Data.Bars;

            Data.Bars = hBars;

            // replace very small values with 0 for performance improvement; don't know why but works
            for (int ctr = 0; ctr < hadMAOscillator.Length; ctr++)
            {
                hadMAOscillator[ctr] = (hadMAOscillator[ctr] < .000000001 && hadMAOscillator[ctr] > -.000000001) ? 0 : hadMAOscillator[ctr];
            }

            OscillatorLogic(iFirstBar, iPrvs, hadMAOscillator, 0, 0, ref Component[2], ref Component[3], indLogic);

            // resest Bars to real value
            Data.Bars = mtfBars;

            // expand component array from wtf to current time frame
            double[] wtfCompValue = Component[2].Value;
            int      err4         = CurrentTimeFrame(hIndex, hBars, ref wtfCompValue);

            if (err4 == 1)
            {
                return;
            }
            Component[2].Value = wtfCompValue;
            wtfCompValue       = Component[3].Value;
            int err5 = CurrentTimeFrame(hIndex, hBars, ref wtfCompValue);

            if (err5 == 1)
            {
                return;
            }
            Component[3].Value = wtfCompValue;

/// end WTF modfication 3 version 4

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            double dAFMin = IndParam.NumParam[0].Value;
            double dAFInc = IndParam.NumParam[1].Value;
            double dAFMax = IndParam.NumParam[2].Value;

            // Reading the parameters
            int intDirNew;
            double dAF;
            double dPExtr;
            double dPSARNew = 0;
            int[]    aiDir  = new int[Bars];
            double[] adPSAR = new double[Bars];

            //----	Calculating the initial values
            adPSAR[0] = 0;
            dAF       = dAFMin;
            intDirNew = 0;
            if (Close[1] > Open[0])
            {
                aiDir[0]  = 1;
                aiDir[1]  = 1;
                dPExtr    = Math.Max(High[0], High[1]);
                adPSAR[1] = Math.Min(Low[0],  Low[1]);
            }
            else
            {
                aiDir[0]  = -1;
                aiDir[1]  = -1;
                dPExtr    = Math.Min(Low[0],  Low[1]);
                adPSAR[1] = Math.Max(High[0], High[1]);
            }

            for (int iBar = 2; iBar < Bars; iBar++)
            {
                //----	PSAR for the current period
                if (intDirNew != 0)
                {
                    // The direction was changed during the last period
                    aiDir[iBar]  = intDirNew;
                    intDirNew    = 0;
                    adPSAR[iBar] = dPSARNew + dAF * (dPExtr - dPSARNew);
                }
                else
                {
                    aiDir[iBar]  = aiDir[iBar - 1];
                    adPSAR[iBar] = adPSAR[iBar - 1] + dAF * (dPExtr - adPSAR[iBar - 1]);
                }

                // PSAR has to be out of the previous two bars limits
                if (aiDir[iBar] > 0 && adPSAR[iBar] > Math.Min(Low[iBar - 1], Low[iBar - 2]))
                    adPSAR[iBar] = Math.Min(Low[iBar - 1], Low[iBar - 2]);
                else if (aiDir[iBar] < 0 && adPSAR[iBar] < Math.Max(High[iBar - 1], High[iBar - 2]))
                    adPSAR[iBar] = Math.Max(High[iBar - 1], High[iBar - 2]);

                //----	PSAR for the next period

                // Calculation of the new values of flPExtr and flAF
                // if there is a new extreme price in the PSAR direction
                if (aiDir[iBar] > 0 && High[iBar] > dPExtr)
                {
                    dPExtr = High[iBar];
                    dAF    = Math.Min(dAF + dAFInc, dAFMax);
                }

                if (aiDir[iBar] < 0 && Low[iBar] < dPExtr)
                {
                    dPExtr = Low[iBar];
                    dAF    = Math.Min(dAF + dAFInc, dAFMax);
                }

                // Whether the price reaches PSAR
                if (Low[iBar] <= adPSAR[iBar] && adPSAR[iBar] <= High[iBar])
                {
                    intDirNew = -aiDir[iBar];
                    dPSARNew  = dPExtr;
                    dAF       = dAFMin;
                    if (intDirNew > 0)
                        dPExtr = High[iBar];
                    else
                        dPExtr = Low[iBar];
                }

            }
            int iFirstBar = 8;

            // Saving the components
            Component = new IndicatorComp[1];

            Component[0] = new IndicatorComp();
            Component[0].CompName = "PSAR value";
            if (slotType == SlotTypes.Close)
                Component[0].DataType = IndComponentType.ClosePrice;
            else
                Component[0].DataType = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Dot;
            Component[0].ChartColor = Color.Violet;
            Component[0].FirstBar   = iFirstBar;
            Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower;
            Component[0].Value      = adPSAR;

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod   maMethod = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int iPeriod = (int)IndParam.NumParam[0].Value;
            int iSmooth = (int)IndParam.NumParam[1].Value;
            int iPrvs   = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + 2;

            double[] adBasePrice = Price(basePrice);
            double[] adCumulSum  = new double[Bars];

            adCumulSum[iPeriod - 1] = 0;

            for (int iBar = 0; iBar < iPeriod; iBar++)
            {
                adCumulSum[iPeriod - 1] += adBasePrice[iBar];
            }

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                adCumulSum[iBar] = adCumulSum[iBar - 1] - adBasePrice[iBar - iPeriod] + adBasePrice[iBar];
            }

            adCumulSum = MovingAverage(iSmooth, 0, maMethod, adCumulSum);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Cumulative Sum";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adCumulSum;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Cumulative Sum rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The Cumulative Sum falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The Cumulative Sum changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The Cumulative Sum changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adCumulSum, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #48
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            int       iShift    = (int)IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Convert to Higher Time Frame ---------------------------------------------
            DataPeriods htfPeriod = DataPeriods.week;

            double[] hfOpen   = new double[Bars];
            double[] hfClose  = new double[Bars];
            double[] hfHigh   = new double[Bars];
            double[] hfLow    = new double[Bars];
            double[] hfVolume = new double[Bars];
            double[] hfPrice  = new double[Bars];
            int[]    hIndex   = new int[Bars];
            int      iFrame;
            int      hBars;

            switch (IndParam.ListParam[4].Index)
            {
            case 0: htfPeriod = DataPeriods.hour1; break;

            case 1: htfPeriod = DataPeriods.min5; break;

            case 2: htfPeriod = DataPeriods.min15; break;

            case 3: htfPeriod = DataPeriods.min30; break;

            case 4: htfPeriod = DataPeriods.hour1; break;

            case 5: htfPeriod = DataPeriods.hour4; break;

            case 6: htfPeriod = DataPeriods.day; break;

            case 7: htfPeriod = DataPeriods.week; break;
            }

            int err1 = HigherTimeFrame(Period, htfPeriod, out hIndex, out hBars, out iFrame, out hfHigh, out hfLow, out hfOpen, out hfClose, out hfVolume);
            int err2 = HigherBasePrice(basePrice, hBars, hfHigh, hfLow, hfOpen, hfClose, out hfPrice);

            //------------------------------------------------------------------------

            // TimeExecution

            if (basePrice == BasePrice.Open && iPeriod == 1 && iShift == 0)
            {
                IndParam.ExecutionTime = ExecutionTime.AtBarOpening;
            }

            // Calculation
            double[] adMA = MovingAverage(iPeriod, iShift, maMethod, hfPrice);

            // v3 -- manually shift so Position entry type logics use previous WTF value, fix bug of not using previous value
            if (IndParam.ListParam[0].Text == "The position opens above the Moving Average" ||
                IndParam.ListParam[0].Text == "The position opens below the Moving Average")
            {
                adMA = MovingAverage(iPeriod, iShift + 1, maMethod, hfPrice);
            }
            else
            {
                adMA = MovingAverage(iPeriod, iShift, maMethod, hfPrice);
            }

            int iFirstBar = iPeriod + iShift + 1 + iPrvs;

            // Convert to Current Time Frame ----------------------------------------------
            iPrvs     = iPrvs * iFrame;
            iFirstBar = iFirstBar * iFrame;

            int err3 = (iFirstBar > 0.25 * Bars) ? 1 : 0;

            int err4 = CurrentTimeFrame(hIndex, hBars, ref adMA);

            // if any WTF conversion errors, return here to fail silently
            if (err1 == 1 || err2 == 1 || err3 == 1 || err4 == 1)
            {
                Component                   = new IndicatorComp[1];
                Component[0]                = new IndicatorComp();
                Component[0].CompName       = "MA Value";
                Component[0].DataType       = IndComponentType.IndicatorValue;
                Component[0].ChartType      = IndChartType.Line;
                Component[0].FirstBar       = (int)Bars / 2;
                Component[0].UsePreviousBar = 0;
                Component[0].Value          = new double[Bars];
                return;
            }
            //-----------------------------------------------------------------------------

            // Saving the components
            if (slotType == SlotTypes.Open || slotType == SlotTypes.Close)
            {
                Component = new IndicatorComp[2];

                Component[1]          = new IndicatorComp();
                Component[1].FirstBar = iFirstBar;
                Component[1].Value    = new double[Bars];

                int hBar = 0;
                for (int iBar = 3 * iFrame; iBar < Bars; iBar++)
                {   // Covers the cases when the price can pass through the MA without a signal
/// start WTF modfication 3 beta 1
                    while (hIndex[hBar] <= iBar && hBar < hBars)
                    {
                        hBar++;
                    }
                    double dValue  = adMA[hIndex[hBar - 2]]; // MA value from previous HTF bar
                    double dValue1 = adMA[hIndex[hBar - 3]]; // MA value from HTF 2 bars previous
/// end WTF modfication 3 beta 1
                    double dTempVal = dValue;
                    if ((dValue1 > High[iBar - 1] && dValue < Low[iBar]) ||  // It jumps below the current bar
                        (dValue1 <Low[iBar - 1] && dValue> High[iBar]) ||    // It jumps above the current bar
                        (Close[iBar - 1] < dValue && dValue < Open[iBar]) || // Positive gap
                        (Close[iBar - 1] > dValue && dValue > Open[iBar]))   // Negative gap
                    {
                        dTempVal = Open[iBar];
                    }
                    Component[1].Value[iBar] = dTempVal;
                }
            }
            else
            {
                Component = new IndicatorComp[3];

                Component[1]           = new IndicatorComp();
                Component[1].ChartType = IndChartType.NoChart;
                Component[1].FirstBar  = iFirstBar;
                Component[1].Value     = new double[Bars];

                Component[2]           = new IndicatorComp();
                Component[2].ChartType = IndChartType.NoChart;
                Component[2].FirstBar  = iFirstBar;
                Component[2].Value     = new double[Bars];
            }

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "MA Value";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.FromName(IndParam.ListParam[3].ItemList[IndParam.ListParam[3].Index]);
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMA;

            if (slotType == SlotTypes.Open)
            {
                Component[1].CompName = "Position opening price";
                Component[1].DataType = IndComponentType.OpenPrice;
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[1].CompName = "Position closing price";
                Component[1].DataType = IndComponentType.ClosePrice;
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
            {
                switch (IndParam.ListParam[0].Text)
                {
                case "The Moving Average rises":
                    IndicatorRisesLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The Moving Average falls":
                    IndicatorFallsLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens above the Moving Average":
                    BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens below the Moving Average":
                    BarOpensBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens above the Moving Average after opening below it":
                    BarOpensAboveIndicatorAfterOpeningBelowLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar opens below the Moving Average after opening above it":
                    BarOpensBelowIndicatorAfterOpeningAboveLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The position opens above the Moving Average":
                    Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower;
                    Component[1].DataType           = IndComponentType.Other;
                    Component[1].ShowInDynInfo      = false;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    break;

                case "The position opens below the Moving Average":
                    Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher;
                    Component[1].DataType           = IndComponentType.Other;
                    Component[1].ShowInDynInfo      = false;
                    Component[2].DataType           = IndComponentType.Other;
                    Component[2].ShowInDynInfo      = false;
                    break;

                case "The bar closes below the Moving Average":
                    BarClosesBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "The bar closes above the Moving Average":
                    BarClosesAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]);
                    break;

                case "Draw only, no entry or exit":
                    Component[1].CompName = "Visual Only";
                    Component[1].DataType = IndComponentType.NotDefined;
                    Component[2].CompName = "Visual Only";
                    Component[2].DataType = IndComponentType.NotDefined;
                    break;

                default:
                    break;
                }
            }

            return;
        }
Пример #49
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       n         = (int)IndParam.NumParam[0].Value;
            double    dLevel    = IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Convert to Higher Time Frame ---------------------------------------------
            DataPeriods htfPeriod = DataPeriods.week;

            double[] hfOpen   = new double[Bars];
            double[] hfClose  = new double[Bars];
            double[] hfHigh   = new double[Bars];
            double[] hfLow    = new double[Bars];
            double[] hfVolume = new double[Bars];
            double[] hfPrice  = new double[Bars];
            int[]    hIndex   = new int[Bars];
            int      iFrame;
            int      hBars;

            switch (IndParam.ListParam[4].Index)
            {
            case 1: htfPeriod = DataPeriods.min5; break;

            case 2: htfPeriod = DataPeriods.min15; break;

            case 3: htfPeriod = DataPeriods.min30; break;

            case 4: htfPeriod = DataPeriods.hour1; break;

            case 5: htfPeriod = DataPeriods.hour4; break;

            case 6: htfPeriod = DataPeriods.day; break;

            case 7: htfPeriod = DataPeriods.week; break;
            }

            int err1 = HigherTimeFrame(Period, htfPeriod, out hIndex, out hBars, out iFrame, out hfHigh, out hfLow, out hfOpen, out hfClose, out hfVolume);
            int err2 = HigherBasePrice(basePrice, hBars, hfHigh, hfLow, hfOpen, hfClose, out hfPrice);

            if (err1 == 1)
            {
                return;
            }

            // Calculation
            int iFirstBar = n + 1;

            double[] adRegr     = new double[Bars];
            double[] adRSquared = new double[Bars];
            double   rsquared;


            for (int period = iFirstBar; period < Bars; period++)
            {
                double x     = 0;
                double xx    = 0;
                double xy    = 0;
                double y     = 0;
                double b     = 0;
                double a     = 0;
                double sumY2 = 0;


                for (int i = 0; i < n; i++)
                {
                    int    ii     = i + 1;
                    double source = hfPrice[period - (n - i)]; // source = xVal
                    x      = x + ii;                           // x = xSum
                    xx     = xx + (ii * ii);                   // xx = sumX2
                    xy     = xy + (ii * source);               // xy = sumXY
                    y      = y + source;                       // y = ySum
                    sumY2 += (source * source);
                }


                // adapting eSignal code from Tech S&C article Dec 2007 p. 74
                // article gets r-squared, matching lines from FXCM code to article's code
                // see Regression .lua or .cs for orignal regression code

                // (nLRlen * sumXY) - (xSum * ySum)
                b = (n * xy) - (x * y);
                double line1 = b;

                // (nLRlen * sumX2 - (xSum*xSum))
                double line2 = n * xx - (x * x);

                if (Math.Abs(line2) < 1e-10)
                {
                    b = 0;
                }
                else
                {
                    b = b / (line2);
                    a = y - (b * x);
                    a = a / n;
                }

                // nLRlen * sumY2 - (ySum * ySum)
                double line3 = n * sumY2 - (y * y);

                rsquared = Math.Pow(line1 / Math.Sqrt(line2 * line3), 2);

                adRSquared[period] = rsquared;
            }

            // Convert to Current Time Frame ----------------------------------------------

/// start WTF modfication 2 version 4
            // copy of wider time frame array of values
            double[] hadRSquared = new double[Bars];
            adRSquared.CopyTo(hadRSquared, 0);

            int err3 = CurrentTimeFrame(hIndex, hBars, ref adRSquared);

            // if any error, return out of calculation and indicator fails silently
            if (err3 == 1)
            {
                return;
            }
/// end WTF modfication 2 version 4

            //-----------------------------------------------------------------------------


            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "R Squared";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adRSquared;


            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The R Squared Line rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

            case "The R Squared Line falls":
                indLogic = IndicatorLogic.The_indicator_falls;
                break;

            case "The R Squared Line is higher than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                SpecialValues = new double[1] {
                    dLevel
                };
                break;

            case "The R Squared Line is lower than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                SpecialValues = new double[1] {
                    dLevel
                };
                break;

            case "The R Squared Line crosses the Level line upward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                SpecialValues = new double[1] {
                    dLevel
                };
                break;

            case "The R Squared Line crosses the Level line downward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                SpecialValues = new double[1] {
                    dLevel
                };
                break;

            case "The R Squared Line changes its direction upward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                break;

            case "The R Squared Line changes its direction downward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                break;


            default:
                break;
            }

/// start WTF modfication 3 version 4

            // back up Bars value, reset to hBars, for performance improvement in indicator logic function
            int mtfBars = Data.Bars;

            Data.Bars = hBars;

            // replace very small values with 0 for performance improvement; don't know why but works
            for (int ctr = 0; ctr < hadRSquared.Length; ctr++)
            {
                hadRSquared[ctr] = (hadRSquared[ctr] < .000000001 && hadRSquared[ctr] > -.000000001) ? 0 : hadRSquared[ctr];
            }

            NoDirectionOscillatorLogic(iFirstBar, iPrvs, hadRSquared, dLevel, ref Component[1], indLogic);

            // resest Bars to real value
            Data.Bars = mtfBars;

            // expand component array from wtf to current time frame
            double[] wtfCompValue = Component[1].Value;
            int      err4         = CurrentTimeFrame(hIndex, hBars, ref wtfCompValue);

            if (err4 == 1)
            {
                return;
            }
            Component[1].Value = Component[2].Value = wtfCompValue;


/// end WTF modfication 3 version 4

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice    = (BasePrice)IndParam.ListParam[1].Index;
            MAMethod  fastMAMethod = (MAMethod )IndParam.ListParam[3].Index;
            MAMethod  slowMAMethod = (MAMethod )IndParam.ListParam[4].Index;
            int       iNFastMA     = (int)IndParam.NumParam[0].Value;
            int       iNSlowMA     = (int)IndParam.NumParam[1].Value;
            int       iSFastMA     = (int)IndParam.NumParam[2].Value;
            int       iSSlowMA     = (int)IndParam.NumParam[3].Value;
            int       iPrvs        = IndParam.CheckParam[0].Checked ? 1 : 0;

            int iFirstBar = (int)Math.Max(iNFastMA + iSFastMA, iNSlowMA + iSSlowMA) + 2;

            double[] adMAFast       = MovingAverage(iNFastMA, iSFastMA, fastMAMethod, Price(basePrice));
            double[] adMASlow       = MovingAverage(iNSlowMA, iSSlowMA, slowMAMethod, Price(basePrice));
            double[] adMAOscillator = new double[Bars];

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adMAOscillator[iBar] = adMAFast[iBar] - adMASlow[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[4];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Fast Moving Average";
            Component[0].ChartColor = Color.Goldenrod;
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMAFast;

            Component[1]            = new IndicatorComp();
            Component[1].CompName   = "Slow Moving Average";
            Component[1].ChartColor = Color.IndianRed;
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adMASlow;

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            Component[3]           = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[2].CompName = "Is long entry allowed";
                Component[3].DataType = IndComponentType.AllowOpenShort;
                Component[3].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[2].CompName = "Close out long position";
                Component[3].DataType = IndComponentType.ForceCloseShort;
                Component[3].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The Fast MA crosses the Slow MA upward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                break;

            case "The Fast MA crosses the Slow MA downward":
                indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                break;

            case "The Fast MA is higher than the Slow MA":
                indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                break;

            case "The Fast MA is lower than the Slow MA":
                indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adMAOscillator, 0, 0, ref Component[2], ref Component[3], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            double[] adOBV  = new double[Bars];

            int iFirstBar = 5;

            adOBV[0] = Volume[0];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                if (Close[iBar] > Close[iBar - 1])
                {
                    adOBV[iBar] = adOBV[iBar - 1] + Volume[iBar];
                }
                else if (Close[iBar] < Close[iBar - 1])
                {
                    adOBV[iBar] = adOBV[iBar - 1] - Volume[iBar];
                }
                else
                {
                    adOBV[iBar] = adOBV[iBar - 1];
                }
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "On Balance Volume";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Green;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adOBV;

            Component[1] = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The On Balance Volume rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "The On Balance Volume falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "The On Balance Volume changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "The On Balance Volume changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adOBV, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #52
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            int       iSmooth   = (int)IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + 2;

            double[] adBasePrice = Price(basePrice);
            double[] adCumulSum  = new double[Bars];

            adCumulSum[iPeriod - 1] = 0;

            for (int iBar = 0; iBar < iPeriod; iBar++)
            {
                adCumulSum[iPeriod - 1] += adBasePrice[iBar];
            }

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                adCumulSum[iBar] = adCumulSum[iBar - 1] - adBasePrice[iBar - iPeriod] + adBasePrice[iBar];
            }

            adCumulSum = MovingAverage(iSmooth, 0, maMethod, adCumulSum);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Cumulative Sum";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adCumulSum;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The Cumulative Sum rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

            case "The Cumulative Sum falls":
                indLogic = IndicatorLogic.The_indicator_falls;
                break;

            case "The Cumulative Sum changes its direction upward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                break;

            case "The Cumulative Sum changes its direction downward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adCumulSum, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iMAPeriod = (int)IndParam.NumParam[0].Value;
            int       iLRLength = (int)IndParam.NumParam[1].Value;
            double    dLevel    = IndParam.NumParam[2].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            double[] dX = new double[Bars];
            double[] dY = new double[Bars];
            double   dSigX;
            double   dSigY;
            double   dSigXY;
            double   dSigXX;

            double[] adLRSlope = new double[Bars];

            int iFirstBar = iMAPeriod + iLRLength + 2;

            double[] adMAPrice = MovingAverage(iMAPeriod, 0, maMethod, Price(basePrice));

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                dSigX  = 0;
                dSigY  = 0;
                dSigXX = 0;
                dSigXY = 0;
                for (int index = 0; index < iLRLength; index++)
                {
                    dSigX  = dSigX + index;
                    dSigY  = dSigY + adMAPrice[iBar - index];
                    dSigXY = dSigXY + index * adMAPrice[iBar - index];
                    dSigXX = dSigXX + index * index;
                }
                adLRSlope[iBar] = -(iLRLength * dSigXY - dSigX * dSigY) / (iLRLength * dSigXX - dSigX * dSigX);
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "LR Slope";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adLRSlope;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The LR Slope rises":
                indLogic      = IndicatorLogic.The_indicator_rises;
                SpecialValues = new double[1] {
                    0
                };
                break;

            case "The LR Slope falls":
                indLogic      = IndicatorLogic.The_indicator_falls;
                SpecialValues = new double[1] {
                    0
                };
                break;

            case "The LR Slope is higher than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                SpecialValues = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The LR Slope is lower than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                SpecialValues = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The LR Slope crosses the Level line upward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                SpecialValues = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The LR Slope crosses the Level line downward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                SpecialValues = new double[2] {
                    dLevel, -dLevel
                };
                break;

            case "The LR Slope changes its direction upward":
                indLogic      = IndicatorLogic.The_indicator_changes_its_direction_upward;
                SpecialValues = new double[1] {
                    0
                };
                break;

            case "The LR Slope changes its direction downward":
                indLogic      = IndicatorLogic.The_indicator_changes_its_direction_downward;
                SpecialValues = new double[1] {
                    0
                };
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adLRSlope, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #54
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       nPeriod   = (int)IndParam.NumParam[0].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = 2 * nPeriod + 2;

            double[] ma1 = MovingAverage(nPeriod, 0, maMethod, Price(basePrice));
            double[] ma2 = MovingAverage(nPeriod, 0, maMethod, ma1);
            double[] ma3 = MovingAverage(nPeriod, 0, maMethod, ma2);

            double[] adTrix = new double[Bars];

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adTrix[iBar] = 100 * (ma3[iBar] - ma3[iBar - 1]) / ma3[iBar - 1];
            }

            double[] adSignal = MovingAverage(nPeriod, 0, maMethod, adTrix);

            // adHistogram reprezents the Trix Index oscillator
            double[] adHistogram = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adHistogram[iBar] = adTrix[iBar] - adSignal[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[5];

            Component[0]           = new IndicatorComp();
            Component[0].CompName  = "Histogram";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adHistogram;

            Component[1]            = new IndicatorComp();
            Component[1].CompName   = "Signal";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Gold;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adSignal;

            Component[2]            = new IndicatorComp();
            Component[2].CompName   = "Trix Line";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Line;
            Component[2].ChartColor = Color.Blue;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = adTrix;

            Component[3]           = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            Component[4]           = new IndicatorComp();
            Component[4].ChartType = IndChartType.NoChart;
            Component[4].FirstBar  = iFirstBar;
            Component[4].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[3].DataType = IndComponentType.AllowOpenLong;
                Component[3].CompName = "Is long entry allowed";
                Component[4].DataType = IndComponentType.AllowOpenShort;
                Component[4].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[3].DataType = IndComponentType.ForceCloseLong;
                Component[3].CompName = "Close out long position";
                Component[4].DataType = IndComponentType.ForceCloseShort;
                Component[4].CompName = "Close out short position";
            }

            switch (IndParam.ListParam[0].Text)
            {
            case "The Trix Index line rises":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_rises);
                break;

            case "The Trix Index line falls":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_falls);
                break;

            case "The Trix Index line is higher than zero":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line);
                break;

            case "The Trix Index line is lower than zero":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line);
                break;

            case "The Trix Index line crosses the zero line upward":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward);
                break;

            case "The Trix Index line crosses the zero line downward":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward);
                break;

            case "The Trix Index line changes its direction upward":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_upward);
                break;

            case "The Trix Index line changes its direction downward":
                OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_downward);
                break;

            case "The Trix Index line crosses the Signal line upward":
                OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward);
                break;

            case "The Trix Index line crosses the Signal line downward":
                OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward);
                break;

            case "The Trix Index line is higher than the Signal line":
                OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line);
                break;

            case "The Trix Index line is lower than the Signal line":
                OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line);
                break;

            default:
                break;
            }

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            double    dLevel    = IndParam.NumParam[1].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int      iFirstBar   = iPeriod + 2;
            double[] adBasePrice = Price(basePrice);
            double[] adCMO1      = new double[Bars];
            double[] adCMO2      = new double[Bars];
            double[] adCMO1Sum   = new double[Bars];
            double[] adCMO2Sum   = new double[Bars];
            double[] adCMO       = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adCMO1[iBar] = 0;
                adCMO2[iBar] = 0;
                if (adBasePrice[iBar] > adBasePrice[iBar - 1])
                    adCMO1[iBar] = adBasePrice[iBar] - adBasePrice[iBar - 1];
                if (adBasePrice[iBar] < adBasePrice[iBar - 1])
                    adCMO2[iBar] = adBasePrice[iBar - 1] - adBasePrice[iBar];
            }

            for (int iBar = 0; iBar < iPeriod; iBar++)
            {
                adCMO1Sum[iPeriod - 1] += adCMO1[iBar];
                adCMO2Sum[iPeriod - 1] += adCMO2[iBar];
            }

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                adCMO1Sum[iBar] = adCMO1Sum[iBar - 1] + adCMO1[iBar] - adCMO1[iBar - iPeriod];
                adCMO2Sum[iBar] = adCMO2Sum[iBar - 1] + adCMO2[iBar] - adCMO2[iBar - iPeriod];

                if (adCMO1Sum[iBar] + adCMO2Sum[iBar] == 0)
                    adCMO[iBar] = 100;
                else
                    adCMO[iBar] = 100 * (adCMO1Sum[iBar] - adCMO2Sum[iBar]) / (adCMO1Sum[iBar] + adCMO2Sum[iBar]);
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "CMO";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.RoyalBlue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adCMO;

            Component[1] = new IndicatorComp();
            Component[1].ChartType  = IndChartType.NoChart;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = new double[Bars];

            Component[2] = new IndicatorComp();
            Component[2].ChartType  = IndChartType.NoChart;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The CMO rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The CMO falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The CMO is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The CMO is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The CMO crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The CMO crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The CMO changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The CMO changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    SpecialValues = new double[1] { 0 };
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adCMO, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int      iPeriod  = (int)IndParam.NumParam[0].Value;
            int      iDivisor = (int)IndParam.NumParam[1].Value;
            int      iPrvs    = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + 2;

            double[] adAEOM = new double[Bars];

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adAEOM[iBar] = iDivisor * (High[iBar] - Low[iBar]) * ((High[iBar] + Low[iBar]) / 2 - (High[iBar - 1] - Low[iBar - 1]) / 2) / Math.Max(Volume[iBar], 1);
            }

            adAEOM = MovingAverage(iPeriod, 0, maMethod, adAEOM);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Ease of Movement";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.LightSeaGreen;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adAEOM;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The Ease of Movement rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

            case "The Ease of Movement falls":
                indLogic = IndicatorLogic.The_indicator_falls;
                break;

            case "The Ease of Movement changes its direction upward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                break;

            case "The Ease of Movement changes its direction downward":
                indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adAEOM, 0, 0, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #57
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int       iPeriod   = (int)IndParam.NumParam[0].Value;
            int       iSmooth   = (int)IndParam.NumParam[1].Value;
            double    dLevel    =      IndParam.NumParam[2].Value;
            int       iPrvs     =      IndParam.CheckParam[0].Checked ? 1 : 0;

            int      iFirstBar   = iPrvs + iPeriod + iSmooth + 2;
            double[] adMomentum  = new double[Bars];
            double[] adBasePrice = Price(basePrice);

            for (int iBar = iPeriod; iBar < Bars; iBar++)
                adMomentum[iBar] = adBasePrice[iBar] - adBasePrice[iBar-iPeriod];

            if (iSmooth > 0)
                adMomentum = MovingAverage(iSmooth, 0, maMethod, adMomentum);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Momentum";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Blue;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMomentum;

            Component[1]            = new IndicatorComp();
            Component[1].ChartType  = IndChartType.NoChart;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = new double[Bars];

            Component[2]            = new IndicatorComp();
            Component[2].ChartType  = IndChartType.NoChart;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Momentum rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The Momentum falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The Momentum is higher than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Momentum is lower than the Level line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Momentum crosses the Level line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Momentum crosses the Level line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    SpecialValues = new double[2] { dLevel, -dLevel };
                    break;

                case "The Momentum changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    SpecialValues = new double[1] { 0 };
                    break;

                case "The Momentum changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    SpecialValues = new double[1] { 0 };
                    break;

                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adMomentum, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }
Пример #58
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iSense = (int)IndParam.NumParam[0].Value;

            int iFirstBar = iSense;

            double[] adFibo0;
            double[] adFibo382;
            double[] adFibo50;
            double[] adFibo618;
            double[] adFibo100;

            bool bReverseLogic = (IndParam.ListParam[1].Text == "Retracement");
            int  iDeviation    = 5;
            int  iBackStep     = 3;

            double[] adHighPoint = new double[Bars];
            double[] adLowPoint  = new double[Bars];

            adFibo0   = new double[Bars];
            adFibo382 = new double[Bars];
            adFibo50  = new double[Bars];
            adFibo618 = new double[Bars];
            adFibo100 = new double[Bars];

            double dLastHigh = 0;
            double dLastLow  = 0;
            for (int iBar = iSense; iBar < Bars; iBar++)
            {
                // The highest High in the period [iBar-iSence, iBar]
                double dHigh = 0;
                for (int iShift = 0; iShift < iSense; iShift++)
                    if (dHigh < High[iBar - iShift])
                        dHigh = High[iBar - iShift];

                if (dHigh == dLastHigh)
                    dHigh = 0;
                else
                {
                    dLastHigh = dHigh;
                    if (dHigh - High[iBar] > iDeviation * Point)
                        dHigh = 0;
                    else
                        for (int iBack = 1; iBack <= iBackStep; iBack++)
                            if (adHighPoint[iBar - iBack] > 0 && adHighPoint[iBar - iBack] < dHigh)
                                adHighPoint[iBar - iBack] = 0;
                }

                adHighPoint[iBar] = dHigh;

                // The lowest Low in the period [iBar-iSence, iBar]
                double dLow = 10000;
                for (int iShift = 0; iShift < iSense; iShift++)
                    if (Low[iBar - iShift] < dLow)
                        dLow = Low[iBar - iShift];

                if (dLow == dLastLow)
                    dLow = 0;
                else
                {
                    dLastLow = dLow;
                    if (Low[iBar] - dLow > iDeviation * Point)
                        dLow = 0;
                    else
                        for (int iBack = 1; iBack <= iBackStep; iBack++)
                            if (adLowPoint[iBar - iBack] > 0 && adLowPoint[iBar - iBack] > dLow)
                                adLowPoint[iBar - iBack] = 0;
                }

                adLowPoint[iBar] = dLow;
            }

            int iLastHighBar = -1;
            int iLastLowBar  = -1;
            double dCurHigh;
            double dCurLow;
            dLastHigh = -1;
            dLastLow  = -1;

            for (int iBar = iSense; iBar < Bars; iBar++)
            {
                dCurHigh = adHighPoint[iBar];
                dCurLow  = adLowPoint[iBar];
                if (dCurLow == 0 && dCurHigh == 0) continue;

                if (dCurHigh != 0)
                {
                    if (dLastHigh > 0)
                    {
                        if (dLastHigh < dCurHigh) adHighPoint[iLastHighBar] = 0;
                        else adHighPoint[iBar] = 0;
                    }
                    if (dLastHigh < dCurHigh || dLastHigh < 0)
                    {
                        dLastHigh    = dCurHigh;
                        iLastHighBar = iBar;
                    }
                    dLastLow = -1;
                }

                if (dCurLow != 0)
                {
                    if (dLastLow > 0)
                    {
                        if (dLastLow > dCurLow) adLowPoint[iLastLowBar] = 0;
                        else adLowPoint[iBar] = 0;
                    }
                    if (dCurLow < dLastLow || dLastLow < 0)
                    {
                        dLastLow    = dCurLow;
                        iLastLowBar = iBar;
                    }
                    dLastHigh = -1;
                }
            }

            dLastHigh = 0;
            dLastLow  = 0;
            int iFirstLowBar  = 0;
            int iFirstHighBar = 0;
            for (int iBar = 0; iBar < Bars; iBar++)
            {
                if (adHighPoint[iBar] > 0)
                {
                    dLastHigh = adHighPoint[iBar];
                    iFirstHighBar = iBar;
                }
                if (adLowPoint[iBar] > 0)
                {
                    dLastLow = adLowPoint[iBar];
                    iFirstLowBar = iBar;
                }
                if (iFirstHighBar > 0 && iFirstLowBar > 0) break;
            }

            for (int iBar = Math.Max(iFirstLowBar, iFirstHighBar); iBar < Bars; iBar++)
            {
                if (adHighPoint[iBar - 1] > 0)
                {
                    dLastHigh = adHighPoint[iBar - 1];
                    adFibo0  [iBar] = dLastHigh;
                    adFibo382[iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.382;
                    adFibo50 [iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.500;
                    adFibo618[iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.618;
                    adFibo100[iBar] = dLastLow;
                }
                else if (adLowPoint[iBar - 1] > 0)
                {
                    dLastLow = adLowPoint[iBar - 1];
                    adFibo0  [iBar] = dLastLow;
                    adFibo382[iBar] = dLastLow + (dLastHigh - dLastLow) * 0.382;
                    adFibo50 [iBar] = dLastLow + (dLastHigh - dLastLow) * 0.500;
                    adFibo618[iBar] = dLastLow + (dLastHigh - dLastLow) * 0.618;
                    adFibo100[iBar] = dLastHigh;
                }
                else
                {
                    adFibo0  [iBar] = adFibo0  [iBar - 1];
                    adFibo382[iBar] = adFibo382[iBar - 1];
                    adFibo50 [iBar] = adFibo50 [iBar - 1];
                    adFibo618[iBar] = adFibo618[iBar - 1];
                    adFibo100[iBar] = adFibo100[iBar - 1];
                }
            }

            // Saving the components
            Component = new IndicatorComp[8];

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Position entry price";
            Component[0].DataType   = IndComponentType.OpenPrice;
            Component[0].ChartType  = IndChartType.NoChart;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = new double[Bars];

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Fibonacci retracement 0%";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Level;
            Component[1].ChartColor = Color.Green;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adFibo0;

            Component[2] = new IndicatorComp();
            Component[2].CompName   = "Fibonacci retracement 38.2%";
            Component[2].DataType   = IndComponentType.IndicatorValue;
            Component[2].ChartType  = IndChartType.Level;
            Component[2].ChartColor = Color.Gold;
            Component[2].FirstBar   = iFirstBar;
            Component[2].Value      = adFibo382;

            Component[3] = new IndicatorComp();
            Component[3].CompName   = "Fibonacci retracement 50%";
            Component[3].DataType   = IndComponentType.IndicatorValue;
            Component[3].ChartType  = IndChartType.Level;
            Component[3].ChartColor = Color.Orchid;
            Component[3].FirstBar   = iFirstBar;
            Component[3].Value      = adFibo50;

            Component[4] = new IndicatorComp();
            Component[4].CompName   = "Fibonacci retracement 61.8%";
            Component[4].DataType   = IndComponentType.IndicatorValue;
            Component[4].ChartType  = IndChartType.Level;
            Component[4].ChartColor = Color.Purple;
            Component[4].FirstBar   = iFirstBar;
            Component[4].Value      = adFibo618;

            Component[5] = new IndicatorComp();
            Component[5].CompName   = "Fibonacci retracement 100%";
            Component[5].DataType   = IndComponentType.IndicatorValue;
            Component[5].ChartType  = IndChartType.Level;
            Component[5].ChartColor = Color.Red;
            Component[5].FirstBar   = iFirstBar;
            Component[5].Value      = adFibo100;

            Component[6] = new IndicatorComp();
            Component[6].CompName  = "Is long entry allowed";
            Component[6].DataType  = IndComponentType.AllowOpenLong;
            Component[6].ChartType = IndChartType.NoChart;
            Component[6].FirstBar  = iFirstBar;
            Component[6].Value     = new double[Bars];

            Component[7]           = new IndicatorComp();
            Component[7].CompName  = "Is short entry allowed";
            Component[7].DataType  = IndComponentType.AllowOpenShort;
            Component[7].ChartType = IndChartType.NoChart;
            Component[7].FirstBar  = iFirstBar;
            Component[7].Value	   = new double[Bars];

            int iBarFibo382Reached = 0;
            int iBarFibo500Reached = 0;
            int iBarFibo618Reached = 0;
            int iBarFibo100Reached = 0;

            for (int iBar = Math.Max(iFirstLowBar, iFirstHighBar); iBar < Bars; iBar++)
            {
                Component[0].Value[iBar] = 0;

                // Reset
                if (adHighPoint[iBar - 1] > 0 || adLowPoint[iBar - 1] > 0)
                {
                    iBarFibo382Reached = 0;
                    iBarFibo500Reached = 0;
                    iBarFibo618Reached = 0;
                    iBarFibo100Reached = 0;
                }

                // Up trend
                if (adFibo0[iBar] < adFibo100[iBar])
                {
                    if (iBarFibo382Reached == 0 && Low[iBar] <= adFibo382[iBar] && High[iBar] >= adFibo382[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 0 : 1;
                        Component[7].Value[iBar] = bReverseLogic ? 1 : 0;
                        Component[0].Value[iBar] = adFibo382[iBar];
                        iBarFibo382Reached = iBar;
                    }
                    if (iBarFibo500Reached == 0 && Low[iBar] <= adFibo50[iBar] && High[iBar] >= adFibo50[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 0 : 1;
                        Component[7].Value[iBar] = bReverseLogic ? 1 : 0;
                        if (iBarFibo382Reached != iBar)
                            Component[0].Value[iBar] = adFibo50[iBar];
                        iBarFibo500Reached = iBar;
                    }
                    if (iBarFibo618Reached == 0 && Low[iBar] <= adFibo618[iBar] && High[iBar] >= adFibo618[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 0 : 1;
                        Component[7].Value[iBar] = bReverseLogic ? 1 : 0;
                        if (iBarFibo500Reached != iBar)
                            Component[0].Value[iBar] = adFibo618[iBar];
                        iBarFibo618Reached = iBar;
                    }
                    if (iBarFibo100Reached == 0 && Low[iBar] <= adFibo100[iBar] && High[iBar] >= adFibo100[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 0 : 1;
                        Component[7].Value[iBar] = bReverseLogic ? 1 : 0;
                        if (iBarFibo618Reached != iBar)
                            Component[0].Value[iBar] = adFibo100[iBar];
                        iBarFibo100Reached = iBar;
                    }
                }

                // Down trend
                if (adFibo0[iBar] > adFibo100[iBar])
                {
                    if (iBarFibo382Reached == 0 && Low[iBar] <= adFibo382[iBar] && High[iBar] >= adFibo382[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 1 : 0;
                        Component[7].Value[iBar] = bReverseLogic ? 0 : 1;
                        Component[0].Value[iBar] = adFibo382[iBar];
                        iBarFibo382Reached = iBar;
                    }
                    if (iBarFibo500Reached == 0 && Low[iBar] <= adFibo50[iBar] && High[iBar] >= adFibo50[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 1 : 0;
                        Component[7].Value[iBar] = bReverseLogic ? 0 : 1;
                        if (iBarFibo382Reached != iBar)
                            Component[0].Value[iBar] = adFibo50[iBar];
                        iBarFibo500Reached = iBar;
                    }
                    if (iBarFibo618Reached == 0 && Low[iBar] <= adFibo618[iBar] && High[iBar] >= adFibo618[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 1 : 0;
                        Component[7].Value[iBar] = bReverseLogic ? 0 : 1;
                        if (iBarFibo500Reached != iBar)
                            Component[0].Value[iBar] = adFibo618[iBar];
                        iBarFibo618Reached = iBar;
                    }
                    if (iBarFibo100Reached == 0 && Low[iBar] <= adFibo100[iBar] && High[iBar] >= adFibo100[iBar])
                    {
                        Component[6].Value[iBar] = bReverseLogic ? 1 : 0;
                        Component[7].Value[iBar] = bReverseLogic ? 0 : 1;
                        if (iBarFibo618Reached != iBar)
                            Component[0].Value[iBar] = adFibo100[iBar];
                        iBarFibo100Reached = iBar;
                    }
                }
            }

            return;
        }
Пример #59
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int period = (int)IndParam.NumParam[0].Value;
            int multipl = (int)IndParam.NumParam[1].Value;
            int prev = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar = period + 2;

            double[] ATR = new double[Bars];

            for (int bar = 1; bar < Bars; bar++)
                ATR[bar] = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);

            ATR = MovingAverage(period, 0, maMethod, ATR);

            double[] ATRStop = new double[Bars];
            double minStop = 5 * Point;

            for (int bar = firstBar; bar < Bars - prev; bar++)
                ATRStop[bar + prev] = Math.Max(ATR[bar] * multipl, minStop);

            // Saving the components
            Component = new IndicatorComp[2];

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "ATR Stop margin";
            Component[0].DataType      = IndComponentType.IndicatorValue;
            Component[0].FirstBar      = firstBar;
            Component[0].ShowInDynInfo = false;
            Component[0].Value         = ATRStop;

            Component[1]               = new IndicatorComp();
            Component[1].CompName      = "ATR Stop for the transferred position";
            Component[1].DataType	   = IndComponentType.Other;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar	   = firstBar;
            Component[1].Value	       = new double[Bars];

            return;
        }
Пример #60
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            MAMethod maMethod   = (MAMethod)IndParam.ListParam[1].Index;
            int      iPeriod    = (int)IndParam.NumParam[0].Value;
            int      iSmoothing = (int)IndParam.NumParam[1].Value;
            int      dLevel     = (int)IndParam.NumParam[2].Value;
            int      iPrvs      = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + iSmoothing + iPrvs + 2;

            double[] adR  = new double[Bars];
            double   dMin = double.MaxValue;
            double   dMax = double.MinValue;

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                dMin = double.MaxValue;
                dMax = double.MinValue;
                for (int index = 0; index < iPeriod; index++)
                {
                    if (High[iBar - index] > dMax)
                    {
                        dMax = High[iBar - index];
                    }
                    if (Low [iBar - index] < dMin)
                    {
                        dMin = Low [iBar - index];
                    }
                }
                adR[iBar] = -100 * (dMax - Close[iBar]) / (dMax - dMin);
            }

            double[] adRSmoothed = MovingAverage(iSmoothing, 0, maMethod, adR);

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "%R";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Teal;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adRSmoothed;

            Component[1]           = new IndicatorComp();
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = new double[Bars];

            Component[2]           = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            // Sets the Component's type
            if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "The %R rises":
                indLogic      = IndicatorLogic.The_indicator_rises;
                SpecialValues = new double[1] {
                    -50
                };
                break;

            case "The %R falls":
                indLogic      = IndicatorLogic.The_indicator_falls;
                SpecialValues = new double[1] {
                    -50
                };
                break;

            case "The %R is higher than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                SpecialValues = new double[2] {
                    dLevel, -100 - dLevel
                };
                break;

            case "The %R is lower than the Level line":
                indLogic      = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                SpecialValues = new double[2] {
                    dLevel, -100 - dLevel
                };
                break;

            case "The %R crosses the Level line upward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                SpecialValues = new double[2] {
                    dLevel, -100 - dLevel
                };
                break;

            case "The %R crosses the Level line downward":
                indLogic      = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                SpecialValues = new double[2] {
                    dLevel, -100 - dLevel
                };
                break;

            case "The %R changes its direction upward":
                indLogic      = IndicatorLogic.The_indicator_changes_its_direction_upward;
                SpecialValues = new double[1] {
                    -50
                };
                break;

            case "The %R changes its direction downward":
                indLogic      = IndicatorLogic.The_indicator_changes_its_direction_downward;
                SpecialValues = new double[1] {
                    -50
                };
                break;

            default:
                break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adRSmoothed, dLevel, -100 - dLevel, ref Component[1], ref Component[2], indLogic);

            return;
        }