Forex_Strategy_Builder.Indicator_Tester.CustomIndicatorThoroughTest C# (CSharp) Метод

CustomIndicatorThoroughTest() публичный статический Метод

Performs thorough indicator test.
public static CustomIndicatorThoroughTest ( string sIndicatorName, string &sErrorList ) : bool
sIndicatorName string The indicator name.
sErrorList string
Результат bool
        public static bool CustomIndicatorThoroughTest(string sIndicatorName, out string sErrorList)
        {
            bool bIsOk = true;

            StringBuilder sb = new StringBuilder();

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

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

                Indicator indicator = Indicator_Store.ConstructIndicator(sIndicatorName, 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);
                    bIsOk = 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);
                    bIsOk = 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 + "'.");
                                    bIsOk = 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 + "'.");
                                    bIsOk = 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 + "'.");
                                    bIsOk = 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 + "'.");
                                    bIsOk = 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.");
                                    bIsOk = false;
                                    break;
                                }
                        }
                    }
                }
                catch (System.Exception exc)
                {
                    sb.AppendLine("\tError when checking the indicator's components. " + exc.Message);
                    bIsOk = false;
                    break;
                }

            }

            if (bIsOk)
                sErrorList = string.Empty;
            else
                sErrorList = sb.ToString();

            return bIsOk;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Does the job
        /// </summary>
        static void DoWorkTestCustomIndicators(object sender, DoWorkEventArgs e)
        {
            bool isErrors = false;

            StringBuilder errorReport = new StringBuilder();

            errorReport.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>");

            StringBuilder okReport = new StringBuilder();

            okReport.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>");
            okReport.AppendLine("<p>");

            foreach (string indicatorName in Indicator_Store.CustomIndicatorNames)
            {
                string errorList;
                if (!Indicator_Tester.CustomIndicatorThoroughTest(indicatorName, out errorList))
                {
                    isErrors = true;
                    errorReport.AppendLine("<h2>" + indicatorName + "</h2>");
                    string error = errorList.Replace(Environment.NewLine, "</br>");
                    error = error.Replace("\t", "&nbsp; &nbsp; &nbsp;");
                    errorReport.AppendLine("<p>" + error + "</p>");
                }
                else
                {
                    okReport.AppendLine(indicatorName + " - OK" + "<br />");
                }
            }

            okReport.AppendLine("</p>");

            CustomIndicatorsTestResult result = new CustomIndicatorsTestResult();

            result.IsErrors    = isErrors;
            result.ErrorReport = errorReport.ToString();
            result.OKReport    = okReport.ToString();

            e.Result = (object)result;

            return;
        }