Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            DataLoader      dataLoader = new DataLoader();
            IndicatorTester tester     = new IndicatorTester();

            dataLoader.UserFilesFolder = @"C:\Program Files\Forex Strategy Builder Pro\User Files";

            // Set Data Source name, symbol, and period
            IDataSet dataSet = dataLoader.LoadDataSet("FSB Demo Data", "EURUSD", DataPeriod.D1);

            if (dataSet == null)
            {
                Console.WriteLine("Data file is not loaded!");
                Console.WriteLine("Press a key to continue!");
                Console.ReadKey();
                return;
            }

            // Create an indicator for testing
            IIndicator indicator = new BollingerBands();

            indicator.Initialize(SlotTypes.Open);
            indicator.Calculate(dataSet);

            // Print first values
            PrintFirstValues(indicator, 0, 50);

            // Calculate indicator with random parameters for all available slots.
            // tester.CalculateIndicatorWithRandomParameters(indicator, dataSet, 25);

            Console.WriteLine("Test completed without errors.");
            Console.WriteLine("Press a key to continue!");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Does the job
        /// </summary>
        private static void DoWorkTestCustomIndicators(object sender, DoWorkEventArgs e)
        {
            bool isErrors = false;

            var errorReport = new StringBuilder();

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

            var okReport = new StringBuilder();

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

            foreach (string indicatorName in IndicatorManager.CustomIndicatorNames)
            {
                string errorList;
                if (!IndicatorTester.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>");

            var result = new CustomIndicatorsTestResult
            {
                IsErrors    = isErrors,
                ErrorReport = errorReport.ToString(),
                OkReport    = okReport.ToString()
            };

            e.Result = result;
        }
        /// <summary>
        ///     Checks and stores the indicator.
        /// </summary>
        private bool IntegrateIndicator(string filePath, out string errorMessages, Indicator newIndicator)
        {
            errorMessages = string.Empty;

            // Check for a repeated indicator name among the custom indicators
            foreach (Indicator indicator in CustomIndicatorsList)
            {
                if (indicator.IndicatorName == newIndicator.IndicatorName)
                {
                    errorMessages = string.Format("Indicator '{0}' found in [{1}] is already loaded.",
                                                  newIndicator.IndicatorName,
                                                  Path.GetFileName(filePath));
                    return(false);
                }
            }

            // Check for a repeated indicator name among the original indicators
            foreach (string indicatorName in IndicatorManager.OriginalIndicatorNames)
            {
                if (indicatorName == newIndicator.IndicatorName)
                {
                    newIndicator.OverrideMainIndicator = true;
                }
            }

            // Test the new custom indicator
            string errorTestIndicator;

            if (!IndicatorTester.CustomIndicatorFastTest(newIndicator, out errorTestIndicator))
            {
                errorMessages = errorTestIndicator;
                return(false);
            }

            // Adds the custom indicator to the list
            CustomIndicatorsList.Add(newIndicator);

            return(true);
        }