Exemplo n.º 1
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description    = "test";
                Name           = "GregTestStrategy";
                DaysToLookBack = 1;
                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                // Add an MSFT 1 day Bars object to the strategy
                AddDataSeries("MSFT", Data.BarsPeriodType.Day, 1);

                SetStopLoss(CalculationMode.Percent, 0.05);

                // Sets a 20 tick trailing stop for an open position
                //SetTrailStop(CalculationMode.Ticks, 20);
            }
            else if (State == State.DataLoaded)
            {
                double input_param = 2.0;
                greg1 = GregIndicator1(input_param);

                AddChartIndicator(greg1);
            }
        }
Exemplo n.º 2
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                = "test";
                Name                       = "GregTestStrategy2";
                DaysToLookBack             = 1;
                FutureValueDaysToLookAhead = 5;

                TrainingStartDate = new DateTime(2017, 07, 01);
                TrainingEndDate   = new DateTime(2017, 07, 28);
                TestingStartDate  = new DateTime(2017, 08, 01);
                TestingEndDate    = new DateTime(2017, 12, 31);

                //KNN params
                MinIndicatorValue = -2.0f;
                MaxIndicatorValue = 2.0f;
                NumNeighbors      = 3;


                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                // Add an MSFT 1 day Bars object to the strategy
                AddDataSeries("MSFT", Data.BarsPeriodType.Day, 1);

                SetStopLoss(CalculationMode.Percent, 0.05);

                // Sets a 20 tick trailing stop for an open position
                //SetTrailStop(CalculationMode.Ticks, 20);
            }
            else if (State == State.DataLoaded)
            {
                double input_param = 2.0;
                greg1 = GregIndicator1(input_param);

                AddChartIndicator(greg1);
            }
            else if (State == State.Transition)  //finished processing historical data (and ready for real-time)
            {
                String training_file_path = "C:\\temp\\ninjatrader_training.csv";
                String testing_file_path  = "C:\\temp\\ninjatrader_testing.csv";
                WriteListToCSV(list_Indicator_FutureValueChange_Training, training_file_path);
                WriteListToCSV(list_Indicator_FutureValueChange_Testing, testing_file_path);

                String training_args = training_file_path + " " + MinIndicatorValue.ToString() +
                                       " " + MaxIndicatorValue.ToString() +
                                       " " + NumNeighbors.ToString();

                CallPythonScript("C:\\GregPython\\Examples\\Greg_HW\\Greg_NinjaTrader_1.py", training_args);
            }
        }
Exemplo n.º 3
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                = "test";
                Name                       = "KNN_Generator6";
                DaysToLookBack             = 1;
                FutureValueDaysToLookAhead = 5;

                TrainingStartDate = new DateTime(2017, 01, 01);
                TrainingEndDate   = new DateTime(2017, 09, 30);
                TestingStartDate  = new DateTime(2017, 10, 1);
                TestingEndDate    = new DateTime(2017, 12, 31);

                //Custom params
                indicator_to_use  = IndicatorEnum.indicator_MACD;
                KNN_num_neighbors = 3;
                num_training_pts  = 200;
                samples_per_group = 10;
                window_size       = 1;
                avg_target        = 1.0f;
                good_target       = 0.5f;
                bad_target        = 0.25f;
                min_samples       = 10;
                thresh1           = 1.0f;
                thresh2           = -1.0f;
                output_folder     = "C:\\temp\\knn\\";

                Param1 = 12;  //Defaults for MACD
                Param2 = 26;
                Param3 = 9;

                Sanitize = false;


                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                for (int i = 0; i < symbol_list.Length; i++)
                {
                    //Don't add the dummy instrument (but we still need a placeholder list which is added below)
                    if (i != 0)
                    {
                        AddDataSeries(symbol_list[i], Data.BarsPeriodType.Day, 1);
                    }

                    list_Indicator_FutureValueChange_Training_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                    list_Indicator_FutureValueChange_Testing_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                }

                SetStopLoss(CalculationMode.Percent, 0.05);

                // Sets a 20 tick trailing stop for an open position
                //SetTrailStop(CalculationMode.Ticks, 20);
            }
            else if (State == State.DataLoaded)
            {
                double input_param = 2.0;
                greg1 = GregIndicator1(input_param);

                AddChartIndicator(greg1);
            }
            else if (State == State.Transition)  //finished processing historical data (and ready for real-time)
            {
                //System.Windows.Forms.MessageBox.Show("test");
                Random rnd       = new Random();
                String unique_id = "_" + rnd.Next(100000, 999999).ToString();                 // creates a number between 100k and 999k

                String control_file_path          = output_folder + "control_file" + unique_id + ".txt";
                String consolidated_txt_file_path = output_folder + "consolidated_report" + unique_id + ".txt";
                String consolidated_csv_file_path = output_folder + "consolidated_report" + unique_id + ".csv";

                switch (indicator_to_use)
                {
                case IndicatorEnum.indicator_MACD:
                    if (Sanitize == false)
                    {
                        description = "MACD";
                    }
                    else
                    {
                        description = "M";
                    }
                    description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")";
                    break;

                case IndicatorEnum.indicator_RSI:
                    if (Sanitize == false)
                    {
                        description = "RSI";
                    }
                    else
                    {
                        description = "R";
                    }
                    description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")";
                    break;

                default:
                    description = "Unknown";
                    break;
                }

                description = description + " - " + FutureValueDaysToLookAhead.ToString();

                if (Sanitize == false)
                {
                    description = description + " days";
                }

                description = description + " - " + unique_id.Substring(1);                  //remove preceding "_"

                bool bFirstTime = true;
                for (int i = 1; i < symbol_list.Length; i++)  //Start at index=1 since we want to ignore the first primary/dummy instrument
                {
                    String symbol_name = symbol_list[i];
                    if (Sanitize == true)
                    {
                        symbol_name = symbol_list[i][0].ToString();
                    }

                    String base_file_path_for_symbol = output_folder + symbol_name;  //i.e. c:\temp\knn\AAPL

                    String training_file_path = base_file_path_for_symbol + "_training" + unique_id + ".csv";
                    String testing_file_path  = base_file_path_for_symbol + "_testing" + unique_id + ".csv";
                    WriteListToCSV(list_Indicator_FutureValueChange_Training_ALL[i], training_file_path);  //trying out +1!!!
                    WriteListToCSV(list_Indicator_FutureValueChange_Testing_ALL[i], testing_file_path);

                    String config_file_name = "";
                    config_file_name = GenerateConfigFile(base_file_path_for_symbol, symbol_name, training_file_path, testing_file_path, unique_id);

                    if (bFirstTime)  //create new file
                    {
                        bFirstTime = false;
                        File.WriteAllText(control_file_path, config_file_name + "\r\n");
                    }
                    else // append to existing file
                    {
                        File.AppendAllText(control_file_path, config_file_name + "\r\n");
                    }
                }

                //Now we can call python for all symbols at once by passing in the control_file as cmd line arg
                CallPythonScript(output_folder + "\\Data_Processing24.py", control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " true");
            }
        }
