コード例 #1
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public N_Bars_Exit(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "N Bars Exit";
            PossibleSlots = SlotTypes.CloseFilter;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Exit N Bars after entry",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "N Bars";
            IndParam.NumParam[0].Value   = 10;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 10000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The number of bars after entry to exit the position.";

            return;
        }
コード例 #2
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Long_or_Short(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Long or Short";
            PossibleSlots = SlotTypes.OpenFilter;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Open long positions only",
                "Open short positions only",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            return;
        }
コード例 #3
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            IndParam.ExecutionTime = ExecutionTime.AtBarClosing;
            IndParam.IndicatorType = TypeOfIndicator.DateTime;
            IndParam.IsAllowLTF = false;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new[]
            {
                "Exit the market before the specified hour"
            };
            IndParam.ListParam[0].Index = 0;
            IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Indicator's logic.";

            IndParam.ListParam[1].Caption = "Base price";
            IndParam.ListParam[1].ItemList = new[] {"Close"};
            IndParam.ListParam[1].Index = 0;
            IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled = true;
            IndParam.ListParam[1].ToolTip = "Exit price of the position.";

            // The NumericUpDown parameters.
            IndParam.NumParam[0].Caption = "Exit hour";
            IndParam.NumParam[0].Value = 0;
            IndParam.NumParam[0].Min = 0;
            IndParam.NumParam[0].Max = 24;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The position's closing hour.";
        }
コード例 #4
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type.
        /// </summary>
        public Account_Percent_Stop(SlotTypes slotType)
        {
            // General properties
            IndicatorName   = "Account Percent Stop";
            PossibleSlots   = SlotTypes.Close;
            SeparatedChart  = false;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Limit the risk to percent of the account"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Account percent";
            IndParam.NumParam[0].Value   = 2;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 20;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "Maximum account to risk.";

            return;
        }
コード例 #5
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Parabolic_SAR(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Parabolic SAR";
            PossibleSlots = SlotTypes.OpenFilter | SlotTypes.Close;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            if (slotType == SlotTypes.OpenFilter)
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "The price is higher than the PSAR value"
                };
            else if (slotType == SlotTypes.Close)
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Exit the market at PSAR"
                };
            else
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Not Defined"
                };
            IndParam.ListParam[0].Index    = 0;
            IndParam.ListParam[0].Text     = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled  = true;
            IndParam.ListParam[0].ToolTip  = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Starting AF";
            IndParam.NumParam[0].Value   = 0.02;
            IndParam.NumParam[0].Min     = 0.00;
            IndParam.NumParam[0].Max     = 5.00;
            IndParam.NumParam[0].Point   = 2;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The starting value of Acceleration Factor.";

            IndParam.NumParam[1].Caption = "Increment";
            IndParam.NumParam[1].Value   = 0.02;
            IndParam.NumParam[1].Min     = 0.01;
            IndParam.NumParam[1].Max     = 5.00;
            IndParam.NumParam[1].Point   = 2;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "Increment value.";

            IndParam.NumParam[2].Caption = "Maximum AF";
            IndParam.NumParam[2].Value   = 2.00;
            IndParam.NumParam[2].Min     = 0.01;
            IndParam.NumParam[2].Max     = 9.00;
            IndParam.NumParam[2].Point   = 2;
            IndParam.NumParam[2].Enabled = true;
            IndParam.NumParam[2].ToolTip = "The maximum value of the Acceleration Factor.";

            return;
        }
コード例 #6
0
        /// <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;
        }
コード例 #7
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new[]
                {
                    "Standard Deviation rises",
                    "Standard Deviation falls",
                    "Standard Deviation is higher than the Level line",
                    "Standard Deviation is lower than the Level line",
                    "Standard Deviation crosses the Level line upward",
                    "Standard Deviation crosses the Level line downward",
                    "Standard Deviation changes its direction upward",
                    "Standard Deviation changes its direction downward"
                };
            IndParam.ListParam[0].Index = 0;
            IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof (MAMethod));
            IndParam.ListParam[1].Index = (int) MAMethod.Simple;
            IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled = true;
            IndParam.ListParam[1].ToolTip = "The method of Moving Average used for the calculations.";

            IndParam.ListParam[2].Caption = "Base price";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof (BasePrice));
            IndParam.ListParam[2].Index = (int) BasePrice.Close;
            IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled = true;
            IndParam.ListParam[2].ToolTip = "The price the indicator is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Period";
            IndParam.NumParam[0].Value = 20;
            IndParam.NumParam[0].Min = 2;
            IndParam.NumParam[0].Max = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of calculation.";

            IndParam.NumParam[1].Caption = "Level";
            IndParam.NumParam[1].Value = 0;
            IndParam.NumParam[1].Min = 0;
            IndParam.NumParam[1].Max = 100;
            IndParam.NumParam[1].Point = 4;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "A critical level (for the appropriate logic).";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
        }
コード例 #8
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Exit at the Stop Loss level",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Stop Loss";
            IndParam.NumParam[0].Value   = 200;
            IndParam.NumParam[0].Min     = 5;
            IndParam.NumParam[0].Max     = 5000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The Stop value (in points).";
        }
コード例 #9
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Force_Index(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "Force Index";
            PossibleSlots  = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The Force Index rises",
                "The Force Index falls",
                "The Force Index is higher than the zero line",
                "The Force Index is lower than the zero line",
                "The Force Index crosses the zero line upward",
                "The Force Index crosses the zero line downward",
                "The Force Index changes its direction upward",
                "The Force Index changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Simple;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The method of smoothing.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[2].Index    = (int)BasePrice.Close;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The price the Force Index is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Period";
            IndParam.NumParam[0].Value   = 13;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 100;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The smoothing period.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #10
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters

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

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adBars[iBar] = 1;
            }

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

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "(No) Used bars";
            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      = "(No) Used bars";
            Component[1].DataType      = IndComponentType.AllowOpenShort;
            Component[1].ChartType     = IndChartType.NoChart;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar      = iFirstBar;
            Component[1].Value         = adBars;

            return;
        }
コード例 #11
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new[]
                {
                    "Exit N Bars after entry"
                };
            IndParam.ListParam[0].Index = 0;
            IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "N Bars";
            IndParam.NumParam[0].Value = 10;
            IndParam.NumParam[0].Min = 1;
            IndParam.NumParam[0].Max = 10000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The number of bars after entry to exit the position.";
        }
コード例 #12
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            ExitPointLongDescription  = "and open a new short one, at the entry price, when a sell entry signal arises";
            ExitPointShortDescription = "and open a new long one, at the entry price, when a buy entry signal arises";

            return;
        }
コード例 #13
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Day_Closing(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Day Closing";
            PossibleSlots = SlotTypes.Close;
            AllowClosingFilters = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.DateTime;
            IndParam.ExecutionTime = ExecutionTime.AtBarClosing;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[] { "Exit the market at the end of the day" };
            IndParam.ListParam[0].Index    = 0;
            IndParam.ListParam[0].Text     = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The execution price of all exit orders.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = new string[] { "Close" };
            IndParam.ListParam[1].Index    = 0;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "Exit price of the position.";

            return;
        }
コード例 #14
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.DateTime;
            IndParam.IsAllowLTF = false;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Enter the market between the specified days"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.NumParam[0].Caption  = "From (incl.)";
            IndParam.NumParam[0].Value    = 1;
            IndParam.NumParam[0].Min      = 1;
            IndParam.NumParam[0].Max      = 31;
            IndParam.NumParam[0].Point    = 0;
            IndParam.NumParam[0].Enabled  = true;
            IndParam.NumParam[0].ToolTip  = "Day of beginning for the entry period.";

            IndParam.NumParam[1].Caption  = "Until (excl.)";
            IndParam.NumParam[1].Value    = 31;
            IndParam.NumParam[1].Min      = 1;
            IndParam.NumParam[1].Max      = 31;
            IndParam.NumParam[1].Point    = 0;
            IndParam.NumParam[1].Enabled  = true;
            IndParam.NumParam[1].ToolTip  = "Day of ending for the entry period.";
        }
コード例 #15
0
        /// <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;
        }
コード例 #16
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public On_Balance_Volume(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "On Balance Volume";
            PossibleSlots  = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The On Balance Volume rises",
                "The On Balance Volume falls",
                "The On Balance Volume changes its direction upward",
                "The On Balance Volume changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #17
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            IndParam.IndicatorType = TypeOfIndicator.DateTime;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new[]
                {
                    "Do not open positions before",
                    "Do not open positions after"
                };
            IndParam.ListParam[0].Index = 0;
            IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of the date filter.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Year";
            IndParam.NumParam[0].Value = 2000;
            IndParam.NumParam[0].Min = 1900;
            IndParam.NumParam[0].Max = 2100;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The year.";

            IndParam.NumParam[1].Caption = "Month";
            IndParam.NumParam[1].Value = 1;
            IndParam.NumParam[1].Min = 1;
            IndParam.NumParam[1].Max = 12;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "The month.";
        }
コード例 #18
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;
        }
コード例 #19
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Narrow_Range(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "Narrow Range";
            PossibleSlots  = SlotTypes.OpenFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "There is a NR4 formation",
                "There is a NR7 formation",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Indicator's logic.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #20
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Volume rises",
                "Volume falls",
                "Volume is higher than the Level line",
                "Volume is lower than the Level line",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Level";
            IndParam.NumParam[0].Value   = 1000;
            IndParam.NumParam[0].Min     = 0;
            IndParam.NumParam[0].Max     = 100000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "A critical level (for the appropriate logic).";

            // CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
        }
コード例 #21
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Lot_Limiter(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Lot Limiter";
            PossibleSlots = SlotTypes.OpenFilter;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[] { "Limit the number of open lots" };
            IndParam.ListParam[0].Index    = 0;
            IndParam.ListParam[0].Text     = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled  = true;
            IndParam.ListParam[0].ToolTip  = "Indicator's logic";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Maximum lots";
            IndParam.NumParam[0].Value   = 5;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 100;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "Maximum number of open lots.";

            return;
        }
