protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); var script = Script.Get(context); var function = Function.Get(context); var newinstance = NewInstance.Get(context); var param1 = Param1.Get(context); var param2 = Param2.Get(context); var param3 = Param3.Get(context); var param4 = Param4.Get(context); if (sharpAHK.ahkGlobal.ahkdll == null || newinstance) { New_AHKSession(newinstance); } if (!sharpAHK.ahkGlobal.ahkdll.FunctionExists(function)) { if (!string.IsNullOrEmpty(filename)) { sharpAHK.ahkGlobal.ahkdll.LoadFile(filename); } else { sharpAHK.ahkGlobal.ahkdll.LoadScript(script); } } if (!sharpAHK.ahkGlobal.ahkdll.FunctionExists(function)) { throw new ArgumentNullException("Function '" + function + "' does not exists"); } var result = sharpAHK.ahkGlobal.ahkdll.ExecFunction(function, param1, param2, param3, param4); Result.Set(context, result); }
public override void Execute(Tile p, Entity e) { if (IsActive) { // target is in parameters // Param1 = x // Param2 = y // Param3 = layer // does the platform already exists? Tile px = Game.I.level.GetPlatform(Param1.ToInt(), Param2.ToInt(), Param3.ToInt()); if (px != null) { //no so we can create it //Tile ppp = Game.I.level.CreatePlatform(Param1.ToInt(), Param2.ToInt(), Param3.ToInt()); // add to level and sort //Game.I.level.Platforms.Add(ppp); //Game.I.level.Sort(); } if (IsOneTimeAction) { IsActive = false; } } }
public override int GetHashCode() { int hash = 1; if (Id != 0L) { hash ^= Id.GetHashCode(); } if (Param1 != 0L) { hash ^= Param1.GetHashCode(); } if (Param2 != 0L) { hash ^= Param2.GetHashCode(); } if (Param3 != 0L) { hash ^= Param3.GetHashCode(); } if (Param4 != 0L) { hash ^= Param4.GetHashCode(); } if (Param5 != 0L) { hash ^= Param5.GetHashCode(); } if (Param6 != 0L) { hash ^= Param6.GetHashCode(); } if (Param7 != 0L) { hash ^= Param7.GetHashCode(); } if (Param8 != 0L) { hash ^= Param8.GetHashCode(); } if (Param9 != 0L) { hash ^= Param9.GetHashCode(); } if (Param10 != 0L) { hash ^= Param10.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hashcode = 157; unchecked { if (__isset.revision) { hashcode = (hashcode * 397) + Revision.GetHashCode(); } if (__isset.createdTime) { hashcode = (hashcode * 397) + CreatedTime.GetHashCode(); } if (__isset.type) { hashcode = (hashcode * 397) + Type.GetHashCode(); } if (__isset.reqSeq) { hashcode = (hashcode * 397) + ReqSeq.GetHashCode(); } if (__isset.checksum) { hashcode = (hashcode * 397) + Checksum.GetHashCode(); } if (__isset.status) { hashcode = (hashcode * 397) + Status.GetHashCode(); } if (__isset.param1) { hashcode = (hashcode * 397) + Param1.GetHashCode(); } if (__isset.param2) { hashcode = (hashcode * 397) + Param2.GetHashCode(); } if (__isset.param3) { hashcode = (hashcode * 397) + Param3.GetHashCode(); } if (__isset.message) { hashcode = (hashcode * 397) + Message.GetHashCode(); } } return(hashcode); }
public string Generate() { return(string.Join("\t", new[] { Index.ToString(), CurrentWP.ToString(), CoordFrame.ToString(), Command.ToString(), Param1.ToString(), Param2.ToString(), Param3.ToString(), Param4.ToString(), Latitude.ToString(), Longitude.ToString(), Altitude.ToString(), AutoContinue ? "1" : "0", })); }
public override void Execute(Tile p, Entity e) { if (IsActive) { // target is in parameters // Param1 = x // Param2 = y // Param3 = layer Tile px = Game.I.level.GetPlatform(Param1.ToInt(), Param2.ToInt(), Param3.ToInt()); Game.I.level.RemovePlatform(px); if (IsOneTimeAction) { IsActive = false; } } }
public override void Execute(Tile p, Entity e) { if (IsActive) { // target is in parameters // Param1 = x // Param2 = y // Param3 = layer e.position.X = Param1.ToInt(); e.position.Y = Param2.ToInt(); e.position.Layer = Param3.ToInt(); if (IsOneTimeAction) { IsActive = false; } } }
public override void Execute(Tile p, Entity e) { if (IsActive) { // target is in parameters // Param1 = x // Param2 = y // Param3 = layer // does the platform already exists? Tile px = Game.I.level.GetPlatform(Param1.ToInt(), Param2.ToInt(), Param3.ToInt()); if (px != null) { new Action_CreatePlatform().Execute(p, e); } else { new Action_DestroyPlatform().Execute(p, e); } } }
public override string ToString() { var sb = new StringBuilder("Operation("); bool __first = true; if (__isset.revision) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Revision: "); Revision.ToString(sb); } if (__isset.createdTime) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("CreatedTime: "); CreatedTime.ToString(sb); } if (__isset.type) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Type: "); Type.ToString(sb); } if (__isset.reqSeq) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("ReqSeq: "); ReqSeq.ToString(sb); } if (Checksum != null && __isset.checksum) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Checksum: "); Checksum.ToString(sb); } if (__isset.status) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Status: "); Status.ToString(sb); } if (Param1 != null && __isset.param1) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Param1: "); Param1.ToString(sb); } if (Param2 != null && __isset.param2) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Param2: "); Param2.ToString(sb); } if (Param3 != null && __isset.param3) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Param3: "); Param3.ToString(sb); } if (Message != null && __isset.message) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Message: "); Message.ToString(sb); } sb.Append(")"); return(sb.ToString()); }
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"); } }
protected override void OnBarUpdate() { //if (CurrentBar > (Count - 2)) //This means we have processed all historical data (https://ninjatrader.com/support/forum/showthread.php?t=66713) //{ // 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); // 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_Processing25.py", control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " true"); //} //double Current_Value = Closes[0][0]; //get the most recent Close data for the input symbol (index 0) //double Prev_Value = Closes[0][0]; ////double greg_indicator_value = GregIndicator1(BarsArray[0], 1.0)[0]; //if (CurrentBar >= DaysToLookBack) //make sure we have enough data loaded to look back n days //{ // Prev_Value = Closes[0][DaysToLookBack]; //} //// if (Current_Value > //// double Prev_Value = Close[CurrentBar - DaysToLookBack]; //double Percent_Change = (Current_Value / Prev_Value) - 1.0; //if (Buy_Price != 0.0) //{ // if ((Current_Value / Buy_Price - 1.0) > 0.02) //sell if gain > 2% // { // Buy_Price = 0.0; // //ExitLong(); // //ExitLong("Percent Drop", "Percent Drop"); // ExitLong(0, 100, "Exit Long from Percent Drop", "Percent Drop"); // //ExitLong("Selling - Went + 2%"); // //EnterShort("Selling - Went + 2%"); // } // //else if ((CurrentBar - BarBought) > 20) //sell after 20 days // //{ // // Buy_Price = 0.0; // // ExitLong(); // // //ExitLong("Selling - Waited 20 days"); // // //EnterShort("Selling - Waited 20 days"); // // } //} //if (Percent_Change < -0.02) //{ // //if (entryOrder == null) // //{ // EnterLong(0, 100, "Percent Drop"); // //} // //EnterLong(); // //EnterLong("Buying - Dropped 2%"); // //EnterLong(0, 100, "Percent Drop"); // //SetTrailStop(CalculationMode.Percent, 0.02); // //SetStopLoss(CalculationMode.Percent, 0.05); // Buy_Price = Current_Value; // BarBought = CurrentBar; // //SetTrailStop(CalculationMode.Percent, 0.01); //} int BarIndex = BarsInProgress; bool bFinishedProcessingAllData = false; if (((CurrentBar + 2) == Count) && BarIndex == (symbol_list.Count - 1)) //we are on the last bar to process { bFinishedProcessingAllData = true; } if ((BarIndex >= 1) && (BarIndex < (symbol_list.Count))) //Start at index=1 since we want to ignore the primary/dummy instrument { if (CurrentBar >= (FutureValueDaysToLookAhead)) //just make sure we avoid out of bounds error in case we don't yet have enough data { //DateTime current_date = Times[0][0].Date; DateTime date_to_process = Times[BarIndex][FutureValueDaysToLookAhead].Date; //need to wait FutureValueDaysToLookAhead days before we can make calcs bool bWithinTrainingPeriod = (date_to_process >= TrainingStartDate) && (date_to_process <= TrainingEndDate); bool bWithinTestingPeriod = (date_to_process >= TestingStartDate) && (date_to_process <= TestingEndDate); if ((bWithinTrainingPeriod) || (bWithinTestingPeriod)) { //TimeSpan diff = TrainingEndDate - TrainingStartDate; //int training_days = (int)Math.Abs(Math.Round(diff.TotalDays)); double indicator_value = 0.0; switch (indicator_to_use) { case IndicatorEnum.indicator_MACD: indicator_value = MACD(BarsArray[BarIndex], Param1, Param2, Param3)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_RSI: indicator_value = RSI(BarsArray[BarIndex], Param1, Param2)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_BOLLINGER: double upper_band = Bollinger(BarsArray[BarIndex], (double)Param1, Param2).Upper[FutureValueDaysToLookAhead]; //get the indicator val from n days ago double middle_band = Bollinger(BarsArray[BarIndex], (double)Param1, Param2).Middle[FutureValueDaysToLookAhead]; //get the indicator val from n days ago double lower_band = Bollinger(BarsArray[BarIndex], (double)Param1, Param2).Lower[FutureValueDaysToLookAhead]; //get the indicator val from n days ago double current_price = Closes[BarIndex][FutureValueDaysToLookAhead]; double diff = current_price - middle_band; double band_range = upper_band - middle_band; indicator_value = diff / band_range; //how far current price is from the middle band (-1.0 means we're at the lower band, +1 means we're at the upper band) break; case IndicatorEnum.indicator_STOCHASTIC: //use the "D" value indicator_value = Stochastics(BarsArray[BarIndex], Param1, Param2, Param3).D[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_STOCHASTIC_RSI: indicator_value = StochRSI(BarsArray[BarIndex], Param1)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_GREG: indicator_value = -999.999; // GregIndicator1(BarsArray[BarIndex], (float)Param1)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; default: indicator_value = -999.99; break; } if (double.IsNaN(indicator_value)) { indicator_value = 0.0; } double future_price_change = 0.0; double future_price = Closes[BarIndex][0]; double start_price = Closes[BarIndex][FutureValueDaysToLookAhead]; future_price_change = ((future_price / start_price) - 1.0) * 100.0; Indicator_FutureValueChange_Pair indicator_pair = new Indicator_FutureValueChange_Pair(); indicator_pair.Date = date_to_process; indicator_pair.Price = start_price; indicator_pair.Indicator = indicator_value; indicator_pair.FutureValueChange = future_price_change; if (bWithinTrainingPeriod) { list_Indicator_FutureValueChange_Training.Add(indicator_pair); list_Indicator_FutureValueChange_Training_ALL[BarIndex].Add(indicator_pair); int count_training = list_Indicator_FutureValueChange_Training.Count; } else if (bWithinTestingPeriod) { list_Indicator_FutureValueChange_Testing.Add(indicator_pair); list_Indicator_FutureValueChange_Testing_ALL[BarIndex].Add(indicator_pair); int count_testing = list_Indicator_FutureValueChange_Testing.Count; } } } } if (bFinishedProcessingAllData) { String unique_id = "_" + rnd.Next(100000, 999999).ToString(); // creates a number between 100k and 999k String debug_txt = "FINISHEDPROCESSING min_samples=" + min_samples_pct.ToString() + " id=" + unique_id.ToString(); Debug.WriteLine(debug_txt); 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; case IndicatorEnum.indicator_BOLLINGER: if (Sanitize == false) { description = "BOLL"; } else { description = "B"; } description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")"; break; case IndicatorEnum.indicator_STOCHASTIC: if (Sanitize == false) { description = "STOCH"; } else { description = "S"; } description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")"; break; case IndicatorEnum.indicator_STOCHASTIC_RSI: if (Sanitize == false) { description = "STOCH_RSI"; } else { description = "SR"; } description = description + "(" + Param1.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.Count; i++) //Start at index=1 since we want to ignore the first primary/dummy instrument { String symbol_name = symbol_list[i]; String company_name = company_name_list[i]; if (Sanitize == true) { String symbol_name_tmp = string.Concat(symbol_list[i].Reverse()).ToLower(); symbol_name = char.ToUpper(symbol_name_tmp[0]) + symbol_name_tmp.Substring(1); company_name = "?"; } 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); 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, company_name, training_file_path, testing_file_path, unique_id); //mut.WaitOne(); 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"); } //mut.ReleaseMutex(); } //Now we can call python for all symbols at once by passing in the control_file as cmd line arg mut.WaitOne(); string args = control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " c:\\temp\\knn\\master_report.csv" + " false"; CallPythonScript(output_folder + "\\Data_Processing33.py", args); mut.ReleaseMutex(); } }
protected override void OnStateChange() { if (State == State.SetDefaults) { if (bFirst) { bFirst = false; } String sp500_csv_file_path = "c:\\temp\\knn\\sp500.csv"; String sp500_config_file_path = "c:\\temp\\knn\\sp500_config_file.txt"; System.IO.StreamReader file1 = new System.IO.StreamReader(sp500_config_file_path); String line1 = file1.ReadLine(); if (line1 != null) { sp500_csv_file_path = line1; } file1.Close(); symbol_list = new List <String> { "DUMMY" }; company_name_list = new List <String> { "DUMMY" }; String line2; // Read the file and display it line by line. System.IO.StreamReader file2 = new System.IO.StreamReader(sp500_csv_file_path); while ((line2 = file2.ReadLine()) != null) { string[] values = line2.Split(','); if (values.Length == 2) { symbol_list.Add(values[0]); company_name_list.Add(values[1]); } } file2.Close(); Description = "test"; Name = "KNN_Generator10"; DaysToLookBack = 1; FutureValueDaysToLookAhead = 5; TrainingStartDate = new DateTime(2017, 01, 01); TrainingEndDate = new DateTime(2017, 12, 31); TestingStartDate = new DateTime(2018, 1, 1); TestingEndDate = DateTime.Today; //Custom params indicator_to_use = IndicatorEnum.indicator_MACD; 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; output_folder = "C:\\temp\\knn\\"; Param1 = 12; //Defaults for MACD Param2 = 26; Param3 = 9; Sanitize = false; bDataLoaded = false; // 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; 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); } 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) { //String debug_txt = "DATALOADED min_samples=" + min_samples.ToString(); //Debug.WriteLine(debug_txt); //double input_param = 2.0; //greg1 = GregIndicator1(input_param); //AddChartIndicator(greg1); bDataLoaded = true; } else if ((bDataLoaded == true) && ((State == State.Transition) || (State == State.Terminated))) //finished processing historical data (and ready for real-time) { if (false) //list_Indicator_FutureValueChange_Training_ALL.Count > 0) { //String debug_txt = "TERMINATED min_samples=" + min_samples.ToString(); //Debug.WriteLine(debug_txt); //if (bExecutedPython == false) //{ // bExecutedPython = true; //System.Threading.Thread.Sleep(2000); //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; case IndicatorEnum.indicator_BOLLINGER: if (Sanitize == false) { description = "BOLL"; } else { description = "B"; } break; case IndicatorEnum.indicator_STOCHASTIC: if (Sanitize == false) { description = "STOCH"; } else { description = "S"; } 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.Count; 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); 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, company_name_list[i], 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_Processing25.py", control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " true"); //bDataLoaded = false; } // } } }
private void Update(EvaluationContext context) { var bufferContent = new ParamBufferLayout(Param1.GetValue(context), Param2.GetValue(context), Param3.GetValue(context), Param4.GetValue(context)); ResourceManager.Instance().SetupConstBuffer(bufferContent, ref Buffer.Value); Buffer.Value.DebugName = nameof(ColorGradeConstBuffer); }
protected override void OnBarUpdate() { if (OnlyGeneratePlots) { return; } int BarIndex = BarsInProgress; bool bFinishedProcessingAllData = false; String debug_txt1 = "Date=" + Times[BarIndex][0].Date.ToShortDateString() + "BarIndex=" + BarIndex.ToString() + "CurrentBar=" + CurrentBar.ToString() + "Count=" + Count.ToString(); Debug.WriteLine(debug_txt1); DateTime current_bar_date = Times[BarIndex][0].Date; Boolean bLastSymbol = BarIndex == (symbol_list.Count - 1); if (current_bar_date > TestingEndDate) { return; } else if (bLastSymbol && (((CurrentBar + 1) == Count) || (current_bar_date == TestingEndDate))) //we are on the last bar to process { Debug.WriteLine("bFinished trigger"); bFinishedProcessingAllData = true; } if (((ProcessAllTickers == true) && (BarIndex >= 1) && (BarIndex < (symbol_list.Count))) || //Start at index=1 since we want to ignore the primary/dummy instrument ((ProcessAllTickers == false) && (BarIndex == 0))) { if (CurrentBar >= (FutureValueDaysToLookAhead)) //just make sure we avoid out of bounds error in case we don't yet have enough data { DateTime date_to_process = Times[BarIndex][FutureValueDaysToLookAhead].Date; //need to wait FutureValueDaysToLookAhead days before we can make calcs bool bWithinTrainingPeriod = (date_to_process >= TrainingStartDate) && (date_to_process <= TrainingEndDate); bool bWithinTestingPeriod = (date_to_process >= TestingStartDate) && (date_to_process <= TestingEndDate); if ((bWithinTrainingPeriod) || (bWithinTestingPeriod)) { for (int i = 0; i < indicator_list.Count; i++) { Indicator_FutureValueChange_Pair indicator_pair = GetIndicatorValue(indicator_list[i], BarIndex, FutureValueDaysToLookAhead, date_to_process); if (bWithinTrainingPeriod) { //list_Indicator_FutureValueChange_Training.Add(indicator_pair); //list_Indicator_FutureValueChange_Training_ALL[BarIndex].Add(indicator_pair); master_list_training[i][BarIndex].Add(indicator_pair); } else if (bWithinTestingPeriod) { //list_Indicator_FutureValueChange_Testing.Add(indicator_pair); //list_Indicator_FutureValueChange_Testing_ALL[BarIndex].Add(indicator_pair); master_list_testing[i][BarIndex].Add(indicator_pair); } } } } } if (bFinishedProcessingAllData) { String debug_txt2 = "finished processing all data"; Debug.WriteLine(debug_txt2); for (int bar_index = 1; bar_index < symbol_list.Count; bar_index++) { for (int i = 0; i < indicator_list.Count; i++) { int num_bars_for_symbol = Times[bar_index].Count; if (CurrentBar < num_bars_for_symbol) //Check for missing data { for (int j = (FutureValueDaysToLookAhead - 1); j >= 0; j--) { DateTime date_to_process = Times[bar_index][j].Date; debug_txt2 = "date_to_process=" + date_to_process.ToShortDateString(); Debug.WriteLine(debug_txt2); Indicator_FutureValueChange_Pair indicator_pair = GetIndicatorValue(indicator_to_use, bar_index, j, date_to_process); //Add to the "Testing" lists since these should be the ones capturing most recent values //list_Indicator_FutureValueChange_Testing.Add(indicator_pair); //list_Indicator_FutureValueChange_Testing_ALL[bar_index].Add(indicator_pair); master_list_testing[i][bar_index].Add(indicator_pair); } } } } uid = rnd.Next(100000, 999999).ToString(); String unique_id = "_" + uid; // 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"; bool bFirstTime = true; int start_index = 1; int max_index = symbol_list.Count; if (ProcessAllTickers == false) { start_index = 0; max_index = 1; } for (int j = 0; j < indicator_list.Count; j++) { uid = rnd.Next(100000, 999999).ToString(); unique_id = "_" + uid; // creates a number between 100k and 999k String debug_txt = "FINISHEDPROCESSING min_samples=" + min_samples_pct.ToString() + " id=" + unique_id.ToString(); Debug.WriteLine(debug_txt); switch (indicator_list[j]) { case IndicatorEnum.indicator_MACD: if (Sanitize == false) { description = "MACD"; } else { description = "M"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")"; break; case IndicatorEnum.indicator_RSI: if (Sanitize == false) { description = "RSI"; } else { description = "R"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")"; break; case IndicatorEnum.indicator_BOLLINGER: if (Sanitize == false) { description = "BOLL"; } else { description = "B"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")"; break; case IndicatorEnum.indicator_STOCHASTIC: if (Sanitize == false) { description = "STOCH"; } else { description = "S"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")"; break; case IndicatorEnum.indicator_STOCHASTIC_RSI: if (Sanitize == false) { description = "STOCH_RSI"; } else { description = "SR"; } indicator = description; description = description + "(" + Param1.ToString() + ")"; break; default: description = "Unknown"; indicator = description; break; } description = description + " - " + FutureValueDaysToLookAhead.ToString(); if (Sanitize == false) { description = description + " days"; } description = description + " - " + unique_id.Substring(1); //remove preceding "_" for (int i = start_index; i < max_index; i++) //Start at index=1 since we want to ignore the first primary/dummy instrument { String symbol_name = symbol_list[i]; if (ProcessAllTickers == false) { symbol_name = master_symbol_name; } String company_name = company_name_list[i]; if (Sanitize == true) { String symbol_name_tmp = string.Concat(symbol_name.Reverse()).ToLower(); symbol_name = char.ToUpper(symbol_name_tmp[0]) + symbol_name_tmp.Substring(1); company_name = "?"; } 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); //WriteListToCSV(list_Indicator_FutureValueChange_Testing_ALL[i], testing_file_path); WriteListToCSV(master_list_training[j][i], training_file_path); WriteListToCSV(master_list_testing[j][i], testing_file_path); String config_file_name = ""; config_file_name = GenerateConfigFile(base_file_path_for_symbol, symbol_name, company_name, training_file_path, testing_file_path, unique_id); //mut.WaitOne(); 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"); } //mut.ReleaseMutex(); } } Debug.WriteLine("Before Python mutex"); //Now we can call python for all symbols at once by passing in the control_file as cmd line arg mut_python.WaitOne(); string mode = " BEST"; if (FindBestSolutions == false) { mode = " RECENT"; } string args = control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " c:\\temp\\knn\\master_report.csv" + " c:\\temp\\knn\\master_trig.csv" + " false" + " false" + mode + " c:\\temp\\knn\\master_sorted.csv" + " " + GeneratePlotsForBestSolutions.ToString() + " " + NumPlotsToGenerate.ToString(); Debug.WriteLine("Python args" + args); CallPythonScript(output_folder + "\\Data_Processing45.py", args); mut_python.ReleaseMutex(); Debug.WriteLine("After Python mutex"); } }
protected String GenerateConfigFile(String filePath, String symbol, String company, String training_file_path, String testing_file_path, String unique_id) { String output_file_base = filePath + "_results_"; String config_file_name = filePath + "_config" + unique_id + ".txt"; List <String> labels = new List <String> { "uid", "KNN_num_neighbors", "num_training_pts", "num_groups", "stagger_factor", "window_size", "avg_target", "good_target", "bad_target", "min_samples_pct", "thresh1", "thresh2", "future_lookahead", "s_name", "co_name", "description", "indicator", "param1", "param2", "param3", "training_file", "training_start", "training_end", "testing_file", "testing_start", "testing_end", "output_csv_file", "output_txt_file", "output_pdf_file" }; List <String> values = new List <String> { uid, KNN_num_neighbors.ToString(), num_training_pts.ToString(), num_groups.ToString(), stagger_factor.ToString(), window_size.ToString(), avg_target.ToString(), good_target.ToString(), bad_target.ToString(), min_samples_pct.ToString(), thresh1.ToString(), thresh2.ToString(), FutureValueDaysToLookAhead.ToString(), symbol, company, description, indicator, Param1.ToString(), Param2.ToString(), Param3.ToString(), training_file_path, TrainingStartDate.ToShortDateString(), TrainingEndDate.ToShortDateString(), testing_file_path, TestingStartDate.ToShortDateString(), TestingEndDate.ToShortDateString(), output_file_base + "data" + unique_id + ".csv", output_file_base + "summary" + unique_id + ".txt", output_file_base + "plot" + unique_id + ".pdf", }; List <String> types = new List <String> { "str", "int", "int", "int", "int", "int", "float", "float", "float", "float", "float", "float", "int", "str", "str", "str", "str", "int", "int", "int", "str", "str", "str", "str", "str", "str", "str", "str", "str" }; var cfg = new StringBuilder(); for (int i = 0; i < labels.Count; i++) { cfg.AppendLine(labels[i] + "=" + values[i] + "#" + types[i]); } //mut.WaitOne(); //wait until safe to enter; prior thread has completed writing. try { File.WriteAllText(config_file_name, cfg.ToString()); //mut.ReleaseMutex(); } catch (System.Exception exp) { Log("File write error for file name '" + filePath + "' Error '" + exp.Message + "'", LogLevel.Warning); } return(config_file_name); }
protected override void OnBarUpdate() { int BarIndex = BarsInProgress; bool bFinishedProcessingAllData = false; if (((CurrentBar + 2) == Count) && BarIndex == (symbol_list.Count - 1)) //we are on the last bar to process { bFinishedProcessingAllData = true; } if (((ProcessAllTickers == true) && (BarIndex >= 1) && (BarIndex < (symbol_list.Count))) || //Start at index=1 since we want to ignore the primary/dummy instrument ((ProcessAllTickers == false) && (BarIndex == 0))) { if (CurrentBar >= (FutureValueDaysToLookAhead)) //just make sure we avoid out of bounds error in case we don't yet have enough data { DateTime current_bar_date = Times[BarIndex][0].Date; DateTime date_to_process = Times[BarIndex][FutureValueDaysToLookAhead].Date; //need to wait FutureValueDaysToLookAhead days before we can make calcs bool bWithinTrainingPeriod = (date_to_process >= TrainingStartDate) && (date_to_process <= TrainingEndDate); bool bWithinTestingPeriod = (date_to_process >= TestingStartDate) && (date_to_process <= TestingEndDate); if ((bWithinTrainingPeriod) || (bWithinTestingPeriod)) { //TimeSpan diff = TrainingEndDate - TrainingStartDate; //int training_days = (int)Math.Abs(Math.Round(diff.TotalDays)); double indicator_value = 0.0; switch (indicator_to_use) { case IndicatorEnum.indicator_MACD: indicator_value = MACD(BarsArray[BarIndex], Param1, Param2, Param3)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_RSI: indicator_value = RSI(BarsArray[BarIndex], Param1, Param2)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_BOLLINGER: double upper_band = Bollinger(BarsArray[BarIndex], (double)Param1, Param2).Upper[FutureValueDaysToLookAhead]; //get the indicator val from n days ago double middle_band = Bollinger(BarsArray[BarIndex], (double)Param1, Param2).Middle[FutureValueDaysToLookAhead]; //get the indicator val from n days ago double lower_band = Bollinger(BarsArray[BarIndex], (double)Param1, Param2).Lower[FutureValueDaysToLookAhead]; //get the indicator val from n days ago double current_price = Closes[BarIndex][FutureValueDaysToLookAhead]; double diff = current_price - middle_band; double band_range = upper_band - middle_band; indicator_value = diff / band_range; //how far current price is from the middle band (-1.0 means we're at the lower band, +1 means we're at the upper band) break; case IndicatorEnum.indicator_STOCHASTIC: //use the "D" value indicator_value = Stochastics(BarsArray[BarIndex], Param1, Param2, Param3).D[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_STOCHASTIC_RSI: indicator_value = StochRSI(BarsArray[BarIndex], Param1)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_GREG: indicator_value = -999.999; // GregIndicator1(BarsArray[BarIndex], (float)Param1)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; default: indicator_value = -999.99; break; } if (double.IsNaN(indicator_value)) { indicator_value = 0.0; } double future_price_change = 0.0; double future_price = Closes[BarIndex][0]; double start_price = Closes[BarIndex][FutureValueDaysToLookAhead]; future_price_change = ((future_price / start_price) - 1.0) * 100.0; Indicator_FutureValueChange_Pair indicator_pair = new Indicator_FutureValueChange_Pair(); indicator_pair.Date = date_to_process; indicator_pair.Price = start_price; indicator_pair.Indicator = indicator_value; indicator_pair.FutureValueChange = future_price_change; if (bWithinTrainingPeriod) { list_Indicator_FutureValueChange_Training.Add(indicator_pair); list_Indicator_FutureValueChange_Training_ALL[BarIndex].Add(indicator_pair); int count_training = list_Indicator_FutureValueChange_Training.Count; } else if (bWithinTestingPeriod) { list_Indicator_FutureValueChange_Testing.Add(indicator_pair); list_Indicator_FutureValueChange_Testing_ALL[BarIndex].Add(indicator_pair); int count_testing = list_Indicator_FutureValueChange_Testing.Count; } } } } else { } if (bFinishedProcessingAllData) { for (int bar_index = 1; bar_index < symbol_list.Count; bar_index++) { for (int j = FutureValueDaysToLookAhead; j >= 0; j--) { DateTime date_to_process = Times[bar_index][j].Date; double indicator_value = 0.0; switch (indicator_to_use) { case IndicatorEnum.indicator_MACD: indicator_value = MACD(BarsArray[bar_index], Param1, Param2, Param3)[j]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_RSI: indicator_value = RSI(BarsArray[bar_index], Param1, Param2)[0]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_BOLLINGER: double upper_band = Bollinger(BarsArray[bar_index], (double)Param1, Param2).Upper[j]; //get the indicator val from n days ago double middle_band = Bollinger(BarsArray[bar_index], (double)Param1, Param2).Middle[j]; //get the indicator val from n days ago double lower_band = Bollinger(BarsArray[bar_index], (double)Param1, Param2).Lower[j]; //get the indicator val from n days ago double current_price = Closes[bar_index][j]; double diff = current_price - middle_band; double band_range = upper_band - middle_band; indicator_value = diff / band_range; //how far current price is from the middle band (-1.0 means we're at the lower band, +1 means we're at the upper band) break; case IndicatorEnum.indicator_STOCHASTIC: //use the "D" value indicator_value = Stochastics(BarsArray[bar_index], Param1, Param2, Param3).D[j]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_STOCHASTIC_RSI: indicator_value = StochRSI(BarsArray[bar_index], Param1)[j]; //get the indicator val from n days ago break; case IndicatorEnum.indicator_GREG: indicator_value = -999.999; // GregIndicator1(BarsArray[BarIndex], (float)Param1)[FutureValueDaysToLookAhead]; //get the indicator val from n days ago break; default: indicator_value = -999.99; break; } if (double.IsNaN(indicator_value)) { indicator_value = 0.0; } double future_price_change = 0.0; double future_price = Closes[bar_index][j]; double start_price = Closes[bar_index][j]; future_price_change = ((future_price / start_price) - 1.0) * 100.0; Indicator_FutureValueChange_Pair indicator_pair = new Indicator_FutureValueChange_Pair(); indicator_pair.Date = date_to_process; indicator_pair.Price = start_price; indicator_pair.Indicator = indicator_value; indicator_pair.FutureValueChange = future_price_change; //if (bWithinTrainingPeriod) //{ // list_Indicator_FutureValueChange_Training.Add(indicator_pair); // list_Indicator_FutureValueChange_Training_ALL[BarIndex].Add(indicator_pair); // int count_training = list_Indicator_FutureValueChange_Training.Count; //} //else if (bWithinTestingPeriod) //{ list_Indicator_FutureValueChange_Testing.Add(indicator_pair); list_Indicator_FutureValueChange_Testing_ALL[bar_index].Add(indicator_pair); int count_testing = list_Indicator_FutureValueChange_Testing.Count; //} } } //if (CurrentBar >= (FutureValueDaysToLookAhead)) //just make sure we avoid out of bounds error in case we don't yet have enough data //{ // DateTime current_bar_date = Times[bar_index][0].Date; // DateTime date_to_process = Times[bar_index][0].Date; //need to wait FutureValueDaysToLookAhead days before we can make calcs // bool bWithinTrainingPeriod = (date_to_process >= TrainingStartDate) && (date_to_process <= TrainingEndDate); // bool bWithinTestingPeriod = (date_to_process >= TestingStartDate) && (date_to_process <= TestingEndDate); // if ((bWithinTrainingPeriod) || (bWithinTestingPeriod)) // { // //TimeSpan diff = TrainingEndDate - TrainingStartDate; // //int training_days = (int)Math.Abs(Math.Round(diff.TotalDays)); // } //} //////// uid = rnd.Next(100000, 999999).ToString(); String unique_id = "_" + uid; // creates a number between 100k and 999k String debug_txt = "FINISHEDPROCESSING min_samples=" + min_samples_pct.ToString() + " id=" + unique_id.ToString(); Debug.WriteLine(debug_txt); 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"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")"; break; case IndicatorEnum.indicator_RSI: if (Sanitize == false) { description = "RSI"; } else { description = "R"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")"; break; case IndicatorEnum.indicator_BOLLINGER: if (Sanitize == false) { description = "BOLL"; } else { description = "B"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")"; break; case IndicatorEnum.indicator_STOCHASTIC: if (Sanitize == false) { description = "STOCH"; } else { description = "S"; } indicator = description; description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")"; break; case IndicatorEnum.indicator_STOCHASTIC_RSI: if (Sanitize == false) { description = "STOCH_RSI"; } else { description = "SR"; } indicator = description; description = description + "(" + Param1.ToString() + ")"; break; default: description = "Unknown"; indicator = description; break; } description = description + " - " + FutureValueDaysToLookAhead.ToString(); if (Sanitize == false) { description = description + " days"; } description = description + " - " + unique_id.Substring(1); //remove preceding "_" bool bFirstTime = true; int start_index = 1; int max_index = symbol_list.Count; if (ProcessAllTickers == false) { start_index = 0; max_index = 1; } for (int i = start_index; i < max_index; i++) //Start at index=1 since we want to ignore the first primary/dummy instrument { String symbol_name = symbol_list[i]; if (ProcessAllTickers == false) { symbol_name = master_symbol_name; } String company_name = company_name_list[i]; if (Sanitize == true) { String symbol_name_tmp = string.Concat(symbol_name.Reverse()).ToLower(); symbol_name = char.ToUpper(symbol_name_tmp[0]) + symbol_name_tmp.Substring(1); company_name = "?"; } 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); 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, company_name, training_file_path, testing_file_path, unique_id); //mut.WaitOne(); 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"); } //mut.ReleaseMutex(); } //Now we can call python for all symbols at once by passing in the control_file as cmd line arg mut.WaitOne(); string mode = " BEST"; if (FindBestSolutions == false) { mode = " SINGLE"; } string args = control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " c:\\temp\\knn\\master_report.csv" + " c:\\temp\\knn\\master_trig.csv" + " false" + mode; CallPythonScript(output_folder + "\\Data_Processing39.py", args); mut.ReleaseMutex(); } }