Exemplo n.º 4
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                = "test";
                Name                       = "KNN_Generator3";
                DaysToLookBack             = 1;
                FutureValueDaysToLookAhead = 5;

                TrainingStartDate = new DateTime(2017, 01, 01);
                TrainingEndDate   = new DateTime(2017, 09, 30);
                TestingStartDate  = new DateTime(2017, 10, 1);
                TestingEndDate    = new DateTime(2017, 12, 31);

                //Custom params
                indicator_to_use  = IndicatorEnum.indicator_MACD;
                KNN_num_neighbors = 3;
                num_training_pts  = 200;
                samples_per_group = 10;
                window_size       = 1;
                avg_target        = 1.0f;
                good_target       = 0.5f;
                bad_target        = 0.25f;
                min_samples       = 10;
                thresh1           = 1.0f;
                thresh2           = -1.0f;
                output_folder     = "C:\\temp\\knn\\";

                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                for (int i = 1; i < symbol_list.Length; i++)              //start at 1 since SLB already added by default
                {
                    // Add an MSFT 1 day Bars object to the strategy
                    AddDataSeries(symbol_list[i], Data.BarsPeriodType.Day, 1);

                    //private List<Indicator_FutureValueChange_Pair> list_Indicator_FutureValueChange_Training = new List<Indicator_FutureValueChange_Pair>();

                    list_Indicator_FutureValueChange_Training_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                    list_Indicator_FutureValueChange_Testing_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                }

                //Add extra one????
                list_Indicator_FutureValueChange_Training_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                list_Indicator_FutureValueChange_Testing_ALL.Add(new List <Indicator_FutureValueChange_Pair>());

                SetStopLoss(CalculationMode.Percent, 0.05);

                // Sets a 20 tick trailing stop for an open position
                //SetTrailStop(CalculationMode.Ticks, 20);
            }
            else if (State == State.DataLoaded)
            {
                double input_param = 2.0;
                greg1 = GregIndicator1(input_param);

                AddChartIndicator(greg1);
            }
            else if (State == State.Transition)  //finished processing historical data (and ready for real-time)
            {
                //System.Windows.Forms.MessageBox.Show("test");

                String control_file_path = output_folder + "control_file.txt";

                switch (indicator_to_use)
                {
                case IndicatorEnum.indicator_MACD:
                    if (bSanitize == false)
                    {
                        description = "MACD";
                    }
                    else
                    {
                        description = "M";
                    }
                    break;

                case IndicatorEnum.indicator_RSI:
                    if (bSanitize == false)
                    {
                        description = "RSI";
                    }
                    else
                    {
                        description = "R";
                    }
                    break;

                default:
                    description = "Unknown";
                    break;
                }

                description = description + " - " + FutureValueDaysToLookAhead.ToString();

                if (bSanitize == false)
                {
                    description = description + " days";
                }


                bool bFirstTime = true;
                for (int i = 1; i < symbol_list.Length; i++)
                {
                    String base_file_path_for_symbol = output_folder + symbol_list[i];  //i.e. c:\temp\knn\AAPL
                    String training_file_path        = base_file_path_for_symbol + "_training.csv";
                    String testing_file_path         = base_file_path_for_symbol + "_testing.csv";
                    WriteListToCSV(list_Indicator_FutureValueChange_Training_ALL[i], training_file_path);  //trying out +1!!!
                    WriteListToCSV(list_Indicator_FutureValueChange_Testing_ALL[i], testing_file_path);
                    //WriteListToCSV(list_Indicator_FutureValueChange_Training_ALL[i], training_file_path);
                    //WriteListToCSV(list_Indicator_FutureValueChange_Testing_ALL[i], testing_file_path);

                    String config_file_name = "";
                    config_file_name = GenerateConfigFile(base_file_path_for_symbol, symbol_list[i], training_file_path, testing_file_path);

                    if (bFirstTime)  //create new file
                    {
                        bFirstTime = false;
                        File.WriteAllText(control_file_path, config_file_name + "\r\n");
                    }
                    else // append to existing file
                    {
                        File.AppendAllText(control_file_path, config_file_name + "\r\n");
                    }
                }

                //Now we can call python for all symbols at once by passing in the control_file as cmd line arg
                CallPythonScript(output_folder + "\\Data_Processing18.py", control_file_path);
            }
        }