コード例 #22
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            if (IndParam.ListParam[0].Text == "Enter no more than once a bar")
            {
                EntryFilterLongDescription  = "this is the first entry during the bar";
                EntryFilterShortDescription = "this is the first entry during the bar";
            }
            else if (IndParam.ListParam[0].Text == "Enter no more than once a day")
            {
                EntryFilterLongDescription  = "this is the first entry during the day";
                EntryFilterShortDescription = "this is the first entry during the day";
            }
            else if (IndParam.ListParam[0].Text == "Enter no more than once a week")
            {
                EntryFilterLongDescription  = "this is the first entry during the week";
                EntryFilterShortDescription = "this is the first entry during the week";
            }
            else if (IndParam.ListParam[0].Text == "Enter no more than once a month")
            {
                EntryFilterLongDescription  = "this is the first entry during the month";
                EntryFilterShortDescription = "this is the first entry during the month";
            }

            return;
        }
コード例 #23
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Take_Profit(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Take Profit";
            PossibleSlots = SlotTypes.Close;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Exit at the Take Profit level",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Take Profit";
            IndParam.NumParam[0].Value   = 200;
            IndParam.NumParam[0].Min     = 5;
            IndParam.NumParam[0].Max     = 5000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The Take Profit value (in pips).";

            return;
        }
コード例 #24
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new[]
                {
                    "Limit the risk to percent of the account"
                };
            IndParam.ListParam[0].Index = 0;
            IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Account percent";
            IndParam.NumParam[0].Value = 2;
            IndParam.NumParam[0].Min = 1;
            IndParam.NumParam[0].Max = 20;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "Maximum account to risk.";
        }
コード例 #25
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Enter_Once(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Enter Once";
            PossibleSlots = SlotTypes.OpenFilter;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.DateTime;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Enter no more than once a bar",
                "Enter no more than once a day",
                "Enter no more than once a week",
                "Enter no more than once a month"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Indicator's logic.";

            return;
        }
コード例 #26
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Bar_Opening(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Bar Opening";
            PossibleSlots = SlotTypes.Open;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;
            IndParam.ExecutionTime = ExecutionTime.AtBarOpening;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[] { "Enter the market at the beginning of the bar" };
            IndParam.ListParam[0].Index    = 0;
            IndParam.ListParam[0].Text     = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled  = true;
            IndParam.ListParam[0].ToolTip  = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = new string[] { "Open" };
            IndParam.ListParam[1].Index    = 0;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The execution price of all entry orders.";

            return;
        }
コード例 #27
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            EntryPointLongDescription  = "at the beginning of the bar";
            EntryPointShortDescription = "at the beginning of the bar";

            return;
        }
コード例 #28
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;
        }
コード例 #29
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Percent_Change(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "Percent Change";
            PossibleSlots  = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The Percent Change rises",
                "The Percent Change falls",
                "The Percent Change is higher than the Level line",
                "The Percent Change is lower than the Level line",
                "The Percent Change crosses the Level line upward",
                "The Percent Change crosses the Level line downward",
                "The Percent Change changes its direction upward",
                "The Percent Change changes its direction downward"
            };
            IndParam.ListParam[0].Index    = 0;
            IndParam.ListParam[0].Text     = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled  = true;
            IndParam.ListParam[0].ToolTip  = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[1].Index    = (int)BasePrice.Close;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The price the Percent Change is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption   = "Period";
            IndParam.NumParam[0].Value     = 10;
            IndParam.NumParam[0].Min       = 1;
            IndParam.NumParam[0].Max       = 200;
            IndParam.NumParam[0].Enabled   = true;
            IndParam.NumParam[0].ToolTip   = "Period used to calculate the Percent Change value.";

            IndParam.NumParam[1].Caption   = "Level";
            IndParam.NumParam[1].Value     = 0;
            IndParam.NumParam[1].Min       = -100;
            IndParam.NumParam[1].Max       = 100;
            IndParam.NumParam[1].Enabled   = true;
            IndParam.NumParam[1].ToolTip   = "A critical level (for the appropriate logic).";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #30
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            IndParam.IndicatorType = TypeOfIndicator.Indicator;
            IndParam.ExecutionTime = ExecutionTime.DuringTheBar;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            IndParam.ListParam[0].ItemList = new[]
                {
                    "ADX rises",
                    "ADX falls",
                    "ADX is higher than the Level line",
                    "ADX is lower than the Level line",
                    "ADX crosses the Level line upward",
                    "ADX crosses the Level line downward",
                    "ADX changes its direction upward",
                    "ADX changes its direction downward"
                };
            IndParam.ListParam[0].Index = 0;
            IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof (MAMethod));
            IndParam.ListParam[1].Index = (int) MAMethod.Exponential;
            IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled = true;
            IndParam.ListParam[1].ToolTip = "The Moving Average method used for smoothing the ADX value.";

            IndParam.ListParam[2].Caption = "Base price";
            IndParam.ListParam[2].ItemList = new[] {"Bar range"};
            IndParam.ListParam[2].Index = 0;
            IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled = true;
            IndParam.ListParam[2].ToolTip = "ADX uses current and previous bar ranges.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Period";
            IndParam.NumParam[0].Value = 14;
            IndParam.NumParam[0].Min = 1;
            IndParam.NumParam[0].Max = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of ADX.";

            IndParam.NumParam[1].Caption = "Level";
            IndParam.NumParam[1].Value = 0;
            IndParam.NumParam[1].Min = 0;
            IndParam.NumParam[1].Max = 100;
            IndParam.NumParam[1].Point = 0;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "A critical level (for the appropriate logic).";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
        }
コード例 #31
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            string sLevelLong  = (IndParam.NumParam[2].Value == 0 ? "0" : IndParam.NumParam[2].ValueToString);
            string sLevelShort = (IndParam.NumParam[2].Value == 0 ? "0" : "-" + IndParam.NumParam[2].ValueToString);

            EntryFilterLongDescription  = "the " + ToString() + " ";
            EntryFilterShortDescription = "the " + ToString() + " ";
            ExitFilterLongDescription   = "the " + ToString() + " ";
            ExitFilterShortDescription  = "the " + ToString() + " ";

            switch (IndParam.ListParam[0].Text)
            {
            case "The Momentum rises":
                EntryFilterLongDescription  += "rises";
                EntryFilterShortDescription += "falls";
                ExitFilterLongDescription   += "rises";
                ExitFilterShortDescription  += "falls";
                break;

            case "The Momentum falls":
                EntryFilterLongDescription  += "falls";
                EntryFilterShortDescription += "rises";
                ExitFilterLongDescription   += "falls";
                ExitFilterShortDescription  += "rises";
                break;

            case "The Momentum is higher than the Level line":
                EntryFilterLongDescription  += "is higher than the Level " + sLevelLong;
                EntryFilterShortDescription += "is lower than the Level " + sLevelShort;
                ExitFilterLongDescription   += "is higher than the Level " + sLevelLong;
                ExitFilterShortDescription  += "is lower than the Level " + sLevelShort;
                break;

            case "The Momentum is lower than the Level line":
                EntryFilterLongDescription  += "is lower than the Level " + sLevelLong;
                EntryFilterShortDescription += "is higher than the Level " + sLevelShort;
                ExitFilterLongDescription   += "is lower than the Level " + sLevelLong;
                ExitFilterShortDescription  += "is higher than the Level " + sLevelShort;
                break;

            case "The Momentum crosses the Level line upward":
                EntryFilterLongDescription  += "crosses the Level " + sLevelLong + " upward";
                EntryFilterShortDescription += "crosses the Level " + sLevelShort + " downward";
                ExitFilterLongDescription   += "crosses the Level " + sLevelLong + " upward";
                ExitFilterShortDescription  += "crosses the Level " + sLevelShort + " downward";
                break;

            case "The Momentum crosses the Level line downward":
                EntryFilterLongDescription  += "crosses the Level " + sLevelLong + " downward";
                EntryFilterShortDescription += "crosses the Level " + sLevelShort + " upward";
                ExitFilterLongDescription   += "crosses the Level " + sLevelLong + " downward";
                ExitFilterShortDescription  += "crosses the Level " + sLevelShort + " upward";
                break;

            case "The Momentum changes its direction upward":
                EntryFilterLongDescription  += "changes its direction upward";
                EntryFilterShortDescription += "changes its direction downward";
                ExitFilterLongDescription   += "changes its direction upward";
                ExitFilterShortDescription  += "changes its direction downward";
                break;

            case "The Momentum changes its direction downward":
                EntryFilterLongDescription  += "changes its direction downward";
                EntryFilterShortDescription += "changes its direction upward";
                ExitFilterLongDescription   += "changes its direction downward";
                ExitFilterShortDescription  += "changes its direction upward";
                break;

            default:
                break;
            }

            return;
        }
コード例 #32
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;
        }
