From b74c3b3ec4b2e27bb10ea81e84e5eccb1b99a793 Mon Sep 17 00:00:00 2001 From: HojouFotytu <36724681+HojouFotytu@users.noreply.github.com> Date: Wed, 15 Jul 2020 16:10:41 +0900 Subject: [PATCH] Fixes to Formula & Level Code --- Core/DataObjects/ProfitTrailerData.cs | 11 ++-- Core/ProfitTrailer/StrategyHelper.cs | 92 +++++++++++++++++---------- 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/Core/DataObjects/ProfitTrailerData.cs b/Core/DataObjects/ProfitTrailerData.cs index 7ecae4b..5083c50 100644 --- a/Core/DataObjects/ProfitTrailerData.cs +++ b/Core/DataObjects/ProfitTrailerData.cs @@ -304,12 +304,13 @@ namespace Core.Main.DataObjects sellLogData.AverageBuyPrice = rsld.avgPrice; sellLogData.TotalCost = sellLogData.SoldAmount * sellLogData.AverageBuyPrice; - // check if bot is a shortbot via PT API. Losses on short bot showing as gains. Issue #195 + // check if bot is a shortbot via PT API. Losses on short bot currently showing as gains. Issue #195 + // code removed - double soldValueRaw = (sellLogData.SoldAmount * sellLogData.SoldPrice); - double soldValueAfterFees = soldValueRaw - (soldValueRaw * ((double)rsld.fee / 100)); - sellLogData.SoldValue = soldValueAfterFees; - sellLogData.Profit = Math.Round(sellLogData.SoldValue - sellLogData.TotalCost, 8); + double soldValueRaw = (sellLogData.SoldAmount * sellLogData.SoldPrice); + double soldValueAfterFees = soldValueRaw - (soldValueRaw * ((double)rsld.fee / 100)); + sellLogData.SoldValue = soldValueAfterFees; + sellLogData.Profit = Math.Round(sellLogData.SoldValue - sellLogData.TotalCost, 8); //Convert Unix Timestamp to Datetime System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); diff --git a/Core/ProfitTrailer/StrategyHelper.cs b/Core/ProfitTrailer/StrategyHelper.cs index 27cb49a..e6b3b0a 100644 --- a/Core/ProfitTrailer/StrategyHelper.cs +++ b/Core/ProfitTrailer/StrategyHelper.cs @@ -234,11 +234,17 @@ namespace Core.ProfitTrailer { result = "CHANGE"; } - if (result.Contains("LEVERAGE")) + if (result.Contains("CROSSED")) + { + leverage = strategyName.Remove(0, 9); + leverage = leverage.Remove(leverage.Length - 1, 1); + result = "CROSS" + leverage + "X"; + } + if (result.Contains("ISOLATED")) { leverage = strategyName.Remove(0, 10); leverage = leverage.Remove(leverage.Length - 1, 1); - result = leverage + " X"; + result = "ISOL " + leverage + "X"; } // buy/sell strategies beginning with PT 2.3.3 contain the strategy designation letter followed by a colon and space. // remove the letter and colon, change to shortcut, then reapply the letter and colon @@ -456,7 +462,6 @@ namespace Core.ProfitTrailer { result = true; } - // Prior to PT 2.3.3 if (!checkForAnyInvalid) { switch (strategyName.ToLower()) @@ -503,6 +508,10 @@ namespace Core.ProfitTrailer case "vwappercentage": case "mvwappercentage": case "btcdominance": + case "combimagain": + case "combimaspread": + case "combimacross": + case "macdpercentage": result = true; break; default: @@ -583,51 +592,68 @@ namespace Core.ProfitTrailer isValidStrategy = StrategyHelper.IsValidStrategy(strategy.Name); if (!isValidStrategy) { - // Parse Formulas - if (strategy.Name.Contains("FORMULA") && !strategy.Name.Contains("STATS") && !strategy.Name.Contains("LEVEL")) + + if (strategy.Name.Contains("TRIGGERED")) + // remove levels already triggered, to show only currently waiting trigger { - string expression = strategy.Name.Remove(0, 10); - expression = expression.Replace("", "true").Replace("", "false").Replace("", "").Replace("&&", "and").Replace("||", "or"); - expression = regx.Replace(expression, String.Empty); - var tokens = new Tokenizer(expression).Tokenize(); - var parser = new Parser(tokens); - if (parser.Parse()) + strategyText += ""; + } + else if (strategy.Name.Contains("STATS")) + // avoid parsing advanced buy stats + { + strategyText += ""; + } + else if (strategy.Name.Contains("FORMULA")) + // Parse Various PT Formulas + { + if (strategy.Name.Contains("LEVEL")) + // level X { - strategyText += "(FORM) "; + string level = strategy.Name.Substring(5, 2); + string expression = strategy.Name.Remove(0, 17); + expression = expression.Replace("", "true").Replace("", "false").Replace("", "").Replace("&&", "and").Replace("||", "or"); + expression = regx.Replace(expression, String.Empty); + var tokens = new Tokenizer(expression).Tokenize(); + var parser = new Parser(tokens); + if (parser.Parse()) + { + strategyText += "L " + level + " "; + } + else + { + strategyText += "L " + level + " "; + } } else + // standard formula { - strategyText += "(FORM) "; + string expression = strategy.Name.Remove(0, 10); + expression = expression.Replace("", "true").Replace("", "false").Replace("", "").Replace("&&", "and").Replace("||", "or"); + expression = regx.Replace(expression, String.Empty); + var tokens = new Tokenizer(expression).Tokenize(); + var parser = new Parser(tokens); + if (parser.Parse()) + { + strategyText += "FORM "; + } + else + { + strategyText += "FORM "; + } } } - if (strategy.Name.Contains("LEVEL") && !strategy.Name.Contains("TRIGGERED")) + else { - string level = strategy.Name.Substring(5, 2); - string expression = strategy.Name.Remove(0, 17); - expression = expression.Replace("", "true").Replace("", "false").Replace("", "").Replace("&&", "and").Replace("||", "or"); - expression = regx.Replace(expression, String.Empty); - var tokens = new Tokenizer(expression).Tokenize(); - var parser = new Parser(tokens); - if (parser.Parse()) - { - strategyText += "LEVEL" + level + " "; - } - else - { - strategyText += "LEVEL" + level + " "; - } - } - if (strategy.Name.Contains("LEVEL") && strategy.Name.Contains("TRIGGERED")) - { - string level = strategy.Name.Substring(5, 2); - strategyText += "LEVEL " + level + "TRIG "; + strategyText += "" + StrategyHelper.GetStrategyShortcut(strategy.Name, false) + " "; } + } else { strategyText += "" + StrategyHelper.GetStrategyShortcut(strategy.Name, false) + " "; } } + if (isTrailingBuyActive) { strategyText += " ";