public static void Go_run_sycle(bool With_indicators, bool Only_BUY, bool Only_SELL, bool interval_ECN_since_22_07_14) { string datastring = null; string[] dataArray; if (With_indicators == false) WorkClasses.base_file_name = "//Ticks_base.txt"; if (With_indicators == true) WorkClasses.base_file_name = "//Ticks_base_indicator.txt"; int BaseCount = 0; StreamReader baseFile_0 = new StreamReader(WorkClasses.dir_str + WorkClasses.base_file_name); for (int i = 0; ; i++) { datastring = baseFile_0.ReadLine(); if (baseFile_0.EndOfStream == true) break; BaseCount++; } baseFile_0.Close(); int jj; DateTime start_time1 = DateTime.Now; StreamReader baseFile_1 = new StreamReader(WorkClasses.dir_str + WorkClasses.base_file_name); datastring = baseFile_1.ReadLine(); if (interval_ECN_since_22_07_14 == true) { int left = 14390211; BaseCount = BaseCount - left; for (int j = 0; j < left; j++) datastring = baseFile_1.ReadLine(); } else { for (jj = 0; jj < BaseCount - 10400000; jj++) { datastring = baseFile_1.ReadLine(); } BaseCount = BaseCount - jj - 10; } string[] CurTime = new string[BaseCount], Date_on_time = new string[BaseCount]; double[] timeStep = new double[BaseCount], Ask = new double[BaseCount], Bid = new double[BaseCount], AskIncrement = new double[BaseCount], BidIncrement = new double[BaseCount]; double[] StM5_733_0 = new double[BaseCount]; double[] StM5_733_1 = new double[BaseCount]; double[] StM5_733_2 = new double[BaseCount]; double[] StM5_733_3 = new double[BaseCount]; double[] StM5_733_4 = new double[BaseCount]; for (int i = 0; i < BaseCount; i++) { datastring = baseFile_1.ReadLine(); if (baseFile_1.EndOfStream == true) break; dataArray = datastring.Split(' '); Date_on_time[i] = dataArray[0]; CurTime[i] = dataArray[1]; timeStep[i] = Convert.ToDouble(dataArray[2]); Ask[i] = Convert.ToDouble(dataArray[3]); Bid[i] = Convert.ToDouble(dataArray[5]); AskIncrement[i] = Convert.ToDouble(dataArray[4]); BidIncrement[i] = Convert.ToDouble(dataArray[6]); if (With_indicators) { StM5_733_0[i] = Convert.ToDouble(dataArray[7]); if (i > 0) { StM5_733_4[i] = StM5_733_4[i - 1]; StM5_733_3[i] = StM5_733_3[i - 1]; StM5_733_2[i] = StM5_733_2[i - 1]; StM5_733_1[i] = StM5_733_1[i - 1]; if (StM5_733_1[i] != Convert.ToDouble(dataArray[8])) { StM5_733_4[i] = StM5_733_3[i - 1]; StM5_733_3[i] = StM5_733_2[i - 1]; StM5_733_2[i] = StM5_733_1[i - 1]; StM5_733_1[i] = Convert.ToDouble(dataArray[8]); } } } } baseFile_1.Close(); DateTime start_end1 = DateTime.Now; Console.WriteLine(" "); Console.WriteLine((start_end1 - start_time1).ToString()); Console.WriteLine(" "); double ticks_sum = 0, Last_MaxFALLbyOrder = 0; StreamWriter ResultFile = new StreamWriter(WorkClasses.dir_str + "//_Agregate_by_Cycle.txt"); ResultFile.WriteLine("cnt_sell cnt_buy _out_sell _out_buy _in_sell _in_buy profit Add_Bal Add_BalDay MAX_FALL MAX_FALL_Day cnt_orders atitude_prcnt max_cnt_sell max_cnt_buy sth_low sth_max a BigMassCnt VolBMSELL_nega VolBMSELL_posi VolBMBUY_posi VolBMBUY_nega MAX_FALL_Round MNK MNM SELL_summ BUY_summ MaxCurProfitToClose_SELL MaxCurProfitToClose_BUY MaxCurStopLossToClose_SELL MaxCurStopLossToClose_BYU"); //Сначала сканируем без BigMass. Затем начинаем варьировать. //лучше искать 1. по SELL, с найденным лучшим вариантом искать по 2.SELL+BUY. Затем можно воварьировать лучший найденный вариант int min_count_sell = 10, max_count_sell = 11, incr_count_sell = 1; int min_count_buy = 10, max_count_buy = 14, incr_count_buy = 1; int min_slice_sell = 10000, max_slice_sell = 10001, incr_slice_sell = 1; int min_slice_buy = 21, max_slice_buy = 31, incr_slice_buy = 3; int min_t_in_sell = 10000, max_t_in_sell = 10001, incr_t_in_sell = 10; int min_t_in_buy = 450, max_t_in_buy = 1051, incr_t_in_buy = 100; int min_sth_low = 190, max_sth_low = 191, incr_sth_low = 20; int min_sth_high = 860, max_sth_high = 861, incr_sth_high = 100; int min_max_ticks_activ_cnt = 10000, max_max_ticks_activ_cnt = 10001, incr_max_ticks_activ_cnt = 2000; int min_max_ticks_activ_cnt_buy = 0, max_max_ticks_activ_cnt_buy = 1, incr_max_ticks_activ_cnt_buy = 1000; int min_BigMassCnt = 0, max_BigMassCnt = 1, incr_BigMassCnt = 2; int min_VolBigMassSELL_negative = 0, max_VolBigMassSELL_negative = 1, incr_VolBigMassSELL_negative = 50; int min_VolBigMassSELL_positive = 0, max_VolBigMassSELL_positive = 1, incr_VolBigMassSELL_positive = 50; int min_VolBigMassBUY_positive = 0, max_VolBigMassBUY_positive = 1, incr_VolBigMassBUY_positive = 50; int min_VolBigMassBUY_negative = 0, max_VolBigMassBUY_negative = 1, incr_VolBigMassBUY_negative = 50; int min_MaxCurProfitToClose_BUY = 0, max_MaxCurProfitToClose_BUY = 501, incr_MaxCurProfitToClose_BUY = 100; int min_MaxCurProfitToClose_SELL = 10000, max_MaxCurProfitToClose_SELL = 10001, incr_MaxCurProfitToClose_SELL = 25; int min_MaxCurStopLossToClose_BUY = 0, max_MaxCurStopLossToClose_BUY = 501, incr_MaxCurStopLossToClose_BUY = 100; int min_MaxCurStopLossToClose_SELL = 10000, max_MaxCurStopLossToClose_SELL = 10001, incr_MaxCurStopLossToClose_SELL = 150; //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 0, flg_F_avg_6, 10, 0, 4.20, 0.0, 17E-5, 0E-5, 0, 0, 22, 82, "new", "new", 0, 250, 0, 0, 0, 0, 0); //(!)3334 18833 59525 -166 -96 39 //Ask_F_avg_3 for (int count_sell = min_count_sell; count_sell < max_count_sell; count_sell = count_sell + incr_count_sell) { for (int count_buy = min_count_buy; count_buy < max_count_buy; count_buy = count_buy + incr_count_buy) { for (int slice_sell = min_slice_sell; slice_sell < max_slice_sell; slice_sell = slice_sell + incr_slice_sell) { for (int slice_buy = min_slice_buy; slice_buy < max_slice_buy; slice_buy = slice_buy + incr_slice_buy) { for (int t_in_sell = min_t_in_sell; t_in_sell < max_t_in_sell; t_in_sell = t_in_sell + incr_t_in_sell) { for (int t_in_buy = min_t_in_buy; t_in_buy < max_t_in_buy; t_in_buy = t_in_buy + incr_t_in_buy) { for (int sth_low = min_sth_low; sth_low < max_sth_low; sth_low = sth_low + incr_sth_low) { for (int sth_high = min_sth_high; sth_high < max_sth_high; sth_high = sth_high + incr_sth_high) { for (int max_ticks_activ_cnt = min_max_ticks_activ_cnt; max_ticks_activ_cnt < max_max_ticks_activ_cnt; max_ticks_activ_cnt = max_ticks_activ_cnt + incr_max_ticks_activ_cnt) { //if (max_ticks_activ_cnt == 950) // max_ticks_activ_cnt = 3350; for (int max_ticks_activ_cnt_buy = min_max_ticks_activ_cnt_buy; max_ticks_activ_cnt_buy < max_max_ticks_activ_cnt_buy; max_ticks_activ_cnt_buy = max_ticks_activ_cnt_buy + incr_max_ticks_activ_cnt_buy) { for (int BigMassCnt = min_BigMassCnt; BigMassCnt < max_BigMassCnt; BigMassCnt = BigMassCnt + incr_BigMassCnt) { //--------------------- for (double VolBigMassSELL_negative = min_VolBigMassSELL_negative; VolBigMassSELL_negative < max_VolBigMassSELL_negative; VolBigMassSELL_negative = VolBigMassSELL_negative + incr_VolBigMassSELL_negative) { for (double VolBigMassSELL_positive = min_VolBigMassSELL_positive; VolBigMassSELL_positive < max_VolBigMassSELL_positive; VolBigMassSELL_positive = VolBigMassSELL_positive + incr_VolBigMassSELL_positive)//обычно заполняется нулем { for (double VolBigMassBUY_positive = min_VolBigMassBUY_positive; VolBigMassBUY_positive < max_VolBigMassBUY_positive; VolBigMassBUY_positive = VolBigMassBUY_positive + incr_VolBigMassBUY_positive) { for (double VolBigMassBUY_negative = min_VolBigMassBUY_negative; VolBigMassBUY_negative < max_VolBigMassBUY_negative; VolBigMassBUY_negative = VolBigMassBUY_negative + incr_VolBigMassBUY_negative)//обычно заполняется нулем { //--------------------- //double SellCustomSthCorrection = 0.0; double SellCustomSthCorrection = 5.0; double SELL_SPREAD = 25; double BUY_SPREAD = 21; for (int MaxCurProfitToClose_BUY = min_MaxCurProfitToClose_BUY; MaxCurProfitToClose_BUY < max_MaxCurProfitToClose_BUY; MaxCurProfitToClose_BUY = MaxCurProfitToClose_BUY + incr_MaxCurProfitToClose_BUY) { for (int MaxCurProfitToClose_SELL = min_MaxCurProfitToClose_SELL; MaxCurProfitToClose_SELL < max_MaxCurProfitToClose_SELL; MaxCurProfitToClose_SELL = MaxCurProfitToClose_SELL + incr_MaxCurProfitToClose_SELL) { for (int MaxCurStopLossToClose_BUY = min_MaxCurStopLossToClose_BUY; MaxCurStopLossToClose_BUY < max_MaxCurStopLossToClose_BUY; MaxCurStopLossToClose_BUY = MaxCurStopLossToClose_BUY + incr_MaxCurStopLossToClose_BUY) { for (int MaxCurStopLossToClose_SELL = min_MaxCurStopLossToClose_SELL; MaxCurStopLossToClose_SELL < max_MaxCurStopLossToClose_SELL; MaxCurStopLossToClose_SELL = MaxCurStopLossToClose_SELL + incr_MaxCurStopLossToClose_SELL) { DateTime start_time = DateTime.Now; if (Last_MaxFALLbyOrder < -1500.0 || ticks_sum * 100000.0 < 500.0) { Last_MaxFALLbyOrder = 10000.0; ticks_sum = 10000.0; DateTime end_time1 = DateTime.Now; Console.WriteLine("Skip iteration. " + (start_time - end_time1).ToString()); continue; } double t_divide_by = 100.0; WorkClasses.Ticks_In TicksIn = new WorkClasses.Ticks_In(); WorkClasses.Ticks_Out TicksOut = new WorkClasses.Ticks_Out(); WorkClasses.Stat_Info StatInfo = new WorkClasses.Stat_Info(); TicksIn.flag_ByCycle = true; TicksIn.SellCustomSthCorrection = SellCustomSthCorrection; if (Only_BUY) TicksIn.Only_BUY_flg = true; if (Only_SELL) TicksIn.Only_SELL_flg = true; int dim = TicksIn.dim - 1; for (int i = 0; i < dim + 1; i++) TicksIn.timeStep[i] = 1; int flg_F_avg_6 = 0; ticks_sum = 0; double summ_dt_3; double[] Last_N_profit = new double[20]; int count_for_Last_N_profit = 3, cnt_closed_orders = 0, cnt_negative_avg_Last_N_profit = 0; int[] Counts_On_Close = new int[50000]; for (int i = 0; i < BaseCount; i++) //for (int i = 4000000; i < BaseCount; i++) { TicksIn.Count = TicksIn.Count + 1; TicksIn.CurTime = CurTime[i]; TicksIn.Date = Date_on_time[i]; for (int j = 0; j < dim; j++) { TicksIn.timeStep[j] = TicksIn.timeStep[j + 1]; TicksIn.Ask[j] = TicksIn.Ask[j + 1]; TicksIn.AskIncrement[j] = TicksIn.AskIncrement[j + 1]; TicksIn.Spread[j] = TicksIn.Spread[j + 1]; //TicksOut.AskSpeed[j] = TicksOut.AskSpeed[j + 1]; TicksOut.Ask_F_avg_6[j] = TicksOut.Ask_F_avg_6[j + 1]; } TicksIn.timeStep[dim] = timeStep[i]; TicksIn.Ask[dim] = Ask[i]; TicksIn.Bid[dim] = Bid[i]; TicksIn.AskIncrement[dim] = AskIncrement[i]; TicksIn.Spread[dim] = Math.Abs(TicksIn.Ask[dim] - TicksIn.Bid[dim]) * 100000.0; if (With_indicators == true) { TicksIn.StM5_733_0 = StM5_733_0[i]; TicksIn.StM5_733_1 = StM5_733_1[i]; TicksIn.StM5_733_2 = StM5_733_2[i]; TicksIn.StM5_733_3 = StM5_733_3[i]; TicksIn.StM5_733_4 = StM5_733_4[i]; TicksIn.Stohastic_Param = TicksIn.StM5_733_3; } //Вычисление индикаторов// summ_dt_3 = TicksIn.timeStep[dim] + TicksIn.timeStep[dim - 1] + TicksIn.timeStep[dim - 2]; TicksOut.AskSpeed[dim] = TicksIn.AskIncrement[dim] / TicksIn.timeStep[dim]; TicksOut.Ask_F_avg_3[dim] = (TicksIn.AskIncrement[dim] + TicksIn.AskIncrement[dim - 1] + TicksIn.AskIncrement[dim - 2]) / Math.Pow(summ_dt_3, 2) * 100000.0; TicksOut.Ask_F_avg_6[dim] = (TicksIn.AskIncrement[dim] + TicksIn.AskIncrement[dim - 1] + TicksIn.AskIncrement[dim - 2] + TicksIn.AskIncrement[dim - 3] + TicksIn.AskIncrement[dim - 4] + TicksIn.AskIncrement[dim - 5]) / Math.Pow(summ_dt_3 + TicksIn.timeStep[dim - 3] + TicksIn.timeStep[dim - 4] + TicksIn.timeStep[dim - 5], 2) * 100000.0; //Пропускаем мимо ситуации, когда ордер открыт в момент ГЭПа по времени. if (WorkClasses.gaps_str.Contains(" " + Convert.ToString(TicksIn.Count) + " ")) { if (Math.Abs(flg_F_avg_6) == 1) { flg_F_avg_6 = 0; TicksOut.ticks_activ_cnt = 0; for (int j = 0; j < dim + 1; j++) { TicksOut.Ask_F_avg_3[j] = 0; //TicksOut.Ask_F_avg_4[j] = 0; //TicksOut.Ask_F_avg_5[j] = 0; TicksOut.Ask_F_avg_6[j] = 0; //TicksOut.Ask_F_avg_8[j] = 0; } } } //---------------------- //------------// //------------// if (count_sell > TicksIn.dim) break; if (flg_F_avg_6 == 1) { TicksOut.local_Open_vs_Cur = TicksIn.Bid[dim] - TicksOut.OpenASK; if (StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] < TicksOut.local_Open_vs_Cur * 100000) StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; TicksOut.ticks_activ_cnt++; if (TicksOut.ticks_activ_cnt == 1) { StatInfo.AskIncremBigMassSummNegative[cnt_closed_orders] = TicksIn.AskIncremBigMassSumm_Negative; StatInfo.AskIncremBigMassSummPositive[cnt_closed_orders] = TicksIn.AskIncremBigMassSumm_Positive; } } else if (flg_F_avg_6 == -1) { TicksOut.local_Open_vs_Cur = TicksOut.OpenBID - TicksIn.Ask[dim]; if (StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] < TicksOut.local_Open_vs_Cur * 100000) StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; TicksOut.ticks_activ_cnt++; if (TicksOut.ticks_activ_cnt == 1) { StatInfo.AskIncremBigMassSummNegative[cnt_closed_orders] = TicksIn.AskIncremBigMassSumm_Negative; StatInfo.AskIncremBigMassSummPositive[cnt_closed_orders] = TicksIn.AskIncremBigMassSumm_Positive; } } else if (flg_F_avg_6 == 0) { TicksOut.local_Open_vs_Cur = 0; } flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, SELL_SPREAD, BUY_SPREAD, flg_F_avg_6, count_sell, count_buy, t_in_sell / t_divide_by, t_in_buy / t_divide_by, slice_sell / 100000.0, slice_buy / 100000.0, max_ticks_activ_cnt, max_ticks_activ_cnt_buy, sth_low / 10.0, sth_high / 10.0, "new", "new", MaxCurProfitToClose_BUY, MaxCurProfitToClose_SELL, -MaxCurStopLossToClose_BUY, -MaxCurStopLossToClose_SELL, VolBigMassSELL_negative, VolBigMassSELL_positive, VolBigMassBUY_positive, VolBigMassBUY_negative, BigMassCnt); if (Math.Abs(flg_F_avg_6) == 1 && TicksOut.ticks_activ_cnt == 0) StatInfo.StartSpread[cnt_closed_orders] = TicksIn.Spread[dim]; count_for_Last_N_profit = 3; if (Math.Abs(flg_F_avg_6) == 2) { if (flg_F_avg_6 == 2) TicksOut.local_Open_vs_Cur = TicksIn.Bid[dim] - TicksOut.OpenASK; if (flg_F_avg_6 == -2) TicksOut.local_Open_vs_Cur = TicksOut.OpenBID - TicksIn.Ask[dim]; ticks_sum = ticks_sum + TicksOut.local_Open_vs_Cur; TicksOut.Ticks_Sum_on_time[cnt_closed_orders] = ticks_sum * 100000; //Присваиваем текущее значение профита для последующего МНК TicksOut.Date_on_time[cnt_closed_orders] = TicksIn.Date; TicksOut.Cur_Order_Profit[cnt_closed_orders] = (TicksOut.local_Open_vs_Cur) * 100000; TicksOut.flg_F_avg_6[cnt_closed_orders] = flg_F_avg_6; Counts_On_Close[cnt_closed_orders] = TicksIn.Count; if (StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] < TicksOut.local_Open_vs_Cur * 100000) StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; for (int j = 0; j < count_for_Last_N_profit - 1; j++) Last_N_profit[j] = Last_N_profit[j + 1]; Last_N_profit[count_for_Last_N_profit - 1] = (TicksOut.local_Open_vs_Cur) * 100000; double avg_Last_N_profit = 0.0; for (int j = 0; j < count_for_Last_N_profit; j++) avg_Last_N_profit += Last_N_profit[j]; avg_Last_N_profit = avg_Last_N_profit / count_for_Last_N_profit; if (cnt_closed_orders < count_for_Last_N_profit) avg_Last_N_profit = 0; if (avg_Last_N_profit < 0.0) cnt_negative_avg_Last_N_profit++; cnt_closed_orders++; } if (flg_F_avg_6 == -2 || flg_F_avg_6 == 2) { flg_F_avg_6 = 0; TicksOut.ticks_activ_cnt = 0; } } DateTime end_time_mid = DateTime.Now; if (cnt_closed_orders == 0) continue; double atitude_pecents = Convert.ToDouble(cnt_negative_avg_Last_N_profit) / (cnt_closed_orders + 1) * 100.0; if (cnt_closed_orders > 1000) { Console.WriteLine("cnt_closed_orders > 1000"); continue; } int cnt_of_start_last_date = 0; double[] Cur_Day_Profit = new double[cnt_closed_orders], Ticks_Sum_on_Day = new double[cnt_closed_orders]; for (int i = 0; i < cnt_closed_orders; i++) { if (TicksOut.Date_on_time[i] == TicksOut.Date_on_time[cnt_closed_orders - 1]) { cnt_of_start_last_date = i; break; } } for (int i = 0; i <= cnt_of_start_last_date; i++) { string temp_date = TicksOut.Date_on_time[i]; Cur_Day_Profit[i] = TicksOut.Cur_Order_Profit[i]; if (i == 0) Ticks_Sum_on_Day[i] = TicksOut.Cur_Order_Profit[i]; else Ticks_Sum_on_Day[i] = Ticks_Sum_on_Day[i - 1] + TicksOut.Cur_Order_Profit[i]; for (int j = i + 1; j < cnt_closed_orders; j++) { if (TicksOut.Date_on_time[j] != temp_date) { for (int t = j - 1; t > i; t--) { Cur_Day_Profit[t] = Cur_Day_Profit[i]; Ticks_Sum_on_Day[t] = Ticks_Sum_on_Day[i]; } i = j - 1; break; } Cur_Day_Profit[i] += TicksOut.Cur_Order_Profit[j]; Ticks_Sum_on_Day[i] += TicksOut.Cur_Order_Profit[j]; } if (i == cnt_of_start_last_date && cnt_of_start_last_date != (cnt_closed_orders - 1)) { for (int j = cnt_of_start_last_date + 1; j < cnt_closed_orders; j++) { Ticks_Sum_on_Day[j] = Ticks_Sum_on_Day[cnt_of_start_last_date]; } } } //---Аппроксимируем прямой--- double[] residuals = new double[cnt_closed_orders]; double s_xy = 0.0, s_x = 0.0, s_y = 0.0, s_x2 = 0.0; for (int i = 0; i < cnt_closed_orders; i++) { s_x += i + 1; s_y += TicksOut.Ticks_Sum_on_time[i]; s_xy += TicksOut.Ticks_Sum_on_time[i] * (i + 1); s_x2 += (i + 1) * (i + 1); } double a = (cnt_closed_orders * s_xy - s_x * s_y) / (cnt_closed_orders * s_x2 - s_x * s_x); double b = (s_y - a * s_x) / (cnt_closed_orders); double SELL_summ_slice = 0.0, BUY_summ_slice = 0.0; double[] Max_FALL = new double[cnt_closed_orders * cnt_closed_orders], Max_FALL_byDay = new double[cnt_closed_orders * cnt_closed_orders]; for (int i = 0; i < cnt_closed_orders; i++) { StatInfo.residual_avg_MNK += Math.Abs((TicksOut.Ticks_Sum_on_time[i] - (a * (i + 1) + b))); StatInfo.residual_avg_MNM += Math.Abs((TicksOut.Ticks_Sum_on_time[i] - (a * (i + 1) + b)) * Math.Cos(Math.Atan(a))); if (TicksOut.flg_F_avg_6[i] == -2) StatInfo.SELL_summ_slice += TicksOut.Cur_Order_Profit[i]; if (TicksOut.flg_F_avg_6[i] == 2) StatInfo.BUY_summ_slice += TicksOut.Cur_Order_Profit[i]; for (int j = 0; j < i; j++) { Max_FALL[i * i + j] = TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - j - 1]; Max_FALL_byDay[i * i + j] = Ticks_Sum_on_Day[i] - Ticks_Sum_on_Day[i - j - 1]; } } StatInfo.MaxFALLbyOrder = Max_FALL.Min(); if (StatInfo.MaxFALLbyOrder > -0.1) StatInfo.MaxFALLbyOrder = 1; StatInfo.MaxFALLbyDay = Max_FALL_byDay.Min(); if (StatInfo.MaxFALLbyDay > -0.1) StatInfo.MaxFALLbyDay = 1; StatInfo.residual_avg_MNK = StatInfo.residual_avg_MNK / cnt_closed_orders; StatInfo.residual_avg_MNM = StatInfo.residual_avg_MNM / cnt_closed_orders; //StreamWriter helpFile = new StreamWriter(WorkClasses.dir_str + "////help_out.txt"); //Смотрим, сколько было бы "+" прибыли, если бы выставили как 10% от баланса по макс.падению double Balance = 3000.0, Balance_Day = 3000.0; for (int i = 0; i < cnt_closed_orders; i++) { residuals[i] = Math.Abs((TicksOut.Ticks_Sum_on_time[i] - (a * (i + 1) + b))); if (i != 0) Balance_Day = Balance_Day + (TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - 1]) * Math.Min((0.10 * Balance_Day) / Math.Abs(StatInfo.MaxFALLbyDay), 100.0); else Balance_Day = Balance_Day + (TicksOut.Ticks_Sum_on_time[i]) * (0.10 * Balance_Day) / Math.Abs(StatInfo.MaxFALLbyDay); if (i != 0) Balance = Balance + (TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - 1]) * Math.Min((0.10 * Balance) / Math.Abs(StatInfo.MaxFALLbyOrder), 100.0); else Balance = Balance + (TicksOut.Ticks_Sum_on_time[i]) * (0.10 * Balance) / Math.Abs(StatInfo.MaxFALLbyOrder); // helpFile.WriteLine((Counts_On_Close[i]).ToString() + " " + TicksOut.Date_on_time[i] + " " + TicksOut.flg_F_avg_6[i].ToString() + " " + TicksOut.Cur_Order_Profit[i].ToString() + " " + StatInfo.MaxLocalProfitInOrder[i].ToString() + " " + TicksOut.Ticks_Sum_on_time[i].ToString() //+ " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(Balance_Day).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0] //+ " " + cnt_closed_orders.ToString() + " " + (a * (i + 1) + b).ToString() + " " + residuals[i] + " " + a.ToString() + " " + StatInfo.residual_avg_MNK.ToString() + " " + StatInfo.residual_avg_MNM.ToString() //+ " " + StatInfo.SELL_summ_slice.ToString() + " " + StatInfo.BUY_summ_slice.ToString() //+ " " + (Math.Round(StatInfo.MaxFALLbyOrder / 1000.0, 1) * 1000.0).ToString()); } //helpFile.Close(); //------------------------- DateTime end_time = DateTime.Now; Console.WriteLine((count_sell).ToString() + " " + (slice_sell / 100000.0).ToString() + " " + (slice_buy / 100000.0).ToString() + " " + (t_in_sell / t_divide_by).ToString() + " " + (t_in_buy / t_divide_by).ToString() + " " + max_ticks_activ_cnt.ToString() + " " + max_ticks_activ_cnt_buy.ToString() + " " + atitude_pecents.ToString() + " " + (start_time - end_time).ToString() + " " + (start_time - end_time_mid).ToString()); //if (ticks_sum * 100000.0 > 100.0 && a > 5.0 && Max_FALL1 > -500.0 && atitude_pecents < 55.0 if (ticks_sum * 100000.0 > 10.0 && a > 0.0 && cnt_closed_orders > 10 && StatInfo.MaxFALLbyOrder > -3000.0 // //&& atitude_pecents < 55.0 && StatInfo.residual_avg_MNK < 1000.0 // //&& (Balance - 3000.0) > 1000.0 ) { ResultFile.WriteLine((count_sell).ToString() + " " + (count_buy).ToString() + " " + slice_sell.ToString() + " " + slice_buy.ToString() + " " + (t_in_sell / t_divide_by).ToString() + " " + (t_in_buy / t_divide_by).ToString() + " " + (ticks_sum * 100000.0).ToString() + " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(Balance_Day).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0] + " " + cnt_closed_orders.ToString() + " " + (atitude_pecents).ToString() + " " + max_ticks_activ_cnt.ToString() + " " + max_ticks_activ_cnt_buy.ToString() + " " + (sth_low / 10.0).ToString() + " " + (sth_high / 10.0).ToString() + " " + a.ToString() + " " + BigMassCnt + " " + VolBigMassSELL_negative + " " + VolBigMassSELL_positive + " " + VolBigMassBUY_positive + " " + VolBigMassBUY_negative + " " + (Math.Round(StatInfo.MaxFALLbyOrder / 1000.0, 1) * 1000.0).ToString() + " " + StatInfo.residual_avg_MNK.ToString() + " " + StatInfo.residual_avg_MNM.ToString() + " " + StatInfo.SELL_summ_slice.ToString() + " " + StatInfo.BUY_summ_slice.ToString() + " " + MaxCurProfitToClose_SELL.ToString() + " " + MaxCurProfitToClose_BUY.ToString() + " " + MaxCurStopLossToClose_SELL.ToString() + " " + MaxCurStopLossToClose_BUY.ToString() ); } Last_MaxFALLbyOrder = StatInfo.MaxFALLbyOrder; } } } } } } } } } } } } } } } } } } } ResultFile.Close(); }
private void StartAnalyse_Click(object sender, EventArgs e) { string datastring = null; if (With_indicators.Checked == false) WorkClasses.base_file_name = "//Ticks_base.txt"; if (With_indicators.Checked == true) { WorkClasses.base_file_name = "//Ticks_base_indicator.txt"; if (this.UseShortFile.Checked == true) WorkClasses.base_file_name = "//Ticks_base_indicator_Short.txt"; //if (Ind_Local_file.Checked == true) // WorkClasses.base_file_name = "//Ticks_base_ind_local.txt"; } StreamWriter temp_help = new StreamWriter(WorkClasses.dir_str + "//_temp_help.txt"); StreamReader baseFile = new StreamReader(WorkClasses.dir_str + WorkClasses.base_file_name); StreamWriter OutFile = new StreamWriter(WorkClasses.dir_str + "//_Ticks_all_processed.txt"); StreamWriter ResultFile = new StreamWriter(WorkClasses.dir_str + "//_Agregate_by_Ind.txt"); StreamWriter DetailResultFile = new StreamWriter(WorkClasses.dir_str + "//_Agregate_Detail_by_Ind.txt"); //StreamReader stream = new StreamReader("D://Ticks//archive//_Bases//2013.11.01_Ticks_base.txt"); //StreamReader stream = new StreamReader("D://Ticks//_Agregate_by_Cycle.txt"); //string allstr = baseFile.ReadToEnd(); //string[] ArrayOfAllString = allstr.Split('\n'); //allstr.Remove(0); DetailResultFile.WriteLine("count Date CurTime AskIncrement flg_F_avg_6 Bid Ask ticks_activ_cnt ticks_active_time profit_step AskSpeed Ask_V_3 Ask_V_6 Ask_V_avg_3 Ask_V_avg_6 Ask_F_avg_3 Ask_F_avg_6"); StreamWriter helpFile = new StreamWriter(WorkClasses.dir_str + "//_help_out.txt"); StreamWriter helpFile_byDays = new StreamWriter(WorkClasses.dir_str + "//_help_out_by_days.txt"); StreamWriter helpFile_byMonth = new StreamWriter(WorkClasses.dir_str + "//_help_out_by_month.txt"); WorkClasses.Ticks_In TicksIn = new WorkClasses.Ticks_In(); WorkClasses.Ticks_Out TicksOut = new WorkClasses.Ticks_Out(); WorkClasses.Stat_Info StatInfo = new WorkClasses.Stat_Info(); if (this.Only_BUY.Checked) TicksIn.Only_BUY_flg = true; if (this.Only_SELL.Checked) TicksIn.Only_SELL_flg = true; if (this.With_indicators.Checked) TicksIn.With_indicators = true; int dim = TicksIn.dim - 1; for (int i = 0; i < dim+1; i++) TicksIn.timeStep[i] = 1; int flg_F_avg_6 = 0; double ticks_sum = 0; int cnt_closed_orders = 0, cnt_negative_avg_Last_N_profit = 0; int[] Counts_On_Close = new int[50000], Counts_On_Open = new int[50000]; double ticks_active_time = 0.0; string order_open_time = ""; double[] Last_N_profit = new double[20]; datastring = baseFile.ReadLine(); OutFile.WriteLine("Count CurTime TimeInc Ask Bid AskIncrement flg_F ticks_activ_cnt ticks_active_time Bid-OpenASK OpenBID-Bid AskSpeed Ask_F_avg_3 Ask_F_avg_6 StM5_733_0 StM5_733_1 StM5_733_2 StM5_733_3"); helpFile.WriteLine("OpenN CloseN Cur_Date flag_F MinLocal MaxLocal OpenSpread CloseSpread CurPointProfit AbsPointProfit Balance BalanceDay MaxFall MaxFallDay CntClosed BigMassNega BigMassPosi AskSpeed Ask_F_avg_3"); DateTime start_time = DateTime.Now; double summ_dt_3; for (int i = 0; ; i++) { if (baseFile.EndOfStream == true || i >= BaseCount) break; if (this.only_full_part.Checked == true && i == 0) { for (int j = 0; j < BaseCountToSkip; j++) { datastring = baseFile.ReadLine(); TicksIn.Count = TicksIn.Count + 1; i++; } } //datastring = baseFile.ReadLine(); ////TicksIn.dataArray = datastring.Split(new Char[] {' '}, 10); //TicksIn.dataArray = datastring.Split(' '); TicksIn.Count = TicksIn.Count + 1; //TicksIn.Date = TicksIn.dataArray[0]; //TicksIn.CurTime = TicksIn.dataArray[1]; TicksIn.CurTime = CurTime[i]; TicksIn.Date = Date_on_time[i]; for (int j = 0; j < dim; j++) { TicksIn.timeStep[j] = TicksIn.timeStep[j + 1]; TicksIn.Ask[j] = TicksIn.Ask[j + 1]; TicksIn.Bid[j] = TicksIn.Bid[j + 1]; TicksIn.AskIncrement[j] = TicksIn.AskIncrement[j + 1]; TicksIn.BidIncrement[j] = TicksIn.BidIncrement[j + 1]; TicksIn.Spread[j] = TicksIn.Spread[j + 1]; TicksOut.AskSpeed[j] = TicksOut.AskSpeed[j + 1]; TicksOut.Ask_F_avg_6[j] = TicksOut.Ask_F_avg_6[j + 1]; } //TicksIn.timeStep[dim] = Convert.ToDouble(TicksIn.dataArray[2]); //TicksIn.Ask[dim] = Convert.ToDouble(TicksIn.dataArray[3]); //TicksIn.Bid[dim] = Convert.ToDouble(TicksIn.dataArray[5]); //TicksIn.AskIncrement[dim] = Convert.ToDouble(TicksIn.dataArray[4]); //TicksIn.BidIncrement[dim] = Convert.ToDouble(TicksIn.dataArray[6]); //TicksIn.Spread[dim] = Math.Abs(TicksIn.Ask[dim] - TicksIn.Bid[dim]) * 100000.0; TicksIn.timeStep[dim] = timeStep[i]; TicksIn.Ask[dim] = Ask[i]; TicksIn.Bid[dim] = Bid[i]; TicksIn.AskIncrement[dim] = AskIncrement[i]; TicksIn.BidIncrement[dim] = BidIncrement[i]; TicksIn.Spread[dim] = Math.Abs(TicksIn.Ask[dim] - TicksIn.Bid[dim]) * 100000.0; if (With_indicators.Checked == true) { //for (int j = TicksIn.StM1_733_0.Length - 1; j > 0; j--) //{ // TicksIn.StM1_733_0[j] = TicksIn.StM1_733_0[j - 1]; //} //TicksIn.StM1_733_0[0] = Convert.ToDouble(TicksIn.dataArray[11]); //TicksIn.StM5_733_0 = Convert.ToDouble(TicksIn.dataArray[7]); //TicksIn.StM5_532_0 = Convert.ToDouble(TicksIn.dataArray[9]); //TicksIn.DifOpenClose_0 = Convert.ToInt32(TicksIn.dataArray[13]); //TicksIn.StdDevM5_40_0 = Convert.ToDouble(TicksIn.dataArray[15]); //if (TicksIn.StM1_733_1 != Convert.ToDouble(TicksIn.dataArray[12])) //{ // TicksIn.StM1_733_4 = TicksIn.StM1_733_3; // TicksIn.StM1_733_3 = TicksIn.StM1_733_2; // TicksIn.StM1_733_2 = TicksIn.StM1_733_1; // TicksIn.StM1_733_1 = Convert.ToDouble(TicksIn.dataArray[12]); //} //if (TicksIn.StM5_733_1 != Convert.ToDouble(TicksIn.dataArray[8])) //{ // TicksIn.StM5_733_4 = TicksIn.StM5_733_3; // TicksIn.StM5_733_3 = TicksIn.StM5_733_2; // TicksIn.StM5_733_2 = TicksIn.StM5_733_1; // TicksIn.StM5_733_1 = Convert.ToDouble(TicksIn.dataArray[8]); // TicksIn.StM5_532_4 = TicksIn.StM5_532_3; // TicksIn.StM5_532_3 = TicksIn.StM5_532_2; // TicksIn.StM5_532_2 = TicksIn.StM5_532_1; // TicksIn.StM5_532_1 = Convert.ToDouble(TicksIn.dataArray[10]); // TicksIn.DifOpenClose_4 = TicksIn.DifOpenClose_3; // TicksIn.DifOpenClose_3 = TicksIn.DifOpenClose_2; // TicksIn.DifOpenClose_2 = TicksIn.DifOpenClose_1; // TicksIn.DifOpenClose_1 = Convert.ToInt32(TicksIn.dataArray[14]); // TicksIn.StdDevM5_40_4 = TicksIn.StdDevM5_40_3; // TicksIn.StdDevM5_40_3 = TicksIn.StdDevM5_40_2; // TicksIn.StdDevM5_40_2 = TicksIn.StdDevM5_40_1; // TicksIn.StdDevM5_40_1 = Convert.ToDouble(TicksIn.dataArray[16]); // TicksIn.iBullsM5_7_4 = TicksIn.iBullsM5_7_3; // TicksIn.iBullsM5_7_3 = TicksIn.iBullsM5_7_2; // TicksIn.iBullsM5_7_2 = TicksIn.iBullsM5_7_1; // TicksIn.iBullsM5_7_1 = Convert.ToDouble(TicksIn.dataArray[17]); // TicksIn.iBearM5_7_4 = TicksIn.iBearM5_7_3; // TicksIn.iBearM5_7_3 = TicksIn.iBearM5_7_2; // TicksIn.iBearM5_7_2 = TicksIn.iBearM5_7_1; // TicksIn.iBearM5_7_1 = Convert.ToDouble(TicksIn.dataArray[18]); //} TicksIn.StM5_733_0 = StM5_733_0[i]; TicksIn.StM5_733_1 = StM5_733_1[i]; TicksIn.StM5_733_2 = StM5_733_2[i]; TicksIn.StM5_733_3 = StM5_733_3[i]; TicksIn.StM5_733_4 = StM5_733_4[i]; TicksIn.Stohastic_Param = TicksIn.StM5_733_3; } //Вычисление индикаторов// summ_dt_3 = TicksIn.timeStep[dim] + TicksIn.timeStep[dim - 1] + TicksIn.timeStep[dim - 2]; TicksOut.AskSpeed[dim] = TicksIn.AskIncrement[dim] / TicksIn.timeStep[dim]; TicksOut.Ask_F_avg_3[dim] = (TicksIn.AskIncrement[dim] + TicksIn.AskIncrement[dim - 1] + TicksIn.AskIncrement[dim - 2]) / Math.Pow(summ_dt_3, 2) * 100000.0; TicksOut.Ask_F_avg_6[dim] = (TicksIn.AskIncrement[dim] + TicksIn.AskIncrement[dim - 1] + TicksIn.AskIncrement[dim - 2] + TicksIn.AskIncrement[dim - 3] + TicksIn.AskIncrement[dim - 4] + TicksIn.AskIncrement[dim - 5]) / Math.Pow(summ_dt_3 + TicksIn.timeStep[dim - 3] + TicksIn.timeStep[dim - 4] + TicksIn.timeStep[dim - 5], 2) * 100000.0; //Пропускаем мимо ситуации, когда ордер открыт в момент ГЭПа по времени. if (WorkClasses.gaps_str.Contains(" " + Convert.ToString(TicksIn.Count) + " ")) { if (Math.Abs(flg_F_avg_6) == 1) { flg_F_avg_6 = 0; TicksOut.ticks_activ_cnt = 0; ticks_active_time = 0.0; for (int j = 0; j < dim+1; j++) { TicksOut.Ask_F_avg_3[j] = 0; TicksOut.Ask_F_avg_4[j] = 0; TicksOut.Ask_F_avg_5[j] = 0; TicksOut.Ask_F_avg_6[j] = 0; TicksOut.Ask_F_avg_7[j] = 0; TicksOut.Ask_F_avg_8[j] = 0; } } } //------------------- if (TicksIn.Count == 8990286) TicksIn.Count = TicksIn.Count; if (Math.Abs(flg_F_avg_6) == 1) { if (flg_F_avg_6 == 1) TicksOut.local_Open_vs_Cur = TicksIn.Bid[dim] - TicksOut.OpenASK; if (flg_F_avg_6 == -1) TicksOut.local_Open_vs_Cur = TicksOut.OpenBID - TicksIn.Ask[dim]; if (StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] < TicksOut.local_Open_vs_Cur * 100000) StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; if (StatInfo.MinLocalProfitInOrder[cnt_closed_orders] > TicksOut.local_Open_vs_Cur * 100000) StatInfo.MinLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; TicksOut.ticks_activ_cnt++; ticks_active_time = ticks_active_time + TicksIn.timeStep[dim]; if (TicksOut.ticks_activ_cnt == 1) { StatInfo.AskIncremBigMassSummNegative[cnt_closed_orders] = TicksIn.AskIncremBigMassSumm_Negative; StatInfo.AskIncremBigMassSummPositive[cnt_closed_orders] = TicksIn.AskIncremBigMassSumm_Positive; } } else if (flg_F_avg_6 == 0) { order_open_time = TicksIn.CurTime; TicksOut.local_Open_vs_Cur = 0; } if (Math.Abs(TicksIn.Ask[dim] - TicksIn.Bid[dim]) * 100000.0 < 4.0) //temp_help.WriteLine(TicksIn.Count + " " + TicksIn.Date + " " + TicksIn.CurTime + " " + (TicksIn.Ask[dim] - TicksIn.Bid[dim]).ToString()); temp_help.WriteLine(datastring); /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ flg_F_avg_6 = ParamVariants.ChouseTheSet(flg_F_avg_6, TicksIn, TicksOut, BaseCountToSkip, this.only_full_part.Checked); /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ if (Math.Abs(flg_F_avg_6) == 1 && TicksOut.ticks_activ_cnt == 0) { Counts_On_Open[cnt_closed_orders] = TicksIn.Count; StatInfo.StartSpread[cnt_closed_orders] = TicksIn.Spread[dim]; if (flg_F_avg_6 < 0) StatInfo.AskSpeedOpen[cnt_closed_orders] = -TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0; else StatInfo.AskSpeedOpen[cnt_closed_orders] = TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0; if (flg_F_avg_6 < 0) StatInfo.Ask_F_avg_3_Open[cnt_closed_orders] = -TicksOut.Ask_F_avg_3[TicksIn.dim - 1]; else StatInfo.Ask_F_avg_3_Open[cnt_closed_orders] = TicksOut.Ask_F_avg_3[TicksIn.dim - 1]; } int count_for_Last_N_profit = 3; if (Math.Abs(flg_F_avg_6) == 2) { if (flg_F_avg_6 == 2) TicksOut.local_Open_vs_Cur = TicksIn.Bid[dim] - TicksOut.OpenASK; if (flg_F_avg_6 == -2) TicksOut.local_Open_vs_Cur = TicksOut.OpenBID - TicksIn.Ask[dim]; if (false) TicksOut.local_Open_vs_Cur = TicksOut.local_Open_vs_Cur - 0.00010; ticks_sum = ticks_sum + TicksOut.local_Open_vs_Cur; TicksOut.Ticks_Sum_on_time[cnt_closed_orders] = ticks_sum * 100000; //Присваиваем текущее значение профита для последующего МНК TicksOut.Date_on_time[cnt_closed_orders] = TicksIn.Date; TicksOut.Cur_Order_Profit[cnt_closed_orders] = (TicksOut.local_Open_vs_Cur) * 100000; TicksOut.flg_F_avg_6[cnt_closed_orders] = flg_F_avg_6; Counts_On_Close[cnt_closed_orders] = TicksIn.Count; StatInfo.CloseSpread[cnt_closed_orders] = TicksIn.Spread[dim]; if (StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] < TicksOut.local_Open_vs_Cur * 100000) StatInfo.MaxLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; if (StatInfo.MinLocalProfitInOrder[cnt_closed_orders] > TicksOut.local_Open_vs_Cur * 100000) StatInfo.MinLocalProfitInOrder[cnt_closed_orders] = TicksOut.local_Open_vs_Cur * 100000; for (int j = 0; j < count_for_Last_N_profit - 1; j++) Last_N_profit[j] = Last_N_profit[j + 1]; Last_N_profit[count_for_Last_N_profit - 1] = (TicksOut.local_Open_vs_Cur) * 100000; double avg_Last_N_profit = 0.0; for (int j = 0; j < count_for_Last_N_profit; j++) avg_Last_N_profit += Last_N_profit[j]; avg_Last_N_profit = avg_Last_N_profit / count_for_Last_N_profit; if (cnt_closed_orders < count_for_Last_N_profit) avg_Last_N_profit = 0; if (avg_Last_N_profit < 0.0) cnt_negative_avg_Last_N_profit++; cnt_closed_orders++; if (flg_F_avg_6 == 2) ResultFile.WriteLine(TicksIn.Count.ToString() + " " + TicksIn.Date + " " + flg_F_avg_6.ToString() + " " + TicksIn.Bid[dim].ToString() + " " + TicksOut.OpenASK.ToString() + " " + TicksOut.ticks_activ_cnt.ToString() + " " + ticks_active_time.ToString() + " " + order_open_time + " " + (TicksOut.local_Open_vs_Cur * 100000).ToString() + " " + (ticks_sum * 100000).ToString() + " " + avg_Last_N_profit.ToString()); if (flg_F_avg_6 == -2) ResultFile.WriteLine(TicksIn.Count.ToString() + " " + TicksIn.Date + " " + flg_F_avg_6.ToString() + " " + TicksOut.OpenBID.ToString() + " " + TicksIn.Ask[dim].ToString() + " " + TicksOut.ticks_activ_cnt.ToString() + " " + ticks_active_time.ToString() + " " + order_open_time + " " + (TicksOut.local_Open_vs_Cur * 100000).ToString() + " " + (ticks_sum * 100000).ToString() + " " + avg_Last_N_profit.ToString()); } if ((TicksIn.Count > 10373200 && TicksIn.Count <= 10373383)) { OutFile.WriteLine(TicksIn.Count + " " + TicksIn.CurTime + " " + TicksIn.timeStep[dim] + " " + TicksIn.Ask[dim] + " " + TicksIn.Bid[dim] + " " + (TicksIn.AskIncrement[dim] * 100000) + " " + flg_F_avg_6 + " " + TicksOut.ticks_activ_cnt + " " + ticks_active_time + " " + ((TicksIn.Bid[dim] - TicksOut.OpenASK) * 100000) + " " + ((TicksOut.OpenBID - TicksIn.Bid[dim]) * 100000) + " " + TicksOut.AskSpeed[dim] + " " + TicksOut.Ask_F_avg_3[dim] + " " + TicksOut.Ask_F_avg_6[dim] + " " + TicksIn.StM5_733_0 + " " + TicksIn.StM5_733_1 + " " + TicksIn.StM5_733_2 + " " + TicksIn.StM5_733_3); } if (flg_F_avg_6 == -2 || flg_F_avg_6 == 2) { flg_F_avg_6 = 0; TicksOut.ticks_activ_cnt = 0; ticks_active_time = 0.0; } } temp_help.Close(); //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- int cnt_of_start_last_date = 0; double[] Cur_Day_Profit = new double[cnt_closed_orders], Ticks_Sum_on_Day = new double[cnt_closed_orders]; for (int i = 0; i < cnt_closed_orders; i++) { if (TicksOut.Date_on_time[i] == TicksOut.Date_on_time[cnt_closed_orders - 1]) { cnt_of_start_last_date = i; break; } } for (int i = 0; i <= cnt_of_start_last_date; i++) { string temp_date = TicksOut.Date_on_time[i]; Cur_Day_Profit[i] = TicksOut.Cur_Order_Profit[i]; if (i == 0) Ticks_Sum_on_Day[i] = TicksOut.Cur_Order_Profit[i]; else Ticks_Sum_on_Day[i] = Ticks_Sum_on_Day[i - 1] + TicksOut.Cur_Order_Profit[i]; for (int j = i + 1; j < cnt_closed_orders; j++) { if (TicksOut.Date_on_time[j] != temp_date) { for (int t = j - 1; t > i; t--) { Cur_Day_Profit[t] = Cur_Day_Profit[i]; Ticks_Sum_on_Day[t] = Ticks_Sum_on_Day[i]; } i = j - 1; break; } Cur_Day_Profit[i] += TicksOut.Cur_Order_Profit[j]; Ticks_Sum_on_Day[i] += TicksOut.Cur_Order_Profit[j]; } if (i == cnt_of_start_last_date && cnt_of_start_last_date != (cnt_closed_orders - 1)) { for (int j = cnt_of_start_last_date+1; j < cnt_closed_orders; j++) { Ticks_Sum_on_Day[j] = Ticks_Sum_on_Day[cnt_of_start_last_date]; } } } //Аппроксимируем прямой double[] residuals = new double[cnt_closed_orders]; double s_xy = 0.0, s_x = 0.0, s_y = 0.0, s_x2 = 0.0; for (int i = 0; i < cnt_closed_orders; i++) { s_x += i+1; s_y += TicksOut.Ticks_Sum_on_time[i]; s_xy += TicksOut.Ticks_Sum_on_time[i] * (i + 1); s_x2 += (i + 1) * (i + 1); } double a = (cnt_closed_orders * s_xy - s_x * s_y) / (cnt_closed_orders * s_x2 - s_x * s_x); double b = (s_y - a * s_x) / (cnt_closed_orders); double[] Max_FALL = new double[cnt_closed_orders * cnt_closed_orders], Max_FALL_byDay = new double[cnt_closed_orders * cnt_closed_orders]; for (int i = 0; i < cnt_closed_orders; i++) { StatInfo.residual_avg_MNK += Math.Abs((TicksOut.Ticks_Sum_on_time[i] - (a * (i + 1) + b))); StatInfo.residual_avg_MNM += Math.Abs((TicksOut.Ticks_Sum_on_time[i] - (a * (i + 1) + b)) * Math.Cos(Math.Atan(a))); if (TicksOut.flg_F_avg_6[i] == -2) StatInfo.SELL_summ_slice += TicksOut.Cur_Order_Profit[i]; if (TicksOut.flg_F_avg_6[i] == 2) StatInfo.BUY_summ_slice += TicksOut.Cur_Order_Profit[i]; for (int j = 0; j < i; j++) { Max_FALL[i * i + j] = TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - j - 1]; Max_FALL_byDay[i * i + j] = Ticks_Sum_on_Day[i] - Ticks_Sum_on_Day[i - j - 1]; } } StatInfo.MaxFALLbyOrder = Max_FALL.Min(); if (StatInfo.MaxFALLbyOrder > -0.1) StatInfo.MaxFALLbyOrder = 1; StatInfo.MaxFALLbyDay = Max_FALL_byDay.Min(); if (StatInfo.MaxFALLbyDay > -0.1) StatInfo.MaxFALLbyDay = 1; StatInfo.residual_avg_MNK = StatInfo.residual_avg_MNK / cnt_closed_orders; StatInfo.residual_avg_MNM = StatInfo.residual_avg_MNM / cnt_closed_orders; double Balance = 3000.0, Balance_Day = 3000.0; for (int i = 0; i < cnt_closed_orders; i++) { residuals[i] = Math.Abs((TicksOut.Ticks_Sum_on_time[i] - (a * (i + 1) + b))); if (i != 0) Balance_Day = Balance_Day + (TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - 1]) * Math.Min((0.10 * Balance_Day) / Math.Abs(StatInfo.MaxFALLbyDay), 100.0); else Balance_Day = Balance_Day + (TicksOut.Ticks_Sum_on_time[i]) * (0.10 * Balance_Day) / Math.Abs(StatInfo.MaxFALLbyDay); if (i != 0) Balance = Balance + (TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - 1]) * Math.Min((0.10 * Balance) / Math.Abs(StatInfo.MaxFALLbyOrder), 100.0); else Balance = Balance + (TicksOut.Ticks_Sum_on_time[i]) * (0.10 * Balance) / Math.Abs(StatInfo.MaxFALLbyOrder); helpFile.WriteLine((Counts_On_Open[i]) + " " + (Counts_On_Close[i]) + " " + TicksOut.Date_on_time[i] + " " + TicksOut.flg_F_avg_6[i] + " " + StatInfo.MinLocalProfitInOrder[i] + " " + StatInfo.MaxLocalProfitInOrder[i] + " " + StatInfo.StartSpread[i] + " " + StatInfo.CloseSpread[i] + " " + TicksOut.Cur_Order_Profit[i] + " " + TicksOut.Ticks_Sum_on_time[i] + " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(Balance_Day).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0] + " " + cnt_closed_orders //+ " " + (a * (i + 1) + b) + " " + residuals[i] + " " + a + " " + StatInfo.residual_avg_MNK + " " + StatInfo.SELL_summ_slice + " " + StatInfo.BUY_summ_slice + " " + StatInfo.AskIncremBigMassSummNegative[i] + " " + StatInfo.AskIncremBigMassSummPositive[i] + " " + StatInfo.AskSpeedOpen[i] + " " + StatInfo.Ask_F_avg_3_Open[i]); } //---ПО ДНЯМ, МЕСЯЦАМ---// Balance = 3000.0; double profit_by_day = 0.0, profit_by_month = 0.0; for (int i = 0; i < cnt_closed_orders; i++) { if (i != 0) Balance = Balance + (TicksOut.Ticks_Sum_on_time[i] - TicksOut.Ticks_Sum_on_time[i - 1]) * Math.Min((0.10 * Balance_Day) / Math.Abs(StatInfo.MaxFALLbyDay), 100.0); else Balance = Balance + (TicksOut.Ticks_Sum_on_time[i]) * Math.Min((0.10 * Balance_Day) / Math.Abs(StatInfo.MaxFALLbyDay), 100.0); if (i != 0) { if (TicksOut.Date_on_time[i] != TicksOut.Date_on_time[i - 1]) { //if (i != cnt_closed_orders - 1) helpFile_byDays.WriteLine((Counts_On_Close[i]).ToString() + " " + TicksOut.Date_on_time[i - 1] + " " + profit_by_day.ToString() + " " + TicksOut.Ticks_Sum_on_time[i - 1].ToString() + " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0]); profit_by_day = 0.0; } if (TicksOut.Date_on_time[i].Split('.')[1] != TicksOut.Date_on_time[i - 1].Split('.')[1]) { if (i != cnt_closed_orders - 1) helpFile_byMonth.WriteLine((Counts_On_Close[i]).ToString() + " " + TicksOut.Date_on_time[i - 1].Split('.')[0] + "." + TicksOut.Date_on_time[i - 1].Split('.')[1] + " " + profit_by_month.ToString() + " " + TicksOut.Ticks_Sum_on_time[i - 1].ToString() + " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0]); profit_by_month = 0.0; } } profit_by_day += TicksOut.Cur_Order_Profit[i]; profit_by_month += TicksOut.Cur_Order_Profit[i]; if (i == cnt_closed_orders - 1) { helpFile_byDays.WriteLine((Counts_On_Close[i]).ToString() + " " + TicksOut.Date_on_time[i] + " " + profit_by_day.ToString() + " " + TicksOut.Ticks_Sum_on_time[i].ToString() + " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0]); helpFile_byMonth.WriteLine((Counts_On_Close[i]).ToString() + " " + TicksOut.Date_on_time[i].Split('.')[0] + "." + TicksOut.Date_on_time[i].Split('.')[1] + " " + profit_by_month.ToString() + " " + TicksOut.Ticks_Sum_on_time[i].ToString() + " " + Convert.ToString(Balance).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyOrder).Split('.')[0] + " " + Convert.ToString(StatInfo.MaxFALLbyDay).Split('.')[0]); } } helpFile_byMonth.Close(); DateTime start_end = DateTime.Now; Console.WriteLine(" "); Console.WriteLine("Итог: " + (ticks_sum * 100000).ToString().Split('.')[0] + " time = " + (start_end - start_time).ToString()); Console.WriteLine(" "); ResultFile.Close(); helpFile.Close(); helpFile_byDays.Close(); OutFile.Close(); DetailResultFile.Close(); //this.Close(); }
public static int ChouseTheSet(int flg_F_avg_6, WorkClasses.Ticks_In TicksIn, WorkClasses.Ticks_Out TicksOut, int BaseCountToSkip, bool only_full_part) { //---FullScan + Limit + Ind----------------------------------------------------------------------------------------------------------------------------- //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 9, 9, 4.37, 4.37, 0.00011, 0.00011, 450, 450, 22, 89, "new", "new", 0, 0, 0, 0, 0); //3744 11195 12855 -267 -239 88 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 9, 9, 4.65, 4.65, 0.00009, 0.00009, 450, 450, 22, 89, "new", "new", 0, 0, 0, 0, 0, 0, 0); //3811 20743 22277 -181 -174 73 //окейный медленный //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 11, 11, 3.44, 3.44, 0.00012, 0.00012, 0, 0, 22, 99, "old", "old", 0, 0, 0, 0, 0); //2695 10112 10112 -208 -208 85 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 11, 11, 4.30, 4.30, 0.00010, 0.00012, 0, 0, 22, 89, "new", "new", 0, 0, 0, 0, 0, 0, 0, 0, 0); //(!!!!!)3163 143741 143741 -64 -64 39 //* //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 11, 11, 3.45, 3.45, 0.00009, 0.00009, 2310, 2310, 22, 89, "new", "new", 0, 0, 0, 0, 0); //3158 9931 16134 -247 -172 82 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 11, 11, 3.75, 3.75, 0.00009, 0.00009, 2310, 2310, 22, 89, "new", "new", 0, 0, 0, 0, 0); //3240 20937 57748 -151 -95 67 //Only SELL +IND------------------------------------------------------------------------------------------------------------------------------------- //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 10, 10, 3.00, 3.00, 0.00014, 0.00014, 770, 770, 26, 97, "new", "new", 0, 0, 0, 0, 0,0,0); //4564 10030 12372 -362 -306 65 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 10, 10, 3.03, 3.03, 0.00015, 0.00015, 2000, 2000, 22, 99, "old", "old", 0, 0, 0, 0, 0,0,0); //3249 13419 13419 -202 -202 61 /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 10, 10, 3.00, 4.52, 0.00014, 0.00012, 725, 250, 30, 97, "new", "new", 350, 620, 300.0, 0, 225.0, 0, 9); //8161 15028 19976 -490 -414 123 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 10, 9, 3.08, 4.68, 0.00013, 0.00013, 725, 250, 30, 97, "new", "new", 350, 620, 300.0, 225.0, 9); //7746 14891 14891 -467 -467 124 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 10, 10, 3.00, 4.62, 0.00013, 0.00012, 725, 250, 30, 97, "new", "new", 350, 620, 300.0, 225.0, 9); //7684 25946 46598 -341 -265 122 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 20, flg_F_avg_6, 10, 10, 3.00, 4.72, 0.00014, 0.00012, 725, 250, 30, 97, "new", "new", 350, 620, 300.0, 225.0, 9); //8169 23342 37884 -382 -306 119 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 18, flg_F_avg_6, 11, 10, 3.59, 4.72, 13E-5, 11E-5, 725, 275, 30, 94, "new", "new", 350, 350, 300.0, 225.0, 9); //5569 38520 84001 -203 -151 86 (Хорош после 09.2013) //---Можно изменить правило выхода на: "TicksIn.StM5_733_2 > TicksIn.StM5_733_1 - 5.0"---// TicksIn.SellCustomSthCorrection = 0.0; TicksIn.SellCustomSthCorrection = 5.0; //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 10, 3.09, 4.70, 13E-5, 11E-5, 800, 275, 30, 94, "new", "new", 350, 350, 0, 0, 0, 0, 0); //5049 11017 11017 -375 -375 96 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 10, 3.09, 4.70, 13E-5, 11E-5, 800, 275, 30, 94, "new", "new", 350, 350, 200, 60, 125, 30, 6); //6892 21333 21333 -333 -333 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 11, 3.09, 4.34, 13E-5, 12E-5, 775, 375, 30, 94, "new", "new", 350, 350, 240, 0, 180, 0, 7); //7089 30053 30053 -292 -292 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 11, 3.09, 4.78, 13E-5, 12E-5, 775, 275, 30, 94, "new", "new", 350, 350, 240, 0, 180, 0, 7); //6970 28949 28949 -292 -292 124 //flg_F_avg_6 = StrtStp.Start_and_StopFLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 10, 3.09, 4.70, 13E-5, 11E-5, 800, 275, 30, 94, "new", "new", 350, 350, 350, 0, 180, 0, 6); //7455 30433 72837 -307 -219 127 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 10, 3.09, 4.70, 13E-5, 11E-5, 800, 275, 30, 94, "new", "new", 350, 350, 220, 0, 180, 0, 6); //7443 18892 18892 -388 -388 139 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 10, 3.15, 4.85, 13E-5, 11E-5, 800, 275, 30, 94, "new", "new", 350, 350, -0, -0, 220, 0, 180, 0, 6); //(!)7281 82381 82381 -204 -204 130 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 10, 3.50, 3.90, 11E-5, 11E-5, 800, 275, 30, 94, "new", "new", 350, 350, 220, 0, 180, 0, 6); //5082 22147 36993 -234 -182 160 //===После перевода на ECN 22.07.14=== //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 0, flg_F_avg_6, 10, 0, 4.20, 0.0, 17E-5, 0E-5, 0, 0, 22, 82, "new", "new", 0, 300, -0, -0, 0, 0, 0, 0, 0); //(!)3334 18833 59525 -166 -96 39 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 0, 5.60, 0.0, 10E-5, 0E-5, 1200, 0, 30, 94, "new", "new", 0, 350, 0, 0, 0, 0, 0); //714 8863 10290 -57 -49 28 (но нет) //===НОВАЯ ИСТОРИЯ 2015 ===// //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 25, 21, flg_F_avg_6, 12, 9, 5.5, 4.5, 29E-5, 28E-5, 0, 0, 19, 96, "new", "new", 0, 300, -0, -600, /**/ 0, 0, 0, 0, 0); //5796 5967 7367 -809 -612 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 25, 21, flg_F_avg_6, 12, 9, 7.1, 4.5, 27E-5, 28E-5, 0, 0, 19, 86, "new", "new", 0, 150, -0, -0, /**/ 0, 0, 0, 0, 0); //5668 9092 24908 -494 -251 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 25, 21, flg_F_avg_6, 12, 9, 7.0, 4.5, 29E-5, 28E-5, 0, 0, 19, 96, "new", "new", 0, 150, -0, -500, /**/ 0, 0, 0, 0, 0); //5213 6230 10630 -691 -389 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 25, 21, flg_F_avg_6, 12, 9, 7.1, 4.5, 29E-5, 28E-5, 0, 0, 19, 86, "new", "new", 0, 150, -0, -450, /**/ 0, 0, 0, 0, 0); //5030 7887 13930 -494 -300 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 25, 21, flg_F_avg_6, 12, 9, 7.5, 4.5, 27E-5, 28E-5, 0, 0, 19, 86, "new", "new", 0, 200, -0, -0, /**/ 0, 0, 0, 0, 0); //4537 8243 15959 -428 -251 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 25, 21, flg_F_avg_6, 13, 9, 6.50, 4.5, 29E-5, 28E-5, 0, 0, 19, 96, "new", "new", 0, 200, -0, -500, /**/ 0, 0, 0, 0, 0); //4392 6944 6944 -502 -502 хорош в конце июля 2015 //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 9, 9.50, 4.5, 28E-5, 28E-5, 0, 0, 19, 96, "new", "new", 150, 120, -0, -350, /**/100, 300, 100, 300, 9); //4300 4777 5684 -888 -636 bigmass //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 9, 9.50, 4.5, 28E-5, 28E-5, 0, 0, 19, 96, "new", "new", 150, 120, -0, -350, /**/ 0, 0, 0, 0, 0); //3748 4380 4982 -950 -698 flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 9, 9.50, 4.5, 28E-5, 28E-5, 0, 0, 19, 96, "new", "new", 150, 120, -0, -350, /**/ 0, 0, 0, 0, 0); //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 9, 9.50, 4.5, 28E-5, 28E-5, 0, 0, 19, 96, "new", "new", 150, 120, -0, -350, /**/ 0, 0, 0, 0, 0); //На этом можно прогонять подбор параметров определения трендов //flg_F_avg_6 = StrtStp.Start_and_Stop_FLG(TicksIn, TicksOut, 35, 21, flg_F_avg_6, 10, 11, 9.50, 6.5, 28E-5, 30E-5, 0, 0, 19, 96, "new", "new", 200, 120, -0, -350, /**/ 0, 0, 0, 0, 0); //Buy+Sell 6812 4614 14773 -1536 -374 123 if (TicksIn.Count == 1 || (TicksIn.Count == BaseCountToSkip + 1 && only_full_part == true)) { TicksIn.Count = TicksIn.Count; } return(flg_F_avg_6); }
/*----------------------------------------------------------------------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------------------------------------------------------------------*/ private void AppendToBaseFile_Click(object sender, EventArgs e) { string datastring = null; string[] dataArray; StreamReader baseFile = new StreamReader(WorkClasses.dir_str + "//Ticks_base.txt"); StreamReader baseFile_Indic = new StreamReader(WorkClasses.dir_str + "//Ticks_base_indicator.txt"); StreamReader addFile = new StreamReader(WorkClasses.dir_str + "//To_append.txt"); StreamWriter OutFileOnlyCountTime = new StreamWriter(WorkClasses.dir_str + "//Ticks_base_CountTime.txt"); StreamWriter OutFile = new StreamWriter(WorkClasses.dir_str + "//Ticks_base_out.txt"); StreamWriter OutFile_Indic = new StreamWriter(WorkClasses.dir_str + "//Ticks_base_indicator_out.txt"); WorkClasses.Ticks_In TicksIn = new WorkClasses.Ticks_In(); WorkClasses.Ticks_Out TicksOut = new WorkClasses.Ticks_Out(); datastring = baseFile.ReadLine(); OutFile.WriteLine("Date CurTime timeStep Ask AskIncrement Bid BidIncrement"); for (int i = 0; ; i++) { if (baseFile.EndOfStream == true) break; datastring = baseFile.ReadLine(); dataArray = datastring.Split(' '); TicksIn.Count = TicksIn.Count + 1; TicksIn.Date = dataArray[0]; TicksIn.CurTime = dataArray[1]; TicksIn.timeStep[TicksIn.dim - 1] = Convert.ToDouble(dataArray[2]); TicksIn.Ask[TicksIn.dim - 1] = Convert.ToDouble(dataArray[3]); TicksIn.Bid[TicksIn.dim - 1] = Convert.ToDouble(dataArray[5]); TicksIn.AskIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[4]); TicksIn.BidIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[6]); if (TicksIn.Count == 5379135 || TicksIn.Count == 4429261 || TicksIn.Count == 4185063 || TicksIn.Count == 1244670) TicksIn.Count = TicksIn.Count; OutFile.WriteLine(TicksIn.Date + " " + TicksIn.CurTime.ToString() + " " + TicksIn.timeStep[TicksIn.dim - 1].ToString() + " " + TicksIn.Ask[TicksIn.dim - 1].ToString() + " " + TicksIn.AskIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.Bid[TicksIn.dim - 1].ToString() + " " + TicksIn.BidIncrement[TicksIn.dim - 1].ToString()); if (i % 5 == 0) OutFileOnlyCountTime.WriteLine(TicksIn.Count + " " + TicksIn.Date); } datastring = addFile.ReadLine(); for (int i = 0; ; i++) { if (addFile.EndOfStream == true) break; datastring = addFile.ReadLine(); dataArray = datastring.Split(' '); TicksIn.Count = TicksIn.Count + 1; TicksIn.Date = dataArray[1]; TicksIn.CurTime = dataArray[2]; TicksIn.timeStep[TicksIn.dim - 1] = Convert.ToDouble(dataArray[3]); TicksIn.Ask[TicksIn.dim - 1] = Convert.ToDouble(dataArray[4]); TicksIn.Bid[TicksIn.dim - 1] = Convert.ToDouble(dataArray[6]); TicksIn.AskIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[5]); TicksIn.BidIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[7]); OutFile.WriteLine(TicksIn.Date + " " + TicksIn.CurTime.ToString() + " " + TicksIn.timeStep[TicksIn.dim - 1].ToString() + " " + TicksIn.Ask[TicksIn.dim - 1].ToString() + " " + TicksIn.AskIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.Bid[TicksIn.dim - 1].ToString() + " " + TicksIn.BidIncrement[TicksIn.dim - 1].ToString()); if (i % 5 == 0) OutFileOnlyCountTime.WriteLine(TicksIn.Count + " " + TicksIn.Date); } OutFile.Close(); addFile.Close(); OutFileOnlyCountTime.Close(); StreamReader addFile1 = new StreamReader(WorkClasses.dir_str + "//To_append.txt"); TicksIn.Count = 0; //-------------------------------------------------------------------------------------------------------------------------------------------------// //-------------------------------------------------------------------------------------------------------------------------------------------------// //-------------------------------------------------------------------------------------------------------------------------------------------------// datastring = baseFile_Indic.ReadLine(); OutFile_Indic.WriteLine("date time time_step ask ask_ink bid bid_ink StM5_733_0 StM5_733_1 StM5_522_0 StM5_522_1 StM1_733_0 StM1_733_1 Close_open_now Close_open_prev std_cur std_prev bulls bear"); for (int i = 0; ; i++) { if (baseFile_Indic.EndOfStream == true) break; datastring = baseFile_Indic.ReadLine(); dataArray = datastring.Split(' '); TicksIn.Count = TicksIn.Count + 1; TicksIn.Date = dataArray[0]; TicksIn.CurTime = dataArray[1]; TicksIn.timeStep[TicksIn.dim - 1] = Convert.ToDouble(dataArray[2]); TicksIn.Ask[TicksIn.dim - 1] = Convert.ToDouble(dataArray[3]); TicksIn.Bid[TicksIn.dim - 1] = Convert.ToDouble(dataArray[5]); TicksIn.AskIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[4]); TicksIn.BidIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[6]); TicksIn.StM5_733_0 = Math.Round(Convert.ToDouble(dataArray[7]), 2); TicksIn.StM5_733_1 = Math.Round(Convert.ToDouble(dataArray[8]), 2); TicksIn.StM5_532_0 = Math.Round(Convert.ToDouble(dataArray[9]), 2); TicksIn.StM5_532_1 = Math.Round(Convert.ToDouble(dataArray[10]), 2); TicksIn.StM1_733_0[0] = Math.Round(Convert.ToDouble(dataArray[11]), 2); TicksIn.StM1_733_1 = Math.Round(Convert.ToDouble(dataArray[12]), 2); TicksIn.DifOpenClose_0 = Convert.ToInt32(dataArray[13]); TicksIn.DifOpenClose_1 = Convert.ToInt32(dataArray[14]); TicksIn.StdDevM5_40_0 = Math.Round(Convert.ToDouble(dataArray[15]), 2); TicksIn.StdDevM5_40_1 = Math.Round(Convert.ToDouble(dataArray[16]), 2); TicksIn.iBullsM5_7_1 = Math.Round(Convert.ToDouble(dataArray[17]), 2); TicksIn.iBearM5_7_1 = Math.Round(Convert.ToDouble(dataArray[18]), 2); if (TicksIn.Count == 5379135 || TicksIn.Count == 4429261 || TicksIn.Count == 4185063 || TicksIn.Count == 1244670) TicksIn.Count = TicksIn.Count; OutFile_Indic.WriteLine(TicksIn.Date + " " + TicksIn.CurTime.ToString() + " " + TicksIn.timeStep[TicksIn.dim - 1].ToString() + " " + TicksIn.Ask[TicksIn.dim - 1].ToString() + " " + TicksIn.AskIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.Bid[TicksIn.dim - 1].ToString() + " " + TicksIn.BidIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.StM5_733_0 + " " + TicksIn.StM5_733_1 + " " + TicksIn.StM5_532_0 + " " + TicksIn.StM5_532_1 + " " + TicksIn.StM1_733_0[0] + " " + TicksIn.StM1_733_1 + " " + TicksIn.DifOpenClose_0 + " " + TicksIn.DifOpenClose_1 + " " + TicksIn.StdDevM5_40_0 + " " + TicksIn.StdDevM5_40_1 + " " + TicksIn.iBullsM5_7_1 + " " + TicksIn.iBearM5_7_1); } string CurDate = TicksIn.Date; datastring = addFile1.ReadLine(); StreamWriter ParsOpenAndCloseMoments = new StreamWriter(WorkClasses.dir_str + "//Ticks_appended_OpenVsClose.txt"); ParsOpenAndCloseMoments.WriteLine("Count Date Time dttm_milli Aks Bid flag_avg_F_6 ticket Dif_int ticks_activ GetLastError _OrderOpenPrice _OrderClosePrice Time_Of_Tick"); int cntOutputAfterClose = 0; for (int i = 0; ; i++) { if (addFile1.EndOfStream == true) break; datastring = addFile1.ReadLine(); dataArray = datastring.Split(' '); TicksIn.Count = TicksIn.Count + 1; TicksIn.Date = dataArray[1]; TicksIn.CurTime = dataArray[2]; TicksIn.timeStep[TicksIn.dim - 1] = Convert.ToDouble(dataArray[3]); TicksIn.Ask[TicksIn.dim - 1] = Convert.ToDouble(dataArray[4]); TicksIn.Bid[TicksIn.dim - 1] = Convert.ToDouble(dataArray[6]); TicksIn.AskIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[5]); TicksIn.BidIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[7]); TicksIn.StM5_733_0 = Math.Round(Convert.ToDouble(dataArray[11]), 2); TicksIn.StM5_733_1 = Math.Round(Convert.ToDouble(dataArray[12]), 2); TicksIn.StM5_532_0 = Math.Round(Convert.ToDouble(dataArray[13]), 2); TicksIn.StM5_532_1 = Math.Round(Convert.ToDouble(dataArray[14]), 2); TicksIn.StM1_733_0[0] = Math.Round(Convert.ToDouble(dataArray[15]), 2); TicksIn.StM1_733_1 = Math.Round(Convert.ToDouble(dataArray[16]), 2); TicksIn.DifOpenClose_0 = Convert.ToInt32(dataArray[17]); TicksIn.DifOpenClose_1 = Convert.ToInt32(dataArray[18]); TicksIn.StdDevM5_40_0 = Math.Round(Convert.ToDouble(dataArray[19]), 2); TicksIn.StdDevM5_40_1 = Math.Round(Convert.ToDouble(dataArray[20]), 2); TicksIn.iBullsM5_7_1 = Math.Round(Convert.ToDouble(dataArray[21]), 2); TicksIn.iBearM5_7_1 = Math.Round(Convert.ToDouble(dataArray[22]), 2); //---выводим моменты открытия-закрытия из добавляемого файла cntOutputAfterClose--; if (Math.Abs(Convert.ToDouble(dataArray[8])) == 1) cntOutputAfterClose = 10; if ( (Math.Abs(Convert.ToDouble(dataArray[8])) == 1 && Convert.ToDouble(dataArray[23]) >= 0 && Convert.ToDouble(dataArray[23]) < 10) || ((Math.Abs(Convert.ToDouble(dataArray[8])) == 2 || Math.Abs(Convert.ToDouble(dataArray[8])) == 0) && cntOutputAfterClose > 0)) { ParsOpenAndCloseMoments.WriteLine(TicksIn.Count + " " + TicksIn.Date + " " + TicksIn.CurTime + " " + TicksIn.timeStep[TicksIn.dim - 1] + " " + TicksIn.Ask[TicksIn.dim - 1] + " " + TicksIn.Bid[TicksIn.dim - 1] + " " + dataArray[8] + " " + dataArray[9] + " " + dataArray[10] + " " + dataArray[23] + " " + dataArray[24] + " " + dataArray[28] + " " + dataArray[29] + " " + dataArray[30]); } OutFile_Indic.WriteLine(TicksIn.Date + " " + TicksIn.CurTime.ToString() + " " + TicksIn.timeStep[TicksIn.dim - 1].ToString() + " " + TicksIn.Ask[TicksIn.dim - 1].ToString() + " " + TicksIn.AskIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.Bid[TicksIn.dim - 1].ToString() + " " + TicksIn.BidIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.StM5_733_0 + " " + TicksIn.StM5_733_1 + " " + TicksIn.StM5_532_0 + " " + TicksIn.StM5_532_1 + " " + TicksIn.StM1_733_0[0] + " " + TicksIn.StM1_733_1 + " " + TicksIn.DifOpenClose_0 + " " + TicksIn.DifOpenClose_1 + " " + TicksIn.StdDevM5_40_0 + " " + TicksIn.StdDevM5_40_1 + " " + TicksIn.iBullsM5_7_1 + " " + TicksIn.iBearM5_7_1); } OutFile.Close(); OutFile_Indic.Close(); baseFile_Indic.Close(); OutFile_Indic.Close(); addFile1.Close(); ParsOpenAndCloseMoments.Close(); Console.WriteLine("Последник каунт = " + TicksIn.Count); //datastring = null; //baseFile_Indic = new StreamReader(WorkClasses.dir_str + "//Ticks_base_indicator_out.txt"); //OutFile_Indic = new StreamWriter(WorkClasses.dir_str + "//Ticks_base_ind_local.txt"); //TicksIn = new WorkClasses.Ticks_In(); //TicksOut = new WorkClasses.Ticks_Out(); //datastring = baseFile_Indic.ReadLine(); //OutFile_Indic.WriteLine("Count Date CurTime timeStep Ask AskIncrement Bid BidIncrement"); //datastring = baseFile_Indic.ReadLine(); //for (int i = 0; ; i++) //{ // if (baseFile_Indic.EndOfStream == true) break; // datastring = baseFile_Indic.ReadLine(); // dataArray = datastring.Split(' '); // TicksIn.Count = TicksIn.Count + 1; // TicksIn.Date = dataArray[1]; // TicksIn.CurTime = dataArray[2]; // TicksIn.timeStep[TicksIn.dim - 1] = Convert.ToDouble(dataArray[3]); // TicksIn.Ask[TicksIn.dim - 1] = Convert.ToDouble(dataArray[4]); // TicksIn.Bid[TicksIn.dim - 1] = Convert.ToDouble(dataArray[6]); // TicksIn.AskIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[5]); // TicksIn.BidIncrement[TicksIn.dim - 1] = Convert.ToDouble(dataArray[7]); // TicksIn.StM5_733_0 = Convert.ToDouble(dataArray[8]); // TicksIn.StM5_733_1 = Convert.ToDouble(dataArray[9]); // TicksIn.StM5_733_2 = Convert.ToDouble(dataArray[10]); // TicksIn.StM5_733_3 = Convert.ToDouble(dataArray[11]); // TicksIn.StM5_733_4 = Convert.ToDouble(dataArray[12]); // //TicksIn.StM5_734_0 = Convert.ToDouble(dataArray[13]); // //TicksIn.StM5_734_1 = Convert.ToDouble(dataArray[14]); // //TicksIn.StM5_734_2 = Convert.ToDouble(dataArray[15]); // //TicksIn.StM5_734_3 = Convert.ToDouble(dataArray[16]); // //TicksIn.StM5_734_4 = Convert.ToDouble(dataArray[17]); // //TicksIn.StM15_733_0 = Convert.ToDouble(dataArray[18]); // //TicksIn.StM15_733_1 = Convert.ToDouble(dataArray[19]); // //TicksIn.StM15_733_2 = Convert.ToDouble(dataArray[20]); // //TicksIn.StM15_733_3 = Convert.ToDouble(dataArray[21]); // //TicksIn.StM15_733_4 = Convert.ToDouble(dataArray[22]); // //TicksIn.StM15_734_0 = Convert.ToDouble(dataArray[23]); // //TicksIn.StM15_734_1 = Convert.ToDouble(dataArray[24]); // //TicksIn.StM15_734_2 = Convert.ToDouble(dataArray[25]); // //TicksIn.StM15_734_3 = Convert.ToDouble(dataArray[26]); // //TicksIn.StM15_734_4 = Convert.ToDouble(dataArray[27]); // OutFile_Indic.WriteLine(TicksIn.Count.ToString() + " " + TicksIn.Date + " " + TicksIn.CurTime.ToString() + " " + TicksIn.timeStep[TicksIn.dim - 1].ToString() + " " + TicksIn.Ask[TicksIn.dim - 1].ToString() + " " + // TicksIn.AskIncrement[TicksIn.dim - 1].ToString() + " " + TicksIn.Bid[TicksIn.dim - 1].ToString() + " " + TicksIn.BidIncrement[TicksIn.dim - 1].ToString() // + " " + TicksIn.StM5_733_0.ToString() + " " + TicksIn.StM5_733_1.ToString() + " " + TicksIn.StM5_733_2.ToString() + " " + TicksIn.StM5_733_3.ToString() + " " + TicksIn.StM5_733_4.ToString()); //} //OutFile_Indic.Close(); //baseFile_Indic.Close(); baseFile.Close(); File.Move(WorkClasses.dir_str + "//Ticks_base_indicator.txt", WorkClasses.dir_str + "//" + CurDate + "_Ticks_base_indicator.txt"); File.Move(WorkClasses.dir_str + "//Ticks_base.txt", WorkClasses.dir_str + "//" + CurDate + "_Ticks_base.txt"); File.Move(WorkClasses.dir_str + "//Ticks_base_indicator_out.txt", WorkClasses.dir_str + "//Ticks_base_indicator.txt"); File.Move(WorkClasses.dir_str + "//Ticks_base_out.txt", WorkClasses.dir_str + "//Ticks_base.txt"); CurDate = TicksIn.Date; File.Move(WorkClasses.dir_str + "//To_append.txt", WorkClasses.dir_str + "//Ticks_Log_" + CurDate + ".txt"); File.Move(WorkClasses.dir_str + "//Ticks_Log_" + CurDate + ".txt", WorkClasses.dir_str + "//archive//" + CurDate.Split('.')[0] + "." + CurDate.Split('.')[1] + "//Ticks_Log_" + CurDate + ".txt"); this.Close(); }
private void DoShortFile_Click(object sender, EventArgs e) { string datastring = ""; WorkClasses.Ticks_In TicksIn = new WorkClasses.Ticks_In(); WorkClasses.base_file_name = "//Ticks_base_indicator.txt"; StreamReader baseFile = new StreamReader(WorkClasses.dir_str + WorkClasses.base_file_name); StreamWriter baseFileShort = new StreamWriter(WorkClasses.dir_str + "//Ticks_base_indicator_Short.txt"); StreamWriter _i_BigSTD = new StreamWriter(WorkClasses.dir_str + "//_i_BigSTD.txt"); datastring = baseFile.ReadLine(); //1000 2000 50.0 int intervalLeft = 1000; int intervalRight = 2000; double initStdDevM5_40_1 = 50.0; for (int i = 0; ; i++) { if (baseFile.EndOfStream == true) break; datastring = baseFile.ReadLine(); TicksIn.dataArray = datastring.Split(' '); if (Convert.ToDouble(TicksIn.dataArray[16]) > initStdDevM5_40_1 && TicksIn.StdDevM5_40_1 != Convert.ToDouble(TicksIn.dataArray[16])) { _i_BigSTD.WriteLine(i); } TicksIn.StdDevM5_40_0 = Convert.ToDouble(TicksIn.dataArray[15]); if (TicksIn.StM5_733_1 != Convert.ToDouble(TicksIn.dataArray[8])) { TicksIn.StdDevM5_40_4 = TicksIn.StdDevM5_40_3; TicksIn.StdDevM5_40_3 = TicksIn.StdDevM5_40_2; TicksIn.StdDevM5_40_2 = TicksIn.StdDevM5_40_1; TicksIn.StdDevM5_40_1 = Convert.ToDouble(TicksIn.dataArray[16]); } } _i_BigSTD.Close(); int _dim_i_BigSTD = 0, _dim_i_BigSTD_full = 0, ji = 0; double temp = 0.0; StreamReader _i_BigSTD_Read = new StreamReader(WorkClasses.dir_str + "//_i_BigSTD.txt"); for (int i = 0; ; i++) { if (_i_BigSTD_Read.EndOfStream == true) break; datastring = _i_BigSTD_Read.ReadLine(); if (Convert.ToDouble(datastring) > temp + Math.Max(intervalLeft, intervalRight)) { _dim_i_BigSTD++; temp = Convert.ToDouble(datastring); } _dim_i_BigSTD_full++; } temp = 0.0; _i_BigSTD_Read.BaseStream.Seek(0, SeekOrigin.Begin); double[] _array_i_BigSTD = new double[_dim_i_BigSTD]; for (int i = 0; i < _dim_i_BigSTD_full; i++) { datastring = _i_BigSTD_Read.ReadLine(); if (Convert.ToDouble(datastring) > temp + Math.Max(intervalLeft, intervalRight)) { _array_i_BigSTD[ji] = Convert.ToDouble(datastring); temp = _array_i_BigSTD[ji]; ji++; } } _i_BigSTD_Read.Close(); baseFile.BaseStream.Seek(0, SeekOrigin.Begin); datastring = baseFile.ReadLine(); for (int i = 0; ; i++) { if (baseFile.EndOfStream == true) break; datastring = baseFile.ReadLine(); TicksIn.dataArray = datastring.Split(' '); for (int j = 0; j < _dim_i_BigSTD; j++) if (i > _array_i_BigSTD[j] - intervalLeft && i < _array_i_BigSTD[j] + intervalRight) { baseFileShort.WriteLine(datastring); break; } TicksIn.StdDevM5_40_0 = Convert.ToDouble(TicksIn.dataArray[15]); if (TicksIn.StM5_733_1 != Convert.ToDouble(TicksIn.dataArray[8])) { TicksIn.StdDevM5_40_4 = TicksIn.StdDevM5_40_3; TicksIn.StdDevM5_40_3 = TicksIn.StdDevM5_40_2; TicksIn.StdDevM5_40_2 = TicksIn.StdDevM5_40_1; TicksIn.StdDevM5_40_1 = Convert.ToDouble(TicksIn.dataArray[16]); } } baseFile.Close(); baseFileShort.Close(); this.Close(); }
private void button1_Click(object sender, EventArgs e) { StreamReader addFile1 = new StreamReader("D://Ticks//Ticks_base.txt"); StreamWriter OutFile_Indic = new StreamWriter("D://Ticks//Ticks_base_2.txt"); string datastring = addFile1.ReadLine(); string[] dataArray; WorkClasses.Ticks_In TicksIn = new WorkClasses.Ticks_In(); double CurTime = 0.0, avg_timestep = 0.0 ; double[] temp = new double[20]; int int1, int2; int CntToAvg = 100; double[] timeStep = new double[CntToAvg]; //--- НУЖЕН ГРАФИК ПО ДНЯМ С МЕДИАНОЙ, СРЕДНЕМ И Т.Д. ЗА ОПРЕДЕЛЕННЫЕ ПРОМЕЖУТКИ ВРЕМЕНИ НА КАЖДЫЙ ДЕНЬ ---// for (int i = 0; ; i++) { if (addFile1.EndOfStream == true) break; datastring = addFile1.ReadLine(); TicksIn.dataArray = datastring.Split(' '); TicksIn.Count = TicksIn.Count + 1; TicksIn.Date = TicksIn.dataArray[0]; TicksIn.CurTime = TicksIn.dataArray[1]; CurTime = Convert.ToInt32(TicksIn.CurTime.Split(':')[0]) * 3600.0 + Convert.ToInt32(TicksIn.CurTime.Split(':')[1]) * 60.0 + Convert.ToInt32(TicksIn.CurTime.Split(':')[2]); if (CurTime > 13 * 3600 && CurTime < 21 * 3600) { //if (TicksIn.Count == 5969721) // TicksIn.Count = TicksIn.Count; if (Convert.ToDouble(TicksIn.dataArray[2]) > 100.0) continue; for (int j = 0; j < CntToAvg-1; j++) { timeStep[j] = timeStep[j + 1]; } timeStep[CntToAvg-1] = Convert.ToDouble(TicksIn.dataArray[2]); avg_timestep = 0.0; for (int j = 10; j < CntToAvg; j++) { avg_timestep += timeStep[j]; } avg_timestep = avg_timestep / (double)CntToAvg; OutFile_Indic.WriteLine(TicksIn.Count + " " + TicksIn.Date + " " + timeStep[CntToAvg-1] + " " + avg_timestep); } } OutFile_Indic.Close(); addFile1.Close(); //Close(); // StreamReader addFile1 = new StreamReader("D://Indicator_Statictics.txt"); // StreamWriter OutFile_Indic = new StreamWriter("D://Indicator_Statictics_2.txt"); // string datastring = addFile1.ReadLine(); // string[] dataArray; // double[] temp = new double[20]; // int int1, int2; // for (int i = 0; ; i++) // { // if (addFile1.EndOfStream == true) break; // datastring = addFile1.ReadLine(); // dataArray = datastring.Split(' '); // temp[0] = Math.Round(Convert.ToDouble(dataArray[3]), 2); // temp[1] = Math.Round(Convert.ToDouble(dataArray[4]), 2); // temp[2] = Math.Round(Convert.ToDouble(dataArray[5]), 2); // temp[3] = Math.Round(Convert.ToDouble(dataArray[6]), 2); // temp[4] = Math.Round(Convert.ToDouble(dataArray[7]), 2); // temp[5] = Math.Round(Convert.ToDouble(dataArray[8]), 2); // int1 = Convert.ToInt32(dataArray[9]); // int2 = Convert.ToInt32(dataArray[10]); // temp[10] = Math.Round(Convert.ToDouble(dataArray[11]), 2); // temp[11] = Math.Round(Convert.ToDouble(dataArray[12]), 2); // temp[12] = Math.Round(Convert.ToDouble(dataArray[13]), 2); // temp[13] = Math.Round(Convert.ToDouble(dataArray[14]), 2); // OutFile_Indic.WriteLine(dataArray[1] + " " + dataArray[2] + " " + temp[0] + " " + temp[1] + " " + temp[2] + " " + temp[3] + " " + temp[4] + " " + temp[5] + " " + int1 + " " + int2 + " " + temp[10] + " " + temp[11] + " " + temp[12] + " " + temp[13]); // } // OutFile_Indic.Close(); addFile1.Close(); // Close(); }
public static int Start_and_Stop_FLG_13_09(WorkClasses.Ticks_In TicksIn, WorkClasses.Ticks_Out TicksOut, int cur_in_flg, int count_parameter, double[] cur_in_Array, double Slice_Criteria_IN_SELL, double Slice_Criteria_IN_BUY, double Slice_Criteria_OUT, int max_ticks_activ_cnt, double Stohastic_SellLimit, double Stohastic_BuyLimit, string mode, string mode_out) { if (cur_in_flg == 0) { int ii_minus = 0; int ii_plus = 0; for (int j = 0; j < count_parameter; j++) { if (cur_in_Array[TicksIn.dim - 1 - j] < -Slice_Criteria_IN_SELL) { ii_minus++; } if (cur_in_Array[TicksIn.dim - 1 - j] > Slice_Criteria_IN_BUY) { ii_plus++; } } if (ii_minus == count_parameter && TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0 < 0.0 && TicksOut.Ask_F_avg_3[TicksIn.dim - 1] < 0.0) { if (TicksIn.Only_BUY_flg) { } else { bool new_mode = false; if (TicksIn.Stohastic_Param > Stohastic_SellLimit && mode == "old") { new_mode = true; } else if ((TicksIn.Stohastic_Param > Stohastic_SellLimit || (TicksIn.Stohastic_Param <= Stohastic_SellLimit && TicksIn.StM5_733_3 >= TicksIn.StM5_733_2)) && mode == "new") { //else if ((TicksIn.StM5_733_3 >= TicksIn.StM5_733_2) && mode == "new") new_mode = true; } else { new_mode = false; } if (new_mode == true) { cur_in_flg = -1; TicksOut.OpenOrderFLG = 1; TicksOut.OpenASK = TicksIn.Ask[TicksIn.dim - 1]; TicksOut.OpenBID = TicksIn.Bid[TicksIn.dim - 1]; } } } else if (ii_plus == count_parameter && TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0 > 0.0 && TicksOut.Ask_F_avg_3[TicksIn.dim - 1] > 0.0) { if (TicksIn.Only_SELL_flg) { } else { bool new_mode = false; if (TicksIn.Stohastic_Param < Stohastic_BuyLimit && mode == "old") { new_mode = true; } else if ((TicksIn.Stohastic_Param < Stohastic_BuyLimit || (TicksIn.Stohastic_Param >= Stohastic_BuyLimit && TicksIn.StM5_733_3 >= TicksIn.StM5_733_2)) && mode == "new") { //else if ((TicksIn.StM5_733_3 >= TicksIn.StM5_733_2) && mode == "new") new_mode = true; } else { new_mode = false; } if (new_mode == true) { cur_in_flg = 1; TicksOut.OpenOrderFLG = 1; TicksOut.OpenASK = TicksIn.Ask[TicksIn.dim - 1]; TicksOut.OpenBID = TicksIn.Bid[TicksIn.dim - 1]; } } } } else if (Math.Abs(cur_in_flg) != 2) { TicksOut.OpenOrderFLG = 0; if (cur_in_flg == -1 && TicksIn.AskIncrement[TicksIn.dim - 1] > Slice_Criteria_OUT) { TicksOut.MoreThanSlice++; } if (cur_in_flg == 1 && TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT) { TicksOut.MoreThanSlice++; } if (TicksIn.Count >= 9815038) { TicksIn.Count = TicksIn.Count; } if (cur_in_flg == -1 && ( (TicksIn.AskIncrement[TicksIn.dim - 1] > Slice_Criteria_OUT && (TicksIn.StM5_733_2 > TicksIn.StM5_733_1 || mode_out == "old" || TicksIn.AskIncrement[TicksIn.dim - 1] > 0.00040)) || (TicksOut.ticks_activ_cnt > max_ticks_activ_cnt && max_ticks_activ_cnt != 0) )) { cur_in_flg = -2; TicksOut.MoreThanSlice = 0; } if (cur_in_flg == 1 && ( //(TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT && (TicksIn.StM5_733_2 < TicksIn.StM5_733_1 || mode_out == "old" || TicksIn.AskIncrement[TicksIn.dim - 1] < -0.00040)) //(TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT && (TicksIn.StM5_733_3 > TicksIn.StM5_733_2 || mode_out == "old" || TicksIn.AskIncrement[TicksIn.dim - 1] < -0.00040)) //(TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT || (TicksIn.StM5_733_0 < TicksIn.StM5_733_1 - 1 && (TicksIn.Bid[TicksIn.dim - 1] - TicksOut.OpenASK) * 100000 < 0.0 && TicksIn.AskIncrement[TicksIn.dim - 1] < -0.00008)) (TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT) || (TicksOut.ticks_activ_cnt > max_ticks_activ_cnt && max_ticks_activ_cnt != 0) )) { cur_in_flg = 2; TicksOut.MoreThanSlice = 0; } } return(cur_in_flg); }
//public static void Read_Indicators(WorkClasses.Ticks_In TicksIn) //{ // if (TicksIn.With_indicators == true) // { // string[] dataArray = TicksIn.dataArray[9].Split(' '); // TicksIn.StM5_733_0 = Convert.ToDouble(TicksIn.dataArray[7]); // TicksIn.StM5_733_0 = Convert.ToDouble(dataArray[0]); // TicksIn.StM5_733_1 = Convert.ToDouble(dataArray[1]); // TicksIn.StM5_733_2 = Convert.ToDouble(dataArray[2]); // TicksIn.StM5_733_3 = Convert.ToDouble(dataArray[3]); // TicksIn.StM5_733_4 = Convert.ToDouble(dataArray[4]); // TicksIn.Stohastic_Param = TicksIn.StM5_733_3; // } //} public static int Start_and_Stop_FLG(WorkClasses.Ticks_In TicksIn, WorkClasses.Ticks_Out TicksOut, double SELL_SPREAD, double BUY_SPREAD, int cur_in_flg, int count_parameter_sell, int count_parameter_buy, double Slice_Criteria_IN_SELL, double Slice_Criteria_IN_BUY, double Slice_Criteria_OUT_sell, double Slice_Criteria_OUT_buy, int max_ticks_activ_cnt_sell, int max_ticks_activ_cnt_buy, double Stohastic_SellLimit, double Stohastic_BuyLimit, string mode, string mode_out, int MaxCurProfitToClose_BUY, int MaxCurProfitToClose_SELL, int MaxCurStopLossToClose_BUY, int MaxCurStopLossToClose_SELL, double VolBigMassSELL_negative, double VolBigMassSELL_positiv, double VolBigMassBUY_positive, double VolBigMassBUY_negative, int BigMassCnt) { if (MaxCurProfitToClose_BUY == 0) { MaxCurProfitToClose_BUY = 5000; } if (MaxCurProfitToClose_SELL == 0) { MaxCurProfitToClose_SELL = 5000; } if (MaxCurStopLossToClose_BUY == 0) { MaxCurStopLossToClose_BUY = -1000; } if (MaxCurStopLossToClose_SELL == 0) { MaxCurStopLossToClose_SELL = -1000; } double[] cur_in_Array = new double[TicksIn.dim]; for (int i = 0; i < TicksIn.dim; i++) { cur_in_Array[i] = TicksOut.Ask_F_avg_6[i]; } if (TicksIn.Count == 9811215) { TicksIn.Count = TicksIn.Count; } if (BigMassCnt != 0) { for (int j = 0; j < BigMassCnt - 1; j++) { TicksIn.AskIncremBigMass[j] = TicksIn.AskIncremBigMass[j + 1]; } TicksIn.AskIncremBigMassSumm_Positive = TicksIn.AskIncremBigMassSumm_Negative = 0.0; TicksIn.AskIncremBigMass[BigMassCnt - 1] = TicksIn.AskIncrement[TicksIn.dim - 1]; if (VolBigMassSELL_positiv == 0 && VolBigMassBUY_negative == 0) { TicksIn.AskIncremBigMassSumm_Positive = TicksIn.AskIncremBigMass.Sum(); TicksIn.AskIncremBigMassSumm_Negative = TicksIn.AskIncremBigMass.Sum(); } else { for (int i = 0; i < BigMassCnt; i++) { if (TicksIn.AskIncremBigMass[i] >= 0) { TicksIn.AskIncremBigMassSumm_Positive += TicksIn.AskIncremBigMass[i]; } if (TicksIn.AskIncremBigMass[i] <= 0) { TicksIn.AskIncremBigMassSumm_Negative += TicksIn.AskIncremBigMass[i]; } } } TicksIn.AskIncremBigMassSumm_Positive *= 100000.0; TicksIn.AskIncremBigMassSumm_Negative *= 100000.0; //for (int j = 1; j <= BigMassCnt; j++) //{ // double[] temp = new double[j]; // for (int ij = 0; ij < j; ij++) temp[ij] = TicksIn.AskIncremBigMass[BigMassCnt - 1 - ij]; // if (Math.Abs(TicksIn.AskIncremBigMassSumm) < Math.Abs(temp.Sum() * 100000.0)) // TicksIn.AskIncremBigMassSumm = temp.Sum() * 100000.0; //} } if (cur_in_flg == 0) { int ii_minus = 0; int ii_plus = 0; for (int j = 0; j < count_parameter_buy; j++) { if (cur_in_Array[TicksIn.dim - 1 - j] > Slice_Criteria_IN_BUY) { ii_plus++; } } for (int j = 0; j < count_parameter_sell; j++) { if (cur_in_Array[TicksIn.dim - 1 - j] < -Slice_Criteria_IN_SELL) { ii_minus++; } } if (( (ii_minus == count_parameter_sell && TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0 < 0.0 && TicksOut.Ask_F_avg_3[TicksIn.dim - 1] < 0.0) || (TicksIn.AskIncremBigMassSumm_Negative < -VolBigMassSELL_negative && (TicksIn.AskIncremBigMassSumm_Positive <= VolBigMassSELL_positiv || VolBigMassSELL_positiv == 0) && BigMassCnt != 0) ) && Math.Abs(TicksIn.AskIncrement[TicksIn.dim - 1]) > -0.00300 ) { if (TicksIn.Spread[TicksIn.dim - 1] < SELL_SPREAD) { if (TicksIn.Only_BUY_flg) { } else { bool new_mode = false; if (TicksIn.Stohastic_Param > Stohastic_SellLimit && mode == "old") { new_mode = true; } else if ((TicksIn.Stohastic_Param > Stohastic_SellLimit || (TicksIn.Stohastic_Param <= Stohastic_SellLimit && TicksIn.StM5_733_3 >= TicksIn.StM5_733_2)) && mode == "new") { //else if ((TicksIn.StM5_733_3 >= TicksIn.StM5_733_2) && mode == "new") new_mode = true; } else { new_mode = false; } if (new_mode == true) { cur_in_flg = -1; TicksOut.OpenOrderFLG = 1; TicksOut.OpenASK = TicksIn.Ask[TicksIn.dim - 1]; TicksOut.OpenBID = TicksIn.Bid[TicksIn.dim - 1]; } } } else { ii_minus = ii_minus; } } else if (( (ii_plus == count_parameter_buy && TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0 > 0.0 && TicksOut.Ask_F_avg_3[TicksIn.dim - 1] > 0.0) || (TicksIn.AskIncremBigMassSumm_Positive > VolBigMassBUY_positive && (TicksIn.AskIncremBigMassSumm_Negative >= -VolBigMassBUY_negative || VolBigMassBUY_negative == 0) && BigMassCnt != 0) ) //&& Math.Abs(TicksIn.AskIncrement[TicksIn.dim - 1]) < 0.00300 && TicksOut.AskSpeed[TicksIn.dim - 1] * 100000.0 < 380.0 ) { if (TicksIn.Spread[TicksIn.dim - 1] < BUY_SPREAD) { if (TicksIn.Only_SELL_flg) { } else { bool new_mode = false; if (TicksIn.Stohastic_Param < Stohastic_BuyLimit && mode == "old") { new_mode = true; } else if ((TicksIn.Stohastic_Param < Stohastic_BuyLimit || (TicksIn.Stohastic_Param >= Stohastic_BuyLimit && TicksIn.StM5_733_3 >= TicksIn.StM5_733_2)) && mode == "new") { //else if ((TicksIn.StM5_733_3 >= TicksIn.StM5_733_2) && mode == "new") new_mode = true; } else { new_mode = false; } if (new_mode == true) { cur_in_flg = 1; TicksOut.OpenOrderFLG = 1; TicksOut.OpenASK = TicksIn.Ask[TicksIn.dim - 1]; TicksOut.OpenBID = TicksIn.Bid[TicksIn.dim - 1]; } } } else { ii_minus = ii_minus; } } } else if (Math.Abs(cur_in_flg) != 2) { TicksOut.OpenOrderFLG = 0; //if (TicksIn.flag_ByCycle == false) // Read_Indicators(TicksIn); if (cur_in_flg == -1 && TicksIn.AskIncrement[TicksIn.dim - 1] > Slice_Criteria_OUT_sell) { TicksOut.MoreThanSlice++; } if (cur_in_flg == 1 && TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT_sell) { TicksOut.MoreThanSlice++; } if (TicksIn.Count == 10458330) { TicksIn.Count = TicksIn.Count; } //if (TicksIn.AskIncrement[TicksIn.dim - 1] > Slice_Criteria_OUT_sell) // TicksIn.Count = TicksIn.Count; if (cur_in_flg == -1 && ( (TicksIn.AskIncrement[TicksIn.dim - 1] > Slice_Criteria_OUT_sell && (TicksIn.StM5_733_2 > TicksIn.StM5_733_1 - TicksIn.SellCustomSthCorrection || mode_out == "old" /*|| TicksIn.AskIncrement[TicksIn.dim - 1] > 0.00040*/)) || (TicksOut.ticks_activ_cnt > max_ticks_activ_cnt_sell && max_ticks_activ_cnt_sell != 0) || ((TicksOut.local_Open_vs_Cur) * 100000 >= Convert.ToDouble(MaxCurProfitToClose_SELL)) || ((TicksOut.local_Open_vs_Cur) * 100000 <= Convert.ToDouble(MaxCurStopLossToClose_SELL)) //|| (TicksIn.StM1_733_0[0] < 10.0 && (TicksIn.StM1_733_0[0] - TicksIn.StM1_733_0[TicksIn.StM1_733_0.Length - 1]) >= 7.0 && TicksIn.StM5_733_1 <= 40.0 && TicksIn.StM5_733_2 < TicksIn.StM5_733_1) ) && TicksIn.Spread[TicksIn.dim - 1] < 30.0 //&& TicksOut.ticks_activ_cnt > 3 //Не проканало. Можно попробовать ввести еще проверку на состояние по индикаторам, т.к. при "3" есть ордер, который выходит в +240, хотя до этого в "-" ) { cur_in_flg = -2; TicksOut.MoreThanSlice = 0; if (TicksIn.Spread[TicksIn.dim - 1] >= 20.0) { TicksIn.Spread = TicksIn.Spread; } } if (cur_in_flg == 1 && ( //(TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT && (TicksIn.StM5_733_2 < TicksIn.StM5_733_1 || mode_out == "old" || TicksIn.AskIncrement[TicksIn.dim - 1] < -0.00040)) //(TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT && (TicksIn.StM5_733_3 > TicksIn.StM5_733_2 || mode_out == "old" || TicksIn.AskIncrement[TicksIn.dim - 1] < -0.00040)) //(TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT || (TicksIn.StM5_733_0 < TicksIn.StM5_733_1 - 1 && (TicksIn.Bid[TicksIn.dim - 1] - TicksOut.OpenASK) * 100000 < 0.0 && TicksIn.AskIncrement[TicksIn.dim - 1] < -0.00008)) (TicksIn.AskIncrement[TicksIn.dim - 1] < -Slice_Criteria_OUT_buy) || (TicksOut.ticks_activ_cnt > max_ticks_activ_cnt_buy && max_ticks_activ_cnt_buy != 0) || ((TicksOut.local_Open_vs_Cur) * 100000 >= Convert.ToDouble(MaxCurProfitToClose_BUY)) || ((TicksOut.local_Open_vs_Cur) * 100000 <= Convert.ToDouble(MaxCurStopLossToClose_BUY)) //|| (TicksIn.StM1_733_0[0] > 89.0 && (TicksIn.StM1_733_0[TicksIn.StM1_733_0.Length - 1] - TicksIn.StM1_733_0[0]) >= 7.0 && TicksIn.StM5_733_1 >= 60.0) //?|| (TicksIn.StM1_733_0[0] > 89.0 && (TicksIn.StM1_733_0.Max()- TicksIn.StM1_733_0.Min()) >= 7.0 && TicksIn.StM5_733_1 >= 60.0) ) && TicksIn.Spread[TicksIn.dim - 1] < 30.0 //&& TicksOut.ticks_activ_cnt > 3 //Не проканало. Можно попробовать ввести еще проверку на состояние по индикаторам, т.к. при "3" есть ордер, который выходит в +240, хотя до этого в "-" ) { cur_in_flg = 2; TicksOut.MoreThanSlice = 0; if (TicksIn.Spread[TicksIn.dim - 1] >= 20.0) { TicksIn.Spread = TicksIn.Spread; } } } return(cur_in_flg); }