コード例 #33
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            EntryFilterLongDescription  = "the " + ToString() + " ";
            EntryFilterShortDescription = "the " + ToString() + " ";
            ExitFilterLongDescription   = "the " + ToString() + " ";
            ExitFilterShortDescription  = "the " + ToString() + " ";

            switch (IndParam.ListParam[0].Text)
            {
            case "The Oscillator rises":
                EntryFilterLongDescription  += "rises";
                EntryFilterShortDescription += "falls";
                ExitFilterLongDescription   += "rises";
                ExitFilterShortDescription  += "falls";
                break;

            case "The Oscillator falls":
                EntryFilterLongDescription  += "falls";
                EntryFilterShortDescription += "rises";
                ExitFilterLongDescription   += "falls";
                ExitFilterShortDescription  += "rises";
                break;

            case "The Oscillator is higher than the zero line":
                EntryFilterLongDescription  += "is higher than the zero line";
                EntryFilterShortDescription += "is lower than the zero line";
                ExitFilterLongDescription   += "is higher than the zero line";
                ExitFilterShortDescription  += "is lower than the zero line";
                break;

            case "The Oscillator is lower than the zero line":
                EntryFilterLongDescription  += "is lower than the zero line";
                EntryFilterShortDescription += "is higher than the zero line";
                ExitFilterLongDescription   += "is lower than the zero line";
                ExitFilterShortDescription  += "is higher than the zero line";
                break;

            case "The Oscillator crosses the zero line upward":
                EntryFilterLongDescription  += "crosses the zero line upward";
                EntryFilterShortDescription += "crosses the zero line downward";
                ExitFilterLongDescription   += "crosses the zero line upward";
                ExitFilterShortDescription  += "crosses the zero line downward";
                break;

            case "The Oscillator crosses the zero line downward":
                EntryFilterLongDescription  += "crosses the zero line downward";
                EntryFilterShortDescription += "crosses the zero line upward";
                ExitFilterLongDescription   += "crosses the zero line downward";
                ExitFilterShortDescription  += "crosses the zero line upward";
                break;

            case "The Oscillator changes its direction upward":
                EntryFilterLongDescription  += "changes its direction upward";
                EntryFilterShortDescription += "changes its direction downward";
                ExitFilterLongDescription   += "changes its direction upward";
                ExitFilterShortDescription  += "changes its direction downward";
                break;

            case "The Oscillator changes its direction downward":
                EntryFilterLongDescription  += "changes its direction downward";
                EntryFilterShortDescription += "changes its direction upward";
                ExitFilterLongDescription   += "changes its direction downward";
                ExitFilterShortDescription  += "changes its direction upward";
                break;

            default:
                break;
            }

            return;
        }
コード例 #34
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Oscillator_of_RSI(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "Oscillator of RSI";
            PossibleSlots  = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.OscillatorOfIndicators;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The Oscillator rises",
                "The Oscillator falls",
                "The Oscillator is higher than the zero line",
                "The Oscillator is lower than the zero line",
                "The Oscillator crosses the zero line upward",
                "The Oscillator crosses the zero line downward",
                "The Oscillator changes its direction upward",
                "The Oscillator changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the oscillator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Smoothed;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The Moving Average method used for smoothing the RSI value.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[2].Index    = (int)BasePrice.Close;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The base price for the RSI oscillator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "First RSI period";
            IndParam.NumParam[0].Value   = 10;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of first RSI.";

            IndParam.NumParam[1].Caption = "Second RSI period";
            IndParam.NumParam[1].Value   = 14;
            IndParam.NumParam[1].Min     = 1;
            IndParam.NumParam[1].Max     = 200;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "The period of second RSI.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #35
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.IndicatorsMA;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new[]
            {
                "RSI MA Oscillator rises",
                "RSI MA Oscillator falls",
                "RSI MA Oscillator is higher than the zero line",
                "RSI MA Oscillator is lower than the zero line",
                "RSI MA Oscillator crosses the zero line upward",
                "RSI MA Oscillator crosses the zero line downward",
                "RSI MA Oscillator changes its direction upward",
                "RSI MA Oscillator changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the oscillator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Smoothed;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The Moving Average method used for smoothing RSI value.";

            IndParam.ListParam[2].Caption  = "Signal line method";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[2].Index    = (int)MAMethod.Exponential;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The Moving Average method used for smoothing the signal line.";

            IndParam.ListParam[3].Caption  = "Base price";
            IndParam.ListParam[3].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[3].Index    = (int)BasePrice.Close;
            IndParam.ListParam[3].Text     = IndParam.ListParam[3].ItemList[IndParam.ListParam[3].Index];
            IndParam.ListParam[3].Enabled  = true;
            IndParam.ListParam[3].ToolTip  = "The price the indicator is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "RSI period";
            IndParam.NumParam[0].Value   = 10;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of RSI.";

            IndParam.NumParam[1].Caption = "Signal line period";
            IndParam.NumParam[1].Value   = 14;
            IndParam.NumParam[1].Min     = 1;
            IndParam.NumParam[1].Max     = 200;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "The period of smoothing the signal line.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
        }
コード例 #36
0
        /// <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;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod + 2;

            double[] adPrice = Price(basePrice);
            double[] adValue = new double[Bars];

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

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                double dHighestHigh = double.MinValue;
                double dLowestLow   = double.MaxValue;
                for (int i = 0; i < iPeriod; i++)
                {
                    if (adPrice[iBar - i] > dHighestHigh)
                    {
                        dHighestHigh = adPrice[iBar - i];
                    }
                    if (adPrice[iBar - i] < dLowestLow)
                    {
                        dLowestLow = adPrice[iBar - i];
                    }
                }

                if (dHighestHigh == dLowestLow)
                {
                    dHighestHigh = dLowestLow + Point;
                }
                if (dHighestHigh - dLowestLow == 0.5)
                {
                    dHighestHigh += Point;
                }

                adValue[iBar] = 0.33 * 2 * ((adPrice[iBar] - dLowestLow) / (dHighestHigh - dLowestLow) - 0.5) + 0.67 * adValue[iBar - 1];
            }

            double[] adFT = new double[Bars];
            adFT[0] = 0;
            for (int iBar = 1; iBar < Bars; iBar++)
            {
                adFT[iBar] = 0.5 * (double)Math.Log10((1 + adValue[iBar]) / (1 - adValue[iBar])) + 0.5 * adFT[iBar - 1];
            }

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

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

            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 Fisher Transform rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

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

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

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

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

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

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

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

            default:
                break;
            }

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

            return;
        }
