Exemplo n.º 1
0
        // 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---
            }
        }