/// <summary> /// Возвращает данные для графика(прибыли по сделкам). Десериализация сохраненного файла /// </summary> public TradesProfitCharts GetDataForCharts(string _path) { TradesProfitCharts result = new TradesProfitCharts(); TestTradesCollection _testTradCol = (TestTradesCollection)StaticService.Deserializes(Directory.GetCurrentDirectory() + _path); foreach (ParametrTestTrades _testTrd in _testTradCol) { result.AddInDictionary(_testTrd.DateTimeTestTrad, _testTrd.ProfitPortfolio); } return(result); }
/// <summary> /// Открываем лонги, если цена выше самой верхней линии. /// Открываем шорты, если цена ниже самой нижней линии. /// Закрытие: переворачиваемся. /// </summary> private Task TrendAlgoritmTest(string _path) { return(Task.Run(() => { TradesBolingerRepository _trdBRepo = null; string file_name = "test_result.txt"; try { _trdBRepo = (TradesBolingerRepository)StaticService.Deserializes(_path); } catch (Exception) { StaticService.LogFileWrite(_path, "error_log.txt", true); } string _key = Path.GetFileNameWithoutExtension(_path); string _dateRes = StaticService.GetComment(_key, SettingsClass.PaternDate1); string _settBB = StaticService.GetComment(_key, SettingsClass.Patern); TestTradesCollection testTradColl = new TestTradesCollection(); TestTradesCollection testTradCollOPT = new TestTradesCollection(); int tp = 0; double profitPortfolio = 0; // прибыль портфеля на каждую сделку int countTrades = 0; double maxProfit = 0; double minProfit = 0; int countProfitTrades = 0; int countLossTrades = 0; // OPT double profitPortfolioOpt = 0; int countTradesOpt = 0; double maxProfitOpt = 0; double minProfitOpt = 0; int countProfitTradesOpt = 0; int countLossTradesOpt = 0; // end opt StaticService.LogFileWrite("\n ---------" + _key + "---------", file_name, true); if (_trdBRepo != null) { foreach (ParametrTradesBolinger pcT in _trdBRepo) { //StaticClassService.LogFileWrite(pcT.DateTimeTrades + "\t" + pcT.NumberTrades + "\t" + pcT.PriceTrades + "\t" + pcT.SeccodeTrades + "\t" + pcT.LineUp + "\t" + pcT.LineDown + "\t" + pcT.LineMidl, file_name, true); DateTime dateTimeTrade = pcT.DateTimeTrades; if (dateTimeTrade.TimeOfDay < new TimeSpan(19, 0, 0)) { double price = (double)pcT.PriceTrades; //---Здесь вызываем Класс нужного алгоритма--- Algoritms.BollingerCrossing.Algoritm(pcT, testTradColl, testTradCollOPT, file_name, price, dateTimeTrade, ref tp, ref countTrades, ref countTradesOpt, ref profitPortfolio, ref profitPortfolioOpt, ref maxProfit, ref maxProfitOpt, ref minProfit, ref minProfitOpt, ref countProfitTrades, ref countProfitTradesOpt, ref countLossTrades, ref countLossTradesOpt); //-------------------------------------------- } } } // save result testResultRepo.Add(new ParametrTestResult(_key, _dateRes, _settBB, profitPortfolio, countTrades, maxProfit, minProfit, countProfitTrades, countLossTrades)); testResultRepo.Add(new ParametrTestResult(_key + "OPT", _dateRes, _settBB, profitPortfolioOpt, countTradesOpt, maxProfitOpt, minProfitOpt, countProfitTradesOpt, countLossTradesOpt)); // Opt // serialize TestTradesCollection end TestTradesCollection'OPT' StaticService.Serializes(testTradColl, folderOutTestTradesSimple + _key); StaticService.Serializes(testTradCollOPT, folderOutTestTradesOPT + _key); })); }
// end opt public static void Algoritm(ParametrTradesBolinger pcT, TestTradesCollection testTradColl, TestTradesCollection testTradCollOPT, string file_name, double price, DateTime dateTimeTrade, ref int tp, ref int countTrades, ref int countTradesOpt, ref double profitPortfolio, ref double profitPortfolioOpt, ref double maxProfit, ref double maxProfitOpt, ref double minProfit, ref double minProfitOpt, ref int countProfitTrades, ref int countProfitTradesOpt, ref int countLossTrades, ref int countLossTradesOpt) { double profit = 0; // прибыль самой сделки double qty = 0; lineUp = pcT.LineUp; lineDown = pcT.LineDown; lineMidl = pcT.LineMidl; // long if (tp <= 0 && price > lineUp) { price_buy = price + SettingsClass.slipPrice; profit = StaticCalculations.CalcProfit(price_buy, price_sell); qty = Math.Abs(tp) + 1; //--1-- tp += Math.Abs(tp) + 1; //--2-- StaticCalculations.CalcParametrTest(profit, dateTimeTrade, ref countTrades, ref profitPortfolio, ref maxProfit, ref minProfit, ref countProfitTrades, ref countLossTrades); testTradColl.Add(new ParametrTestTrades(pcT.NumberTrades, dateTimeTrade, price_buy, qty, Operation.Buuy, profitPortfolio)); // log StaticService.LogFileWrite("-----" + "\t" + pcT.NumberTrades + "\t" + dateTimeTrade + "\t" + price_buy + "\t" + qty + "\t" + Operation.Buuy + " \t" + profit + "\t" + profitPortfolio + "\tlongProfit: " + longProfit + "\tshortProfit: " + shortProfit + "\t level_0", file_name, true); //---Opt--- //if (StaticOptimizer.PsevdoRealTrades(profit, dateTimeTrade, ref counter_prof, ref counter_loss)) //{ // CalcParametrTest(profit, dateTimeTrade, ref countTradesOpt, ref profitPortfolioOpt, ref maxProfitOpt, ref minProfitOpt, ref countProfitTradesOpt, ref countLossTradesOpt); // testTradCollOPT.Add(new ParametrTestTrades(pcT.NumberTrades, dateTimeTrade, price_buy, qty, Operation.Buy, profitPortfolioOpt)); // // log Opt // StaticService.LogFileWrite("-----" + "\t" + pcT.NumberTrades + "\t" + dateTimeTrade + "\t" + price_buy + "\t" + qty + "\t" + Operation.Buy + "\t" + profitPortfolioOpt + "\t level_1", file_name, true); //} if (shortProfit) { StaticCalculations.CalcParametrTest(profit, dateTimeTrade, ref countTradesOpt, ref profitPortfolioOpt, ref maxProfitOpt, ref minProfitOpt, ref countProfitTradesOpt, ref countLossTradesOpt); testTradCollOPT.Add(new ParametrTestTrades(pcT.NumberTrades, dateTimeTrade, price_buy, qty, Operation.Buuy, profitPortfolioOpt)); // log Opt StaticService.LogFileWrite("-----" + "\t" + pcT.NumberTrades + "\t" + dateTimeTrade + "\t" + price_buy + "\t" + qty + "\t" + Operation.Buuy + " \t" + profit + "\t" + profitPortfolioOpt + "\tshortProfit: " + shortProfit + "\t level_1", file_name, true); } StaticOptimizer.PsevdoRealTrades(profit, false, ref longProfit, ref shortProfit); //---end Opt--- } // short if (tp >= 0 && price < lineDown) { price_sell = price - SettingsClass.slipPrice; profit = StaticCalculations.CalcProfit(price_buy, price_sell); qty = Math.Abs(tp) + 1; //--1-- tp -= Math.Abs(tp) + 1; //--2-- StaticCalculations.CalcParametrTest(profit, dateTimeTrade, ref countTrades, ref profitPortfolio, ref maxProfit, ref minProfit, ref countProfitTrades, ref countLossTrades); testTradColl.Add(new ParametrTestTrades(pcT.NumberTrades, dateTimeTrade, price_sell, qty, Operation.Sell, profitPortfolio)); // log StaticService.LogFileWrite("-----" + "\t" + pcT.NumberTrades + "\t" + dateTimeTrade + "\t" + price_sell + "\t" + qty + "\t" + Operation.Sell + "\t" + profit + "\t" + profitPortfolio + "\tlongProfit: " + longProfit + "\tshortProfit: " + shortProfit + "\t level_0", file_name, true); // Opt //if (StaticOptimizer.PsevdoRealTrades(profit, dateTimeTrade, ref counter_prof, ref counter_loss)) //{ // CalcParametrTest(profit, dateTimeTrade, ref countTradesOpt, ref profitPortfolioOpt, ref maxProfitOpt, ref minProfitOpt, ref countProfitTradesOpt, ref countLossTradesOpt); // testTradCollOPT.Add(new ParametrTestTrades(pcT.NumberTrades, dateTimeTrade, price_sell, qty, Operation.Sell, profitPortfolioOpt)); // // log Opt // StaticService.LogFileWrite("-----" + "\t" + pcT.NumberTrades + "\t" + dateTimeTrade + "\t" + price_sell + "\t" + qty + "\t" + Operation.Sell + "\t" + profitPortfolioOpt + "\t level_1", file_name, true); //} if (longProfit) { StaticCalculations.CalcParametrTest(profit, dateTimeTrade, ref countTradesOpt, ref profitPortfolioOpt, ref maxProfitOpt, ref minProfitOpt, ref countProfitTradesOpt, ref countLossTradesOpt); testTradCollOPT.Add(new ParametrTestTrades(pcT.NumberTrades, dateTimeTrade, price_sell, qty, Operation.Sell, profitPortfolioOpt)); // log Opt StaticService.LogFileWrite("-----" + "\t" + pcT.NumberTrades + "\t" + dateTimeTrade + "\t" + price_sell + "\t" + qty + "\t" + Operation.Sell + "\t" + profit + "\t" + profitPortfolioOpt + "\tlongProfit: " + longProfit + "\t level_1", file_name, true); } StaticOptimizer.PsevdoRealTrades(profit, true, ref longProfit, ref shortProfit); //---end Opt--- } }
public static void Algoritm(TestTradesCollection testTradColl, TestTradesCollection testTradCollOPT, string file_name, DateTime dateTimeTrade, double price, ref int tp, ref int countTrades, ref double profitPortfolio, ref double maxProfit, ref double minProfit, ref int countProfitTrades, ref int countLossTrades) { }