コード例 #37
0
        /// <summary>
        ///     Panel Slot Paint
        /// </summary>
        private void PnlSlotPaint(object sender, PaintEventArgs e)
        {
            var       pnl      = (ContextPanel)sender;
            Graphics  g        = e.Graphics;
            var       slot     = (int)pnl.Tag;
            int       width    = pnl.ClientSize.Width;
            SlotTypes slotType = strategy.GetSlotType(slot);

            Color colorBackground             = LayoutColors.ColorSlotBackground;
            Color colorCaptionText            = LayoutColors.ColorSlotCaptionText;
            Color colorCaptionBackOpen        = LayoutColors.ColorSlotCaptionBackOpen;
            Color colorCaptionBackOpenFilter  = LayoutColors.ColorSlotCaptionBackOpenFilter;
            Color colorCaptionBackClose       = LayoutColors.ColorSlotCaptionBackClose;
            Color colorCaptionBackCloseFilter = LayoutColors.ColorSlotCaptionBackCloseFilter;
            Color colorIndicatorNameText      = LayoutColors.ColorSlotIndicatorText;
            Color colorLogicText = LayoutColors.ColorSlotLogicText;
            Color colorParamText = LayoutColors.ColorSlotParamText;
            Color colorValueText = LayoutColors.ColorSlotValueText;
            Color colorDash      = LayoutColors.ColorSlotDash;

            // Caption
            string stringCaptionText = string.Empty;
            Color  colorCaptionBack  = LayoutColors.ColorSignalRed;

            switch (slotType)
            {
            case SlotTypes.Open:
                stringCaptionText = Language.T("Opening Point of the Position");
                colorCaptionBack  = colorCaptionBackOpen;
                break;

            case SlotTypes.OpenFilter:
                stringCaptionText = Language.T("Opening Logic Condition");
                colorCaptionBack  = colorCaptionBackOpenFilter;
                break;

            case SlotTypes.Close:
                stringCaptionText = Language.T("Closing Point of the Position");
                colorCaptionBack  = colorCaptionBackClose;
                break;

            case SlotTypes.CloseFilter:
                stringCaptionText = Language.T("Closing Logic Condition");
                colorCaptionBack  = colorCaptionBackCloseFilter;
                break;
            }

            var penBorder = new Pen(Data.GetGradientColor(colorCaptionBack, -LayoutColors.DepthCaption), Border);

            var   fontCaptionText     = new Font(Font.FontFamily, 9);
            float captionHeight       = Math.Max(fontCaptionText.Height, 18);
            float captionWidth        = width;
            Brush brushCaptionText    = new SolidBrush(colorCaptionText);
            var   stringFormatCaption = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap,
                Alignment     = StringAlignment.Center
            };

            var rectCaption = new RectangleF(0, 0, captionWidth, captionHeight);

            Data.GradientPaint(g, rectCaption, colorCaptionBack, LayoutColors.DepthCaption);

            if (ShowRemoveSlotButtons && slot != strategy.OpenSlot && slot != strategy.CloseSlot)
            {
                int   buttonDimentions = (int)captionHeight - 2;
                int   buttonX          = width - buttonDimentions - 1;
                float captionTextWidth = g.MeasureString(stringCaptionText, fontCaptionText).Width;
                float captionTextX     = Math.Max((captionWidth - captionTextWidth) / 2f, 0);
                var   pfCaptionText    = new PointF(captionTextX, 0);
                var   sfCaptionText    = new SizeF(buttonX - captionTextX, captionHeight);
                rectCaption = new RectangleF(pfCaptionText, sfCaptionText);
                stringFormatCaption.Alignment = StringAlignment.Near;
            }
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectCaption, stringFormatCaption);

            // Border
            g.DrawLine(penBorder, 1, captionHeight, 1, pnl.Height);
            g.DrawLine(penBorder, pnl.Width - Border + 1, captionHeight, pnl.Width - Border + 1, pnl.Height);
            g.DrawLine(penBorder, 0, pnl.Height - Border + 1, pnl.Width, pnl.Height - Border + 1);

            // Paints the panel
            var rectPanel = new RectangleF(Border, captionHeight, pnl.Width - 2 * Border,
                                           pnl.Height - captionHeight - Border);

            Data.GradientPaint(g, rectPanel, colorBackground, LayoutColors.DepthControl);

            int vPosition = (int)captionHeight + 3;

            // Padlock image
            if (ShowPadlockImg)
            {
                if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Locked)
                {
                    g.DrawImage(Resources.padlock_img, 1, 1, 16, 16);
                }
                else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Open)
                {
                    g.DrawImage(Resources.open_padlock, 1, 1, 16, 16);
                }
                else if (strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked)
                {
                    g.DrawImage(Resources.linked, 1, 1, 16, 16);
                }
            }

            // Indicator name
            var stringFormatIndicatorName = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            var   fontIndicator = new Font(Font.FontFamily, 11f, FontStyle.Regular);
            Brush brushIndName  = new SolidBrush(colorIndicatorNameText);
            float indNameHeight = fontIndicator.Height;
            float fGroupWidth   = 0;

            if (Configs.UseLogicalGroups && (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter))
            {
                string sLogicalGroup = "[" + strategy.Slot[slot].LogicalGroup + "]";
                fGroupWidth = g.MeasureString(sLogicalGroup, fontIndicator).Width;
                var rectGroup = new RectangleF(0, vPosition, fGroupWidth, indNameHeight);
                g.DrawString(sLogicalGroup, fontIndicator, brushIndName, rectGroup, stringFormatIndicatorName);
            }
            stringFormatIndicatorName.Trimming = StringTrimming.EllipsisCharacter;
            string indicatorName = strategy.Slot[slot].IndicatorName;
            float  nameWidth     = g.MeasureString(indicatorName, fontIndicator).Width;

            RectangleF rectIndName = width >= 2 * fGroupWidth + nameWidth
                                         ? new RectangleF(0, vPosition, width, indNameHeight)
                                         : new RectangleF(fGroupWidth, vPosition, width - fGroupWidth, indNameHeight);

            g.DrawString(indicatorName, fontIndicator, brushIndName, rectIndName, stringFormatIndicatorName);
            vPosition += (int)indNameHeight;


            if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
            {
                pnl.CloseButton.ColorBack = colorCaptionBack;
                pnl.CloseButton.ColorFore = colorCaptionText;
                pnl.CloseButton.Visible   = ShowRemoveSlotButtons;
            }

            if (SlotMinMidMax == SlotSizeMinMidMax.min)
            {
                return;
            }

            // Logic
            var stringFormatLogic = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoClip
            };
            float padding = Space;

            if (strategy.Slot[slot].IndParam.ListParam[0].Enabled)
            {
                string value      = strategy.Slot[slot].IndParam.ListParam[0].Text;
                var    fontLogic  = new Font(Font.FontFamily, 10.5f, FontStyle.Regular);
                SizeF  sizeValue  = g.MeasureString(value, fontLogic, (int)(width - 2 * padding), stringFormatLogic);
                var    rectValue  = new RectangleF(padding, vPosition, width - 2 * padding, sizeValue.Height);
                Brush  brushLogic = new SolidBrush(colorLogicText);

                g.DrawString(value, fontLogic, brushLogic, rectValue, stringFormatLogic);
                vPosition += (int)sizeValue.Height;
            }

            if (SlotMinMidMax == SlotSizeMinMidMax.mid)
            {
                return;
            }

            // Parameters
            var stringFormat = new StringFormat
            {
                Trimming    = StringTrimming.EllipsisCharacter,
                FormatFlags = StringFormatFlags.NoWrap
            };
            var   fontParam  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            var   fontValue  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Brush brushParam = new SolidBrush(colorParamText);
            Brush brushValue = new SolidBrush(colorValueText);
            var   penDash    = new Pen(colorDash);

            // Find Maximum width of the strings
            float maxParamWidth = 0;
            float maxValueWidth = 0;

            for (int i = 1; i < 5; i++)
            {
                if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled)
                {
                    continue;
                }

                string caption   = strategy.Slot[slot].IndParam.ListParam[i].Caption;
                string value     = strategy.Slot[slot].IndParam.ListParam[i].Text;
                SizeF  sizeParam = g.MeasureString(caption, fontParam);
                SizeF  sizeValue = g.MeasureString(value, fontValue);

                if (maxParamWidth < sizeParam.Width)
                {
                    maxParamWidth = sizeParam.Width;
                }

                if (maxValueWidth < sizeValue.Width)
                {
                    maxValueWidth = sizeValue.Width;
                }
            }

            foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam)
            {
                if (!numericParam.Enabled)
                {
                    continue;
                }

                string caption   = numericParam.Caption;
                string value     = numericParam.ValueToString;
                SizeF  sizeParam = g.MeasureString(caption, fontParam);
                SizeF  sizeValue = g.MeasureString(value, fontValue);

                if (maxParamWidth < sizeParam.Width)
                {
                    maxParamWidth = sizeParam.Width;
                }

                if (maxValueWidth < sizeValue.Width)
                {
                    maxValueWidth = sizeValue.Width;
                }
            }

            foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam)
            {
                if (!checkParam.Enabled)
                {
                    continue;
                }

                string param     = checkParam.Caption;
                string value     = checkParam.Checked ? "Yes" : "No";
                SizeF  sizeParam = g.MeasureString(param, fontParam);
                SizeF  sizeValue = g.MeasureString(value, fontValue);

                if (maxParamWidth < sizeParam.Width)
                {
                    maxParamWidth = sizeParam.Width;
                }

                if (maxValueWidth < sizeValue.Width)
                {
                    maxValueWidth = sizeValue.Width;
                }
            }

            // Padding Parameter Padding Dash Padding Value Padding
            const float dashWidth      = 5;
            float       necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth;

            padding = width > necessaryWidth
                          ? Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding)
                          : 2;

            float tabParam = 2 * padding;
            float tabDash  = tabParam + maxParamWidth + padding;
            float tabValue = tabDash + dashWidth + padding;

            // List Parameters
            for (int i = 1; i < 5; i++)
            {
                if (!strategy.Slot[slot].IndParam.ListParam[i].Enabled)
                {
                    continue;
                }

                string caption    = strategy.Slot[slot].IndParam.ListParam[i].Caption;
                string value      = strategy.Slot[slot].IndParam.ListParam[i].Text;
                var    pointParam = new PointF(tabParam, vPosition);
                var    pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(tabValue, vPosition);
                var    sizeValue  = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectValue  = new RectangleF(pointValue, sizeValue);

                g.DrawString(caption, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectValue, stringFormat);
                vPosition += fontValue.Height;
            }

            // Num Parameters
            foreach (NumericParam numericParam in strategy.Slot[slot].IndParam.NumParam)
            {
                if (!numericParam.Enabled)
                {
                    continue;
                }

                string caption    = numericParam.Caption;
                string value      = numericParam.ValueToString;
                var    pointParam = new PointF(tabParam, vPosition);
                var    pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(tabValue, vPosition);
                var    sizeValue  = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectValue  = new RectangleF(pointValue, sizeValue);

                g.DrawString(caption, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectValue, stringFormat);
                vPosition += fontValue.Height;
            }

            // Check Parameters
            foreach (CheckParam checkParam in strategy.Slot[slot].IndParam.CheckParam)
            {
                if (!checkParam.Enabled)
                {
                    continue;
                }

                string param      = checkParam.Caption;
                string value      = checkParam.Checked ? "Yes" : "No";
                var    pointParam = new PointF(tabParam, vPosition);
                var    pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                var    pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                var    pointValue = new PointF(tabValue, vPosition);
                var    sizeValue  = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                var    rectValue  = new RectangleF(pointValue, sizeValue);

                g.DrawString(param, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(value, fontValue, brushValue, rectValue, stringFormat);
                vPosition += fontValue.Height;
            }
        }
コード例 #38
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Directional_Indicators(SlotTypes slotType)
        {
            // General properties
            IndicatorName          = "Directional Indicators";
            PossibleSlots          = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart         = true;
            SeparatedChartMinValue = 0;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The ADI+ rises",
                "The ADI+ falls",
                "The ADI- rises",
                "The ADI- falls",
                "The ADI+ is higher than ADI-",
                "The ADI+ is lower than ADI-",
                "The ADI+ crosses the ADI- line upward",
                "The ADI+ crosses the ADI- line downward",
                "The ADI+ changes its direction upward",
                "The ADI+ changes its direction downward",
                "The ADI- changes its direction upward",
                "The ADI- changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Exponential;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The Moving Average method used for ADI smoothing.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = new string[] { "Bar range" };
            IndParam.ListParam[2].Index    = 0;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "ADI uses the current bar range.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Period";
            IndParam.NumParam[0].Value   = 14;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of ADI.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #39
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Standard_Deviation(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "Standard Deviation";
            PossibleSlots  = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The Standard Deviation rises",
                "The Standard Deviation falls",
                "The Standard Deviation is higher than the Level line",
                "The Standard Deviation is lower than the Level line",
                "The Standard Deviation crosses the Level line upward",
                "The Standard Deviation crosses the Level line downward",
                "The Standard Deviation changes its direction upward",
                "The Standard Deviation changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Simple;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The method of Moving Average used for the calculations.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[2].Index    = (int)BasePrice.Close;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The price the indicator is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Period";
            IndParam.NumParam[0].Value   = 20;
            IndParam.NumParam[0].Min     = 2;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of calculation.";

            IndParam.NumParam[1].Caption = "Level";
            IndParam.NumParam[1].Value   = 0;
            IndParam.NumParam[1].Min     = 0;
            IndParam.NumParam[1].Max     = 100;
            IndParam.NumParam[1].Point   = 4;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "A critical level (for the appropriate logic).";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #40
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;
        }
コード例 #41
0
 /// <summary>
 /// Calculates the indicator's components
 /// </summary>
 public override void Calculate(SlotTypes slotType)
 {
     return;
 }
コード例 #42
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.Additional;
            IndParam.IsAllowLTF    = false;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            if (SlotType == SlotTypes.Open)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Enter the market at the previous Bar Closing"
                }
            }
            ;
            else if (SlotType == SlotTypes.OpenFilter)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "The bar opens above the previous Bar Closing",
                    "The bar opens below the previous Bar Closing",
                    "The position opens above the previous Bar Closing",
                    "The position opens below the previous Bar Closing"
                }
            }
            ;
            else if (SlotType == SlotTypes.Close)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Exit the market at the previous Bar Closing"
                }
            }
            ;
            else if (SlotType == SlotTypes.CloseFilter)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "The bar closes above the previous Bar Closing",
                    "The bar closes below the previous Bar Closing"
                }
            }
            ;
            else
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Not Defined"
                }
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = new[] { "Previous Bar Closing" };
            IndParam.ListParam[1].Index    = 0;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "Used price from the indicator.";
        }
