From 39b509c0cff3f25b77131319be07e503c3e352be Mon Sep 17 00:00:00 2001 From: vlad zverzhkhovskiy Date: Wed, 24 Sep 2025 10:53:18 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Declisions/Utils/MovingAverage.cs | 4 ++-- KLHZ.Trader.Core/Exchange/Services/Trader.cs | 20 ++++++++++++------- .../Controllers/PlayController.cs | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs b/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs index e53c5e0..ee7f2e5 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs @@ -182,7 +182,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils // если фильтрация окном 15 наползает на окно 120 сверху, потенциальное время закрытия лонга и возможно открытия шорта if (twavss[size - 1] <= twavbs[size - 1] && twavss[size - 2] > twavbs[size - 2]) { - if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] >= uptrendEndingDetectionMeanfullStep) + //if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] >= uptrendEndingDetectionMeanfullStep) { res |= TradingEvent.UptrendEnd; } @@ -191,7 +191,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils // если фильтрация окном 120 наползает на окно 15 сверху, потенциальное время открытия лонга и закрытия шорта if (twavss[size - 1] >= twavbs[size - 1] && twavss[size - 2] < twavbs[size - 2]) { - if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] <= uptrendStartingDetectionMeanfullStep) + //if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] <= uptrendStartingDetectionMeanfullStep) { res |= TradingEvent.UptrendStart; } diff --git a/KLHZ.Trader.Core/Exchange/Services/Trader.cs b/KLHZ.Trader.Core/Exchange/Services/Trader.cs index f393448..9eea799 100644 --- a/KLHZ.Trader.Core/Exchange/Services/Trader.cs +++ b/KLHZ.Trader.Core/Exchange/Services/Trader.cs @@ -444,6 +444,7 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt { price = await _tradeDataProvider.GetLastPrice(message.Figi); } + price = System.Math.Round(price, 2); var messages = new List(); foreach (var asset in assets) { @@ -458,6 +459,7 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt } if (profit > 0) { + profit= System.Math.Round(profit, 2); assetsForClose.Add(asset); messages.Add($"Закрываю позицию {asset.Figi} ({(asset.Count > 0 ? "лонг" : "шорт")}) на счёте {_portfolioWrapper.Accounts[asset.AccountId].AccountName}. Количество {(long)asset.Count}, цена ~{price}, профит {profit}"); if (loggedDeclisions == 0) @@ -495,7 +497,7 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt { Text = $"Открываю позицию {message.Figi} ({(positionType == PositionType.Long ? "лонг" : "шорт")}) " + $"на счёте {acc.AccountName}. Количество {(positionType == PositionType.Long ? "" : "-")}{count}, " + - $"цена ~{message.Value}. Стоп лосс: {(positionType == PositionType.Long ? "-" : "+")}{stopLossShift}. " + + $"цена ~{System.Math.Round(message.Value,2)}. Стоп лосс: {(positionType == PositionType.Long ? "-" : "+")}{stopLossShift}. " + $"Тейк профит: {(positionType == PositionType.Long ? "+" : "-")}{takeProfitShift}" }); } @@ -538,13 +540,13 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt //result = MergeResults(result, resTask3.Result.ToImmutableDictionary()); result = MergeResultsMax(result, changeModeData); result = MergeResultsMult(result, getFFTModsTask.Result); - //result = MergeResults(result, getAreasModsTask.Result); + ////result = MergeResults(result, getAreasModsTask.Result); result = MergeResultsMult(result, getSellsDiffsModsTask.Result); result = MergeResultsMult(result, getTradingModeModsTask.Result); if (result[TradingEvent.UptrendStart] > Constants.UppingCoefficient - && !LongOpeningStops.ContainsKey(message.Figi) - && state == ExchangeState.Open + // && !LongOpeningStops.ContainsKey(message.Figi) + // && state == ExchangeState.Open ) { var stops = GetStops(message, PositionType.Long); @@ -564,8 +566,8 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt await LogDeclision(DeclisionTradeAction.ResetStopsLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message); } if (result[TradingEvent.DowntrendStart] > Constants.PowerUppingCoefficient - && !ShortOpeningStops.ContainsKey(message.Figi) - && state == ExchangeState.Open + //&& !ShortOpeningStops.ContainsKey(message.Figi) + // && state == ExchangeState.Open ) { var stops = GetStops(message, PositionType.Short); @@ -806,7 +808,7 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt //res[TradingEvent.UptrendStart] = Constants.UppingCoefficient; res[TradingEvent.DowntrendEnd] = Constants.PowerUppingCoefficient; //res[TradingEvent.UptrendEnd] = Constants.LowingCoefficient; - //res[TradingEvent.DowntrendStart] = Constants.LowingCoefficient; + res[TradingEvent.DowntrendStart] = Constants.BlockingCoefficient; } if (position == ValueAmplitudePosition.UpperThen30Decil) { @@ -873,11 +875,15 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt { uptrendStartMode *= Constants.PowerUppingCoefficient; downstartMode *= Constants.PowerUppingCoefficient; + uptrendEndMode *= Constants.BlockingCoefficient; + downtrendEndMode *= Constants.BlockingCoefficient; } else if (System.Math.Abs(bys_rel) > 0.3m || System.Math.Abs(sells_rel) > 0.3m) { uptrendStartMode *= Constants.UppingCoefficient; downstartMode *= Constants.UppingCoefficient; + uptrendEndMode *=Constants.BlockingCoefficient; + downtrendEndMode *= Constants.BlockingCoefficient; } //else if (System.Math.Abs(bys_rel) <= 0.2m && System.Math.Abs(sells_rel) <= 0.2m) //{ diff --git a/KLHZ.Trader.Service/Controllers/PlayController.cs b/KLHZ.Trader.Service/Controllers/PlayController.cs index d55e1ce..a0492b9 100644 --- a/KLHZ.Trader.Service/Controllers/PlayController.cs +++ b/KLHZ.Trader.Service/Controllers/PlayController.cs @@ -34,8 +34,8 @@ namespace KLHZ.Trader.Service.Controllers //var figi1 = "BBG004730N88"; var figi2 = "BBG004730N88"; //var figi2 = "FUTIMOEXF000"; - //var time1 = DateTime.UtcNow.AddDays(-shift ?? -7).Date; - var time1 = new DateTime(2025, 9, 23, 17, 0, 0, DateTimeKind.Utc); + var time1 = DateTime.UtcNow.AddDays(-shift ?? -7).Date; + //var time1 = new DateTime(2025, 9, 24, 7, 15, 0, DateTimeKind.Utc); //var time2 = DateTime.UtcNow.AddMinutes(18); using var context1 = await _dbContextFactory.CreateDbContextAsync(); context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;