Exemple #1
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                if (bFirst)
                {
                    bFirst = false;
                }

                symbol_list = new List <String> {
                    "DUMMY", "^SP500"
                };
                company_name_list = new List <String> {
                    "DUMMY", "S&P 500"
                };

                Trade_Status = new List <String> {
                    "DUMMY", "DUMMY"
                };
                DaysSincePurchase = new List <int> {
                    -1, -1
                };
                NumShares = new List <int> {
                    -1, -1
                };

                output_folder = "C:\\temp\\knn\\";

                LoadTickers(); //load symbols from file


                Description = "test";
                Name        = "Trade_Scanner2";
                Calculate   = Calculate.OnEachTick; //This will let us get the last Bar

                TestingStartDate = DateTime.Today;
                TestingEndDate   = DateTime.Today;


                //Trading params
                SimulateTrades  = true;
                AmountPerTrade  = 500.0f;
                StopLossPercent = 5;  //use int so we can potentially change during optimization
                DaysToHold      = 5;

                //Allows multiple stocks to be traded on same day
                EntryHandling = EntryHandling.UniqueEntries;

                //Custom params
                uid       = "";
                indicator = "";

                master_symbol_name = "";

                bDataLoaded = false;

                BOLL_param_string = "2;14;-1";

                Strategy_Num = 1;



                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;
                //IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                //Set our stop loss here
                SetStopLoss(CalculationMode.Percent, StopLossPercent / 100.0f);

                //System.Windows.Forms.MessageBox.Show("Configure");
                bDataLoaded = false;

                for (int i = 0; i < symbol_list.Count; 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);
                    }
                }

                for (int i = 0; i < indicator_list.Count; i++)
                {
                    master_list_training.Add(new List <List <Indicator_FutureValueChange_Pair> >());
                    master_list_testing.Add(new List <List <Indicator_FutureValueChange_Pair> >());
                    for (int j = 0; j < symbol_list.Count; j++)
                    {
                        master_list_training[i].Add(new List <Indicator_FutureValueChange_Pair>());
                        master_list_testing[i].Add(new List <Indicator_FutureValueChange_Pair>());
                    }
                }
            }
            else if (State == State.DataLoaded)
            {
                //master_symbol_name = Instrument.MasterInstrument.Name;

                bDataLoaded = true;

                TrainingStartDate = TestingEndDate.AddYears(-1);
                TrainingEndDate   = TestingEndDate.AddDays(-91);
                //TestingStartDate = TestingEndDate.AddDays(-90);

                output_folder_with_date = output_folder + TestingEndDate.ToString("ddMMMyyyy") + "\\";

                DirectoryInfo di = Directory.CreateDirectory(output_folder_with_date);
            }
            else if ((bDataLoaded == true) && ((State == State.Transition) || (State == State.Terminated)))  //finished processing historical data (and ready for real-time)
            {
            }
        }
Exemple #2
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                if (bFirst)
                {
                    bFirst = false;
                }

                symbol_list = new List <String> {
                    "DUMMY", "^SP500"
                };
                company_name_list = new List <String> {
                    "DUMMY", "S&P 500"
                };

                output_folder = "C:\\temp\\knn\\";

                LoadTickers(); //load symbols from file


                Description                = "test";
                Name                       = "KNN_Generator16";
                Calculate                  = Calculate.OnEachTick; //This will let us get the last Bar
                DaysToLookBack             = 1;
                FutureValueDaysToLookAhead = 5;


                TestingEndDate = DateTime.Today;

                //Custom params
                uid               = "";
                indicator         = "";
                KNN_num_neighbors = 3;
                num_training_pts  = 200;
                num_groups        = 20;
                stagger_factor    = 0;
                window_size       = 1;
                avg_target        = 1.0f;
                good_target       = 0.5f;
                bad_target        = 0.20f;
                min_samples_pct   = 0.06f;
                thresh1           = 1.0f;
                thresh2           = -1.0f;


                Sanitize                      = false;
                ProcessAllTickers             = true;
                FindBestSolutions             = false;
                GeneratePlotsForBestSolutions = false;
                OnlyGeneratePlots             = false;

                NumPlotsToGenerate = 20;

                master_symbol_name = "";

                bDataLoaded = false;

                MACD_param_string      = "12;26;9";
                RSI_param_string       = "14;3;-1";
                BOLL_param_string      = "2;14;-1";
                STOCH_param_string     = "7;14;3";
                STOCH_RSI_param_string = "14;-1;-1";


                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;
                //IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                //System.Windows.Forms.MessageBox.Show("Configure");

                bDataLoaded = false;

                if (!OnlyGeneratePlots)
                {
                    for (int i = 0; i < symbol_list.Count; 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);
                        }
                    }

                    for (int i = 0; i < indicator_list.Count; i++)
                    {
                        master_list_training.Add(new List <List <Indicator_FutureValueChange_Pair> >());
                        master_list_testing.Add(new List <List <Indicator_FutureValueChange_Pair> >());
                        for (int j = 0; j < symbol_list.Count; j++)
                        {
                            master_list_training[i].Add(new List <Indicator_FutureValueChange_Pair>());
                            master_list_testing[i].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)
            {
                //master_symbol_name = Instrument.MasterInstrument.Name;

                bDataLoaded = true;

                TrainingStartDate = TestingEndDate.AddYears(-1);
                TrainingEndDate   = TestingEndDate.AddDays(-91);
                TestingStartDate  = TestingEndDate.AddDays(-90);

                output_folder_with_date = output_folder + TestingEndDate.ToString("ddMMMyyyy") + "\\";

                DirectoryInfo di = Directory.CreateDirectory(output_folder_with_date);

                if (OnlyGeneratePlots)
                {
                    mut_python.WaitOne();
                    string args = output_folder_with_date + "master_sorted.csv" + " " + NumPlotsToGenerate.ToString();
                    Debug.WriteLine("Python args" + args);
                    CallPythonScript(output_folder + "\\Data_Processing46.py", args);
                    mut_python.ReleaseMutex();
                    Debug.WriteLine("After Python mutex");
                }
            }
            else if ((bDataLoaded == true) && ((State == State.Transition) || (State == State.Terminated)))  //finished processing historical data (and ready for real-time)
            {
            }
        }