コード例 #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;
            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;
        }
コード例 #44
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            EntryFilterLongDescription  = ToString() + "; ";
            EntryFilterShortDescription = ToString() + "; ";
            ExitFilterLongDescription   = ToString() + "; ";
            ExitFilterShortDescription  = ToString() + "; ";

            switch (IndParam.ListParam[0].Text)
            {
            case "The ADI+ rises":
                EntryFilterLongDescription  += "the ADI+ rises";
                EntryFilterShortDescription += "the ADI+ falls";
                ExitFilterLongDescription   += "the ADI+ rises";
                ExitFilterShortDescription  += "the ADI+ falls";
                break;

            case "The ADI+ falls":
                EntryFilterLongDescription  += "the ADI+ falls";
                EntryFilterShortDescription += "the ADI+ rises";
                ExitFilterLongDescription   += "the ADI+ falls";
                ExitFilterShortDescription  += "the ADI+ rises";
                break;

            case "The ADI- rises":
                EntryFilterLongDescription  += "the ADI- rises";
                EntryFilterShortDescription += "the ADI- falls";
                ExitFilterLongDescription   += "the ADI- rises";
                ExitFilterShortDescription  += "the ADI- falls";
                break;

            case "The ADI- falls":
                EntryFilterLongDescription  += "the ADI- falls";
                EntryFilterShortDescription += "the ADI- rises";
                ExitFilterLongDescription   += "the ADI- falls";
                ExitFilterShortDescription  += "the ADI- rises";
                break;

            case "The ADI+ is higher than ADI-":
                EntryFilterLongDescription  += "the ADI+ is higher than the ADI-";
                EntryFilterShortDescription += "the ADI+ is lower than the ADI-";
                ExitFilterLongDescription   += "the ADI+ is higher than the ADI-";
                ExitFilterShortDescription  += "the ADI+ is lower than the ADI-";
                break;

            case "The ADI+ is lower than ADI-":
                EntryFilterLongDescription  += "the ADI+ is lower than the ADI-";
                EntryFilterShortDescription += "the ADI+ is higher than the ADI-";
                ExitFilterLongDescription   += "the ADI+ is lower than the ADI-";
                ExitFilterShortDescription  += "the ADI+ is higher than the ADI-";
                break;

            case "The ADI+ crosses the ADI- line upward":
                EntryFilterLongDescription  += "the ADI+ crosses the ADI- line upward";
                EntryFilterShortDescription += "the ADI+ crosses the ADI- line downward";
                ExitFilterLongDescription   += "the ADI+ crosses the ADI- line upward";
                ExitFilterShortDescription  += "the ADI+ crosses the ADI- line downward";
                break;

            case "The ADI+ crosses the ADI- line downward":
                EntryFilterLongDescription  += "the ADI+ crosses the ADI- line downward";
                EntryFilterShortDescription += "the ADI+ crosses the ADI- line upward";
                ExitFilterLongDescription   += "the ADI+ crosses the ADI- line downward";
                ExitFilterShortDescription  += "the ADI+ crosses the ADI- line upward";
                break;

            case "The ADI+ changes its direction upward":
                EntryFilterLongDescription  += "the ADI+ changes its direction upward";
                EntryFilterShortDescription += "the ADI+ changes its direction downward";
                ExitFilterLongDescription   += "the ADI+ changes its direction upward";
                ExitFilterShortDescription  += "the ADI+ changes its direction downward";
                break;

            case "The ADI+ changes its direction downward":
                EntryFilterLongDescription  += "the ADI+ changes its direction downward";
                EntryFilterShortDescription += "the ADI+ changes its direction upward";
                ExitFilterLongDescription   += "the ADI+ changes its direction downward";
                ExitFilterShortDescription  += "the ADI+ changes its direction upward";
                break;

            case "The ADI- changes its direction upward":
                EntryFilterLongDescription  += "the ADI- changes its direction upward";
                EntryFilterShortDescription += "the ADI- changes its direction downward";
                ExitFilterLongDescription   += "the ADI- changes its direction upward";
                ExitFilterShortDescription  += "the ADI- changes its direction downward";
                break;

            case "The ADI- changes its direction downward":
                EntryFilterLongDescription  += "the ADI- changes its direction downward";
                EntryFilterShortDescription += "the ADI- changes its direction upward";
                ExitFilterLongDescription   += "the ADI- changes its direction downward";
                ExitFilterShortDescription  += "the ADI- changes its direction upward";
                break;

            default:
                break;
            }

            return;
        }
コード例 #45
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Top_Bottom_Price(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Top Bottom Price";
            PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            if (slotType == SlotTypes.Open)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Enter long at the top price",
                    "Enter long at the bottom price"
                }
            }
            ;
            else if (slotType == SlotTypes.OpenFilter)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "The bar opens below the top price",
                    "The bar opens above the top price",
                    "The bar opens below the bottom price",
                    "The bar opens above the bottom price",
                    "The position opens below the top price",
                    "The position opens above the top price",
                    "The position opens below the bottom price",
                    "The position opens above the bottom price"
                }
            }
            ;
            else if (slotType == SlotTypes.Close)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Exit long at the top price",
                    "Exit long at the bottom price"
                }
            }
            ;
            else if (slotType == SlotTypes.CloseFilter)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "The bar closes below the top price",
                    "The bar closes above the top price",
                    "The bar closes below the bottom price",
                    "The bar closes above the bottom price"
                }
            }
            ;
            else
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Not Defined"
                }
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = new string[] { "High & Low" };
            IndParam.ListParam[1].Index    = 0;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "Used price from the indicator.";

            IndParam.ListParam[2].Caption  = "Base period";
            IndParam.ListParam[2].ItemList = new string[] { "Previous bar", "Previous day", "Previous week", "Previous month" };
            IndParam.ListParam[2].Index    = 1;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The period, the top/bottom prices are based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Vertical shift";
            IndParam.NumParam[0].Value   = 0;
            IndParam.NumParam[0].Min     = -2000;
            IndParam.NumParam[0].Max     = +2000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "A vertical shift above the top and below the bottom price.";

            return;
        }

        /// <summary>
        /// Checks if the period have been changed
        /// </summary>
        bool IsPeriodChanged(int iBar)
        {
            bool bIsPeriodChanged = false;

            switch (IndParam.ListParam[2].Index)
            {
            case 0:     // Previous bar
                bIsPeriodChanged = true;
                break;

            case 1:     // Previous day
                bIsPeriodChanged = Time[iBar].Day != Time[iBar - 1].Day;
                break;

            case 2:     // Previous week
                bIsPeriodChanged = Time[iBar].DayOfWeek <= DayOfWeek.Wednesday && Time[iBar - 1].DayOfWeek > DayOfWeek.Wednesday;
                break;

            case 3:     // Previous month
                bIsPeriodChanged = Time[iBar].Month != Time[iBar - 1].Month;
                break;

            default:
                break;
            }

            return(bIsPeriodChanged);
        }
コード例 #46
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;
        }
コード例 #47
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            switch (IndParam.ListParam[0].Text)
            {
            case "Enter long at the Upper Band":
                EntryPointLongDescription  = "at the Upper Band of " + ToString();
                EntryPointShortDescription = "at the Lower Band of " + ToString();
                break;

            case "Enter long at the Lower Band":
                EntryPointLongDescription  = "at the Lower Band of " + ToString();
                EntryPointShortDescription = "at the Upper Band of " + ToString();
                break;

            case "Exit long at the Upper Band":
                ExitPointLongDescription  = "at the Upper Band of " + ToString();
                ExitPointShortDescription = "at the Lower Band of " + ToString();
                break;

            case "Exit long at the Lower Band":
                ExitPointLongDescription  = "at the Lower Band of " + ToString();
                ExitPointShortDescription = "at the Upper Band of " + ToString();
                break;

            case "The bar opens below the Upper Band":
                EntryFilterLongDescription  = "the bar opens below the Upper Band of " + ToString();
                EntryFilterShortDescription = "the bar opens above the Lower Band of " + ToString();
                break;

            case "The bar opens above the Upper Band":
                EntryFilterLongDescription  = "the bar opens above the Upper Band of " + ToString();
                EntryFilterShortDescription = "the bar opens below the Lower Band of " + ToString();
                break;

            case "The bar opens below the Lower Band":
                EntryFilterLongDescription  = "the bar opens below the Lower Band of " + ToString();
                EntryFilterShortDescription = "the bar opens above the Upper Band of " + ToString();
                break;

            case "The bar opens above the Lower Band":
                EntryFilterLongDescription  = "the bar opens above the Lower Band of " + ToString();
                EntryFilterShortDescription = "the bar opens below the Upper Band of " + ToString();
                break;

            case "The position opens above the Upper Band":
                EntryFilterLongDescription  = "the position opening price is higher than the Upper Band of " + ToString();
                EntryFilterShortDescription = "the position opening price is lower than the Lower Band of " + ToString();
                break;

            case "The position opens below the Upper Band":
                EntryFilterLongDescription  = "the position opening price is lower than the Upper Band of " + ToString();
                EntryFilterShortDescription = "the position opening price is higher than the Lower Band of " + ToString();
                break;

            case "The position opens above the Lower Band":
                EntryFilterLongDescription  = "the position opening price is higher than the Lower Band of " + ToString();
                EntryFilterShortDescription = "the position opening price is lower than the Upper Band of " + ToString();
                break;

            case "The position opens below the Lower Band":
                EntryFilterLongDescription  = "the position opening price is lower than the Lower Band of " + ToString();
                EntryFilterShortDescription = "the position opening price is higher than the Upper Band of " + ToString();
                break;

            case "The bar opens below the Upper Band after opening above it":
                EntryFilterLongDescription  = "the bar opens below the Upper Band of " + ToString() + " after the previous bar has opened above it";
                EntryFilterShortDescription = "the bar opens above the Lower Band of " + ToString() + " after the previous bar has opened below it";
                break;

            case "The bar opens above the Upper Band after opening below it":
                EntryFilterLongDescription  = "the bar opens above the Upper Band of " + ToString() + " after the previous bar has opened below it";
                EntryFilterShortDescription = "the bar opens below the Lower Band of " + ToString() + " after the previous bar has opened above it";
                break;

            case "The bar opens below the Lower Band after opening above it":
                EntryFilterLongDescription  = "the bar opens below the Lower Band of " + ToString() + " after the previous bar has opened above it";
                EntryFilterShortDescription = "the bar opens above the Upper Band of " + ToString() + " after the previous bar has opened below it";
                break;

            case "The bar opens above the Lower Band after opening below it":
                EntryFilterLongDescription  = "the bar opens above the Lower Band of " + ToString() + " after the previous bar has opened below it";
                EntryFilterShortDescription = "the bar opens below the Upper Band of " + ToString() + " after the previous bar has opened above it";
                break;

            case "The bar closes below the Upper Band":
                ExitFilterLongDescription  = "the bar closes below the Upper Band of " + ToString();
                ExitFilterShortDescription = "the bar closes above the Lower Band of " + ToString();
                break;

            case "The bar closes above the Upper Band":
                ExitFilterLongDescription  = "the bar closes above the Upper Band of " + ToString();
                ExitFilterShortDescription = "the bar closes below the Lower Band of " + ToString();
                break;

            case "The bar closes below the Lower Band":
                ExitFilterLongDescription  = "the bar closes below the Lower Band of " + ToString();
                ExitFilterShortDescription = "the bar closes above the Upper Band of " + ToString();
                break;

            case "The bar closes above the Lower Band":
                ExitFilterLongDescription  = "the bar closes above the Lower Band of " + ToString();
                ExitFilterShortDescription = "the bar closes below the Upper Band of " + ToString();
                break;

            default:
                break;
            }

            return;
        }
