Forex_Strategy_Builder.Indicator.TestPossibleSlot C# (CSharp) Method

TestPossibleSlot() public method

Tests if this is one of the possible slots.
public TestPossibleSlot ( SlotTypes slotType ) : bool
slotType SlotTypes The slot we test.
return bool
        public bool TestPossibleSlot(SlotTypes slotType)
        {
            if ((slotType & possibleSlots) == SlotTypes.Open)
                return true;

            if ((slotType & possibleSlots) == SlotTypes.OpenFilter)
                return true;

            if ((slotType & possibleSlots) == SlotTypes.Close)
                return true;

            if ((slotType & possibleSlots) == SlotTypes.CloseFilter)
                return true;

            return false;
        }

Usage Example

        /// <summary>
        /// Performs thorough indicator test.
        /// </summary>
        /// <param name="indicatorName">The indicator name.</param>
        /// <returns>True, if the test succeed.</returns>
        public static bool CustomIndicatorThoroughTest(string indicatorName, out string errorsList)
        {
            bool isOk = true;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("ERROR: Indicator test failed for the '" + indicatorName + "' indicator.");

            foreach (SlotTypes slotType in  Enum.GetValues(typeof(SlotTypes)))
            {
                if (slotType == SlotTypes.NotDefined)
                {
                    continue;
                }

                Indicator indicator = Indicator_Store.ConstructIndicator(indicatorName, slotType);

                if (!indicator.TestPossibleSlot(slotType))
                {
                    continue;
                }

                foreach (NumericParam numParam in indicator.IndParam.NumParam)
                {
                    if (numParam.Enabled)
                    {
                        numParam.Value = numParam.Min;
                    }
                }

                try
                {
                    indicator.Calculate(slotType);
                }
                catch (System.Exception exc)
                {
                    sb.AppendLine("\tError when calculating with NumParams set to their minimal values. " + exc.Message);
                    isOk = false;
                    break;
                }

                foreach (NumericParam numParam in indicator.IndParam.NumParam)
                {
                    if (numParam.Enabled)
                    {
                        numParam.Value = numParam.Max;
                    }
                }

                try
                {
                    indicator.Calculate(slotType);
                }
                catch (System.Exception exc)
                {
                    sb.AppendLine("\tError when calculating with NumParams set to their maximal values. " + exc.Message);
                    isOk = false;
                    break;
                }

                try
                {
                    foreach (IndicatorComp component in indicator.Component)
                    {
                        switch (slotType)
                        {
                        case SlotTypes.Open:
                            if (component.DataType == IndComponentType.AllowOpenLong ||
                                component.DataType == IndComponentType.AllowOpenShort ||
                                component.DataType == IndComponentType.CloseLongPrice ||
                                component.DataType == IndComponentType.ClosePrice ||
                                component.DataType == IndComponentType.CloseShortPrice ||
                                component.DataType == IndComponentType.ForceClose ||
                                component.DataType == IndComponentType.ForceCloseLong ||
                                component.DataType == IndComponentType.ForceCloseShort ||
                                component.DataType == IndComponentType.NotDefined)
                            {
                                sb.AppendLine("\tProbably wrong component type when SlotType is 'SlotTypes.Open' - '" + component.CompName + "' of type '" + component.DataType + "'.");
                                isOk = false;
                            }
                            break;

                        case SlotTypes.OpenFilter:
                            if (component.DataType == IndComponentType.OpenClosePrice ||
                                component.DataType == IndComponentType.OpenLongPrice ||
                                component.DataType == IndComponentType.OpenPrice ||
                                component.DataType == IndComponentType.OpenShortPrice ||
                                component.DataType == IndComponentType.CloseLongPrice ||
                                component.DataType == IndComponentType.ClosePrice ||
                                component.DataType == IndComponentType.CloseShortPrice ||
                                component.DataType == IndComponentType.ForceClose ||
                                component.DataType == IndComponentType.ForceCloseLong ||
                                component.DataType == IndComponentType.ForceCloseShort ||
                                component.DataType == IndComponentType.NotDefined)
                            {
                                sb.AppendLine("\tProbably wrong component type when SlotType is 'SlotTypes.OpenFilter' - '" + component.CompName + "' of type '" + component.DataType + "'.");
                                isOk = false;
                            }
                            break;

                        case SlotTypes.Close:
                            if (component.DataType == IndComponentType.AllowOpenLong ||
                                component.DataType == IndComponentType.AllowOpenShort ||
                                component.DataType == IndComponentType.OpenLongPrice ||
                                component.DataType == IndComponentType.OpenPrice ||
                                component.DataType == IndComponentType.OpenShortPrice ||
                                component.DataType == IndComponentType.ForceClose ||
                                component.DataType == IndComponentType.ForceCloseLong ||
                                component.DataType == IndComponentType.ForceCloseShort ||
                                component.DataType == IndComponentType.NotDefined)
                            {
                                sb.AppendLine("\tProbably wrong component type when SlotType is 'SlotTypes.Close' - '" + component.CompName + "' of type '" + component.DataType + "'.");
                                isOk = false;
                            }
                            break;

                        case SlotTypes.CloseFilter:
                            if (component.DataType == IndComponentType.AllowOpenLong ||
                                component.DataType == IndComponentType.AllowOpenShort ||
                                component.DataType == IndComponentType.OpenLongPrice ||
                                component.DataType == IndComponentType.OpenPrice ||
                                component.DataType == IndComponentType.OpenShortPrice ||
                                component.DataType == IndComponentType.CloseLongPrice ||
                                component.DataType == IndComponentType.ClosePrice ||
                                component.DataType == IndComponentType.CloseShortPrice ||
                                component.DataType == IndComponentType.NotDefined)
                            {
                                sb.AppendLine("\tProbably wrong component type when SlotType is 'SlotTypes.CloseFilter' - '" + component.CompName + "' of type '" + component.DataType + "'.");
                                isOk = false;
                            }
                            break;

                        default:
                            break;
                        }
                        if (component.DataType == IndComponentType.AllowOpenLong ||
                            component.DataType == IndComponentType.AllowOpenShort ||
                            component.DataType == IndComponentType.ForceClose ||
                            component.DataType == IndComponentType.ForceCloseLong ||
                            component.DataType == IndComponentType.ForceCloseShort)
                        {
                            foreach (double value in component.Value)
                            {
                                if (value != 0 && value != 1)
                                {
                                    sb.AppendLine("\tWrong component values. The values of '" + component.CompName + "' must be 0 or 1.");
                                    isOk = false;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    sb.AppendLine("\tError when checking the indicator's components. " + exc.Message);
                    isOk = false;
                    break;
                }
            }

            errorsList = isOk ? string.Empty : sb.ToString();

            return(isOk);
        }
All Usage Examples Of Forex_Strategy_Builder.Indicator::TestPossibleSlot