コード例 #48
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            int iShift = (int)IndParam.NumParam[0].Value;

            string sUpperTrade;
            string sLowerTrade;

            if (iShift > 0)
            {
                sUpperTrade = iShift + " pips above the ";
                sLowerTrade = iShift + " pips below the ";
            }
            else if (iShift == 0)
            {
                if (IndParam.ListParam[0].Text == "Enter long at the top price" ||
                    IndParam.ListParam[0].Text == "Enter long at the bottom price" ||
                    IndParam.ListParam[0].Text == "Exit long at the top price" ||
                    IndParam.ListParam[0].Text == "Exit long at the bottom price")
                {
                    sUpperTrade = "at the ";
                    sLowerTrade = "at the ";
                }
                else
                {
                    sUpperTrade = "the ";
                    sLowerTrade = "the ";
                }
            }
            else
            {
                sUpperTrade = -iShift + " pips below the ";
                sLowerTrade = -iShift + " pips above the ";
            }

            string sPeriod = "of the " + IndParam.ListParam[2].Text.ToLower();

            switch (IndParam.ListParam[0].Text)
            {
            case "Enter long at the top price":
                EntryPointLongDescription  = sUpperTrade + "top price " + sPeriod;
                EntryPointShortDescription = sLowerTrade + "bottom price " + sPeriod;
                break;

            case "Enter long at the bottom price":
                EntryPointLongDescription  = sLowerTrade + "bottom price " + sPeriod;
                EntryPointShortDescription = sUpperTrade + "top price " + sPeriod;
                break;

            case "Exit long at the top price":
                ExitPointLongDescription  = sUpperTrade + "top price " + sPeriod;
                ExitPointShortDescription = sLowerTrade + "bottom price " + sPeriod;
                break;

            case "Exit long at the bottom price":
                ExitPointLongDescription  = sLowerTrade + "bottom price " + sPeriod;
                ExitPointShortDescription = sUpperTrade + "top price " + sPeriod;
                break;

            case "The bar opens below the top price":
                EntryFilterLongDescription  = "the bar opens lower than " + sUpperTrade + "top price " + sPeriod;
                EntryFilterShortDescription = "the bar opens higher than " + sLowerTrade + "bottom price " + sPeriod;
                break;

            case "The bar opens above the top price":
                EntryFilterLongDescription  = "the bar opens higher than " + sUpperTrade + "top price " + sPeriod;
                EntryFilterShortDescription = "the bar opens lower than " + sLowerTrade + "bottom price " + sPeriod;
                break;

            case "The bar opens below the bottom price":
                EntryFilterLongDescription  = "the bar opens lower than " + sLowerTrade + "bottom price " + sPeriod;
                EntryFilterShortDescription = "the bar opens higher than " + sUpperTrade + "top price " + sPeriod;
                break;

            case "The bar opens above the bottom price":
                EntryFilterLongDescription  = "the bar opens higher than " + sLowerTrade + "bottom price " + sPeriod;
                EntryFilterShortDescription = "the bar opens lower than " + sUpperTrade + "top price " + sPeriod;
                break;

            case "The position opens below the top price":
                EntryFilterLongDescription  = "the position opens lower than " + sUpperTrade + "top price " + sPeriod;
                EntryFilterShortDescription = "the position opens higher than " + sLowerTrade + "bottom price " + sPeriod;
                break;

            case "The position opens above the top price":
                EntryFilterLongDescription  = "the position opens higher than " + sUpperTrade + "top price " + sPeriod;
                EntryFilterShortDescription = "the position opens lower than " + sLowerTrade + "bottom price " + sPeriod;
                break;

            case "The position opens below the bottom price":
                EntryFilterLongDescription  = "the position opens lower than " + sLowerTrade + "bottom price " + sPeriod;
                EntryFilterShortDescription = "the position opens higher than " + sUpperTrade + "top price " + sPeriod;
                break;

            case "The position opens above the bottom price":
                EntryFilterLongDescription  = "the position opens higher than " + sLowerTrade + "bottom price " + sPeriod;
                EntryFilterShortDescription = "the position opens lower than " + sUpperTrade + "top price " + sPeriod;
                break;

            case "The bar closes below the top price":
                ExitFilterLongDescription  = "the bar closes lower than " + sUpperTrade + "top price " + sPeriod;
                ExitFilterShortDescription = "the bar closes higher than " + sLowerTrade + "bottom price " + sPeriod;
                break;

            case "The bar closes above the top price":
                ExitFilterLongDescription  = "the bar closes higher than " + sUpperTrade + "top price " + sPeriod;
                ExitFilterShortDescription = "the bar closes lower than " + sLowerTrade + "bottom price " + sPeriod;
                break;

            case "The bar closes below the bottom price":
                ExitFilterLongDescription  = "the bar closes lower than " + sLowerTrade + "bottom price " + sPeriod;
                ExitFilterShortDescription = "the bar closes higher than " + sUpperTrade + "top price " + sPeriod;
                break;

            case "The bar closes above the bottom price":
                ExitFilterLongDescription  = "the bar closes higher than " + sLowerTrade + "bottom price " + sPeriod;
                ExitFilterShortDescription = "the bar closes lower than " + sUpperTrade + "top price " + sPeriod;
                break;

            default:
                break;
            }

            return;
        }
コード例 #49
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 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;
        }
コード例 #50
0
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            double dShift    = IndParam.NumParam[0].Value * Point;
            int    iFirstBar = 1;

            // Calculation
            double[] adTopPrice    = new double[Bars];
            double[] adBottomPrice = new double[Bars];

            adTopPrice[0]    = 0;
            adBottomPrice[0] = 0;

            double dTop    = double.MinValue;
            double dBottom = double.MaxValue;

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                if (High[iBar - 1] > dTop)
                {
                    dTop = High[iBar - 1];
                }
                if (Low[iBar - 1] < dBottom)
                {
                    dBottom = Low[iBar - 1];
                }

                if (IsPeriodChanged(iBar))
                {
                    adTopPrice[iBar]    = dTop;
                    adBottomPrice[iBar] = dBottom;
                    dTop    = double.MinValue;
                    dBottom = double.MaxValue;
                }
                else
                {
                    adTopPrice[iBar]    = adTopPrice[iBar - 1];
                    adBottomPrice[iBar] = adBottomPrice[iBar - 1];
                }
            }

            double[] adUpperBand = new double[Bars];
            double[] adLowerBand = new double[Bars];
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adUpperBand[iBar] = adTopPrice[iBar] + dShift;
                adLowerBand[iBar] = adBottomPrice[iBar] - dShift;
            }

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

            Component[0]            = new IndicatorComp();
            Component[0].CompName   = "Top price";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Level;
            Component[0].ChartColor = Color.DarkGreen;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adTopPrice;

            Component[1]            = new IndicatorComp();
            Component[1].CompName   = "Bottom price";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Level;
            Component[1].ChartColor = Color.DarkRed;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adBottomPrice;

            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].CompName = "Long position entry price";
                Component[2].DataType = IndComponentType.OpenLongPrice;
                Component[3].CompName = "Short position entry price";
                Component[3].DataType = IndComponentType.OpenShortPrice;
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[2].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[3].CompName = "Is short entry allowed";
                Component[3].DataType = IndComponentType.AllowOpenShort;
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[2].CompName = "Long position closing price";
                Component[2].DataType = IndComponentType.CloseLongPrice;
                Component[3].CompName = "Short position closing price";
                Component[3].DataType = IndComponentType.CloseShortPrice;
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[2].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[3].CompName = "Close out short position";
                Component[3].DataType = IndComponentType.ForceCloseShort;
            }

            switch (IndParam.ListParam[0].Text)
            {
            case "Enter long at the top price":
            case "Exit long at the top price":
                Component[2].Value = adUpperBand;
                Component[3].Value = adLowerBand;
                break;

            case "Enter long at the bottom price":
            case "Exit long at the bottom price":
                Component[2].Value = adLowerBand;
                Component[3].Value = adUpperBand;
                break;

            case "The bar opens below the top price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band);
                break;

            case "The bar opens above the top price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band);
                break;

            case "The bar opens below the bottom price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band);
                break;

            case "The bar opens above the bottom price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band);
                break;

            case "The bar closes below the top price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band);
                break;

            case "The bar closes above the top price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band);
                break;

            case "The bar closes below the bottom price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band);
                break;

            case "The bar closes above the bottom price":
                BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band);
                break;

            case "The position opens above the top price":
                Component[0].DataType           = IndComponentType.Other;
                Component[1].DataType           = IndComponentType.Other;
                Component[2].CompName           = "Shifted top price";
                Component[2].DataType           = IndComponentType.OpenLongPrice;
                Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                Component[3].CompName           = "Shifted bottom price";
                Component[3].DataType           = IndComponentType.OpenShortPrice;
                Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                Component[2].Value = adUpperBand;
                Component[3].Value = adLowerBand;
                break;

            case "The position opens below the top price":
                Component[0].DataType           = IndComponentType.Other;
                Component[1].DataType           = IndComponentType.Other;
                Component[2].CompName           = "Shifted top price";
                Component[2].DataType           = IndComponentType.OpenLongPrice;
                Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
                Component[3].CompName           = "Shifted bottom price";
                Component[3].DataType           = IndComponentType.OpenShortPrice;
                Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
                Component[2].Value = adUpperBand;
                Component[3].Value = adLowerBand;
                break;

            case "The position opens above the bottom price":
                Component[0].DataType           = IndComponentType.Other;
                Component[1].DataType           = IndComponentType.Other;
                Component[2].CompName           = "Shifted bottom price";
                Component[2].DataType           = IndComponentType.OpenLongPrice;
                Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
                Component[3].CompName           = "Shifted top price";
                Component[3].DataType           = IndComponentType.OpenShortPrice;
                Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower;
                Component[2].Value = adLowerBand;
                Component[3].Value = adUpperBand;
                break;

            case "The position opens below the bottom price":
                Component[0].DataType           = IndComponentType.Other;
                Component[1].DataType           = IndComponentType.Other;
                Component[2].CompName           = "Shifted bottom price";
                Component[2].DataType           = IndComponentType.OpenLongPrice;
                Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
                Component[3].CompName           = "Shifted top price";
                Component[3].DataType           = IndComponentType.OpenShortPrice;
                Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
                Component[2].Value = adLowerBand;
                Component[3].Value = adUpperBand;
                break;

            default:
                break;
            }

            return;
        }
コード例 #51
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            if (SlotType == SlotTypes.Open)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Enter long at the hourly high",
                    "Enter long at the hourly low"
                }
            }
            ;
            else if (SlotType == SlotTypes.OpenFilter)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "The position opens above the hourly high",
                    "The position opens below the hourly high",
                    "The position opens above the hourly low",
                    "The position opens below the hourly low"
                }
            }
            ;
            else if (SlotType == SlotTypes.Close)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Exit long at the hourly high",
                    "Exit long at the hourly low"
                }
            }
            ;
            else if (SlotType == SlotTypes.CloseFilter)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "The bar closes above the hourly high",
                    "The bar closes below the hourly high",
                    "The bar closes above the hourly low",
                    "The bar closes below the hourly low"
                }
            }
            ;
            else
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Not Defined"
                }
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = new[] { "High and Low" };
            IndParam.ListParam[1].Index    = 0;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "Used price from the indicator.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Start hour (incl.)";
            IndParam.NumParam[0].Value   = 0;
            IndParam.NumParam[0].Min     = 0;
            IndParam.NumParam[0].Max     = 24;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The starting hour of the period.";

            IndParam.NumParam[1].Caption = "Start minutes (incl.)";
            IndParam.NumParam[1].Value   = 0;
            IndParam.NumParam[1].Min     = 0;
            IndParam.NumParam[1].Max     = 59;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "The starting minutes of the period.";

            IndParam.NumParam[2].Caption = "End hour (excl.)";
            IndParam.NumParam[2].Value   = 24;
            IndParam.NumParam[2].Min     = 0;
            IndParam.NumParam[2].Max     = 24;
            IndParam.NumParam[2].Enabled = true;
            IndParam.NumParam[2].ToolTip = "The ending hour of the period.";

            IndParam.NumParam[3].Caption = "End minutes (excl.)";
            IndParam.NumParam[3].Value   = 0;
            IndParam.NumParam[3].Min     = 0;
            IndParam.NumParam[3].Max     = 59;
            IndParam.NumParam[3].Enabled = true;
            IndParam.NumParam[3].ToolTip = "The ending minutes of the period.";

            IndParam.NumParam[4].Caption = "Vertical shift";
            IndParam.NumParam[4].Value   = 0;
            IndParam.NumParam[4].Min     = -2000;
            IndParam.NumParam[4].Max     = +2000;
            IndParam.NumParam[4].Enabled = true;
            IndParam.NumParam[4].ToolTip = "A vertical shift above the high and below the low price.";
        }
コード例 #52
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type.
        /// </summary>
        public Keltner_Channel(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "Keltner Channel";
            PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";

            if (slotType == SlotTypes.Open)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Enter long at the Upper Band",
                    "Enter long at the Lower Band"
                }
            }
            ;

            else if (slotType == SlotTypes.OpenFilter)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "The bar opens below the Upper Band",
                    "The bar opens above the Upper Band",
                    "The bar opens below the Lower Band",
                    "The bar opens above the Lower Band",
                    "The position opens below the Upper Band",
                    "The position opens above the Upper Band",
                    "The position opens below the Lower Band",
                    "The position opens above the Lower Band",
                    "The bar opens below the Upper Band after opening above it",
                    "The bar opens above the Upper Band after opening below it",
                    "The bar opens below the Lower Band after opening above it",
                    "The bar opens above the Lower Band after opening below it",
                }
            }
            ;

            else if (slotType == SlotTypes.Close)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Exit long at the Upper Band",
                    "Exit long at the Lower Band"
                }
            }
            ;

            else if (slotType == SlotTypes.CloseFilter)
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "The bar closes below the Upper Band",
                    "The bar closes above the Upper Band",
                    "The bar closes below the Lower Band",
                    "The bar closes above the Lower Band"
                }
            }
            ;

            else
            {
                IndParam.ListParam[0].ItemList = new string[]
                {
                    "Not Defined"
                }
            };

            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Exponential;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The method of smoothing of central Moving Average.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = new string[] { "Close" };
            IndParam.ListParam[2].Index    = 0;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The price the central Moving Average is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "MA period";
            IndParam.NumParam[0].Value   = 20;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The central Moving Average period.";

            IndParam.NumParam[1].Caption = "ATR period";
            IndParam.NumParam[1].Value   = 10;
            IndParam.NumParam[1].Min     = 1;
            IndParam.NumParam[1].Max     = 50;
            IndParam.NumParam[1].Point   = 0;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "Average True Range Period.";

            IndParam.NumParam[3].Caption = "ATR multiplier";
            IndParam.NumParam[3].Value   = 2;
            IndParam.NumParam[3].Min     = 1;
            IndParam.NumParam[3].Max     = 10;
            IndParam.NumParam[3].Point   = 0;
            IndParam.NumParam[3].Enabled = true;
            IndParam.NumParam[3].ToolTip = "Average True Range Multiplier.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }
コード例 #53
0
 public virtual void Initialize(SlotTypes slot)
 {
 }
コード例 #54
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // Setting up the indicator parameters
            IndParam.IndicatorType = TypeOfIndicator.Additional;
            IndParam.IsAllowLTF    = false;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption = "Logic";
            if (SlotType == SlotTypes.Open)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Enter long at the top price",
                    "Enter long at the bottom price"
                }
            }
            ;
            else if (SlotType == SlotTypes.OpenFilter)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "The bar opens below the top price",
                    "The bar opens above the top price",
                    "The bar opens below the bottom price",
                    "The bar opens above the bottom price",
                    "The position opens below the top price",
                    "The position opens above the top price",
                    "The position opens below the bottom price",
                    "The position opens above the bottom price"
                }
            }
            ;
            else if (SlotType == SlotTypes.Close)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Exit long at the top price",
                    "Exit long at the bottom price"
                }
            }
            ;
            else if (SlotType == SlotTypes.CloseFilter)
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "The bar closes below the top price",
                    "The bar closes above the top price",
                    "The bar closes below the bottom price",
                    "The bar closes above the bottom price"
                }
            }
            ;
            else
            {
                IndParam.ListParam[0].ItemList = new[]
                {
                    "Not Defined"
                }
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Base price";
            IndParam.ListParam[1].ItemList = new[] { "High & Low" };
            IndParam.ListParam[1].Index    = 0;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "Used price from the indicator.";

            IndParam.ListParam[2].Caption  = "Base period";
            IndParam.ListParam[2].ItemList = new[] { "Previous bar", "Previous day", "Previous week", "Previous month" };
            IndParam.ListParam[2].Index    = 1;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The period, the top/bottom prices are based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Vertical shift";
            IndParam.NumParam[0].Value   = 0;
            IndParam.NumParam[0].Min     = -2000;
            IndParam.NumParam[0].Max     = +2000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "A vertical shift above the top and below the bottom price.";
        }
コード例 #55
0
        public override void Initialize(SlotTypes slotType)
        {
            SlotType = slotType;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new[]
            {
                "Momentum rises",
                "Momentum falls",
                "Momentum is higher than the Level line",
                "Momentum is lower than the Level line",
                "Momentum crosses the Level line upward",
                "Momentum crosses the Level line downward",
                "Momentum changes its direction upward",
                "Momentum changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Simple;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The Moving Average method used for smoothing Momentum value.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[2].Index    = (int)BasePrice.Close;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The price Momentum is based on.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Period";
            IndParam.NumParam[0].Value   = 14;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of Momentum.";

            IndParam.NumParam[1].Caption = "Additional smoothing";
            IndParam.NumParam[1].Value   = 0;
            IndParam.NumParam[1].Min     = 0;
            IndParam.NumParam[1].Max     = 200;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "The period of additional smoothing.";

            IndParam.NumParam[2].Caption = "Level";
            IndParam.NumParam[2].Value   = 0;
            IndParam.NumParam[2].Min     = -100;
            IndParam.NumParam[2].Max     = 100;
            IndParam.NumParam[2].Point   = 4;
            IndParam.NumParam[2].Enabled = true;
            IndParam.NumParam[2].ToolTip = "A critical level (for the appropriate logic).";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
        }
コード例 #56
0
        /// <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;
        }
コード例 #57
0
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            string sLevelLong  = IndParam.NumParam[1].ValueToString;
            string sLevelShort = sLevelLong;

            EntryFilterLongDescription  = "the " + ToString() + " ";
            EntryFilterShortDescription = "the " + ToString() + " ";
            ExitFilterLongDescription   = "the " + ToString() + " ";
            ExitFilterShortDescription  = "the " + ToString() + " ";

            switch (IndParam.ListParam[0].Text)
            {
            case "The Standard Deviation rises":
                EntryFilterLongDescription  += "rises";
                EntryFilterShortDescription += "rises";
                ExitFilterLongDescription   += "rises";
                ExitFilterShortDescription  += "rises";
                break;

            case "The Standard Deviation falls":
                EntryFilterLongDescription  += "falls";
                EntryFilterShortDescription += "falls";
                ExitFilterLongDescription   += "falls";
                ExitFilterShortDescription  += "falls";
                break;

            case "The Standard Deviation is higher than the Level line":
                EntryFilterLongDescription  += "is higher than the Level " + sLevelLong;
                EntryFilterShortDescription += "is higher than the Level " + sLevelShort;
                ExitFilterLongDescription   += "is higher than the Level " + sLevelLong;
                ExitFilterShortDescription  += "is higher than the Level " + sLevelShort;
                break;

            case "The Standard Deviation is lower than the Level line":
                EntryFilterLongDescription  += "is lower than the Level " + sLevelLong;
                EntryFilterShortDescription += "is lower than the Level " + sLevelShort;
                ExitFilterLongDescription   += "is lower than the Level " + sLevelLong;
                ExitFilterShortDescription  += "is lower than the Level " + sLevelShort;
                break;

            case "The Standard Deviation crosses the Level line upward":
                EntryFilterLongDescription  += "crosses the Level " + sLevelLong + " upward";
                EntryFilterShortDescription += "crosses the Level " + sLevelShort + " upward";
                ExitFilterLongDescription   += "crosses the Level " + sLevelLong + " upward";
                ExitFilterShortDescription  += "crosses the Level " + sLevelShort + " upward";
                break;

            case "The Standard Deviation crosses the Level line downward":
                EntryFilterLongDescription  += "crosses the Level " + sLevelLong + " downward";
                EntryFilterShortDescription += "crosses the Level " + sLevelShort + " downward";
                ExitFilterLongDescription   += "crosses the Level " + sLevelLong + " downward";
                ExitFilterShortDescription  += "crosses the Level " + sLevelShort + " downward";
                break;

            case "The Standard Deviation changes its direction upward":
                EntryFilterLongDescription  += "changes its direction upward";
                EntryFilterShortDescription += "changes its direction upward";
                ExitFilterLongDescription   += "changes its direction upward";
                ExitFilterShortDescription  += "changes its direction upward";
                break;

            case "The Standard Deviation changes its direction downward":
                EntryFilterLongDescription  += "changes its direction downward";
                EntryFilterShortDescription += "changes its direction downward";
                ExitFilterLongDescription   += "changes its direction downward";
                ExitFilterShortDescription  += "changes its direction downward";
                break;

            default:
                break;
            }

            return;
        }
コード例 #58
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Oscillator_of_MACD(SlotTypes slotType)
        {
            // General properties
            IndicatorName  = "Oscillator of MACD";
            PossibleSlots  = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
            SeparatedChart = true;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.OscillatorOfIndicators;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "The Oscillator of MACD rises",
                "The Oscillator of MACD falls",
                "The Oscillator of MACD is higher than the zero line",
                "The Oscillator of MACD is lower than the zero line",
                "The Oscillator of MACD crosses the zero line upward",
                "The Oscillator of MACD crosses the zero line downward",
                "The Oscillator of MACD changes its direction upward",
                "The Oscillator of MACD changes its direction downward"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the oscillator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Exponential;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The Moving Average method used for smoothing the MACD value.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
            IndParam.ListParam[2].Index    = (int)BasePrice.Close;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "The price the indicator is based on.";

            IndParam.ListParam[3].Caption  = "Signal line method";
            IndParam.ListParam[3].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[3].Index    = (int)MAMethod.Exponential;
            IndParam.ListParam[3].Text     = IndParam.ListParam[3].ItemList[IndParam.ListParam[3].Index];
            IndParam.ListParam[3].Enabled  = true;
            IndParam.ListParam[3].ToolTip  = "The smoothing method of the signal line.";

            IndParam.ListParam[4].Caption  = "What to compare";
            IndParam.ListParam[4].ItemList = new string[] { "Histogram 1 to Histogram 2", "Signal line 1 to Signal line 2", "MACD line 1 to MACD line 2" };
            IndParam.ListParam[4].Index    = 0;
            IndParam.ListParam[4].Text     = IndParam.ListParam[4].ItemList[IndParam.ListParam[4].Index];
            IndParam.ListParam[4].Enabled  = true;
            IndParam.ListParam[4].ToolTip  = "The smoothing method of the signal line.";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "MACD1 slow MA";
            IndParam.NumParam[0].Value   = 26;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of first MACD slow line.";

            IndParam.NumParam[1].Caption = "MACD2 slow MA";
            IndParam.NumParam[1].Value   = 32;
            IndParam.NumParam[1].Min     = 1;
            IndParam.NumParam[1].Max     = 200;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "The period of second MACD slow line.";

            IndParam.NumParam[2].Caption = "MACD1 fast MA";
            IndParam.NumParam[2].Value   = 12;
            IndParam.NumParam[2].Min     = 1;
            IndParam.NumParam[2].Max     = 200;
            IndParam.NumParam[2].Enabled = true;
            IndParam.NumParam[2].ToolTip = "The period of first MACD fast line.";

            IndParam.NumParam[3].Caption = "MACD2 fast MA";
            IndParam.NumParam[3].Value   = 21;
            IndParam.NumParam[3].Min     = 1;
            IndParam.NumParam[3].Max     = 200;
            IndParam.NumParam[3].Enabled = true;
            IndParam.NumParam[3].ToolTip = "The period of second MACD fast line.";

            IndParam.NumParam[4].Caption = "MACD1 Signal line";
            IndParam.NumParam[4].Value   = 9;
            IndParam.NumParam[4].Min     = 1;
            IndParam.NumParam[4].Max     = 200;
            IndParam.NumParam[4].Enabled = true;
            IndParam.NumParam[4].ToolTip = "The period of Signal line.";

            IndParam.NumParam[5].Caption = "MACD2 Signal line";
            IndParam.NumParam[5].Value   = 13;
            IndParam.NumParam[5].Min     = 1;
            IndParam.NumParam[5].Max     = 200;
            IndParam.NumParam[5].Enabled = true;
            IndParam.NumParam[5].ToolTip = "The period of Signal line.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            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;
            BasePrice price    = (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
            double[] adPrice = Price(price);
            double[] adMA    = MovingAverage(iPeriod, 0, maMethod, adPrice);
            double[] adSTDV  = new double[Bars];

            int iFirstBar = iPeriod + 1;

            for (int iBar = iPeriod; iBar < Bars; iBar++)
            {
                double dSum = 0;
                for (int index = 0; index < iPeriod; index++)
                {
                    double fDelta = (adPrice[iBar - index] - adMA[iBar]);
                    dSum += fDelta * fDelta;
                }
                adSTDV[iBar] = Math.Sqrt(dSum / iPeriod);
            }

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

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

            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 Standard Deviation rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

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

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

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

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

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

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

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

            default:
                break;
            }

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

            return;
        }
コード例 #60
0
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public ATR_Stop(SlotTypes slotType)
        {
            // General properties
            IndicatorName = "ATR Stop";
            PossibleSlots = SlotTypes.Close;

            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;

            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Exit at the ATR Stop level"
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";

            IndParam.ListParam[1].Caption  = "Smoothing method";
            IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
            IndParam.ListParam[1].Index    = (int)MAMethod.Simple;
            IndParam.ListParam[1].Text     = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
            IndParam.ListParam[1].Enabled  = true;
            IndParam.ListParam[1].ToolTip  = "The Moving Average method used for smoothing the ATR.";

            IndParam.ListParam[2].Caption  = "Base price";
            IndParam.ListParam[2].ItemList = new string[] { "Bar range" };
            IndParam.ListParam[2].Index    = 0;
            IndParam.ListParam[2].Text     = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
            IndParam.ListParam[2].Enabled  = true;
            IndParam.ListParam[2].ToolTip  = "ATR uses the range of the current bar";

            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Smoothing period";
            IndParam.NumParam[0].Value   = 14;
            IndParam.NumParam[0].Min     = 1;
            IndParam.NumParam[0].Max     = 200;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The period of ATR smoothing.";

            IndParam.NumParam[1].Caption = "Multiplier";
            IndParam.NumParam[1].Value   = 2;
            IndParam.NumParam[1].Min     = 1;
            IndParam.NumParam[1].Max     = 10;
            IndParam.NumParam[1].Point   = 2;
            IndParam.NumParam[1].Enabled = true;
            IndParam.NumParam[1].ToolTip = "Determines the stop level.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";

            return;
        }