From 78fdb0490a7e7659d7d4a88c375329c2126ba709 Mon Sep 17 00:00:00 2001 From: ooples Date: Wed, 2 Aug 2023 08:18:19 -0400 Subject: [PATCH] Fixed calculations for Negative Volume Index and Positive Volume Index #40 Changed many variables to use var keyword instead --- src/Calculations/BollingerBands.cs | 292 +- src/Calculations/Chande.cs | 314 +- src/Calculations/Demark.cs | 158 +- src/Calculations/Ehlers.cs | 3308 ++++++++-------- src/Calculations/Inputs.cs | 108 +- src/Calculations/Macd.cs | 330 +- src/Calculations/Momentum.cs | 260 +- src/Calculations/MovingAvg.cs | 3974 +++++++++---------- src/Calculations/Oscillator.cs | 5912 ++++++++++++++-------------- src/Calculations/PivotPoint.cs | 298 +- src/Calculations/Ppo.cs | 238 +- src/Calculations/PriceChannel.cs | 1608 ++++---- src/Calculations/Ratio.cs | 244 +- src/Calculations/Rsi.cs | 556 +-- src/Calculations/Stochastic.cs | 444 +-- src/Calculations/TrailingStop.cs | 386 +- src/Calculations/Trend.cs | 648 +-- src/Calculations/Volatility.cs | 706 ++-- src/Calculations/Volume.cs | 1066 ++--- src/Calculations/Wilder.cs | 98 +- src/Helpers/CalculationsHelper.cs | 44 +- src/Helpers/MathHelper.cs | 2 +- src/Models/StockData.cs | 4 +- 23 files changed, 10500 insertions(+), 10498 deletions(-) diff --git a/src/Calculations/BollingerBands.cs b/src/Calculations/BollingerBands.cs index 5d18824..8b13f85 100644 --- a/src/Calculations/BollingerBands.cs +++ b/src/Calculations/BollingerBands.cs @@ -30,23 +30,23 @@ public static StockData CalculateBollingerBands(this StockData stockData, Moving var smaList = GetMovingAverageList(stockData, maType, length, inputList); var stdDeviationList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = smaList[i]; - double currentValue = inputList[i]; - double currentStdDeviation = stdDeviationList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; - - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (currentStdDeviation * stdDevMult); + var middleBand = smaList[i]; + var currentValue = inputList[i]; + var currentStdDeviation = stdDeviationList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; + + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (currentStdDeviation * stdDevMult); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (currentStdDeviation * stdDevMult); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (currentStdDeviation * stdDevMult); lowerBandList.AddRounded(lowerBand); - Signal signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); + var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); signalsList.Add(signal); } @@ -81,39 +81,39 @@ public static StockData CalculateAdaptivePriceZoneIndicator(this StockData stock List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - int nP = MinOrMax((int)Math.Ceiling(Sqrt(length))); + var nP = MinOrMax((int)Math.Ceiling(Sqrt(length))); var ema1List = GetMovingAverageList(stockData, maType, nP, inputList); var ema2List = GetMovingAverageList(stockData, maType, nP, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double xHL = currentHigh - currentLow; + var xHL = currentHigh - currentLow; xHLList.AddRounded(xHL); } var xHLEma1List = GetMovingAverageList(stockData, maType, nP, xHLList); var xHLEma2List = GetMovingAverageList(stockData, maType, nP, xHLEma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double xVal1 = ema2List[i]; - double xVal2 = xHLEma2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var xVal1 = ema2List[i]; + var xVal2 = xHLEma2List[i]; - double prevUpBand = outerUpBandList.LastOrDefault(); - double outerUpBand = (pct * xVal2) + xVal1; + var prevUpBand = outerUpBandList.LastOrDefault(); + var outerUpBand = (pct * xVal2) + xVal1; outerUpBandList.AddRounded(outerUpBand); - double prevDnBand = outerDnBandList.LastOrDefault(); - double outerDnBand = xVal1 - (pct * xVal2); + var prevDnBand = outerDnBandList.LastOrDefault(); + var outerDnBand = xVal1 - (pct * xVal2); outerDnBandList.AddRounded(outerDnBand); - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (outerUpBand + outerDnBand) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (outerUpBand + outerDnBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, outerUpBand, @@ -154,28 +154,28 @@ public static StockData CalculateAutoDispersionBands(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double x = MinPastValues(i, length, currentValue - prevValue); + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var x = MinPastValues(i, length, currentValue - prevValue); - double x2 = x * x; + var x2 = x * x; x2List.AddRounded(x2); - double x2Sma = x2List.TakeLastExt(length).Average(); - double sq = x2Sma >= 0 ? Sqrt(x2Sma) : 0; + var x2Sma = x2List.TakeLastExt(length).Average(); + var sq = x2Sma >= 0 ? Sqrt(x2Sma) : 0; - double a = currentValue + sq; + var a = currentValue + sq; aList.AddRounded(a); - double b = currentValue - sq; + var b = currentValue - sq; bList.AddRounded(b); - double aMax = aList.TakeLastExt(length).Max(); + var aMax = aList.TakeLastExt(length).Max(); aMaxList.AddRounded(aMax); - double bMin = bList.TakeLastExt(length).Min(); + var bMin = bList.TakeLastExt(length).Min(); bMinList.AddRounded(bMin); } @@ -183,17 +183,17 @@ public static StockData CalculateAutoDispersionBands(this StockData stockData, M var upperBandList = GetMovingAverageList(stockData, maType, smoothLength, aMaList); var bMaList = GetMovingAverageList(stockData, maType, length, bMinList); var lowerBandList = GetMovingAverageList(stockData, maType, smoothLength, bMaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double upperBand = upperBandList[i]; - double lowerBand = lowerBandList[i]; - double prevUpperBand = i >= 1 ? upperBandList[i - 1] : 0; - double prevLowerBand = i >= 1 ? lowerBandList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (upperBand + lowerBand) / 2; + var currentValue = inputList[i]; + var upperBand = upperBandList[i]; + var lowerBand = lowerBandList[i]; + var prevUpperBand = i >= 1 ? upperBandList[i - 1] : 0; + var prevLowerBand = i >= 1 ? lowerBandList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (upperBand + lowerBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, @@ -235,28 +235,28 @@ public static StockData CalculateBollingerBandsFibonacciRatios(this StockData st var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double atr = atrList[i]; - double sma = smaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; - double r1 = atr * fibRatio1; - double r2 = atr * fibRatio2; - double r3 = atr * fibRatio3; - - double prevFibTop3 = fibTop3List.LastOrDefault(); - double fibTop3 = sma + r3; + var atr = atrList[i]; + var sma = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; + var r1 = atr * fibRatio1; + var r2 = atr * fibRatio2; + var r3 = atr * fibRatio3; + + var prevFibTop3 = fibTop3List.LastOrDefault(); + var fibTop3 = sma + r3; fibTop3List.AddRounded(fibTop3); - double fibTop2 = sma + r2; - double fibTop1 = sma + r1; - double fibBottom1 = sma - r1; - double fibBottom2 = sma - r2; + var fibTop2 = sma + r2; + var fibTop1 = sma + r1; + var fibBottom1 = sma - r1; + var fibBottom2 = sma - r2; - double prevFibBottom3 = fibBottom3List.LastOrDefault(); - double fibBottom3 = sma - r3; + var prevFibBottom3 = fibBottom3List.LastOrDefault(); + var fibBottom3 = sma - r3; fibBottom3List.AddRounded(fibBottom3); var signal = GetBollingerBandsSignal(currentValue - sma, prevValue - prevSma, currentValue, prevValue, fibTop3, prevFibTop3, @@ -299,18 +299,18 @@ public static StockData CalculateBollingerBandsAvgTrueRange(this StockData stock var emaList = GetMovingAverageList(stockData, maType, atrLength, inputList); var atrList = CalculateAverageTrueRange(stockData, maType, atrLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double currentAtr = atrList[i]; - double upperBand = upperBandList[i]; - double lowerBand = lowerBandList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double bbDiff = upperBand - lowerBand; - - double atrDev = bbDiff != 0 ? currentAtr / bbDiff : 0; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var currentAtr = atrList[i]; + var upperBand = upperBandList[i]; + var lowerBand = lowerBandList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var bbDiff = upperBand - lowerBand; + + var atrDev = bbDiff != 0 ? currentAtr / bbDiff : 0; atrDevList.AddRounded(atrDev); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, atrDev, 0.5); @@ -346,36 +346,36 @@ public static StockData CalculateBollingerBandsWithAtrPct(this StockData stockDa List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - double ratio = (double)2 / (length + 1); + var ratio = (double)2 / (length + 1); var smaList = GetMovingAverageList(stockData, maType, bbLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double basis = smaList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double lh = currentHigh - currentLow; - double hc = Math.Abs(currentHigh - prevValue); - double lc = Math.Abs(currentLow - prevValue); - double mm = Math.Max(Math.Max(lh, hc), lc); - double prevBasis = i >= 1 ? smaList[i - 1] : 0; - double atrs = mm == hc ? hc / (prevValue + (hc / 2)) : mm == lc ? lc / (currentLow + (lc / 2)) : mm == lh ? lh / + var basis = smaList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var lh = currentHigh - currentLow; + var hc = Math.Abs(currentHigh - prevValue); + var lc = Math.Abs(currentLow - prevValue); + var mm = Math.Max(Math.Max(lh, hc), lc); + var prevBasis = i >= 1 ? smaList[i - 1] : 0; + var atrs = mm == hc ? hc / (prevValue + (hc / 2)) : mm == lc ? lc / (currentLow + (lc / 2)) : mm == lh ? lh / (currentLow + (lh / 2)) : 0; - double prevAptr = aptrList.LastOrDefault(); - double aptr = (100 * atrs * ratio) + (prevAptr * (1 - ratio)); + var prevAptr = aptrList.LastOrDefault(); + var aptr = (100 * atrs * ratio) + (prevAptr * (1 - ratio)); aptrList.AddRounded(aptr); - double dev = stdDevMult * aptr; - double prevUpper = upperList.LastOrDefault(); - double upper = basis + (basis * dev / 100); + var dev = stdDevMult * aptr; + var prevUpper = upperList.LastOrDefault(); + var upper = basis + (basis * dev / 100); upperList.AddRounded(upper); - double prevLower = lowerList.LastOrDefault(); - double lower = basis - (basis * dev / 100); + var prevLower = lowerList.LastOrDefault(); + var lower = basis - (basis * dev / 100); lowerList.AddRounded(lower); var signal = GetBollingerBandsSignal(currentValue - basis, prevValue - prevBasis, currentValue, prevValue, upper, prevUpper, lower, prevLower); @@ -414,18 +414,18 @@ public static StockData CalculateBollingerBandsPercentB(this StockData stockData var upperBandList = bbList.OutputValues["UpperBand"]; var lowerBandList = bbList.OutputValues["LowerBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double upperBand = upperBandList[i]; - double lowerBand = lowerBandList[i]; - double prevPctB1 = i >= 1 ? pctBList[i - 1] : 0; - double prevPctB2 = i >= 2 ? pctBList[i - 2] : 0; + var currentValue = inputList[i]; + var upperBand = upperBandList[i]; + var lowerBand = lowerBandList[i]; + var prevPctB1 = i >= 1 ? pctBList[i - 1] : 0; + var prevPctB2 = i >= 2 ? pctBList[i - 2] : 0; - double pctB = upperBand - lowerBand != 0 ? (currentValue - lowerBand) / (upperBand - lowerBand) * 100 : 0; + var pctB = upperBand - lowerBand != 0 ? (currentValue - lowerBand) / (upperBand - lowerBand) * 100 : 0; pctBList.AddRounded(pctB); - Signal signal = GetRsiSignal(pctB - prevPctB1, prevPctB1 - prevPctB2, pctB, prevPctB1, 100, 0); + var signal = GetRsiSignal(pctB - prevPctB1, prevPctB1 - prevPctB2, pctB, prevPctB1, 100, 0); signalsList.Add(signal); } @@ -460,20 +460,20 @@ public static StockData CalculateBollingerBandsWidth(this StockData stockData, d var lowerBandList = bbList.OutputValues["LowerBand"]; var middleBandList = bbList.OutputValues["MiddleBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double upperBand = upperBandList[i]; - double lowerBand = lowerBandList[i]; - double middleBand = middleBandList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; - - double prevBbWidth = bbWidthList.LastOrDefault(); - double bbWidth = middleBand != 0 ? (upperBand - lowerBand) / middleBand : 0; + var upperBand = upperBandList[i]; + var lowerBand = lowerBandList[i]; + var middleBand = middleBandList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; + + var prevBbWidth = bbWidthList.LastOrDefault(); + var bbWidth = middleBand != 0 ? (upperBand - lowerBand) / middleBand : 0; bbWidthList.AddRounded(bbWidth); - Signal signal = GetVolatilitySignal(currentValue - middleBand, prevValue - prevMiddleBand, bbWidth, prevBbWidth); + var signal = GetVolatilitySignal(currentValue - middleBand, prevValue - prevMiddleBand, bbWidth, prevBbWidth); signalsList.Add(signal); } @@ -513,30 +513,30 @@ public static StockData CalculateVervoortModifiedBollingerBandIndicator(this Sto List signalsList = new(); var (inputList, highList, lowList, _, _, _) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = inputList[i]; - double prevOhlc = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = inputList[i]; + var prevOhlc = i >= 1 ? inputList[i - 1] : 0; - double prevHaOpen = haOpenList.LastOrDefault(); - double haOpen = (prevOhlc + prevHaOpen) / 2; + var prevHaOpen = haOpenList.LastOrDefault(); + var haOpen = (prevOhlc + prevHaOpen) / 2; haOpenList.AddRounded(haOpen); - double haC = (currentValue + haOpen + Math.Max(currentHigh, haOpen) + Math.Min(currentLow, haOpen)) / 4; + var haC = (currentValue + haOpen + Math.Max(currentHigh, haOpen) + Math.Min(currentLow, haOpen)) / 4; hacList.AddRounded(haC); } var tma1List = GetMovingAverageList(stockData, maType, smoothLength, hacList); var tma2List = GetMovingAverageList(stockData, maType, smoothLength, tma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tma1 = tma1List[i]; - double tma2 = tma2List[i]; - double diff = tma1 - tma2; + var tma1 = tma1List[i]; + var tma2 = tma2List[i]; + var diff = tma1 - tma2; - double zlha = tma1 + diff; + var zlha = tma1 + diff; zlhaList.AddRounded(zlha); } @@ -544,37 +544,37 @@ public static StockData CalculateVervoortModifiedBollingerBandIndicator(this Sto stockData.CustomValuesList = zlhaTemaList; var zlhaTemaStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length1).CustomValuesList; var wmaZlhaTemaList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, length1, zlhaTemaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double zihaTema = zlhaTemaList[i]; - double zihaTemaStdDev = zlhaTemaStdDevList[i]; - double wmaZihaTema = wmaZlhaTemaList[i]; + var zihaTema = zlhaTemaList[i]; + var zihaTemaStdDev = zlhaTemaStdDevList[i]; + var wmaZihaTema = wmaZlhaTemaList[i]; - double percb = zihaTemaStdDev != 0 ? (zihaTema + (2 * zihaTemaStdDev) - wmaZihaTema) / (4 * zihaTemaStdDev) * 100 : 0; + var percb = zihaTemaStdDev != 0 ? (zihaTema + (2 * zihaTemaStdDev) - wmaZihaTema) / (4 * zihaTemaStdDev) * 100 : 0; percbList.AddRounded(percb); } stockData.CustomValuesList = percbList; var percbStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = percbList[i]; - double percbStdDev = percbStdDevList[i]; - double prevValue = i >= 1 ? percbList[i - 1] : 0; + var currentValue = percbList[i]; + var percbStdDev = percbStdDevList[i]; + var prevValue = i >= 1 ? percbList[i - 1] : 0; - double prevUb = ubList.LastOrDefault(); - double ub = 50 + (stdDevMult * percbStdDev); + var prevUb = ubList.LastOrDefault(); + var ub = 50 + (stdDevMult * percbStdDev); ubList.AddRounded(ub); - double prevLb = lbList.LastOrDefault(); - double lb = 50 - (stdDevMult * percbStdDev); + var prevLb = lbList.LastOrDefault(); + var lb = 50 - (stdDevMult * percbStdDev); lbList.AddRounded(lb); - double prevPercbSignal = percbSignalList.LastOrDefault(); - double percbSignal = (ub + lb) / 2; + var prevPercbSignal = percbSignalList.LastOrDefault(); + var percbSignal = (ub + lb) / 2; percbSignalList.AddRounded(percbSignal); - Signal signal = GetBollingerBandsSignal(currentValue - percbSignal, prevValue - prevPercbSignal, currentValue, + var signal = GetBollingerBandsSignal(currentValue - percbSignal, prevValue - prevPercbSignal, currentValue, prevValue, ub, prevUb, lb, prevLb); signalsList.Add(signal); } diff --git a/src/Calculations/Chande.cs b/src/Calculations/Chande.cs index ea02bb2..ba1a8ab 100644 --- a/src/Calculations/Chande.cs +++ b/src/Calculations/Chande.cs @@ -25,20 +25,20 @@ public static StockData CalculateChandeQuickStick(this StockData stockData, Movi List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentClose = inputList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; - double openClose = currentClose - currentOpen; + var openClose = currentClose - currentOpen; openCloseList.AddRounded(openClose); } var smaList = GetMovingAverageList(stockData, maType, length, openCloseList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma = smaList[i]; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var sma = smaList[i]; + var prevSma = i >= 1 ? smaList[i - 1] : 0; var signal = GetCompareSignal(sma, prevSma); signalsList.Add(signal); @@ -72,13 +72,13 @@ public static StockData CalculateChandeMomentumOscillatorFilter(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double diff = MinPastValues(i, 1, currentValue - prevValue); - double absDiff = Math.Abs(diff); + var diff = MinPastValues(i, 1, currentValue - prevValue); + var absDiff = Math.Abs(diff); if (absDiff > filter) { diff = 0; absDiff = 0; @@ -86,20 +86,20 @@ public static StockData CalculateChandeMomentumOscillatorFilter(this StockData s diffList.AddRounded(diff); absDiffList.AddRounded(absDiff); - double diffSum = diffList.TakeLastExt(length).Sum(); - double absDiffSum = absDiffList.TakeLastExt(length).Sum(); + var diffSum = diffList.TakeLastExt(length).Sum(); + var absDiffSum = absDiffList.TakeLastExt(length).Sum(); - double cmo = absDiffSum != 0 ? MinOrMax(100 * diffSum / absDiffSum, 100, -100) : 0; + var cmo = absDiffSum != 0 ? MinOrMax(100 * diffSum / absDiffSum, 100, -100) : 0; cmoList.AddRounded(cmo); } var cmoSignalList = GetMovingAverageList(stockData, maType, length, cmoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double cmo = cmoList[i]; - double cmoSignal = cmoSignalList[i]; - double prevCmo = i >= 1 ? cmoList[i - 1] : 0; - double prevCmoSignal = i >= 1 ? cmoSignalList[i - 1] : 0; + var cmo = cmoList[i]; + var cmoSignal = cmoSignalList[i]; + var prevCmo = i >= 1 ? cmoList[i - 1] : 0; + var prevCmoSignal = i >= 1 ? cmoSignalList[i - 1] : 0; var signal = GetRsiSignal(cmo - cmoSignal, prevCmo - prevCmoSignal, cmo, prevCmo, 70, -70); signalsList.Add(signal); @@ -130,21 +130,21 @@ public static StockData CalculateChandeMomentumOscillatorAbsolute(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorValue = i >= length ? inputList[i - length] : 0; - double prevCmoAbs1 = i >= 1 ? cmoAbsList[i - 1] : 0; - double prevCmoAbs2 = i >= 2 ? cmoAbsList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorValue = i >= length ? inputList[i - length] : 0; + var prevCmoAbs1 = i >= 1 ? cmoAbsList[i - 1] : 0; + var prevCmoAbs2 = i >= 2 ? cmoAbsList[i - 2] : 0; - double absDiff = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); + var absDiff = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); absDiffList.AddRounded(absDiff); - double num = Math.Abs(100 * MinPastValues(i, length, currentValue - priorValue)); - double denom = absDiffList.TakeLastExt(length).Sum(); + var num = Math.Abs(100 * MinPastValues(i, length, currentValue - priorValue)); + var denom = absDiffList.TakeLastExt(length).Sum(); - double cmoAbs = denom != 0 ? MinOrMax(num / denom, 100, 0) : 0; + var cmoAbs = denom != 0 ? MinOrMax(num / denom, 100, 0) : 0; cmoAbsList.AddRounded(cmoAbs); var signal = GetRsiSignal(cmoAbs - prevCmoAbs1, prevCmoAbs1 - prevCmoAbs2, cmoAbs, prevCmoAbs1, 70, 30); @@ -178,30 +178,30 @@ public static StockData CalculateChandeMomentumOscillatorAverage(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; - double prevPrice = i >= 1 ? inputList[i - 1] : 0; - double prevCmoAvg1 = i >= 1 ? cmoAvgList[i - 1] : 0; - double prevCmoAvg2 = i >= 2 ? cmoAvgList[i - 2] : 0; + var currentPrice = inputList[i]; + var prevPrice = i >= 1 ? inputList[i - 1] : 0; + var prevCmoAvg1 = i >= 1 ? cmoAvgList[i - 1] : 0; + var prevCmoAvg2 = i >= 2 ? cmoAvgList[i - 2] : 0; - double diff = currentPrice - prevPrice; + var diff = currentPrice - prevPrice; diffList.AddRounded(diff); - double absDiff = Math.Abs(diff); + var absDiff = Math.Abs(diff); absDiffList.AddRounded(absDiff); - double diffSum1 = diffList.TakeLastExt(length1).Sum(); - double absSum1 = absDiffList.TakeLastExt(length1).Sum(); - double diffSum2 = diffList.TakeLastExt(length2).Sum(); - double absSum2 = absDiffList.TakeLastExt(length2).Sum(); - double diffSum3 = diffList.TakeLastExt(length3).Sum(); - double absSum3 = absDiffList.TakeLastExt(length3).Sum(); - double temp1 = absSum1 != 0 ? MinOrMax(diffSum1 / absSum1, 1, -1) : 0; - double temp2 = absSum2 != 0 ? MinOrMax(diffSum2 / absSum2, 1, -1) : 0; - double temp3 = absSum3 != 0 ? MinOrMax(diffSum3 / absSum3, 1, -1) : 0; - - double cmoAvg = 100 * ((temp1 + temp2 + temp3) / 3); + var diffSum1 = diffList.TakeLastExt(length1).Sum(); + var absSum1 = absDiffList.TakeLastExt(length1).Sum(); + var diffSum2 = diffList.TakeLastExt(length2).Sum(); + var absSum2 = absDiffList.TakeLastExt(length2).Sum(); + var diffSum3 = diffList.TakeLastExt(length3).Sum(); + var absSum3 = absDiffList.TakeLastExt(length3).Sum(); + var temp1 = absSum1 != 0 ? MinOrMax(diffSum1 / absSum1, 1, -1) : 0; + var temp2 = absSum2 != 0 ? MinOrMax(diffSum2 / absSum2, 1, -1) : 0; + var temp3 = absSum3 != 0 ? MinOrMax(diffSum3 / absSum3, 1, -1) : 0; + + var cmoAvg = 100 * ((temp1 + temp2 + temp3) / 3); cmoAvgList.AddRounded(cmoAvg); var signal = GetRsiSignal(cmoAvg - prevCmoAvg1, prevCmoAvg1 - prevCmoAvg2, cmoAvg, prevCmoAvg1, 50, -50); @@ -235,30 +235,30 @@ public static StockData CalculateChandeMomentumOscillatorAbsoluteAverage(this St List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; - double prevPrice = i >= 1 ? inputList[i - 1] : 0; - double prevCmoAbsAvg1 = i >= 1 ? cmoAbsAvgList[i - 1] : 0; - double prevCmoAbsAvg2 = i >= 2 ? cmoAbsAvgList[i - 2] : 0; + var currentPrice = inputList[i]; + var prevPrice = i >= 1 ? inputList[i - 1] : 0; + var prevCmoAbsAvg1 = i >= 1 ? cmoAbsAvgList[i - 1] : 0; + var prevCmoAbsAvg2 = i >= 2 ? cmoAbsAvgList[i - 2] : 0; - double diff = currentPrice - prevPrice; + var diff = currentPrice - prevPrice; diffList.AddRounded(diff); - double absDiff = Math.Abs(diff); + var absDiff = Math.Abs(diff); absDiffList.AddRounded(absDiff); - double diffSum1 = diffList.TakeLastExt(length1).Sum(); - double absSum1 = absDiffList.TakeLastExt(length1).Sum(); - double diffSum2 = diffList.TakeLastExt(length2).Sum(); - double absSum2 = absDiffList.TakeLastExt(length2).Sum(); - double diffSum3 = diffList.TakeLastExt(length3).Sum(); - double absSum3 = absDiffList.TakeLastExt(length3).Sum(); - double temp1 = absSum1 != 0 ? MinOrMax(diffSum1 / absSum1, 1, -1) : 0; - double temp2 = absSum2 != 0 ? MinOrMax(diffSum2 / absSum2, 1, -1) : 0; - double temp3 = absSum3 != 0 ? MinOrMax(diffSum3 / absSum3, 1, -1) : 0; - - double cmoAbsAvg = Math.Abs(100 * ((temp1 + temp2 + temp3) / 3)); + var diffSum1 = diffList.TakeLastExt(length1).Sum(); + var absSum1 = absDiffList.TakeLastExt(length1).Sum(); + var diffSum2 = diffList.TakeLastExt(length2).Sum(); + var absSum2 = absDiffList.TakeLastExt(length2).Sum(); + var diffSum3 = diffList.TakeLastExt(length3).Sum(); + var absSum3 = absDiffList.TakeLastExt(length3).Sum(); + var temp1 = absSum1 != 0 ? MinOrMax(diffSum1 / absSum1, 1, -1) : 0; + var temp2 = absSum2 != 0 ? MinOrMax(diffSum2 / absSum2, 1, -1) : 0; + var temp3 = absSum3 != 0 ? MinOrMax(diffSum3 / absSum3, 1, -1) : 0; + + var cmoAbsAvg = Math.Abs(100 * ((temp1 + temp2 + temp3) / 3)); cmoAbsAvgList.AddRounded(cmoAbsAvg); var signal = GetRsiSignal(cmoAbsAvg - prevCmoAbsAvg1, prevCmoAbsAvg1 - prevCmoAbsAvg2, cmoAbsAvg, prevCmoAbsAvg1, 70, 30); @@ -304,56 +304,56 @@ public static StockData CalculateChandeCompositeMomentumIndex(this StockData sto var stdDev10List = CalculateStandardDeviationVolatility(stockData, maType, length2).CustomValuesList; var stdDev20List = CalculateStandardDeviationVolatility(stockData, maType, length3).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double valueDiff1 = currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; + var valueDiff1 = currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; valueDiff1List.AddRounded(valueDiff1); - double valueDiff2 = currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; + var valueDiff2 = currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; valueDiff2List.AddRounded(valueDiff2); - double cmo51 = valueDiff1List.TakeLastExt(length1).Sum(); - double cmo52 = valueDiff2List.TakeLastExt(length1).Sum(); - double cmo101 = valueDiff1List.TakeLastExt(length2).Sum(); - double cmo102 = valueDiff2List.TakeLastExt(length2).Sum(); - double cmo201 = valueDiff1List.TakeLastExt(length3).Sum(); - double cmo202 = valueDiff2List.TakeLastExt(length3).Sum(); + var cmo51 = valueDiff1List.TakeLastExt(length1).Sum(); + var cmo52 = valueDiff2List.TakeLastExt(length1).Sum(); + var cmo101 = valueDiff1List.TakeLastExt(length2).Sum(); + var cmo102 = valueDiff2List.TakeLastExt(length2).Sum(); + var cmo201 = valueDiff1List.TakeLastExt(length3).Sum(); + var cmo202 = valueDiff2List.TakeLastExt(length3).Sum(); - double cmo5Ratio = cmo51 + cmo52 != 0 ? MinOrMax(100 * (cmo51 - cmo52) / (cmo51 + cmo52), 100, -100) : 0; + var cmo5Ratio = cmo51 + cmo52 != 0 ? MinOrMax(100 * (cmo51 - cmo52) / (cmo51 + cmo52), 100, -100) : 0; cmo5RatioList.AddRounded(cmo5Ratio); - double cmo10Ratio = cmo101 + cmo102 != 0 ? MinOrMax(100 * (cmo101 - cmo102) / (cmo101 + cmo102), 100, -100) : 0; + var cmo10Ratio = cmo101 + cmo102 != 0 ? MinOrMax(100 * (cmo101 - cmo102) / (cmo101 + cmo102), 100, -100) : 0; cmo10RatioList.AddRounded(cmo10Ratio); - double cmo20Ratio = cmo201 + cmo202 != 0 ? MinOrMax(100 * (cmo201 - cmo202) / (cmo201 + cmo202), 100, -100) : 0; + var cmo20Ratio = cmo201 + cmo202 != 0 ? MinOrMax(100 * (cmo201 - cmo202) / (cmo201 + cmo202), 100, -100) : 0; cmo20RatioList.AddRounded(cmo20Ratio); } var cmo5List = GetMovingAverageList(stockData, maType, smoothLength, cmo5RatioList); var cmo10List = GetMovingAverageList(stockData, maType, smoothLength, cmo10RatioList); var cmo20List = GetMovingAverageList(stockData, maType, smoothLength, cmo20RatioList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDev5 = stdDevList[i]; - double stdDev10 = stdDev10List[i]; - double stdDev20 = stdDev20List[i]; - double cmo5 = cmo5List[i]; - double cmo10 = cmo10List[i]; - double cmo20 = cmo20List[i]; - - double dmi = stdDev5 + stdDev10 + stdDev20 != 0 ? + var stdDev5 = stdDevList[i]; + var stdDev10 = stdDev10List[i]; + var stdDev20 = stdDev20List[i]; + var cmo5 = cmo5List[i]; + var cmo10 = cmo10List[i]; + var cmo20 = cmo20List[i]; + + var dmi = stdDev5 + stdDev10 + stdDev20 != 0 ? MinOrMax(((stdDev5 * cmo5) + (stdDev10 * cmo10) + (stdDev20 * cmo20)) / (stdDev5 + stdDev10 + stdDev20), 100, -100) : 0; dmiList.AddRounded(dmi); - double prevS = sList.LastOrDefault(); - double s = dmiList.TakeLastExt(length1).Average(); + var prevS = sList.LastOrDefault(); + var s = dmiList.TakeLastExt(length1).Average(); sList.AddRounded(s); - double prevE = eList.LastOrDefault(); - double e = CalculateEMA(dmi, prevE, smoothLength); + var prevE = eList.LastOrDefault(); + var e = CalculateEMA(dmi, prevE, smoothLength); eList.AddRounded(e); var signal = GetRsiSignal(e - s, prevE - prevS, e, prevE, 70, -70); @@ -392,18 +392,18 @@ public static StockData CalculateChandeMomentumOscillatorAverageDisparityIndex(t var secondEmaList = GetMovingAverageList(stockData, maType, length2, inputList); var thirdEmaList = GetMovingAverageList(stockData, maType, length3, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double firstEma = firstEmaList[i]; - double secondEma = secondEmaList[i]; - double thirdEma = thirdEmaList[i]; - double firstDisparityIndex = currentValue != 0 ? (currentValue - firstEma) / currentValue * 100 : 0; - double secondDisparityIndex = currentValue != 0 ? (currentValue - secondEma) / currentValue * 100 : 0; - double thirdDisparityIndex = currentValue != 0 ? (currentValue - thirdEma) / currentValue * 100 : 0; - - double prevAvgDisparityIndex = avgDisparityIndexList.LastOrDefault(); - double avgDisparityIndex = (firstDisparityIndex + secondDisparityIndex + thirdDisparityIndex) / 3; + var currentValue = inputList[i]; + var firstEma = firstEmaList[i]; + var secondEma = secondEmaList[i]; + var thirdEma = thirdEmaList[i]; + var firstDisparityIndex = currentValue != 0 ? (currentValue - firstEma) / currentValue * 100 : 0; + var secondDisparityIndex = currentValue != 0 ? (currentValue - secondEma) / currentValue * 100 : 0; + var thirdDisparityIndex = currentValue != 0 ? (currentValue - thirdEma) / currentValue * 100 : 0; + + var prevAvgDisparityIndex = avgDisparityIndexList.LastOrDefault(); + var avgDisparityIndex = (firstDisparityIndex + secondDisparityIndex + thirdDisparityIndex) / 3; avgDisparityIndexList.AddRounded(avgDisparityIndex); var signal = GetCompareSignal(avgDisparityIndex, prevAvgDisparityIndex); @@ -438,12 +438,12 @@ public static StockData CalculateChandeKrollRSquaredIndex(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double index = i; indexList.AddRounded(index); - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempValueList.AddRounded(currentValue); var r2 = GoodnessOfFit.RSquared(indexList.TakeLastExt(length).Select(x => (double)x), @@ -453,11 +453,11 @@ public static StockData CalculateChandeKrollRSquaredIndex(this StockData stockDa } var r2SmoothedList = GetMovingAverageList(stockData, maType, smoothLength, r2RawList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double r2Sma = r2SmoothedList[i]; - double prevR2Sma1 = i >= 1 ? r2SmoothedList[i - 1] : 0; - double prevR2Sma2 = i >= 2 ? r2SmoothedList[i - 2] : 0; + var r2Sma = r2SmoothedList[i]; + var prevR2Sma1 = i >= 1 ? r2SmoothedList[i - 1] : 0; + var prevR2Sma2 = i >= 2 ? r2SmoothedList[i - 2] : 0; var signal = GetCompareSignal(r2Sma - prevR2Sma1, prevR2Sma1 - prevR2Sma2); signalsList.Add(signal); @@ -494,20 +494,20 @@ public static StockData CalculateChandeVolatilityIndexDynamicAverageIndicator(th var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var stdDevEmaList = GetMovingAverageList(stockData, maType, length, stdDevList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentStdDev = stdDevList[i]; - double currentStdDevEma = stdDevEmaList[i]; - double prevVidya1 = i >= 1 ? vidya1List.LastOrDefault() : currentValue; - double prevVidya2 = i >= 1 ? vidya2List.LastOrDefault() : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ratio = currentStdDevEma != 0 ? currentStdDev / currentStdDevEma : 0; - - double vidya1 = (alpha1 * ratio * currentValue) + ((1 - (alpha1 * ratio)) * prevVidya1); + var currentValue = inputList[i]; + var currentStdDev = stdDevList[i]; + var currentStdDevEma = stdDevEmaList[i]; + var prevVidya1 = i >= 1 ? vidya1List.LastOrDefault() : currentValue; + var prevVidya2 = i >= 1 ? vidya2List.LastOrDefault() : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ratio = currentStdDevEma != 0 ? currentStdDev / currentStdDevEma : 0; + + var vidya1 = (alpha1 * ratio * currentValue) + ((1 - (alpha1 * ratio)) * prevVidya1); vidya1List.AddRounded(vidya1); - double vidya2 = (alpha2 * ratio * currentValue) + ((1 - (alpha2 * ratio)) * prevVidya2); + var vidya2 = (alpha2 * ratio * currentValue) + ((1 - (alpha2 * ratio)) * prevVidya2); vidya2List.AddRounded(vidya2); var signal = GetBullishBearishSignal(currentValue - Math.Max(vidya1, vidya2), prevValue - Math.Max(prevVidya1, prevVidya2), @@ -540,15 +540,15 @@ public static StockData CalculateChandeTrendScore(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double prevTs = tsList.LastOrDefault(); + var prevTs = tsList.LastOrDefault(); double ts = 0; - for (int j = startLength; j <= endLength; j++) + for (var j = startLength; j <= endLength; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; ts += currentValue >= prevValue ? 1 : -1; } tsList.AddRounded(ts); @@ -582,13 +582,13 @@ public static StockData CalculateChandeForecastOscillator(this StockData stockDa var linRegList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentLinReg = linRegList[i]; + var currentValue = inputList[i]; + var currentLinReg = linRegList[i]; - double prevPf = pfList.LastOrDefault(); - double pf = currentValue != 0 ? (currentValue - currentLinReg) * 100 / currentValue : 0; + var prevPf = pfList.LastOrDefault(); + var pf = currentValue != 0 ? (currentValue - currentLinReg) * 100 / currentValue : 0; pfList.AddRounded(pf); var signal = GetCompareSignal(pf, prevPf); @@ -620,25 +620,25 @@ public static StockData CalculateChandeIntradayMomentumIndex(this StockData stoc List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double prevImi1 = i >= 1 ? imiUnfilteredList[i - 1] : 0; - double prevImi2 = i >= 2 ? imiUnfilteredList[i - 2] : 0; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var prevImi1 = i >= 1 ? imiUnfilteredList[i - 1] : 0; + var prevImi2 = i >= 2 ? imiUnfilteredList[i - 2] : 0; - double prevGains = gainsList.LastOrDefault(); - double gains = currentClose > currentOpen ? prevGains + (currentClose - currentOpen) : 0; + var prevGains = gainsList.LastOrDefault(); + var gains = currentClose > currentOpen ? prevGains + (currentClose - currentOpen) : 0; gainsList.AddRounded(gains); - double prevLosses = lossesList.LastOrDefault(); - double losses = currentClose < currentOpen ? prevLosses + (currentOpen - currentClose) : 0; + var prevLosses = lossesList.LastOrDefault(); + var losses = currentClose < currentOpen ? prevLosses + (currentOpen - currentClose) : 0; lossesList.AddRounded(losses); - double upt = gainsList.TakeLastExt(length).Sum(); - double dnt = lossesList.TakeLastExt(length).Sum(); + var upt = gainsList.TakeLastExt(length).Sum(); + var dnt = lossesList.TakeLastExt(length).Sum(); - double imiUnfiltered = upt + dnt != 0 ? MinOrMax(100 * upt / (upt + dnt), 100, 0) : 0; + var imiUnfiltered = upt + dnt != 0 ? MinOrMax(100 * upt / (upt + dnt), 100, 0) : 0; imiUnfilteredList.AddRounded(imiUnfiltered); var signal = GetRsiSignal(imiUnfiltered - prevImi1, prevImi1 - prevImi2, imiUnfiltered, prevImi1, 70, 30); @@ -673,32 +673,32 @@ public static StockData CalculateChandeMomentumOscillator(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double diff = MinPastValues(i, 1, currentValue - prevValue); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var diff = MinPastValues(i, 1, currentValue - prevValue); - double negChg = i >= 1 && diff < 0 ? Math.Abs(diff) : 0; + var negChg = i >= 1 && diff < 0 ? Math.Abs(diff) : 0; cmoNegChgList.AddRounded(negChg); - double posChg = i >= 1 && diff > 0 ? diff : 0; + var posChg = i >= 1 && diff > 0 ? diff : 0; cmoPosChgList.AddRounded(posChg); - double negSum = cmoNegChgList.TakeLastExt(length).Sum(); - double posSum = cmoPosChgList.TakeLastExt(length).Sum(); + var negSum = cmoNegChgList.TakeLastExt(length).Sum(); + var posSum = cmoPosChgList.TakeLastExt(length).Sum(); - double cmo = posSum + negSum != 0 ? MinOrMax((posSum - negSum) / (posSum + negSum) * 100, 100, -100) : 0; + var cmo = posSum + negSum != 0 ? MinOrMax((posSum - negSum) / (posSum + negSum) * 100, 100, -100) : 0; cmoList.AddRounded(cmo); } var cmoSignalList = GetMovingAverageList(stockData, maType, signalLength, cmoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double cmo = cmoList[i]; - double cmoSignal = cmoSignalList[i]; - double prevCmo = i >= 1 ? cmoList[i - 1] : 0; - double prevCmoSignal = i >= 1 ? cmoSignalList[i - 1] : 0; + var cmo = cmoList[i]; + var cmoSignal = cmoSignalList[i]; + var prevCmo = i >= 1 ? cmoList[i - 1] : 0; + var prevCmoSignal = i >= 1 ? cmoSignalList[i - 1] : 0; var signal = GetRsiSignal(cmo - cmoSignal, prevCmo - prevCmoSignal, cmo, prevCmo, 50, -50); signalsList.Add(signal); diff --git a/src/Calculations/Demark.cs b/src/Calculations/Demark.cs index 2e3d84f..95c729e 100644 --- a/src/Calculations/Demark.cs +++ b/src/Calculations/Demark.cs @@ -26,34 +26,34 @@ public static StockData CalculateDemarkRangeExpansionIndex(this StockData stockD List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double high = highList[i]; - double prevHigh2 = i >= 2 ? highList[i - 2] : 0; - double prevHigh5 = i >= 5 ? highList[i - 5] : 0; - double prevHigh6 = i >= 6 ? highList[i - 6] : 0; - double low = lowList[i]; - double prevLow2 = i >= 2 ? lowList[i - 2] : 0; - double prevLow5 = i >= 5 ? lowList[i - 5] : 0; - double prevLow6 = i >= 6 ? lowList[i - 6] : 0; - double prevClose7 = i >= 7 ? inputList[i - 7] : 0; - double prevClose8 = i >= 8 ? inputList[i - 8] : 0; - double prevRei1 = i >= 1 ? reiList[i - 1] : 0; - double prevRei2 = i >= 2 ? reiList[i - 2] : 0; + var high = highList[i]; + var prevHigh2 = i >= 2 ? highList[i - 2] : 0; + var prevHigh5 = i >= 5 ? highList[i - 5] : 0; + var prevHigh6 = i >= 6 ? highList[i - 6] : 0; + var low = lowList[i]; + var prevLow2 = i >= 2 ? lowList[i - 2] : 0; + var prevLow5 = i >= 5 ? lowList[i - 5] : 0; + var prevLow6 = i >= 6 ? lowList[i - 6] : 0; + var prevClose7 = i >= 7 ? inputList[i - 7] : 0; + var prevClose8 = i >= 8 ? inputList[i - 8] : 0; + var prevRei1 = i >= 1 ? reiList[i - 1] : 0; + var prevRei2 = i >= 2 ? reiList[i - 2] : 0; double n = (high >= prevLow5 || high >= prevLow6) && (low <= prevHigh5 || low <= prevHigh6) ? 0 : 1; double m = prevHigh2 >= prevClose8 && (prevLow2 <= prevClose7 || prevLow2 <= prevClose8) ? 0 : 1; - double s = high - prevHigh2 + (low - prevLow2); + var s = high - prevHigh2 + (low - prevLow2); - double s1 = n * m * s; + var s1 = n * m * s; s1List.AddRounded(s1); - double s2 = Math.Abs(s); + var s2 = Math.Abs(s); s2List.AddRounded(s2); - double s1Sum = s1List.TakeLastExt(length).Sum(); - double s2Sum = s2List.TakeLastExt(length).Sum(); + var s1Sum = s1List.TakeLastExt(length).Sum(); + var s2Sum = s2List.TakeLastExt(length).Sum(); - double rei = s2Sum != 0 ? s1Sum / s2Sum * 100 : 0; + var rei = s2Sum != 0 ? s1Sum / s2Sum * 100 : 0; reiList.AddRounded(rei); var signal = GetRsiSignal(rei - prevRei1, prevRei1 - prevRei2, rei, prevRei1, 100, -100); @@ -85,31 +85,31 @@ public static StockData CalculateDemarkPressureRatioV1(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, openList, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double currentVolume = volumeList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevPr1 = i >= 1 ? pressureRatioList[i - 1] : 0; - double prevPr2 = i >= 2 ? pressureRatioList[i - 2] : 0; - double gapup = prevClose != 0 ? (currentOpen - prevClose) / prevClose : 0; - double gapdown = currentOpen != 0 ? (prevClose - currentOpen) / currentOpen : 0; - - double bp = gapup > 0.15 ? (currentHigh - prevClose + currentClose - currentLow) * currentVolume : + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var currentVolume = volumeList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevPr1 = i >= 1 ? pressureRatioList[i - 1] : 0; + var prevPr2 = i >= 2 ? pressureRatioList[i - 2] : 0; + var gapup = prevClose != 0 ? (currentOpen - prevClose) / prevClose : 0; + var gapdown = currentOpen != 0 ? (prevClose - currentOpen) / currentOpen : 0; + + var bp = gapup > 0.15 ? (currentHigh - prevClose + currentClose - currentLow) * currentVolume : currentClose > currentOpen ? (currentClose - currentOpen) * currentVolume : 0; bpList.AddRounded(bp); - double sp = gapdown > 0.15 ? (prevClose - currentLow + currentHigh - currentClose) * currentVolume : + var sp = gapdown > 0.15 ? (prevClose - currentLow + currentHigh - currentClose) * currentVolume : currentClose < currentOpen ? (currentClose - currentOpen) * currentVolume : 0; spList.AddRounded(sp); - double bpSum = bpList.TakeLastExt(length).Sum(); - double spSum = spList.TakeLastExt(length).Sum(); + var bpSum = bpList.TakeLastExt(length).Sum(); + var spSum = spList.TakeLastExt(length).Sum(); - double pressureRatio = bpSum - spSum != 0 ? MinOrMax(100 * bpSum / (bpSum - spSum), 100, 0) : 0; + var pressureRatio = bpSum - spSum != 0 ? MinOrMax(100 * bpSum / (bpSum - spSum), 100, 0) : 0; pressureRatioList.AddRounded(pressureRatio); var signal = GetRsiSignal(pressureRatio - prevPr1, prevPr1 - prevPr2, pressureRatio, prevPr1, 75, 25); @@ -141,30 +141,30 @@ public static StockData CalculateDemarkPressureRatioV2(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, openList, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double currentVolume = volumeList[i]; - double delta = currentClose - currentOpen; - double trueRange = currentHigh - currentLow; - double ratio = trueRange != 0 ? delta / trueRange : 0; - double prevPr1 = i >= 1 ? pressureRatioList[i - 1] : 0; - double prevPr2 = i >= 2 ? pressureRatioList[i - 2] : 0; - - double buyingPressure = delta > 0 ? ratio * currentVolume : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var currentVolume = volumeList[i]; + var delta = currentClose - currentOpen; + var trueRange = currentHigh - currentLow; + var ratio = trueRange != 0 ? delta / trueRange : 0; + var prevPr1 = i >= 1 ? pressureRatioList[i - 1] : 0; + var prevPr2 = i >= 2 ? pressureRatioList[i - 2] : 0; + + var buyingPressure = delta > 0 ? ratio * currentVolume : 0; bpList.AddRounded(buyingPressure); - double sellingPressure = delta < 0 ? ratio * currentVolume : 0; + var sellingPressure = delta < 0 ? ratio * currentVolume : 0; spList.AddRounded(sellingPressure); - double bpSum = bpList.TakeLastExt(length).Sum(); - double spSum = spList.TakeLastExt(length).Sum(); - double denom = bpSum + Math.Abs(spSum); + var bpSum = bpList.TakeLastExt(length).Sum(); + var spSum = spList.TakeLastExt(length).Sum(); + var denom = bpSum + Math.Abs(spSum); - double pressureRatio = denom != 0 ? MinOrMax(100 * bpSum / denom, 100, 0) : 50; + var pressureRatio = denom != 0 ? MinOrMax(100 * bpSum / denom, 100, 0) : 50; pressureRatioList.AddRounded(pressureRatio); var signal = GetRsiSignal(pressureRatio - prevPr1, prevPr1 - prevPr2, pressureRatio, prevPr1, 75, 25); @@ -195,22 +195,22 @@ public static StockData CalculateDemarkReversalPoints(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; double uCount = 0, dCount = 0; - for (int j = 0; j < length1; j++) + for (var j = 0; j < length1; j++) { - double value = i >= j ? inputList[i - j] : 0; - double prevValue = i >= j + length2 ? inputList[i - (j + length2)] : 0; + var value = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j + length2 ? inputList[i - (j + length2)] : 0; uCount += value > prevValue ? 1 : 0; dCount += value < prevValue ? 1 : 0; } double drp = dCount == length1 ? 1 : uCount == length1 ? -1 : 0; - double drpPrice = drp != 0 ? currentValue : 0; + var drpPrice = drp != 0 ? currentValue : 0; drpPriceList.AddRounded(drpPrice); var signal = GetConditionSignal(drp > 0 || uCount > dCount, drp < 0 || dCount > uCount); @@ -240,22 +240,22 @@ public static StockData CalculateDemarkSetupIndicator(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; double uCount = 0, dCount = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double value = i >= j ? inputList[i - j] : 0; - double prevValue = i >= j + length ? inputList[i - (j + length)] : 0; + var value = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j + length ? inputList[i - (j + length)] : 0; uCount += value > prevValue ? 1 : 0; dCount += value < prevValue ? 1 : 0; } double drp = dCount == length ? 1 : uCount == length ? -1 : 0; - double drpPrice = drp != 0 ? currentValue : 0; + var drpPrice = drp != 0 ? currentValue : 0; drpPriceList.AddRounded(drpPrice); var signal = GetConditionSignal(drp > 0 || uCount > dCount, drp < 0 || dCount > uCount); @@ -288,30 +288,30 @@ public static StockData CalculateDemarker(this StockData stockData, MovingAvgTyp List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentLow = lowList[i]; - double currentHigh = highList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; + var currentLow = lowList[i]; + var currentHigh = highList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; - double dMax = currentHigh > prevHigh ? currentHigh - prevHigh : 0; + var dMax = currentHigh > prevHigh ? currentHigh - prevHigh : 0; dMaxList.AddRounded(dMax); - double dMin = currentLow < prevLow ? prevLow - currentLow : 0; + var dMin = currentLow < prevLow ? prevLow - currentLow : 0; dMinList.AddRounded(dMin); } var maxMaList = GetMovingAverageList(stockData, maType, length, dMaxList); var minMaList = GetMovingAverageList(stockData, maType, length, dMinList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double maxMa = maxMaList[i]; - double minMa = minMaList[i]; - double prevDemarker1 = i >= 1 ? demarkerList[i - 1] : 0; - double prevDemarker2 = i >= 2 ? demarkerList[i - 2] : 0; + var maxMa = maxMaList[i]; + var minMa = minMaList[i]; + var prevDemarker1 = i >= 1 ? demarkerList[i - 1] : 0; + var prevDemarker2 = i >= 2 ? demarkerList[i - 2] : 0; - double demarker = maxMa + minMa != 0 ? MinOrMax(maxMa / (maxMa + minMa) * 100, 100, 0) : 0; + var demarker = maxMa + minMa != 0 ? MinOrMax(maxMa / (maxMa + minMa) * 100, 100, 0) : 0; demarkerList.AddRounded(demarker); var signal = GetRsiSignal(demarker - prevDemarker1, prevDemarker1 - prevDemarker2, demarker, prevDemarker1, 70, 30); diff --git a/src/Calculations/Ehlers.cs b/src/Calculations/Ehlers.cs index c25820d..97c5634 100644 --- a/src/Calculations/Ehlers.cs +++ b/src/Calculations/Ehlers.cs @@ -26,36 +26,36 @@ public static StockData CalculateEhlersRoofingFilterV2(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alphaArg = Math.Min(0.707 * 2 * Math.PI / upperLength, 0.99); - double alphaCos = Math.Cos(alphaArg); - double alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; - double a1 = Exp(-1.414 * Math.PI / lowerLength); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / lowerLength, 0.99)); - double c2 = b1; - double c3 = -1 * a1 * a1; - double c1 = 1 - c2 - c3; - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - double prevHp1 = i >= 1 ? highPassList[i - 1] : 0; - double prevHp2 = i >= 2 ? highPassList[i - 2] : 0; - double test1 = Pow((1 - alpha1) / 2, 2); - double test2 = currentValue - (2 * prevValue1) + prevValue2; - double v1 = test1 * test2; - double v2 = 2 * (1 - alpha1) * prevHp1; - double v3 = Pow(1 - alpha1, 2) * prevHp2; - - double highPass = v1 + v2 - v3; + var alphaArg = Math.Min(0.707 * 2 * Math.PI / upperLength, 0.99); + var alphaCos = Math.Cos(alphaArg); + var alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; + var a1 = Exp(-1.414 * Math.PI / lowerLength); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / lowerLength, 0.99)); + var c2 = b1; + var c3 = -1 * a1 * a1; + var c1 = 1 - c2 - c3; + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + var prevHp2 = i >= 2 ? highPassList[i - 2] : 0; + var test1 = Pow((1 - alpha1) / 2, 2); + var test2 = currentValue - (2 * prevValue1) + prevValue2; + var v1 = test1 * test2; + var v2 = 2 * (1 - alpha1) * prevHp1; + var v3 = Pow(1 - alpha1, 2) * prevHp2; + + var highPass = v1 + v2 - v3; highPassList.AddRounded(highPass); - double prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - double roofingFilter = (c1 * ((highPass + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var roofingFilter = (c1 * ((highPass + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); roofingFilterList.AddRounded(roofingFilter); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); @@ -87,17 +87,17 @@ public static StockData CalculateEhlersPhaseCalculation(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double realPart = 0, imagPart = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double weight = i >= j ? inputList[i - j] : 0; + var weight = i >= j ? inputList[i - j] : 0; realPart += Math.Cos(2 * Math.PI * j / length) * weight; imagPart += Math.Sin(2 * Math.PI * j / length) * weight; } - double phase = Math.Abs(realPart) > 0.001 ? Math.Atan(imagPart / realPart).ToDegrees() : 90 * Math.Sign(imagPart); + var phase = Math.Abs(realPart) > 0.001 ? Math.Atan(imagPart / realPart).ToDegrees() : 90 * Math.Sign(imagPart); phase = realPart < 0 ? phase + 180 : phase; phase += 90; phase = phase < 0 ? phase + 360 : phase; @@ -106,12 +106,12 @@ public static StockData CalculateEhlersPhaseCalculation(this StockData stockData } var phaseEmaList = GetMovingAverageList(stockData, maType, length, phaseList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double phase = phaseList[i]; - double phaseEma = phaseEmaList[i]; - double prevPhase = i >= 1 ? phaseList[i - 1] : 0; - double prevPhaseEma = i >= 1 ? phaseEmaList[i - 1] : 0; + var phase = phaseList[i]; + var phaseEma = phaseEmaList[i]; + var prevPhase = i >= 1 ? phaseList[i - 1] : 0; + var prevPhaseEma = i >= 1 ? phaseEmaList[i - 1] : 0; var signal = GetCompareSignal(phase - phaseEma, prevPhase - prevPhaseEma, true); signalsList.Add(signal); @@ -149,53 +149,53 @@ public static StockData CalculateEhlersAdaptiveCyberCycle(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevCycle = i >= 1 ? cycleList[i - 1] : 0; - double prevSmooth = i >= 1 ? smoothList[i - 1] : 0; - double prevIp = i >= 1 ? ipList[i - 1] : 0; - double prevAc1 = i >= 1 ? acList[i - 1] : 0; - double prevI1 = i >= 1 ? i1List[i - 1] : 0; - double prevQ1 = i >= 1 ? q1List[i - 1] : 0; - double prevP = i >= 1 ? pList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; - double prevCycle2 = i >= 2 ? cycleList[i - 2] : 0; - double prevAc2 = i >= 2 ? acList[i - 2] : 0; - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; - double prevCycle3 = i >= 3 ? cycleList[i - 3] : 0; - double prevCycle4 = i >= 4 ? cycleList[i - 4] : 0; - double prevCycle6 = i >= 6 ? cycleList[i - 6] : 0; - - double smooth = (currentValue + (2 * prevValue) + (2 * prevValue2) + prevValue3) / 6; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevCycle = i >= 1 ? cycleList[i - 1] : 0; + var prevSmooth = i >= 1 ? smoothList[i - 1] : 0; + var prevIp = i >= 1 ? ipList[i - 1] : 0; + var prevAc1 = i >= 1 ? acList[i - 1] : 0; + var prevI1 = i >= 1 ? i1List[i - 1] : 0; + var prevQ1 = i >= 1 ? q1List[i - 1] : 0; + var prevP = i >= 1 ? pList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + var prevCycle2 = i >= 2 ? cycleList[i - 2] : 0; + var prevAc2 = i >= 2 ? acList[i - 2] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var prevCycle3 = i >= 3 ? cycleList[i - 3] : 0; + var prevCycle4 = i >= 4 ? cycleList[i - 4] : 0; + var prevCycle6 = i >= 6 ? cycleList[i - 6] : 0; + + var smooth = (currentValue + (2 * prevValue) + (2 * prevValue2) + prevValue3) / 6; smoothList.AddRounded(smooth); - double cycle = i < 7 ? (currentValue - (2 * prevValue) + prevValue2) / 4 : (Pow(1 - (0.5 * alpha), 2) * (smooth - (2 * prevSmooth) + prevSmooth2)) + + var cycle = i < 7 ? (currentValue - (2 * prevValue) + prevValue2) / 4 : (Pow(1 - (0.5 * alpha), 2) * (smooth - (2 * prevSmooth) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle) - (Pow(1 - alpha, 2) * prevCycle2); cycleList.AddRounded(cycle); - double q1 = ((0.0962 * cycle) + (0.5769 * prevCycle2) - (0.5769 * prevCycle4) - (0.0962 * prevCycle6)) * (0.5 + (0.08 * prevIp)); + var q1 = ((0.0962 * cycle) + (0.5769 * prevCycle2) - (0.5769 * prevCycle4) - (0.0962 * prevCycle6)) * (0.5 + (0.08 * prevIp)); q1List.AddRounded(q1); - double i1 = prevCycle3; + var i1 = prevCycle3; i1List.AddRounded(i1); - double dp = MinOrMax(q1 != 0 && prevQ1 != 0 ? ((i1 / q1) - (prevI1 / prevQ1)) / (1 + (i1 * prevI1 / (q1 * prevQ1))) : 0, 1.1, 0.1); + var dp = MinOrMax(q1 != 0 && prevQ1 != 0 ? ((i1 / q1) - (prevI1 / prevQ1)) / (1 + (i1 * prevI1 / (q1 * prevQ1))) : 0, 1.1, 0.1); dpList.AddRounded(dp); - double medianDelta = dpList.TakeLastExt(length).Median(); - double dc = medianDelta != 0 ? (6.28318 / medianDelta) + 0.5 : 15; + var medianDelta = dpList.TakeLastExt(length).Median(); + var dc = medianDelta != 0 ? (6.28318 / medianDelta) + 0.5 : 15; - double ip = (0.33 * dc) + (0.67 * prevIp); + var ip = (0.33 * dc) + (0.67 * prevIp); ipList.AddRounded(ip); - double p = (0.15 * ip) + (0.85 * prevP); + var p = (0.15 * ip) + (0.85 * prevP); pList.AddRounded(p); - double a1 = 2 / (p + 1); - double ac = i < 7 ? (currentValue - (2 * prevValue) + prevValue2) / 4 : + var a1 = 2 / (p + 1); + var ac = i < 7 ? (currentValue - (2 * prevValue) + prevValue2) / 4 : (Pow(1 - (0.5 * a1), 2) * (smooth - (2 * prevSmooth) + prevSmooth2)) + (2 * (1 - a1) * prevAc1) - (Pow(1 - a1, 2) * prevAc2); acList.AddRounded(ac); @@ -233,20 +233,20 @@ public static StockData CalculateEhlersSimpleDecycler(this StockData stockData, var hpList = CalculateEhlersHighPassFilterV1(stockData, length, 1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double hp = hpList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var hp = hpList[i]; - double prevDecycler = decyclerList.LastOrDefault(); - double decycler = currentValue - hp; + var prevDecycler = decyclerList.LastOrDefault(); + var decycler = currentValue - hp; decyclerList.AddRounded(decycler); - double upperBand = (1 + (upperPct / 100)) * decycler; + var upperBand = (1 + (upperPct / 100)) * decycler; upperBandList.AddRounded(upperBand); - double lowerBand = (1 - (lowerPct / 100)) * decycler; + var lowerBand = (1 - (lowerPct / 100)) * decycler; lowerBandList.AddRounded(lowerBand); var signal = GetCompareSignal(currentValue - decycler, prevValue - prevDecycler); @@ -279,21 +279,21 @@ public static StockData CalculateEhlersHighPassFilterV1(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alphaArg = MinOrMax(2 * Math.PI / (mult * length * Sqrt(2)), 0.99, 0.01); - double alphaCos = Math.Cos(alphaArg); - double alpha = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; + var alphaArg = MinOrMax(2 * Math.PI / (mult * length * Sqrt(2)), 0.99, 0.01); + var alphaCos = Math.Cos(alphaArg); + var alpha = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevHp1 = i >= 1 ? highPassList[i - 1] : 0; - double prevHp2 = i >= 2 ? highPassList[i - 2] : 0; - double pow1 = Pow(1 - (alpha / 2), 2); - double pow2 = Pow(1 - alpha, 2); + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + var prevHp2 = i >= 2 ? highPassList[i - 2] : 0; + var pow1 = Pow(1 - (alpha / 2), 2); + var pow2 = Pow(1 - alpha, 2); - double highPass = (pow1 * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - alpha) * prevHp1) - (pow2 * prevHp2); + var highPass = (pow1 * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - alpha) * prevHp1) - (pow2 * prevHp2); highPassList.AddRounded(highPass); var signal = GetCompareSignal(highPass, prevHp1); @@ -333,48 +333,48 @@ public static StockData CalculateEhlersRocketRelativeStrengthIndex(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double obLevel = obosLevel * mult; - double osLevel = -obosLevel * mult; + var obLevel = obosLevel * mult; + var osLevel = -obosLevel * mult; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length1 - 1 ? inputList[i - (length1 - 1)] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length1 - 1 ? inputList[i - (length1 - 1)] : 0; - double prevMom = momList.LastOrDefault(); - double mom = MinPastValues(i, length1 - 1, currentValue - prevValue); + var prevMom = momList.LastOrDefault(); + var mom = MinPastValues(i, length1 - 1, currentValue - prevValue); momList.AddRounded(mom); - double arg = (mom + prevMom) / 2; + var arg = (mom + prevMom) / 2; argList.AddRounded(arg); } var argSsf2PoleList = GetMovingAverageList(stockData, maType, length2, argList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ssf2Pole = argSsf2PoleList[i]; - double prevSsf2Pole = i >= 1 ? argSsf2PoleList[i - 1] : 0; - double prevRocketRsi1 = i >= 1 ? ssf2PoleRocketRsiList[i - 1] : 0; - double prevRocketRsi2 = i >= 2 ? ssf2PoleRocketRsiList[i - 2] : 0; - double ssf2PoleMom = ssf2Pole - prevSsf2Pole; + var ssf2Pole = argSsf2PoleList[i]; + var prevSsf2Pole = i >= 1 ? argSsf2PoleList[i - 1] : 0; + var prevRocketRsi1 = i >= 1 ? ssf2PoleRocketRsiList[i - 1] : 0; + var prevRocketRsi2 = i >= 2 ? ssf2PoleRocketRsiList[i - 2] : 0; + var ssf2PoleMom = ssf2Pole - prevSsf2Pole; - double up2PoleChg = ssf2PoleMom > 0 ? ssf2PoleMom : 0; + var up2PoleChg = ssf2PoleMom > 0 ? ssf2PoleMom : 0; ssf2PoleUpChgList.AddRounded(up2PoleChg); - double down2PoleChg = ssf2PoleMom < 0 ? Math.Abs(ssf2PoleMom) : 0; + var down2PoleChg = ssf2PoleMom < 0 ? Math.Abs(ssf2PoleMom) : 0; ssf2PoleDownChgList.AddRounded(down2PoleChg); - double up2PoleChgSum = ssf2PoleUpChgList.TakeLastExt(length1).Sum(); - double down2PoleChgSum = ssf2PoleDownChgList.TakeLastExt(length1).Sum(); + var up2PoleChgSum = ssf2PoleUpChgList.TakeLastExt(length1).Sum(); + var down2PoleChgSum = ssf2PoleDownChgList.TakeLastExt(length1).Sum(); - double prevTmp2Pole = ssf2PoleTmpList.LastOrDefault(); - double tmp2Pole = up2PoleChgSum + down2PoleChgSum != 0 ? + var prevTmp2Pole = ssf2PoleTmpList.LastOrDefault(); + var tmp2Pole = up2PoleChgSum + down2PoleChgSum != 0 ? MinOrMax((up2PoleChgSum - down2PoleChgSum) / (up2PoleChgSum + down2PoleChgSum), 0.999, -0.999) : prevTmp2Pole; ssf2PoleTmpList.AddRounded(tmp2Pole); - double ssf2PoleTempLog = 1 - tmp2Pole != 0 ? (1 + tmp2Pole) / (1 - tmp2Pole) : 0; - double ssf2PoleLog = Math.Log(ssf2PoleTempLog); - double ssf2PoleRocketRsi = 0.5 * ssf2PoleLog * mult; + var ssf2PoleTempLog = 1 - tmp2Pole != 0 ? (1 + tmp2Pole) / (1 - tmp2Pole) : 0; + var ssf2PoleLog = Math.Log(ssf2PoleTempLog); + var ssf2PoleRocketRsi = 0.5 * ssf2PoleLog * mult; ssf2PoleRocketRsiList.AddRounded(ssf2PoleRocketRsi); var signal = GetRsiSignal(ssf2PoleRocketRsi - prevRocketRsi1, prevRocketRsi1 - prevRocketRsi2, ssf2PoleRocketRsi, prevRocketRsi1, obLevel, osLevel); @@ -404,15 +404,15 @@ public static StockData CalculateEhlersCorrelationTrendIndicator(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevCorr1 = i >= 1 ? corrList[i - 1] : 0; - double prevCorr2 = i >= 2 ? corrList[i - 2] : 0; + var prevCorr1 = i >= 1 ? corrList[i - 1] : 0; + var prevCorr2 = i >= 2 ? corrList[i - 2] : 0; double sx = 0, sy = 0, sxx = 0, sxy = 0, syy = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double x = i >= j ? inputList[i - j] : 0; + var x = i >= j ? inputList[i - j] : 0; double y = -j; sx += x; @@ -422,7 +422,7 @@ public static StockData CalculateEhlersCorrelationTrendIndicator(this StockData syy += Pow(y, 2); } - double corr = (length * sxx) - (sx * sx) > 0 && (length * syy) - (sy * sy) > 0 ? ((length * sxy) - (sx * sy)) / + var corr = (length * sxx) - (sx * sx) > 0 && (length * syy) - (sy * sy) > 0 ? ((length * sxy) - (sx * sy)) / Sqrt(((length * sxx) - (sx * sx)) * ((length * syy) - (sy * sy))) : 0; corrList.AddRounded(corr); @@ -456,25 +456,25 @@ public static StockData CalculateEhlersRelativeVigorIndex(this StockData stockDa List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double rvi = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; + var rvi = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; rviList.AddRounded(rvi); } var rviSmaList = GetMovingAverageList(stockData, maType, length, rviList); var rviSignalList = GetMovingAverageList(stockData, maType, signalLength, rviSmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rviSma = rviSmaList[i]; - double prevRviSma = i >= 1 ? rviSmaList[i - 1] : 0; - double rviSignal = rviSignalList[i]; - double prevRviSignal = i >= 1 ? rviSignalList[i - 1] : 0; + var rviSma = rviSmaList[i]; + var prevRviSma = i >= 1 ? rviSmaList[i - 1] : 0; + var rviSignal = rviSignalList[i]; + var prevRviSignal = i >= 1 ? rviSignalList[i - 1] : 0; var signal = GetCompareSignal(rviSma - rviSignal, prevRviSma - prevRviSignal); signalsList.Add(signal); @@ -504,18 +504,18 @@ public static StockData CalculateEhlersCenterofGravityOscillator(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double num = 0, denom = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; num += (1 + j) * prevValue; denom += prevValue; } - double prevCg = cgList.LastOrDefault(); - double cg = denom != 0 ? (-num / denom) + ((double)(length + 1) / 2) : 0; + var prevCg = cgList.LastOrDefault(); + var cg = denom != 0 ? (-num / denom) + ((double)(length + 1) / 2) : 0; cgList.AddRounded(cg); var signal = GetCompareSignal(cg, prevCg); @@ -547,22 +547,22 @@ public static StockData CalculateEhlersAdaptiveCenterOfGravityOscillator(this St var pList = CalculateEhlersAdaptiveCyberCycle(stockData, length: length).OutputValues["Period"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double p = pList[i]; - int intPeriod = (int)Math.Ceiling(p / 2); - double prevCg1 = i >= 1 ? cgList[i - 1] : 0; - double prevCg2 = i >= 2 ? cgList[i - 2] : 0; + var p = pList[i]; + var intPeriod = (int)Math.Ceiling(p / 2); + var prevCg1 = i >= 1 ? cgList[i - 1] : 0; + var prevCg2 = i >= 2 ? cgList[i - 2] : 0; double num = 0, denom = 0; - for (int j = 0; j <= intPeriod - 1; j++) + for (var j = 0; j <= intPeriod - 1; j++) { - double prevPrice = i >= j ? inputList[i - j] : 0; + var prevPrice = i >= j ? inputList[i - j] : 0; num += (1 + j) * prevPrice; denom += prevPrice; } - double cg = denom != 0 ? (-num / denom) + ((intPeriod + 1) / 2) : 0; + var cg = denom != 0 ? (-num / denom) + ((intPeriod + 1) / 2) : 0; cgList.AddRounded(cg); var signal = GetCompareSignal(cg - prevCg1, prevCg1 - prevCg2); @@ -595,38 +595,38 @@ public static StockData CalculateEhlersSmoothedAdaptiveMomentum(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(-Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(1.738 * Math.PI / length2); - double c1 = Pow(a1, 2); - double coef2 = b1 + c1; - double coef3 = -1 * (c1 + (b1 * c1)); - double coef4 = c1 * c1; - double coef1 = 1 - coef2 - coef3 - coef4; + var a1 = Exp(-Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(1.738 * Math.PI / length2); + var c1 = Pow(a1, 2); + var coef2 = b1 + c1; + var coef3 = -1 * (c1 + (b1 * c1)); + var coef4 = c1 * c1; + var coef1 = 1 - coef2 - coef3 - coef4; var pList = CalculateEhlersAdaptiveCyberCycle(stockData, length1).OutputValues["Period"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double p = pList[i]; - double prevF3_1 = i >= 1 ? f3List[i - 1] : 0; - double prevF3_2 = i >= 2 ? f3List[i - 2] : 0; - double prevF3_3 = i >= 3 ? f3List[i - 3] : 0; - int pr = (int)Math.Ceiling(Math.Abs(p - 1)); - double prevValue = i >= pr ? inputList[i - pr] : 0; - double v1 = MinPastValues(i, pr, currentValue - prevValue); + var currentValue = inputList[i]; + var p = pList[i]; + var prevF3_1 = i >= 1 ? f3List[i - 1] : 0; + var prevF3_2 = i >= 2 ? f3List[i - 2] : 0; + var prevF3_3 = i >= 3 ? f3List[i - 3] : 0; + var pr = (int)Math.Ceiling(Math.Abs(p - 1)); + var prevValue = i >= pr ? inputList[i - pr] : 0; + var v1 = MinPastValues(i, pr, currentValue - prevValue); - double f3 = (coef1 * v1) + (coef2 * prevF3_1) + (coef3 * prevF3_2) + (coef4 * prevF3_3); + var f3 = (coef1 * v1) + (coef2 * prevF3_1) + (coef3 * prevF3_2) + (coef4 * prevF3_3); f3List.AddRounded(f3); } var f3EmaList = GetMovingAverageList(stockData, maType, length2, f3List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double f3 = f3List[i]; - double f3Ema = f3EmaList[i]; - double prevF3 = i >= 1 ? f3List[i - 1] : 0; - double prevF3Ema = i >= 1 ? f3EmaList[i - 1] : 0; + var f3 = f3List[i]; + var f3Ema = f3EmaList[i]; + var prevF3 = i >= 1 ? f3List[i - 1] : 0; + var prevF3Ema = i >= 1 ? f3EmaList[i - 1] : 0; var signal = GetCompareSignal(f3 - f3Ema, prevF3 - prevF3Ema); signalsList.Add(signal); @@ -660,26 +660,26 @@ public static StockData CalculateEhlersStochasticCenterOfGravityOscillator(this var ehlersCGOscillatorList = CalculateEhlersCenterofGravityOscillator(stockData, length).CustomValuesList; var (highestList, lowestList) = GetMaxAndMinValuesList(ehlersCGOscillatorList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double cg = ehlersCGOscillatorList[i]; - double maxc = highestList[i]; - double minc = lowestList[i]; - double prevV1_1 = i >= 1 ? v1List[i - 1] : 0; - double prevV1_2 = i >= 2 ? v1List[i - 2] : 0; - double prevV1_3 = i >= 3 ? v1List[i - 3] : 0; - double prevV2_1 = i >= 1 ? v2List[i - 1] : 0; - double prevT1 = i >= 1 ? tList[i - 1] : 0; - double prevT2 = i >= 2 ? tList[i - 2] : 0; + var cg = ehlersCGOscillatorList[i]; + var maxc = highestList[i]; + var minc = lowestList[i]; + var prevV1_1 = i >= 1 ? v1List[i - 1] : 0; + var prevV1_2 = i >= 2 ? v1List[i - 2] : 0; + var prevV1_3 = i >= 3 ? v1List[i - 3] : 0; + var prevV2_1 = i >= 1 ? v2List[i - 1] : 0; + var prevT1 = i >= 1 ? tList[i - 1] : 0; + var prevT2 = i >= 2 ? tList[i - 2] : 0; - double v1 = maxc - minc != 0 ? (cg - minc) / (maxc - minc) : 0; + var v1 = maxc - minc != 0 ? (cg - minc) / (maxc - minc) : 0; v1List.AddRounded(v1); - double v2_ = ((4 * v1) + (3 * prevV1_1) + (2 * prevV1_2) + prevV1_3) / 10; - double v2 = 2 * (v2_ - 0.5); + var v2_ = ((4 * v1) + (3 * prevV1_1) + (2 * prevV1_2) + prevV1_3) / 10; + var v2 = 2 * (v2_ - 0.5); v2List.AddRounded(v2); - double t = MinOrMax(0.96 * (prevV2_1 + 0.02), 1, 0); + var t = MinOrMax(0.96 * (prevV2_1 + 0.02), 1, 0); tList.AddRounded(t); var signal = GetRsiSignal(t - prevT1, prevT1 - prevT2, t, prevT1, 0.8, 0.2); @@ -711,27 +711,27 @@ public static StockData CalculateEhlersSimpleCycleIndicator(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentMedianPrice = inputList[i]; - double prevMedianPrice1 = i >= 1 ? inputList[i - 1] : 0; - double prevMedianPrice2 = i >= 2 ? inputList[i - 2] : 0; - double prevMedianPrice3 = i >= 3 ? inputList[i - 3] : 0; - double prevSmooth1 = smoothList.LastOrDefault(); - double prevCycle1 = cycle_List.LastOrDefault(); - double prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; - double prevCycle2 = i >= 2 ? cycle_List[i - 2] : 0; - double prevCyc1 = i >= 1 ? cycleList[i - 1] : 0; - double prevCyc2 = i >= 2 ? cycleList[i - 2] : 0; + var currentMedianPrice = inputList[i]; + var prevMedianPrice1 = i >= 1 ? inputList[i - 1] : 0; + var prevMedianPrice2 = i >= 2 ? inputList[i - 2] : 0; + var prevMedianPrice3 = i >= 3 ? inputList[i - 3] : 0; + var prevSmooth1 = smoothList.LastOrDefault(); + var prevCycle1 = cycle_List.LastOrDefault(); + var prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + var prevCycle2 = i >= 2 ? cycle_List[i - 2] : 0; + var prevCyc1 = i >= 1 ? cycleList[i - 1] : 0; + var prevCyc2 = i >= 2 ? cycleList[i - 2] : 0; - double smooth = (currentMedianPrice + (2 * prevMedianPrice1) + (2 * prevMedianPrice2) + prevMedianPrice3) / 6; + var smooth = (currentMedianPrice + (2 * prevMedianPrice1) + (2 * prevMedianPrice2) + prevMedianPrice3) / 6; smoothList.AddRounded(smooth); - double cycle_ = ((1 - (0.5 * alpha)) * (1 - (0.5 * alpha)) * (smooth - (2 * prevSmooth1) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle1) - - ((1 - alpha) * (1 - alpha) * prevCycle2); + var cycle_ = ((1 - (0.5 * alpha)) * (1 - (0.5 * alpha)) * (smooth - (2 * prevSmooth1) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle1) - + ((1 - alpha) * (1 - alpha) * prevCycle2); cycle_List.AddRounded(cycle_); - double cycle = i < 7 ? (currentMedianPrice - (2 * prevMedianPrice1) + prevMedianPrice2) / 4 : cycle_; + var cycle = i < 7 ? (currentMedianPrice - (2 * prevMedianPrice1) + prevMedianPrice2) / 4 : cycle_; cycleList.AddRounded(cycle); var signal = GetCompareSignal(cycle - prevCyc1, prevCyc1 - prevCyc2); @@ -773,18 +773,18 @@ public static StockData CalculateEhlersDecyclerOscillatorV1(this StockData stock stockData.CustomValuesList = decycler2List; var decycler2FilteredList = CalculateEhlersHighPassFilterV1(stockData, slowLength, 0.5).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double decycler1Filtered = decycler1FilteredList[i]; - double decycler2Filtered = decycler2FilteredList[i]; + var currentValue = inputList[i]; + var decycler1Filtered = decycler1FilteredList[i]; + var decycler2Filtered = decycler2FilteredList[i]; - double prevDecyclerOsc1 = decycler1OscillatorList.LastOrDefault(); - double decyclerOscillator1 = currentValue != 0 ? 100 * fastMult * decycler1Filtered / currentValue : 0; + var prevDecyclerOsc1 = decycler1OscillatorList.LastOrDefault(); + var decyclerOscillator1 = currentValue != 0 ? 100 * fastMult * decycler1Filtered / currentValue : 0; decycler1OscillatorList.AddRounded(decyclerOscillator1); - double prevDecyclerOsc2 = decycler2OscillatorList.LastOrDefault(); - double decyclerOscillator2 = currentValue != 0 ? 100 * slowMult * decycler2Filtered / currentValue : 0; + var prevDecyclerOsc2 = decycler2OscillatorList.LastOrDefault(); + var decyclerOscillator2 = currentValue != 0 ? 100 * slowMult * decycler2Filtered / currentValue : 0; decycler2OscillatorList.AddRounded(decyclerOscillator2); var signal = GetCompareSignal(decyclerOscillator2 - decyclerOscillator1, prevDecyclerOsc2 - prevDecyclerOsc1); @@ -816,31 +816,31 @@ public static StockData CalculateEhlersHighPassFilterV2(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(-1.414 * Math.PI / length); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = (1 + c2 - c3) / 4; + var a1 = Exp(-1.414 * Math.PI / length); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = (1 + c2 - c3) / 4; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); + var hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); hpList.AddRounded(hp); } var hpMa1List = GetMovingAverageList(stockData, maType, length, hpList); var hpMa2List = GetMovingAverageList(stockData, maType, length, hpMa1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double hp = hpMa2List[i]; - double prevHp1 = i >= 1 ? hpMa2List[i - 1] : 0; - double prevHp2 = i >= 2 ? hpMa2List[i - 2] : 0; + var hp = hpMa2List[i]; + var prevHp1 = i >= 1 ? hpMa2List[i - 1] : 0; + var prevHp2 = i >= 2 ? hpMa2List[i - 2] : 0; var signal = GetCompareSignal(hp - prevHp1, prevHp1 - prevHp2); signalsList.Add(signal); @@ -874,13 +874,13 @@ public static StockData CalculateEhlersDecyclerOscillatorV2(this StockData stock var hp1List = CalculateEhlersHighPassFilterV2(stockData, maType, fastLength).CustomValuesList; var hp2List = CalculateEhlersHighPassFilterV2(stockData, maType, slowLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double hp1 = hp1List[i]; - double hp2 = hp2List[i]; + var hp1 = hp1List[i]; + var hp2 = hp2List[i]; - double prevDec = decList.LastOrDefault(); - double dec = hp2 - hp1; + var prevDec = decList.LastOrDefault(); + var dec = hp2 - hp1; decList.AddRounded(dec); var signal = GetCompareSignal(dec, prevDec); @@ -914,28 +914,28 @@ public static StockData CalculateEhlersModifiedStochasticIndicator(this StockDat List modStocList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length1); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length1, 0.99)); - double c2 = b1; - double c3 = -1 * a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length1); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length1, 0.99)); + var c2 = b1; + var c3 = -1 * a1 * a1; + var c1 = 1 - c2 - c3; var roofingFilterList = CalculateEhlersRoofingFilterV1(stockData, maType, length1, length2).CustomValuesList; var (highestList, lowestList) = GetMaxAndMinValuesList(roofingFilterList, length3); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double roofingFilter = roofingFilterList[i]; - double prevModStoc1 = i >= 1 ? modStocList[i - 1] : 0; - double prevModStoc2 = i >= 2 ? modStocList[i - 2] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var roofingFilter = roofingFilterList[i]; + var prevModStoc1 = i >= 1 ? modStocList[i - 1] : 0; + var prevModStoc2 = i >= 2 ? modStocList[i - 2] : 0; - double prevStoc = stocList.LastOrDefault(); - double stoc = highest - lowest != 0 ? (roofingFilter - lowest) / (highest - lowest) * 100 : 0; + var prevStoc = stocList.LastOrDefault(); + var stoc = highest - lowest != 0 ? (roofingFilter - lowest) / (highest - lowest) * 100 : 0; stocList.AddRounded(stoc); - double modStoc = (c1 * ((stoc + prevStoc) / 2)) + (c2 * prevModStoc1) + (c3 * prevModStoc2); + var modStoc = (c1 * ((stoc + prevStoc) / 2)) + (c2 * prevModStoc1) + (c3 * prevModStoc2); modStocList.AddRounded(modStoc); var signal = GetRsiSignal(modStoc - prevModStoc1, prevModStoc1 - prevModStoc2, modStoc, prevModStoc1, 70, 30); @@ -970,39 +970,39 @@ public static StockData CalculateEhlersModifiedRelativeStrengthIndex(this StockD List mrsiSigList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -1 * a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -1 * a1 * a1; + var c1 = 1 - c2 - c3; var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roofingFilter = roofingFilterList[i]; - double prevRoofingFilter = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevMrsi1 = i >= 1 ? mrsiList[i - 1] : 0; - double prevMrsi2 = i >= 2 ? mrsiList[i - 2] : 0; - double prevMrsiSig1 = i >= 1 ? mrsiSigList[i - 1] : 0; - double prevMrsiSig2 = i >= 2 ? mrsiSigList[i - 2] : 0; + var roofingFilter = roofingFilterList[i]; + var prevRoofingFilter = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevMrsi1 = i >= 1 ? mrsiList[i - 1] : 0; + var prevMrsi2 = i >= 2 ? mrsiList[i - 2] : 0; + var prevMrsiSig1 = i >= 1 ? mrsiSigList[i - 1] : 0; + var prevMrsiSig2 = i >= 2 ? mrsiSigList[i - 2] : 0; - double upChg = roofingFilter > prevRoofingFilter ? roofingFilter - prevRoofingFilter : 0; + var upChg = roofingFilter > prevRoofingFilter ? roofingFilter - prevRoofingFilter : 0; upChgList.AddRounded(upChg); - double dnChg = roofingFilter < prevRoofingFilter ? prevRoofingFilter - roofingFilter : 0; - double prevUpChgSum = upChgSumList.LastOrDefault(); - double upChgSum = upChgList.TakeLastExt(length3).Sum(); + var dnChg = roofingFilter < prevRoofingFilter ? prevRoofingFilter - roofingFilter : 0; + var prevUpChgSum = upChgSumList.LastOrDefault(); + var upChgSum = upChgList.TakeLastExt(length3).Sum(); upChgSumList.AddRounded(upChgSum); - double prevDenom = denomList.LastOrDefault(); - double denom = upChg + dnChg; + var prevDenom = denomList.LastOrDefault(); + var denom = upChg + dnChg; denomList.AddRounded(denom); - double mrsi = denom != 0 && prevDenom != 0 ? (c1 * (((upChgSum / denom) + (prevUpChgSum / prevDenom)) / 2)) + (c2 * prevMrsi1) + (c3 * prevMrsi2) : 0; + var mrsi = denom != 0 && prevDenom != 0 ? (c1 * (((upChgSum / denom) + (prevUpChgSum / prevDenom)) / 2)) + (c2 * prevMrsi1) + (c3 * prevMrsi2) : 0; mrsiList.AddRounded(mrsi); - double mrsiSig = (c1 * ((mrsi + prevMrsi1) / 2)) + (c2 * prevMrsiSig1) + (c3 * prevMrsiSig2); + var mrsiSig = (c1 * ((mrsi + prevMrsi1) / 2)) + (c2 * prevMrsiSig1) + (c3 * prevMrsiSig2); mrsiSigList.AddRounded(mrsiSig); var signal = GetRsiSignal(mrsi - mrsiSig, prevMrsi1 - prevMrsiSig1, mrsi, prevMrsi1, 0.7, 0.3); @@ -1035,27 +1035,27 @@ public static StockData CalculateEhlersHpLpRoofingFilter(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alphaArg = Math.Min(2 * Math.PI / length1, 0.99); - double alphaCos = Math.Cos(alphaArg); - double alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -1 * a1 * a1; - double c1 = 1 - c2 - c3; + var alphaArg = Math.Min(2 * Math.PI / length1, 0.99); + var alphaCos = Math.Cos(alphaArg); + var alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -1 * a1 * a1; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - double prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var prevHp1 = i >= 1 ? highPassList[i - 1] : 0; - double hp = ((1 - (alpha1 / 2)) * MinPastValues(i, 1, currentValue - prevValue)) + ((1 - alpha1) * prevHp1); + var hp = ((1 - (alpha1 / 2)) * MinPastValues(i, 1, currentValue - prevValue)) + ((1 - alpha1) * prevHp1); highPassList.AddRounded(hp); - double filter = (c1 * ((hp + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filter = (c1 * ((hp + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); roofingFilterList.AddRounded(filter); var signal = GetCompareSignal(filter - prevFilter1, prevFilter1 - prevFilter2); @@ -1085,17 +1085,17 @@ public static StockData CalculateEhlersDecycler(this StockData stockData, int le List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alphaArg = Math.Min(2 * Math.PI / length, 0.99); - double alphaCos = Math.Cos(alphaArg); - double alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; + var alphaArg = Math.Min(2 * Math.PI / length, 0.99); + var alphaCos = Math.Cos(alphaArg); + var alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevDec = decList.LastOrDefault(); - double dec = (alpha1 / 2 * (currentValue + prevValue1)) + ((1 - alpha1) * prevDec); + var prevDec = decList.LastOrDefault(); + var dec = (alpha1 / 2 * (currentValue + prevValue1)) + ((1 - alpha1) * prevDec); decList.AddRounded(dec); var signal = GetCompareSignal(currentValue - dec, prevValue1 - prevDec); @@ -1125,20 +1125,20 @@ public static StockData CalculateEhlersZeroMeanRoofingFilter(this StockData stoc List zmrFilterList = new(); List signalsList = new(); - double alphaArg = Math.Min(2 * Math.PI / length1, 0.99); - double alphaCos = Math.Cos(alphaArg); - double alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; + var alphaArg = Math.Min(2 * Math.PI / length1, 0.99); + var alphaCos = Math.Cos(alphaArg); + var alpha1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; var roofingFilterList = CalculateEhlersHpLpRoofingFilter(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRf = roofingFilterList[i]; - double prevRf = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevZmrFilt1 = i >= 1 ? zmrFilterList[i - 1] : 0; - double prevZmrFilt2 = i >= 2 ? zmrFilterList[i - 2] : 0; + var currentRf = roofingFilterList[i]; + var prevRf = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevZmrFilt1 = i >= 1 ? zmrFilterList[i - 1] : 0; + var prevZmrFilt2 = i >= 2 ? zmrFilterList[i - 2] : 0; - double zmrFilt = ((1 - (alpha1 / 2)) * (currentRf - prevRf)) + ((1 - alpha1) * prevZmrFilt1); + var zmrFilt = ((1 - (alpha1 / 2)) * (currentRf - prevRf)) + ((1 - alpha1) * prevZmrFilt1); zmrFilterList.AddRounded(zmrFilt); var signal = GetCompareSignal(zmrFilt - prevZmrFilt1, prevZmrFilt1 - prevZmrFilt2); @@ -1170,29 +1170,29 @@ public static StockData CalculateEhlersRoofingFilterIndicator(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alphaArg = Math.Min(0.707 * 2 * Math.PI / length1, 0.99); - double alphaCos = Math.Cos(alphaArg); - double a1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; - double a2 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a2 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -a2 * a2; - double c1 = 1 - c2 - c3; - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - double prevHp1 = i >= 1 ? highPassList[i - 1] : 0; - double prevHp2 = i >= 2 ? highPassList[i - 2] : 0; - - double hp = (Pow(1 - (a1 / 2), 2) * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - a1) * prevHp1) - (Pow(1 - a1, 2) * prevHp2); + var alphaArg = Math.Min(0.707 * 2 * Math.PI / length1, 0.99); + var alphaCos = Math.Cos(alphaArg); + var a1 = alphaCos != 0 ? (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos : 0; + var a2 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a2 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -a2 * a2; + var c1 = 1 - c2 - c3; + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + var prevHp2 = i >= 2 ? highPassList[i - 2] : 0; + + var hp = (Pow(1 - (a1 / 2), 2) * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - a1) * prevHp1) - (Pow(1 - a1, 2) * prevHp2); highPassList.AddRounded(hp); - double filter = (c1 * ((hp + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filter = (c1 * ((hp + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); roofingFilterList.AddRounded(filter); var signal = GetCompareSignal(filter - prevFilter1, prevFilter1 - prevFilter2); @@ -1225,48 +1225,48 @@ public static StockData CalculateEhlersHurstCoefficient(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int hLength = (int)Math.Ceiling((double)length1 / 2); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var hLength = (int)Math.Ceiling((double)length1 / 2); + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var (hh3List, ll3List) = GetMaxAndMinValuesList(inputList, length1); var (hh1List, ll1List) = GetMaxAndMinValuesList(inputList, hLength); - for (int i = 0; i < stockData.Count; i++) - { - double hh3 = hh3List[i]; - double ll3 = ll3List[i]; - double hh1 = hh1List[i]; - double ll1 = ll1List[i]; - double currentValue = inputList[i]; - double priorValue = i >= hLength ? inputList[i - hLength] : currentValue; - double prevSmoothHurst1 = i >= 1 ? smoothHurstList[i - 1] : 0; - double prevSmoothHurst2 = i >= 2 ? smoothHurstList[i - 2] : 0; - double n3 = (hh3 - ll3) / length1; - double n1 = (hh1 - ll1) / hLength; - double hh2 = i >= hLength ? priorValue : currentValue; - double ll2 = i >= hLength ? priorValue : currentValue; - - for (int j = hLength; j < length1; j++) + for (var i = 0; i < stockData.Count; i++) + { + var hh3 = hh3List[i]; + var ll3 = ll3List[i]; + var hh1 = hh1List[i]; + var ll1 = ll1List[i]; + var currentValue = inputList[i]; + var priorValue = i >= hLength ? inputList[i - hLength] : currentValue; + var prevSmoothHurst1 = i >= 1 ? smoothHurstList[i - 1] : 0; + var prevSmoothHurst2 = i >= 2 ? smoothHurstList[i - 2] : 0; + var n3 = (hh3 - ll3) / length1; + var n1 = (hh1 - ll1) / hLength; + var hh2 = i >= hLength ? priorValue : currentValue; + var ll2 = i >= hLength ? priorValue : currentValue; + + for (var j = hLength; j < length1; j++) { - double price = i >= j ? inputList[i - j] : 0; + var price = i >= j ? inputList[i - j] : 0; hh2 = price > hh2 ? price : hh2; ll2 = price < ll2 ? price : ll2; } - double n2 = (hh2 - ll2) / hLength; + var n2 = (hh2 - ll2) / hLength; - double prevDimen = dimenList.LastOrDefault(); - double dimen = 0.5 * (((Math.Log(n1 + n2) - Math.Log(n3)) / Math.Log(2)) + prevDimen); + var prevDimen = dimenList.LastOrDefault(); + var dimen = 0.5 * (((Math.Log(n1 + n2) - Math.Log(n3)) / Math.Log(2)) + prevDimen); dimenList.AddRounded(dimen); - double prevHurst = hurstList.LastOrDefault(); - double hurst = 2 - dimen; + var prevHurst = hurstList.LastOrDefault(); + var hurst = 2 - dimen; hurstList.AddRounded(hurst); - double smoothHurst = (c1 * ((hurst + prevHurst) / 2)) + (c2 * prevSmoothHurst1) + (c3 * prevSmoothHurst2); + var smoothHurst = (c1 * ((hurst + prevHurst) / 2)) + (c2 * prevSmoothHurst1) + (c3 * prevSmoothHurst2); smoothHurstList.AddRounded(smoothHurst); var signal = GetCompareSignal(smoothHurst - prevSmoothHurst1, prevSmoothHurst1 - prevSmoothHurst2); @@ -1298,39 +1298,39 @@ public static StockData CalculateEhlersReflexIndicator(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(-1.414 * Math.PI / 0.5 * length); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / 0.5 * length); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / 0.5 * length); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / 0.5 * length); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = filterList.LastOrDefault(); - double prevFilter2 = i >= 2 ? filterList[i - 2] : 0; - double priorFilter = i >= length ? filterList[i - length] : 0; - double prevReflex1 = i >= 1 ? reflexList[i - 1] : 0; - double prevReflex2 = i >= 2 ? reflexList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = filterList.LastOrDefault(); + var prevFilter2 = i >= 2 ? filterList[i - 2] : 0; + var priorFilter = i >= length ? filterList[i - length] : 0; + var prevReflex1 = i >= 1 ? reflexList[i - 1] : 0; + var prevReflex2 = i >= 2 ? reflexList[i - 2] : 0; - double filter = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filter = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); filterList.AddRounded(filter); - double slope = length != 0 ? (priorFilter - filter) / length : 0; + var slope = length != 0 ? (priorFilter - filter) / length : 0; double sum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevFilterCount = i >= j ? filterList[i - j] : 0; + var prevFilterCount = i >= j ? filterList[i - j] : 0; sum += filter + (j * slope) - prevFilterCount; } sum /= length; - double prevMs = msList.LastOrDefault(); - double ms = (0.04 * sum * sum) + (0.96 * prevMs); + var prevMs = msList.LastOrDefault(); + var ms = (0.04 * sum * sum) + (0.96 * prevMs); msList.AddRounded(ms); - double reflex = ms > 0 ? sum / Sqrt(ms) : 0; + var reflex = ms > 0 ? sum / Sqrt(ms) : 0; reflexList.AddRounded(reflex); var signal = GetCompareSignal(reflex - prevReflex1, prevReflex1 - prevReflex2); @@ -1370,46 +1370,46 @@ public static StockData CalculateEhlersSpectrumDerivedFilterBank(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double twoPiPer = MinOrMax(2 * Math.PI / length1, 0.99, 0.01); - double alpha1 = (1 - Math.Sin(twoPiPer)) / Math.Cos(twoPiPer); + var twoPiPer = MinOrMax(2 * Math.PI / length1, 0.99, 0.01); + var alpha1 = (1 - Math.Sin(twoPiPer)) / Math.Cos(twoPiPer); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double delta = Math.Max((-0.015 * i) + 0.5, 0.15); - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevHp3 = i >= 3 ? hpList[i - 3] : 0; - double prevHp4 = i >= 4 ? hpList[i - 4] : 0; - double prevHp5 = i >= 5 ? hpList[i - 5] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var delta = Math.Max((-0.015 * i) + 0.5, 0.15); + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevHp3 = i >= 3 ? hpList[i - 3] : 0; + var prevHp4 = i >= 4 ? hpList[i - 4] : 0; + var prevHp5 = i >= 5 ? hpList[i - 5] : 0; - double hp = i < 7 ? currentValue : (0.5 * (1 + alpha1) * (currentValue - prevValue)) + (alpha1 * prevHp1); + var hp = i < 7 ? currentValue : (0.5 * (1 + alpha1) * (currentValue - prevValue)) + (alpha1 * prevHp1); hpList.AddRounded(hp); - double prevSmoothHp = smoothHpList.LastOrDefault(); - double smoothHp = i < 7 ? currentValue - prevValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; + var prevSmoothHp = smoothHpList.LastOrDefault(); + var smoothHp = i < 7 ? currentValue - prevValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; smoothHpList.AddRounded(smoothHp); double num = 0, denom = 0, dc = 0, real = 0, imag = 0, q1 = 0, maxAmpl = 0; - for (int j = minLength; j <= maxLength; j++) + for (var j = minLength; j <= maxLength; j++) { - double beta = Math.Cos(MinOrMax(2 * Math.PI / j, 0.99, 0.01)); - double gamma = 1 / Math.Cos(MinOrMax(4 * Math.PI * delta / j, 0.99, 0.01)); - double alpha = gamma - Sqrt((gamma * gamma) - 1); - double priorSmoothHp = i >= j ? smoothHpList[i - j] : 0; - double prevReal = i >= j ? realList[i - j] : 0; - double priorReal = i >= j * 2 ? realList[i - (j * 2)] : 0; - double prevImag = i >= j ? imagList[i - j] : 0; - double priorImag = i >= j * 2 ? imagList[i - (j * 2)] : 0; - double prevQ1 = i >= j ? q1List[i - j] : 0; + var beta = Math.Cos(MinOrMax(2 * Math.PI / j, 0.99, 0.01)); + var gamma = 1 / Math.Cos(MinOrMax(4 * Math.PI * delta / j, 0.99, 0.01)); + var alpha = gamma - Sqrt((gamma * gamma) - 1); + var priorSmoothHp = i >= j ? smoothHpList[i - j] : 0; + var prevReal = i >= j ? realList[i - j] : 0; + var priorReal = i >= j * 2 ? realList[i - (j * 2)] : 0; + var prevImag = i >= j ? imagList[i - j] : 0; + var priorImag = i >= j * 2 ? imagList[i - (j * 2)] : 0; + var prevQ1 = i >= j ? q1List[i - j] : 0; q1 = j / Math.PI * 2 * (smoothHp - prevSmoothHp); real = (0.5 * (1 - alpha) * (smoothHp - priorSmoothHp)) + (beta * (1 + alpha) * prevReal) - (alpha * priorReal); imag = (0.5 * (1 - alpha) * (q1 - prevQ1)) + (beta * (1 + alpha) * prevImag) - (alpha * priorImag); - double ampl = (real * real) + (imag * imag); + var ampl = (real * real) + (imag * imag); maxAmpl = ampl > maxAmpl ? ampl : maxAmpl; - double db = maxAmpl != 0 && ampl / maxAmpl > 0 ? -length2 * Math.Log(0.01 / (1 - (0.99 * ampl / maxAmpl))) / Math.Log(length2) : 0; + var db = maxAmpl != 0 && ampl / maxAmpl > 0 ? -length2 * Math.Log(0.01 / (1 - (0.99 * ampl / maxAmpl))) / Math.Log(length2) : 0; db = db > maxLength ? maxLength : db; num += db <= 3 ? j * (maxLength - db) : 0; denom += db <= 3 ? maxLength - db : 0; @@ -1420,7 +1420,7 @@ public static StockData CalculateEhlersSpectrumDerivedFilterBank(this StockData imagList.AddRounded(imag); dcList.AddRounded(dc); - double domCyc = dcList.TakeLastExt(length2).Median(); + var domCyc = dcList.TakeLastExt(length2).Median(); domCycList.AddRounded(domCyc); var signal = GetCompareSignal(smoothHp, prevSmoothHp); @@ -1457,39 +1457,39 @@ public static StockData CalculateEhlersDominantCycleTunedBypassFilter(this Stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double twoPiPer = MinOrMax(2 * Math.PI / length1, 0.99, 0.01); - double alpha1 = (1 - Math.Sin(twoPiPer)) / Math.Cos(twoPiPer); + var twoPiPer = MinOrMax(2 * Math.PI / length1, 0.99, 0.01); + var alpha1 = (1 - Math.Sin(twoPiPer)) / Math.Cos(twoPiPer); var domCycList = CalculateEhlersSpectrumDerivedFilterBank(stockData, minLength, maxLength, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double domCyc = domCycList[i]; - double beta = Math.Cos(MinOrMax(2 * Math.PI / domCyc, 0.99, 0.01)); - double delta = Math.Max((-0.015 * i) + 0.5, 0.15); - double gamma = 1 / Math.Cos(MinOrMax(4 * Math.PI * (delta / domCyc), 0.99, 0.01)); - double alpha = gamma - Sqrt((gamma * gamma) - 1); - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevHp3 = i >= 3 ? hpList[i - 3] : 0; - double prevHp4 = i >= 4 ? hpList[i - 4] : 0; - double prevHp5 = i >= 5 ? hpList[i - 5] : 0; - - double hp = i < 7 ? currentValue : (0.5 * (1 + alpha1) * (currentValue - prevValue)) + (alpha1 * prevHp1); + for (var i = 0; i < stockData.Count; i++) + { + var domCyc = domCycList[i]; + var beta = Math.Cos(MinOrMax(2 * Math.PI / domCyc, 0.99, 0.01)); + var delta = Math.Max((-0.015 * i) + 0.5, 0.15); + var gamma = 1 / Math.Cos(MinOrMax(4 * Math.PI * (delta / domCyc), 0.99, 0.01)); + var alpha = gamma - Sqrt((gamma * gamma) - 1); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevHp3 = i >= 3 ? hpList[i - 3] : 0; + var prevHp4 = i >= 4 ? hpList[i - 4] : 0; + var prevHp5 = i >= 5 ? hpList[i - 5] : 0; + + var hp = i < 7 ? currentValue : (0.5 * (1 + alpha1) * (currentValue - prevValue)) + (alpha1 * prevHp1); hpList.AddRounded(hp); - double prevSmoothHp = smoothHpList.LastOrDefault(); - double smoothHp = i < 7 ? currentValue - prevValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; + var prevSmoothHp = smoothHpList.LastOrDefault(); + var smoothHp = i < 7 ? currentValue - prevValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; smoothHpList.AddRounded(smoothHp); - double prevV1 = i >= 1 ? v1List[i - 1] : 0; - double prevV1_2 = i >= 2 ? v1List[i - 2] : 0; - double v1 = (0.5 * (1 - alpha) * (smoothHp - prevSmoothHp)) + (beta * (1 + alpha) * prevV1) - (alpha * prevV1_2); + var prevV1 = i >= 1 ? v1List[i - 1] : 0; + var prevV1_2 = i >= 2 ? v1List[i - 2] : 0; + var v1 = (0.5 * (1 - alpha) * (smoothHp - prevSmoothHp)) + (beta * (1 + alpha) * prevV1) - (alpha * prevV1_2); v1List.AddRounded(v1); - double v2 = domCyc / Math.PI * 2 * (v1 - prevV1); + var v2 = domCyc / Math.PI * 2 * (v1 - prevV1); v2List.AddRounded(v2); var signal = GetConditionSignal(v2 > v1 && v2 >= 0, v2 < v1 || v2 < 0); @@ -1527,22 +1527,22 @@ public static StockData CalculateEhlersRestoringPullIndicator(this StockData sto var domCycList = CalculateEhlersSpectrumDerivedFilterBank(stockData, minLength, maxLength, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double domCyc = domCycList[i]; - double volume = volumeList[i]; + var domCyc = domCycList[i]; + var volume = volumeList[i]; - double rpi = volume * Pow(MinOrMax(2 * Math.PI / domCyc, 0.99, 0.01), 2); + var rpi = volume * Pow(MinOrMax(2 * Math.PI / domCyc, 0.99, 0.01), 2); rpiList.AddRounded(rpi); } var rpiEmaList = GetMovingAverageList(stockData, maType, minLength, rpiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rpi = rpiList[i]; - double rpiEma = rpiEmaList[i]; - double prevRpi = i >= 1 ? rpiList[i - 1] : 0; - double prevRpiEma = i >= 1 ? rpiEmaList[i - 1] : 0; + var rpi = rpiList[i]; + var rpiEma = rpiEmaList[i]; + var prevRpi = i >= 1 ? rpiList[i - 1] : 0; + var prevRpiEma = i >= 1 ? rpiEmaList[i - 1] : 0; var signal = GetCompareSignal(rpi - rpiEma, prevRpi - prevRpiEma, true); signalsList.Add(signal); @@ -1574,36 +1574,36 @@ public static StockData CalculateEhlersTrendflexIndicator(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(-1.414 * Math.PI / 0.5 * length); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / 0.5 * length); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / 0.5 * length); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / 0.5 * length); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? filterList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filterList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? filterList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filterList[i - 2] : 0; - double filter = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filter = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); filterList.AddRounded(filter); double sum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevFilterCount = i >= j ? filterList[i - j] : 0; + var prevFilterCount = i >= j ? filterList[i - j] : 0; sum += filter - prevFilterCount; } sum /= length; - double prevMs = msList.LastOrDefault(); - double ms = (0.04 * Pow(sum, 2)) + (0.96 * prevMs); + var prevMs = msList.LastOrDefault(); + var ms = (0.04 * Pow(sum, 2)) + (0.96 * prevMs); msList.AddRounded(ms); - double prevTrendflex = trendflexList.LastOrDefault(); - double trendflex = ms > 0 ? sum / Sqrt(ms) : 0; + var prevTrendflex = trendflexList.LastOrDefault(); + var trendflex = ms > 0 ? sum / Sqrt(ms) : 0; trendflexList.AddRounded(trendflex); var signal = GetCompareSignal(trendflex, prevTrendflex); @@ -1634,15 +1634,15 @@ public static StockData CalculateEhlersCorrelationCycleIndicator(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double sx = 0, sy = 0, nsy = 0, sxx = 0, syy = 0, nsyy = 0, sxy = 0, nsxy = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double x = i >= j - 1 ? inputList[i - (j - 1)] : 0; - double v = MinOrMax(2 * Math.PI * ((double)(j - 1) / length), 0.99, 0.01); - double y = Math.Cos(v); - double ny = -Math.Sin(v); + var x = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var v = MinOrMax(2 * Math.PI * ((double)(j - 1) / length), 0.99, 0.01); + var y = Math.Cos(v); + var ny = -Math.Sin(v); sx += x; sy += y; nsy += ny; @@ -1653,13 +1653,13 @@ public static StockData CalculateEhlersCorrelationCycleIndicator(this StockData nsxy += x * ny; } - double prevReal = realList.LastOrDefault(); - double real = (length * sxx) - (sx * sx) > 0 && (length * syy) - (sy * sy) > 0 ? ((length * sxy) - (sx * sy)) / + var prevReal = realList.LastOrDefault(); + var real = (length * sxx) - (sx * sx) > 0 && (length * syy) - (sy * sy) > 0 ? ((length * sxy) - (sx * sy)) / Sqrt(((length * sxx) - (sx * sx)) * ((length * syy) - (sy * sy))) : 0; realList.AddRounded(real); - double prevImag = imagList.LastOrDefault(); - double imag = (length * sxx) - (sx * sx) > 0 && (length * nsyy) - (nsy * nsy) > 0 ? ((length * nsxy) - (sx * nsy)) / + var prevImag = imagList.LastOrDefault(); + var imag = (length * sxx) - (sx * sx) > 0 && (length * nsyy) - (nsy * nsy) > 0 ? ((length * nsxy) - (sx * nsy)) / Sqrt(((length * sxx) - (sx * sx)) * ((length * nsyy) - (nsy * nsy))) : 0; imagList.AddRounded(imag); @@ -1694,13 +1694,13 @@ public static StockData CalculateEhlersCorrelationAngleIndicator(this StockData var realList = ecciList.OutputValues["Real"]; var imagList = ecciList.OutputValues["Imag"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double real = realList[i]; - double imag = imagList[i]; + var real = realList[i]; + var imag = imagList[i]; - double prevAngle = i >= 1 ? angleList[i - 1] : 0; - double angle = imag != 0 ? 90 + Math.Atan(real / imag).ToDegrees() : 90; + var prevAngle = i >= 1 ? angleList[i - 1] : 0; + var angle = imag != 0 ? 90 + Math.Atan(real / imag).ToDegrees() : 90; angle = imag > 0 ? angle - 180 : angle; angle = prevAngle - angle < 270 && angle < prevAngle ? prevAngle : angle; angleList.AddRounded(angle); @@ -1733,12 +1733,12 @@ public static StockData CalculateEhlersMarketStateIndicator(this StockData stock var angleList = CalculateEhlersCorrelationAngleIndicator(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double angle = angleList[i]; - double prevAngle = i >= 1 ? angleList[i - 1] : 0; + var angle = angleList[i]; + var prevAngle = i >= 1 ? angleList[i - 1] : 0; - double prevState = stateList.LastOrDefault(); + var prevState = stateList.LastOrDefault(); double state = Math.Abs(angle - prevAngle) < 9 && angle < 0 ? -1 : Math.Abs(angle - prevAngle) < 9 && angle >= 0 ? 1 : 0; stateList.AddRounded(state); @@ -1772,26 +1772,26 @@ public static StockData CalculateEhlersTrendExtraction(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double beta = Math.Max(Math.Cos(2 * Math.PI / length), 0.99); - double gamma = 1 / Math.Cos(4 * Math.PI * delta / length); - double alpha = Math.Max(gamma - Sqrt((gamma * gamma) - 1), 0.99); + var beta = Math.Max(Math.Cos(2 * Math.PI / length), 0.99); + var gamma = 1 / Math.Cos(4 * Math.PI * delta / length); + var alpha = Math.Max(gamma - Sqrt((gamma * gamma) - 1), 0.99); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double bp = (0.5 * (1 - alpha) * MinPastValues(i, 2, currentValue - prevValue)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); + var bp = (0.5 * (1 - alpha) * MinPastValues(i, 2, currentValue - prevValue)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); bpList.AddRounded(bp); } var trendList = GetMovingAverageList(stockData, maType, length * 2, bpList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double trend = trendList[i]; - double prevTrend = i >= 1 ? trendList[i - 1] : 0; + var trend = trendList[i]; + var prevTrend = i >= 1 ? trendList[i - 1] : 0; var signal = GetCompareSignal(trend, prevTrend); signalsList.Add(signal); @@ -1832,36 +1832,36 @@ public static StockData CalculateEhlersEmpiricalModeDecomposition(this StockData var trendList = eteList.OutputValues["Trend"]; var bpList = eteList.OutputValues["Bp"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double bp = bpList[i]; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var bp = bpList[i]; - double prevPeak = peakList.LastOrDefault(); - double peak = prevBp1 > bp && prevBp1 > prevBp2 ? prevBp1 : prevPeak; + var prevPeak = peakList.LastOrDefault(); + var peak = prevBp1 > bp && prevBp1 > prevBp2 ? prevBp1 : prevPeak; peakList.AddRounded(peak); - double prevValley = valleyList.LastOrDefault(); - double valley = prevBp1 < bp && prevBp1 < prevBp2 ? prevBp1 : prevValley; + var prevValley = valleyList.LastOrDefault(); + var valley = prevBp1 < bp && prevBp1 < prevBp2 ? prevBp1 : prevValley; valleyList.AddRounded(valley); } var peakAvgList = GetMovingAverageList(stockData, maType, length2, peakList); var valleyAvgList = GetMovingAverageList(stockData, maType, length2, valleyList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double peakAvg = peakAvgList[i]; - double valleyAvg = valleyAvgList[i]; - double trend = trendList[i]; - double prevTrend = i >= 1 ? trendList[i - 1] : 0; + var peakAvg = peakAvgList[i]; + var valleyAvg = valleyAvgList[i]; + var trend = trendList[i]; + var prevTrend = i >= 1 ? trendList[i - 1] : 0; - double prevPeakAvgFrac = peakAvgFracList.LastOrDefault(); - double peakAvgFrac = fraction * peakAvg; + var prevPeakAvgFrac = peakAvgFracList.LastOrDefault(); + var peakAvgFrac = fraction * peakAvg; peakAvgFracList.AddRounded(peakAvgFrac); - double prevValleyAvgFrac = valleyAvgFracList.LastOrDefault(); - double valleyAvgFrac = fraction * valleyAvg; + var prevValleyAvgFrac = valleyAvgFracList.LastOrDefault(); + var valleyAvgFrac = fraction * valleyAvg; valleyAvgFracList.AddRounded(valleyAvgFrac); var signal = GetBullishBearishSignal(trend - Math.Max(peakAvgFrac, valleyAvgFrac), prevTrend - Math.Max(prevPeakAvgFrac, prevValleyAvgFrac), @@ -1900,17 +1900,17 @@ public static StockData CalculateEhlersEarlyOnsetTrendIndicator(this StockData s stockData.CustomValuesList = hpList; var superSmoothList = CalculateEhlersSuperSmootherFilter(stockData, length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filter = superSmoothList[i]; + var filter = superSmoothList[i]; - double prevPeak = peakList.LastOrDefault(); - double peak = Math.Abs(filter) > 0.991 * prevPeak ? Math.Abs(filter) : 0.991 * prevPeak; + var prevPeak = peakList.LastOrDefault(); + var peak = Math.Abs(filter) > 0.991 * prevPeak ? Math.Abs(filter) : 0.991 * prevPeak; peakList.AddRounded(peak); - double ratio = peak != 0 ? filter / peak : 0; - double prevQuotient = quotientList.LastOrDefault(); - double quotient = (k * ratio) + 1 != 0 ? (ratio + k) / ((k * ratio) + 1) : 0; + var ratio = peak != 0 ? filter / peak : 0; + var prevQuotient = quotientList.LastOrDefault(); + var quotient = (k * ratio) + 1 != 0 ? (ratio + k) / ((k * ratio) + 1) : 0; quotientList.AddRounded(quotient); var signal = GetCompareSignal(quotient, prevQuotient); @@ -1944,20 +1944,20 @@ public static StockData CalculateEhlersRoofingFilterV1(this StockData stockData, var hpFilterList = CalculateEhlersHighPassFilterV1(stockData, length1, 1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highPass = hpFilterList[i]; - double prevHp1 = i >= 1 ? hpFilterList[i - 1] : 0; + var highPass = hpFilterList[i]; + var prevHp1 = i >= 1 ? hpFilterList[i - 1] : 0; - double arg = (highPass + prevHp1) / 2; + var arg = (highPass + prevHp1) / 2; argList.AddRounded(arg); } var roofingFilter2PoleList = GetMovingAverageList(stockData, maType, length2, argList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roofingFilter = roofingFilter2PoleList[i]; - double prevRoofingFilter = i >= 1 ? roofingFilter2PoleList[i - 1] : 0; + var roofingFilter = roofingFilter2PoleList[i]; + var prevRoofingFilter = i >= 1 ? roofingFilter2PoleList[i - 1] : 0; var signal = GetCompareSignal(roofingFilter, prevRoofingFilter); signalsList.Add(signal); @@ -1993,36 +1993,36 @@ public static StockData CalculateEhlersSnakeUniversalTradingFilter(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double l1 = Math.Cos(MinOrMax(2 * Math.PI / 2 * length1, 0.99, 0.01)); - double g1 = Math.Cos(MinOrMax(bw * 2 * Math.PI / 2 * length1, 0.99, 0.01)); - double s1 = (1 / g1) - Sqrt(1 / Pow(g1, 2) - 1); + var l1 = Math.Cos(MinOrMax(2 * Math.PI / 2 * length1, 0.99, 0.01)); + var g1 = Math.Cos(MinOrMax(bw * 2 * Math.PI / 2 * length1, 0.99, 0.01)); + var s1 = (1 / g1) - Sqrt(1 / Pow(g1, 2) - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double bp = i < 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); + var bp = i < 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); bpList.AddRounded(bp); } var filtList = GetMovingAverageList(stockData, maType, length1, bpList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var filt = filtList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double filtPow = Pow(filt, 2); + var filtPow = Pow(filt, 2); filtPowList.AddRounded(filtPow); - double filtPowMa = filtPowList.TakeLastExt(length2).Average(); - double rms = Sqrt(filtPowMa); + var filtPowMa = filtPowList.TakeLastExt(length2).Average(); + var rms = Sqrt(filtPowMa); rmsList.AddRounded(rms); - double negRms = -rms; + var negRms = -rms; negRmsList.AddRounded(negRms); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); @@ -2057,28 +2057,28 @@ public static StockData CalculateEhlersImpulseResponse(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int hannLength = MinOrMax((int)Math.Ceiling(length / 1.4)); - double l1 = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); - double g1 = Math.Cos(MinOrMax(bw * 2 * Math.PI / length, 0.99, 0.01)); - double s1 = (1 / g1) - Sqrt(1 / Pow(g1, 2) - 1); + var hannLength = MinOrMax((int)Math.Ceiling(length / 1.4)); + var l1 = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); + var g1 = Math.Cos(MinOrMax(bw * 2 * Math.PI / length, 0.99, 0.01)); + var s1 = (1 / g1) - Sqrt(1 / Pow(g1, 2) - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double bp = i < 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); + var bp = i < 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); bpList.AddRounded(bp); } var filtList = GetMovingAverageList(stockData, maType, hannLength, bpList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var filt = filtList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -2115,28 +2115,28 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(MinOrMax(-1.414 * Math.PI / upperLength, -0.01, -0.99)); - double b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / upperLength, 0.99, 0.01)); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = (1 + c2 - c3) / 4; - double a = Exp(MinOrMax(-1.414 * Math.PI / lowerLength, -0.01, -0.99)); - double b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / lowerLength, 0.99, 0.01)); - double coef2 = b; - double coef3 = -a * a; - double coef1 = 1 - coef2 - coef3; - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; - double prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; - double prevPredict1 = i >= 1 ? predictList[i - 1] : 0; - double priorSsf = i >= upperLength - 1 ? ssfList[i - (upperLength - 1)] : 0; + var a1 = Exp(MinOrMax(-1.414 * Math.PI / upperLength, -0.01, -0.99)); + var b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / upperLength, 0.99, 0.01)); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = (1 + c2 - c3) / 4; + var a = Exp(MinOrMax(-1.414 * Math.PI / lowerLength, -0.01, -0.99)); + var b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / lowerLength, 0.99, 0.01)); + var coef2 = b; + var coef3 = -a * a; + var coef1 = 1 - coef2 - coef3; + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; + var prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; + var prevPredict1 = i >= 1 ? predictList[i - 1] : 0; + var priorSsf = i >= upperLength - 1 ? ssfList[i - (upperLength - 1)] : 0; var pArray = new double[500]; var bb1Array = new double[500]; var bb2Array = new double[500]; @@ -2145,55 +2145,55 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto var xxArray = new double[520]; var hCoefArray = new double[520]; - double hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); + var hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); hpList.AddRounded(hp); - double ssf = i < 3 ? hp : (coef1 * ((hp + prevHp1) / 2)) + (coef2 * prevSsf1) + (coef3 * prevSsf2); + var ssf = i < 3 ? hp : (coef1 * ((hp + prevHp1) / 2)) + (coef2 * prevSsf1) + (coef3 * prevSsf2); ssfList.AddRounded(ssf); double pwrSum = 0; - for (int j = 0; j < upperLength; j++) + for (var j = 0; j < upperLength; j++) { - double prevSsf = i >= j ? ssfList[i - j] : 0; + var prevSsf = i >= j ? ssfList[i - j] : 0; pwrSum += Pow(prevSsf, 2); } - double pwr = pwrSum / upperLength; + var pwr = pwrSum / upperLength; bb1Array[1] = ssf; bb2Array[upperLength - 1] = priorSsf; - for (int j = 2; j < upperLength; j++) + for (var j = 2; j < upperLength; j++) { - double prevSsf = i >= j - 1 ? ssfList[i - (j - 1)] : 0; + var prevSsf = i >= j - 1 ? ssfList[i - (j - 1)] : 0; bb1Array[j] = prevSsf; bb2Array[j - 1] = prevSsf; } double num = 0, denom = 0; - for (int j = 1; j < upperLength; j++) + for (var j = 1; j < upperLength; j++) { num += bb1Array[j] * bb2Array[j]; denom += Pow(bb1Array[j], 2) + Pow(bb2Array[j], 2); } - double coef = denom != 0 ? 2 * num / denom : 0; - double p = pwr * (1 - Pow(coef, 2)); + var coef = denom != 0 ? 2 * num / denom : 0; + var p = pwr * (1 - Pow(coef, 2)); coefArray[1] = coef; pArray[1] = p; - for (int j = 2; j <= length2; j++) + for (var j = 2; j <= length2; j++) { - for (int k = 1; k < j; k++) + for (var k = 1; k < j; k++) { coefAArray[k] = coefArray[k]; } - for (int k = 1; k < upperLength; k++) + for (var k = 1; k < upperLength; k++) { bb1Array[k] = bb1Array[k] - (coefAArray[j - 1] * bb2Array[k]); bb2Array[k] = bb2Array[k + 1] - (coefAArray[j - 1] * bb1Array[k + 1]); } double num1 = 0, denom1 = 0; - for (int k = 1; k <= upperLength - j; k++) + for (var k = 1; k <= upperLength - j; k++) { num1 += bb1Array[k] * bb2Array[k]; denom1 += Pow(bb1Array[k], 2) + Pow(bb2Array[k], 2); @@ -2201,27 +2201,27 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto coefArray[j] = denom1 != 0 ? 2 * num1 / denom1 : 0; pArray[j] = pArray[j - 1] * (1 - Pow(coefArray[j], 2)); - for (int k = 1; k < j; k++) + for (var k = 1; k < j; k++) { coefArray[k] = coefAArray[k] - (coefArray[j] * coefAArray[j - k]); } } var coef1Array = new double[500]; - for (int j = 1; j <= length2; j++) + for (var j = 1; j <= length2; j++) { coef1Array[1] = coefArray[j]; - for (int k = lowerLength; k >= 2; k--) + for (var k = lowerLength; k >= 2; k--) { coef1Array[k] = coef1Array[k - 1]; } } - for (int j = 1; j <= length2; j++) + for (var j = 1; j <= length2; j++) { hCoefArray[j] = 0; double cc = 0; - for (int k = 1; k <= lowerLength; k++) + for (var k = 1; k <= lowerLength; k++) { hCoefArray[j] = hCoefArray[j] + ((1 - Math.Cos(MinOrMax(2 * Math.PI * ((double)k / (lowerLength + 1)), 0.99, 0.01))) * coef1Array[k]); cc += 1 - Math.Cos(MinOrMax(2 * Math.PI * ((double)k / (lowerLength + 1)), 0.99, 0.01)); @@ -2229,25 +2229,25 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto hCoefArray[j] = cc != 0 ? hCoefArray[j] / cc : 0; } - for (int j = 1; j <= upperLength; j++) + for (var j = 1; j <= upperLength; j++) { xxArray[j] = i >= upperLength - j ? ssfList[i - (upperLength - j)] : 0; } - for (int j = 1; j <= length3; j++) + for (var j = 1; j <= length3; j++) { xxArray[upperLength + j] = 0; - for (int k = 1; k <= length2; k++) + for (var k = 1; k <= length2; k++) { xxArray[upperLength + j] = xxArray[upperLength + j] + (hCoefArray[k] * xxArray[upperLength + j - k]); } } - double prevPrePredict = prePredictList.LastOrDefault(); - double prePredict = xxArray[upperLength + length1]; + var prevPrePredict = prePredictList.LastOrDefault(); + var prePredict = xxArray[upperLength + length1]; prePredictList.AddRounded(prePredict); - double predict = (prePredict + prevPrePredict) / 2; + var predict = (prePredict + prevPrePredict) / 2; predictList.AddRounded(predict); var signal = GetCompareSignal(ssf - predict, prevSsf1 - prevPredict1); @@ -2294,67 +2294,67 @@ public static StockData CalculateEhlersMesaPredictIndicatorV2(this StockData sto coefArray[3] = -4.045; coefArray[4] = 0.825; - double a1 = Exp(MinOrMax(-1.414 * Math.PI / length2, -0.01, -0.99)); - double b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length2, 0.99, 0.01)); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = (1 + c2 - c3) / 4; - double a = Exp(MinOrMax(-1.414 * Math.PI / length3, -0.01, -0.99)); - double b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / length3, 0.99, 0.01)); - double coef2 = b; - double coef3 = -a * a; - double coef1 = 1 - coef2 - coef3; - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; - double prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; - - double hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); + var a1 = Exp(MinOrMax(-1.414 * Math.PI / length2, -0.01, -0.99)); + var b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length2, 0.99, 0.01)); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = (1 + c2 - c3) / 4; + var a = Exp(MinOrMax(-1.414 * Math.PI / length3, -0.01, -0.99)); + var b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / length3, 0.99, 0.01)); + var coef2 = b; + var coef3 = -a * a; + var coef1 = 1 - coef2 - coef3; + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; + var prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; + + var hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); hpList.AddRounded(hp); - double ssf = i < 3 ? hp : (coef1 * ((hp + prevHp1) / 2)) + (coef2 * prevSsf1) + (coef3 * prevSsf2); + var ssf = i < 3 ? hp : (coef1 * ((hp + prevHp1) / 2)) + (coef2 * prevSsf1) + (coef3 * prevSsf2); ssfList.AddRounded(ssf); } var filtList = GetMovingAverageList(stockData, maType, length3, ssfList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevPredict1 = i >= 1 ? predictList[i - 1] : 0; - double prevPredict2 = i >= 2 ? predictList[i - 2] : 0; + var prevPredict1 = i >= 1 ? predictList[i - 1] : 0; + var prevPredict2 = i >= 2 ? predictList[i - 2] : 0; var xxArray = new double[100]; var yyArray = new double[100]; - for (int j = 1; j <= length1; j++) + for (var j = 1; j <= length1; j++) { - double prevFilt = i >= length1 - j ? filtList[i - (length1 - j)] : 0; + var prevFilt = i >= length1 - j ? filtList[i - (length1 - j)] : 0; xxArray[j] = prevFilt; yyArray[j] = prevFilt; } - for (int j = 1; j <= length1; j++) + for (var j = 1; j <= length1; j++) { xxArray[length1 + j] = 0; - for (int k = 1; k <= 5; k++) + for (var k = 1; k <= 5; k++) { xxArray[length1 + j] = xxArray[length1 + j] + (coefArray[k - 1] * xxArray[length1 + j - (k - 1)]); } } - for (int j = 0; j <= length1; j++) + for (var j = 0; j <= length1; j++) { yyArray[length1 + j + 1] = (2 * yyArray[length1 + j]) - yyArray[length1 + j - 1]; } - double predict = xxArray[length1 + length4]; + var predict = xxArray[length1 + length4]; predictList.AddRounded(predict); - double extrap = yyArray[length1 + length4]; + var extrap = yyArray[length1 + length4]; extrapList.AddRounded(extrap); var signal = GetCompareSignal(predict - prevPredict1, prevPredict1 - prevPredict2); @@ -2390,30 +2390,30 @@ public static StockData CalculateEhlersAnticipateIndicator(this StockData stockD var hFiltList = CalculateEhlersImpulseResponse(stockData, maType, length, bw).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double maxCorr = -1, start = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { double sx = 0, sy = 0, sxx = 0, syy = 0, sxy = 0; - for (int k = 0; k < length; k++) + for (var k = 0; k < length; k++) { - double x = i >= k ? hFiltList[i - k] : 0; - double y = -Math.Sin(MinOrMax(2 * Math.PI * ((double)(j + k) / length), 0.99, 0.01)); + var x = i >= k ? hFiltList[i - k] : 0; + var y = -Math.Sin(MinOrMax(2 * Math.PI * ((double)(j + k) / length), 0.99, 0.01)); sx += x; sy += y; sxx += Pow(x, 2); sxy += x * y; syy += Pow(y, 2); } - double corr = ((length * sxx) - Pow(sx, 2)) * ((length * syy) - Pow(sy, 2)) > 0 ? ((length * sxy) - (sx * sy)) / + var corr = ((length * sxx) - Pow(sx, 2)) * ((length * syy) - Pow(sy, 2)) > 0 ? ((length * sxy) - (sx * sy)) / Sqrt(((length * sxx) - Pow(sx, 2)) * ((length * syy) - Pow(sy, 2))) : 0; start = corr > maxCorr ? length - j : 0; maxCorr = corr > maxCorr ? corr : maxCorr; } - double prevPredict = predictList.LastOrDefault(); - double predict = Math.Sin(MinOrMax(2 * Math.PI * start / length, 0.99, 0.01)); + var prevPredict = predictList.LastOrDefault(); + var predict = Math.Sin(MinOrMax(2 * Math.PI * start / length, 0.99, 0.01)); predictList.AddRounded(predict); var signal = GetCompareSignal(predict, prevPredict); @@ -2446,23 +2446,23 @@ public static StockData CalculateEhlersImpulseReaction(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double c2 = 2 * qq * Math.Cos(2 * Math.PI / length2); - double c3 = -qq * qq; - double c1 = (1 + c3) / 2; + var c2 = 2 * qq * Math.Cos(2 * Math.PI / length2); + var c3 = -qq * qq; + var c1 = (1 + c3) / 2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double priorValue = i >= length1 ? inputList[i - length1] : 0; - double prevReaction1 = i >= 1 ? reactionList[i - 1] : 0; - double prevReaction2 = i >= 2 ? reactionList[i - 2] : 0; - double prevIReact1 = i >= 1 ? ireactList[i - 1] : 0; - double prevIReact2 = i >= 2 ? ireactList[i - 2] : 0; + var currentValue = inputList[i]; + var priorValue = i >= length1 ? inputList[i - length1] : 0; + var prevReaction1 = i >= 1 ? reactionList[i - 1] : 0; + var prevReaction2 = i >= 2 ? reactionList[i - 2] : 0; + var prevIReact1 = i >= 1 ? ireactList[i - 1] : 0; + var prevIReact2 = i >= 2 ? ireactList[i - 2] : 0; - double reaction = (c1 * (currentValue - priorValue)) + (c2 * prevReaction1) + (c3 * prevReaction2); + var reaction = (c1 * (currentValue - priorValue)) + (c2 * prevReaction1) + (c3 * prevReaction2); reactionList.AddRounded(reaction); - double ireact = currentValue != 0 ? 100 * reaction / currentValue : 0; + var ireact = currentValue != 0 ? 100 * reaction / currentValue : 0; ireactList.AddRounded(ireact); var signal = GetCompareSignal(ireact - prevIReact1, prevIReact1 - prevIReact2); @@ -2499,32 +2499,32 @@ public static StockData CalculateEhlersUniversalTradingFilter(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int hannLength = (int)Math.Ceiling(mult * length1); + var hannLength = (int)Math.Ceiling(mult * length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double priorValue = i >= hannLength ? inputList[i - hannLength] : 0; + var currentValue = inputList[i]; + var priorValue = i >= hannLength ? inputList[i - hannLength] : 0; - double mom = currentValue - priorValue; + var mom = currentValue - priorValue; momList.AddRounded(mom); } var filtList = GetMovingAverageList(stockData, maType, length1, momList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var filt = filtList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double filtPow = Pow(filt, 2); + var filtPow = Pow(filt, 2); filtPowList.AddRounded(filtPow); - double filtPowMa = filtPowList.TakeLastExt(length2).Average(); - double rms = filtPowMa > 0 ? Sqrt(filtPowMa) : 0; + var filtPowMa = filtPowList.TakeLastExt(length2).Average(); + var rms = filtPowMa > 0 ? Sqrt(filtPowMa) : 0; rmsList.AddRounded(rms); - double negRms = -rms; + var negRms = -rms; negRmsList.AddRounded(negRms); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); @@ -2560,28 +2560,28 @@ public static StockData CalculateEhlersRecursiveMedianOscillator(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha1Arg = MinOrMax(2 * Math.PI / length2, 0.99, 0.01); - double alpha1ArgCos = Math.Cos(alpha1Arg); - double alpha2Arg = MinOrMax(1 / Sqrt(2) * 2 * Math.PI / length3, 0.99, 0.01); - double alpha2ArgCos = Math.Cos(alpha2Arg); - double alpha1 = alpha1ArgCos != 0 ? (alpha1ArgCos + Math.Sin(alpha1Arg) - 1) / alpha1ArgCos : 0; - double alpha2 = alpha2ArgCos != 0 ? (alpha2ArgCos + Math.Sin(alpha2Arg) - 1) / alpha2ArgCos : 0; + var alpha1Arg = MinOrMax(2 * Math.PI / length2, 0.99, 0.01); + var alpha1ArgCos = Math.Cos(alpha1Arg); + var alpha2Arg = MinOrMax(1 / Sqrt(2) * 2 * Math.PI / length3, 0.99, 0.01); + var alpha2ArgCos = Math.Cos(alpha2Arg); + var alpha1 = alpha1ArgCos != 0 ? (alpha1ArgCos + Math.Sin(alpha1Arg) - 1) / alpha1ArgCos : 0; + var alpha2 = alpha2ArgCos != 0 ? (alpha2ArgCos + Math.Sin(alpha2Arg) - 1) / alpha2ArgCos : 0; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double median = tempList.TakeLastExt(length1).Median(); - double prevRm1 = i >= 1 ? rmList[i - 1] : 0; - double prevRm2 = i >= 2 ? rmList[i - 2] : 0; - double prevRmo1 = i >= 1 ? rmoList[i - 1] : 0; - double prevRmo2 = i >= 2 ? rmoList[i - 2] : 0; + var median = tempList.TakeLastExt(length1).Median(); + var prevRm1 = i >= 1 ? rmList[i - 1] : 0; + var prevRm2 = i >= 2 ? rmList[i - 2] : 0; + var prevRmo1 = i >= 1 ? rmoList[i - 1] : 0; + var prevRmo2 = i >= 2 ? rmoList[i - 2] : 0; - double rm = (alpha1 * median) + ((1 - alpha1) * prevRm1); + var rm = (alpha1 * median) + ((1 - alpha1) * prevRm1); rmList.AddRounded(rm); - double rmo = (Pow(1 - (alpha2 / 2), 2) * (rm - (2 * prevRm1) + prevRm2)) + (2 * (1 - alpha2) * prevRmo1) - (Pow(1 - alpha2, 2) * prevRmo2); + var rmo = (Pow(1 - (alpha2 / 2), 2) * (rm - (2 * prevRm1) + prevRm2)) + (2 * (1 - alpha2) * prevRmo1) - (Pow(1 - alpha2, 2) * prevRmo2); rmoList.AddRounded(rmo); var signal = GetCompareSignal(rmo, prevRmo1); @@ -2617,30 +2617,30 @@ public static StockData CalculateEhlersSuperPassbandFilter(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = MinOrMax((double)length1 / fastLength, 0.99, 0.01); - double a2 = MinOrMax((double)length1 / slowLength, 0.99, 0.01); + var a1 = MinOrMax((double)length1 / fastLength, 0.99, 0.01); + var a2 = MinOrMax((double)length1 / slowLength, 0.99, 0.01); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevEspf1 = i >= 1 ? espfList[i - 1] : 0; - double prevEspf2 = i >= 2 ? espfList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevEspf1 = i >= 1 ? espfList[i - 1] : 0; + var prevEspf2 = i >= 2 ? espfList[i - 2] : 0; - double espf = ((a1 - a2) * currentValue) + (((a2 * (1 - a1)) - (a1 * (1 - a2))) * prevValue1) + ((1 - a1 + (1 - a2)) * prevEspf1) - - ((1 - a1) * (1 - a2) * prevEspf2); + var espf = ((a1 - a2) * currentValue) + (((a2 * (1 - a1)) - (a1 * (1 - a2))) * prevValue1) + ((1 - a1 + (1 - a2)) * prevEspf1) - + ((1 - a1) * (1 - a2) * prevEspf2); espfList.AddRounded(espf); - double espfPow = Pow(espf, 2); + var espfPow = Pow(espf, 2); squareList.AddRounded(espfPow); - double squareAvg = squareList.TakeLastExt(length2).Average(); - double prevRms = rmsList.LastOrDefault(); - double rms = Sqrt(squareAvg); + var squareAvg = squareList.TakeLastExt(length2).Average(); + var prevRms = rmsList.LastOrDefault(); + var rms = Sqrt(squareAvg); rmsList.AddRounded(rms); - double prevNegRms = negRmsList.LastOrDefault(); - double negRms = -rms; + var prevNegRms = negRmsList.LastOrDefault(); + var negRms = -rms; negRmsList.AddRounded(negRms); var signal = GetBullishBearishSignal(espf - rms, prevEspf1 - prevRms, espf - negRms, prevEspf1 - prevNegRms); @@ -2676,26 +2676,26 @@ public static StockData CalculateEhlersSimpleDerivIndicator(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double prevDeriv1 = i >= 1 ? derivList[i - 1] : 0; - double prevDeriv2 = i >= 2 ? derivList[i - 2] : 0; - double prevDeriv3 = i >= 3 ? derivList[i - 3] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var prevDeriv1 = i >= 1 ? derivList[i - 1] : 0; + var prevDeriv2 = i >= 2 ? derivList[i - 2] : 0; + var prevDeriv3 = i >= 3 ? derivList[i - 3] : 0; - double deriv = MinPastValues(i, length, currentValue - prevValue); + var deriv = MinPastValues(i, length, currentValue - prevValue); derivList.AddRounded(deriv); - double z3 = deriv + prevDeriv1 + prevDeriv2 + prevDeriv3; + var z3 = deriv + prevDeriv1 + prevDeriv2 + prevDeriv3; z3List.AddRounded(z3); } var z3EmaList = GetMovingAverageList(stockData, maType, signalLength, z3List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double z3Ema = z3EmaList[i]; - double prevZ3Ema = i >= 1 ? z3EmaList[i - 1] : 0; + var z3Ema = z3EmaList[i]; + var prevZ3Ema = i >= 1 ? z3EmaList[i - 1] : 0; var signal = GetCompareSignal(z3Ema, prevZ3Ema); signalsList.Add(signal); @@ -2732,36 +2732,36 @@ public static StockData CalculateEhlersSimpleClipIndicator(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length1 ? inputList[i - length1] : 0; - double prevClip1 = i >= 1 ? clipList[i - 1] : 0; - double prevClip2 = i >= 2 ? clipList[i - 2] : 0; - double prevClip3 = i >= 3 ? clipList[i - 3] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length1 ? inputList[i - length1] : 0; + var prevClip1 = i >= 1 ? clipList[i - 1] : 0; + var prevClip2 = i >= 2 ? clipList[i - 2] : 0; + var prevClip3 = i >= 3 ? clipList[i - 3] : 0; - double deriv = MinPastValues(i, length1, currentValue - prevValue); + var deriv = MinPastValues(i, length1, currentValue - prevValue); derivList.AddRounded(deriv); double rms = 0; - for (int j = 0; j < length3; j++) + for (var j = 0; j < length3; j++) { - double prevDeriv = i >= j ? derivList[i - j] : 0; + var prevDeriv = i >= j ? derivList[i - j] : 0; rms += Pow(prevDeriv, 2); } - double clip = rms != 0 ? MinOrMax(2 * deriv / Sqrt(rms / length3), 1, -1) : 0; + var clip = rms != 0 ? MinOrMax(2 * deriv / Sqrt(rms / length3), 1, -1) : 0; clipList.AddRounded(clip); - double z3 = clip + prevClip1 + prevClip2 + prevClip3; + var z3 = clip + prevClip1 + prevClip2 + prevClip3; z3List.AddRounded(z3); } var z3EmaList = GetMovingAverageList(stockData, maType, signalLength, z3List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double z3Ema = z3EmaList[i]; - double prevZ3Ema = i >= 1 ? z3EmaList[i - 1] : 0; + var z3Ema = z3EmaList[i]; + var prevZ3Ema = i >= 1 ? z3EmaList[i - 1] : 0; var signal = GetCompareSignal(z3Ema, prevZ3Ema); signalsList.Add(signal); @@ -2791,22 +2791,22 @@ public static StockData CalculateEhlersSpearmanRankIndicator(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var priceArray = new double[50]; var rankArray = new double[50]; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { var prevPrice = i >= j - 1 ? inputList[i - (j - 1)] : 0; priceArray[j] = prevPrice; rankArray[j] = j; } - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { var count = length + 1 - j; - for (int k = 1; k <= length - count; k++) + for (var k = 1; k <= length - count; k++) { var array1 = priceArray[k + 1]; @@ -2824,13 +2824,13 @@ public static StockData CalculateEhlersSpearmanRankIndicator(this StockData stoc } double sum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { sum += Pow(j - rankArray[j], 2); } - double prevSri = sriList.LastOrDefault(); - double sri = 2 * (0.5 - (1 - (6 * sum / (length * (Pow(length, 2) - 1))))); + var prevSri = sriList.LastOrDefault(); + var sri = 2 * (0.5 - (1 - (6 * sum / (length * (Pow(length, 2) - 1))))); sriList.AddRounded(sri); var signal = GetCompareSignal(sri, prevSri); @@ -2860,28 +2860,28 @@ public static StockData CalculateEhlersNoiseEliminationTechnology(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double denom = 0.5 * length * (length - 1); + var denom = 0.5 * length * (length - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var xArray = new double[50]; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { var prevPrice = i >= j - 1 ? inputList[i - (j - 1)] : 0; xArray[j] = prevPrice; } double num = 0; - for (int j = 2; j <= length; j++) + for (var j = 2; j <= length; j++) { - for (int k = 1; k <= j - 1; k++) + for (var k = 1; k <= j - 1; k++) { num -= Math.Sign(xArray[j] - xArray[k]); } } - double prevNet = netList.LastOrDefault(); - double net = denom != 0 ? num / denom : 0; + var prevNet = netList.LastOrDefault(); + var net = denom != 0 ? num / denom : 0; netList.AddRounded(net); var signal = GetCompareSignal(net, prevNet); @@ -2913,22 +2913,22 @@ public static StockData CalculateEhlersTruncatedBandPassFilter(this StockData st List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double l1 = Math.Cos(MinOrMax(2 * Math.PI / length1, 0.99, 0.01)); - double g1 = Math.Cos(bw * 2 * Math.PI / length1); - double s1 = (1 / g1) - Sqrt((1 / Pow(g1, 2)) - 1); + var l1 = Math.Cos(MinOrMax(2 * Math.PI / length1, 0.99, 0.01)); + var g1 = Math.Cos(bw * 2 * Math.PI / length1); + var s1 = (1 / g1) - Sqrt((1 / Pow(g1, 2)) - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var trunArray = new double[100]; - for (int j = length2; j > 0; j--) + for (var j = length2; j > 0; j--) { - double prevValue1 = i >= j - 1 ? inputList[i - (j - 1)] : 0; - double prevValue2 = i >= j + 1 ? inputList[i - (j + 1)] : 0; + var prevValue1 = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var prevValue2 = i >= j + 1 ? inputList[i - (j + 1)] : 0; trunArray[j] = (0.5 * (1 - s1) * (prevValue1 - prevValue2)) + (l1 * (1 + s1) * trunArray[j + 1]) - (s1 * trunArray[j + 2]); } - double prevBpt = bptList.LastOrDefault(); - double bpt = trunArray[1]; + var prevBpt = bptList.LastOrDefault(); + var bpt = trunArray[1]; bptList.AddRounded(bpt); var signal = GetCompareSignal(bpt, prevBpt); @@ -2965,33 +2965,33 @@ public static StockData CalculateEhlersAutoCorrelationIndicator(this StockData s var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevCorr1 = i >= 1 ? corrList[i - 1] : 0; - double prevCorr2 = i >= 2 ? corrList[i - 2] : 0; + var prevCorr1 = i >= 1 ? corrList[i - 1] : 0; + var prevCorr2 = i >= 2 ? corrList[i - 2] : 0; - double x = roofingFilterList[i]; + var x = roofingFilterList[i]; xList.AddRounded(x); - double y = i >= length1 ? roofingFilterList[i - length1] : 0; + var y = i >= length1 ? roofingFilterList[i - length1] : 0; yList.AddRounded(y); - double xx = Pow(x, 2); + var xx = Pow(x, 2); xxList.AddRounded(xx); - double yy = Pow(y, 2); + var yy = Pow(y, 2); yyList.AddRounded(yy); - double xy = x * y; + var xy = x * y; xyList.AddRounded(xy); - double sx = xList.TakeLastExt(length1).Sum(); - double sy = yList.TakeLastExt(length1).Sum(); - double sxx = xxList.TakeLastExt(length1).Sum(); - double syy = yyList.TakeLastExt(length1).Sum(); - double sxy = xyList.TakeLastExt(length1).Sum(); + var sx = xList.TakeLastExt(length1).Sum(); + var sy = yList.TakeLastExt(length1).Sum(); + var sxx = xxList.TakeLastExt(length1).Sum(); + var syy = yyList.TakeLastExt(length1).Sum(); + var sxy = xyList.TakeLastExt(length1).Sum(); - double corr = ((i * sxx) - (sx * sx)) * ((i * syy) - (sy * sy)) > 0 ? 0.5 * ((((i * sxy) - (sx * sy)) / + var corr = ((i * sxx) - (sx * sx)) * ((i * syy) - (sy * sy)) > 0 ? 0.5 * ((((i * sxy) - (sx * sy)) / Sqrt(((i * sxx) - (sx * sx)) * ((i * syy) - (sy * sy)))) + 1) : 0; corrList.AddRounded(corr); @@ -3026,28 +3026,28 @@ public static StockData CalculateEhlersAutoCorrelationPeriodogram(this StockData var corrList = CalculateEhlersAutoCorrelationIndicator(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double corr = corrList[i]; - double prevCorr1 = i >= 1 ? corrList[i - 1] : 0; - double prevCorr2 = i >= 2 ? corrList[i - 2] : 0; + var corr = corrList[i]; + var prevCorr1 = i >= 1 ? corrList[i - 1] : 0; + var prevCorr2 = i >= 2 ? corrList[i - 2] : 0; double maxPwr = 0, spx = 0, sp = 0; - for (int j = length2; j <= length1; j++) + for (var j = length2; j <= length1; j++) { double cosPart = 0, sinPart = 0; - for (int k = length3; k <= length1; k++) + for (var k = length3; k <= length1; k++) { - double prevCorr = i >= k ? corrList[i - k] : 0; + var prevCorr = i >= k ? corrList[i - k] : 0; cosPart += prevCorr * Math.Cos(2 * Math.PI * ((double)k / j)); sinPart += prevCorr * Math.Sin(2 * Math.PI * ((double)k / j)); } - double sqSum = Pow(cosPart, 2) + Pow(sinPart, 2); - double prevR = i >= j - 1 ? rList[i - (j - 1)] : 0; - double r = (0.2 * Pow(sqSum, 2)) + (0.8 * prevR); + var sqSum = Pow(cosPart, 2) + Pow(sinPart, 2); + var prevR = i >= j - 1 ? rList[i - (j - 1)] : 0; + var r = (0.2 * Pow(sqSum, 2)) + (0.8 * prevR); maxPwr = Math.Max(r, maxPwr); - double pwr = maxPwr != 0 ? r / maxPwr : 0; + var pwr = maxPwr != 0 ? r / maxPwr : 0; if (pwr >= 0.5) { @@ -3056,7 +3056,7 @@ public static StockData CalculateEhlersAutoCorrelationPeriodogram(this StockData } } - double domCyc = sp != 0 ? spx / sp : 0; + var domCyc = sp != 0 ? spx / sp : 0; domCycList.AddRounded(domCyc); var signal = GetCompareSignal(corr - prevCorr1, prevCorr1 - prevCorr2); @@ -3091,47 +3091,47 @@ public static StockData CalculateEhlersAdaptiveRelativeStrengthIndexV2(this Stoc List arsiList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var domCycList = CalculateEhlersAutoCorrelationPeriodogram(stockData, length1, length2, length3).CustomValuesList; var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double domCyc = MinOrMax(domCycList[i], length1, length2); - double prevArsi1 = i >= 1 ? arsiList[i - 1] : 0; - double prevArsi2 = i >= 2 ? arsiList[i - 2] : 0; + var domCyc = MinOrMax(domCycList[i], length1, length2); + var prevArsi1 = i >= 1 ? arsiList[i - 1] : 0; + var prevArsi2 = i >= 2 ? arsiList[i - 2] : 0; - double prevUpChg = upChgList.LastOrDefault(); + var prevUpChg = upChgList.LastOrDefault(); double upChg = 0, dnChg = 0; - for (int j = 0; j < (int)Math.Ceiling(domCyc / 2); j++) + for (var j = 0; j < (int)Math.Ceiling(domCyc / 2); j++) { - double filt = i >= j ? roofingFilterList[i - j] : 0; - double prevFilt = i >= j + 1 ? roofingFilterList[i - (j + 1)] : 0; + var filt = i >= j ? roofingFilterList[i - j] : 0; + var prevFilt = i >= j + 1 ? roofingFilterList[i - (j + 1)] : 0; upChg += filt > prevFilt ? filt - prevFilt : 0; dnChg += filt < prevFilt ? prevFilt - filt : 0; } upChgList.AddRounded(upChg); - double prevDenom = denomList.LastOrDefault(); - double denom = upChg + dnChg; + var prevDenom = denomList.LastOrDefault(); + var denom = upChg + dnChg; denomList.AddRounded(denom); - double arsi = denom != 0 && prevDenom != 0 ? (c1 * ((upChg / denom) + (prevUpChg / prevDenom)) / 2) + (c2 * prevArsi1) + (c3 * prevArsi2) : 0; + var arsi = denom != 0 && prevDenom != 0 ? (c1 * ((upChg / denom) + (prevUpChg / prevDenom)) / 2) + (c2 * prevArsi1) + (c3 * prevArsi2) : 0; arsiList.AddRounded(arsi); } var arsiEmaList = GetMovingAverageList(stockData, maType, length2, arsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double arsi = arsiList[i]; - double arsiEma = arsiEmaList[i]; - double prevArsi = i >= 1 ? arsiList[i - 1] : 0; - double prevArsiEma = i >= 1 ? arsiEmaList[i - 1] : 0; + var arsi = arsiList[i]; + var arsiEma = arsiEmaList[i]; + var prevArsi = i >= 1 ? arsiList[i - 1] : 0; + var prevArsiEma = i >= 1 ? arsiEmaList[i - 1] : 0; var signal = GetRsiSignal(arsi - arsiEma, prevArsi - prevArsiEma, arsi, prevArsi, 0.7, 0.3); signalsList.Add(signal); @@ -3166,15 +3166,15 @@ public static StockData CalculateEhlersAdaptiveRsiFisherTransformV2(this StockDa var arsiList = CalculateEhlersAdaptiveRelativeStrengthIndexV2(stockData, maType, length1, length2, length3).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double arsi = arsiList[i] / 100; - double prevFish1 = i >= 1 ? fishList[i - 1] : 0; - double prevFish2 = i >= 2 ? fishList[i - 2] : 0; - double tranRsi = 2 * (arsi - 0.5); - double ampRsi = MinOrMax(1.5 * tranRsi, 0.999, -0.999); + var arsi = arsiList[i] / 100; + var prevFish1 = i >= 1 ? fishList[i - 1] : 0; + var prevFish2 = i >= 2 ? fishList[i - 2] : 0; + var tranRsi = 2 * (arsi - 0.5); + var ampRsi = MinOrMax(1.5 * tranRsi, 0.999, -0.999); - double fish = 0.5 * Math.Log((1 + ampRsi) / (1 - ampRsi)); + var fish = 0.5 * Math.Log((1 + ampRsi) / (1 - ampRsi)); fishList.AddRounded(fish); var signal = GetRsiSignal(fish - prevFish1, prevFish1 - prevFish2, fish, prevFish1, 2, -2); @@ -3208,45 +3208,45 @@ public static StockData CalculateEhlersAdaptiveStochasticIndicatorV2(this StockD List astocList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var domCycList = CalculateEhlersAutoCorrelationPeriodogram(stockData, length1, length2, length3).CustomValuesList; var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double domCyc = MinOrMax(domCycList[i], length1, length2); - double roofingFilter = roofingFilterList[i]; - double prevAstoc1 = i >= 1 ? astocList[i - 1] : 0; - double prevAstoc2 = i >= 2 ? astocList[i - 2] : 0; + var domCyc = MinOrMax(domCycList[i], length1, length2); + var roofingFilter = roofingFilterList[i]; + var prevAstoc1 = i >= 1 ? astocList[i - 1] : 0; + var prevAstoc2 = i >= 2 ? astocList[i - 2] : 0; double highest = 0, lowest = 0; - for (int j = 0; j < (int)Math.Ceiling(domCyc); j++) + for (var j = 0; j < (int)Math.Ceiling(domCyc); j++) { - double filt = i >= j ? roofingFilterList[i - j] : 0; + var filt = i >= j ? roofingFilterList[i - j] : 0; highest = filt > highest ? filt : highest; lowest = filt < lowest ? filt : lowest; } - double prevStoc = stocList.LastOrDefault(); - double stoc = highest != lowest ? (roofingFilter - lowest) / (highest - lowest) : 0; + var prevStoc = stocList.LastOrDefault(); + var stoc = highest != lowest ? (roofingFilter - lowest) / (highest - lowest) : 0; stocList.AddRounded(stoc); - double astoc = (c1 * ((stoc + prevStoc) / 2)) + (c2 * prevAstoc1) + (c3 * prevAstoc2); + var astoc = (c1 * ((stoc + prevStoc) / 2)) + (c2 * prevAstoc1) + (c3 * prevAstoc2); astocList.AddRounded(astoc); } var astocEmaList = GetMovingAverageList(stockData, maType, length2, astocList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double astoc = astocList[i]; - double astocEma = astocEmaList[i]; - double prevAstoc = i >= 1 ? astocList[i - 1] : 0; - double prevAstocEma = i >= 1 ? astocEmaList[i - 1] : 0; + var astoc = astocList[i]; + var astocEma = astocEmaList[i]; + var prevAstoc = i >= 1 ? astocList[i - 1] : 0; + var prevAstocEma = i >= 1 ? astocEmaList[i - 1] : 0; var signal = GetRsiSignal(astoc - astocEma, prevAstoc - prevAstocEma, astoc, prevAstoc, 0.7, 0.3); signalsList.Add(signal); @@ -3282,17 +3282,17 @@ public static StockData CalculateEhlersAdaptiveStochasticInverseFisherTransform( var astocList = CalculateEhlersAdaptiveStochasticIndicatorV2(stockData, maType, length1, length2, length3).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double astoc = astocList[i]; - double v1 = 2 * (astoc - 0.5); + var astoc = astocList[i]; + var v1 = 2 * (astoc - 0.5); - double prevFish = fishList.LastOrDefault(); - double fish = (Exp(6 * v1) - 1) / (Exp(6 * v1) + 1); + var prevFish = fishList.LastOrDefault(); + var fish = (Exp(6 * v1) - 1) / (Exp(6 * v1) + 1); fishList.AddRounded(fish); - double prevTrigger = triggerList.LastOrDefault(); - double trigger = 0.9 * prevFish; + var prevTrigger = triggerList.LastOrDefault(); + var trigger = 0.9 * prevFish; triggerList.AddRounded(trigger); var signal = GetCompareSignal(fish - trigger, prevFish - prevTrigger); @@ -3329,49 +3329,49 @@ public static StockData CalculateEhlersAdaptiveCommodityChannelIndexV2(this Stoc List ratioList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(Math.Min(1.414 * Math.PI / length2, 0.99)); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var domCycList = CalculateEhlersAutoCorrelationPeriodogram(stockData, length1, length2, length3).CustomValuesList; var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double domCyc = MinOrMax(domCycList[i], length1, length2); - double prevAcci1 = i >= 1 ? acciList[i - 1] : 0; - double prevAcci2 = i >= 2 ? acciList[i - 2] : 0; - int cycLength = (int)Math.Ceiling(domCyc); + var domCyc = MinOrMax(domCycList[i], length1, length2); + var prevAcci1 = i >= 1 ? acciList[i - 1] : 0; + var prevAcci2 = i >= 2 ? acciList[i - 2] : 0; + var cycLength = (int)Math.Ceiling(domCyc); - double roofingFilter = roofingFilterList[i]; + var roofingFilter = roofingFilterList[i]; tempList.AddRounded(roofingFilter); - double avg = tempList.TakeLastExt(cycLength).Average(); - double md = Pow(roofingFilter - avg, 2); + var avg = tempList.TakeLastExt(cycLength).Average(); + var md = Pow(roofingFilter - avg, 2); mdList.AddRounded(md); - double mdAvg = mdList.TakeLastExt(cycLength).Average(); - double rms = cycLength >= 0 ? Sqrt(mdAvg) : 0; - double num = roofingFilter - avg; - double denom = 0.015 * rms; + var mdAvg = mdList.TakeLastExt(cycLength).Average(); + var rms = cycLength >= 0 ? Sqrt(mdAvg) : 0; + var num = roofingFilter - avg; + var denom = 0.015 * rms; - double prevRatio = ratioList.LastOrDefault(); - double ratio = denom != 0 ? num / denom : 0; + var prevRatio = ratioList.LastOrDefault(); + var ratio = denom != 0 ? num / denom : 0; ratioList.AddRounded(ratio); - double acci = (c1 * ((ratio + prevRatio) / 2)) + (c2 * prevAcci1) + (c3 * prevAcci2); + var acci = (c1 * ((ratio + prevRatio) / 2)) + (c2 * prevAcci1) + (c3 * prevAcci2); acciList.AddRounded(acci); } var acciEmaList = GetMovingAverageList(stockData, maType, length2, acciList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double acci = acciList[i]; - double acciEma = acciEmaList[i]; - double prevAcci = i >= 1 ? acciList[i - 1] : 0; - double prevAcciEma = i >= 1 ? acciEmaList[i - 1] : 0; + var acci = acciList[i]; + var acciEma = acciEmaList[i]; + var prevAcci = i >= 1 ? acciList[i - 1] : 0; + var prevAcciEma = i >= 1 ? acciEmaList[i - 1] : 0; var signal = GetRsiSignal(acci - acciEma, prevAcci - prevAcciEma, acci, prevAcci, 100, -100); signalsList.Add(signal); @@ -3404,28 +3404,28 @@ public static StockData CalculateEhlersDiscreteFourierTransformSpectralEstimate( var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roofingFilter = roofingFilterList[i]; - double prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var roofingFilter = roofingFilterList[i]; + var prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; double maxPwr = 0, spx = 0, sp = 0; - for (int j = length2; j <= length1; j++) + for (var j = length2; j <= length1; j++) { double cosPart = 0, sinPart = 0; - for (int k = 0; k <= length1; k++) + for (var k = 0; k <= length1; k++) { - double prevFilt = i >= k ? roofingFilterList[i - k] : 0; + var prevFilt = i >= k ? roofingFilterList[i - k] : 0; cosPart += prevFilt * Math.Cos(2 * Math.PI * ((double)k / j)); sinPart += prevFilt * Math.Sin(2 * Math.PI * ((double)k / j)); } - double sqSum = Pow(cosPart, 2) + Pow(sinPart, 2); - double prevR = i >= j - 1 ? rList[i - (j - 1)] : 0; - double r = (0.2 * Pow(sqSum, 2)) + (0.8 * prevR); + var sqSum = Pow(cosPart, 2) + Pow(sinPart, 2); + var prevR = i >= j - 1 ? rList[i - (j - 1)] : 0; + var r = (0.2 * Pow(sqSum, 2)) + (0.8 * prevR); maxPwr = Math.Max(r, maxPwr); - double pwr = maxPwr != 0 ? r / maxPwr : 0; + var pwr = maxPwr != 0 ? r / maxPwr : 0; if (pwr >= 0.5) { @@ -3434,7 +3434,7 @@ public static StockData CalculateEhlersDiscreteFourierTransformSpectralEstimate( } } - double domCyc = sp != 0 ? spx / sp : 0; + var domCyc = sp != 0 ? spx / sp : 0; domCycList.AddRounded(domCyc); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); @@ -3468,26 +3468,26 @@ public static StockData CalculateEhlersCombFilterSpectralEstimate(this StockData var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roofingFilter = roofingFilterList[i]; - double prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var roofingFilter = roofingFilterList[i]; + var prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; double bp = 0, maxPwr = 0, spx = 0, sp = 0; - for (int j = length2; j <= length1; j++) + for (var j = length2; j <= length1; j++) { - double beta = Math.Cos(2 * Math.PI / j); - double gamma = 1 / Math.Cos(2 * Math.PI * bw / j); - double alpha = MinOrMax(gamma - Sqrt((gamma * gamma) - 1), 0.99, 0.01); + var beta = Math.Cos(2 * Math.PI / j); + var gamma = 1 / Math.Cos(2 * Math.PI * bw / j); + var alpha = MinOrMax(gamma - Sqrt((gamma * gamma) - 1), 0.99, 0.01); bp = (0.5 * (1 - alpha) * (roofingFilter - prevRoofingFilter2)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); double pwr = 0; - for (int k = 1; k <= j; k++) + for (var k = 1; k <= j; k++) { - double prevBp = i >= k ? bpList[i - k] : 0; + var prevBp = i >= k ? bpList[i - k] : 0; pwr += prevBp / j >= 0 ? Pow(prevBp / j, 2) : 0; } @@ -3502,7 +3502,7 @@ public static StockData CalculateEhlersCombFilterSpectralEstimate(this StockData } bpList.AddRounded(bp); - double domCyc = sp != 0 ? spx / sp : 0; + var domCyc = sp != 0 ? spx / sp : 0; domCycList.AddRounded(domCyc); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); @@ -3539,16 +3539,16 @@ public static StockData CalculateEhlersAutoCorrelationReversals(this StockData s var corrList = CalculateEhlersAutoCorrelationIndicator(stockData, length1, length2).CustomValuesList; var emaList = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema = emaList[i]; - double currentValue = inputList[i]; + var ema = emaList[i]; + var currentValue = inputList[i]; double delta = 0; - for (int j = length3; j <= length1; j++) + for (var j = length3; j <= length1; j++) { - double corr = i >= j ? corrList[i - j] : 0; - double prevCorr = i >= j - 1 ? corrList[i - (j - 1)] : 0; + var corr = i >= j ? corrList[i - j] : 0; + var prevCorr = i >= j - 1 ? corrList[i - (j - 1)] : 0; delta += (corr > 0.5 && prevCorr < 0.5) || (corr < 0.5 && prevCorr > 0.5) ? 1 : 0; } @@ -3590,47 +3590,47 @@ public static StockData CalculateEhlersReverseExponentialMovingAverageIndicatorV List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double cc = 1 - alpha; + var cc = 1 - alpha; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double prevEma = emaList.LastOrDefault(); - double ema = (alpha * currentValue) + (cc * prevEma); + var prevEma = emaList.LastOrDefault(); + var ema = (alpha * currentValue) + (cc * prevEma); emaList.AddRounded(ema); - double prevRe1 = re1List.LastOrDefault(); - double re1 = (cc * ema) + prevEma; + var prevRe1 = re1List.LastOrDefault(); + var re1 = (cc * ema) + prevEma; re1List.AddRounded(re1); - double prevRe2 = re2List.LastOrDefault(); - double re2 = (Pow(cc, 2) * re1) + prevRe1; + var prevRe2 = re2List.LastOrDefault(); + var re2 = (Pow(cc, 2) * re1) + prevRe1; re2List.AddRounded(re2); - double prevRe3 = re3List.LastOrDefault(); - double re3 = (Pow(cc, 4) * re2) + prevRe2; + var prevRe3 = re3List.LastOrDefault(); + var re3 = (Pow(cc, 4) * re2) + prevRe2; re3List.AddRounded(re3); - double prevRe4 = re4List.LastOrDefault(); - double re4 = (Pow(cc, 8) * re3) + prevRe3; + var prevRe4 = re4List.LastOrDefault(); + var re4 = (Pow(cc, 8) * re3) + prevRe3; re4List.AddRounded(re4); - double prevRe5 = re5List.LastOrDefault(); - double re5 = (Pow(cc, 16) * re4) + prevRe4; + var prevRe5 = re5List.LastOrDefault(); + var re5 = (Pow(cc, 16) * re4) + prevRe4; re5List.AddRounded(re5); - double prevRe6 = re6List.LastOrDefault(); - double re6 = (Pow(cc, 32) * re5) + prevRe5; + var prevRe6 = re6List.LastOrDefault(); + var re6 = (Pow(cc, 32) * re5) + prevRe5; re6List.AddRounded(re6); - double prevRe7 = re7List.LastOrDefault(); - double re7 = (Pow(cc, 64) * re6) + prevRe6; + var prevRe7 = re7List.LastOrDefault(); + var re7 = (Pow(cc, 64) * re6) + prevRe6; re7List.AddRounded(re7); - double re8 = (Pow(cc, 128) * re7) + prevRe7; - double prevWave = waveList.LastOrDefault(); - double wave = ema - (alpha * re8); + var re8 = (Pow(cc, 128) * re7) + prevRe7; + var prevWave = waveList.LastOrDefault(); + var wave = ema - (alpha * re8); waveList.AddRounded(wave); var signal = GetCompareSignal(wave, prevWave); @@ -3662,12 +3662,12 @@ public static StockData CalculateEhlersReverseExponentialMovingAverageIndicatorV var trendList = CalculateEhlersReverseExponentialMovingAverageIndicatorV1(stockData, trendAlpha).CustomValuesList; var cycleList = CalculateEhlersReverseExponentialMovingAverageIndicatorV1(stockData, cycleAlpha).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double waveCycle = cycleList[i]; - double waveTrend = trendList[i]; - double prevWaveCycle = i >= 1 ? cycleList[i - 1] : 0; - double prevWaveTrend = i >= 1 ? trendList[i - 1] : 0; + var waveCycle = cycleList[i]; + var waveTrend = trendList[i]; + var prevWaveCycle = i >= 1 ? cycleList[i - 1] : 0; + var prevWaveTrend = i >= 1 ? trendList[i - 1] : 0; var signal = GetCompareSignal(waveCycle - waveTrend, prevWaveCycle - prevWaveTrend); signalsList.Add(signal); @@ -3703,14 +3703,14 @@ public static StockData CalculateEhlersMovingAverageDifferenceIndicator(this Sto var shortMaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var longMaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double shortMa = shortMaList[i]; - double longMa = longMaList[i]; - double prevMad1 = i >= 1 ? madList[i - 1] : 0; - double prevMad2 = i >= 2 ? madList[i - 2] : 0; + var shortMa = shortMaList[i]; + var longMa = longMaList[i]; + var prevMad1 = i >= 1 ? madList[i - 1] : 0; + var prevMad2 = i >= 2 ? madList[i - 2] : 0; - double mad = longMa != 0 ? 100 * (shortMa - longMa) / longMa : 0; + var mad = longMa != 0 ? 100 * (shortMa - longMa) / longMa : 0; madList.AddRounded(mad); var signal = GetCompareSignal(mad - prevMad1, prevMad1 - prevMad2); @@ -3745,13 +3745,13 @@ public static StockData CalculateEhlersFisherizedDeviationScaledOscillator(this var scaledFilter2PoleList = GetMovingAverageList(stockData, maType, fastLength, inputList, fastLength, slowLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentScaledFilter2Pole = scaledFilter2PoleList[i]; - double prevEfdsoPole1 = i >= 1 ? efdso2PoleList[i - 1] : 0; - double prevEfdsoPole2 = i >= 2 ? efdso2PoleList[i - 2] : 0; + var currentScaledFilter2Pole = scaledFilter2PoleList[i]; + var prevEfdsoPole1 = i >= 1 ? efdso2PoleList[i - 1] : 0; + var prevEfdsoPole2 = i >= 2 ? efdso2PoleList[i - 2] : 0; - double efdso2Pole = Math.Abs(currentScaledFilter2Pole) < 2 ? 0.5 * Math.Log((1 + (currentScaledFilter2Pole / 2)) / + var efdso2Pole = Math.Abs(currentScaledFilter2Pole) < 2 ? 0.5 * Math.Log((1 + (currentScaledFilter2Pole / 2)) / (1 - (currentScaledFilter2Pole / 2))) : prevEfdsoPole1; efdso2PoleList.AddRounded(efdso2Pole); @@ -3786,24 +3786,24 @@ public static StockData CalculateEhlersHilbertTransformIndicator(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double v2 = i >= 2 ? v1List[i - 2] : 0; - double v4 = i >= 4 ? v1List[i - 4] : 0; - double inPhase3 = i >= 3 ? inPhaseList[i - 3] : 0; - double quad2 = i >= 2 ? quadList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var v2 = i >= 2 ? v1List[i - 2] : 0; + var v4 = i >= 4 ? v1List[i - 4] : 0; + var inPhase3 = i >= 3 ? inPhaseList[i - 3] : 0; + var quad2 = i >= 2 ? quadList[i - 2] : 0; - double v1 = MinPastValues(i, length, currentValue - prevValue); + var v1 = MinPastValues(i, length, currentValue - prevValue); v1List.AddRounded(v1); - double prevInPhase = inPhaseList.LastOrDefault(); - double inPhase = (1.25 * (v4 - (iMult * v2))) + (iMult * inPhase3); + var prevInPhase = inPhaseList.LastOrDefault(); + var inPhase = (1.25 * (v4 - (iMult * v2))) + (iMult * inPhase3); inPhaseList.AddRounded(inPhase); - double prevQuad = quadList.LastOrDefault(); - double quad = v2 - (qMult * v1) + (qMult * quad2); + var prevQuad = quadList.LastOrDefault(); + var quad = v2 - (qMult * v1) + (qMult * quad2); quadList.AddRounded(quad); var signal = GetCompareSignal(quad - (-1 * inPhase), prevQuad - (-1 * prevInPhase)); @@ -3840,35 +3840,35 @@ public static StockData CalculateEhlersInstantaneousPhaseIndicator(this StockDat var ipList = ehtList.OutputValues["Inphase"]; var quList = ehtList.OutputValues["Quad"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ip = ipList[i]; - double qu = quList[i]; - double prevIp = i >= 1 ? ipList[i - 1] : 0; - double prevQu = i >= 1 ? quList[i - 1] : 0; + var ip = ipList[i]; + var qu = quList[i]; + var prevIp = i >= 1 ? ipList[i - 1] : 0; + var prevQu = i >= 1 ? quList[i - 1] : 0; - double prevPhase = phaseList.LastOrDefault(); - double phase = Math.Abs(ip + prevIp) > 0 ? Math.Atan(Math.Abs((qu + prevQu) / (ip + prevIp))).ToDegrees() : 0; + var prevPhase = phaseList.LastOrDefault(); + var phase = Math.Abs(ip + prevIp) > 0 ? Math.Atan(Math.Abs((qu + prevQu) / (ip + prevIp))).ToDegrees() : 0; phase = ip < 0 && qu > 0 ? 180 - phase : phase; phase = ip < 0 && qu < 0 ? 180 + phase : phase; phase = ip > 0 && qu < 0 ? 360 - phase : phase; phaseList.AddRounded(phase); - double dPhase = prevPhase - phase; + var dPhase = prevPhase - phase; dPhase = prevPhase < 90 && phase > 270 ? 360 + prevPhase - phase : dPhase; dPhase = MinOrMax(dPhase, 60, 1); dPhaseList.AddRounded(dPhase); double instPeriod = 0, v4 = 0; - for (int j = 0; j <= length2; j++) + for (var j = 0; j <= length2; j++) { - double prevDPhase = i >= j ? dPhaseList[i - j] : 0; + var prevDPhase = i >= j ? dPhaseList[i - j] : 0; v4 += prevDPhase; instPeriod = v4 > 360 && instPeriod == 0 ? j : instPeriod; } - double prevDcPeriod = dcPeriodList.LastOrDefault(); - double dcPeriod = (0.25 * instPeriod) + (0.75 * prevDcPeriod); + var prevDcPeriod = dcPeriodList.LastOrDefault(); + var dcPeriod = (0.25 * instPeriod) + (0.75 * prevDcPeriod); dcPeriodList.AddRounded(dcPeriod); var signal = GetCompareSignal(qu - (-1 * ip), prevQu - (-1 * prevIp)); @@ -3906,49 +3906,49 @@ public static StockData CalculateEhlersSquelchIndicator(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length1 ? inputList[i - length1] : 0; - double priorV1 = i >= length1 ? v1List[i - length1] : 0; - double prevV12 = i >= 2 ? v1List[i - 2] : 0; - double prevV14 = i >= 4 ? v1List[i - 4] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length1 ? inputList[i - length1] : 0; + var priorV1 = i >= length1 ? v1List[i - length1] : 0; + var prevV12 = i >= 2 ? v1List[i - 2] : 0; + var prevV14 = i >= 4 ? v1List[i - 4] : 0; - double v1 = MinPastValues(i, length1, currentValue - prevValue); + var v1 = MinPastValues(i, length1, currentValue - prevValue); v1List.AddRounded(v1); - double v2 = i >= 3 ? v1List[i - 3] : 0; - double v3 = (0.75 * (v1 - priorV1)) + (0.25 * (prevV12 - prevV14)); - double prevIp = ipList.LastOrDefault(); - double ip = (0.33 * v2) + (0.67 * prevIp); + var v2 = i >= 3 ? v1List[i - 3] : 0; + var v3 = (0.75 * (v1 - priorV1)) + (0.25 * (prevV12 - prevV14)); + var prevIp = ipList.LastOrDefault(); + var ip = (0.33 * v2) + (0.67 * prevIp); ipList.AddRounded(ip); - double prevQu = quList.LastOrDefault(); - double qu = (0.2 * v3) + (0.8 * prevQu); + var prevQu = quList.LastOrDefault(); + var qu = (0.2 * v3) + (0.8 * prevQu); quList.AddRounded(qu); - double prevPhase = phaseList.LastOrDefault(); - double phase = Math.Abs(ip + prevIp) > 0 ? Math.Atan(Math.Abs((qu + prevQu) / (ip + prevIp))).ToDegrees() : 0; + var prevPhase = phaseList.LastOrDefault(); + var phase = Math.Abs(ip + prevIp) > 0 ? Math.Atan(Math.Abs((qu + prevQu) / (ip + prevIp))).ToDegrees() : 0; phase = ip < 0 && qu > 0 ? 180 - phase : phase; phase = ip < 0 && qu < 0 ? 180 + phase : phase; phase = ip > 0 && qu < 0 ? 360 - phase : phase; phaseList.AddRounded(phase); - double dPhase = prevPhase - phase; + var dPhase = prevPhase - phase; dPhase = prevPhase < 90 && phase > 270 ? 360 + prevPhase - phase : dPhase; dPhase = MinOrMax(dPhase, 60, 1); dPhaseList.AddRounded(dPhase); double instPeriod = 0, v4 = 0; - for (int j = 0; j <= length3; j++) + for (var j = 0; j <= length3; j++) { - double prevDPhase = i >= j ? dPhaseList[i - j] : 0; + var prevDPhase = i >= j ? dPhaseList[i - j] : 0; v4 += prevDPhase; instPeriod = v4 > 360 && instPeriod == 0 ? j : instPeriod; } - double prevDcPeriod = dcPeriodList.LastOrDefault(); - double dcPeriod = (0.25 * instPeriod) + (0.75 * prevDcPeriod); + var prevDcPeriod = dcPeriodList.LastOrDefault(); + var dcPeriod = (0.25 * instPeriod) + (0.75 * prevDcPeriod); dcPeriodList.AddRounded(dcPeriod); double si = dcPeriod < length2 ? 0 : 1; @@ -3985,31 +3985,31 @@ public static StockData CalculateEhlersClassicHilbertTransformer(this StockData var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double roofingFilter = roofingFilterList[i]; - double prevReal1 = i >= 1 ? realList[i - 1] : 0; - double prevReal2 = i >= 2 ? realList[i - 2] : 0; - double prevReal4 = i >= 4 ? realList[i - 4] : 0; - double prevReal6 = i >= 6 ? realList[i - 6] : 0; - double prevReal8 = i >= 8 ? realList[i - 8] : 0; - double prevReal10 = i >= 10 ? realList[i - 10] : 0; - double prevReal12 = i >= 12 ? realList[i - 12] : 0; - double prevReal14 = i >= 14 ? realList[i - 14] : 0; - double prevReal16 = i >= 16 ? realList[i - 16] : 0; - double prevReal18 = i >= 18 ? realList[i - 18] : 0; - double prevReal20 = i >= 20 ? realList[i - 20] : 0; - double prevReal22 = i >= 22 ? realList[i - 22] : 0; - - double prevPeak = peakList.LastOrDefault(); - double peak = Math.Max(0.991 * prevPeak, Math.Abs(roofingFilter)); + for (var i = 0; i < stockData.Count; i++) + { + var roofingFilter = roofingFilterList[i]; + var prevReal1 = i >= 1 ? realList[i - 1] : 0; + var prevReal2 = i >= 2 ? realList[i - 2] : 0; + var prevReal4 = i >= 4 ? realList[i - 4] : 0; + var prevReal6 = i >= 6 ? realList[i - 6] : 0; + var prevReal8 = i >= 8 ? realList[i - 8] : 0; + var prevReal10 = i >= 10 ? realList[i - 10] : 0; + var prevReal12 = i >= 12 ? realList[i - 12] : 0; + var prevReal14 = i >= 14 ? realList[i - 14] : 0; + var prevReal16 = i >= 16 ? realList[i - 16] : 0; + var prevReal18 = i >= 18 ? realList[i - 18] : 0; + var prevReal20 = i >= 20 ? realList[i - 20] : 0; + var prevReal22 = i >= 22 ? realList[i - 22] : 0; + + var prevPeak = peakList.LastOrDefault(); + var peak = Math.Max(0.991 * prevPeak, Math.Abs(roofingFilter)); peakList.AddRounded(peak); - double real = peak != 0 ? roofingFilter / peak : 0; + var real = peak != 0 ? roofingFilter / peak : 0; realList.AddRounded(real); - double imag = ((0.091 * real) + (0.111 * prevReal2) + (0.143 * prevReal4) + (0.2 * prevReal6) + (0.333 * prevReal8) + prevReal10 - - prevReal12 - (0.333 * prevReal14) - (0.2 * prevReal16) - (0.143 * prevReal18) - (0.111 * prevReal20) - (0.091 * prevReal22)) / 1.865; + var imag = ((0.091 * real) + (0.111 * prevReal2) + (0.143 * prevReal4) + (0.2 * prevReal6) + (0.333 * prevReal8) + prevReal10 - + prevReal12 - (0.333 * prevReal14) - (0.2 * prevReal16) - (0.143 * prevReal18) - (0.111 * prevReal20) - (0.091 * prevReal22)) / 1.865; imagList.AddRounded(imag); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); @@ -4045,26 +4045,26 @@ public static StockData CalculateEhlersHilbertTransformer(this StockData stockDa var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roofingFilter = roofingFilterList[i]; - double prevReal1 = i >= 1 ? realList[i - 1] : 0; - double prevReal2 = i >= 2 ? realList[i - 2] : 0; + var roofingFilter = roofingFilterList[i]; + var prevReal1 = i >= 1 ? realList[i - 1] : 0; + var prevReal2 = i >= 2 ? realList[i - 2] : 0; - double prevPeak = peakList.LastOrDefault(); - double peak = Math.Max(0.991 * prevPeak, Math.Abs(roofingFilter)); + var prevPeak = peakList.LastOrDefault(); + var peak = Math.Max(0.991 * prevPeak, Math.Abs(roofingFilter)); peakList.AddRounded(peak); - double prevReal = realList.LastOrDefault(); - double real = peak != 0 ? roofingFilter / peak : 0; + var prevReal = realList.LastOrDefault(); + var real = peak != 0 ? roofingFilter / peak : 0; realList.AddRounded(real); - double qFilt = real - prevReal; - double prevQPeak = qPeakList.LastOrDefault(); - double qPeak = Math.Max(0.991 * prevQPeak, Math.Abs(qFilt)); + var qFilt = real - prevReal; + var prevQPeak = qPeakList.LastOrDefault(); + var qPeak = Math.Max(0.991 * prevQPeak, Math.Abs(qFilt)); qPeakList.AddRounded(qPeak); - double imag = qPeak != 0 ? qFilt / qPeak : 0; + var imag = qPeak != 0 ? qFilt / qPeak : 0; imagList.AddRounded(imag); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); @@ -4100,38 +4100,38 @@ public static StockData CalculateEhlersHilbertTransformerIndicator(this StockDat List qPeakList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length3); - double b2 = 2 * a1 * Math.Cos(1.414 * Math.PI / length3); - double c2 = b2; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length3); + var b2 = 2 * a1 * Math.Cos(1.414 * Math.PI / length3); + var c2 = b2; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roofingFilter = roofingFilterList[i]; - double prevQFilt = i >= 1 ? qFiltList[i - 1] : 0; - double prevImag1 = i >= 1 ? imagList[i - 1] : 0; - double prevImag2 = i >= 2 ? imagList[i - 2] : 0; + var roofingFilter = roofingFilterList[i]; + var prevQFilt = i >= 1 ? qFiltList[i - 1] : 0; + var prevImag1 = i >= 1 ? imagList[i - 1] : 0; + var prevImag2 = i >= 2 ? imagList[i - 2] : 0; - double prevPeak = peakList.LastOrDefault(); - double peak = Math.Max(0.991 * prevPeak, Math.Abs(roofingFilter)); + var prevPeak = peakList.LastOrDefault(); + var peak = Math.Max(0.991 * prevPeak, Math.Abs(roofingFilter)); peakList.AddRounded(peak); - double prevReal = realList.LastOrDefault(); - double real = peak != 0 ? roofingFilter / peak : 0; + var prevReal = realList.LastOrDefault(); + var real = peak != 0 ? roofingFilter / peak : 0; realList.AddRounded(real); - double qFilt = real - prevReal; - double prevQPeak = qPeakList.LastOrDefault(); - double qPeak = Math.Max(0.991 * prevQPeak, Math.Abs(qFilt)); + var qFilt = real - prevReal; + var prevQPeak = qPeakList.LastOrDefault(); + var qPeak = Math.Max(0.991 * prevQPeak, Math.Abs(qFilt)); qPeakList.AddRounded(qPeak); qFilt = qPeak != 0 ? qFilt / qPeak : 0; qFiltList.AddRounded(qFilt); - double imag = (c1 * ((qFilt + prevQFilt) / 2)) + (c2 * prevImag1) + (c3 * prevImag2); + var imag = (c1 * ((qFilt + prevQFilt) / 2)) + (c2 * prevImag1) + (c3 * prevImag2); imagList.AddRounded(imag); var signal = GetCompareSignal(imag - qFilt, prevImag1 - prevQFilt); @@ -4164,34 +4164,34 @@ public static StockData CalculateEhlersDualDifferentiatorDominantCycle(this Stoc List domCycList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var hilbertList = CalculateEhlersHilbertTransformer(stockData, length1, length2); var realList = hilbertList.OutputValues["Real"]; var imagList = hilbertList.OutputValues["Imag"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double real = realList[i]; - double imag = imagList[i]; - double prevReal1 = i >= 1 ? realList[i - 1] : 0; - double prevReal2 = i >= 2 ? realList[i - 2] : 0; - double prevImag1 = i >= 1 ? imagList[i - 1] : 0; - double iDot = real - prevReal1; - double prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; - double prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; - double qDot = imag - prevImag1; + var real = realList[i]; + var imag = imagList[i]; + var prevReal1 = i >= 1 ? realList[i - 1] : 0; + var prevReal2 = i >= 2 ? realList[i - 2] : 0; + var prevImag1 = i >= 1 ? imagList[i - 1] : 0; + var iDot = real - prevReal1; + var prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; + var prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; + var qDot = imag - prevImag1; - double prevPeriod = periodList.LastOrDefault(); - double period = (real * qDot) - (imag * iDot) != 0 ? 2 * Math.PI * ((real * real) + (imag * imag)) / ((-real * qDot) + (imag * iDot)) : 0; + var prevPeriod = periodList.LastOrDefault(); + var period = (real * qDot) - (imag * iDot) != 0 ? 2 * Math.PI * ((real * real) + (imag * imag)) / ((-real * qDot) + (imag * iDot)) : 0; period = MinOrMax(period, length1, length3); periodList.AddRounded(period); - double domCyc = (c1 * ((period + prevPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); + var domCyc = (c1 * ((period + prevPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); domCycList.AddRounded(domCyc); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); @@ -4227,42 +4227,42 @@ public static StockData CalculateEhlersPhaseAccumulationDominantCycle(this Stock List domCycList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var hilbertList = CalculateEhlersHilbertTransformer(stockData, length1, length2); var realList = hilbertList.OutputValues["Real"]; var imagList = hilbertList.OutputValues["Imag"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double real = realList[i]; - double imag = imagList[i]; - double prevReal1 = i >= 1 ? realList[i - 1] : 0; - double prevReal2 = i >= 2 ? realList[i - 2] : 0; - double prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; - double prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; + var real = realList[i]; + var imag = imagList[i]; + var prevReal1 = i >= 1 ? realList[i - 1] : 0; + var prevReal2 = i >= 2 ? realList[i - 2] : 0; + var prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; + var prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; - double prevPhase = phaseList.LastOrDefault(); - double phase = Math.Abs(real) > 0 ? Math.Atan(Math.Abs(imag / real)).ToDegrees() : 0; + var prevPhase = phaseList.LastOrDefault(); + var phase = Math.Abs(real) > 0 ? Math.Atan(Math.Abs(imag / real)).ToDegrees() : 0; phase = real < 0 && imag > 0 ? 180 - phase : phase; phase = real < 0 && imag < 0 ? 180 + phase : phase; phase = real > 0 && imag < 0 ? 360 - phase : phase; phaseList.AddRounded(phase); - double dPhase = prevPhase - phase; + var dPhase = prevPhase - phase; dPhase = prevPhase < 90 && phase > 270 ? 360 + prevPhase - phase : dPhase; dPhase = MinOrMax(dPhase, length1, length3); dPhaseList.AddRounded(dPhase); - double prevInstPeriod = instPeriodList.LastOrDefault(); + var prevInstPeriod = instPeriodList.LastOrDefault(); double instPeriod = 0, phaseSum = 0; - for (int j = 0; j < length4; j++) + for (var j = 0; j < length4; j++) { - double prevDPhase = i >= j ? dPhaseList[i - j] : 0; + var prevDPhase = i >= j ? dPhaseList[i - j] : 0; phaseSum += prevDPhase; if (phaseSum > 360 && instPeriod == 0) @@ -4273,7 +4273,7 @@ public static StockData CalculateEhlersPhaseAccumulationDominantCycle(this Stock instPeriod = instPeriod == 0 ? prevInstPeriod : instPeriod; instPeriodList.AddRounded(instPeriod); - double domCyc = (c1 * ((instPeriod + prevInstPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); + var domCyc = (c1 * ((instPeriod + prevInstPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); domCycList.AddRounded(domCyc); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); @@ -4305,34 +4305,34 @@ public static StockData CalculateEhlersHomodyneDominantCycle(this StockData stoc List domCycList = new(); List signalsList = new(); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; var hilbertList = CalculateEhlersHilbertTransformer(stockData, length1, length2); var realList = hilbertList.OutputValues["Real"]; var imagList = hilbertList.OutputValues["Imag"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double real = realList[i]; - double imag = imagList[i]; - double prevReal1 = i >= 1 ? realList[i - 1] : 0; - double prevImag1 = i >= 1 ? imagList[i - 1] : 0; - double prevReal2 = i >= 2 ? realList[i - 2] : 0; - double prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; - double prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; - double re = (real * prevReal1) + (imag * prevImag1); - double im = (prevReal1 * imag) - (real * prevImag1); + var real = realList[i]; + var imag = imagList[i]; + var prevReal1 = i >= 1 ? realList[i - 1] : 0; + var prevImag1 = i >= 1 ? imagList[i - 1] : 0; + var prevReal2 = i >= 2 ? realList[i - 2] : 0; + var prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; + var prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; + var re = (real * prevReal1) + (imag * prevImag1); + var im = (prevReal1 * imag) - (real * prevImag1); - double prevPeriod = periodList.LastOrDefault(); - double period = im != 0 && re != 0 ? 2 * Math.PI / Math.Abs(im / re) : 0; + var prevPeriod = periodList.LastOrDefault(); + var period = im != 0 && re != 0 ? 2 * Math.PI / Math.Abs(im / re) : 0; period = MinOrMax(period, length1, length3); periodList.AddRounded(period); - double domCyc = (c1 * ((period + prevPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); + var domCyc = (c1 * ((period + prevPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); domCycList.AddRounded(domCyc); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); @@ -4371,27 +4371,27 @@ public static StockData CalculateEhlersSignalToNoiseRatioV1(this StockData stock var quadList = hilbertTransformList.OutputValues["Quad"]; var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEma = emaList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double inPhase = inPhaseList[i]; - double quad = quadList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentEma = emaList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var inPhase = inPhaseList[i]; + var quad = quadList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double prevV2 = v2List.LastOrDefault(); - double v2 = (0.2 * ((inPhase * inPhase) + (quad * quad))) + (0.8 * prevV2); + var prevV2 = v2List.LastOrDefault(); + var v2 = (0.2 * ((inPhase * inPhase) + (quad * quad))) + (0.8 * prevV2); v2List.AddRounded(v2); - double prevRange = rangeList.LastOrDefault(); - double range = (0.2 * (currentHigh - currentLow)) + (0.8 * prevRange); + var prevRange = rangeList.LastOrDefault(); + var range = (0.2 * (currentHigh - currentLow)) + (0.8 * prevRange); rangeList.AddRounded(range); - double prevAmp = ampList.LastOrDefault(); - double amp = range != 0 ? (0.25 * ((10 * Math.Log(v2 / (range * range)) / Math.Log(10)) + 1.9)) + (0.75 * prevAmp) : 0; + var prevAmp = ampList.LastOrDefault(); + var amp = range != 0 ? (0.25 * ((10 * Math.Log(v2 / (range * range)) / Math.Log(10)) + 1.9)) + (0.75 * prevAmp) : 0; ampList.AddRounded(amp); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, amp, 1.9); @@ -4423,23 +4423,23 @@ public static StockData CalculateEhlersHannWindowIndicator(this StockData stockD List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentValue = inputList[i]; + var currentOpen = openList[i]; + var currentValue = inputList[i]; - double deriv = currentValue - currentOpen; + var deriv = currentValue - currentOpen; derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var filt = filtList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double roc = length / 2 * Math.PI * (filt - prevFilt1); + var roc = length / 2 * Math.PI * (filt - prevFilt1); rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); @@ -4474,24 +4474,24 @@ public static StockData CalculateEhlersHammingWindowIndicator(this StockData sto List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentValue = inputList[i]; + var currentOpen = openList[i]; + var currentValue = inputList[i]; - double deriv = currentValue - currentOpen; + var deriv = currentValue - currentOpen; derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var filt = filtList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double roc = length / 2 * Math.PI * (filt - prevFilt1); + var roc = length / 2 * Math.PI * (filt - prevFilt1); rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); @@ -4525,23 +4525,23 @@ public static StockData CalculateEhlersTriangleWindowIndicator(this StockData st List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentValue = inputList[i]; + var currentOpen = openList[i]; + var currentValue = inputList[i]; - double deriv = currentValue - currentOpen; + var deriv = currentValue - currentOpen; derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var filt = filtList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double roc = length / 2 * Math.PI * (filt - prevFilt1); + var roc = length / 2 * Math.PI * (filt - prevFilt1); rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); @@ -4574,25 +4574,25 @@ public static StockData CalculateEhlersSimpleWindowIndicator(this StockData stoc List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentValue = inputList[i]; + var currentOpen = openList[i]; + var currentValue = inputList[i]; - double deriv = currentValue - currentOpen; + var deriv = currentValue - currentOpen; derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); var filtMa1List = GetMovingAverageList(stockData, maType, length, filtList); var filtMa2List = GetMovingAverageList(stockData, maType, length, filtMa1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtMa2List[i]; - double prevFilt1 = i >= 1 ? filtMa2List[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtMa2List[i - 2] : 0; + var filt = filtMa2List[i]; + var prevFilt1 = i >= 1 ? filtMa2List[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtMa2List[i - 2] : 0; - double roc = length / 2 * Math.PI * (filt - prevFilt1); + var roc = length / 2 * Math.PI * (filt - prevFilt1); rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); @@ -4629,24 +4629,24 @@ public static StockData CalculateEhlersSignalToNoiseRatioV2(this StockData stock var q1List = ehlersMamaList.OutputValues["Q1"]; var mamaList = ehlersMamaList.CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevMama = i >= 1 ? mamaList[i - 1] : 0; - double i1 = i1List[i]; - double q1 = q1List[i]; - double mama = mamaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevMama = i >= 1 ? mamaList[i - 1] : 0; + var i1 = i1List[i]; + var q1 = q1List[i]; + var mama = mamaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevRange = rangeList.LastOrDefault(); - double range = (0.1 * (currentHigh - currentLow)) + (0.9 * prevRange); + var prevRange = rangeList.LastOrDefault(); + var range = (0.1 * (currentHigh - currentLow)) + (0.9 * prevRange); rangeList.AddRounded(range); - double temp = range != 0 ? ((i1 * i1) + (q1 * q1)) / (range * range) : 0; - double prevSnr = snrList.LastOrDefault(); - double snr = range > 0 ? (0.25 * ((10 * Math.Log(temp) / Math.Log(10)) + length)) + (0.75 * prevSnr) : 0; + var temp = range != 0 ? ((i1 * i1) + (q1 * q1)) / (range * range) : 0; + var prevSnr = snrList.LastOrDefault(); + var snr = range > 0 ? (0.25 * ((10 * Math.Log(temp) / Math.Log(10)) + length)) + (0.75 * prevSnr) : 0; snrList.AddRounded(snr); var signal = GetVolatilitySignal(currentValue - mama, prevValue - prevMama, snr, length); @@ -4683,38 +4683,38 @@ public static StockData CalculateEhlersEnhancedSignalToNoiseRatio(this StockData var smoothList = ehlersMamaList.OutputValues["Smooth"]; var smoothPeriodList = ehlersMamaList.OutputValues["SmoothPeriod"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double smooth = smoothList[i]; - double prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; - double smoothPeriod = smoothPeriodList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSmooth = i >= 1 ? smoothList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var smooth = smoothList[i]; + var prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + var smoothPeriod = smoothPeriodList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSmooth = i >= 1 ? smoothList[i - 1] : 0; - double q3 = 0.5 * (smooth - prevSmooth2) * ((0.1759 * smoothPeriod) + 0.4607); + var q3 = 0.5 * (smooth - prevSmooth2) * ((0.1759 * smoothPeriod) + 0.4607); q3List.AddRounded(q3); - int sp = (int)Math.Ceiling(smoothPeriod / 2); + var sp = (int)Math.Ceiling(smoothPeriod / 2); double i3 = 0; - for (int j = 0; j <= sp - 1; j++) + for (var j = 0; j <= sp - 1; j++) { - double prevQ3 = i >= j ? q3List[i - j] : 0; + var prevQ3 = i >= j ? q3List[i - j] : 0; i3 += prevQ3; } i3 = sp != 0 ? 1.57 * i3 / sp : i3; i3List.AddRounded(i3); - double signalValue = (i3 * i3) + (q3 * q3); - double prevNoise = noiseList.LastOrDefault(); - double noise = (0.1 * (currentHigh - currentLow) * (currentHigh - currentLow) * 0.25) + (0.9 * prevNoise); + var signalValue = (i3 * i3) + (q3 * q3); + var prevNoise = noiseList.LastOrDefault(); + var noise = (0.1 * (currentHigh - currentLow) * (currentHigh - currentLow) * 0.25) + (0.9 * prevNoise); noiseList.AddRounded(noise); - double temp = noise != 0 ? signalValue / noise : 0; - double prevSnr = snrList.LastOrDefault(); - double snr = (0.33 * (10 * Math.Log(temp) / Math.Log(10))) + (0.67 * prevSnr); + var temp = noise != 0 ? signalValue / noise : 0; + var prevSnr = snrList.LastOrDefault(); + var snr = (0.33 * (10 * Math.Log(temp) / Math.Log(10))) + (0.67 * prevSnr); snrList.AddRounded(snr); var signal = GetVolatilitySignal(currentValue - smooth, prevValue - prevSmooth, snr, length); @@ -4751,18 +4751,18 @@ public static StockData CalculateEhlersHilbertOscillator(this StockData stockDat var q3List = snrv2List.OutputValues["Q3"]; var i3List = snrv2List.OutputValues["I3"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double smoothPeriod = smoothPeriodList[i]; - double i3 = i3List[i]; - double prevI3 = i >= 1 ? i3List[i - 1] : 0; - double prevIq = i >= 1 ? iqList[i - 1] : 0; + var smoothPeriod = smoothPeriodList[i]; + var i3 = i3List[i]; + var prevI3 = i >= 1 ? i3List[i - 1] : 0; + var prevIq = i >= 1 ? iqList[i - 1] : 0; - int maxCount = (int)Math.Ceiling(smoothPeriod / 4); + var maxCount = (int)Math.Ceiling(smoothPeriod / 4); double iq = 0; - for (int j = 0; j <= maxCount - 1; j++) + for (var j = 0; j <= maxCount - 1; j++) { - double prevQ3 = i >= j ? q3List[i - j] : 0; + var prevQ3 = i >= j ? q3List[i - j] : 0; iq += prevQ3; } iq = maxCount != 0 ? 1.25 * iq / maxCount : iq; @@ -4802,24 +4802,24 @@ public static StockData CalculateEhlersAlternateSignalToNoiseRatio(this StockDat var imList = ehlersMamaList.OutputValues["Imag"]; var mamaList = ehlersMamaList.CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mama = mamaList[i]; - double re = reList[i]; - double im = imList[i]; - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMama = i >= 1 ? mamaList[i - 1] : 0; + var mama = mamaList[i]; + var re = reList[i]; + var im = imList[i]; + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMama = i >= 1 ? mamaList[i - 1] : 0; - double prevRange = rangeList.LastOrDefault(); - double range = (0.1 * (currentHigh - currentLow)) + (0.9 * prevRange); + var prevRange = rangeList.LastOrDefault(); + var range = (0.1 * (currentHigh - currentLow)) + (0.9 * prevRange); rangeList.AddRounded(range); - double temp = range != 0 ? (re + im) / (range * range) : 0; - double prevSnr = snrList.LastOrDefault(); - double snr = (0.25 * ((10 * Math.Log(temp) / Math.Log(10)) + length)) + (0.75 * prevSnr); + var temp = range != 0 ? (re + im) / (range * range) : 0; + var prevSnr = snrList.LastOrDefault(); + var snr = (0.25 * ((10 * Math.Log(temp) / Math.Log(10)) + length)) + (0.75 * prevSnr); snrList.AddRounded(snr); var signal = GetVolatilitySignal(currentValue - mama, prevValue - prevMama, snr, length); @@ -4854,31 +4854,31 @@ public static StockData CalculateEhlersDiscreteFourierTransform(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double twoPiPrd = MinOrMax(2 * Math.PI / length, 0.99, 0.01); - double alpha = (1 - Math.Sin(twoPiPrd)) / Math.Cos(twoPiPrd); + var twoPiPrd = MinOrMax(2 * Math.PI / length, 0.99, 0.01); + var alpha = (1 - Math.Sin(twoPiPrd)) / Math.Cos(twoPiPrd); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevHp3 = i >= 3 ? hpList[i - 3] : 0; - double prevHp4 = i >= 4 ? hpList[i - 4] : 0; - double prevHp5 = i >= 5 ? hpList[i - 5] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevHp3 = i >= 3 ? hpList[i - 3] : 0; + var prevHp4 = i >= 4 ? hpList[i - 4] : 0; + var prevHp5 = i >= 5 ? hpList[i - 5] : 0; - double hp = i <= 5 ? currentValue : (0.5 * (1 + alpha) * (currentValue - prevValue1)) + (alpha * prevHp1); + var hp = i <= 5 ? currentValue : (0.5 * (1 + alpha) * (currentValue - prevValue1)) + (alpha * prevHp1); hpList.AddRounded(hp); - double cleanedData = i <= 5 ? currentValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; + var cleanedData = i <= 5 ? currentValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; cleanedDataList.AddRounded(cleanedData); double pwr = 0, cosPart = 0, sinPart = 0; - for (int j = minLength; j <= maxLength; j++) + for (var j = minLength; j <= maxLength; j++) { - for (int n = 0; n <= maxLength - 1; n++) + for (var n = 0; n <= maxLength - 1; n++) { - double prevCleanedData = i >= n ? cleanedDataList[i - n] : 0; + var prevCleanedData = i >= n ? cleanedDataList[i - n] : 0; cosPart += prevCleanedData * Math.Cos(MinOrMax(2 * Math.PI * ((double)n / j), 0.99, 0.01)); sinPart += prevCleanedData * Math.Sin(MinOrMax(2 * Math.PI * ((double)n / j), 0.99, 0.01)); } @@ -4887,20 +4887,20 @@ public static StockData CalculateEhlersDiscreteFourierTransform(this StockData s } powerList.AddRounded(pwr); - double maxPwr = i >= minLength ? powerList[i - minLength] : 0; + var maxPwr = i >= minLength ? powerList[i - minLength] : 0; double num = 0, denom = 0; - for (int period = minLength; period <= maxLength; period++) + for (var period = minLength; period <= maxLength; period++) { - double prevPwr = i >= period ? powerList[i - period] : 0; + var prevPwr = i >= period ? powerList[i - period] : 0; maxPwr = prevPwr > maxPwr ? prevPwr : maxPwr; - double db = maxPwr > 0 && prevPwr > 0 ? -10 * Math.Log(0.01 / (1 - (0.99 * prevPwr / maxPwr))) / Math.Log(10) : 0; + var db = maxPwr > 0 && prevPwr > 0 ? -10 * Math.Log(0.01 / (1 - (0.99 * prevPwr / maxPwr))) / Math.Log(10) : 0; db = db > 20 ? 20 : db; num += db < 3 ? period * (3 - db) : 0; denom += db < 3 ? 3 - db : 0; } - double dominantCycle = denom != 0 ? num / denom : 0; + var dominantCycle = denom != 0 ? num / denom : 0; dominantCycleList.AddRounded(dominantCycle); var signal = GetCompareSignal(hp, prevHp1); @@ -4938,66 +4938,66 @@ public static StockData CalculateEhlersFourierSeriesAnalysis(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double l1 = Math.Cos(2 * Math.PI / length); - double g1 = Math.Cos(bw * 2 * Math.PI / length); - double s1 = (1 / g1) - Sqrt((1 / (g1 * g1)) - 1); - double l2 = Math.Cos(2 * Math.PI / ((double)length / 2)); - double g2 = Math.Cos(bw * 2 * Math.PI / ((double)length / 2)); - double s2 = (1 / g2) - Sqrt((1 / (g2 * g2)) - 1); - double l3 = Math.Cos(2 * Math.PI / ((double)length / 3)); - double g3 = Math.Cos(bw * 2 * Math.PI / ((double)length / 3)); - double s3 = (1 / g3) - Sqrt((1 / (g3 * g3)) - 1); - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevBp1_1 = bp1List.LastOrDefault(); - double prevBp2_1 = bp2List.LastOrDefault(); - double prevBp3_1 = bp3List.LastOrDefault(); - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevBp1_2 = i >= 2 ? bp1List[i - 2] : 0; - double prevBp2_2 = i >= 2 ? bp2List[i - 2] : 0; - double prevBp3_2 = i >= 2 ? bp3List[i - 2] : 0; - double prevWave2 = i >= 2 ? waveList[i - 2] : 0; - - double bp1 = i <= 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1_1) - (s1 * prevBp1_2); + var l1 = Math.Cos(2 * Math.PI / length); + var g1 = Math.Cos(bw * 2 * Math.PI / length); + var s1 = (1 / g1) - Sqrt((1 / (g1 * g1)) - 1); + var l2 = Math.Cos(2 * Math.PI / ((double)length / 2)); + var g2 = Math.Cos(bw * 2 * Math.PI / ((double)length / 2)); + var s2 = (1 / g2) - Sqrt((1 / (g2 * g2)) - 1); + var l3 = Math.Cos(2 * Math.PI / ((double)length / 3)); + var g3 = Math.Cos(bw * 2 * Math.PI / ((double)length / 3)); + var s3 = (1 / g3) - Sqrt((1 / (g3 * g3)) - 1); + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevBp1_1 = bp1List.LastOrDefault(); + var prevBp2_1 = bp2List.LastOrDefault(); + var prevBp3_1 = bp3List.LastOrDefault(); + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevBp1_2 = i >= 2 ? bp1List[i - 2] : 0; + var prevBp2_2 = i >= 2 ? bp2List[i - 2] : 0; + var prevBp3_2 = i >= 2 ? bp3List[i - 2] : 0; + var prevWave2 = i >= 2 ? waveList[i - 2] : 0; + + var bp1 = i <= 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1_1) - (s1 * prevBp1_2); bp1List.AddRounded(bp1); - double q1 = i <= 4 ? 0 : length / 2 * Math.PI * (bp1 - prevBp1_1); + var q1 = i <= 4 ? 0 : length / 2 * Math.PI * (bp1 - prevBp1_1); q1List.AddRounded(q1); - double bp2 = i <= 3 ? 0 : (0.5 * (1 - s2) * (currentValue - prevValue)) + (l2 * (1 + s2) * prevBp2_1) - (s2 * prevBp2_2); + var bp2 = i <= 3 ? 0 : (0.5 * (1 - s2) * (currentValue - prevValue)) + (l2 * (1 + s2) * prevBp2_1) - (s2 * prevBp2_2); bp2List.AddRounded(bp2); - double q2 = i <= 4 ? 0 : length / 2 * Math.PI * (bp2 - prevBp2_1); + var q2 = i <= 4 ? 0 : length / 2 * Math.PI * (bp2 - prevBp2_1); q2List.AddRounded(q2); - double bp3 = i <= 3 ? 0 : (0.5 * (1 - s3) * (currentValue - prevValue)) + (l3 * (1 + s3) * prevBp3_1) - (s3 * prevBp3_2); + var bp3 = i <= 3 ? 0 : (0.5 * (1 - s3) * (currentValue - prevValue)) + (l3 * (1 + s3) * prevBp3_1) - (s3 * prevBp3_2); bp3List.AddRounded(bp3); - double q3 = i <= 4 ? 0 : length / 2 * Math.PI * (bp3 - prevBp3_1); + var q3 = i <= 4 ? 0 : length / 2 * Math.PI * (bp3 - prevBp3_1); q3List.AddRounded(q3); double p1 = 0, p2 = 0, p3 = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double prevBp1 = i >= j ? bp1List[i - j] : 0; - double prevBp2 = i >= j ? bp2List[i - j] : 0; - double prevBp3 = i >= j ? bp3List[i - j] : 0; - double prevQ1 = i >= j ? q1List[i - j] : 0; - double prevQ2 = i >= j ? q2List[i - j] : 0; - double prevQ3 = i >= j ? q3List[i - j] : 0; + var prevBp1 = i >= j ? bp1List[i - j] : 0; + var prevBp2 = i >= j ? bp2List[i - j] : 0; + var prevBp3 = i >= j ? bp3List[i - j] : 0; + var prevQ1 = i >= j ? q1List[i - j] : 0; + var prevQ2 = i >= j ? q2List[i - j] : 0; + var prevQ3 = i >= j ? q3List[i - j] : 0; p1 += (prevBp1 * prevBp1) + (prevQ1 * prevQ1); p2 += (prevBp2 * prevBp2) + (prevQ2 * prevQ2); p3 += (prevBp3 * prevBp3) + (prevQ3 * prevQ3); } - double prevWave = waveList.LastOrDefault(); - double wave = p1 != 0 ? bp1 + (Sqrt(p2 / p1) * bp2) + (Sqrt(p3 / p1) * bp3) : 0; + var prevWave = waveList.LastOrDefault(); + var wave = p1 != 0 ? bp1 + (Sqrt(p2 / p1) * bp2) + (Sqrt(p3 / p1) * bp3) : 0; waveList.AddRounded(wave); - double roc = length / Math.PI * 4 * (wave - prevWave2); + var roc = length / Math.PI * 4 * (wave - prevWave2); rocList.AddRounded(roc); var signal = GetCompareSignal(wave, prevWave); @@ -5031,30 +5031,30 @@ public static StockData CalculateEhlersVossPredictiveFilter(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int order = MinOrMax((int)Math.Ceiling(3 * predict)); - double f1 = Math.Cos(2 * Math.PI / length); - double g1 = Math.Cos(bw * 2 * Math.PI / length); - double s1 = (1 / g1) - Sqrt((1 / (g1 * g1)) - 1); + var order = MinOrMax((int)Math.Ceiling(3 * predict)); + var f1 = Math.Cos(2 * Math.PI / length); + var g1 = Math.Cos(bw * 2 * Math.PI / length); + var s1 = (1 / g1) - Sqrt((1 / (g1 * g1)) - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double prevValue = i >= 2 ? inputList[i - 2] : 0; + var currentValue = inputList[i]; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var prevValue = i >= 2 ? inputList[i - 2] : 0; - double filt = i <= 5 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (f1 * (1 + s1) * prevFilt1) - (s1 * prevFilt2); + var filt = i <= 5 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (f1 * (1 + s1) * prevFilt1) - (s1 * prevFilt2); filtList.AddRounded(filt); double sumC = 0; - for (int j = 0; j <= order - 1; j++) + for (var j = 0; j <= order - 1; j++) { - double prevVoss = i >= order - j ? vossList[i - (order - j)] : 0; + var prevVoss = i >= order - j ? vossList[i - (order - j)] : 0; sumC += (double)(j + 1) / order * prevVoss; } - double prevvoss = vossList.LastOrDefault(); - double voss = ((double)(3 + order) / 2 * filt) - sumC; + var prevvoss = vossList.LastOrDefault(); + var voss = ((double)(3 + order) / 2 * filt) - sumC; vossList.AddRounded(voss); var signal = GetCompareSignal(voss - filt, prevvoss - prevFilt1); @@ -5095,81 +5095,81 @@ public static StockData CalculateEhlersSwissArmyKnifeIndicator(this StockData st List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double twoPiPrd = MinOrMax(2 * Math.PI / length, 0.99, 0.01); - double deltaPrd = MinOrMax(2 * Math.PI * 2 * delta / length, 0.99, 0.01); - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevPrice1 = i >= 1 ? inputList[i - 1] : 0; - double prevPrice2 = i >= 2 ? inputList[i - 2] : 0; - double prevPrice = i >= length ? inputList[i - length] : 0; - double prevEmaFilter1 = emaFilterList.LastOrDefault(); - double prevSmaFilter1 = smaFilterList.LastOrDefault(); - double prevGaussFilter1 = gaussFilterList.LastOrDefault(); - double prevButterFilter1 = butterFilterList.LastOrDefault(); - double prevSmoothFilter1 = smoothFilterList.LastOrDefault(); - double prevHpFilter1 = hpFilterList.LastOrDefault(); - double prevPhp2Filter1 = php2FilterList.LastOrDefault(); - double prevBpFilter1 = bpFilterList.LastOrDefault(); - double prevBsFilter1 = bsFilterList.LastOrDefault(); - double prevEmaFilter2 = i >= 2 ? emaFilterList[i - 2] : 0; - double prevSmaFilter2 = i >= 2 ? smaFilterList[i - 2] : 0; - double prevGaussFilter2 = i >= 2 ? gaussFilterList[i - 2] : 0; - double prevButterFilter2 = i >= 2 ? butterFilterList[i - 2] : 0; - double prevSmoothFilter2 = i >= 2 ? smoothFilterList[i - 2] : 0; - double prevHpFilter2 = i >= 2 ? hpFilterList[i - 2] : 0; - double prevPhp2Filter2 = i >= 2 ? php2FilterList[i - 2] : 0; - double prevBpFilter2 = i >= 2 ? bpFilterList[i - 2] : 0; - double prevBsFilter2 = i >= 2 ? bsFilterList[i - 2] : 0; + var twoPiPrd = MinOrMax(2 * Math.PI / length, 0.99, 0.01); + var deltaPrd = MinOrMax(2 * Math.PI * 2 * delta / length, 0.99, 0.01); + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevPrice1 = i >= 1 ? inputList[i - 1] : 0; + var prevPrice2 = i >= 2 ? inputList[i - 2] : 0; + var prevPrice = i >= length ? inputList[i - length] : 0; + var prevEmaFilter1 = emaFilterList.LastOrDefault(); + var prevSmaFilter1 = smaFilterList.LastOrDefault(); + var prevGaussFilter1 = gaussFilterList.LastOrDefault(); + var prevButterFilter1 = butterFilterList.LastOrDefault(); + var prevSmoothFilter1 = smoothFilterList.LastOrDefault(); + var prevHpFilter1 = hpFilterList.LastOrDefault(); + var prevPhp2Filter1 = php2FilterList.LastOrDefault(); + var prevBpFilter1 = bpFilterList.LastOrDefault(); + var prevBsFilter1 = bsFilterList.LastOrDefault(); + var prevEmaFilter2 = i >= 2 ? emaFilterList[i - 2] : 0; + var prevSmaFilter2 = i >= 2 ? smaFilterList[i - 2] : 0; + var prevGaussFilter2 = i >= 2 ? gaussFilterList[i - 2] : 0; + var prevButterFilter2 = i >= 2 ? butterFilterList[i - 2] : 0; + var prevSmoothFilter2 = i >= 2 ? smoothFilterList[i - 2] : 0; + var prevHpFilter2 = i >= 2 ? hpFilterList[i - 2] : 0; + var prevPhp2Filter2 = i >= 2 ? php2FilterList[i - 2] : 0; + var prevBpFilter2 = i >= 2 ? bpFilterList[i - 2] : 0; + var prevBsFilter2 = i >= 2 ? bsFilterList[i - 2] : 0; double alpha = (Math.Cos(twoPiPrd) + Math.Sin(twoPiPrd) - 1) / Math.Cos(twoPiPrd), c0 = 1, c1 = 0, b0 = alpha, b1 = 0, b2 = 0, a1 = 1 - alpha, a2 = 0; - double emaFilter = i <= length ? currentValue : + var emaFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevEmaFilter1) + (a2 * prevEmaFilter2) - (c1 * prevPrice); emaFilterList.AddRounded(emaFilter); - int n = length; c0 = 1; c1 = (double)1 / n; b0 = (double)1 / n; b1 = 0; b2 = 0; a1 = 1; a2 = 0; - double smaFilter = i <= length ? currentValue : + var n = length; c0 = 1; c1 = (double)1 / n; b0 = (double)1 / n; b1 = 0; b2 = 0; a1 = 1; a2 = 0; + var smaFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevSmaFilter1) + (a2 * prevSmaFilter2) - (c1 * prevPrice); smaFilterList.AddRounded(smaFilter); double beta = 2.415 * (1 - Math.Cos(twoPiPrd)), sqrtData = Pow(beta, 2) + (2 * beta), sqrt = Sqrt(sqrtData); alpha = (-1 * beta) + sqrt; c0 = Pow(alpha, 2); c1 = 0; b0 = 1; b1 = 0; b2 = 0; a1 = 2 * (1 - alpha); a2 = -(1 - alpha) * (1 - alpha); - double gaussFilter = i <= length ? currentValue : + var gaussFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevGaussFilter1) + (a2 * prevGaussFilter2) - (c1 * prevPrice); gaussFilterList.AddRounded(gaussFilter); beta = 2.415 * (1 - Math.Cos(twoPiPrd)); sqrtData = (beta * beta) + (2 * beta); sqrt = sqrtData >= 0 ? Sqrt(sqrtData) : 0; alpha = (-1 * beta) + sqrt; c0 = Pow(alpha, 2) / 4; c1 = 0; b0 = 1; b1 = 2; b2 = 1; a1 = 2 * (1 - alpha); a2 = -(1 - alpha) * (1 - alpha); - double butterFilter = i <= length ? currentValue : + var butterFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevButterFilter1) + (a2 * prevButterFilter2) - (c1 * prevPrice); butterFilterList.AddRounded(butterFilter); c0 = (double)1 / 4; c1 = 0; b0 = 1; b1 = 2; b2 = 1; a1 = 0; a2 = 0; - double smoothFilter = (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevSmoothFilter1) + + var smoothFilter = (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevSmoothFilter1) + (a2 * prevSmoothFilter2) - (c1 * prevPrice); smoothFilterList.AddRounded(smoothFilter); alpha = (Math.Cos(twoPiPrd) + Math.Sin(twoPiPrd) - 1) / Math.Cos(twoPiPrd); c0 = 1 - (alpha / 2); c1 = 0; b0 = 1; b1 = -1; b2 = 0; a1 = 1 - alpha; a2 = 0; - double hpFilter = i <= length ? 0 : + var hpFilter = i <= length ? 0 : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevHpFilter1) + (a2 * prevHpFilter2) - (c1 * prevPrice); hpFilterList.AddRounded(hpFilter); beta = 2.415 * (1 - Math.Cos(twoPiPrd)); sqrtData = Pow(beta, 2) + (2 * beta); sqrt = sqrtData >= 0 ? Sqrt(sqrtData) : 0; alpha = (-1 * beta) + sqrt; c0 = (1 - (alpha / 2)) * (1 - (alpha / 2)); c1 = 0; b0 = 1; b1 = -2; b2 = 1; a1 = 2 * (1 - alpha); a2 = -(1 - alpha) * (1 - alpha); - double php2Filter = i <= length ? 0 : + var php2Filter = i <= length ? 0 : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevPhp2Filter1) + (a2 * prevPhp2Filter2) - (c1 * prevPrice); php2FilterList.AddRounded(php2Filter); - beta = Math.Cos(twoPiPrd); double gamma = 1 / Math.Cos(deltaPrd); sqrtData = Pow(gamma, 2) - 1; sqrt = Sqrt(sqrtData); + beta = Math.Cos(twoPiPrd); var gamma = 1 / Math.Cos(deltaPrd); sqrtData = Pow(gamma, 2) - 1; sqrt = Sqrt(sqrtData); alpha = gamma - sqrt; c0 = (1 - alpha) / 2; c1 = 0; b0 = 1; b1 = 0; b2 = -1; a1 = beta * (1 + alpha); a2 = alpha * -1; - double bpFilter = i <= length ? currentValue : + var bpFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevBpFilter1) + (a2 * prevBpFilter2) - (c1 * prevPrice); bpFilterList.AddRounded(bpFilter); beta = Math.Cos(twoPiPrd); gamma = 1 / Math.Cos(deltaPrd); sqrtData = Pow(gamma, 2) - 1; sqrt = sqrtData >= 0 ? Sqrt(sqrtData) : 0; alpha = gamma - sqrt; c0 = (1 + alpha) / 2; c1 = 0; b0 = 1; b1 = -2 * beta; b2 = 1; a1 = beta * (1 + alpha); a2 = alpha * -1; - double bsFilter = i <= length ? currentValue : + var bsFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevBsFilter1) + (a2 * prevBsFilter2) - (c1 * prevPrice); bsFilterList.AddRounded(bsFilter); @@ -5214,43 +5214,43 @@ public static StockData CalculateEhlersUniversalOscillator(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(-MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(-MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double prevWhitenoise = whitenoiseList.LastOrDefault(); - double whitenoise = MinPastValues(i, 2, currentValue - prevValue) / 2; + var prevWhitenoise = whitenoiseList.LastOrDefault(); + var whitenoise = MinPastValues(i, 2, currentValue - prevValue) / 2; whitenoiseList.AddRounded(whitenoise); - double prevFilt1 = filtList.LastOrDefault(); - double filt = (c1 * ((whitenoise + prevWhitenoise) / 2)) + (c2 * prevFilt1) + (c3 * prevFilt2); + var prevFilt1 = filtList.LastOrDefault(); + var filt = (c1 * ((whitenoise + prevWhitenoise) / 2)) + (c2 * prevFilt1) + (c3 * prevFilt2); filtList.AddRounded(filt); - double prevPk = pkList.LastOrDefault(); - double pk = Math.Abs(filt) > prevPk ? Math.Abs(filt) : 0.991 * prevPk; + var prevPk = pkList.LastOrDefault(); + var pk = Math.Abs(filt) > prevPk ? Math.Abs(filt) : 0.991 * prevPk; pkList.AddRounded(pk); - double denom = pk == 0 ? -1 : pk; - double prevEuo = euoList.LastOrDefault(); - double euo = denom == -1 ? prevEuo : pk != 0 ? filt / pk : 0; + var denom = pk == 0 ? -1 : pk; + var prevEuo = euoList.LastOrDefault(); + var euo = denom == -1 ? prevEuo : pk != 0 ? filt / pk : 0; euoList.AddRounded(euo); } var euoMaList = GetMovingAverageList(stockData, maType, signalLength, euoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double euo = euoList[i]; - double euoMa = euoMaList[i]; - double prevEuo = i >= 1 ? euoList[i - 1] : 0; - double prevEuoMa = i >= 1 ? euoMaList[i - 1] : 0; + var euo = euoList[i]; + var euoMa = euoMaList[i]; + var prevEuo = i >= 1 ? euoList[i - 1] : 0; + var prevEuoMa = i >= 1 ? euoMaList[i - 1] : 0; var signal = GetCompareSignal(euo - euoMa, prevEuo - prevEuoMa); signalsList.Add(signal); @@ -5284,34 +5284,34 @@ public static StockData CalculateEhlersDetrendedLeadingIndicator(this StockData List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - double alpha = length > 2 ? (double)2 / (length + 1) : 0.67; - double alpha2 = alpha / 2; + var alpha = length > 2 ? (double)2 / (length + 1) : 0.67; + var alpha2 = alpha / 2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double currentHigh = Math.Max(prevHigh, highList[i]); - double currentLow = Math.Min(prevLow, lowList[i]); - double currentPrice = (currentHigh + currentLow) / 2; - double prevEma1 = i >= 1 ? ema1List.LastOrDefault() : currentPrice; - double prevEma2 = i >= 1 ? ema2List.LastOrDefault() : currentPrice; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var currentHigh = Math.Max(prevHigh, highList[i]); + var currentLow = Math.Min(prevLow, lowList[i]); + var currentPrice = (currentHigh + currentLow) / 2; + var prevEma1 = i >= 1 ? ema1List.LastOrDefault() : currentPrice; + var prevEma2 = i >= 1 ? ema2List.LastOrDefault() : currentPrice; - double ema1 = (alpha * currentPrice) + ((1 - alpha) * prevEma1); + var ema1 = (alpha * currentPrice) + ((1 - alpha) * prevEma1); ema1List.AddRounded(ema1); - double ema2 = (alpha2 * currentPrice) + ((1 - alpha2) * prevEma2); + var ema2 = (alpha2 * currentPrice) + ((1 - alpha2) * prevEma2); ema2List.AddRounded(ema2); - double dsp = ema1 - ema2; + var dsp = ema1 - ema2; dspList.AddRounded(dsp); - double prevTemp = tempList.LastOrDefault(); - double temp = (alpha * dsp) + ((1 - alpha) * prevTemp); + var prevTemp = tempList.LastOrDefault(); + var temp = (alpha * dsp) + ((1 - alpha) * prevTemp); tempList.AddRounded(temp); - double prevDeli = deliList.LastOrDefault(); - double deli = dsp - temp; + var prevDeli = deliList.LastOrDefault(); + var deli = dsp - temp; deliList.AddRounded(deli); var signal = GetCompareSignal(deli, prevDeli); @@ -5347,39 +5347,39 @@ public static StockData CalculateEhlersBandPassFilterV1(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double twoPiPrd1 = MinOrMax(0.25 * bw * 2 * Math.PI / length, 0.99, 0.01); - double twoPiPrd2 = MinOrMax(1.5 * bw * 2 * Math.PI / length, 0.99, 0.01); - double beta = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); - double gamma = 1 / Math.Cos(MinOrMax(2 * Math.PI * bw / length, 0.99, 0.01)); - double alpha1 = gamma - Sqrt(Pow(gamma, 2) - 1); - double alpha2 = (Math.Cos(twoPiPrd1) + Math.Sin(twoPiPrd1) - 1) / Math.Cos(twoPiPrd1); - double alpha3 = (Math.Cos(twoPiPrd2) + Math.Sin(twoPiPrd2) - 1) / Math.Cos(twoPiPrd2); + var twoPiPrd1 = MinOrMax(0.25 * bw * 2 * Math.PI / length, 0.99, 0.01); + var twoPiPrd2 = MinOrMax(1.5 * bw * 2 * Math.PI / length, 0.99, 0.01); + var beta = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); + var gamma = 1 / Math.Cos(MinOrMax(2 * Math.PI * bw / length, 0.99, 0.01)); + var alpha1 = gamma - Sqrt(Pow(gamma, 2) - 1); + var alpha2 = (Math.Cos(twoPiPrd1) + Math.Sin(twoPiPrd1) - 1) / Math.Cos(twoPiPrd1); + var alpha3 = (Math.Cos(twoPiPrd2) + Math.Sin(twoPiPrd2) - 1) / Math.Cos(twoPiPrd2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double hp = ((1 + (alpha2 / 2)) * MinPastValues(i, 1, currentValue - prevValue)) + ((1 - alpha2) * prevHp1); + var hp = ((1 + (alpha2 / 2)) * MinPastValues(i, 1, currentValue - prevValue)) + ((1 - alpha2) * prevHp1); hpList.AddRounded(hp); - double bp = i > 2 ? (0.5 * (1 - alpha1) * (hp - prevHp2)) + (beta * (1 + alpha1) * prevBp1) - (alpha1 * prevBp2) : 0; + var bp = i > 2 ? (0.5 * (1 - alpha1) * (hp - prevHp2)) + (beta * (1 + alpha1) * prevBp1) - (alpha1 * prevBp2) : 0; bpList.AddRounded(bp); - double prevPeak = peakList.LastOrDefault(); - double peak = Math.Max(0.991 * prevPeak, Math.Abs(bp)); + var prevPeak = peakList.LastOrDefault(); + var peak = Math.Max(0.991 * prevPeak, Math.Abs(bp)); peakList.AddRounded(peak); - double prevSig = signalList.LastOrDefault(); - double sig = peak != 0 ? bp / peak : 0; + var prevSig = signalList.LastOrDefault(); + var sig = peak != 0 ? bp / peak : 0; signalList.AddRounded(sig); - double prevTrigger = triggerList.LastOrDefault(); - double trigger = ((1 + (alpha3 / 2)) * (sig - prevSig)) + ((1 - alpha3) * prevTrigger); + var prevTrigger = triggerList.LastOrDefault(); + var trigger = ((1 + (alpha3 / 2)) * (sig - prevSig)) + ((1 - alpha3) * prevTrigger); triggerList.AddRounded(trigger); var signal = GetCompareSignal(sig - trigger, prevSig - prevTrigger); @@ -5411,18 +5411,18 @@ public static StockData CalculateEhlersBandPassFilterV2(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double l1 = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); - double g1 = Math.Cos(MinOrMax(bw * 2 * Math.PI / length, 0.99, 0.01)); - double s1 = (1 / g1) - Sqrt(1 / Pow(g1, 2) - 1); + var l1 = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); + var g1 = Math.Cos(MinOrMax(bw * 2 * Math.PI / length, 0.99, 0.01)); + var s1 = (1 / g1) - Sqrt(1 / Pow(g1, 2) - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double bp = i < 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); + var bp = i < 3 ? 0 : (0.5 * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); bpList.AddRounded(bp); var signal = GetCompareSignal(bp - prevBp1, prevBp1 - prevBp2); @@ -5453,18 +5453,18 @@ public static StockData CalculateEhlersCycleBandPassFilter(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double beta = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); - double gamma = 1 / Math.Cos(MinOrMax(4 * Math.PI * delta / length, 0.99, 0.01)); - double alpha = gamma - Sqrt(Pow(gamma, 2) - 1); + var beta = Math.Cos(MinOrMax(2 * Math.PI / length, 0.99, 0.01)); + var gamma = 1 / Math.Cos(MinOrMax(4 * Math.PI * delta / length, 0.99, 0.01)); + var alpha = gamma - Sqrt(Pow(gamma, 2) - 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double bp = (0.5 * (1 - alpha) * MinPastValues(i, 2, currentValue - prevValue)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); + var bp = (0.5 * (1 - alpha) * MinPastValues(i, 2, currentValue - prevValue)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); bpList.AddRounded(bp); var signal = GetCompareSignal(bp - prevBp1, prevBp1 - prevBp2); @@ -5494,24 +5494,24 @@ public static StockData CalculateEhlersCycleAmplitude(this StockData stockData, List ptopList = new(); List signalsList = new(); - int lbLength = (int)Math.Ceiling((double)length / 4); + var lbLength = (int)Math.Ceiling((double)length / 4); var bpList = CalculateEhlersCycleBandPassFilter(stockData, length, delta).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevPtop1 = i >= 1 ? ptopList[i - 1] : 0; - double prevPtop2 = i >= 2 ? ptopList[i - 2] : 0; + var prevPtop1 = i >= 1 ? ptopList[i - 1] : 0; + var prevPtop2 = i >= 2 ? ptopList[i - 2] : 0; double power = 0; - for (int j = length; j < length; j++) + for (var j = length; j < length; j++) { - double prevBp1 = i >= j ? bpList[i - j] : 0; - double prevBp2 = i >= j + lbLength ? bpList[i - (j + lbLength)] : 0; + var prevBp1 = i >= j ? bpList[i - j] : 0; + var prevBp2 = i >= j + lbLength ? bpList[i - (j + lbLength)] : 0; power += Pow(prevBp1, 2) + Pow(prevBp2, 2); } - double ptop = 2 * 1.414 * Sqrt(power / length); + var ptop = 2 * 1.414 * Sqrt(power / length); ptopList.AddRounded(ptop); var signal = GetCompareSignal(ptop - prevPtop1, prevPtop1 - prevPtop2); @@ -5541,21 +5541,21 @@ public static StockData CalculateEhlersZeroCrossingsDominantCycle(this StockData List dcList = new(); List signalsList = new(); - int counter = 0; + var counter = 0; var ebpfList = CalculateEhlersBandPassFilterV1(stockData, length, bw); var realList = ebpfList.OutputValues["Ebpf"]; var triggerList = ebpfList.OutputValues["Signal"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double real = realList[i]; - double trigger = triggerList[i]; - double prevReal = i >= 1 ? realList[i - 1] : 0; - double prevTrigger = i >= 1 ? triggerList[i - 1] : 0; + var real = realList[i]; + var trigger = triggerList[i]; + var prevReal = i >= 1 ? realList[i - 1] : 0; + var prevTrigger = i >= 1 ? triggerList[i - 1] : 0; - double prevDc = dcList.LastOrDefault(); - double dc = Math.Max(prevDc, 6); + var prevDc = dcList.LastOrDefault(); + var dc = Math.Max(prevDc, 6); counter += 1; if ((real > 0 && prevReal <= 0) || (real < 0 && prevReal >= 0)) { @@ -5600,37 +5600,37 @@ public static StockData CalculateEhlersAdaptiveBandPassFilter(this StockData sto var domCycList = CalculateEhlersAutoCorrelationPeriodogram(stockData, length1, length2, length3).CustomValuesList; var roofingFilterList = CalculateEhlersRoofingFilterV2(stockData, length1, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double roofingFilter = roofingFilterList[i]; - double domCyc = MinOrMax(domCycList[i], length1, length3); - double beta = Math.Cos(2 * Math.PI / 0.9 * domCyc); - double gamma = 1 / Math.Cos(2 * Math.PI * bw / 0.9 * domCyc); - double alpha = MinOrMax(gamma - Sqrt((gamma * gamma) - 1), 0.99, 0.01); - double prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - double prevBp1 = i >= 1 ? bpList[i - 1] : 0; - double prevBp2 = i >= 2 ? bpList[i - 2] : 0; - double prevSignal1 = i >= 1 ? signalList[i - 1] : 0; - double prevSignal2 = i >= 2 ? signalList[i - 2] : 0; - double prevSignal3 = i >= 3 ? signalList[i - 3] : 0; - - double bp = i > 2 ? (0.5 * (1 - alpha) * (roofingFilter - prevRoofingFilter2)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var roofingFilter = roofingFilterList[i]; + var domCyc = MinOrMax(domCycList[i], length1, length3); + var beta = Math.Cos(2 * Math.PI / 0.9 * domCyc); + var gamma = 1 / Math.Cos(2 * Math.PI * bw / 0.9 * domCyc); + var alpha = MinOrMax(gamma - Sqrt((gamma * gamma) - 1), 0.99, 0.01); + var prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + var prevBp1 = i >= 1 ? bpList[i - 1] : 0; + var prevBp2 = i >= 2 ? bpList[i - 2] : 0; + var prevSignal1 = i >= 1 ? signalList[i - 1] : 0; + var prevSignal2 = i >= 2 ? signalList[i - 2] : 0; + var prevSignal3 = i >= 3 ? signalList[i - 3] : 0; + + var bp = i > 2 ? (0.5 * (1 - alpha) * (roofingFilter - prevRoofingFilter2)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2) : 0; bpList.AddRounded(bp); - double prevPeak = peakList.LastOrDefault(); - double peak = Math.Max(0.991 * prevPeak, Math.Abs(bp)); + var prevPeak = peakList.LastOrDefault(); + var peak = Math.Max(0.991 * prevPeak, Math.Abs(bp)); peakList.AddRounded(peak); - double sig = peak != 0 ? bp / peak : 0; + var sig = peak != 0 ? bp / peak : 0; signalList.AddRounded(sig); - double lead = 1.3 * (sig + prevSignal1 - prevSignal2 - prevSignal3) / 4; - double prevLeadPeak = leadPeakList.LastOrDefault(); - double leadPeak = Math.Max(0.93 * prevLeadPeak, Math.Abs(lead)); + var lead = 1.3 * (sig + prevSignal1 - prevSignal2 - prevSignal3) / 4; + var prevLeadPeak = leadPeakList.LastOrDefault(); + var leadPeak = Math.Max(0.93 * prevLeadPeak, Math.Abs(lead)); leadPeakList.AddRounded(leadPeak); - double prevTrigger = triggerList.LastOrDefault(); - double trigger = 0.9 * prevSignal1; + var prevTrigger = triggerList.LastOrDefault(); + var trigger = 0.9 * prevSignal1; triggerList.AddRounded(trigger); var signal = GetRsiSignal(sig - trigger, prevSignal1 - prevTrigger, sig, prevSignal1, 0.707, -0.707); @@ -5662,21 +5662,21 @@ public static StockData CalculateEhlersCyberCycle(this StockData stockData, doub List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; - double prevSmooth1 = i >= 1 ? smoothList[i - 1] : 0; - double prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; - double prevCycle1 = i >= 1 ? cycleList[i - 1] : 0; - double prevCycle2 = i >= 2 ? cycleList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var prevSmooth1 = i >= 1 ? smoothList[i - 1] : 0; + var prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + var prevCycle1 = i >= 1 ? cycleList[i - 1] : 0; + var prevCycle2 = i >= 2 ? cycleList[i - 2] : 0; - double smooth = (currentValue + (2 * prevValue1) + (2 * prevValue2) + prevValue3) / 6; + var smooth = (currentValue + (2 * prevValue1) + (2 * prevValue2) + prevValue3) / 6; smoothList.AddRounded(smooth); - double cycle = i < 7 ? (currentValue - (2 * prevValue1) + prevValue2) / 4 : (Pow(1 - (0.5 * alpha), 2) * (smooth - (2 * prevSmooth1) + prevSmooth2)) + + var cycle = i < 7 ? (currentValue - (2 * prevValue1) + prevValue2) / 4 : (Pow(1 - (0.5 * alpha), 2) * (smooth - (2 * prevSmooth1) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle1) - (Pow(1 - alpha, 2) * prevCycle2); cycleList.AddRounded(cycle); @@ -5712,24 +5712,24 @@ public static StockData CalculateEhlersStochasticCyberCycle(this StockData stock var cyberCycleList = CalculateEhlersCyberCycle(stockData, alpha).CustomValuesList; var (maxCycleList, minCycleList) = GetMaxAndMinValuesList(cyberCycleList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevStoch1 = i >= 1 ? stochList[i - 1] : 0; - double prevStoch2 = i >= 2 ? stochList[i - 2] : 0; - double prevStoch3 = i >= 3 ? stochList[i - 3] : 0; - double cycle = cyberCycleList[i]; - double maxCycle = maxCycleList[i]; - double minCycle = minCycleList[i]; + var prevStoch1 = i >= 1 ? stochList[i - 1] : 0; + var prevStoch2 = i >= 2 ? stochList[i - 2] : 0; + var prevStoch3 = i >= 3 ? stochList[i - 3] : 0; + var cycle = cyberCycleList[i]; + var maxCycle = maxCycleList[i]; + var minCycle = minCycleList[i]; - double stoch = maxCycle - minCycle != 0 ? MinOrMax((cycle - minCycle) / (maxCycle - minCycle), 1, 0) : 0; + var stoch = maxCycle - minCycle != 0 ? MinOrMax((cycle - minCycle) / (maxCycle - minCycle), 1, 0) : 0; stochList.AddRounded(stoch); - double prevStochCC = stochCCList.LastOrDefault(); - double stochCC = MinOrMax(2 * ((((4 * stoch) + (3 * prevStoch1) + (2 * prevStoch2) + prevStoch3) / 10) - 0.5), 1, -1); + var prevStochCC = stochCCList.LastOrDefault(); + var stochCC = MinOrMax(2 * ((((4 * stoch) + (3 * prevStoch1) + (2 * prevStoch2) + prevStoch3) / 10) - 0.5), 1, -1); stochCCList.AddRounded(stochCC); - double prevTrigger = triggerList.LastOrDefault(); - double trigger = MinOrMax(0.96 * (prevStochCC + 0.02), 1, -1); + var prevTrigger = triggerList.LastOrDefault(); + var trigger = MinOrMax(0.96 * (prevStochCC + 0.02), 1, -1); triggerList.AddRounded(trigger); var signal = GetRsiSignal(stochCC - trigger, prevStochCC - prevTrigger, stochCC, prevStochCC, 0.5, -0.5); @@ -5763,22 +5763,22 @@ public static StockData CalculateEhlersFMDemodulatorIndicator(this StockData sto List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double der = currentClose - currentOpen; - double hlRaw = fastLength * der; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var der = currentClose - currentOpen; + var hlRaw = fastLength * der; - double hl = MinOrMax(hlRaw, 1, -1); + var hl = MinOrMax(hlRaw, 1, -1); hlList.AddRounded(hl); } var ssList = GetMovingAverageList(stockData, maType, slowLength, hlList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ss = ssList[i]; - double prevSs = i >= 1 ? ssList[i - 1] : 0; + var ss = ssList[i]; + var prevSs = i >= 1 ? ssList[i - 1] : 0; var signal = GetCompareSignal(ss, prevSs); signalsList.Add(signal); @@ -5814,26 +5814,26 @@ public static StockData CalculateEhlersStochastic(this StockData stockData, Movi var roofingFilter2PoleList = CalculateEhlersRoofingFilterV1(stockData, maType, length1, length3).CustomValuesList; var (max2PoleList, min2PoleList) = GetMaxAndMinValuesList(roofingFilter2PoleList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rf2Pole = roofingFilter2PoleList[i]; - double min2Pole = min2PoleList[i]; - double max2Pole = max2PoleList[i]; + var rf2Pole = roofingFilter2PoleList[i]; + var min2Pole = min2PoleList[i]; + var max2Pole = max2PoleList[i]; - double prevStoch2Pole = stoch2PoleList.LastOrDefault(); - double stoch2Pole = max2Pole - min2Pole != 0 ? MinOrMax((rf2Pole - min2Pole) / (max2Pole - min2Pole), 1, 0) : 0; + var prevStoch2Pole = stoch2PoleList.LastOrDefault(); + var stoch2Pole = max2Pole - min2Pole != 0 ? MinOrMax((rf2Pole - min2Pole) / (max2Pole - min2Pole), 1, 0) : 0; stoch2PoleList.AddRounded(stoch2Pole); - double arg2Pole = (stoch2Pole + prevStoch2Pole) / 2; + var arg2Pole = (stoch2Pole + prevStoch2Pole) / 2; arg2PoleList.AddRounded(arg2Pole); } var estoch2PoleList = GetMovingAverageList(stockData, maType, length2, arg2PoleList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double estoch2Pole = estoch2PoleList[i]; - double prevEstoch2Pole1 = i >= 1 ? estoch2PoleList[i - 1] : 0; - double prevEstoch2Pole2 = i >= 2 ? estoch2PoleList[i - 2] : 0; + var estoch2Pole = estoch2PoleList[i]; + var prevEstoch2Pole1 = i >= 1 ? estoch2PoleList[i - 1] : 0; + var prevEstoch2Pole2 = i >= 2 ? estoch2PoleList[i - 2] : 0; var signal = GetRsiSignal(estoch2Pole - prevEstoch2Pole1, prevEstoch2Pole1 - prevEstoch2Pole2, estoch2Pole, prevEstoch2Pole1, 0.8, 0.2); signalsList.Add(signal); @@ -5867,32 +5867,32 @@ public static StockData CalculateEhlersTripleDelayLineDetrender(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevTmp1_6 = i >= 6 ? tmp1List[i - 6] : 0; - double prevTmp2_6 = i >= 6 ? tmp2List[i - 6] : 0; - double prevTmp2_12 = i >= 12 ? tmp2List[i - 12] : 0; + var currentValue = inputList[i]; + var prevTmp1_6 = i >= 6 ? tmp1List[i - 6] : 0; + var prevTmp2_6 = i >= 6 ? tmp2List[i - 6] : 0; + var prevTmp2_12 = i >= 12 ? tmp2List[i - 12] : 0; - double tmp1 = currentValue + (0.088 * prevTmp1_6); + var tmp1 = currentValue + (0.088 * prevTmp1_6); tmp1List.AddRounded(tmp1); - double tmp2 = tmp1 - prevTmp1_6 + (1.2 * prevTmp2_6) - (0.7 * prevTmp2_12); + var tmp2 = tmp1 - prevTmp1_6 + (1.2 * prevTmp2_6) - (0.7 * prevTmp2_12); tmp2List.AddRounded(tmp2); - double detrender = prevTmp2_12 - (2 * prevTmp2_6) + tmp2; + var detrender = prevTmp2_12 - (2 * prevTmp2_6) + tmp2; detrenderList.AddRounded(detrender); } var tdldList = GetMovingAverageList(stockData, maType, length, detrenderList); var tdldSignalList = GetMovingAverageList(stockData, maType, length, tdldList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tdld = tdldList[i]; - double tdldSignal = tdldSignalList[i]; + var tdld = tdldList[i]; + var tdldSignal = tdldSignalList[i]; - double prevHist = histList.LastOrDefault(); - double hist = tdld - tdldSignal; + var prevHist = histList.LastOrDefault(); + var hist = tdld - tdldSignal; histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); @@ -5929,29 +5929,29 @@ public static StockData CalculateEhlersAMDetector(this StockData stockData, Movi var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double der = currentClose - currentOpen; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var der = currentClose - currentOpen; - double absDer = Math.Abs(der); + var absDer = Math.Abs(der); absDerList.AddRounded(absDer); - double env = absDerList.TakeLastExt(length1).Max(); + var env = absDerList.TakeLastExt(length1).Max(); envList.AddRounded(env); } var volList = GetMovingAverageList(stockData, maType, length2, envList); var volEmaList = GetMovingAverageList(stockData, maType, length2, volList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vol = volList[i]; - double volEma = volEmaList[i]; - double ema = emaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var vol = volList[i]; + var volEma = volEmaList[i]; + var ema = emaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, vol, volEma); signalsList.Add(signal); @@ -5985,32 +5985,32 @@ public static StockData CalculateEhlersSineWaveIndicatorV1(this StockData stockD var spList = ehlersMamaList.OutputValues["SmoothPeriod"]; var smoothList = ehlersMamaList.OutputValues["Smooth"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sp = spList[i]; - int dcPeriod = (int)Math.Ceiling(sp + 0.5); + var sp = spList[i]; + var dcPeriod = (int)Math.Ceiling(sp + 0.5); double realPart = 0, imagPart = 0; - for (int j = 0; j <= dcPeriod - 1; j++) + for (var j = 0; j <= dcPeriod - 1; j++) { - double prevSmooth = i >= j ? smoothList[i - j] : 0; + var prevSmooth = i >= j ? smoothList[i - j] : 0; realPart += Math.Sin(MinOrMax(2 * Math.PI * ((double)j / dcPeriod), 0.99, 0.01)) * prevSmooth; imagPart += Math.Cos(MinOrMax(2 * Math.PI * ((double)j / dcPeriod), 0.99, 0.01)) * prevSmooth; } - double dcPhase = Math.Abs(imagPart) > 0.001 ? Math.Atan(realPart / imagPart).ToDegrees() : 90 * Math.Sign(realPart); + var dcPhase = Math.Abs(imagPart) > 0.001 ? Math.Atan(realPart / imagPart).ToDegrees() : 90 * Math.Sign(realPart); dcPhase += 90; dcPhase += sp != 0 ? 360 / sp : 0; dcPhase += imagPart < 0 ? 180 : 0; dcPhase -= dcPhase > 315 ? 360 : 0; dcPhaseList.AddRounded(dcPhase); - double prevSine = sineList.LastOrDefault(); - double sine = Math.Sin(dcPhase.ToRadians()); + var prevSine = sineList.LastOrDefault(); + var sine = Math.Sin(dcPhase.ToRadians()); sineList.AddRounded(sine); - double prevLeadSine = leadSineList.LastOrDefault(); - double leadSine = Math.Sin((dcPhase + 45).ToRadians()); + var prevLeadSine = leadSineList.LastOrDefault(); + var leadSine = Math.Sin((dcPhase + 45).ToRadians()); leadSineList.AddRounded(leadSine); var signal = GetCompareSignal(sine - leadSine, prevSine - prevLeadSine); @@ -6046,31 +6046,31 @@ public static StockData CalculateEhlersSineWaveIndicatorV2(this StockData stockD var periodList = CalculateEhlersAdaptiveCyberCycle(stockData, length, alpha).OutputValues["Period"]; var cycleList = CalculateEhlersCyberCycle(stockData).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double period = periodList[i]; - int dcPeriod = (int)Math.Ceiling(period); + var period = periodList[i]; + var dcPeriod = (int)Math.Ceiling(period); double realPart = 0, imagPart = 0; - for (int j = 0; j <= dcPeriod - 1; j++) + for (var j = 0; j <= dcPeriod - 1; j++) { - double prevCycle = i >= j ? cycleList[i - j] : 0; + var prevCycle = i >= j ? cycleList[i - j] : 0; realPart += Math.Sin(MinOrMax(2 * Math.PI * ((double)j / dcPeriod), 0.99, 0.01)) * prevCycle; imagPart += Math.Cos(MinOrMax(2 * Math.PI * ((double)j / dcPeriod), 0.99, 0.01)) * prevCycle; } - double dcPhase = Math.Abs(imagPart) > 0.001 ? Math.Atan(realPart / imagPart).ToDegrees() : 90 * Math.Sign(realPart); + var dcPhase = Math.Abs(imagPart) > 0.001 ? Math.Atan(realPart / imagPart).ToDegrees() : 90 * Math.Sign(realPart); dcPhase += 90; dcPhase += imagPart < 0 ? 180 : 0; dcPhase -= dcPhase > 315 ? 360 : 0; dcPhaseList.AddRounded(dcPhase); - double prevSine = sineList.LastOrDefault(); - double sine = Math.Sin(dcPhase.ToRadians()); + var prevSine = sineList.LastOrDefault(); + var sine = Math.Sin(dcPhase.ToRadians()); sineList.AddRounded(sine); - double prevLeadSine = leadSineList.LastOrDefault(); - double leadSine = Math.Sin((dcPhase + 45).ToRadians()); + var prevLeadSine = leadSineList.LastOrDefault(); + var leadSine = Math.Sin((dcPhase + 45).ToRadians()); leadSineList.AddRounded(leadSine); var signal = GetCompareSignal(sine - leadSine, prevSine - prevLeadSine); @@ -6104,32 +6104,32 @@ public static StockData CalculateEhlersEvenBetterSineWaveIndicator(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double piHp = MinOrMax(2 * Math.PI / length1, 0.99, 0.01); - double a1 = (1 - Math.Sin(piHp)) / Math.Cos(piHp); - double a2 = Exp(MinOrMax(-1.414 * Math.PI / length2, -0.01, -0.99)); - double b = 2 * a2 * Math.Cos(MinOrMax(1.414 * Math.PI / length2, 0.99, 0.01)); - double c2 = b; - double c3 = -a2 * a2; - double c1 = 1 - c2 - c3; + var piHp = MinOrMax(2 * Math.PI / length1, 0.99, 0.01); + var a1 = (1 - Math.Sin(piHp)) / Math.Cos(piHp); + var a2 = Exp(MinOrMax(-1.414 * Math.PI / length2, -0.01, -0.99)); + var b = 2 * a2 * Math.Cos(MinOrMax(1.414 * Math.PI / length2, 0.99, 0.01)); + var c2 = b; + var c3 = -a2 * a2; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilt1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilt2 = i >= 2 ? filtList[i - 2] : 0; - double prevHp = hpList.LastOrDefault(); - double hp = ((0.5 * (1 + a1)) * MinPastValues(i, 1, currentValue - prevValue)) + (a1 * prevHp); + var prevHp = hpList.LastOrDefault(); + var hp = ((0.5 * (1 + a1)) * MinPastValues(i, 1, currentValue - prevValue)) + (a1 * prevHp); hpList.AddRounded(hp); - double filt = (c1 * ((hp + prevHp) / 2)) + (c2 * prevFilt1) + (c3 * prevFilt2); + var filt = (c1 * ((hp + prevHp) / 2)) + (c2 * prevFilt1) + (c3 * prevFilt2); filtList.AddRounded(filt); - double wave = (filt + prevFilt1 + prevFilt2) / 3; - double pwr = (Pow(filt, 2) + Pow(prevFilt1, 2) + Pow(prevFilt2, 2)) / 3; - double prevEbsi = ebsiList.LastOrDefault(); - double ebsi = pwr > 0 ? wave / Sqrt(pwr) : 0; + var wave = (filt + prevFilt1 + prevFilt2) / 3; + var pwr = (Pow(filt, 2) + Pow(prevFilt1, 2) + Pow(prevFilt2, 2)) / 3; + var prevEbsi = ebsiList.LastOrDefault(); + var ebsi = pwr > 0 ? wave / Sqrt(pwr) : 0; ebsiList.AddRounded(ebsi); var signal = GetCompareSignal(ebsi, prevEbsi); @@ -6164,37 +6164,37 @@ public static StockData CalculateEhlersConvolutionIndicator(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double piPrd = 0.707 * 2 * Math.PI / length1; - double alpha = (Math.Cos(piPrd) + Math.Sin(piPrd) - 1) / Math.Cos(piPrd); - double a1 = Exp(-1.414 * Math.PI / length2); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevHp1 = i >= 1 ? hpList[i - 1] : 0; - double prevHp2 = i >= 2 ? hpList[i - 2] : 0; - double prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; - double prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; - - double highPass = (Pow(1 - (alpha / 2), 2) * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - alpha) * prevHp1) - - (Pow(1 - alpha, 2) * prevHp2); + var piPrd = 0.707 * 2 * Math.PI / length1; + var alpha = (Math.Cos(piPrd) + Math.Sin(piPrd) - 1) / Math.Cos(piPrd); + var a1 = Exp(-1.414 * Math.PI / length2); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI / length2); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevHp1 = i >= 1 ? hpList[i - 1] : 0; + var prevHp2 = i >= 2 ? hpList[i - 2] : 0; + var prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + var prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + + var highPass = (Pow(1 - (alpha / 2), 2) * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - alpha) * prevHp1) - + (Pow(1 - alpha, 2) * prevHp2); hpList.AddRounded(highPass); - double roofingFilter = (c1 * ((highPass + prevHp1) / 2)) + (c2 * prevRoofingFilter1) + (c3 * prevRoofingFilter2); + var roofingFilter = (c1 * ((highPass + prevHp1) / 2)) + (c2 * prevRoofingFilter1) + (c3 * prevRoofingFilter2); roofingFilterList.AddRounded(roofingFilter); - int n = i + 1; + var n = i + 1; double sx = 0, sy = 0, sxx = 0, syy = 0, sxy = 0, corr = 0, conv = 0, slope = 0; - for (int j = 1; j <= length3; j++) + for (var j = 1; j <= length3; j++) { - double x = i >= j - 1 ? roofingFilterList[i - (j - 1)] : 0; - double y = i >= j ? roofingFilterList[i - j] : 0; + var x = i >= j - 1 ? roofingFilterList[i - (j - 1)] : 0; + var y = i >= j ? roofingFilterList[i - j] : 0; sx += x; sy += y; sxx += Pow(x, 2); @@ -6204,8 +6204,8 @@ public static StockData CalculateEhlersConvolutionIndicator(this StockData stock Sqrt(((n * sxx) - (sx * sx)) * ((n * syy) - (sy * sy))) : 0; conv = (1 + (Exp(3 * corr) - 1)) / (Exp(3 * corr) + 1) / 2; - int filtLength = (int)Math.Ceiling(0.5 * n); - double prevFilt = i >= filtLength ? roofingFilterList[i - filtLength] : 0; + var filtLength = (int)Math.Ceiling(0.5 * n); + var prevFilt = i >= filtLength ? roofingFilterList[i - filtLength] : 0; slope = prevFilt < roofingFilter ? -1 : 1; } convList.AddRounded(conv); @@ -6241,20 +6241,20 @@ public static StockData CalculateEhlersFisherTransform(this StockData stockData, var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (maxList, minList) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double maxH = maxList[i]; - double minL = minList[i]; - double ratio = maxH - minL != 0 ? (currentValue - minL) / (maxH - minL) : 0; - double prevFisherTransform1 = i >= 1 ? fisherTransformList[i - 1] : 0; - double prevFisherTransform2 = i >= 2 ? fisherTransformList[i - 2] : 0; + var currentValue = inputList[i]; + var maxH = maxList[i]; + var minL = minList[i]; + var ratio = maxH - minL != 0 ? (currentValue - minL) / (maxH - minL) : 0; + var prevFisherTransform1 = i >= 1 ? fisherTransformList[i - 1] : 0; + var prevFisherTransform2 = i >= 2 ? fisherTransformList[i - 2] : 0; - double prevNValue = nValueList.LastOrDefault(); - double nValue = MinOrMax((0.33 * 2 * (ratio - 0.5)) + (0.67 * prevNValue), 0.999, -0.999); + var prevNValue = nValueList.LastOrDefault(); + var nValue = MinOrMax((0.33 * 2 * (ratio - 0.5)) + (0.67 * prevNValue), 0.999, -0.999); nValueList.AddRounded(nValue); - double fisherTransform = (0.5 * Math.Log((1 + nValue) / (1 - nValue))) + (0.5 * prevFisherTransform1); + var fisherTransform = (0.5 * Math.Log((1 + nValue) / (1 - nValue))) + (0.5 * prevFisherTransform1); fisherTransformList.AddRounded(fisherTransform); var signal = GetCompareSignal(fisherTransform - prevFisherTransform1, prevFisherTransform1 - prevFisherTransform2); @@ -6289,23 +6289,23 @@ public static StockData CalculateEhlersInverseFisherTransform(this StockData sto var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length: length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRsi = rsiList[i]; + var currentRsi = rsiList[i]; - double v1 = 0.1 * (currentRsi - 50); + var v1 = 0.1 * (currentRsi - 50); v1List.AddRounded(v1); } var v2List = GetMovingAverageList(stockData, maType, length2, v1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double v2 = v2List[i]; - double prevIft1 = i >= 1 ? inverseFisherTransformList[i - 1] : 0; - double prevIft2 = i >= 2 ? inverseFisherTransformList[i - 2] : 0; - double bottom = Exp(2 * v2) + 1; + var v2 = v2List[i]; + var prevIft1 = i >= 1 ? inverseFisherTransformList[i - 1] : 0; + var prevIft2 = i >= 2 ? inverseFisherTransformList[i - 2] : 0; + var bottom = Exp(2 * v2) + 1; - double inverseFisherTransform = bottom != 0 ? MinOrMax((Exp(2 * v2) - 1) / bottom, 1, -1) : 0; + var inverseFisherTransform = bottom != 0 ? MinOrMax((Exp(2 * v2) - 1) / bottom, 1, -1) : 0; inverseFisherTransformList.AddRounded(inverseFisherTransform); var signal = GetRsiSignal(inverseFisherTransform - prevIft1, prevIft1 - prevIft2, inverseFisherTransform, prevIft1, 0.5, -0.5); @@ -6336,20 +6336,20 @@ public static StockData CalculateEhlersInstantaneousTrendlineV2(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevIt1 = i >= 1 ? itList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevIt2 = i >= 2 ? itList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevIt1 = i >= 1 ? itList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevIt2 = i >= 2 ? itList[i - 2] : 0; - double it = i < 7 ? (currentValue + (2 * prevValue1) + prevValue2) / 4 : ((alpha - (Pow(alpha, 2) / 4)) * currentValue) + + var it = i < 7 ? (currentValue + (2 * prevValue1) + prevValue2) / 4 : ((alpha - (Pow(alpha, 2) / 4)) * currentValue) + (0.5 * Pow(alpha, 2) * prevValue1) - ((alpha - (0.75 * Pow(alpha, 2))) * prevValue2) + (2 * (1 - alpha) * prevIt1) - (Pow(1 - alpha, 2) * prevIt2); itList.AddRounded(it); - double prevLag = lagList.LastOrDefault(); - double lag = (2 * it) - prevIt2; + var prevLag = lagList.LastOrDefault(); + var lag = (2 * it) - prevIt2; lagList.AddRounded(lag); var signal = GetCompareSignal(lag - it, prevLag - prevIt1); @@ -6382,28 +6382,28 @@ public static StockData CalculateEhlersInstantaneousTrendlineV1(this StockData s var spList = CalculateEhlersMotherOfAdaptiveMovingAverages(stockData).OutputValues["SmoothPeriod"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sp = spList[i]; - double currentValue = inputList[i]; - double prevIt1 = i >= 1 ? itList[i - 1] : 0; - double prevIt2 = i >= 2 ? itList[i - 2] : 0; - double prevIt3 = i >= 3 ? itList[i - 3] : 0; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var sp = spList[i]; + var currentValue = inputList[i]; + var prevIt1 = i >= 1 ? itList[i - 1] : 0; + var prevIt2 = i >= 2 ? itList[i - 2] : 0; + var prevIt3 = i >= 3 ? itList[i - 3] : 0; + var prevVal = i >= 1 ? inputList[i - 1] : 0; - int dcPeriod = (int)Math.Ceiling(sp + 0.5); + var dcPeriod = (int)Math.Ceiling(sp + 0.5); double iTrend = 0; - for (int j = 0; j <= dcPeriod - 1; j++) + for (var j = 0; j <= dcPeriod - 1; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; iTrend += prevValue; } iTrend = dcPeriod != 0 ? iTrend / dcPeriod : iTrend; itList.AddRounded(iTrend); - double prevTrendLine = trendLineList.LastOrDefault(); - double trendLine = ((4 * iTrend) + (3 * prevIt1) + (2 * prevIt2) + prevIt3) / 10; + var prevTrendLine = trendLineList.LastOrDefault(); + var trendLine = ((4 * iTrend) + (3 * prevIt1) + (2 * prevIt2) + prevIt3) / 10; trendLineList.AddRounded(trendLine); var signal = GetCompareSignal(currentValue - trendLine, prevVal - prevTrendLine); @@ -6440,35 +6440,35 @@ public static StockData CalculateEhlersLaguerreRelativeStrengthIndex(this StockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; - double prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; - double prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; - double prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; - double prevRsi1 = i >= 1 ? laguerreRsiList[i - 1] : 0; - double prevRsi2 = i >= 2 ? laguerreRsiList[i - 2] : 0; + var currentValue = inputList[i]; + var prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; + var prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; + var prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; + var prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; + var prevRsi1 = i >= 1 ? laguerreRsiList[i - 1] : 0; + var prevRsi2 = i >= 2 ? laguerreRsiList[i - 2] : 0; - double l0 = ((1 - gamma) * currentValue) + (gamma * prevL0); + var l0 = ((1 - gamma) * currentValue) + (gamma * prevL0); l0List.AddRounded(l0); - double l1 = (-1 * gamma * l0) + prevL0 + (gamma * prevL1); + var l1 = (-1 * gamma * l0) + prevL0 + (gamma * prevL1); l1List.AddRounded(l1); - double l2 = (-1 * gamma * l1) + prevL1 + (gamma * prevL2); + var l2 = (-1 * gamma * l1) + prevL1 + (gamma * prevL2); l2List.AddRounded(l2); - double l3 = (-1 * gamma * l2) + prevL2 + (gamma * prevL3); + var l3 = (-1 * gamma * l2) + prevL2 + (gamma * prevL3); l3List.AddRounded(l3); - double cu = (l0 >= l1 ? l0 - l1 : 0) + (l1 >= l2 ? l1 - l2 : 0) + (l2 >= l3 ? l2 - l3 : 0); + var cu = (l0 >= l1 ? l0 - l1 : 0) + (l1 >= l2 ? l1 - l2 : 0) + (l2 >= l3 ? l2 - l3 : 0); cuList.AddRounded(cu); - double cd = (l0 >= l1 ? 0 : l1 - l0) + (l1 >= l2 ? 0 : l2 - l1) + (l2 >= l3 ? 0 : l3 - l2); + var cd = (l0 >= l1 ? 0 : l1 - l0) + (l1 >= l2 ? 0 : l2 - l1) + (l2 >= l3 ? 0 : l3 - l2); cdList.AddRounded(cd); - double laguerreRsi = cu + cd != 0 ? MinOrMax(cu / (cu + cd), 1, 0) : 0; + var laguerreRsi = cu + cd != 0 ? MinOrMax(cu / (cu + cd), 1, 0) : 0; laguerreRsiList.AddRounded(laguerreRsi); var signal = GetRsiSignal(laguerreRsi - prevRsi1, prevRsi1 - prevRsi2, laguerreRsi, prevRsi1, 0.8, 0.2); @@ -6504,46 +6504,46 @@ public static StockData CalculateEhlersLaguerreRelativeStrengthIndexWithSelfAdju var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevRsi1 = i >= 1 ? laguerreRsiList[i - 1] : 0; - double prevRsi2 = i >= 2 ? laguerreRsiList[i - 2] : 0; - double oc = (currentOpen + prevValue) / 2; - double hc = Math.Max(currentHigh, prevValue); - double lc = Math.Min(currentLow, prevValue); - double feValue = (oc + hc + lc + currentValue) / 4; - - double ratio = highestHigh - lowestLow != 0 ? (hc - lc) / (highestHigh - lowestLow) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevRsi1 = i >= 1 ? laguerreRsiList[i - 1] : 0; + var prevRsi2 = i >= 2 ? laguerreRsiList[i - 2] : 0; + var oc = (currentOpen + prevValue) / 2; + var hc = Math.Max(currentHigh, prevValue); + var lc = Math.Min(currentLow, prevValue); + var feValue = (oc + hc + lc + currentValue) / 4; + + var ratio = highestHigh - lowestLow != 0 ? (hc - lc) / (highestHigh - lowestLow) : 0; ratioList.AddRounded(ratio); - double ratioSum = ratioList.TakeLastExt(length).Sum(); - double alpha = ratioSum > 0 ? MinOrMax(Math.Log(ratioSum) / Math.Log(length), 0.99, 0.01) : 0.01; - double prevL0 = l0List.LastOrDefault(); - double l0 = (alpha * feValue) + ((1 - alpha) * prevL0); + var ratioSum = ratioList.TakeLastExt(length).Sum(); + var alpha = ratioSum > 0 ? MinOrMax(Math.Log(ratioSum) / Math.Log(length), 0.99, 0.01) : 0.01; + var prevL0 = l0List.LastOrDefault(); + var l0 = (alpha * feValue) + ((1 - alpha) * prevL0); l0List.AddRounded(l0); - double prevL1 = l1List.LastOrDefault(); - double l1 = (-(1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); + var prevL1 = l1List.LastOrDefault(); + var l1 = (-(1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); l1List.AddRounded(l1); - double prevL2 = l2List.LastOrDefault(); - double l2 = (-(1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); + var prevL2 = l2List.LastOrDefault(); + var l2 = (-(1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); l2List.AddRounded(l2); - double prevL3 = l3List.LastOrDefault(); - double l3 = (-(1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); + var prevL3 = l3List.LastOrDefault(); + var l3 = (-(1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); l3List.AddRounded(l3); - double cu = (l0 >= l1 ? l0 - l1 : 0) + (l1 >= l2 ? l1 - l2 : 0) + (l2 >= l3 ? l2 - l3 : 0); - double cd = (l0 >= l1 ? 0 : l1 - l0) + (l1 >= l2 ? 0 : l2 - l1) + (l2 >= l3 ? 0 : l3 - l2); - double laguerreRsi = cu + cd != 0 ? MinOrMax(cu / (cu + cd), 1, 0) : 0; + var cu = (l0 >= l1 ? l0 - l1 : 0) + (l1 >= l2 ? l1 - l2 : 0) + (l2 >= l3 ? l2 - l3 : 0); + var cd = (l0 >= l1 ? 0 : l1 - l0) + (l1 >= l2 ? 0 : l2 - l1) + (l2 >= l3 ? 0 : l3 - l2); + var laguerreRsi = cu + cd != 0 ? MinOrMax(cu / (cu + cd), 1, 0) : 0; laguerreRsiList.AddRounded(laguerreRsi); var signal = GetRsiSignal(laguerreRsi - prevRsi1, prevRsi1 - prevRsi2, laguerreRsi, prevRsi1, 0.8, 0.2); @@ -6576,14 +6576,14 @@ public static StockData CalculateEhlersAdaptiveRelativeStrengthIndexV1(this Stoc var spList = CalculateEhlersMotherOfAdaptiveMovingAverages(stockData).OutputValues["SmoothPeriod"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sp = spList[i]; - double prevArsi1 = i >= 1 ? arsiEmaList[i - 1] : 0; - double prevArsi2 = i >= 2 ? arsiEmaList[i - 2] : 0; + var sp = spList[i]; + var prevArsi1 = i >= 1 ? arsiEmaList[i - 1] : 0; + var prevArsi2 = i >= 2 ? arsiEmaList[i - 2] : 0; double cu = 0, cd = 0; - for (int j = 0; j < (int)Math.Ceiling(cycPart * sp); j++) + for (var j = 0; j < (int)Math.Ceiling(cycPart * sp); j++) { var price = i >= j ? inputList[i - j] : 0; var pPrice = i >= j + 1 ? inputList[i - (j + 1)] : 0; @@ -6592,10 +6592,10 @@ public static StockData CalculateEhlersAdaptiveRelativeStrengthIndexV1(this Stoc cd += price - pPrice < 0 ? pPrice - price : 0; } - double arsi = cu + cd != 0 ? 100 * cu / (cu + cd) : 0; + var arsi = cu + cd != 0 ? 100 * cu / (cu + cd) : 0; arsiList.AddRounded(arsi); - double arsiEma = CalculateEMA(arsi, prevArsi1, (int)Math.Ceiling(sp)); + var arsiEma = CalculateEMA(arsi, prevArsi1, (int)Math.Ceiling(sp)); arsiEmaList.AddRounded(arsiEma); var signal = GetRsiSignal(arsiEma - prevArsi1, prevArsi1 - prevArsi2, arsiEma, prevArsi1, 70, 30); @@ -6626,15 +6626,15 @@ public static StockData CalculateEhlersAdaptiveRsiFisherTransformV1(this StockDa var arsiList = CalculateEhlersAdaptiveRelativeStrengthIndexV1(stockData).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double arsi = arsiList[i] / 100; - double prevFish1 = i >= 1 ? fishList[i - 1] : 0; - double prevFish2 = i >= 2 ? fishList[i - 2] : 0; - double tranRsi = 2 * (arsi - 0.5); - double ampRsi = MinOrMax(1.5 * tranRsi, 0.999, -0.999); + var arsi = arsiList[i] / 100; + var prevFish1 = i >= 1 ? fishList[i - 1] : 0; + var prevFish2 = i >= 2 ? fishList[i - 2] : 0; + var tranRsi = 2 * (arsi - 0.5); + var ampRsi = MinOrMax(1.5 * tranRsi, 0.999, -0.999); - double fish = 0.5 * Math.Log((1 + ampRsi) / (1 - ampRsi)); + var fish = 0.5 * Math.Log((1 + ampRsi) / (1 - ampRsi)); fishList.AddRounded(fish); var signal = GetCompareSignal(fish - prevFish1, prevFish1 - prevFish2); @@ -6667,18 +6667,18 @@ public static StockData CalculateEhlersAdaptiveStochasticIndicatorV1(this StockD var spList = CalculateEhlersMotherOfAdaptiveMovingAverages(stockData).OutputValues["SmoothPeriod"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sp = spList[i]; - double high = highList[i]; - double low = lowList[i]; - double close = inputList[i]; - double prevAstoc1 = i >= 1 ? astocEmaList[i - 1] : 0; - double prevAstoc2 = i >= 2 ? astocEmaList[i - 2] : 0; + var sp = spList[i]; + var high = highList[i]; + var low = lowList[i]; + var close = inputList[i]; + var prevAstoc1 = i >= 1 ? astocEmaList[i - 1] : 0; + var prevAstoc2 = i >= 2 ? astocEmaList[i - 2] : 0; - int length = (int)Math.Ceiling(cycPart * sp); + var length = (int)Math.Ceiling(cycPart * sp); double hh = high, ll = low; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { var h = i >= j ? highList[i - j] : 0; var l = i >= j ? lowList[i - j] : 0; @@ -6687,10 +6687,10 @@ public static StockData CalculateEhlersAdaptiveStochasticIndicatorV1(this StockD ll = l < ll ? l : ll; } - double astoc = hh - ll != 0 ? 100 * (close - ll) / (hh - ll) : 0; + var astoc = hh - ll != 0 ? 100 * (close - ll) / (hh - ll) : 0; astocList.AddRounded(astoc); - double astocEma = CalculateEMA(astoc, prevAstoc1, length); + var astocEma = CalculateEMA(astoc, prevAstoc1, length); astocEmaList.AddRounded(astocEma); var signal = GetRsiSignal(astocEma - prevAstoc1, prevAstoc1 - prevAstoc2, astocEma, prevAstoc1, 70, 30); @@ -6727,34 +6727,34 @@ public static StockData CalculateEhlersAdaptiveCommodityChannelIndexV1(this Stoc var spList = CalculateEhlersMotherOfAdaptiveMovingAverages(stockData).OutputValues["SmoothPeriod"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sp = spList[i]; - double prevAcci1 = i >= 1 ? acciEmaList[i - 1] : 0; - double prevAcci2 = i >= 2 ? acciEmaList[i - 2] : 0; - double tp = inputList[i]; + var sp = spList[i]; + var prevAcci1 = i >= 1 ? acciEmaList[i - 1] : 0; + var prevAcci2 = i >= 2 ? acciEmaList[i - 2] : 0; + var tp = inputList[i]; - int length = (int)Math.Ceiling(cycPart * sp); + var length = (int)Math.Ceiling(cycPart * sp); double avg = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double prevMp = i >= j ? inputList[i - j] : 0; + var prevMp = i >= j ? inputList[i - j] : 0; avg += prevMp; } avg /= length; double md = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double prevMp = i >= j ? inputList[i - j] : 0; + var prevMp = i >= j ? inputList[i - j] : 0; md += Math.Abs(prevMp - avg); } md /= length; - double acci = md != 0 ? (tp - avg) / (constant * md) : 0; + var acci = md != 0 ? (tp - avg) / (constant * md) : 0; acciList.AddRounded(acci); - double acciEma = CalculateEMA(acci, prevAcci1, (int)Math.Ceiling(sp)); + var acciEma = CalculateEMA(acci, prevAcci1, (int)Math.Ceiling(sp)); acciEmaList.AddRounded(acciEma); var signal = GetRsiSignal(acciEma - prevAcci1, prevAcci1 - prevAcci2, acciEma, prevAcci1, 100, -100); @@ -6792,23 +6792,23 @@ public static StockData CalculateEhlersCommodityChannelIndexInverseFisherTransfo var cciList = CalculateCommodityChannelIndex(stockData, inputName, maType, length, constant).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double cci = cciList[i]; + var cci = cciList[i]; - double v1 = 0.1 * (cci - 50); + var v1 = 0.1 * (cci - 50); v1List.AddRounded(v1); } var v2List = GetMovingAverageList(stockData, maType, signalLength, v1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double v2 = v2List[i]; - double expValue = Exp(2 * v2); - double prevIFish1 = i >= 1 ? iFishList[i - 1] : 0; - double prevIFish2 = i >= 2 ? iFishList[i - 2] : 0; + var v2 = v2List[i]; + var expValue = Exp(2 * v2); + var prevIFish1 = i >= 1 ? iFishList[i - 1] : 0; + var prevIFish2 = i >= 2 ? iFishList[i - 2] : 0; - double iFish = expValue + 1 != 0 ? (expValue - 1) / (expValue + 1) : 0; + var iFish = expValue + 1 != 0 ? (expValue - 1) / (expValue + 1) : 0; iFishList.AddRounded(iFish); var signal = GetRsiSignal(iFish - prevIFish1, prevIFish1 - prevIFish2, iFish, prevIFish1, 0.5, -0.5); @@ -6843,23 +6843,23 @@ public static StockData CalculateEhlersRelativeStrengthIndexInverseFisherTransfo var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; + var rsi = rsiList[i]; - double v1 = 0.1 * (rsi - 50); + var v1 = 0.1 * (rsi - 50); v1List.AddRounded(v1); } var v2List = GetMovingAverageList(stockData, maType, signalLength, v1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double v2 = v2List[i]; - double expValue = Exp(2 * v2); - double prevIfish1 = i >= 1 ? iFishList[i - 1] : 0; - double prevIfish2 = i >= 2 ? iFishList[i - 2] : 0; + var v2 = v2List[i]; + var expValue = Exp(2 * v2); + var prevIfish1 = i >= 1 ? iFishList[i - 1] : 0; + var prevIfish2 = i >= 2 ? iFishList[i - 2] : 0; - double iFish = expValue + 1 != 0 ? MinOrMax((expValue - 1) / (expValue + 1), 1, -1) : 0; + var iFish = expValue + 1 != 0 ? MinOrMax((expValue - 1) / (expValue + 1), 1, -1) : 0; iFishList.AddRounded(iFish); var signal = GetRsiSignal(iFish - prevIfish1, prevIfish1 - prevIfish2, iFish, prevIfish1, 0.5, -0.5); diff --git a/src/Calculations/Inputs.cs b/src/Calculations/Inputs.cs index 7d78c0f..a7c7f7d 100644 --- a/src/Calculations/Inputs.cs +++ b/src/Calculations/Inputs.cs @@ -23,18 +23,18 @@ public static StockData CalculateTypicalPrice(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double prevTypicalPrice1 = i >= 1 ? tpList[i - 1] : 0; - double prevTypicalPrice2 = i >= 2 ? tpList[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var prevTypicalPrice1 = i >= 1 ? tpList[i - 1] : 0; + var prevTypicalPrice2 = i >= 2 ? tpList[i - 2] : 0; - double typicalPrice = (currentHigh + currentLow + currentClose) / 3; + var typicalPrice = (currentHigh + currentLow + currentClose) / 3; tpList.AddRounded(typicalPrice); - Signal signal = GetCompareSignal(typicalPrice - prevTypicalPrice1, prevTypicalPrice1 - prevTypicalPrice2); + var signal = GetCompareSignal(typicalPrice - prevTypicalPrice1, prevTypicalPrice1 - prevTypicalPrice2); signalsList.Add(signal); } @@ -60,17 +60,17 @@ public static StockData CalculateMedianPrice(this StockData stockData) List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentLow = lowList[i]; - double currentHigh = highList[i]; - double prevMedianPrice1 = i >= 1 ? medianPriceList[i - 1] : 0; - double prevMedianPrice2 = i >= 2 ? medianPriceList[i - 2] : 0; + var currentLow = lowList[i]; + var currentHigh = highList[i]; + var prevMedianPrice1 = i >= 1 ? medianPriceList[i - 1] : 0; + var prevMedianPrice2 = i >= 2 ? medianPriceList[i - 2] : 0; - double medianPrice = (currentHigh + currentLow) / 2; + var medianPrice = (currentHigh + currentLow) / 2; medianPriceList.AddRounded(medianPrice); - Signal signal = GetCompareSignal(medianPrice - prevMedianPrice1, prevMedianPrice1 - prevMedianPrice2); + var signal = GetCompareSignal(medianPrice - prevMedianPrice1, prevMedianPrice1 - prevMedianPrice2); signalsList.Add(signal); } @@ -96,17 +96,17 @@ public static StockData CalculateAveragePrice(this StockData stockData) List signalsList = new(); var (closeList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentClose = closeList[i]; - double prevAvgPrice1 = i >= 1 ? avgPriceList[i - 1] : 0; - double prevAvgPrice2 = i >= 2 ? avgPriceList[i - 2] : 0; + var currentOpen = openList[i]; + var currentClose = closeList[i]; + var prevAvgPrice1 = i >= 1 ? avgPriceList[i - 1] : 0; + var prevAvgPrice2 = i >= 2 ? avgPriceList[i - 2] : 0; - double avgPrice = (currentOpen + currentClose) / 2; + var avgPrice = (currentOpen + currentClose) / 2; avgPriceList.AddRounded(avgPrice); - Signal signal = GetCompareSignal(avgPrice - prevAvgPrice1, prevAvgPrice1 - prevAvgPrice2); + var signal = GetCompareSignal(avgPrice - prevAvgPrice1, prevAvgPrice1 - prevAvgPrice2); signalsList.Add(signal); } @@ -132,19 +132,19 @@ public static StockData CalculateFullTypicalPrice(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double prevTypicalPrice1 = i >= 1 ? fullTpList[i - 1] : 0; - double prevTypicalPrice2 = i >= 2 ? fullTpList[i - 2] : 0; - - double typicalPrice = (currentHigh + currentLow + currentClose + currentOpen) / 4; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var prevTypicalPrice1 = i >= 1 ? fullTpList[i - 1] : 0; + var prevTypicalPrice2 = i >= 2 ? fullTpList[i - 2] : 0; + + var typicalPrice = (currentHigh + currentLow + currentClose + currentOpen) / 4; fullTpList.AddRounded(typicalPrice); - Signal signal = GetCompareSignal(typicalPrice - prevTypicalPrice1, prevTypicalPrice1 - prevTypicalPrice2); + var signal = GetCompareSignal(typicalPrice - prevTypicalPrice1, prevTypicalPrice1 - prevTypicalPrice2); signalsList.Add(signal); } @@ -170,18 +170,18 @@ public static StockData CalculateWeightedClose(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevWeightedClose = weightedCloseList.LastOrDefault(); - double weightedClose = (currentHigh + currentLow + (currentClose * 2)) / 4; + var prevWeightedClose = weightedCloseList.LastOrDefault(); + var weightedClose = (currentHigh + currentLow + (currentClose * 2)) / 4; weightedCloseList.AddRounded(weightedClose); - Signal signal = GetCompareSignal(currentClose - weightedClose, prevClose - prevWeightedClose); + var signal = GetCompareSignal(currentClose - weightedClose, prevClose - prevWeightedClose); signalsList.Add(signal); } @@ -209,15 +209,15 @@ public static StockData CalculateMidpoint(this StockData stockData, int length = var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double highest = highestList[i]; - double lowest = lowestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; - double prevMidPoint = midpointList.LastOrDefault(); - double midpoint = (highest + lowest) / 2; + var prevMidPoint = midpointList.LastOrDefault(); + var midpoint = (highest + lowest) / 2; midpointList.AddRounded(midpoint); var signal = GetCompareSignal(currentValue - midpoint, prevValue - prevMidPoint); @@ -248,15 +248,15 @@ public static StockData CalculateMidprice(this StockData stockData, int length = var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double highest = highestList[i]; - double lowest = lowestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; - double prevMidPrice = midpriceList.LastOrDefault(); - double midPrice = (highest + lowest) / 2; + var prevMidPrice = midpriceList.LastOrDefault(); + var midPrice = (highest + lowest) / 2; midpriceList.AddRounded(midPrice); var signal = GetCompareSignal(currentValue - midPrice, prevValue - prevMidPrice); diff --git a/src/Calculations/Macd.cs b/src/Calculations/Macd.cs index b97567a..13ee570 100644 --- a/src/Calculations/Macd.cs +++ b/src/Calculations/Macd.cs @@ -32,23 +32,23 @@ public static StockData CalculateMovingAverageConvergenceDivergence(this StockDa var fastEmaList = GetMovingAverageList(stockData, movingAvgType, fastLength, inputList); var slowEmaList = GetMovingAverageList(stockData, movingAvgType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastEma = fastEmaList[i]; - double slowEma = slowEmaList[i]; + var fastEma = fastEmaList[i]; + var slowEma = slowEmaList[i]; - double macd = fastEma - slowEma; + var macd = fastEma - slowEma; macdList.AddRounded(macd); } var macdSignalLineList = GetMovingAverageList(stockData, movingAvgType, signalLength, macdList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macd = macdList[i]; - double macdSignalLine = macdSignalLineList[i]; + var macd = macdList[i]; + var macdSignalLine = macdSignalLineList[i]; - double prevMacdHistogram = macdHistogramList.LastOrDefault(); - double macdHistogram = macd - macdSignalLine; + var prevMacdHistogram = macdHistogramList.LastOrDefault(); + var macdHistogram = macd - macdSignalLine; macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); @@ -102,25 +102,25 @@ public static StockData Calculate4MovingAverageConvergenceDivergence(this StockD var ema14List = GetMovingAverageList(stockData, maType, length5, inputList); var ema16List = GetMovingAverageList(stockData, maType, length6, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema5 = ema5List[i]; - double ema8 = ema8List[i]; - double ema10 = ema10List[i]; - double ema14 = ema14List[i]; - double ema16 = ema16List[i]; - double ema17 = ema17List[i]; + var ema5 = ema5List[i]; + var ema8 = ema8List[i]; + var ema10 = ema10List[i]; + var ema14 = ema14List[i]; + var ema16 = ema16List[i]; + var ema17 = ema17List[i]; - double macd1 = ema17 - ema14; + var macd1 = ema17 - ema14; macd1List.AddRounded(macd1); - double macd2 = ema17 - ema8; + var macd2 = ema17 - ema8; macd2List.AddRounded(macd2); - double macd3 = ema10 - ema16; + var macd3 = ema10 - ema16; macd3List.AddRounded(macd3); - double macd4 = ema5 - ema10; + var macd4 = ema5 - ema10; macd4List.AddRounded(macd4); } @@ -128,28 +128,28 @@ public static StockData Calculate4MovingAverageConvergenceDivergence(this StockD var macd2SignalLineList = GetMovingAverageList(stockData, maType, length1, macd2List); //-V3056 var macd3SignalLineList = GetMovingAverageList(stockData, maType, length1, macd3List); var macd4SignalLineList = GetMovingAverageList(stockData, maType, length1, macd4List); - for (int i = 0; i < stockData.Count; i++) - { - double macd1 = macd1List[i]; - double macd1SignalLine = macd1SignalLineList[i]; - double macd2 = macd2List[i]; - double macd2SignalLine = macd2SignalLineList[i]; - double macd3 = macd3List[i]; - double macd3SignalLine = macd3SignalLineList[i]; - double macd4 = macd4List[i]; - double macd4SignalLine = macd4SignalLineList[i]; - double macd1Histogram = macd1 - macd1SignalLine; - double macdBlue = blueMult * macd1Histogram; - - double prevMacd2Histogram = macd2HistogramList.LastOrDefault(); - double macd2Histogram = macd2 - macd2SignalLine; + for (var i = 0; i < stockData.Count; i++) + { + var macd1 = macd1List[i]; + var macd1SignalLine = macd1SignalLineList[i]; + var macd2 = macd2List[i]; + var macd2SignalLine = macd2SignalLineList[i]; + var macd3 = macd3List[i]; + var macd3SignalLine = macd3SignalLineList[i]; + var macd4 = macd4List[i]; + var macd4SignalLine = macd4SignalLineList[i]; + var macd1Histogram = macd1 - macd1SignalLine; + var macdBlue = blueMult * macd1Histogram; + + var prevMacd2Histogram = macd2HistogramList.LastOrDefault(); + var macd2Histogram = macd2 - macd2SignalLine; macd2HistogramList.AddRounded(macd2Histogram); - double macd3Histogram = macd3 - macd3SignalLine; - double macdYellow = yellowMult * macd3Histogram; + var macd3Histogram = macd3 - macd3SignalLine; + var macdYellow = yellowMult * macd3Histogram; - double prevMacd4Histogram = macd4HistogramList.LastOrDefault(); - double macd4Histogram = macd4 - macd4SignalLine; + var prevMacd4Histogram = macd4HistogramList.LastOrDefault(); + var macd4Histogram = macd4 - macd4SignalLine; macd4HistogramList.AddRounded(macd4Histogram); var signal = GetCompareSignal(macd4Histogram - macd2Histogram, prevMacd4Histogram - prevMacd2Histogram); @@ -194,20 +194,20 @@ public static StockData CalculateImpulseMovingAverageConvergenceDivergence(this var wellesWilderHighMovingAvgList = GetMovingAverageList(stockData, maType, length, highList); var wellesWilderLowMovingAvgList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double hi = wellesWilderHighMovingAvgList[i]; - double lo = wellesWilderLowMovingAvgList[i]; - double mi = typicalPriceZeroLagEmaList[i]; + var hi = wellesWilderHighMovingAvgList[i]; + var lo = wellesWilderLowMovingAvgList[i]; + var mi = typicalPriceZeroLagEmaList[i]; - double macd = mi > hi ? mi - hi : mi < lo ? mi - lo : 0; + var macd = mi > hi ? mi - hi : mi < lo ? mi - lo : 0; macdList.AddRounded(macd); - double macdSignalLine = macdList.TakeLastExt(signalLength).Average(); + var macdSignalLine = macdList.TakeLastExt(signalLength).Average(); macdSignalLineList.AddRounded(macdSignalLine); - double prevMacdHistogram = macdHistogramList.LastOrDefault(); - double macdHistogram = macd - macdSignalLine; + var prevMacdHistogram = macdHistogramList.LastOrDefault(); + var macdHistogram = macd - macdSignalLine; macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); @@ -245,13 +245,13 @@ public static StockData CalculateKaseConvergenceDivergence(this StockData stockD var pkList = CalculateKasePeakOscillatorV1(stockData, length1, length2).OutputValues["Pk"]; var pkSignalList = GetMovingAverageList(stockData, maType, length3, pkList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pk = pkList[i]; - double pkSma = pkSignalList[i]; + var pk = pkList[i]; + var pkSma = pkSignalList[i]; - double prevKcd = kcdList.LastOrDefault(); - double kcd = pk - pkSma; + var prevKcd = kcdList.LastOrDefault(); + var kcd = pk - pkSma; kcdList.AddRounded(kcd); var signal = GetCompareSignal(kcd, prevKcd); @@ -293,46 +293,46 @@ public static StockData CalculateMovingAverageConvergenceDivergenceLeader(this S var emaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var ema26List = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ema12 = emaList[i]; - double ema26 = ema26List[i]; + var currentValue = inputList[i]; + var ema12 = emaList[i]; + var ema26 = ema26List[i]; - double diff12 = currentValue - ema12; + var diff12 = currentValue - ema12; diff12List.AddRounded(diff12); - double diff26 = currentValue - ema26; + var diff26 = currentValue - ema26; diff26List.AddRounded(diff26); } var diff12EmaList = GetMovingAverageList(stockData, maType, fastLength, diff12List); var diff26EmaList = GetMovingAverageList(stockData, maType, slowLength, diff26List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema12 = emaList[i]; - double ema26 = ema26List[i]; - double diff12Ema = diff12EmaList[i]; - double diff26Ema = diff26EmaList[i]; + var ema12 = emaList[i]; + var ema26 = ema26List[i]; + var diff12Ema = diff12EmaList[i]; + var diff26Ema = diff26EmaList[i]; - double i1 = ema12 + diff12Ema; + var i1 = ema12 + diff12Ema; i1List.AddRounded(i1); - double i2 = ema26 + diff26Ema; + var i2 = ema26 + diff26Ema; i2List.AddRounded(i2); - double macd = i1 - i2; + var macd = i1 - i2; macdList.AddRounded(macd); } var macdSignalLineList = GetMovingAverageList(stockData, maType, signalLength, macdList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macd = macdList[i]; - double macdSignalLine = macdSignalLineList[i]; + var macd = macdList[i]; + var macdSignalLine = macdSignalLineList[i]; - double prevMacdHistogram = macdHistogramList.LastOrDefault(); - double macdHistogram = macd - macdSignalLine; + var prevMacdHistogram = macdHistogramList.LastOrDefault(); + var macdHistogram = macd - macdSignalLine; macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); @@ -372,23 +372,23 @@ public static StockData CalculateTFSMboIndicator(this StockData stockData, Movin var mob1List = GetMovingAverageList(stockData, maType, fastLength, inputList); var mob2List = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mob1 = mob1List[i]; - double mob2 = mob2List[i]; + var mob1 = mob1List[i]; + var mob2 = mob2List[i]; - double tfsMob = mob1 - mob2; + var tfsMob = mob1 - mob2; tfsMobList.AddRounded(tfsMob); } var tfsMobSignalLineList = GetMovingAverageList(stockData, maType, signalLength, tfsMobList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tfsMob = tfsMobList[i]; - double tfsMobSignalLine = tfsMobSignalLineList[i]; + var tfsMob = tfsMobList[i]; + var tfsMobSignalLine = tfsMobSignalLineList[i]; - double prevTfsMobHistogram = tfsMobHistogramList.LastOrDefault(); - double tfsMobHistogram = tfsMob - tfsMobSignalLine; + var prevTfsMobHistogram = tfsMobHistogramList.LastOrDefault(); + var tfsMobHistogram = tfsMob - tfsMobSignalLine; tfsMobHistogramList.AddRounded(tfsMobHistogram); var signal = GetCompareSignal(tfsMobHistogram, prevTfsMobHistogram); @@ -438,45 +438,45 @@ public static StockData CalculateMacZVwapIndicator(this StockData stockData, Mov var slowSmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); var zScoreList = CalculateZDistanceFromVwapIndicator(stockData, length: length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdev = stdDevList[i]; - double fastMa = fastSmaList[i]; - double slowMa = slowSmaList[i]; - double zscore = zScoreList[i]; + var stdev = stdDevList[i]; + var fastMa = fastSmaList[i]; + var slowMa = slowSmaList[i]; + var zscore = zScoreList[i]; - double macd = fastMa - slowMa; - double maczt = stdev != 0 ? zscore + (macd / stdev) : zscore; + var macd = fastMa - slowMa; + var maczt = stdev != 0 ? zscore + (macd / stdev) : zscore; macztList.AddRounded(maczt); - double prevL0 = i >= 1 ? l0List.LastOrDefault() : maczt; - double l0 = ((1 - gamma) * maczt) + (gamma * prevL0); + var prevL0 = i >= 1 ? l0List.LastOrDefault() : maczt; + var l0 = ((1 - gamma) * maczt) + (gamma * prevL0); l0List.AddRounded(l0); - double prevL1 = i >= 1 ? l1List.LastOrDefault() : maczt; - double l1 = (-1 * gamma * l0) + prevL0 + (gamma * prevL1); + var prevL1 = i >= 1 ? l1List.LastOrDefault() : maczt; + var l1 = (-1 * gamma * l0) + prevL0 + (gamma * prevL1); l1List.AddRounded(l1); - double prevL2 = i >= 1 ? l2List.LastOrDefault() : maczt; - double l2 = (-1 * gamma * l1) + prevL1 + (gamma * prevL2); + var prevL2 = i >= 1 ? l2List.LastOrDefault() : maczt; + var l2 = (-1 * gamma * l1) + prevL1 + (gamma * prevL2); l2List.AddRounded(l2); - double prevL3 = i >= 1 ? l3List.LastOrDefault() : maczt; - double l3 = (-1 * gamma * l2) + prevL2 + (gamma * prevL3); + var prevL3 = i >= 1 ? l3List.LastOrDefault() : maczt; + var l3 = (-1 * gamma * l2) + prevL2 + (gamma * prevL3); l3List.AddRounded(l3); - double macz = (l0 + (2 * l1) + (2 * l2) + l3) / 6; + var macz = (l0 + (2 * l1) + (2 * l2) + l3) / 6; maczList.AddRounded(macz); } var maczSignalList = GetMovingAverageList(stockData, maType, signalLength, maczList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macz = maczList[i]; - double maczSignal = maczSignalList[i]; + var macz = maczList[i]; + var maczSignal = maczSignalList[i]; - double prevHist = histList.LastOrDefault(); - double hist = macz - maczSignal; + var prevHist = histList.LastOrDefault(); + var hist = macz - maczSignal; histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); @@ -521,28 +521,28 @@ public static StockData CalculateMacZIndicator(this StockData stockData, MovingA var slowSmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); var wilderMovingAvgList = GetMovingAverageList(stockData, MovingAvgType.WildersSmoothingMethod, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double stdev = stdDevList[i]; - double wima = wilderMovingAvgList[i]; - double fastMa = fastSmaList[i]; - double slowMa = slowSmaList[i]; - double zscore = stdev != 0 ? (currentValue - wima) / stdev : 0; + var currentValue = inputList[i]; + var stdev = stdDevList[i]; + var wima = wilderMovingAvgList[i]; + var fastMa = fastSmaList[i]; + var slowMa = slowSmaList[i]; + var zscore = stdev != 0 ? (currentValue - wima) / stdev : 0; - double macd = fastMa - slowMa; - double macz = stdev != 0 ? (zscore * mult) + (mult * macd / stdev) : zscore; + var macd = fastMa - slowMa; + var macz = stdev != 0 ? (zscore * mult) + (mult * macd / stdev) : zscore; maczList.AddRounded(macz); } var maczSignalList = GetMovingAverageList(stockData, maType, signalLength, maczList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macz = maczList[i]; - double maczSignal = maczSignalList[i]; + var macz = maczList[i]; + var maczSignal = maczSignalList[i]; - double prevHist = histList.LastOrDefault(); - double hist = macz - maczSignal; + var prevHist = histList.LastOrDefault(); + var hist = macz - maczSignal; histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); @@ -583,32 +583,32 @@ public static StockData CalculateMirroredMovingAverageConvergenceDivergence(this var emaOpenList = GetMovingAverageList(stockData, maType, length, openList); var emaCloseList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mao = emaOpenList[i]; - double mac = emaCloseList[i]; + var mao = emaOpenList[i]; + var mac = emaCloseList[i]; - double macd = mac - mao; + var macd = mac - mao; macdList.AddRounded(macd); - double macdMirror = mao - mac; + var macdMirror = mao - mac; macdMirrorList.AddRounded(macdMirror); } var macdSignalLineList = GetMovingAverageList(stockData, maType, signalLength, macdList); var macdMirrorSignalLineList = GetMovingAverageList(stockData, maType, signalLength, macdMirrorList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macd = macdList[i]; - double macdMirror = macdMirrorList[i]; - double macdSignalLine = macdSignalLineList[i]; - double macdMirrorSignalLine = macdMirrorSignalLineList[i]; + var macd = macdList[i]; + var macdMirror = macdMirrorList[i]; + var macdSignalLine = macdSignalLineList[i]; + var macdMirrorSignalLine = macdMirrorSignalLineList[i]; - double prevMacdHistogram = macdHistogramList.LastOrDefault(); - double macdHistogram = macd - macdSignalLine; + var prevMacdHistogram = macdHistogramList.LastOrDefault(); + var macdHistogram = macd - macdSignalLine; macdHistogramList.AddRounded(macdHistogram); - double macdMirrorHistogram = macdMirror - macdMirrorSignalLine; + var macdMirrorHistogram = macdMirror - macdMirrorSignalLine; macdMirrorHistogramList.AddRounded(macdMirrorHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); @@ -650,31 +650,31 @@ public static StockData CalculateDiNapoliMovingAverageConvergenceDivergence(this List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double scAlpha = 2 / (1 + sc); - double lcAlpha = 2 / (1 + lc); - double spAlpha = 2 / (1 + sp); + var scAlpha = 2 / (1 + sc); + var lcAlpha = 2 / (1 + lc); + var spAlpha = 2 / (1 + sp); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double prevFs = fsList.LastOrDefault(); - double fs = prevFs + (scAlpha * (currentValue - prevFs)); + var prevFs = fsList.LastOrDefault(); + var fs = prevFs + (scAlpha * (currentValue - prevFs)); fsList.AddRounded(fs); - double prevSs = ssList.LastOrDefault(); - double ss = prevSs + (lcAlpha * (currentValue - prevSs)); + var prevSs = ssList.LastOrDefault(); + var ss = prevSs + (lcAlpha * (currentValue - prevSs)); ssList.AddRounded(ss); - double r = fs - ss; + var r = fs - ss; rList.AddRounded(r); - double prevS = sList.LastOrDefault(); - double s = prevS + (spAlpha * (r - prevS)); + var prevS = sList.LastOrDefault(); + var s = prevS + (spAlpha * (r - prevS)); sList.AddRounded(s); - double prevH = hList.LastOrDefault(); - double h = r - s; + var prevH = hList.LastOrDefault(); + var h = r - s; hList.AddRounded(h); var signal = GetCompareSignal(h, prevH); @@ -720,32 +720,32 @@ public static StockData CalculateStochasticMovingAverageConvergenceDivergenceOsc var fastEmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowEmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastEma = fastEmaList[i]; - double slowEma = slowEmaList[i]; - double hh = highestList[i]; - double ll = lowestList[i]; - double range = hh - ll; + var fastEma = fastEmaList[i]; + var slowEma = slowEmaList[i]; + var hh = highestList[i]; + var ll = lowestList[i]; + var range = hh - ll; - double fastStochastic = range != 0 ? (fastEma - ll) / range : 0; + var fastStochastic = range != 0 ? (fastEma - ll) / range : 0; fastStochasticList.AddRounded(fastStochastic); - double slowStochastic = range != 0 ? (slowEma - ll) / range : 0; + var slowStochastic = range != 0 ? (slowEma - ll) / range : 0; slowStochasticList.AddRounded(slowStochastic); - double macdStochastic = 10 * (fastStochastic - slowStochastic); + var macdStochastic = 10 * (fastStochastic - slowStochastic); macdStochasticList.AddRounded(macdStochastic); } var macdStochasticSignalLineList = GetMovingAverageList(stockData, maType, signalLength, macdStochasticList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macdStochastic = macdStochasticList[i]; - double macdStochasticSignalLine = macdStochasticSignalLineList[i]; + var macdStochastic = macdStochasticList[i]; + var macdStochasticSignalLine = macdStochasticSignalLineList[i]; - double prevMacdHistogram = macdStochasticHistogramList.LastOrDefault(); - double macdHistogram = macdStochastic - macdStochasticSignalLine; + var prevMacdHistogram = macdStochasticHistogramList.LastOrDefault(); + var macdHistogram = macdStochastic - macdStochasticSignalLine; macdStochasticHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); @@ -785,23 +785,23 @@ public static StockData CalculateErgodicMovingAverageConvergenceDivergence(this var period1EmaList = GetMovingAverageList(stockData, maType, length1, inputList); var period2EmaList = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema1 = period1EmaList[i]; - double ema2 = period2EmaList[i]; + var ema1 = period1EmaList[i]; + var ema2 = period2EmaList[i]; - double macd = ema1 - ema2; + var macd = ema1 - ema2; macdList.AddRounded(macd); } var macdSignalLineList = GetMovingAverageList(stockData, maType, length3, macdList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double macd = macdList[i]; - double macdSignalLine = macdSignalLineList[i]; + var macd = macdList[i]; + var macdSignalLine = macdSignalLineList[i]; - double prevMacdHistogram = macdHistogramList.LastOrDefault(); - double macdHistogram = macd - macdSignalLine; + var prevMacdHistogram = macdHistogramList.LastOrDefault(); + var macdHistogram = macd - macdSignalLine; macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); diff --git a/src/Calculations/Momentum.cs b/src/Calculations/Momentum.cs index 8360469..9870789 100644 --- a/src/Calculations/Momentum.cs +++ b/src/Calculations/Momentum.cs @@ -32,23 +32,23 @@ public static StockData CalculateDynamicMomentumOscillator(this StockData stockD var stochSmaList = stochList.OutputValues["FastD"]; var smaValList = stochList.OutputValues["SlowD"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double smaVal = smaValList[i]; - double stochSma = stochSmaList[i]; - double prevDmo1 = i >= 1 ? dmoList[i - 1] : 0; - double prevDmo2 = i >= 2 ? dmoList[i - 2] : 0; + var smaVal = smaValList[i]; + var stochSma = stochSmaList[i]; + var prevDmo1 = i >= 1 ? dmoList[i - 1] : 0; + var prevDmo2 = i >= 2 ? dmoList[i - 2] : 0; - double prevHighest = highestList.LastOrDefault(); - double highest = stochSma > prevHighest ? stochSma : prevHighest; + var prevHighest = highestList.LastOrDefault(); + var highest = stochSma > prevHighest ? stochSma : prevHighest; highestList.AddRounded(highest); - double prevLowest = i >= 1 ? lowestList.LastOrDefault() : double.MaxValue; - double lowest = stochSma < prevLowest ? stochSma : prevLowest; + var prevLowest = i >= 1 ? lowestList.LastOrDefault() : double.MaxValue; + var lowest = stochSma < prevLowest ? stochSma : prevLowest; lowestList.AddRounded(lowest); - double midpoint = MinOrMax((lowest + highest) / 2, 100, 0); - double dmo = MinOrMax(midpoint - (smaVal - stochSma), 100, 0); + var midpoint = MinOrMax((lowest + highest) / 2, 100, 0); + var dmo = MinOrMax(midpoint - (smaVal - stochSma), 100, 0); dmoList.AddRounded(dmo); var signal = GetRsiSignal(dmo - prevDmo1, prevDmo1 - prevDmo2, dmo, prevDmo1, 77, 23); @@ -83,31 +83,31 @@ public static StockData CalculatePriceMomentumOscillator(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double sc1 = 2 / (double)length1; - double sc2 = 2 / (double)length2; + var sc1 = 2 / (double)length1; + var sc2 = 2 / (double)length2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double roc = prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / prevValue * 100 : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var roc = prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / prevValue * 100 : 0; - double prevRocMa1 = rocMaList.LastOrDefault(); - double rocMa = prevRocMa1 + ((roc - prevRocMa1) * sc1); + var prevRocMa1 = rocMaList.LastOrDefault(); + var rocMa = prevRocMa1 + ((roc - prevRocMa1) * sc1); rocMaList.AddRounded(rocMa); - double prevPmo = pmoList.LastOrDefault(); - double pmo = prevPmo + (((rocMa * 10) - prevPmo) * sc2); + var prevPmo = pmoList.LastOrDefault(); + var pmo = prevPmo + (((rocMa * 10) - prevPmo) * sc2); pmoList.AddRounded(pmo); } var pmoSignalList = GetMovingAverageList(stockData, maType, signalLength, pmoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pmo = pmoList[i]; - double prevPmo = i >= 1 ? pmoList[i - 1] : 0; - double pmoSignal = pmoSignalList[i]; - double prevPmoSignal = i >= 1 ? pmoSignalList[i - 1] : 0; + var pmo = pmoList[i]; + var prevPmo = i >= 1 ? pmoList[i - 1] : 0; + var pmoSignal = pmoSignalList[i]; + var prevPmoSignal = i >= 1 ? pmoSignalList[i - 1] : 0; var signal = GetCompareSignal(pmo - pmoSignal, prevPmo - prevPmoSignal); signalsList.Add(signal); @@ -143,24 +143,24 @@ public static StockData CalculateAnchoredMomentum(this StockData stockData, Movi List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int p = MinOrMax((2 * momentumLength) + 1); + var p = MinOrMax((2 * momentumLength) + 1); var emaList = GetMovingAverageList(stockData, maType, smoothLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEma = emaList[i]; + var currentEma = emaList[i]; - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double sma = tempList.TakeLastExt(p).Average(); - double prevAmom = amomList.LastOrDefault(); - double amom = sma != 0 ? 100 * ((currentEma / sma) - 1) : 0; + var sma = tempList.TakeLastExt(p).Average(); + var prevAmom = amomList.LastOrDefault(); + var amom = sma != 0 ? 100 * ((currentEma / sma) - 1) : 0; amomList.AddRounded(amom); - double prevAmoms = amomsList.LastOrDefault(); - double amoms = amomList.TakeLastExt(signalLength).Average(); + var prevAmoms = amomsList.LastOrDefault(); + var amoms = amomList.TakeLastExt(signalLength).Average(); amomsList.AddRounded(amoms); var signal = GetCompareSignal(amom - amoms, prevAmom - prevAmoms); @@ -209,29 +209,29 @@ public static StockData CalculateUltimateMomentumIndicator(this StockData stockD var mfi2List = CalculateMoneyFlowIndex(stockData, inputName, length3).CustomValuesList; var mfi3List = CalculateMoneyFlowIndex(stockData, inputName, length4).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mo = moList[i]; - double bbPct = bbPctList[i]; - double mfi1 = mfi1List[i]; - double mfi2 = mfi2List[i]; - double mfi3 = mfi3List[i]; - double advSum = advSumList[i]; - double decSum = decSumList[i]; - double ratio = decSum != 0 ? advSum / decSum : 0; - - double utm = (200 * bbPct) + (100 * ratio) + (2 * mo) + (1.5 * mfi3) + (3 * mfi2) + (3 * mfi1); + var mo = moList[i]; + var bbPct = bbPctList[i]; + var mfi1 = mfi1List[i]; + var mfi2 = mfi2List[i]; + var mfi3 = mfi3List[i]; + var advSum = advSumList[i]; + var decSum = decSumList[i]; + var ratio = decSum != 0 ? advSum / decSum : 0; + + var utm = (200 * bbPct) + (100 * ratio) + (2 * mo) + (1.5 * mfi3) + (3 * mfi2) + (3 * mfi1); utmList.AddRounded(utm); } stockData.CustomValuesList = utmList; var utmRsiList = CalculateRelativeStrengthIndex(stockData, maType, length1, length1).CustomValuesList; var utmiList = GetMovingAverageList(stockData, maType, length1, utmRsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double utmi = utmiList[i]; - double prevUtmi1 = i >= 1 ? utmiList[i - 1] : 0; - double prevUtmi2 = i >= 2 ? utmiList[i - 2] : 0; + var utmi = utmiList[i]; + var prevUtmi1 = i >= 1 ? utmiList[i - 1] : 0; + var prevUtmi2 = i >= 2 ? utmiList[i - 2] : 0; var signal = GetCompareSignal(utmi - prevUtmi1, prevUtmi1 - prevUtmi2); signalsList.Add(signal); @@ -269,13 +269,13 @@ public static StockData CalculateComparePriceMomentumOscillator(this StockData s var pmoList = CalculatePriceMomentumOscillator(stockData, maType, length1, length2, signalLength).CustomValuesList; var spPmoList = CalculatePriceMomentumOscillator(marketDataClass, maType, length1, length2, signalLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pmo = pmoList[i]; - double spPmo = spPmoList[i]; + var pmo = pmoList[i]; + var spPmo = spPmoList[i]; - double prevCpmo = cpmoList.LastOrDefault(); - double cpmo = pmo - spPmo; + var prevCpmo = cpmoList.LastOrDefault(); + var cpmo = pmo - spPmo; cpmoList.AddRounded(cpmo); var signal = GetCompareSignal(cpmo, prevCpmo); @@ -312,26 +312,26 @@ public static StockData CalculateTickLineMomentumOscillator(this StockData stock var maList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevMa = i >= 1 ? maList[i - 1] : 0; + var currentValue = inputList[i]; + var prevMa = i >= 1 ? maList[i - 1] : 0; double cumo = currentValue > prevMa ? 1 : currentValue < prevMa ? -1 : 0; cumoList.AddRounded(cumo); - double cumoSum = cumoList.Sum(); + var cumoSum = cumoList.Sum(); cumoSumList.AddRounded(cumoSum); } stockData.CustomValuesList = cumoSumList; var rocList = CalculateRateOfChange(stockData, smoothLength).CustomValuesList; var tlmoList = GetMovingAverageList(stockData, maType, smoothLength, rocList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tlmo = tlmoList[i]; - double prevTlmo1 = i >= 1 ? tlmoList[i - 1] : 0; - double prevTlmo2 = i >= 2 ? tlmoList[i - 2] : 0; + var tlmo = tlmoList[i]; + var prevTlmo1 = i >= 1 ? tlmoList[i - 1] : 0; + var prevTlmo2 = i >= 2 ? tlmoList[i - 2] : 0; var signal = GetRsiSignal(tlmo - prevTlmo1, prevTlmo1 - prevTlmo2, tlmo, prevTlmo1, 5, -5); signalsList.Add(signal); @@ -362,20 +362,20 @@ public static StockData CalculateMomentumOscillator(this StockData stockData, Mo List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; - double prevPrice = i >= length ? inputList[i - length] : 0; + var currentPrice = inputList[i]; + var prevPrice = i >= length ? inputList[i - length] : 0; - double momentumOscillator = prevPrice != 0 ? currentPrice / prevPrice * 100 : 0; + var momentumOscillator = prevPrice != 0 ? currentPrice / prevPrice * 100 : 0; momentumOscillatorList.AddRounded(momentumOscillator); } var emaList = GetMovingAverageList(stockData, maType, length, momentumOscillatorList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double momentum = emaList[i]; - double prevMomentum = i >= 1 ? emaList[i - 1] : 0; + var momentum = emaList[i]; + var prevMomentum = i >= 1 ? emaList[i - 1] : 0; var signal = GetCompareSignal(momentum, prevMomentum); signalsList.Add(signal); @@ -411,40 +411,40 @@ public static StockData CalculateRelativeMomentumIndex(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length2 ? inputList[i - length2] : 0; - double priceChg = MinPastValues(i, length2, currentValue - prevValue); + var currentValue = inputList[i]; + var prevValue = i >= length2 ? inputList[i - length2] : 0; + var priceChg = MinPastValues(i, length2, currentValue - prevValue); - double loss = i >= length2 && priceChg < 0 ? Math.Abs(priceChg) : 0; + var loss = i >= length2 && priceChg < 0 ? Math.Abs(priceChg) : 0; lossList.AddRounded(loss); - double gain = i >= length2 && priceChg > 0 ? priceChg : 0; + var gain = i >= length2 && priceChg > 0 ? priceChg : 0; gainList.AddRounded(gain); } var avgGainList = GetMovingAverageList(stockData, maType, length1, gainList); var avgLossList = GetMovingAverageList(stockData, maType, length1, lossList); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double avgGain = avgGainList[i]; - double avgLoss = avgLossList[i]; - double rs = avgLoss != 0 ? avgGain / avgLoss : 0; + var avgGain = avgGainList[i]; + var avgLoss = avgLossList[i]; + var rs = avgLoss != 0 ? avgGain / avgLoss : 0; - double rsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rsiList.AddRounded(rsi); } var rsiSignalList = GetMovingAverageList(stockData, maType, length1, rsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double rsiSignal = rsiSignalList[i]; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var rsi = rsiList[i]; + var rsiSignal = rsiSignalList[i]; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double prevRsiHistogram = rsiHistogramList.LastOrDefault(); - double rsiHistogram = rsi - rsiSignal; + var prevRsiHistogram = rsiHistogramList.LastOrDefault(); + var rsiHistogram = rsi - rsiSignal; rsiHistogramList.AddRounded(rsiHistogram); var signal = GetRsiSignal(rsiHistogram, prevRsiHistogram, rsi, prevRsi, 70, 30); @@ -482,32 +482,32 @@ public static StockData CalculateDecisionPointPriceMomentumOscillator(this Stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double smPmol2 = (double)2 / length1; - double smPmol = (double)2 / length2; + var smPmol2 = (double)2 / length1; + var smPmol = (double)2 / length2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ival = prevValue != 0 ? currentValue / prevValue * 100 : 100; - double prevPmol = pmolList.LastOrDefault(); - double prevPmol2 = pmol2List.LastOrDefault(); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ival = prevValue != 0 ? currentValue / prevValue * 100 : 100; + var prevPmol = pmolList.LastOrDefault(); + var prevPmol2 = pmol2List.LastOrDefault(); - double pmol2 = ((ival - 100 - prevPmol2) * smPmol2) + prevPmol2; + var pmol2 = ((ival - 100 - prevPmol2) * smPmol2) + prevPmol2; pmol2List.AddRounded(pmol2); - double pmol = (((10 * pmol2) - prevPmol) * smPmol) + prevPmol; + var pmol = (((10 * pmol2) - prevPmol) * smPmol) + prevPmol; pmolList.AddRounded(pmol); } var pmolsList = GetMovingAverageList(stockData, maType, signalLength, pmolList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pmol = pmolList[i]; - double pmols = pmolsList[i]; + var pmol = pmolList[i]; + var pmols = pmolsList[i]; - double prevD = dList.LastOrDefault(); - double d = pmol - pmols; + var prevD = dList.LastOrDefault(); + var d = pmol - pmols; dList.AddRounded(d); var signal = GetCompareSignal(d, prevD); @@ -552,11 +552,11 @@ public static StockData CalculateDynamicMomentumIndex(this StockData stockData, var standardDeviationList = CalculateStandardDeviationVolatility(stockData, maType, length1).CustomValuesList; var stdDeviationSmaList = GetMovingAverageList(stockData, maType, length2, standardDeviationList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double asd = stdDeviationSmaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var asd = stdDeviationSmaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; int dTime; try @@ -568,28 +568,28 @@ public static StockData CalculateDynamicMomentumIndex(this StockData stockData, dTime = upLimit; } - int dmiLength = Math.Max(Math.Min(dTime, upLimit), dnLimit); - double priceChg = MinPastValues(i, 1, currentValue - prevValue); + var dmiLength = Math.Max(Math.Min(dTime, upLimit), dnLimit); + var priceChg = MinPastValues(i, 1, currentValue - prevValue); - double loss = i >= 1 && priceChg < 0 ? Math.Abs(priceChg) : 0; + var loss = i >= 1 && priceChg < 0 ? Math.Abs(priceChg) : 0; lossList.AddRounded(loss); - double gain = i >= 1 && priceChg > 0 ? priceChg : 0; + var gain = i >= 1 && priceChg > 0 ? priceChg : 0; gainList.AddRounded(gain); - double avgGainSma = gainList.TakeLastExt(dmiLength).Average(); - double avgLossSma = lossList.TakeLastExt(dmiLength).Average(); - double rsSma = avgLossSma != 0 ? avgGainSma / avgLossSma : 0; + var avgGainSma = gainList.TakeLastExt(dmiLength).Average(); + var avgLossSma = lossList.TakeLastExt(dmiLength).Average(); + var rsSma = avgLossSma != 0 ? avgGainSma / avgLossSma : 0; - double prevDmiSma = dmiSmaList.LastOrDefault(); - double dmiSma = avgLossSma == 0 ? 100 : avgGainSma == 0 ? 0 : 100 - (100 / (1 + rsSma)); + var prevDmiSma = dmiSmaList.LastOrDefault(); + var dmiSma = avgLossSma == 0 ? 100 : avgGainSma == 0 ? 0 : 100 - (100 / (1 + rsSma)); dmiSmaList.AddRounded(dmiSma); - double dmiSignalSma = dmiSmaList.TakeLastExt(dmiLength).Average(); + var dmiSignalSma = dmiSmaList.TakeLastExt(dmiLength).Average(); dmiSignalSmaList.AddRounded(dmiSignalSma); - double prevDmiHistogram = dmiHistogramSmaList.LastOrDefault(); - double dmiHistogramSma = dmiSma - dmiSignalSma; + var prevDmiHistogram = dmiHistogramSmaList.LastOrDefault(); + var dmiHistogramSma = dmiSma - dmiSignalSma; dmiHistogramSmaList.AddRounded(dmiHistogramSma); var signal = GetRsiSignal(dmiHistogramSma, prevDmiHistogram, dmiSma, prevDmiSma, 70, 30); @@ -625,25 +625,25 @@ public static StockData CalculateSqueezeMomentumIndicator(this StockData stockDa var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double midprice = (highest + lowest) / 2; - double sma = smaList[i]; - double midpriceSmaAvg = (midprice + sma) / 2; - - double diff = currentValue - midpriceSmaAvg; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var midprice = (highest + lowest) / 2; + var sma = smaList[i]; + var midpriceSmaAvg = (midprice + sma) / 2; + + var diff = currentValue - midpriceSmaAvg; diffList.AddRounded(diff); } stockData.CustomValuesList = diffList; var linregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double predictedToday = linregList[i]; - double prevPredictedToday = i >= 1 ? linregList[i - 1] : 0; + var predictedToday = linregList[i]; + var prevPredictedToday = i >= 1 ? linregList[i - 1] : 0; var signal = GetCompareSignal(predictedToday, prevPredictedToday); signalsList.Add(signal); diff --git a/src/Calculations/MovingAvg.cs b/src/Calculations/MovingAvg.cs index f174f29..460f751 100644 --- a/src/Calculations/MovingAvg.cs +++ b/src/Calculations/MovingAvg.cs @@ -25,17 +25,17 @@ public static StockData CalculateSimpleMovingAverage(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevSma = smaList.LastOrDefault(); - double sma = tempList.Count >= length ? tempList.TakeLastExt(length).Average() : 0; + var prevSma = smaList.LastOrDefault(); + var sma = tempList.Count >= length ? tempList.TakeLastExt(length).Average() : 0; smaList.AddRounded(sma); - Signal signal = GetCompareSignal(currentValue - sma, prevValue - prevSma); + var signal = GetCompareSignal(currentValue - sma, prevValue - prevSma); signalsList.Add(signal); } @@ -62,26 +62,26 @@ public static StockData CalculateWeightedMovingAverage(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { double weight = length - j; - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevWma = wmaList.LastOrDefault(); - double wma = weightedSum != 0 ? sum / weightedSum : 0; + var prevWma = wmaList.LastOrDefault(); + var wma = weightedSum != 0 ? sum / weightedSum : 0; wmaList.AddRounded(wma); - Signal signal = GetCompareSignal(currentValue - wma, prevVal - prevWma); + var signal = GetCompareSignal(currentValue - wma, prevVal - prevWma); signalsList.Add(signal); } @@ -109,14 +109,14 @@ public static StockData CalculateExponentialMovingAverage(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = emaList.LastOrDefault(); - double ema = i < length ? tempList.Average() : CalculateEMA(currentValue, prevEma, length); + var prevEma = emaList.LastOrDefault(); + var ema = i < length ? tempList.Average() : CalculateEMA(currentValue, prevEma, length); emaList.AddRounded(ema); var signal = GetCompareSignal(currentValue - ema, prevValue - prevEma); @@ -149,12 +149,12 @@ public static StockData CalculateTriangularMovingAverage(this StockData stockDat var sma1List = GetMovingAverageList(stockData, maType, length, inputList); var tmaList = GetMovingAverageList(stockData, maType, length, sma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double tma = tmaList[i]; - double prevTma = i >= 1 ? tmaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var tma = tmaList[i]; + var prevTma = i >= 1 ? tmaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - tma, prevValue - prevTma); signalsList.Add(signal); @@ -185,28 +185,28 @@ public static StockData CalculateHullMovingAverage(this StockData stockData, Mov List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int length2 = MinOrMax((int)Math.Round((double)length / 2)); - int sqrtLength = MinOrMax((int)Math.Round(Sqrt(length))); + var length2 = MinOrMax((int)Math.Round((double)length / 2)); + var sqrtLength = MinOrMax((int)Math.Round(Sqrt(length))); var wma1List = GetMovingAverageList(stockData, maType, length, inputList); var wma2List = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentWMA1 = wma1List[i]; - double currentWMA2 = wma2List[i]; + var currentWMA1 = wma1List[i]; + var currentWMA2 = wma2List[i]; - double totalWeightedMA = (2 * currentWMA2) - currentWMA1; + var totalWeightedMA = (2 * currentWMA2) - currentWMA1; totalWeightedMAList.AddRounded(totalWeightedMA); } var hullMAList = GetMovingAverageList(stockData, maType, sqrtLength, totalWeightedMAList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double hullMa = hullMAList[i]; - double prevHullMa = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var hullMa = hullMAList[i]; + var prevHullMa = i >= 1 ? inputList[i - 1] : 0; var signal = GetCompareSignal(currentValue - hullMa, prevValue - prevHullMa); signalsList.Add(signal); @@ -239,27 +239,27 @@ public static StockData CalculateKaufmanAdaptiveMovingAverage(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double fastAlpha = (double)2 / (fastLength + 1); - double slowAlpha = (double)2 / (slowLength + 1); + var fastAlpha = (double)2 / (fastLength + 1); + var slowAlpha = (double)2 / (slowLength + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorValue = i >= length ? inputList[i - length] : 0; - double volatility = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); + var volatility = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); volatilityList.AddRounded(volatility); - double volatilitySum = volatilityList.TakeLastExt(length).Sum(); - double momentum = Math.Abs(MinPastValues(i, length, currentValue - priorValue)); + var volatilitySum = volatilityList.TakeLastExt(length).Sum(); + var momentum = Math.Abs(MinPastValues(i, length, currentValue - priorValue)); - double efficiencyRatio = volatilitySum != 0 ? momentum / volatilitySum : 0; + var efficiencyRatio = volatilitySum != 0 ? momentum / volatilitySum : 0; erList.AddRounded(efficiencyRatio); - double sc = Pow((efficiencyRatio * (fastAlpha - slowAlpha)) + slowAlpha, 2); - double prevKama = kamaList.LastOrDefault(); - double currentKAMA = (sc * currentValue) + ((1 - sc) * prevKama); + var sc = Pow((efficiencyRatio * (fastAlpha - slowAlpha)) + slowAlpha, 2); + var prevKama = kamaList.LastOrDefault(); + var currentKAMA = (sc * currentValue) + ((1 - sc) * prevKama); kamaList.AddRounded(currentKAMA); var signal = GetCompareSignal(currentValue - currentKAMA, prevValue - prevKama); @@ -292,26 +292,26 @@ public static StockData CalculateArnaudLegouxMovingAverage(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double m = offset * (length - 1); - double s = (double)length / sigma; + var m = offset * (length - 1); + var s = (double)length / sigma; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = s != 0 ? Exp(-1 * Pow(j - m, 2) / (2 * Pow(s, 2))) : 0; - double prevValue = i >= length - 1 - j ? inputList[i - (length - 1 - j)] : 0; + var weight = s != 0 ? Exp(-1 * Pow(j - m, 2) / (2 * Pow(s, 2))) : 0; + var prevValue = i >= length - 1 - j ? inputList[i - (length - 1 - j)] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevAlma = almaList.LastOrDefault(); - double alma = weightedSum != 0 ? sum / weightedSum : 0; + var prevAlma = almaList.LastOrDefault(); + var alma = weightedSum != 0 ? sum / weightedSum : 0; almaList.AddRounded(alma); var signal = GetCompareSignal(currentValue - alma, prevVal - prevAlma); @@ -342,23 +342,23 @@ public static StockData CalculateEndPointMovingAverage(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { double weight = length - j - length; - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevEpma = epmaList.LastOrDefault(); - double epma = weightedSum != 0 ? 1 / weightedSum * sum : 0; + var prevEpma = epmaList.LastOrDefault(); + var epma = weightedSum != 0 ? 1 / weightedSum * sum : 0; epmaList.AddRounded(epma); var signal = GetCompareSignal(currentValue - epma, prevVal - prevEpma); @@ -391,15 +391,15 @@ public static StockData CalculateLeastSquaresMovingAverage(this StockData stockD var wmaList = CalculateWeightedMovingAverage(stockData, length).CustomValuesList; var smaList = CalculateSimpleMovingAverage(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentWma = wmaList[i]; - double currentSma = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentWma = wmaList[i]; + var currentSma = smaList[i]; - double prevLsma = lsmaList.LastOrDefault(); - double lsma = (3 * currentWma) - (2 * currentSma); + var prevLsma = lsmaList.LastOrDefault(); + var lsma = (3 * currentWma) - (2 * currentSma); lsmaList.AddRounded(lsma); var signal = GetCompareSignal(currentValue - lsma, prevValue - prevLsma); @@ -442,87 +442,87 @@ public static StockData CalculateEhlersMotherOfAdaptiveMovingAverages(this Stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevPrice1 = i >= 1 ? inputList[i - 1] : 0; - double previ2 = i >= 1 ? i2List[i - 1] : 0; - double prevq2 = i >= 1 ? q2List[i - 1] : 0; - double prevRe = i >= 1 ? reList[i - 1] : 0; - double prevIm = i >= 1 ? imList[i - 1] : 0; - double prevSprd = i >= 1 ? sPrdList[i - 1] : 0; - double prevPhase = i >= 1 ? phaseList[i - 1] : 0; - double prevPeriod = i >= 1 ? periodList[i - 1] : 0; - double prevPrice2 = i >= 2 ? inputList[i - 2] : 0; - double prevPrice3 = i >= 3 ? inputList[i - 3] : 0; - double prevs2 = i >= 2 ? smoothList[i - 2] : 0; - double prevd2 = i >= 2 ? detList[i - 2] : 0; - double prevq1x2 = i >= 2 ? q1List[i - 2] : 0; - double previ1x2 = i >= 2 ? i1List[i - 2] : 0; - double prevd3 = i >= 3 ? detList[i - 3] : 0; - double prevs4 = i >= 4 ? smoothList[i - 4] : 0; - double prevd4 = i >= 4 ? detList[i - 4] : 0; - double prevq1x4 = i >= 4 ? q1List[i - 4] : 0; - double previ1x4 = i >= 4 ? i1List[i - 4] : 0; - double prevs6 = i >= 6 ? smoothList[i - 6] : 0; - double prevd6 = i >= 6 ? detList[i - 6] : 0; - double prevq1x6 = i >= 6 ? q1List[i - 6] : 0; - double previ1x6 = i >= 6 ? i1List[i - 6] : 0; - double prevMama = i >= 1 ? mamaList[i - 1] : 0; - double prevFama = i >= 1 ? famaList[i - 1] : 0; - - double smooth = ((4 * currentValue) + (3 * prevPrice1) + (2 * prevPrice2) + prevPrice3) / 10; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevPrice1 = i >= 1 ? inputList[i - 1] : 0; + var previ2 = i >= 1 ? i2List[i - 1] : 0; + var prevq2 = i >= 1 ? q2List[i - 1] : 0; + var prevRe = i >= 1 ? reList[i - 1] : 0; + var prevIm = i >= 1 ? imList[i - 1] : 0; + var prevSprd = i >= 1 ? sPrdList[i - 1] : 0; + var prevPhase = i >= 1 ? phaseList[i - 1] : 0; + var prevPeriod = i >= 1 ? periodList[i - 1] : 0; + var prevPrice2 = i >= 2 ? inputList[i - 2] : 0; + var prevPrice3 = i >= 3 ? inputList[i - 3] : 0; + var prevs2 = i >= 2 ? smoothList[i - 2] : 0; + var prevd2 = i >= 2 ? detList[i - 2] : 0; + var prevq1x2 = i >= 2 ? q1List[i - 2] : 0; + var previ1x2 = i >= 2 ? i1List[i - 2] : 0; + var prevd3 = i >= 3 ? detList[i - 3] : 0; + var prevs4 = i >= 4 ? smoothList[i - 4] : 0; + var prevd4 = i >= 4 ? detList[i - 4] : 0; + var prevq1x4 = i >= 4 ? q1List[i - 4] : 0; + var previ1x4 = i >= 4 ? i1List[i - 4] : 0; + var prevs6 = i >= 6 ? smoothList[i - 6] : 0; + var prevd6 = i >= 6 ? detList[i - 6] : 0; + var prevq1x6 = i >= 6 ? q1List[i - 6] : 0; + var previ1x6 = i >= 6 ? i1List[i - 6] : 0; + var prevMama = i >= 1 ? mamaList[i - 1] : 0; + var prevFama = i >= 1 ? famaList[i - 1] : 0; + + var smooth = ((4 * currentValue) + (3 * prevPrice1) + (2 * prevPrice2) + prevPrice3) / 10; smoothList.AddRounded(smooth); - double det = ((0.0962 * smooth) + (0.5769 * prevs2) - (0.5769 * prevs4) - (0.0962 * prevs6)) * ((0.075 * prevPeriod) + 0.54); + var det = ((0.0962 * smooth) + (0.5769 * prevs2) - (0.5769 * prevs4) - (0.0962 * prevs6)) * ((0.075 * prevPeriod) + 0.54); detList.AddRounded(det); - double q1 = ((0.0962 * det) + (0.5769 * prevd2) - (0.5769 * prevd4) - (0.0962 * prevd6)) * ((0.075 * prevPeriod) + 0.54); + var q1 = ((0.0962 * det) + (0.5769 * prevd2) - (0.5769 * prevd4) - (0.0962 * prevd6)) * ((0.075 * prevPeriod) + 0.54); q1List.AddRounded(q1); - double i1 = prevd3; + var i1 = prevd3; i1List.AddRounded(i1); - double j1 = ((0.0962 * i1) + (0.5769 * previ1x2) - (0.5769 * previ1x4) - (0.0962 * previ1x6)) * ((0.075 * prevPeriod) + 0.54); - double jq = ((0.0962 * q1) + (0.5769 * prevq1x2) - (0.5769 * prevq1x4) - (0.0962 * prevq1x6)) * ((0.075 * prevPeriod) + 0.54); + var j1 = ((0.0962 * i1) + (0.5769 * previ1x2) - (0.5769 * previ1x4) - (0.0962 * previ1x6)) * ((0.075 * prevPeriod) + 0.54); + var jq = ((0.0962 * q1) + (0.5769 * prevq1x2) - (0.5769 * prevq1x4) - (0.0962 * prevq1x6)) * ((0.075 * prevPeriod) + 0.54); - double i2 = i1 - jq; + var i2 = i1 - jq; i2 = (0.2 * i2) + (0.8 * previ2); i2List.AddRounded(i2); - double q2 = q1 + j1; + var q2 = q1 + j1; q2 = (0.2 * q2) + (0.8 * prevq2); q2List.AddRounded(q2); - double re = (i2 * previ2) + (q2 * prevq2); + var re = (i2 * previ2) + (q2 * prevq2); re = (0.2 * re) + (0.8 * prevRe); reList.AddRounded(re); - double im = (i2 * prevq2) - (q2 * previ2); + var im = (i2 * prevq2) - (q2 * previ2); im = (0.2 * im) + (0.8 * prevIm); imList.AddRounded(im); var atan = re != 0 ? Math.Atan(im / re) : 0; - double period = atan != 0 ? 2 * Math.PI / atan : 0; + var period = atan != 0 ? 2 * Math.PI / atan : 0; period = MinOrMax(period, 1.5 * prevPeriod, 0.67 * prevPeriod); period = MinOrMax(period, 50, 6); period = (0.2 * period) + (0.8 * prevPeriod); periodList.AddRounded(period); - double sPrd = (0.33 * period) + (0.67 * prevSprd); + var sPrd = (0.33 * period) + (0.67 * prevSprd); sPrdList.AddRounded(sPrd); - double phase = i1 != 0 ? Math.Atan(q1 / i1).ToDegrees() : 0; + var phase = i1 != 0 ? Math.Atan(q1 / i1).ToDegrees() : 0; phaseList.AddRounded(phase); - double deltaPhase = prevPhase - phase < 1 ? 1 : prevPhase - phase; - double alpha = deltaPhase != 0 ? fastAlpha / deltaPhase : 0; + var deltaPhase = prevPhase - phase < 1 ? 1 : prevPhase - phase; + var alpha = deltaPhase != 0 ? fastAlpha / deltaPhase : 0; alpha = alpha < slowAlpha ? slowAlpha : alpha; - double mama = (alpha * currentValue) + ((1 - alpha) * prevMama); + var mama = (alpha * currentValue) + ((1 - alpha) * prevMama); mamaList.AddRounded(mama); - double fama = (0.5 * alpha * mama) + ((1 - (0.5 * alpha)) * prevFama); + var fama = (0.5 * alpha * mama) + ((1 - (0.5 * alpha)) * prevFama); famaList.AddRounded(fama); var signal = GetCompareSignal(mama - fama, prevMama - prevFama); @@ -559,15 +559,15 @@ public static StockData CalculateWellesWilderMovingAverage(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double k = (double)1 / length; + var k = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevWwma = wwmaList.LastOrDefault(); - double wwma = (currentValue * k) + (prevWwma * (1 - k)); + var prevWwma = wwmaList.LastOrDefault(); + var wwma = (currentValue * k) + (prevWwma * (1 - k)); wwmaList.AddRounded(wwma); var signal = GetCompareSignal(currentValue - wwma, prevValue - prevWwma); @@ -600,10 +600,10 @@ public static StockData CalculateTillsonT3MovingAverage(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double c1 = -vFactor * vFactor * vFactor; - double c2 = (3 * vFactor * vFactor) + (3 * vFactor * vFactor * vFactor); - double c3 = (-6 * vFactor * vFactor) - (3 * vFactor) - (3 * vFactor * vFactor * vFactor); - double c4 = 1 + (3 * vFactor) + (vFactor * vFactor * vFactor) + (3 * vFactor * vFactor); + var c1 = -vFactor * vFactor * vFactor; + var c2 = (3 * vFactor * vFactor) + (3 * vFactor * vFactor * vFactor); + var c3 = (-6 * vFactor * vFactor) - (3 * vFactor) - (3 * vFactor * vFactor * vFactor); + var c4 = 1 + (3 * vFactor) + (vFactor * vFactor * vFactor) + (3 * vFactor * vFactor); var ema1List = GetMovingAverageList(stockData, maType, length, inputList); var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); @@ -612,17 +612,17 @@ public static StockData CalculateTillsonT3MovingAverage(this StockData stockData var ema5List = GetMovingAverageList(stockData, maType, length, ema4List); var ema6List = GetMovingAverageList(stockData, maType, length, ema5List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ema6 = ema6List[i]; - double ema5 = ema5List[i]; - double ema4 = ema4List[i]; - double ema3 = ema3List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ema6 = ema6List[i]; + var ema5 = ema5List[i]; + var ema4 = ema4List[i]; + var ema3 = ema3List[i]; - double prevT3 = t3List.LastOrDefault(); - double t3 = (c1 * ema6) + (c2 * ema5) + (c3 * ema4) + (c4 * ema3); + var prevT3 = t3List.LastOrDefault(); + var t3 = (c1 * ema6) + (c2 * ema5) + (c3 * ema4) + (c4 * ema3); t3List.AddRounded(t3); var signal = GetCompareSignal(currentValue - t3, prevValue - prevT3); @@ -658,16 +658,16 @@ public static StockData CalculateTripleExponentialMovingAverage(this StockData s var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); var ema3List = GetMovingAverageList(stockData, maType, length, ema2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentEma1 = ema1List[i]; - double currentEma2 = ema2List[i]; - double currentEma3 = ema3List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma1 = ema1List[i]; + var currentEma2 = ema2List[i]; + var currentEma3 = ema3List[i]; - double prevTema = temaList.LastOrDefault(); - double tema = (3 * currentEma1) - (3 * currentEma2) + currentEma3; + var prevTema = temaList.LastOrDefault(); + var tema = (3 * currentEma1) - (3 * currentEma2) + currentEma3; temaList.AddRounded(tema); var signal = GetCompareSignal(currentValue - tema, prevValue - prevTema); @@ -699,22 +699,22 @@ public static StockData CalculateVolumeWeightedAveragePrice(this StockData stock List signalsList = new(); var (inputList, _, _, _, _, volumeList) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; + var currentVolume = volumeList[i]; tempVolList.AddRounded(currentVolume); - double volumePrice = currentValue * currentVolume; + var volumePrice = currentValue * currentVolume; tempVolPriceList.AddRounded(volumePrice); - double volPriceSum = tempVolPriceList.Sum(); - double volSum = tempVolList.Sum(); + var volPriceSum = tempVolPriceList.Sum(); + var volSum = tempVolList.Sum(); - double prevVwap = vwapList.LastOrDefault(); - double vwap = volSum != 0 ? volPriceSum / volSum : 0; + var prevVwap = vwapList.LastOrDefault(); + var vwap = volSum != 0 ? volPriceSum / volSum : 0; vwapList.AddRounded(vwap); var signal = GetCompareSignal(currentValue - vwap, prevValue - prevVwap); @@ -749,20 +749,20 @@ public static StockData CalculateVolumeWeightedMovingAverage(this StockData stoc var volumeSmaList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double currentVolumeSma = volumeSmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var currentVolumeSma = volumeSmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double volumePrice = currentValue * currentVolume; + var volumePrice = currentValue * currentVolume; volumePriceList.AddRounded(volumePrice); - double volumePriceSma = volumePriceList.TakeLastExt(length).Average(); + var volumePriceSma = volumePriceList.TakeLastExt(length).Average(); - double prevVwma = vwmaList.LastOrDefault(); - double vwma = currentVolumeSma != 0 ? volumePriceSma / currentVolumeSma : 0; + var prevVwma = vwmaList.LastOrDefault(); + var vwma = currentVolumeSma != 0 ? volumePriceSma / currentVolumeSma : 0; vwmaList.AddRounded(vwma); var signal = GetCompareSignal(currentValue - vwma, prevValue - prevVwma); @@ -801,41 +801,41 @@ public static StockData CalculateUltimateMovingAverage(this StockData stockData, var lenList = CalculateVariableLengthMovingAverage(stockData, maType, minLength, maxLength).OutputValues["Length"]; var tpList = CalculateTypicalPrice(stockData).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = stockData.Volumes[i]; - double typicalPrice = tpList[i]; - double prevTypicalPrice = i >= 1 ? tpList[i - 1] : 0; - double length = MinOrMax(lenList[i], maxLength, minLength); - double rawMoneyFlow = typicalPrice * currentVolume; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = stockData.Volumes[i]; + var typicalPrice = tpList[i]; + var prevTypicalPrice = i >= 1 ? tpList[i - 1] : 0; + var length = MinOrMax(lenList[i], maxLength, minLength); + var rawMoneyFlow = typicalPrice * currentVolume; - double posMoneyFlow = i >= 1 && typicalPrice > prevTypicalPrice ? rawMoneyFlow : 0; + var posMoneyFlow = i >= 1 && typicalPrice > prevTypicalPrice ? rawMoneyFlow : 0; posMoneyFlowList.AddRounded(posMoneyFlow); - double negMoneyFlow = i >= 1 && typicalPrice < prevTypicalPrice ? rawMoneyFlow : 0; + var negMoneyFlow = i >= 1 && typicalPrice < prevTypicalPrice ? rawMoneyFlow : 0; negMoneyFlowList.AddRounded(negMoneyFlow); - int len = (int)length; - double posMoneyFlowTotal = posMoneyFlowList.TakeLastExt(len).Sum(); - double negMoneyFlowTotal = negMoneyFlowList.TakeLastExt(len).Sum(); - double mfiRatio = negMoneyFlowTotal != 0 ? posMoneyFlowTotal / negMoneyFlowTotal : 0; - double mfi = negMoneyFlowTotal == 0 ? 100 : posMoneyFlowTotal == 0 ? 0 : MinOrMax(100 - (100 / (1 + mfiRatio)), 100, 0); - double mfScaled = (mfi * 2) - 100; - double p = acc + (Math.Abs(mfScaled) / 25); + var len = (int)length; + var posMoneyFlowTotal = posMoneyFlowList.TakeLastExt(len).Sum(); + var negMoneyFlowTotal = negMoneyFlowList.TakeLastExt(len).Sum(); + var mfiRatio = negMoneyFlowTotal != 0 ? posMoneyFlowTotal / negMoneyFlowTotal : 0; + var mfi = negMoneyFlowTotal == 0 ? 100 : posMoneyFlowTotal == 0 ? 0 : MinOrMax(100 - (100 / (1 + mfiRatio)), 100, 0); + var mfScaled = (mfi * 2) - 100; + var p = acc + (Math.Abs(mfScaled) / 25); double sum = 0, weightedSum = 0; - for (int j = 0; j <= len - 1; j++) + for (var j = 0; j <= len - 1; j++) { - double weight = Pow(len - j, p); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(len - j, p); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevUma = umaList.LastOrDefault(); - double uma = weightedSum != 0 ? sum / weightedSum : 0; + var prevUma = umaList.LastOrDefault(); + var uma = weightedSum != 0 ? sum / weightedSum : 0; umaList.AddRounded(uma); var signal = GetCompareSignal(currentValue - uma, prevVal - prevUma); @@ -872,25 +872,25 @@ public static StockData CalculateVariableLengthMovingAverage(this StockData stoc var smaList = GetMovingAverageList(stockData, maType, maxLength, inputList); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, maxLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = smaList[i]; - double stdDev = stdDevList[i]; - double a = sma - (1.75 * stdDev); - double b = sma - (0.25 * stdDev); - double c = sma + (0.25 * stdDev); - double d = sma + (1.75 * stdDev); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; + var stdDev = stdDevList[i]; + var a = sma - (1.75 * stdDev); + var b = sma - (0.25 * stdDev); + var c = sma + (0.25 * stdDev); + var d = sma + (1.75 * stdDev); - double prevLength = i >= 1 ? lengthList[i - 1] : maxLength; - double length = MinOrMax(currentValue >= b && currentValue <= c ? prevLength + 1 : currentValue < a || + var prevLength = i >= 1 ? lengthList[i - 1] : maxLength; + var length = MinOrMax(currentValue >= b && currentValue <= c ? prevLength + 1 : currentValue < a || currentValue > d ? prevLength - 1 : prevLength, maxLength, minLength); lengthList.AddRounded(length); - double sc = 2 / (length + 1); - double prevVlma = i >= 1 ? vlmaList[i - 1] : currentValue; - double vlma = (currentValue * sc) + ((1 - sc) * prevVlma); + var sc = 2 / (length + 1); + var prevVlma = i >= 1 ? vlmaList[i - 1] : currentValue; + var vlma = (currentValue * sc) + ((1 - sc) * prevVlma); vlmaList.AddRounded(vlma); var signal = GetCompareSignal(currentValue - vlma, prevValue - prevVlma); @@ -921,14 +921,14 @@ public static StockData CalculateAhrensMovingAverage(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorAhma = i >= length ? ahmaList[i - length] : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorAhma = i >= length ? ahmaList[i - length] : currentValue; - double prevAhma = ahmaList.LastOrDefault(); - double ahma = prevAhma + ((currentValue - ((prevAhma + priorAhma) / 2)) / length); + var prevAhma = ahmaList.LastOrDefault(); + var ahma = prevAhma + ((currentValue - ((prevAhma + priorAhma) / 2)) / length); ahmaList.AddRounded(ahma); var signal = GetCompareSignal(currentValue - ahma, prevValue - prevAhma); @@ -961,20 +961,20 @@ public static StockData CalculateAdaptiveMovingAverage(this StockData stockData, var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length + 1); - double fastAlpha = (double)2 / (fastLength + 1); - double slowAlpha = (double)2 / (slowLength + 1); + var fastAlpha = (double)2 / (fastLength + 1); + var slowAlpha = (double)2 / (slowLength + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double hh = highestList[i]; - double ll = lowestList[i]; - double mltp = hh - ll != 0 ? MinOrMax(Math.Abs((2 * currentValue) - ll - hh) / (hh - ll), 1, 0) : 0; - double ssc = (mltp * (fastAlpha - slowAlpha)) + slowAlpha; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var hh = highestList[i]; + var ll = lowestList[i]; + var mltp = hh - ll != 0 ? MinOrMax(Math.Abs((2 * currentValue) - ll - hh) / (hh - ll), 1, 0) : 0; + var ssc = (mltp * (fastAlpha - slowAlpha)) + slowAlpha; - double prevAma = amaList.LastOrDefault(); - double ama = prevAma + (Pow(ssc, 2) * (currentValue - prevAma)); + var prevAma = amaList.LastOrDefault(); + var ama = prevAma + (Pow(ssc, 2) * (currentValue - prevAma)); amaList.AddRounded(ama); var signal = GetCompareSignal(currentValue - ama, prevValue - prevAma); @@ -1007,22 +1007,22 @@ public static StockData CalculateAdaptiveExponentialMovingAverage(this StockData var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - double mltp1 = (double)2 / (length + 1); + var mltp1 = (double)2 / (length + 1); var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double hh = highestList[i]; - double ll = lowestList[i]; - double sma = smaList[i]; - double mltp2 = hh - ll != 0 ? MinOrMax(Math.Abs((2 * currentValue) - ll - hh) / (hh - ll), 1, 0) : 0; - double rate = mltp1 * (1 + mltp2); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var hh = highestList[i]; + var ll = lowestList[i]; + var sma = smaList[i]; + var mltp2 = hh - ll != 0 ? MinOrMax(Math.Abs((2 * currentValue) - ll - hh) / (hh - ll), 1, 0) : 0; + var rate = mltp1 * (1 + mltp2); - double prevAema = i >= 1 ? aemaList.LastOrDefault() : currentValue; - double aema = i <= length ? sma : prevAema + (rate * (currentValue - prevAema)); + var prevAema = i >= 1 ? aemaList.LastOrDefault() : currentValue; + var aema = i <= length ? sma : prevAema + (rate * (currentValue - prevAema)); aemaList.AddRounded(aema); var signal = GetCompareSignal(currentValue - aema, prevValue - prevAema); @@ -1058,25 +1058,25 @@ public static StockData CalculateAdaptiveAutonomousRecursiveMovingAverage(this S var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double er = erList[i]; - double prevMa2 = i >= 1 ? ma2List[i - 1] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var er = erList[i]; + var prevMa2 = i >= 1 ? ma2List[i - 1] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double absDiff = Math.Abs(currentValue - prevMa2); + var absDiff = Math.Abs(currentValue - prevMa2); absDiffList.AddRounded(absDiff); - double d = i != 0 ? absDiffList.Sum() / i * gamma : 0; + var d = i != 0 ? absDiffList.Sum() / i * gamma : 0; dList.AddRounded(d); - double c = currentValue > prevMa2 + d ? currentValue + d : currentValue < prevMa2 - d ? currentValue - d : prevMa2; - double prevMa1 = i >= 1 ? ma1List[i - 1] : currentValue; - double ma1 = (er * c) + ((1 - er) * prevMa1); + var c = currentValue > prevMa2 + d ? currentValue + d : currentValue < prevMa2 - d ? currentValue - d : prevMa2; + var prevMa1 = i >= 1 ? ma1List[i - 1] : currentValue; + var ma1 = (er * c) + ((1 - er) * prevMa1); ma1List.AddRounded(ma1); - double ma2 = (er * ma1) + ((1 - er) * prevMa2); + var ma2 = (er * ma1) + ((1 - er) * prevMa2); ma2List.AddRounded(ma2); var signal = GetCompareSignal(currentValue - ma2, prevValue - prevMa2); @@ -1112,24 +1112,24 @@ public static StockData CalculateAutonomousRecursiveMovingAverage(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorValue = i >= length ? inputList[i - momLength] : 0; - double prevMad = i >= 1 ? madList[i - 1] : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorValue = i >= length ? inputList[i - momLength] : 0; + var prevMad = i >= 1 ? madList[i - 1] : currentValue; - double absDiff = Math.Abs(priorValue - prevMad); + var absDiff = Math.Abs(priorValue - prevMad); absDiffList.AddRounded(absDiff); - double d = i != 0 ? absDiffList.Sum() / i * gamma : 0; - double c = currentValue > prevMad + d ? currentValue + d : currentValue < prevMad - d ? currentValue - d : prevMad; + var d = i != 0 ? absDiffList.Sum() / i * gamma : 0; + var c = currentValue > prevMad + d ? currentValue + d : currentValue < prevMad - d ? currentValue - d : prevMad; cList.AddRounded(c); - double ma1 = cList.TakeLastExt(length).Average(); + var ma1 = cList.TakeLastExt(length).Average(); ma1List.AddRounded(ma1); - double mad = ma1List.TakeLastExt(length).Average(); + var mad = ma1List.TakeLastExt(length).Average(); madList.AddRounded(mad); var signal = GetCompareSignal(currentValue - mad, prevValue - prevMad); @@ -1171,57 +1171,57 @@ public static StockData CalculateAtrFilteredExponentialMovingAverage(this StockD List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - double trVal = currentValue != 0 ? tr / currentValue : tr; + var trVal = currentValue != 0 ? tr / currentValue : tr; trValList.AddRounded(trVal); } var atrValList = GetMovingAverageList(stockData, maType, atrLength, trValList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double atrVal = atrValList[i]; + var atrVal = atrValList[i]; - double atrValPow = Pow(atrVal, 2); + var atrValPow = Pow(atrVal, 2); atrValPowList.AddRounded(atrValPow); } var stdDevAList = GetMovingAverageList(stockData, maType, stdDevLength, atrValPowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDevA = stdDevAList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var stdDevA = stdDevAList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double atrVal = atrValList[i]; + var atrVal = atrValList[i]; tempList.AddRounded(atrVal); - double atrValSum = tempList.TakeLastExt(stdDevLength).Sum(); - double stdDevB = Pow(atrValSum, 2) / Pow(stdDevLength, 2); + var atrValSum = tempList.TakeLastExt(stdDevLength).Sum(); + var stdDevB = Pow(atrValSum, 2) / Pow(stdDevLength, 2); - double stdDev = stdDevA - stdDevB >= 0 ? Sqrt(stdDevA - stdDevB) : 0; + var stdDev = stdDevA - stdDevB >= 0 ? Sqrt(stdDevA - stdDevB) : 0; stdDevList.AddRounded(stdDev); - double stdDevLow = stdDevList.TakeLastExt(lbLength).Min(); - double stdDevFactorAFP = stdDev != 0 ? stdDevLow / stdDev : 0; - double stdDevFactorCTP = stdDevLow != 0 ? stdDev / stdDevLow : 0; - double stdDevFactorAFPLow = Math.Min(stdDevFactorAFP, min); - double stdDevFactorCTPLow = Math.Min(stdDevFactorCTP, min); - double alphaAfp = (2 * stdDevFactorAFPLow) / (length + 1); - double alphaCtp = (2 * stdDevFactorCTPLow) / (length + 1); + var stdDevLow = stdDevList.TakeLastExt(lbLength).Min(); + var stdDevFactorAFP = stdDev != 0 ? stdDevLow / stdDev : 0; + var stdDevFactorCTP = stdDevLow != 0 ? stdDev / stdDevLow : 0; + var stdDevFactorAFPLow = Math.Min(stdDevFactorAFP, min); + var stdDevFactorCTPLow = Math.Min(stdDevFactorCTP, min); + var alphaAfp = (2 * stdDevFactorAFPLow) / (length + 1); + var alphaCtp = (2 * stdDevFactorCTPLow) / (length + 1); - double prevEmaAfp = emaAFPList.LastOrDefault(); - double emaAfp = (alphaAfp * currentValue) + ((1 - alphaAfp) * prevEmaAfp); + var prevEmaAfp = emaAFPList.LastOrDefault(); + var emaAfp = (alphaAfp * currentValue) + ((1 - alphaAfp) * prevEmaAfp); emaAFPList.AddRounded(emaAfp); - double prevEmaCtp = emaCTPList.LastOrDefault(); - double emaCtp = (alphaCtp * currentValue) + ((1 - alphaCtp) * prevEmaCtp); + var prevEmaCtp = emaCTPList.LastOrDefault(); + var emaCtp = (alphaCtp * currentValue) + ((1 - alphaCtp) * prevEmaCtp); emaCTPList.AddRounded(emaCtp); var signal = GetCompareSignal(currentValue - emaAfp, prevValue - prevEmaAfp); @@ -1260,64 +1260,64 @@ public static StockData CalculateAdaptiveLeastSquares(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; double index = i; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); tempList.AddRounded(tr); - double highest = tempList.TakeLastExt(length).Max(); - double alpha = highest != 0 ? MinOrMax(Pow(tr / highest, smooth), 0.99, 0.01) : 0.01; - double xx = index * index; - double yy = currentValue * currentValue; - double xy = index * currentValue; + var highest = tempList.TakeLastExt(length).Max(); + var alpha = highest != 0 ? MinOrMax(Pow(tr / highest, smooth), 0.99, 0.01) : 0.01; + var xx = index * index; + var yy = currentValue * currentValue; + var xy = index * currentValue; - double prevX = i >= 1 ? xList[i - 1] : index; - double x = (alpha * index) + ((1 - alpha) * prevX); + var prevX = i >= 1 ? xList[i - 1] : index; + var x = (alpha * index) + ((1 - alpha) * prevX); xList.AddRounded(x); - double prevY = i >= 1 ? yList[i - 1] : currentValue; - double y = (alpha * currentValue) + ((1 - alpha) * prevY); + var prevY = i >= 1 ? yList[i - 1] : currentValue; + var y = (alpha * currentValue) + ((1 - alpha) * prevY); yList.AddRounded(y); - double dx = Math.Abs(index - x); - double dy = Math.Abs(currentValue - y); + var dx = Math.Abs(index - x); + var dy = Math.Abs(currentValue - y); - double prevMx = i >= 1 ? mxList[i - 1] : dx; - double mx = (alpha * dx) + ((1 - alpha) * prevMx); + var prevMx = i >= 1 ? mxList[i - 1] : dx; + var mx = (alpha * dx) + ((1 - alpha) * prevMx); mxList.AddRounded(mx); - double prevMy = i >= 1 ? myList[i - 1] : dy; - double my = (alpha * dy) + ((1 - alpha) * prevMy); + var prevMy = i >= 1 ? myList[i - 1] : dy; + var my = (alpha * dy) + ((1 - alpha) * prevMy); myList.AddRounded(my); - double prevMxx = i >= 1 ? mxxList[i - 1] : xx; - double mxx = (alpha * xx) + ((1 - alpha) * prevMxx); + var prevMxx = i >= 1 ? mxxList[i - 1] : xx; + var mxx = (alpha * xx) + ((1 - alpha) * prevMxx); mxxList.AddRounded(mxx); - double prevMyy = i >= 1 ? myyList[i - 1] : yy; - double myy = (alpha * yy) + ((1 - alpha) * prevMyy); + var prevMyy = i >= 1 ? myyList[i - 1] : yy; + var myy = (alpha * yy) + ((1 - alpha) * prevMyy); myyList.AddRounded(myy); - double prevMxy = i >= 1 ? mxyList[i - 1] : xy; - double mxy = (alpha * xy) + ((1 - alpha) * prevMxy); + var prevMxy = i >= 1 ? mxyList[i - 1] : xy; + var mxy = (alpha * xy) + ((1 - alpha) * prevMxy); mxyList.AddRounded(mxy); - double alphaVal = (2 / alpha) + 1; - double a1 = alpha != 0 ? (Pow(alphaVal, 2) * mxy) - (alphaVal * mx * alphaVal * my) : 0; - double tempVal = ((Pow(alphaVal, 2) * mxx) - Pow(alphaVal * mx, 2)) * ((Pow(alphaVal, 2) * myy) - Pow(alphaVal * my, 2)); - double b1 = tempVal >= 0 ? Sqrt(tempVal) : 0; - double r = b1 != 0 ? a1 / b1 : 0; - double a = mx != 0 ? r * (my / mx) : 0; - double b = y - (a * x); + var alphaVal = (2 / alpha) + 1; + var a1 = alpha != 0 ? (Pow(alphaVal, 2) * mxy) - (alphaVal * mx * alphaVal * my) : 0; + var tempVal = ((Pow(alphaVal, 2) * mxx) - Pow(alphaVal * mx, 2)) * ((Pow(alphaVal, 2) * myy) - Pow(alphaVal * my, 2)); + var b1 = tempVal >= 0 ? Sqrt(tempVal) : 0; + var r = b1 != 0 ? a1 / b1 : 0; + var a = mx != 0 ? r * (my / mx) : 0; + var b = y - (a * x); - double prevReg = regList.LastOrDefault(); - double reg = (x * a) + b; + var prevReg = regList.LastOrDefault(); + var reg = (x * a) + b; regList.AddRounded(reg); var signal = GetCompareSignal(currentValue - reg, prevValue - prevReg); @@ -1346,14 +1346,14 @@ public static StockData CalculateAlphaDecreasingExponentialMovingAverage(this St List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double alpha = (double)2 / (i + 1); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var alpha = (double)2 / (i + 1); - double prevEma = emaList.LastOrDefault(); - double ema = (alpha * currentValue) + ((1 - alpha) * prevEma); + var prevEma = emaList.LastOrDefault(); + var ema = (alpha * currentValue) + ((1 - alpha) * prevEma); emaList.AddRounded(ema); var signal = GetCompareSignal(currentValue - ema, prevValue - prevEma); @@ -1388,23 +1388,23 @@ public static StockData CalculatePoweredKaufmanAdaptiveMovingAverage(this StockD var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double er = erList[i]; - double powSp = er != 0 ? 1 / er : factor; - double perSp = Pow(er, powSp); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var er = erList[i]; + var powSp = er != 0 ? 1 / er : factor; + var perSp = Pow(er, powSp); - double per = Pow(er, factor); + var per = Pow(er, factor); perList.AddRounded(per); - double prevA = i >= 1 ? aList.LastOrDefault() : currentValue; - double a = (per * currentValue) + ((1 - per) * prevA); + var prevA = i >= 1 ? aList.LastOrDefault() : currentValue; + var a = (per * currentValue) + ((1 - per) * prevA); aList.AddRounded(a); - double prevASp = i >= 1 ? aSpList.LastOrDefault() : currentValue; - double aSp = (perSp * currentValue) + ((1 - perSp) * prevASp); + var prevASp = i >= 1 ? aSpList.LastOrDefault() : currentValue; + var aSp = (perSp * currentValue) + ((1 - perSp) * prevASp); aSpList.AddRounded(aSp); var signal = GetCompareSignal(currentValue - a, prevValue - prevA); @@ -1444,15 +1444,15 @@ public static StockData CalculateAutoFilter(this StockData stockData, MovingAvgT var yMaList = GetMovingAverageList(stockData, maType, length, inputList); var devList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dev = devList[i]; + var dev = devList[i]; - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevX = i >= 1 ? xList[i - 1] : currentValue; - double x = currentValue > prevX + dev ? currentValue : currentValue < prevX - dev ? currentValue : prevX; + var prevX = i >= 1 ? xList[i - 1] : currentValue; + var x = currentValue > prevX + dev ? currentValue : currentValue < prevX - dev ? currentValue : prevX; xList.AddRounded(x); var corr = GoodnessOfFit.R(tempList.TakeLastExt(length).Select(x => (double)x), xList.TakeLastExt(length).Select(x => (double)x)); @@ -1463,21 +1463,21 @@ public static StockData CalculateAutoFilter(this StockData stockData, MovingAvgT var xMaList = GetMovingAverageList(stockData, maType, length, xList); stockData.CustomValuesList = xList; var mxList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double my = devList[i]; - double mx = mxList[i]; - double corr = corrList[i]; - double yMa = yMaList[i]; - double xMa = xMaList[i]; - double x = xList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double slope = mx != 0 ? corr * (my / mx) : 0; - double inter = yMa - (slope * xMa); - - double prevReg = regList.LastOrDefault(); - double reg = (x * slope) + inter; + for (var i = 0; i < stockData.Count; i++) + { + var my = devList[i]; + var mx = mxList[i]; + var corr = corrList[i]; + var yMa = yMaList[i]; + var xMa = xMaList[i]; + var x = xList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var slope = mx != 0 ? corr * (my / mx) : 0; + var inter = yMa - (slope * xMa); + + var prevReg = regList.LastOrDefault(); + var reg = (x * slope) + inter; regList.AddRounded(reg); var signal = GetCompareSignal(currentValue - reg, prevValue - prevReg); @@ -1509,14 +1509,14 @@ public static StockData CalculateAutoLine(this StockData stockData, int length = var devList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dev = devList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var dev = devList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevX = i >= 1 ? xList[i - 1] : currentValue; - double x = currentValue > prevX + dev ? currentValue : currentValue < prevX - dev ? currentValue : prevX; + var prevX = i >= 1 ? xList[i - 1] : currentValue; + var x = currentValue > prevX + dev ? currentValue : currentValue < prevX - dev ? currentValue : prevX; xList.AddRounded(x); var signal = GetCompareSignal(currentValue - x, prevValue - prevX); @@ -1548,16 +1548,16 @@ public static StockData CalculateAutoLineWithDrift(this StockData stockData, int var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double dev = stdDevList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double r = Math.Round(currentValue); + var currentValue = inputList[i]; + var dev = stdDevList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var r = Math.Round(currentValue); - double prevA = i >= 1 ? aList[i - 1] : r; - double priorA = i >= length + 1 ? aList[i - (length + 1)] : r; - double a = currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : + var prevA = i >= 1 ? aList[i - 1] : r; + var priorA = i >= length + 1 ? aList[i - (length + 1)] : r; + var a = currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA + ((double)1 / (length * 2) * (prevA - priorA)); aList.AddRounded(a); @@ -1596,9 +1596,9 @@ public static StockData Calculate1LCLeastSquaresMovingAverage(this StockData sto var smaList = GetMovingAverageList(stockData, maType, length, inputList); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); double index = i; @@ -1609,16 +1609,16 @@ public static StockData Calculate1LCLeastSquaresMovingAverage(this StockData sto corrList.AddRounded((double)corr); } - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma = smaList[i]; - double corr = corrList[i]; - double stdDev = stdDevList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; + var corr = corrList[i]; + var stdDev = stdDevList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevY = yList.LastOrDefault(); - double y = sma + (corr * stdDev * 1.7); + var prevY = yList.LastOrDefault(); + var y = sma + (corr * stdDev * 1.7); yList.AddRounded(y); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); @@ -1649,31 +1649,31 @@ public static StockData Calculate3HMA(this StockData stockData, MovingAvgType ma List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int p = MinOrMax((int)Math.Ceiling((double)length / 2)); - int p1 = MinOrMax((int)Math.Ceiling((double)p / 3)); - int p2 = MinOrMax((int)Math.Ceiling((double)p / 2)); + var p = MinOrMax((int)Math.Ceiling((double)length / 2)); + var p1 = MinOrMax((int)Math.Ceiling((double)p / 3)); + var p2 = MinOrMax((int)Math.Ceiling((double)p / 2)); var wma1List = GetMovingAverageList(stockData, maType, p1, inputList); var wma2List = GetMovingAverageList(stockData, maType, p2, inputList); var wma3List = GetMovingAverageList(stockData, maType, p, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wma1 = wma1List[i]; - double wma2 = wma2List[i]; - double wma3 = wma3List[i]; + var wma1 = wma1List[i]; + var wma2 = wma2List[i]; + var wma3 = wma3List[i]; - double mid = (wma1 * 3) - wma2 - wma3; + var mid = (wma1 * 3) - wma2 - wma3; midList.AddRounded(mid); } var aList = GetMovingAverageList(stockData, maType, p, midList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = aList[i]; - double prevA = i >= 1 ? aList[i - 1] : 0; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var a = aList[i]; + var prevA = i >= 1 ? aList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; var signal = GetCompareSignal(currentValue - a, prevValue - prevA); signalsList.Add(signal); @@ -1702,14 +1702,14 @@ public static StockData CalculateJsaMovingAverage(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double priorValue = i >= length ? inputList[i - length] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var priorValue = i >= length ? inputList[i - length] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevJma = jmaList.LastOrDefault(); - double jma = (currentValue + priorValue) / 2; + var prevJma = jmaList.LastOrDefault(); + var jma = (currentValue + priorValue) / 2; jmaList.AddRounded(jma); var signal = GetCompareSignal(currentValue - jma, prevValue - prevJma); @@ -1744,33 +1744,33 @@ public static StockData CalculateJurikMovingAverage(this StockData stockData, in List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : ((double)phase / 100) + 1.5; - double ratio = 0.45 * (length - 1); - double beta = ratio / (ratio + 2); - double alpha = Pow(beta, power); + var phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : ((double)phase / 100) + 1.5; + var ratio = 0.45 * (length - 1); + var beta = ratio / (ratio + 2); + var alpha = Pow(beta, power); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevJma = jmaList.LastOrDefault(); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevJma = jmaList.LastOrDefault(); - double prevE0 = e0List.LastOrDefault(); - double e0 = ((1 - alpha) * currentValue) + (alpha * prevE0); + var prevE0 = e0List.LastOrDefault(); + var e0 = ((1 - alpha) * currentValue) + (alpha * prevE0); e0List.AddRounded(e0); - double prevE1 = e1List.LastOrDefault(); - double e1 = ((currentValue - e0) * (1 - beta)) + (beta * prevE1); + var prevE1 = e1List.LastOrDefault(); + var e1 = ((currentValue - e0) * (1 - beta)) + (beta * prevE1); e1List.AddRounded(e1); - double prevE2 = e2List.LastOrDefault(); - double e2 = ((e0 + (phaseRatio * e1) - prevJma) * Pow(1 - alpha, 2)) + (Pow(alpha, 2) * prevE2); + var prevE2 = e2List.LastOrDefault(); + var e2 = ((e0 + (phaseRatio * e1) - prevJma) * Pow(1 - alpha, 2)) + (Pow(alpha, 2) * prevE2); e2List.AddRounded(e2); - double jma = e2 + prevJma; + var jma = e2 + prevJma; jmaList.AddRounded(jma); - Signal signal = GetCompareSignal(currentValue - jma, prevValue - prevJma); + var signal = GetCompareSignal(currentValue - jma, prevValue - prevJma); signalsList.Add(signal); } @@ -1799,22 +1799,22 @@ public static StockData CalculateZeroLowLagMovingAverage(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int lbLength = MinOrMax((int)Math.Ceiling((double)length / 2)); + var lbLength = MinOrMax((int)Math.Ceiling((double)length / 2)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorB = i >= lbLength ? bList[i - lbLength] : currentValue; - double priorA = i >= length ? aList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorB = i >= lbLength ? bList[i - lbLength] : currentValue; + var priorA = i >= length ? aList[i - length] : 0; - double prevA = aList.LastOrDefault(); - double a = (lag * currentValue) + ((1 - lag) * priorB) + prevA; + var prevA = aList.LastOrDefault(); + var a = (lag * currentValue) + ((1 - lag) * priorB) + prevA; aList.AddRounded(a); - double aDiff = a - priorA; - double prevB = bList.LastOrDefault(); - double b = aDiff / length; + var aDiff = a - priorA; + var prevB = bList.LastOrDefault(); + var b = aDiff / length; bList.AddRounded(b); var signal = GetCompareSignal(currentValue - b, prevValue - prevB); @@ -1849,16 +1849,16 @@ public static StockData CalculateZeroLagExponentialMovingAverage(this StockData var ema1List = GetMovingAverageList(stockData, maType, length, inputList); var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ema1 = ema1List[i]; - double ema2 = ema2List[i]; - double d = ema1 - ema2; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ema1 = ema1List[i]; + var ema2 = ema2List[i]; + var d = ema1 - ema2; - double prevZema = zemaList.LastOrDefault(); - double zema = ema1 + d; + var prevZema = zemaList.LastOrDefault(); + var zema = ema1 + d; zemaList.AddRounded(zema); var signal = GetCompareSignal(currentValue - zema, prevValue - prevZema); @@ -1893,16 +1893,16 @@ public static StockData CalculateZeroLagTripleExponentialMovingAverage(this Stoc var tma1List = GetMovingAverageList(stockData, maType, length, inputList); var tma2List = GetMovingAverageList(stockData, maType, length, tma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double tma1 = tma1List[i]; - double tma2 = tma2List[i]; - double diff = tma1 - tma2; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var tma1 = tma1List[i]; + var tma2 = tma2List[i]; + var diff = tma1 - tma2; - double prevZltema = zlTemaList.LastOrDefault(); - double zltema = tma1 + diff; + var prevZltema = zlTemaList.LastOrDefault(); + var zltema = tma1 + diff; zlTemaList.AddRounded(zltema); var signal = GetCompareSignal(currentValue - zltema, prevValue - prevZltema); @@ -1936,18 +1936,18 @@ public static StockData CalculateBryantAdaptiveMovingAverage(this StockData stoc var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double er = erList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ver = Pow(er - (((2 * er) - 1) / 2 * (1 - trend)) + 0.5, 2); - double vLength = ver != 0 ? (length - ver + 1) / ver : 0; + var currentValue = inputList[i]; + var er = erList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ver = Pow(er - (((2 * er) - 1) / 2 * (1 - trend)) + 0.5, 2); + var vLength = ver != 0 ? (length - ver + 1) / ver : 0; vLength = Math.Min(vLength, maxLength); - double vAlpha = 2 / (vLength + 1); + var vAlpha = 2 / (vLength + 1); - double prevBama = bamaList.LastOrDefault(); - double bama = (vAlpha * currentValue) + ((1 - vAlpha) * prevBama); + var prevBama = bamaList.LastOrDefault(); + var bama = (vAlpha * currentValue) + ((1 - vAlpha) * prevBama); bamaList.AddRounded(bama); var signal = GetCompareSignal(currentValue - bama, prevValue - prevBama); @@ -1985,48 +1985,48 @@ public static StockData CalculateWindowedVolumeWeightedMovingAverage(this StockD List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double iRatio = (double)i / length; - double bartlett = 1 - (2 * Math.Abs(i - ((double)length / 2)) / length); + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var iRatio = (double)i / length; + var bartlett = 1 - (2 * Math.Abs(i - ((double)length / 2)) / length); - double bartlettW = bartlett * currentVolume; + var bartlettW = bartlett * currentVolume; bartlettWList.AddRounded(bartlettW); - double bartlettWSum = bartlettWList.TakeLastExt(length).Sum(); - double bartlettVW = currentValue * bartlettW; + var bartlettWSum = bartlettWList.TakeLastExt(length).Sum(); + var bartlettVW = currentValue * bartlettW; bartlettVWList.AddRounded(bartlettVW); - double bartlettVWSum = bartlettVWList.TakeLastExt(length).Sum(); - double prevBartlettWvwma = bartlettWvwmaList.LastOrDefault(); - double bartlettWvwma = bartlettWSum != 0 ? bartlettVWSum / bartlettWSum : 0; + var bartlettVWSum = bartlettVWList.TakeLastExt(length).Sum(); + var prevBartlettWvwma = bartlettWvwmaList.LastOrDefault(); + var bartlettWvwma = bartlettWSum != 0 ? bartlettVWSum / bartlettWSum : 0; bartlettWvwmaList.AddRounded(bartlettWvwma); - double blackman = 0.42 - (0.5 * Math.Cos(2 * Math.PI * iRatio)) + (0.08 * Math.Cos(4 * Math.PI * iRatio)); - double blackmanW = blackman * currentVolume; + var blackman = 0.42 - (0.5 * Math.Cos(2 * Math.PI * iRatio)) + (0.08 * Math.Cos(4 * Math.PI * iRatio)); + var blackmanW = blackman * currentVolume; blackmanWList.AddRounded(blackmanW); - double blackmanWSum = blackmanWList.TakeLastExt(length).Sum(); - double blackmanVW = currentValue * blackmanW; + var blackmanWSum = blackmanWList.TakeLastExt(length).Sum(); + var blackmanVW = currentValue * blackmanW; blackmanVWList.AddRounded(blackmanVW); - double blackmanVWSum = blackmanVWList.TakeLastExt(length).Sum(); - double blackmanWvwma = blackmanWSum != 0 ? blackmanVWSum / blackmanWSum : 0; + var blackmanVWSum = blackmanVWList.TakeLastExt(length).Sum(); + var blackmanWvwma = blackmanWSum != 0 ? blackmanVWSum / blackmanWSum : 0; blackmanWvwmaList.AddRounded(blackmanWvwma); - double hanning = 0.5 - (0.5 * Math.Cos(2 * Math.PI * iRatio)); - double hanningW = hanning * currentVolume; + var hanning = 0.5 - (0.5 * Math.Cos(2 * Math.PI * iRatio)); + var hanningW = hanning * currentVolume; hanningWList.AddRounded(hanningW); - double hanningWSum = hanningWList.TakeLastExt(length).Sum(); - double hanningVW = currentValue * hanningW; + var hanningWSum = hanningWList.TakeLastExt(length).Sum(); + var hanningVW = currentValue * hanningW; hanningVWList.AddRounded(hanningVW); - double hanningVWSum = hanningVWList.TakeLastExt(length).Sum(); - double hanningWvwma = hanningWSum != 0 ? hanningVWSum / hanningWSum : 0; + var hanningVWSum = hanningVWList.TakeLastExt(length).Sum(); + var hanningWvwma = hanningWSum != 0 ? hanningVWSum / hanningWSum : 0; hanningWvwmaList.AddRounded(hanningWvwma); var signal = GetCompareSignal(currentValue - bartlettWvwma, prevValue - prevBartlettWvwma); @@ -2061,36 +2061,36 @@ public static StockData CalculateWellRoundedMovingAverage(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSrcY = i >= 1 ? srcYList[i - 1] : 0; - double prevSrcEma = i >= 1 ? srcEmaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSrcY = i >= 1 ? srcYList[i - 1] : 0; + var prevSrcEma = i >= 1 ? srcEmaList[i - 1] : 0; - double prevA = aList.LastOrDefault(); - double a = prevA + (alpha * prevSrcY); + var prevA = aList.LastOrDefault(); + var a = prevA + (alpha * prevSrcY); aList.AddRounded(a); - double prevB = bList.LastOrDefault(); - double b = prevB + (alpha * prevSrcEma); + var prevB = bList.LastOrDefault(); + var b = prevB + (alpha * prevSrcEma); bList.AddRounded(b); - double ab = a + b; - double prevY = yList.LastOrDefault(); - double y = CalculateEMA(ab, prevY, 1); + var ab = a + b; + var prevY = yList.LastOrDefault(); + var y = CalculateEMA(ab, prevY, 1); yList.AddRounded(y); - double srcY = currentValue - y; + var srcY = currentValue - y; srcYList.AddRounded(srcY); - double prevYEma = yEmaList.LastOrDefault(); - double yEma = CalculateEMA(y, prevYEma, length); + var prevYEma = yEmaList.LastOrDefault(); + var yEma = CalculateEMA(y, prevYEma, length); yEmaList.AddRounded(yEma); - double srcEma = currentValue - yEma; + var srcEma = currentValue - yEma; srcEmaList.AddRounded(srcEma); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); @@ -2120,13 +2120,13 @@ public static StockData CalculateWellesWilderSummation(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSum = sumList.LastOrDefault(); - double sum = prevSum - (prevSum / length) + currentValue; + var prevSum = sumList.LastOrDefault(); + var sum = prevSum - (prevSum / length) + currentValue; sumList.AddRounded(sum); var signal = GetCompareSignal(currentValue - sum, prevValue - prevSum); @@ -2156,25 +2156,25 @@ public static StockData CalculateQuickMovingAverage(this StockData stockData, in List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int peak = MinOrMax((int)Math.Ceiling((double)length / 3)); + var peak = MinOrMax((int)Math.Ceiling((double)length / 3)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double num = 0, denom = 0; - for (int j = 1; j <= length + 1; j++) + for (var j = 1; j <= length + 1; j++) { - double mult = j <= peak ? (double)j / peak : (double)(length + 1 - j) / (length + 1 - peak); - double prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var mult = j <= peak ? (double)j / peak : (double)(length + 1 - j) / (length + 1 - peak); + var prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; num += prevValue * mult; denom += mult; } - double prevQma = qmaList.LastOrDefault(); - double qma = denom != 0 ? num / denom : 0; + var prevQma = qmaList.LastOrDefault(); + var qma = denom != 0 ? num / denom : 0; qmaList.AddRounded(qma); var signal = GetCompareSignal(currentValue - qma, prevVal - prevQma); @@ -2205,17 +2205,17 @@ public static StockData CalculateQuadraticMovingAverage(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double pow = Pow(currentValue, 2); + var pow = Pow(currentValue, 2); powList.AddRounded(pow); - double prevQma = qmaList.LastOrDefault(); - double powSma = powList.TakeLastExt(length).Average(); - double qma = powSma >= 0 ? Sqrt(powSma) : 0; + var prevQma = qmaList.LastOrDefault(); + var powSma = powList.TakeLastExt(length).Average(); + var qma = powSma >= 0 ? Sqrt(powSma) : 0; qmaList.AddRounded(qma); var signal = GetCompareSignal(currentValue - qma, prevValue - prevQma); @@ -2253,18 +2253,18 @@ public static StockData CalculateQuadrupleExponentialMovingAverage(this StockDat var ema4List = GetMovingAverageList(stockData, maType, length, ema3List); var ema5List = GetMovingAverageList(stockData, maType, length, ema4List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ema1 = ema1List[i]; - double ema2 = ema2List[i]; - double ema3 = ema3List[i]; - double ema4 = ema4List[i]; - double ema5 = ema5List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ema1 = ema1List[i]; + var ema2 = ema2List[i]; + var ema3 = ema3List[i]; + var ema4 = ema4List[i]; + var ema5 = ema5List[i]; - double prevQema = qemaList.LastOrDefault(); - double qema = (5 * ema1) - (10 * ema2) + (10 * ema3) - (5 * ema4) + ema5; + var prevQema = qemaList.LastOrDefault(); + var qema = (5 * ema1) - (10 * ema2) + (10 * ema3) - (5 * ema4) + ema5; qemaList.AddRounded(qema); var signal = GetCompareSignal(currentValue - qema, prevValue - prevQema); @@ -2308,23 +2308,23 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; double n = i; nList.AddRounded(n); - double n2 = Pow(n, 2); + var n2 = Pow(n, 2); n2List.AddRounded(n2); - double nn2 = n * n2; + var nn2 = n * n2; nn2List.AddRounded(nn2); - double n2v = n2 * currentValue; + var n2v = n2 * currentValue; n2vList.AddRounded(n2v); - double nv = n * currentValue; + var nv = n * currentValue; nvList.AddRounded(nv); } @@ -2333,22 +2333,22 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa var n2vSmaList = GetMovingAverageList(stockData, maType, length, n2vList); var nvSmaList = GetMovingAverageList(stockData, maType, length, nvList); var nn2SmaList = GetMovingAverageList(stockData, maType, length, nn2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nSma = nSmaList[i]; - double n2Sma = n2SmaList[i]; - double n2vSma = n2vSmaList[i]; - double nvSma = nvSmaList[i]; - double nn2Sma = nn2SmaList[i]; - double sma = smaList[i]; + var nSma = nSmaList[i]; + var n2Sma = n2SmaList[i]; + var n2vSma = n2vSmaList[i]; + var nvSma = nvSmaList[i]; + var nn2Sma = nn2SmaList[i]; + var sma = smaList[i]; - double nn2Cov = nn2Sma - (nSma * n2Sma); + var nn2Cov = nn2Sma - (nSma * n2Sma); nn2CovList.AddRounded(nn2Cov); - double n2vCov = n2vSma - (n2Sma * sma); + var n2vCov = n2vSma - (n2Sma * sma); n2vCovList.AddRounded(n2vCov); - double nvCov = nvSma - (nSma * sma); + var nvCov = nvSma - (nSma * sma); nvCovList.AddRounded(nvCov); } @@ -2356,29 +2356,29 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa var nVarianceList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; stockData.CustomValuesList = n2List; var n2VarianceList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double n2Variance = n2VarianceList[i]; - double nVariance = nVarianceList[i]; - double nn2Cov = nn2CovList[i]; - double n2vCov = n2vCovList[i]; - double nvCov = nvCovList[i]; - double sma = smaList[i]; - double n2Sma = n2SmaList[i]; - double nSma = nSmaList[i]; - double n2 = n2List[i]; - double norm = (n2Variance * nVariance) - Pow(nn2Cov, 2); - double a = norm != 0 ? ((n2vCov * nVariance) - (nvCov * nn2Cov)) / norm : 0; - double b = norm != 0 ? ((nvCov * n2Variance) - (n2vCov * nn2Cov)) / norm : 0; - double c = sma - (a * n2Sma) - (b * nSma); - - double prevQlsma = qlsmaList.LastOrDefault(); - double qlsma = (a * n2) + (b * i) + c; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var n2Variance = n2VarianceList[i]; + var nVariance = nVarianceList[i]; + var nn2Cov = nn2CovList[i]; + var n2vCov = n2vCovList[i]; + var nvCov = nvCovList[i]; + var sma = smaList[i]; + var n2Sma = n2SmaList[i]; + var nSma = nSmaList[i]; + var n2 = n2List[i]; + var norm = (n2Variance * nVariance) - Pow(nn2Cov, 2); + var a = norm != 0 ? ((n2vCov * nVariance) - (nvCov * nn2Cov)) / norm : 0; + var b = norm != 0 ? ((nvCov * n2Variance) - (n2vCov * nn2Cov)) / norm : 0; + var c = sma - (a * n2Sma) - (b * nSma); + + var prevQlsma = qlsmaList.LastOrDefault(); + var qlsma = (a * n2) + (b * i) + c; qlsmaList.AddRounded(qlsma); - double fcast = (a * Pow(i + forecastLength, 2)) + (b * (i + forecastLength)) + c; + var fcast = (a * Pow(i + forecastLength, 2)) + (b * (i + forecastLength)) + c; fcastList.AddRounded(fcast); var signal = GetCompareSignal(currentValue - qlsma, prevValue - prevQlsma); @@ -2425,82 +2425,82 @@ public static StockData CalculateQuadraticRegression(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double y = inputList[i]; + var y = inputList[i]; tempList.AddRounded(y); double x1 = i; x1List.AddRounded(x1); - double x2 = Pow(x1, 2); + var x2 = Pow(x1, 2); x2List.AddRounded(x2); - double x1x2 = x1 * x2; + var x1x2 = x1 * x2; x1x2List.AddRounded(x1x2); - double yx1 = y * x1; + var yx1 = y * x1; yx1List.AddRounded(yx1); - double yx2 = y * x2; + var yx2 = y * x2; yx2List.AddRounded(yx2); - double x2Pow = Pow(x2, 2); + var x2Pow = Pow(x2, 2); x2PowList.AddRounded(x2Pow); - double ySum = tempList.TakeLastExt(length).Sum(); + var ySum = tempList.TakeLastExt(length).Sum(); ySumList.AddRounded(ySum); - double x1Sum = x1List.TakeLastExt(length).Sum(); + var x1Sum = x1List.TakeLastExt(length).Sum(); x1SumList.AddRounded(x1Sum); - double x2Sum = x2List.TakeLastExt(length).Sum(); + var x2Sum = x2List.TakeLastExt(length).Sum(); x2SumList.AddRounded(x2Sum); - double x1x2Sum = x1x2List.TakeLastExt(length).Sum(); + var x1x2Sum = x1x2List.TakeLastExt(length).Sum(); x1x2SumList.AddRounded(x1x2Sum); - double yx1Sum = yx1List.TakeLastExt(length).Sum(); + var yx1Sum = yx1List.TakeLastExt(length).Sum(); yx1SumList.AddRounded(yx1Sum); - double yx2Sum = yx2List.TakeLastExt(length).Sum(); + var yx2Sum = yx2List.TakeLastExt(length).Sum(); yx2SumList.AddRounded(yx2Sum); - double x2PowSum = x2PowList.TakeLastExt(length).Sum(); + var x2PowSum = x2PowList.TakeLastExt(length).Sum(); x2PowSumList.AddRounded(x2PowSum); } var max1List = GetMovingAverageList(stockData, maType, length, x1List); var max2List = GetMovingAverageList(stockData, maType, length, x2List); var mayList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) - { - double x1Sum = x1SumList[i]; - double x2Sum = x2SumList[i]; - double x1x2Sum = x1x2SumList[i]; - double x2PowSum = x2PowSumList[i]; - double yx1Sum = yx1SumList[i]; - double yx2Sum = yx2SumList[i]; - double ySum = ySumList[i]; - double may = mayList[i]; - double max1 = max1List[i]; - double max2 = max2List[i]; - double x1 = x1List[i]; - double x2 = x2List[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double s11 = x2Sum - (Pow(x1Sum, 2) / length); - double s12 = x1x2Sum - ((x1Sum * x2Sum) / length); - double s22 = x2PowSum - (Pow(x2Sum, 2) / length); - double sy1 = yx1Sum - ((ySum * x1Sum) / length); - double sy2 = yx2Sum - ((ySum * x2Sum) / length); - double bot = (s22 * s11) - Pow(s12, 2); - double b2 = bot != 0 ? ((sy1 * s22) - (sy2 * s12)) / bot : 0; - double b3 = bot != 0 ? ((sy2 * s11) - (sy1 * s12)) / bot : 0; - double b1 = may - (b2 * max1) - (b3 * max2); - - double prevY = yList.LastOrDefault(); - double y = b1 + (b2 * x1) + (b3 * x2); + for (var i = 0; i < stockData.Count; i++) + { + var x1Sum = x1SumList[i]; + var x2Sum = x2SumList[i]; + var x1x2Sum = x1x2SumList[i]; + var x2PowSum = x2PowSumList[i]; + var yx1Sum = yx1SumList[i]; + var yx2Sum = yx2SumList[i]; + var ySum = ySumList[i]; + var may = mayList[i]; + var max1 = max1List[i]; + var max2 = max2List[i]; + var x1 = x1List[i]; + var x2 = x2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var s11 = x2Sum - (Pow(x1Sum, 2) / length); + var s12 = x1x2Sum - ((x1Sum * x2Sum) / length); + var s22 = x2PowSum - (Pow(x2Sum, 2) / length); + var sy1 = yx1Sum - ((ySum * x1Sum) / length); + var sy2 = yx2Sum - ((ySum * x2Sum) / length); + var bot = (s22 * s11) - Pow(s12, 2); + var b2 = bot != 0 ? ((sy1 * s22) - (sy2 * s12)) / bot : 0; + var b3 = bot != 0 ? ((sy2 * s11) - (sy1 * s12)) / bot : 0; + var b1 = may - (b2 * max1) - (b3 * max2); + + var prevY = yList.LastOrDefault(); + var y = b1 + (b2 * x1) + (b3 * x2); yList.AddRounded(y); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); @@ -2530,23 +2530,23 @@ public static StockData CalculateLinearWeightedMovingAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { double weight = length - j; - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevLwma = lwmaList.LastOrDefault(); - double lwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevLwma = lwmaList.LastOrDefault(); + var lwma = weightedSum != 0 ? sum / weightedSum : 0; lwmaList.AddRounded(lwma); var signal = GetCompareSignal(currentValue - lwma, prevVal - prevLwma); @@ -2579,15 +2579,15 @@ public static StockData CalculateLeoMovingAverage(this StockData stockData, int var wmaList = CalculateWeightedMovingAverage(stockData, length).CustomValuesList; var smaList = CalculateSimpleMovingAverage(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentWma = wmaList[i]; - double currentSma = smaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentWma = wmaList[i]; + var currentSma = smaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevLma = lmaList.LastOrDefault(); - double lma = (2 * currentWma) - currentSma; + var prevLma = lmaList.LastOrDefault(); + var lma = (2 * currentWma) - currentSma; lmaList.AddRounded(lma); var signal = GetCompareSignal(currentValue - lma, prevValue - prevLma); @@ -2620,9 +2620,9 @@ public static StockData CalculateLightLeastSquaresMovingAverage(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); + var length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double index = i; indexList.AddRounded(index); @@ -2634,20 +2634,20 @@ public static StockData CalculateLightLeastSquaresMovingAverage(this StockData s stockData.CustomValuesList = indexList; var indexStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var indexSmaList = GetMovingAverageList(stockData, maType, length, indexList); - for (int i = 0; i < stockData.Count; i++) - { - double sma1 = sma1List[i]; - double sma2 = sma2List[i]; - double stdDev = stdDevList[i]; - double indexStdDev = indexStdDevList[i]; - double indexSma = indexSmaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double c = stdDev != 0 ? (sma2 - sma1) / stdDev : 0; - double z = indexStdDev != 0 && c != 0 ? (i - indexSma) / indexStdDev * c : 0; - - double prevY = yList.LastOrDefault(); - double y = sma1 + (z * stdDev); + for (var i = 0; i < stockData.Count; i++) + { + var sma1 = sma1List[i]; + var sma2 = sma2List[i]; + var stdDev = stdDevList[i]; + var indexStdDev = indexStdDevList[i]; + var indexSma = indexSmaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var c = stdDev != 0 ? (sma2 - sma1) / stdDev : 0; + var z = indexStdDev != 0 && c != 0 ? (i - indexSma) / indexStdDev * c : 0; + + var prevY = yList.LastOrDefault(); + var y = sma1 + (z * stdDev); yList.AddRounded(y); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); @@ -2678,20 +2678,20 @@ public static StockData CalculateLinearExtrapolation(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevY = i >= 1 ? inputList[i - 1] : 0; - double priorY = i >= length ? inputList[i - length] : 0; - double priorY2 = i >= length * 2 ? inputList[i - (length * 2)] : 0; - double priorX = i >= length ? xList[i - length] : 0; - double priorX2 = i >= length * 2 ? xList[i - (length * 2)] : 0; + var currentValue = inputList[i]; + var prevY = i >= 1 ? inputList[i - 1] : 0; + var priorY = i >= length ? inputList[i - length] : 0; + var priorY2 = i >= length * 2 ? inputList[i - (length * 2)] : 0; + var priorX = i >= length ? xList[i - length] : 0; + var priorX2 = i >= length * 2 ? xList[i - (length * 2)] : 0; double x = i; xList.AddRounded(i); - double prevExt = extList.LastOrDefault(); - double ext = priorX2 - priorX != 0 && priorY2 - priorY != 0 ? priorY + ((x - priorX) / (priorX2 - priorX) * (priorY2 - priorY)) : priorY; + var prevExt = extList.LastOrDefault(); + var ext = priorX2 - priorX != 0 && priorY2 - priorY != 0 ? priorY + ((x - priorX) / (priorX2 - priorX) * (priorY2 - priorY)) : priorY; extList.AddRounded(ext); var signal = GetCompareSignal(currentValue - ext, prevY - prevExt); @@ -2729,9 +2729,9 @@ public static StockData CalculateLinearRegressionLine(this StockData stockData, var yMaList = GetMovingAverageList(stockData, maType, length, inputList); var myList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; yList.AddRounded(currentValue); double x = i; @@ -2745,21 +2745,21 @@ public static StockData CalculateLinearRegressionLine(this StockData stockData, var xMaList = GetMovingAverageList(stockData, maType, length, xList); stockData.CustomValuesList = xList; var mxList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; ; - for (int i = 0; i < stockData.Count; i++) - { - double my = myList[i]; - double mx = mxList[i]; - double corr = corrList[i]; - double yMa = yMaList[i]; - double xMa = xMaList[i]; - double x = xList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double slope = mx != 0 ? corr * (my / mx) : 0; - double inter = yMa - (slope * xMa); - - double prevReg = regList.LastOrDefault(); - double reg = (x * slope) + inter; + for (var i = 0; i < stockData.Count; i++) + { + var my = myList[i]; + var mx = mxList[i]; + var corr = corrList[i]; + var yMa = yMaList[i]; + var xMa = xMaList[i]; + var x = xList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var slope = mx != 0 ? corr * (my / mx) : 0; + var inter = yMa - (slope * xMa); + + var prevReg = regList.LastOrDefault(); + var reg = (x * slope) + inter; regList.AddRounded(reg); var signal = GetCompareSignal(currentValue - reg, prevValue - prevReg); @@ -2790,20 +2790,20 @@ public static StockData CalculateIIRLeastSquaresEstimate(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a = (double)4 / (length + 2); - int halfLength = MinOrMax((int)Math.Ceiling((double)length / 2)); + var a = (double)4 / (length + 2); + var halfLength = MinOrMax((int)Math.Ceiling((double)length / 2)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevS = i >= 1 ? sList[i - 1] : currentValue; - double prevSEma = sEmaList.LastOrDefault(); - double sEma = CalculateEMA(prevS, prevSEma, halfLength); + var prevS = i >= 1 ? sList[i - 1] : currentValue; + var prevSEma = sEmaList.LastOrDefault(); + var sEma = CalculateEMA(prevS, prevSEma, halfLength); sEmaList.AddRounded(prevSEma); - double s = (a * currentValue) + prevS - (a * sEma); + var s = (a * currentValue) + prevS - (a * sEma); sList.AddRounded(s); var signal = GetCompareSignal(currentValue - s, prevValue - prevS); @@ -2833,20 +2833,20 @@ public static StockData CalculateInverseDistanceWeightedMovingAverage(this Stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; double weight = 0; - for (int k = 0; k <= length - 1; k++) + for (var k = 0; k <= length - 1; k++) { - double prevValue2 = i >= k ? inputList[i - k] : 0; + var prevValue2 = i >= k ? inputList[i - k] : 0; weight += Math.Abs(prevValue - prevValue2); } @@ -2854,8 +2854,8 @@ public static StockData CalculateInverseDistanceWeightedMovingAverage(this Stock weightedSum += weight; } - double prevIdwma = idwmaList.LastOrDefault(); - double idwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevIdwma = idwmaList.LastOrDefault(); + var idwma = weightedSum != 0 ? sum / weightedSum : 0; idwmaList.AddRounded(idwma); var signal = GetCompareSignal(currentValue - idwma, prevVal - prevIdwma); @@ -2889,25 +2889,25 @@ public static StockData CalculateTrimean(this StockData stockData, int length = List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = tempList.LastOrDefault(); - double currentValue = inputList[i]; + var prevValue = tempList.LastOrDefault(); + var currentValue = inputList[i]; tempList.AddRounded(currentValue); var lookBackList = tempList.TakeLastExt(length); - double q1 = lookBackList.PercentileNearestRank(25); + var q1 = lookBackList.PercentileNearestRank(25); q1List.AddRounded(q1); - double median = lookBackList.PercentileNearestRank(50); + var median = lookBackList.PercentileNearestRank(50); medianList.AddRounded(median); - double q3 = lookBackList.PercentileNearestRank(75); + var q3 = lookBackList.PercentileNearestRank(75); q3List.AddRounded(q3); - double prevTrimean = trimeanList.LastOrDefault(); - double trimean = (q1 + (2 * median) + q3) / 4; + var prevTrimean = trimeanList.LastOrDefault(); + var trimean = (q1 + (2 * median) + q3) / 4; trimeanList.AddRounded(trimean); var signal = GetCompareSignal(currentValue - trimean, prevValue - prevTrimean); @@ -2942,29 +2942,29 @@ public static StockData CalculateOptimalWeightedMovingAverage(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevVal = tempList.LastOrDefault(); - double currentValue = inputList[i]; + var prevVal = tempList.LastOrDefault(); + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevOwma = i >= 1 ? owmaList[i - 1] : 0; + var prevOwma = i >= 1 ? owmaList[i - 1] : 0; prevOwmaList.AddRounded(prevOwma); var corr = GoodnessOfFit.R(tempList.TakeLastExt(length).Select(x => (double)x), prevOwmaList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Pow(length - j, (double)corr); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(length - j, (double)corr); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double owma = weightedSum != 0 ? sum / weightedSum : 0; + var owma = weightedSum != 0 ? sum / weightedSum : 0; owmaList.AddRounded(owma); var signal = GetCompareSignal(currentValue - owma, prevVal - prevOwma); @@ -3001,14 +3001,14 @@ public static StockData CalculateOvershootReductionMovingAverage(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int length1 = (int)Math.Ceiling((double)length / 2); + var length1 = (int)Math.Ceiling((double)length / 2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double index = i; indexList.AddRounded(index); - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); var corr = GoodnessOfFit.R(indexList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); @@ -3021,29 +3021,29 @@ public static StockData CalculateOvershootReductionMovingAverage(this StockData var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; stockData.CustomValuesList = indexList; var indexStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double index = indexList[i]; - double indexSma = indexSmaList[i]; - double indexStdDev = indexStdDevList[i]; - double corr = corrList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevD = i >= 1 ? dList[i - 1] != 0 ? dList[i - 1] : prevValue : prevValue; - double sma = smaList[i]; - double stdDev = stdDevList[i]; - double a = indexStdDev != 0 && corr != 0 ? (index - indexSma) / indexStdDev * corr : 0; - - double b = Math.Abs(prevD - currentValue); + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var index = indexList[i]; + var indexSma = indexSmaList[i]; + var indexStdDev = indexStdDevList[i]; + var corr = corrList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevD = i >= 1 ? dList[i - 1] != 0 ? dList[i - 1] : prevValue : prevValue; + var sma = smaList[i]; + var stdDev = stdDevList[i]; + var a = indexStdDev != 0 && corr != 0 ? (index - indexSma) / indexStdDev * corr : 0; + + var b = Math.Abs(prevD - currentValue); bList.AddRounded(b); - double bSma = bList.TakeLastExt(length1).Average(); + var bSma = bList.TakeLastExt(length1).Average(); bSmaList.AddRounded(bSma); - double highest = bSmaList.TakeLastExt(length).Max(); - double c = highest != 0 ? b / highest : 0; + var highest = bSmaList.TakeLastExt(length).Max(); + var c = highest != 0 ? b / highest : 0; - double d = sma + (a * (stdDev * c)); + var d = sma + (a * (stdDev * c)); dList.AddRounded(d); var signal = GetCompareSignal(currentValue - d, prevValue - prevD); @@ -3075,18 +3075,18 @@ public static StockData CalculateVariableIndexDynamicAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); var cmoList = CalculateChandeMomentumOscillator(stockData, maType, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentCmo = Math.Abs(cmoList[i] / 100); - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentCmo = Math.Abs(cmoList[i] / 100); + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevVidya = vidyaList.LastOrDefault(); - double currentVidya = (currentValue * alpha * currentCmo) + (prevVidya * (1 - (alpha * currentCmo))); + var prevVidya = vidyaList.LastOrDefault(); + var currentVidya = (currentValue * alpha * currentCmo) + (prevVidya * (1 - (alpha * currentCmo))); vidyaList.AddRounded(currentVidya); var signal = GetCompareSignal(currentValue - currentVidya, prevValue - prevVidya); @@ -3117,27 +3117,27 @@ public static StockData CalculateNaturalMovingAverage(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; + var ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; lnList.AddRounded(ln); double num = 0, denom = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double currentLn = i >= j ? lnList[i - j] : 0; - double prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; - double oi = Math.Abs(currentLn - prevLn); + var currentLn = i >= j ? lnList[i - j] : 0; + var prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; + var oi = Math.Abs(currentLn - prevLn); num += oi * (Sqrt(j + 1) - Sqrt(j)); denom += oi; } - double ratio = denom != 0 ? num / denom : 0; - double prevNma = nmaList.LastOrDefault(); - double nma = (currentValue * ratio) + (prevValue * (1 - ratio)); + var ratio = denom != 0 ? num / denom : 0; + var prevNma = nmaList.LastOrDefault(); + var nma = (currentValue * ratio) + (prevValue * (1 - ratio)); nmaList.AddRounded(nma); var signal = GetCompareSignal(currentValue - nma, prevValue - prevNma); @@ -3167,54 +3167,54 @@ public static StockData CalculateSymmetricallyWeightedMovingAverage(this StockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int floorLength = (int)Math.Floor((double)length / 2); - int roundLength = (int)Math.Round((double)length / 2); + var floorLength = (int)Math.Floor((double)length / 2); + var roundLength = (int)Math.Round((double)length / 2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double nr = 0, nl = 0, sr = 0, sl = 0; if (floorLength == roundLength) { - for (int j = 0; j <= floorLength - 1; j++) + for (var j = 0; j <= floorLength - 1; j++) { double wr = (length - (length - 1 - j)) * length; - double prevVal = i >= j ? inputList[i - j] : 0; + var prevVal = i >= j ? inputList[i - j] : 0; nr += wr; sr += prevVal * wr; } - for (int j = floorLength; j <= length - 1; j++) + for (var j = floorLength; j <= length - 1; j++) { double wl = (length - j) * length; - double prevVal = i >= j ? inputList[i - j] : 0; + var prevVal = i >= j ? inputList[i - j] : 0; nl += wl; sl += prevVal * wl; } } else { - for (int j = 0; j <= floorLength; j++) + for (var j = 0; j <= floorLength; j++) { double wr = (length - (length - 1 - j)) * length; - double prevVal = i >= j ? inputList[i - j] : 0; + var prevVal = i >= j ? inputList[i - j] : 0; nr += wr; sr += prevVal * wr; } - for (int j = roundLength; j <= length - 1; j++) + for (var j = roundLength; j <= length - 1; j++) { double wl = (length - j) * length; - double prevVal = i >= j ? inputList[i - j] : 0; + var prevVal = i >= j ? inputList[i - j] : 0; nl += wl; sl += prevVal * wl; } } - double prevSwma = swmaList.LastOrDefault(); - double swma = nr + nl != 0 ? (sr + sl) / (nr + nl) : 0; + var prevSwma = swmaList.LastOrDefault(); + var swma = nr + nl != 0 ? (sr + sl) / (nr + nl) : 0; swmaList.AddRounded(swma); var signal = GetCompareSignal(currentValue - swma, prevValue - prevSwma); @@ -3250,15 +3250,15 @@ public static StockData CalculateGeneralizedDoubleExponentialMovingAverage(this var ema1List = GetMovingAverageList(stockData, maType, length, inputList); var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentEma1 = ema1List[i]; - double currentEma2 = ema2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma1 = ema1List[i]; + var currentEma2 = ema2List[i]; - double prevGd = gdList.LastOrDefault(); - double gd = (currentEma1 * (1 + factor)) - (currentEma2 * factor); + var prevGd = gdList.LastOrDefault(); + var gd = (currentEma1 * (1 + factor)) - (currentEma2 * factor); gdList.AddRounded(gd); var signal = GetCompareSignal(currentValue - gd, prevValue - prevGd); @@ -3293,24 +3293,24 @@ public static StockData CalculateGeneralFilterEstimator(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int p = beta != 0 ? (int)Math.Ceiling(length / beta) : 0; + var p = beta != 0 ? (int)Math.Ceiling(length / beta) : 0; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorB = i >= p ? bList[i - p] : currentValue; - double a = currentValue - priorB; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorB = i >= p ? bList[i - p] : currentValue; + var a = currentValue - priorB; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double b = prevB + (a / p * gamma); + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var b = prevB + (a / p * gamma); bList.AddRounded(b); - double priorD = i >= p ? dList[i - p] : b; - double c = b - priorD; + var priorD = i >= p ? dList[i - p] : b; + var c = b - priorD; - double prevD = i >= 1 ? dList[i - 1] : currentValue; - double d = prevD + (((zeta * a) + ((1 - zeta) * c)) / p * gamma); + var prevD = i >= 1 ? dList[i - 1] : currentValue; + var d = prevD + (((zeta * a) + ((1 - zeta) * c)) / p * gamma); dList.AddRounded(d); var signal = GetCompareSignal(currentValue - d, prevValue - prevD); @@ -3340,31 +3340,31 @@ public static StockData CalculateHendersonWeightedMovingAverage(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int termMult = MinOrMax((int)Math.Floor((double)(length - 1) / 2)); + var termMult = MinOrMax((int)Math.Floor((double)(length - 1) / 2)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - int m = termMult; - int n = j - termMult; - double numerator = 315 * (Pow(m + 1, 2) - Pow(n, 2)) * (Pow(m + 2, 2) - Pow(n, 2)) * (Pow(m + 3, 2) - + var m = termMult; + var n = j - termMult; + var numerator = 315 * (Pow(m + 1, 2) - Pow(n, 2)) * (Pow(m + 2, 2) - Pow(n, 2)) * (Pow(m + 3, 2) - Pow(n, 2)) * ((3 * Pow(m + 2, 2)) - (11 * Pow(n, 2)) - 16); - double denominator = 8 * (m + 2) * (Pow(m + 2, 2) - 1) * ((4 * Pow(m + 2, 2)) - 1) * ((4 * Pow(m + 2, 2)) - 9) * - ((4 * Pow(m + 2, 2)) - 25); - double weight = denominator != 0 ? numerator / denominator : 0; - double prevValue = i >= j ? inputList[i - j] : 0; + var denominator = 8 * (m + 2) * (Pow(m + 2, 2) - 1) * ((4 * Pow(m + 2, 2)) - 1) * ((4 * Pow(m + 2, 2)) - 9) * + ((4 * Pow(m + 2, 2)) - 25); + var weight = denominator != 0 ? numerator / denominator : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevHwma = hwmaList.LastOrDefault(); - double hwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevHwma = hwmaList.LastOrDefault(); + var hwma = weightedSum != 0 ? sum / weightedSum : 0; hwmaList.AddRounded(hwma); var signal = GetCompareSignal(currentValue - hwma, prevVal - prevHwma); @@ -3396,20 +3396,20 @@ public static StockData CalculateHoltExponentialMovingAverage(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (alphaLength + 1); - double gamma = (double)2 / (gammaLength + 1); + var alpha = (double)2 / (alphaLength + 1); + var gamma = (double)2 / (gammaLength + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHema = hemaList.LastOrDefault(); - double hema = ((1 - alpha) * (prevHema + prevB)) + (alpha * currentValue); + var prevHema = hemaList.LastOrDefault(); + var hema = ((1 - alpha) * (prevHema + prevB)) + (alpha * currentValue); hemaList.AddRounded(hema); - double b = ((1 - gamma) * prevB) + (gamma * (hema - prevHema)); + var b = ((1 - gamma) * prevB) + (gamma * (hema - prevHema)); bList.AddRounded(b); var signal = GetCompareSignal(currentValue - hema, prevValue - prevHema); @@ -3439,20 +3439,20 @@ public static StockData CalculateHullEstimate(this StockData stockData, int leng List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int maLength = MinOrMax((int)Math.Ceiling((double)length / 2)); + var maLength = MinOrMax((int)Math.Ceiling((double)length / 2)); var wmaList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, maLength, inputList); var emaList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, maLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentWma = wmaList[i]; - double currentEma = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentWma = wmaList[i]; + var currentEma = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHema = hemaList.LastOrDefault(); - double hema = (3 * currentWma) - (2 * currentEma); + var prevHema = hemaList.LastOrDefault(); + var hema = (3 * currentWma) - (2 * currentEma); hemaList.AddRounded(hema); var signal = GetCompareSignal(currentValue - hema, prevValue - prevHema); @@ -3486,24 +3486,24 @@ public static StockData CalculateHampelFilter(this StockData stockData, int leng List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = tempList.LastOrDefault(); - double currentValue = inputList[i]; + var prevValue = tempList.LastOrDefault(); + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double sampleMedian = tempList.TakeLastExt(length).Median(); - double absDiff = Math.Abs(currentValue - sampleMedian); + var sampleMedian = tempList.TakeLastExt(length).Median(); + var absDiff = Math.Abs(currentValue - sampleMedian); absDiffList.AddRounded(absDiff); - double mad = absDiffList.TakeLastExt(length).Median(); - double hf = absDiff <= scalingFactor * mad ? currentValue : sampleMedian; + var mad = absDiffList.TakeLastExt(length).Median(); + var hf = absDiff <= scalingFactor * mad ? currentValue : sampleMedian; hfList.AddRounded(hf); - double prevHfEma = hfEmaList.LastOrDefault(); - double hfEma = (alpha * hf) + ((1 - alpha) * prevHfEma); + var prevHfEma = hfEmaList.LastOrDefault(); + var hfEma = (alpha * hf) + ((1 - alpha) * prevHfEma); hfEmaList.AddRounded(hfEma); var signal = GetCompareSignal(currentValue - hfEma, prevValue - prevHfEma); @@ -3533,18 +3533,18 @@ public static StockData CalculateHybridConvolutionFilter(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; - double prevOutput = i >= 1 ? outputList[i - 1] : currentValue; + var prevOutput = i >= 1 ? outputList[i - 1] : currentValue; double output = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double sign = 0.5 * (1 - Math.Cos(MinOrMax((double)j / length * Math.PI, 0.99, 0.01))); - double d = sign - (0.5 * (1 - Math.Cos(MinOrMax((double)(j - 1) / length, 0.99, 0.01)))); - double prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var sign = 0.5 * (1 - Math.Cos(MinOrMax((double)j / length * Math.PI, 0.99, 0.01))); + var d = sign - (0.5 * (1 - Math.Cos(MinOrMax((double)(j - 1) / length, 0.99, 0.01)))); + var prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; output += ((sign * prevOutput) + ((1 - sign) * prevValue)) * d; } outputList.AddRounded(output); @@ -3576,26 +3576,26 @@ public static StockData CalculateFibonacciWeightedMovingAverage(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double phi = (1 + Sqrt(5)) / 2; + var phi = (1 + Sqrt(5)) / 2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double pow = Pow(phi, length - j); - double weight = (pow - (Pow(-1, j) / pow)) / Sqrt(5); - double prevValue = i >= j ? inputList[i - j] : 0; + var pow = Pow(phi, length - j); + var weight = (pow - (Pow(-1, j) / pow)) / Sqrt(5); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevFwma = fibonacciWmaList.LastOrDefault(); - double fwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevFwma = fibonacciWmaList.LastOrDefault(); + var fwma = weightedSum != 0 ? sum / weightedSum : 0; fibonacciWmaList.AddRounded(fwma); var signal = GetCompareSignal(currentValue - fwma, prevVal - prevFwma); @@ -3625,43 +3625,43 @@ public static StockData CalculateFareySequenceWeightedMovingAverage(this StockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double[] array = new double[4] { 0, 1, 1, length }; + var array = new double[4] { 0, 1, 1, length }; List resList = new(); while (array[2] <= length) { - double a = array[0]; - double b = array[1]; - double c = array[2]; - double d = array[3]; - double k = Math.Floor((length + b) / array[3]); + var a = array[0]; + var b = array[1]; + var c = array[2]; + var d = array[3]; + var k = Math.Floor((length + b) / array[3]); array[0] = c; array[1] = d; array[2] = (k * c) - a; array[3] = (k * d) - b; - double res = array[1] != 0 ? Math.Round(array[0] / array[1], 3) : 0; + var res = array[1] != 0 ? Math.Round(array[0] / array[1], 3) : 0; resList.Insert(0, res); } - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j < resList.Count; j++) + for (var j = 0; j < resList.Count; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; - double weight = resList[j]; + var prevValue = i >= j ? inputList[i - j] : 0; + var weight = resList[j]; sum += prevValue * weight; weightedSum += weight; } - double prevFswma = fswmaList.LastOrDefault(); - double fswma = weightedSum != 0 ? sum / weightedSum : 0; + var prevFswma = fswmaList.LastOrDefault(); + var fswma = weightedSum != 0 ? sum / weightedSum : 0; fswmaList.AddRounded(fswma); var signal = GetCompareSignal(currentValue - fswma, prevVal - prevFswma); @@ -3691,29 +3691,29 @@ public static StockData CalculateEhlersFractalAdaptiveMovingAverage(this StockDa List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - int halfP = MinOrMax((int)Math.Ceiling((double)length / 2)); + var halfP = MinOrMax((int)Math.Ceiling((double)length / 2)); var (highestList1, lowestList1) = GetMaxAndMinValuesList(highList, lowList, length); var (highestList2, lowestList2) = GetMaxAndMinValuesList(highList, lowList, halfP); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevFilter = i >= 1 ? filterList.LastOrDefault() : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double highestHigh1 = highestList1[i]; - double lowestLow1 = lowestList1[i]; - double highestHigh2 = highestList2[i]; - double lowestLow2 = lowestList2[i]; - double highestHigh3 = highestList2[Math.Max(i - halfP, i)]; - double lowestLow3 = lowestList2[Math.Max(i - halfP, i)]; - double n3 = (highestHigh1 - lowestLow1) / length; - double n1 = (highestHigh2 - lowestLow2) / halfP; - double n2 = (highestHigh3 - lowestLow3) / halfP; - double dm = n1 > 0 && n2 > 0 && n3 > 0 ? (Math.Log(n1 + n2) - Math.Log(n3)) / Math.Log(2) : 0; - - double alpha = MinOrMax(Exp(-4.6 * (dm - 1)), 1, 0.01); - double filter = (alpha * currentValue) + ((1 - alpha) * prevFilter); + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevFilter = i >= 1 ? filterList.LastOrDefault() : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var highestHigh1 = highestList1[i]; + var lowestLow1 = lowestList1[i]; + var highestHigh2 = highestList2[i]; + var lowestLow2 = lowestList2[i]; + var highestHigh3 = highestList2[Math.Max(i - halfP, i)]; + var lowestLow3 = lowestList2[Math.Max(i - halfP, i)]; + var n3 = (highestHigh1 - lowestLow1) / length; + var n1 = (highestHigh2 - lowestLow2) / halfP; + var n2 = (highestHigh3 - lowestLow3) / halfP; + var dm = n1 > 0 && n2 > 0 && n3 > 0 ? (Math.Log(n1 + n2) - Math.Log(n3)) / Math.Log(2) : 0; + + var alpha = MinOrMax(Exp(-4.6 * (dm - 1)), 1, 0.01); + var filter = (alpha * currentValue) + ((1 - alpha) * prevFilter); filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter); @@ -3745,23 +3745,23 @@ public static StockData CalculateFallingRisingFilter(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevA = i >= 1 ? aList[i - 1] : 0; - double prevError = i >= 1 ? errorList[i - 1] : 0; + var currentValue = inputList[i]; + var prevA = i >= 1 ? aList[i - 1] : 0; + var prevError = i >= 1 ? errorList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; tempList.AddRounded(prevValue); var lbList = tempList.TakeLastExt(length).ToList(); - double beta = currentValue > lbList.Max() || currentValue < lbList.Min() ? 1 : alpha; - double a = prevA + (alpha * prevError) + (beta * prevError); + var beta = currentValue > lbList.Max() || currentValue < lbList.Min() ? 1 : alpha; + var a = prevA + (alpha * prevError) + (beta * prevError); aList.AddRounded(a); - double error = currentValue - a; + var error = currentValue - a; errorList.AddRounded(error); var signal = GetCompareSignal(error, prevError); @@ -3799,7 +3799,7 @@ public static StockData CalculateFisherLeastSquaresMovingAverage(this StockData var stdDevSrcList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var smaSrcList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double index = i; indexList.AddRounded(index); @@ -3808,28 +3808,28 @@ public static StockData CalculateFisherLeastSquaresMovingAverage(this StockData stockData.CustomValuesList = indexList; var indexStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var indexSmaList = GetMovingAverageList(stockData, maType, length, indexList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDevSrc = stdDevSrcList[i]; - double indexStdDev = indexStdDevList[i]; - double currentValue = inputList[i]; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double indexSma = indexSmaList[i]; - double sma = smaSrcList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var stdDevSrc = stdDevSrcList[i]; + var indexStdDev = indexStdDevList[i]; + var currentValue = inputList[i]; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var indexSma = indexSmaList[i]; + var sma = smaSrcList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double diff = currentValue - prevB; + var diff = currentValue - prevB; diffList.AddRounded(diff); - double absDiff = Math.Abs(diff); + var absDiff = Math.Abs(diff); absDiffList.AddRounded(absDiff); - double e = absDiffList.TakeLastExt(length).Average(); - double z = e != 0 ? diffList.TakeLastExt(length).Average() / e : 0; - double r = Exp(2 * z) + 1 != 0 ? (Exp(2 * z) - 1) / (Exp(2 * z) + 1) : 0; - double a = indexStdDev != 0 && r != 0 ? (i - indexSma) / indexStdDev * r : 0; + var e = absDiffList.TakeLastExt(length).Average(); + var z = e != 0 ? diffList.TakeLastExt(length).Average() / e : 0; + var r = Exp(2 * z) + 1 != 0 ? (Exp(2 * z) - 1) / (Exp(2 * z) + 1) : 0; + var a = indexStdDev != 0 && r != 0 ? (i - indexSma) / indexStdDev * r : 0; - double b = sma + (a * stdDevSrc); + var b = sma + (a * stdDevSrc); bList.AddRounded(b); var signal = GetCompareSignal(currentValue - b, prevValue - prevB); @@ -3868,27 +3868,27 @@ public static StockData CalculateKaufmanAdaptiveLeastSquaresMovingAverage(this S var rList = kamaList.OutputValues["Kaco"]; var srcMaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double index = i; indexList.AddRounded(index); } var indexMaList = GetMovingAverageList(stockData, maType, length, indexList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; var indexSt = indexStList[i]; var srcSt = srcStList[i]; var srcMa = srcMaList[i]; var indexMa = indexMaList[i]; var r = rList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double alpha = indexSt != 0 ? srcSt / indexSt * r : 0; - double beta = srcMa - (alpha * indexMa); + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var alpha = indexSt != 0 ? srcSt / indexSt * r : 0; + var beta = srcMa - (alpha * indexMa); - double prevKalsma = kalsmaList.LastOrDefault(); - double kalsma = (alpha * i) + beta; + var prevKalsma = kalsmaList.LastOrDefault(); + var kalsma = (alpha * i) + beta; kalsmaList.AddRounded(kalsma); var signal = GetCompareSignal(currentValue - kalsma, prevValue - prevKalsma); @@ -3919,19 +3919,19 @@ public static StockData CalculateKalmanSmoother(this StockData stockData, int le List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevKf = i >= 1 ? kfList[i - 1] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double dk = currentValue - prevKf; - double smooth = prevKf + (dk * Sqrt((double)length / 10000 * 2)); + var currentValue = inputList[i]; + var prevKf = i >= 1 ? kfList[i - 1] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var dk = currentValue - prevKf; + var smooth = prevKf + (dk * Sqrt((double)length / 10000 * 2)); - double prevVelo = i >= 1 ? veloList[i - 1] : 0; - double velo = prevVelo + ((double)length / 10000 * dk); + var prevVelo = i >= 1 ? veloList[i - 1] : 0; + var velo = prevVelo + ((double)length / 10000 * dk); veloList.AddRounded(velo); - double kf = smooth + velo; + var kf = smooth + velo; kfList.AddRounded(kf); var signal = GetCompareSignal(currentValue - kf, prevValue - prevKf); @@ -3970,28 +3970,28 @@ public static StockData CalculateVolumeAdjustedMovingAverage(this StockData stoc var volumeSmaList = GetMovingAverageList(stockData, maType, length, volumeList); ; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentVolume = volumeList[i]; - double currentValue = inputList[i]; - double volumeSma = volumeSmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double volumeIncrement = volumeSma * factor; + var currentVolume = volumeList[i]; + var currentValue = inputList[i]; + var volumeSma = volumeSmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var volumeIncrement = volumeSma * factor; - double volumeRatio = volumeIncrement != 0 ? currentVolume / volumeIncrement : 0; + var volumeRatio = volumeIncrement != 0 ? currentVolume / volumeIncrement : 0; volumeRatioList.AddRounded(volumeRatio); - double priceVolumeRatio = currentValue * volumeRatio; + var priceVolumeRatio = currentValue * volumeRatio; priceVolumeRatioList.AddRounded(priceVolumeRatio); - double volumeRatioSum = volumeRatioList.TakeLastExt(length).Sum(); + var volumeRatioSum = volumeRatioList.TakeLastExt(length).Sum(); volumeRatioSumList.AddRounded(volumeRatioSum); - double priceVolumeRatioSum = priceVolumeRatioList.TakeLastExt(length).Sum(); + var priceVolumeRatioSum = priceVolumeRatioList.TakeLastExt(length).Sum(); priceVolumeRatioSumList.AddRounded(priceVolumeRatioSum); - double prevVama = vamaList.LastOrDefault(); - double vama = volumeRatioSum != 0 ? priceVolumeRatioSum / volumeRatioSum : 0; + var prevVama = vamaList.LastOrDefault(); + var vama = volumeRatioSum != 0 ? priceVolumeRatioSum / volumeRatioSum : 0; vamaList.AddRounded(vama); var signal = GetCompareSignal(currentValue - vama, prevValue - prevVama); @@ -4026,49 +4026,49 @@ public static StockData CalculateVolatilityWaveMovingAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int s = MinOrMax((int)Math.Ceiling(Sqrt(length))); + var s = MinOrMax((int)Math.Ceiling(Sqrt(length))); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDev = stdDevList[i]; - double currentValue = inputList[i]; - double sdPct = currentValue != 0 ? stdDev / currentValue * 100 : 0; + var stdDev = stdDevList[i]; + var currentValue = inputList[i]; + var sdPct = currentValue != 0 ? stdDev / currentValue * 100 : 0; - double p = sdPct >= 0 ? MinOrMax(Sqrt(sdPct) * kf, 4, 1) : 1; + var p = sdPct >= 0 ? MinOrMax(Sqrt(sdPct) * kf, 4, 1) : 1; pList.AddRounded(p); } - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double p = pList[i]; + var p = pList[i]; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Pow(length - j, p); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(length - j, p); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double pma = weightedSum != 0 ? sum / weightedSum : 0; + var pma = weightedSum != 0 ? sum / weightedSum : 0; pmaList.AddRounded(pma); } var wmap1List = GetMovingAverageList(stockData, maType, s, pmaList); var wmap2List = GetMovingAverageList(stockData, maType, s, wmap1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double wmap1 = wmap1List[i]; - double wmap2 = wmap2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var wmap1 = wmap1List[i]; + var wmap2 = wmap2List[i]; - double prevZlmap = zlmapList.LastOrDefault(); - double zlmap = (2 * wmap1) - wmap2; + var prevZlmap = zlmapList.LastOrDefault(); + var zlmap = (2 * wmap1) - wmap2; zlmapList.AddRounded(zlmap); var signal = GetCompareSignal(currentValue - zlmap, prevValue - prevZlmap); @@ -4105,18 +4105,18 @@ public static StockData CalculateVariableAdaptiveMovingAverage(this StockData st var hList = GetMovingAverageList(stockData, maType, length, highList); var lList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double c = cList[i]; - double o = oList[i]; - double h = hList[i]; - double l = lList[i]; - double lv = h - l != 0 ? MinOrMax(Math.Abs(c - o) / (h - l), 0.99, 0.01) : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var c = cList[i]; + var o = oList[i]; + var h = hList[i]; + var l = lList[i]; + var lv = h - l != 0 ? MinOrMax(Math.Abs(c - o) / (h - l), 0.99, 0.01) : 0; - double prevVma = i >= 1 ? vmaList[i - 1] : currentValue; - double vma = (lv * currentValue) + ((1 - lv) * prevVma); + var prevVma = i >= 1 ? vmaList[i - 1] : currentValue; + var vma = (lv * currentValue) + ((1 - lv) * prevVma); vmaList.AddRounded(vma); var signal = GetCompareSignal(currentValue - vma, prevValue - prevVma); @@ -4151,51 +4151,51 @@ public static StockData CalculateVariableMovingAverage(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double k = (double)1 / length; + var k = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double pdm = Math.Max(MinPastValues(i, 1, currentValue - prevValue), 0); - double mdm = Math.Max(MinPastValues(i, 1, prevValue - currentValue), 0); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var pdm = Math.Max(MinPastValues(i, 1, currentValue - prevValue), 0); + var mdm = Math.Max(MinPastValues(i, 1, prevValue - currentValue), 0); - double prevPdms = pdmsList.LastOrDefault(); - double pdmS = ((1 - k) * prevPdms) + (k * pdm); + var prevPdms = pdmsList.LastOrDefault(); + var pdmS = ((1 - k) * prevPdms) + (k * pdm); pdmsList.AddRounded(pdmS); - double prevMdms = mdmsList.LastOrDefault(); - double mdmS = ((1 - k) * prevMdms) + (k * mdm); + var prevMdms = mdmsList.LastOrDefault(); + var mdmS = ((1 - k) * prevMdms) + (k * mdm); mdmsList.AddRounded(mdmS); - double s = pdmS + mdmS; - double pdi = s != 0 ? pdmS / s : 0; - double mdi = s != 0 ? mdmS / s : 0; + var s = pdmS + mdmS; + var pdi = s != 0 ? pdmS / s : 0; + var mdi = s != 0 ? mdmS / s : 0; - double prevPdis = pdisList.LastOrDefault(); - double pdiS = ((1 - k) * prevPdis) + (k * pdi); + var prevPdis = pdisList.LastOrDefault(); + var pdiS = ((1 - k) * prevPdis) + (k * pdi); pdisList.AddRounded(pdiS); - double prevMdis = mdisList.LastOrDefault(); - double mdiS = ((1 - k) * prevMdis) + (k * mdi); + var prevMdis = mdisList.LastOrDefault(); + var mdiS = ((1 - k) * prevMdis) + (k * mdi); mdisList.AddRounded(mdiS); - double d = Math.Abs(pdiS - mdiS); - double s1 = pdiS + mdiS; - double dS1 = s1 != 0 ? d / s1 : 0; + var d = Math.Abs(pdiS - mdiS); + var s1 = pdiS + mdiS; + var dS1 = s1 != 0 ? d / s1 : 0; - double prevIs = isList.LastOrDefault(); - double iS = ((1 - k) * prevIs) + (k * dS1); + var prevIs = isList.LastOrDefault(); + var iS = ((1 - k) * prevIs) + (k * dS1); isList.AddRounded(iS); var lbList = isList.TakeLastExt(length).ToList(); - double hhv = lbList.Max(); - double llv = lbList.Min(); - double d1 = hhv - llv; - double vI = d1 != 0 ? (iS - llv) / d1 : 0; + var hhv = lbList.Max(); + var llv = lbList.Min(); + var d1 = hhv - llv; + var vI = d1 != 0 ? (iS - llv) / d1 : 0; - double prevVma = vmaList.LastOrDefault(); - double vma = ((1 - k) * vI * prevVma) + (k * vI * currentValue); + var prevVma = vmaList.LastOrDefault(); + var vma = ((1 - k) * vI * prevVma) + (k * vI * currentValue); vmaList.AddRounded(vma); var signal = GetCompareSignal(currentValue - vma, prevValue - prevVma); @@ -4234,48 +4234,48 @@ public static StockData CalculateVolatilityMovingAverage(this StockData stockDat var smaList = GetMovingAverageList(stockData, maType, lbLength, inputList); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, lbLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma = smaList[i]; - double currentValue = inputList[i]; - double dev = stdDevList[i]; - double upper = sma + dev; - double lower = sma - dev; + var sma = smaList[i]; + var currentValue = inputList[i]; + var dev = stdDevList[i]; + var upper = sma + dev; + var lower = sma - dev; - double k = upper - lower != 0 ? (currentValue - sma) / (upper - lower) * 100 * 2 : 0; + var k = upper - lower != 0 ? (currentValue - sma) / (upper - lower) * 100 * 2 : 0; kList.AddRounded(k); } var kMaList = GetMovingAverageList(stockData, maType, smoothLength, kList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double kMa = kMaList[i]; - double kNorm = Math.Min(Math.Max(kMa, -100), 100); - double kAbs = Math.Round(Math.Abs(kNorm) / lbLength); - double kRescaled = RescaleValue(kAbs, 10, 0, length, 0, true); - int vLength = (int)Math.Round(Math.Max(kRescaled, 1)); + var kMa = kMaList[i]; + var kNorm = Math.Min(Math.Max(kMa, -100), 100); + var kAbs = Math.Round(Math.Abs(kNorm) / lbLength); + var kRescaled = RescaleValue(kAbs, 10, 0, length, 0, true); + var vLength = (int)Math.Round(Math.Max(kRescaled, 1)); double sum = 0, weightedSum = 0; - for (int j = 0; j <= vLength - 1; j++) + for (var j = 0; j <= vLength - 1; j++) { double weight = vLength - j; - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double vma1 = weightedSum != 0 ? sum / weightedSum : 0; + var vma1 = weightedSum != 0 ? sum / weightedSum : 0; vma1List.AddRounded(vma1); } var vma2List = GetMovingAverageList(stockData, maType, smoothLength, vma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double vma = vma2List[i]; - double prevVma = i >= 1 ? vma2List[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var vma = vma2List[i]; + var prevVma = i >= 1 ? vma2List[i - 1] : 0; var signal = GetCompareSignal(currentValue - vma, prevValue - prevVma); signalsList.Add(signal); @@ -4306,23 +4306,23 @@ public static StockData CalculateVerticalHorizontalMovingAverage(this StockData var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double priorValue = i >= length ? inputList[i - length] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double highest = highestList[i]; - double lowest = lowestList[i]; + var currentValue = inputList[i]; + var priorValue = i >= length ? inputList[i - length] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; - double priceChange = Math.Abs(currentValue - priorValue); + var priceChange = Math.Abs(currentValue - priorValue); changeList.AddRounded(priceChange); - double numerator = highest - lowest; - double denominator = changeList.TakeLastExt(length).Sum(); - double vhf = denominator != 0 ? numerator / denominator : 0; + var numerator = highest - lowest; + var denominator = changeList.TakeLastExt(length).Sum(); + var vhf = denominator != 0 ? numerator / denominator : 0; - double prevVhma = vhmaList.LastOrDefault(); - double vhma = prevVhma + (Pow(vhf, 2) * (currentValue - prevVhma)); + var prevVhma = vhmaList.LastOrDefault(); + var vhma = prevVhma + (Pow(vhf, 2) * (currentValue - prevVhma)); vhmaList.AddRounded(vhma); var signal = GetCompareSignal(currentValue - vhma, prevValue - prevVhma); @@ -4354,20 +4354,20 @@ public static StockData CalculateMcNichollMovingAverage(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); var ema1List = GetMovingAverageList(stockData, maType, length, inputList); var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ema1 = ema1List[i]; - double ema2 = ema2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ema1 = ema1List[i]; + var ema2 = ema2List[i]; - double prevMnma = mnmaList.LastOrDefault(); - double mnma = 1 - alpha != 0 ? (((2 - alpha) * ema1) - ema2) / (1 - alpha) : 0; + var prevMnma = mnmaList.LastOrDefault(); + var mnma = 1 - alpha != 0 ? (((2 - alpha) * ema1) - ema2) / (1 - alpha) : 0; mnmaList.AddRounded(mnma); var signal = GetCompareSignal(currentValue - mnma, prevValue - prevMnma); @@ -4399,32 +4399,32 @@ public static StockData CalculateCompoundRatioMovingAverage(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double r = Pow(length, ((double)1 / (length - 1)) - 1); - int smoothLength = Math.Max((int)Math.Round(Math.Sqrt(length)), 1); + var r = Pow(length, ((double)1 / (length - 1)) - 1); + var smoothLength = Math.Max((int)Math.Round(Math.Sqrt(length)), 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double sum = 0, weightedSum = 0, bas = 1 + (r * 2); - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Pow(bas, length - i); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(bas, length - i); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double coraRaw = weightedSum != 0 ? sum / weightedSum : 0; + var coraRaw = weightedSum != 0 ? sum / weightedSum : 0; coraRawList.AddRounded(coraRaw); } var coraWaveList = GetMovingAverageList(stockData, maType, smoothLength, coraRawList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double coraWave = coraWaveList[i]; - double prevCoraWave = i >= 1 ? coraWaveList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var coraWave = coraWaveList[i]; + var prevCoraWave = i >= 1 ? coraWaveList[i - 1] : 0; var signal = GetCompareSignal(currentValue - coraWave, prevValue - prevCoraWave); signalsList.Add(signal); @@ -4453,23 +4453,23 @@ public static StockData CalculateCubedWeightedMovingAverage(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Pow(length - j, 3); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(length - j, 3); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevCwma = cwmaList.LastOrDefault(); - double cwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevCwma = cwmaList.LastOrDefault(); + var cwma = weightedSum != 0 ? sum / weightedSum : 0; cwmaList.AddRounded(cwma); var signal = GetCompareSignal(currentValue - cwma, prevVal - prevCwma); @@ -4504,18 +4504,18 @@ public static StockData CalculateCorrectedMovingAverage(this StockData stockData var smaList = GetMovingAverageList(stockData, maType, length, inputList); var v1List = CalculateStandardDeviationVolatility(stockData, maType, length).OutputValues["Variance"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = smaList[i]; - double prevCma = i >= 1 ? cmaList[i - 1] : sma; - double v1 = v1List[i]; - double v2 = Pow(prevCma - sma, 2); - double v3 = v1 == 0 || v2 == 0 ? 1 : v2 / (v1 + v2); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; + var prevCma = i >= 1 ? cmaList[i - 1] : sma; + var v1 = v1List[i]; + var v2 = Pow(prevCma - sma, 2); + var v3 = v1 == 0 || v2 == 0 ? 1 : v2 / (v1 + v2); double tolerance = Pow(10, -5), err = 1, kPrev = 1, k = 1; - for (int j = 0; j <= 5000; j++) + for (var j = 0; j <= 5000; j++) { if (err > tolerance) { @@ -4525,7 +4525,7 @@ public static StockData CalculateCorrectedMovingAverage(this StockData stockData } } - double cma = prevCma + (k * (sma - prevCma)); + var cma = prevCma + (k * (sma - prevCma)); cmaList.AddRounded(cma); var signal = GetCompareSignal(currentValue - cma, prevValue - prevCma); @@ -4560,15 +4560,15 @@ public static StockData CalculateDoubleExponentialMovingAverage(this StockData s var ema1List = GetMovingAverageList(stockData, maType, length, inputList); var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentEma = ema1List[i]; - double currentEma2 = ema2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma = ema1List[i]; + var currentEma2 = ema2List[i]; - double prevDema = demaList.LastOrDefault(); - double dema = (2 * currentEma) - currentEma2; + var prevDema = demaList.LastOrDefault(); + var dema = (2 * currentEma) - currentEma2; demaList.AddRounded(dema); var signal = GetCompareSignal(currentValue - dema, prevValue - prevDema); @@ -4609,21 +4609,21 @@ public static StockData CalculatePentupleExponentialMovingAverage(this StockData var ema7List = GetMovingAverageList(stockData, maType, length, ema6List); var ema8List = GetMovingAverageList(stockData, maType, length, ema7List); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ema1 = ema1List[i]; - double ema2 = ema2List[i]; - double ema3 = ema3List[i]; - double ema4 = ema4List[i]; - double ema5 = ema5List[i]; - double ema6 = ema6List[i]; - double ema7 = ema7List[i]; - double ema8 = ema8List[i]; - - double prevPema = pemaList.LastOrDefault(); - double pema = (8 * ema1) - (28 * ema2) + (56 * ema3) - (70 * ema4) + (56 * ema5) - (28 * ema6) + (8 * ema7) - ema8; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ema1 = ema1List[i]; + var ema2 = ema2List[i]; + var ema3 = ema3List[i]; + var ema4 = ema4List[i]; + var ema5 = ema5List[i]; + var ema6 = ema6List[i]; + var ema7 = ema7List[i]; + var ema8 = ema8List[i]; + + var prevPema = pemaList.LastOrDefault(); + var pema = (8 * ema1) - (28 * ema2) + (56 * ema3) - (70 * ema4) + (56 * ema5) - (28 * ema6) + (8 * ema7) - ema8; pemaList.AddRounded(pema); var signal = GetCompareSignal(currentValue - pema, prevValue - prevPema); @@ -4653,26 +4653,26 @@ public static StockData CalculatePolynomialLeastSquaresMovingAverage(this StockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; - double prevSumPow3 = sumPow3List.LastOrDefault(); + var prevSumPow3 = sumPow3List.LastOrDefault(); double x1Pow1Sum, x2Pow1Sum, x1Pow2Sum, x2Pow2Sum, x1Pow3Sum, x2Pow3Sum, wPow1, wPow2, wPow3, sumPow1 = 0, sumPow2 = 0, sumPow3 = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; - double x1 = (double)j / length; - double x2 = (double)(j - 1) / length; - double ax1 = x1 * x1; - double ax2 = x2 * x2; + var prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var x1 = (double)j / length; + var x2 = (double)(j - 1) / length; + var ax1 = x1 * x1; + var ax2 = x2 * x2; double b1Pow1Sum = 0, b2Pow1Sum = 0, b1Pow2Sum = 0, b2Pow2Sum = 0, b1Pow3Sum = 0, b2Pow3Sum = 0; - for (int k = 1; k <= 3; k++) + for (var k = 1; k <= 3; k++) { - double b1 = (double)1 / k * Math.Sin(x1 * k * Math.PI); - double b2 = (double)1 / k * Math.Sin(x2 * k * Math.PI); + var b1 = (double)1 / k * Math.Sin(x1 * k * Math.PI); + var b2 = (double)1 / k * Math.Sin(x2 * k * Math.PI); b1Pow1Sum += k == 1 ? b1 : 0; b2Pow1Sum += k == 1 ? b2 : 0; @@ -4732,35 +4732,35 @@ public static StockData CalculateParametricCorrectiveLinearMovingAverage(this St List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= length ? inputList[i - length] : 0; - double p1 = i + 1 - (per / 100 * length); - double p2 = i + 1 - ((100 - per) / 100 * length); + var prevValue = i >= length ? inputList[i - length] : 0; + var p1 = i + 1 - (per / 100 * length); + var p2 = i + 1 - ((100 - per) / 100 * length); - double w1 = p1 >= 0 ? p1 : alpha * p1; + var w1 = p1 >= 0 ? p1 : alpha * p1; w1List.AddRounded(w1); - double w2 = p2 >= 0 ? p2 : alpha * p2; + var w2 = p2 >= 0 ? p2 : alpha * p2; w2List.AddRounded(w2); - double vw1 = prevValue * w1; + var vw1 = prevValue * w1; vw1List.AddRounded(vw1); - double vw2 = prevValue * w2; + var vw2 = prevValue * w2; vw2List.AddRounded(vw2); - double wSum1 = w1List.TakeLastExt(length).Sum(); - double wSum2 = w2List.TakeLastExt(length).Sum(); - double sum1 = vw1List.TakeLastExt(length).Sum(); - double sum2 = vw2List.TakeLastExt(length).Sum(); + var wSum1 = w1List.TakeLastExt(length).Sum(); + var wSum2 = w2List.TakeLastExt(length).Sum(); + var sum1 = vw1List.TakeLastExt(length).Sum(); + var sum2 = vw2List.TakeLastExt(length).Sum(); - double prevRrma1 = rrma1List.LastOrDefault(); - double rrma1 = wSum1 != 0 ? sum1 / wSum1 : 0; + var prevRrma1 = rrma1List.LastOrDefault(); + var rrma1 = wSum1 != 0 ? sum1 / wSum1 : 0; rrma1List.AddRounded(rrma1); - double prevRrma2 = rrma2List.LastOrDefault(); - double rrma2 = wSum2 != 0 ? sum2 / wSum2 : 0; + var prevRrma2 = rrma2List.LastOrDefault(); + var rrma2 = wSum2 != 0 ? sum2 / wSum2 : 0; rrma2List.AddRounded(rrma2); var signal = GetCompareSignal(rrma1 - rrma2, prevRrma1 - prevRrma2); @@ -4790,23 +4790,23 @@ public static StockData CalculateParabolicWeightedMovingAverage(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Pow(length - j, 2); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(length - j, 2); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevPwma = pwmaList.LastOrDefault(); - double pwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevPwma = pwmaList.LastOrDefault(); + var pwma = weightedSum != 0 ? sum / weightedSum : 0; pwmaList.AddRounded(pwma); var signal = GetCompareSignal(currentValue - pwma, prevVal - prevPwma); @@ -4837,24 +4837,24 @@ public static StockData CalculateParametricKalmanFilter(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorEst = i >= length ? estList[i - length] : prevValue; - double errMea = Math.Abs(priorEst - currentValue); - double errPrv = Math.Abs(MinPastValues(i, 1, currentValue - prevValue) * -1); - double prevErr = i >= 1 ? errList[i - 1] : errPrv; - double kg = prevErr != 0 ? prevErr / (prevErr + errMea) : 0; - double prevEst = i >= 1 ? estList[i - 1] : prevValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorEst = i >= length ? estList[i - length] : prevValue; + var errMea = Math.Abs(priorEst - currentValue); + var errPrv = Math.Abs(MinPastValues(i, 1, currentValue - prevValue) * -1); + var prevErr = i >= 1 ? errList[i - 1] : errPrv; + var kg = prevErr != 0 ? prevErr / (prevErr + errMea) : 0; + var prevEst = i >= 1 ? estList[i - 1] : prevValue; - double est = prevEst + (kg * (currentValue - prevEst)); + var est = prevEst + (kg * (currentValue - prevEst)); estList.AddRounded(est); - double err = (1 - kg) * errPrv; + var err = (1 - kg) * errPrv; errList.AddRounded(err); - Signal signal = GetCompareSignal(currentValue - est, prevValue - prevEst); + var signal = GetCompareSignal(currentValue - est, prevValue - prevEst); signalsList.Add(signal); } @@ -4892,20 +4892,20 @@ public static StockData CalculateTStepLeastSquaresMovingAverage(this StockData s var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double efRatio = efRatioList[i]; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double er = 1 - efRatio; + var efRatio = efRatioList[i]; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var er = 1 - efRatio; - double chg = Math.Abs(currentValue - prevB); + var chg = Math.Abs(currentValue - prevB); chgList.AddRounded(chg); - double a = chgList.Average() * (1 + er); - double b = currentValue > prevB + a ? currentValue : currentValue < prevB - a ? currentValue : prevB; + var a = chgList.Average() * (1 + er); + var b = currentValue > prevB + a ? currentValue : currentValue < prevB - a ? currentValue : prevB; bList.AddRounded(b); var corr = GoodnessOfFit.R(bList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); @@ -4916,23 +4916,23 @@ public static StockData CalculateTStepLeastSquaresMovingAverage(this StockData s stockData.CustomValuesList = bList; var bStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var bSmaList = GetMovingAverageList(stockData, maType, length, bList); - for (int i = 0; i < stockData.Count; i++) - { - double corr = corrList[i]; - double stdDev = stdDevList[i]; - double bStdDev = bStdDevList[i]; - double bSma = bSmaList[i]; - double sma = smaList[i]; - double currentValue = inputList[i]; - double prevLs = i >= 1 ? lsList[i - 1] : currentValue; - double b = bList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - - double tslsma = (sc * currentValue) + ((1 - sc) * prevLs); - double alpha = bStdDev != 0 ? corr * stdDev / bStdDev : 0; - double beta = sma - (alpha * bSma); - - double ls = (alpha * b) + beta; + for (var i = 0; i < stockData.Count; i++) + { + var corr = corrList[i]; + var stdDev = stdDevList[i]; + var bStdDev = bStdDevList[i]; + var bSma = bSmaList[i]; + var sma = smaList[i]; + var currentValue = inputList[i]; + var prevLs = i >= 1 ? lsList[i - 1] : currentValue; + var b = bList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + + var tslsma = (sc * currentValue) + ((1 - sc) * prevLs); + var alpha = bStdDev != 0 ? corr * stdDev / bStdDev : 0; + var beta = sma - (alpha * bSma); + + var ls = (alpha * b) + beta; lsList.AddRounded(ls); var signal = GetCompareSignal(currentValue - ls, prevValue - prevLs); @@ -4966,17 +4966,17 @@ public static StockData CalculateTillsonIE2(this StockData stockData, MovingAvgT var smaList = GetMovingAverageList(stockData, maType, length, inputList); var linRegList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma = smaList[i]; - double a0 = linRegList[i]; - double a1 = i >= 1 ? linRegList[i - 1] : 0; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double m = a0 - a1 + sma; + var sma = smaList[i]; + var a0 = linRegList[i]; + var a1 = i >= 1 ? linRegList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var m = a0 - a1 + sma; - double prevIe2 = ie2List.LastOrDefault(); - double ie2 = (m + a0) / 2; + var prevIe2 = ie2List.LastOrDefault(); + var ie2 = (m + a0) / 2; ie2List.AddRounded(ie2); var signal = GetCompareSignal(currentValue - ie2, prevValue - prevIe2); @@ -5017,37 +5017,37 @@ public static StockData CalculateR2AdaptiveRegression(this StockData stockData, var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDev = stdDevList[i]; - double sma = smaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var stdDev = stdDevList[i]; + var sma = smaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); var lbList = tempList.TakeLastExt(length).Select(x => (double)x); - double y1 = linregList[i]; + var y1 = linregList[i]; y1List.AddRounded(y1); - double x2 = i >= 1 ? outList[i - 1] : currentValue; + var x2 = i >= 1 ? outList[i - 1] : currentValue; x2List.AddRounded(x2); var x2LbList = x2List.TakeLastExt(length).Select(x => (double)x).ToList(); var r2x2 = GoodnessOfFit.R(x2LbList, lbList); r2x2 = IsValueNullOrInfinity(r2x2) ? 0 : r2x2; - double x2Avg = (double)x2LbList.TakeLastExt(length).Average(); - double x2Dev = x2 - x2Avg; + var x2Avg = (double)x2LbList.TakeLastExt(length).Average(); + var x2Dev = x2 - x2Avg; - double x2Pow = Pow(x2Dev, 2); + var x2Pow = Pow(x2Dev, 2); x2PowList.AddRounded(x2Pow); - double x2PowAvg = x2PowList.TakeLastExt(length).Average(); - double x2StdDev = x2PowAvg >= 0 ? Sqrt(x2PowAvg) : 0; - double a = x2StdDev != 0 ? stdDev * (double)r2x2 / x2StdDev : 0; - double b = sma - (a * x2Avg); + var x2PowAvg = x2PowList.TakeLastExt(length).Average(); + var x2StdDev = x2PowAvg >= 0 ? Sqrt(x2PowAvg) : 0; + var a = x2StdDev != 0 ? stdDev * (double)r2x2 / x2StdDev : 0; + var b = sma - (a * x2Avg); - double y2 = (a * x2) + b; + var y2 = (a * x2) + b; y2List.AddRounded(y2); var ry1 = Math.Pow(GoodnessOfFit.R(y1List.TakeLastExt(length).Select(x => (double)x), lbList), 2); @@ -5055,8 +5055,8 @@ public static StockData CalculateR2AdaptiveRegression(this StockData stockData, var ry2 = Math.Pow(GoodnessOfFit.R(y2List.TakeLastExt(length).Select(x => (double)x), lbList), 2); ry2 = IsValueNullOrInfinity(ry2) ? 0 : ry2; - double prevOutVal = outList.LastOrDefault(); - double outval = ((double)ry1 * y1) + ((double)ry2 * y2) + ((1 - (double)(ry1 + ry2)) * x2); + var prevOutVal = outList.LastOrDefault(); + var outval = ((double)ry1 * y1) + ((double)ry2 * y2) + ((1 - (double)(ry1 + ry2)) * x2); outList.AddRounded(outval); var signal = GetCompareSignal(currentValue - outval, prevValue - prevOutVal); @@ -5085,18 +5085,18 @@ public static StockData CalculateRatioOCHLAverager(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double b = currentHigh - currentLow != 0 ? Math.Abs(currentValue - currentOpen) / (currentHigh - currentLow) : 0; - double c = b > 1 ? 1 : b; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var b = currentHigh - currentLow != 0 ? Math.Abs(currentValue - currentOpen) / (currentHigh - currentLow) : 0; + var c = b > 1 ? 1 : b; - double prevD = i >= 1 ? dList[i - 1] : currentValue; - double d = (c * currentValue) + ((1 - c) * prevD); + var prevD = i >= 1 ? dList[i - 1] : currentValue; + var d = (c * currentValue) + ((1 - c) * prevD); dList.AddRounded(d); var signal = GetCompareSignal(currentValue - d, prevValue - prevD); @@ -5127,16 +5127,16 @@ public static StockData CalculateRegularizedExponentialMovingAverage(this StockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevRema1 = i >= 1 ? remaList[i - 1] : 0; - double prevRema2 = i >= 2 ? remaList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevRema1 = i >= 1 ? remaList[i - 1] : 0; + var prevRema2 = i >= 2 ? remaList[i - 2] : 0; - double rema = (prevRema1 + (alpha * (currentValue - prevRema1)) + (lambda * ((2 * prevRema1) - prevRema2))) / (lambda + 1); + var rema = (prevRema1 + (alpha * (currentValue - prevRema1)) + (lambda * ((2 * prevRema1) - prevRema2))) / (lambda + 1); remaList.AddRounded(rema); var signal = GetCompareSignal(currentValue - rema, prevValue - prevRema1); @@ -5172,16 +5172,16 @@ public static StockData CalculateRepulsionMovingAverage(this StockData stockData var sma2List = GetMovingAverageList(stockData, maType, length * 2, inputList); var sma3List = GetMovingAverageList(stockData, maType, length * 3, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma1 = sma1List[i]; - double sma2 = sma2List[i]; - double sma3 = sma3List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma1 = sma1List[i]; + var sma2 = sma2List[i]; + var sma3 = sma3List[i]; - double prevMa = maList.LastOrDefault(); - double ma = sma3 + sma2 - sma1; + var prevMa = maList.LastOrDefault(); + var ma = sma3 + sma2 - sma1; maList.AddRounded(ma); var signal = GetCompareSignal(currentValue - ma, prevValue - prevMa); @@ -5213,26 +5213,26 @@ public static StockData CalculateRetentionAccelerationFilter(this StockData stoc var (highestList1, lowestList1) = GetMaxAndMinValuesList(highList, lowList, length); var (highestList2, lowestList2) = GetMaxAndMinValuesList(highList, lowList, length * 2); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double highest1 = highestList1[i]; - double lowest1 = lowestList1[i]; - double highest2 = highestList2[i]; - double lowest2 = lowestList2[i]; - double ar = 2 * (highest1 - lowest1); - double br = 2 * (highest2 - lowest2); - double k1 = ar != 0 ? (1 - ar) / ar : 0; - double k2 = br != 0 ? (1 - br) / br : 0; - double alpha = k1 != 0 ? k2 / k1 : 0; - double r1 = alpha != 0 && highest1 >= 0 ? Sqrt(highest1) / 4 * ((alpha - 1) / alpha) * (k2 / (k2 + 1)) : 0; - double r2 = highest2 >= 0 ? Sqrt(highest2) / 4 * (alpha - 1) * (k1 / (k1 + 1)) : 0; - double factor = r1 != 0 ? r2 / r1 : 0; - double altk = Pow(factor >= 1 ? 1 : factor, Sqrt(length)) * ((double)1 / length); - - double prevAltma = i >= 1 ? altmaList[i - 1] : currentValue; - double altma = (altk * currentValue) + ((1 - altk) * prevAltma); + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var highest1 = highestList1[i]; + var lowest1 = lowestList1[i]; + var highest2 = highestList2[i]; + var lowest2 = lowestList2[i]; + var ar = 2 * (highest1 - lowest1); + var br = 2 * (highest2 - lowest2); + var k1 = ar != 0 ? (1 - ar) / ar : 0; + var k2 = br != 0 ? (1 - br) / br : 0; + var alpha = k1 != 0 ? k2 / k1 : 0; + var r1 = alpha != 0 && highest1 >= 0 ? Sqrt(highest1) / 4 * ((alpha - 1) / alpha) * (k2 / (k2 + 1)) : 0; + var r2 = highest2 >= 0 ? Sqrt(highest2) / 4 * (alpha - 1) * (k1 / (k1 + 1)) : 0; + var factor = r1 != 0 ? r2 / r1 : 0; + var altk = Pow(factor >= 1 ? 1 : factor, Sqrt(length)) * ((double)1 / length); + + var prevAltma = i >= 1 ? altmaList[i - 1] : currentValue; + var altma = (altk * currentValue) + ((1 - altk) * prevAltma); altmaList.AddRounded(altma); var signal = GetCompareSignal(currentValue - altma, prevValue - prevAltma); @@ -5266,24 +5266,24 @@ public static StockData CalculateReverseEngineeringRelativeStrengthIndex(this St var (inputList, _, _, _, _) = GetInputValuesList(stockData); double expPeriod = (2 * length) - 1; - double k = 2 / (expPeriod + 1); + var k = 2 / (expPeriod + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevAuc = i >= 1 ? aucList[i - 1] : 1; - double prevAdc = i >= 1 ? adcList[i - 1] : 1; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevAuc = i >= 1 ? aucList[i - 1] : 1; + var prevAdc = i >= 1 ? adcList[i - 1] : 1; - double auc = currentValue > prevValue ? (k * MinPastValues(i, 1, currentValue - prevValue)) + ((1 - k) * prevAuc) : (1 - k) * prevAuc; + var auc = currentValue > prevValue ? (k * MinPastValues(i, 1, currentValue - prevValue)) + ((1 - k) * prevAuc) : (1 - k) * prevAuc; aucList.AddRounded(auc); - double adc = currentValue > prevValue ? ((1 - k) * prevAdc) : (k * MinPastValues(i, 1, prevValue - currentValue)) + ((1 - k) * prevAdc); + var adc = currentValue > prevValue ? ((1 - k) * prevAdc) : (k * MinPastValues(i, 1, prevValue - currentValue)) + ((1 - k) * prevAdc); adcList.AddRounded(adc); - double rsiValue = (length - 1) * ((adc * rsiLevel / (100 - rsiLevel)) - auc); - double prevRevRsi = revRsiList.LastOrDefault(); - double revRsi = rsiValue >= 0 ? currentValue + rsiValue : currentValue + (rsiValue * (100 - rsiLevel) / rsiLevel); + var rsiValue = (length - 1) * ((adc * rsiLevel / (100 - rsiLevel)) - auc); + var prevRevRsi = revRsiList.LastOrDefault(); + var revRsi = rsiValue >= 0 ? currentValue + rsiValue : currentValue + (rsiValue * (100 - rsiLevel) / rsiLevel); revRsiList.AddRounded(revRsi); var signal = GetCompareSignal(currentValue - revRsi, prevValue - prevRevRsi); @@ -5314,23 +5314,23 @@ public static StockData CalculateRightSidedRickerMovingAverage(this StockData st List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double width = pctWidth / 100 * length; + var width = pctWidth / 100 * length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double w = 0, vw = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double prevV = i >= j ? inputList[i - j] : 0; + var prevV = i >= j ? inputList[i - j] : 0; w += (1 - Pow(j / width, 2)) * Exp(-(Pow(j, 2) / (2 * Pow(width, 2)))); vw += prevV * w; } - double prevRrma = rrmaList.LastOrDefault(); - double rrma = w != 0 ? vw / w : 0; + var prevRrma = rrmaList.LastOrDefault(); + var rrma = w != 0 ? vw / w : 0; rrmaList.AddRounded(rrma); var signal = GetCompareSignal(currentValue - rrma, prevValue - prevRrma); @@ -5361,19 +5361,19 @@ public static StockData CalculateRecursiveMovingTrendAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevBot = i >= 1 ? botList[i - 1] : currentValue; - double prevNRes = i >= 1 ? nResList[i - 1] : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevBot = i >= 1 ? botList[i - 1] : currentValue; + var prevNRes = i >= 1 ? nResList[i - 1] : currentValue; - double bot = ((1 - alpha) * prevBot) + currentValue; + var bot = ((1 - alpha) * prevBot) + currentValue; botList.AddRounded(bot); - double nRes = ((1 - alpha) * prevNRes) + (alpha * (currentValue + bot - prevBot)); + var nRes = ((1 - alpha) * prevNRes) + (alpha * (currentValue + bot - prevBot)); nResList.AddRounded(nRes); var signal = GetCompareSignal(currentValue - nRes, prevValue - prevNRes); @@ -5411,38 +5411,38 @@ public static StockData CalculateReverseMovingAverageConvergenceDivergence(this List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double fastAlpha = (double)2 / (1 + fastLength); - double slowAlpha = (double)2 / (1 + slowLength); + var fastAlpha = (double)2 / (1 + fastLength); + var slowAlpha = (double)2 / (1 + slowLength); var fastEmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowEmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevFastEma = i >= 1 ? fastEmaList[i - 1] : 0; - double prevSlowEma = i >= 1 ? slowEmaList[i - 1] : 0; + var prevFastEma = i >= 1 ? fastEmaList[i - 1] : 0; + var prevSlowEma = i >= 1 ? slowEmaList[i - 1] : 0; - double pMacdEq = fastAlpha - slowAlpha != 0 ? ((prevFastEma * fastAlpha) - (prevSlowEma * slowAlpha)) / (fastAlpha - slowAlpha) : 0; + var pMacdEq = fastAlpha - slowAlpha != 0 ? ((prevFastEma * fastAlpha) - (prevSlowEma * slowAlpha)) / (fastAlpha - slowAlpha) : 0; pMacdEqList.AddRounded(pMacdEq); - double pMacdLevel = fastAlpha - slowAlpha != 0 ? (macdLevel - (prevFastEma * (1 - fastAlpha)) + (prevSlowEma * (1 - slowAlpha))) / - (fastAlpha - slowAlpha) : 0; + var pMacdLevel = fastAlpha - slowAlpha != 0 ? (macdLevel - (prevFastEma * (1 - fastAlpha)) + (prevSlowEma * (1 - slowAlpha))) / + (fastAlpha - slowAlpha) : 0; pMacdLevelList.AddRounded(pMacdLevel); } var pMacdEqSignalList = GetMovingAverageList(stockData, maType, signalLength, pMacdEqList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pMacdEq = pMacdEqList[i]; - double pMacdEqSignal = pMacdEqSignalList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevPMacdEq = i >= 1 ? pMacdEqList[i - 1] : 0; + var pMacdEq = pMacdEqList[i]; + var pMacdEqSignal = pMacdEqSignalList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevPMacdEq = i >= 1 ? pMacdEqList[i - 1] : 0; - double macdHistogram = pMacdEq - pMacdEqSignal; + var macdHistogram = pMacdEq - pMacdEqSignal; histogramList.AddRounded(macdHistogram); - Signal signal = GetCompareSignal(currentValue - pMacdEq, prevValue - prevPMacdEq); + var signal = GetCompareSignal(currentValue - pMacdEq, prevValue - prevPMacdEq); signalsList.Add(signal); } @@ -5478,36 +5478,36 @@ public static StockData CalculateLinearRegression(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = yList.LastOrDefault(); - double currentValue = inputList[i]; + var prevValue = yList.LastOrDefault(); + var currentValue = inputList[i]; yList.AddRounded(currentValue); double x = i; xList.AddRounded(x); - double xy = x * currentValue; + var xy = x * currentValue; xyList.AddRounded(xy); - double sumX = xList.TakeLastExt(length).Sum(); - double sumY = yList.TakeLastExt(length).Sum(); - double sumXY = xyList.TakeLastExt(length).Sum(); - double sumX2 = x2List.TakeLastExt(length).Sum(); - double top = (length * sumXY) - (sumX * sumY); - double bottom = (length * sumX2) - Pow(sumX, 2); + var sumX = xList.TakeLastExt(length).Sum(); + var sumY = yList.TakeLastExt(length).Sum(); + var sumXY = xyList.TakeLastExt(length).Sum(); + var sumX2 = x2List.TakeLastExt(length).Sum(); + var top = (length * sumXY) - (sumX * sumY); + var bottom = (length * sumX2) - Pow(sumX, 2); - double b = bottom != 0 ? top / bottom : 0; + var b = bottom != 0 ? top / bottom : 0; slopeList.AddRounded(b); - double a = length != 0 ? (sumY - (b * sumX)) / length : 0; + var a = length != 0 ? (sumY - (b * sumX)) / length : 0; interceptList.AddRounded(a); - double predictedToday = a + (b * x); + var predictedToday = a + (b * x); predictedTodayList.AddRounded(predictedToday); - double prevPredictedNextDay = predictedTomorrowList.LastOrDefault(); - double predictedNextDay = a + (b * (x + 1)); + var prevPredictedNextDay = predictedTomorrowList.LastOrDefault(); + var predictedNextDay = a + (b * (x + 1)); predictedTomorrowList.AddRounded(predictedNextDay); var signal = GetCompareSignal(currentValue - predictedNextDay, prevValue - prevPredictedNextDay, true); @@ -5545,15 +5545,15 @@ public static StockData CalculateMovingAverageAdaptiveQ(this StockData stockData var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMaaq = i >= 1 ? maaqList[i - 1] : currentValue; - double er = erList[i]; - double temp = (er * fastAlpha) + slowAlpha; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMaaq = i >= 1 ? maaqList[i - 1] : currentValue; + var er = erList[i]; + var temp = (er * fastAlpha) + slowAlpha; - double maaq = prevMaaq + (Pow(temp, 2) * (currentValue - prevMaaq)); + var maaq = prevMaaq + (Pow(temp, 2) * (currentValue - prevMaaq)); maaqList.AddRounded(maaq); var signal = GetCompareSignal(currentValue - maaq, prevValue - prevMaaq); @@ -5584,15 +5584,15 @@ public static StockData CalculateMcGinleyDynamicIndicator(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevMdi = i >= 1 ? mdiList.LastOrDefault() : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ratio = prevMdi != 0 ? currentValue / prevMdi : 0; - double bottom = k * length * Pow(ratio, 4); + var currentValue = inputList[i]; + var prevMdi = i >= 1 ? mdiList.LastOrDefault() : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ratio = prevMdi != 0 ? currentValue / prevMdi : 0; + var bottom = k * length * Pow(ratio, 4); - double mdi = bottom != 0 ? prevMdi + ((currentValue - prevMdi) / Math.Max(bottom, 1)) : currentValue; + var mdi = bottom != 0 ? prevMdi + ((currentValue - prevMdi) / Math.Max(bottom, 1)) : currentValue; mdiList.AddRounded(mdi); var signal = GetCompareSignal(currentValue - mdi, prevValue - prevMdi); @@ -5625,22 +5625,22 @@ public static StockData CalculateEhlersMedianAverageAdaptiveFilter(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; - double prevP1 = i >= 1 ? inputList[i - 1] : 0; - double prevP2 = i >= 2 ? inputList[i - 2] : 0; - double prevP3 = i >= 3 ? inputList[i - 3] : 0; + var currentPrice = inputList[i]; + var prevP1 = i >= 1 ? inputList[i - 1] : 0; + var prevP2 = i >= 2 ? inputList[i - 2] : 0; + var prevP3 = i >= 3 ? inputList[i - 3] : 0; - double smth = (currentPrice + (2 * prevP1) + (2 * prevP2) + prevP3) / 6; + var smth = (currentPrice + (2 * prevP1) + (2 * prevP2) + prevP3) / 6; smthList.AddRounded(smth); - int len = length; + var len = length; double value3 = 0.2, value2 = 0, prevV2 = value2List.LastOrDefault(), alpha; while (value3 > threshold && len > 0) { alpha = (double)2 / (len + 1); - double value1 = smthList.TakeLastExt(len).Median(); + var value1 = smthList.TakeLastExt(len).Median(); value2 = (alpha * smth) + ((1 - alpha) * prevV2); value3 = value1 != 0 ? Math.Abs(value1 - value2) / value1 : value3; len -= 2; @@ -5650,8 +5650,8 @@ public static StockData CalculateEhlersMedianAverageAdaptiveFilter(this StockDat len = len < 3 ? 3 : len; alpha = (double)2 / (len + 1); - double prevFilter = filterList.LastOrDefault(); - double filter = (alpha * smth) + ((1 - alpha) * prevFilter); + var prevFilter = filterList.LastOrDefault(); + var filter = (alpha * smth) + ((1 - alpha) * prevFilter); filterList.AddRounded(filter); var signal = GetCompareSignal(currentPrice - filter, prevP1 - prevFilter); @@ -5686,12 +5686,12 @@ public static StockData CalculateMiddleHighLowMovingAverage(this StockData stock var mhlList = CalculateMidpoint(stockData, length2).CustomValuesList; var mhlMaList = GetMovingAverageList(stockData, maType, length1, mhlList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentMhlMa = mhlMaList[i]; - double prevMhlma = i >= 1 ? mhlMaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentMhlMa = mhlMaList[i]; + var prevMhlma = i >= 1 ? mhlMaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - currentMhlMa, prevValue - prevMhlma); signalsList.Add(signal); @@ -5723,21 +5723,21 @@ public static StockData CalculateMovingAverageV3(this StockData stockData, Movin List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double lamdaRatio = (double)length1 / length2; - double alpha = length1 - lamdaRatio != 0 ? lamdaRatio * (length1 - 1) / (length1 - lamdaRatio) : 0; + var lamdaRatio = (double)length1 / length2; + var alpha = length1 - lamdaRatio != 0 ? lamdaRatio * (length1 - 1) / (length1 - lamdaRatio) : 0; var ma1List = GetMovingAverageList(stockData, maType, length1, inputList); var ma2List = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ma1 = ma1List[i]; - double ma2 = ma2List[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var ma1 = ma1List[i]; + var ma2 = ma2List[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevNma = nmaList.LastOrDefault(); - double nma = ((1 + alpha) * ma1) - (alpha * ma2); + var prevNma = nmaList.LastOrDefault(); + var nma = ((1 + alpha) * ma1) - (alpha * ma2); nmaList.AddRounded(nma); var signal = GetCompareSignal(currentValue - nma, prevValue - prevNma); @@ -5775,59 +5775,59 @@ public static StockData CalculateMultiDepthZeroLagExponentialMovingAverage(this List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = (double)2 / (length + 1); - double a2 = Exp(-Sqrt(2) * Math.PI / length); - double a3 = Exp(-Math.PI / length); - double b2 = 2 * a2 * Math.Cos(Sqrt(2) * Math.PI / length); - double b3 = 2 * a3 * Math.Cos(Sqrt(3) * Math.PI / length); - double c = Exp(-2 * Math.PI / length); + var a1 = (double)2 / (length + 1); + var a2 = Exp(-Sqrt(2) * Math.PI / length); + var a3 = Exp(-Math.PI / length); + var b2 = 2 * a2 * Math.Cos(Sqrt(2) * Math.PI / length); + var b3 = 2 * a3 * Math.Cos(Sqrt(3) * Math.PI / length); + var c = Exp(-2 * Math.PI / length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevAlpha1 = i >= 1 ? alpha1List[i - 1] : currentValue; - double alpha1 = (a1 * currentValue) + ((1 - a1) * prevAlpha1); + var prevAlpha1 = i >= 1 ? alpha1List[i - 1] : currentValue; + var alpha1 = (a1 * currentValue) + ((1 - a1) * prevAlpha1); alpha1List.AddRounded(alpha1); - double prevAlpha2 = i >= 1 ? alpha2List[i - 1] : currentValue; - double priorAlpha2 = i >= 2 ? alpha2List[i - 2] : currentValue; - double alpha2 = (b2 * prevAlpha2) - (a2 * a2 * priorAlpha2) + ((1 - b2 + (a2 * a2)) * currentValue); + var prevAlpha2 = i >= 1 ? alpha2List[i - 1] : currentValue; + var priorAlpha2 = i >= 2 ? alpha2List[i - 2] : currentValue; + var alpha2 = (b2 * prevAlpha2) - (a2 * a2 * priorAlpha2) + ((1 - b2 + (a2 * a2)) * currentValue); alpha2List.AddRounded(alpha2); - double prevAlpha3 = i >= 1 ? alpha3List[i - 1] : currentValue; - double prevAlpha3_2 = i >= 2 ? alpha3List[i - 2] : currentValue; - double prevAlpha3_3 = i >= 3 ? alpha3List[i - 3] : currentValue; - double alpha3 = ((b3 + c) * prevAlpha3) - ((c + (b3 * c)) * prevAlpha3_2) + (c * c * prevAlpha3_3) + ((1 - b3 + c) * (1 - c) * currentValue); + var prevAlpha3 = i >= 1 ? alpha3List[i - 1] : currentValue; + var prevAlpha3_2 = i >= 2 ? alpha3List[i - 2] : currentValue; + var prevAlpha3_3 = i >= 3 ? alpha3List[i - 3] : currentValue; + var alpha3 = ((b3 + c) * prevAlpha3) - ((c + (b3 * c)) * prevAlpha3_2) + (c * c * prevAlpha3_3) + ((1 - b3 + c) * (1 - c) * currentValue); alpha3List.AddRounded(alpha3); - double detrend1 = currentValue - alpha1; - double detrend2 = currentValue - alpha2; - double detrend3 = currentValue - alpha3; + var detrend1 = currentValue - alpha1; + var detrend2 = currentValue - alpha2; + var detrend3 = currentValue - alpha3; - double prevBeta1 = i >= 1 ? beta1List[i - 1] : 0; - double beta1 = (a1 * detrend1) + ((1 - a1) * prevBeta1); + var prevBeta1 = i >= 1 ? beta1List[i - 1] : 0; + var beta1 = (a1 * detrend1) + ((1 - a1) * prevBeta1); beta1List.AddRounded(beta1); - double prevBeta2 = i >= 1 ? beta2List[i - 1] : 0; - double prevBeta2_2 = i >= 2 ? beta2List[i - 2] : 0; - double beta2 = (b2 * prevBeta2) - (a2 * a2 * prevBeta2_2) + ((1 - b2 + (a2 * a2)) * detrend2); + var prevBeta2 = i >= 1 ? beta2List[i - 1] : 0; + var prevBeta2_2 = i >= 2 ? beta2List[i - 2] : 0; + var beta2 = (b2 * prevBeta2) - (a2 * a2 * prevBeta2_2) + ((1 - b2 + (a2 * a2)) * detrend2); beta2List.AddRounded(beta2); - double prevBeta3_2 = i >= 2 ? beta3List[i - 2] : 0; - double prevBeta3_3 = i >= 3 ? beta3List[i - 3] : 0; - double beta3 = ((b3 + c) * prevBeta3_2) - ((c + (b3 * c)) * prevBeta3_2) + (c * c * prevBeta3_3) + ((1 - b3 + c) * (1 - c) * detrend3); + var prevBeta3_2 = i >= 2 ? beta3List[i - 2] : 0; + var prevBeta3_3 = i >= 3 ? beta3List[i - 3] : 0; + var beta3 = ((b3 + c) * prevBeta3_2) - ((c + (b3 * c)) * prevBeta3_2) + (c * c * prevBeta3_3) + ((1 - b3 + c) * (1 - c) * detrend3); beta3List.AddRounded(beta3); - double mda1 = alpha1 + ((double)1 / 1 * beta1); + var mda1 = alpha1 + ((double)1 / 1 * beta1); mda1List.AddRounded(mda1); - double prevMda2 = mda2List.LastOrDefault(); - double mda2 = alpha2 + ((double)1 / 2 * beta2); + var prevMda2 = mda2List.LastOrDefault(); + var mda2 = alpha2 + ((double)1 / 2 * beta2); mda2List.AddRounded(mda2); - double mda3 = alpha3 + ((double)1 / 3 * beta3); + var mda3 = alpha3 + ((double)1 / 3 * beta3); mda3List.AddRounded(mda3); var signal = GetCompareSignal(currentValue - mda2, prevValue - prevMda2); @@ -5864,30 +5864,30 @@ public static StockData CalculateModularFilter(this StockData stockData, int len List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); + var alpha = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevB2 = i >= 1 ? b2List[i - 1] : currentValue; - double b2 = currentValue > (alpha * currentValue) + ((1 - alpha) * prevB2) ? currentValue : (alpha * currentValue) + ((1 - alpha) * prevB2); + var prevB2 = i >= 1 ? b2List[i - 1] : currentValue; + var b2 = currentValue > (alpha * currentValue) + ((1 - alpha) * prevB2) ? currentValue : (alpha * currentValue) + ((1 - alpha) * prevB2); b2List.AddRounded(b2); - double prevC2 = i >= 1 ? c2List[i - 1] : currentValue; - double c2 = currentValue < (alpha * currentValue) + ((1 - alpha) * prevC2) ? currentValue : (alpha * currentValue) + ((1 - alpha) * prevC2); + var prevC2 = i >= 1 ? c2List[i - 1] : currentValue; + var c2 = currentValue < (alpha * currentValue) + ((1 - alpha) * prevC2) ? currentValue : (alpha * currentValue) + ((1 - alpha) * prevC2); c2List.AddRounded(c2); - double prevOs2 = os2List.LastOrDefault(); - double os2 = currentValue == b2 ? 1 : currentValue == c2 ? 0 : prevOs2; + var prevOs2 = os2List.LastOrDefault(); + var os2 = currentValue == b2 ? 1 : currentValue == c2 ? 0 : prevOs2; os2List.AddRounded(os2); - double upper2 = (beta * b2) + ((1 - beta) * c2); - double lower2 = (beta * c2) + ((1 - beta) * b2); + var upper2 = (beta * b2) + ((1 - beta) * c2); + var lower2 = (beta * c2) + ((1 - beta) * b2); - double prevTs2 = ts2List.LastOrDefault(); - double ts2 = (os2 * upper2) + ((1 - os2) * lower2); + var prevTs2 = ts2List.LastOrDefault(); + var ts2 = (os2 * upper2) + ((1 - os2) * lower2); ts2List.AddRounded(ts2); var signal = GetCompareSignal(currentValue - ts2, prevValue - prevTs2); @@ -5917,23 +5917,23 @@ public static StockData CalculateDampedSineWaveWeightedFilter(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double w, wSum = 0, wvSum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; w = Math.Sin(MinOrMax(2 * Math.PI * ((double)j / length), 0.99, 0.01)) / j; wvSum += w * prevValue; wSum += w; } - double prevDswwf = dswwfList.LastOrDefault(); - double dswwf = wSum != 0 ? wvSum / wSum : 0; + var prevDswwf = dswwfList.LastOrDefault(); + var dswwf = wSum != 0 ? wvSum / wSum : 0; dswwfList.AddRounded(dswwf); var signal = GetCompareSignal(currentValue - dswwf, prevVal - prevDswwf); @@ -5964,15 +5964,15 @@ public static StockData CalculateDoubleExponentialSmoothing(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double x = inputList[i]; - double prevX = i >= 1 ? inputList[i - 1] : 0; - double prevS = i >= 1 ? sList[i - 1] : 0; - double prevS2 = i >= 2 ? sList[i - 2] : 0; - double sChg = prevS - prevS2; + var x = inputList[i]; + var prevX = i >= 1 ? inputList[i - 1] : 0; + var prevS = i >= 1 ? sList[i - 1] : 0; + var prevS2 = i >= 2 ? sList[i - 2] : 0; + var sChg = prevS - prevS2; - double s = (alpha * x) + ((1 - alpha) * (prevS + (gamma * (sChg + ((1 - gamma) * sChg))))); + var s = (alpha * x) + ((1 - alpha) * (prevS + (gamma * (sChg + ((1 - gamma) * sChg))))); sList.AddRounded(s); var signal = GetCompareSignal(x - s, prevX - prevS); @@ -6002,32 +6002,32 @@ public static StockData CalculateDistanceWeightedMovingAverage(this StockData st List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; double distanceSum = 0; - for (int k = 0; k < length; k++) + for (var k = 0; k < length; k++) { - double prevValue2 = i >= k ? inputList[i - k] : 0; + var prevValue2 = i >= k ? inputList[i - k] : 0; distanceSum += Math.Abs(prevValue - prevValue2); } - double weight = distanceSum != 0 ? 1 / distanceSum : 0; + var weight = distanceSum != 0 ? 1 / distanceSum : 0; sum += prevValue * weight; weightedSum += weight; } - double prevDwma = dwmaList.LastOrDefault(); - double dwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevDwma = dwmaList.LastOrDefault(); + var dwma = weightedSum != 0 ? sum / weightedSum : 0; dwmaList.AddRounded(dwma); var signal = GetCompareSignal(currentValue - dwma, prevVal - prevDwma); @@ -6060,25 +6060,25 @@ public static StockData CalculateDynamicallyAdjustableFilter(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevOut = i >= 1 ? outList[i - 1] : currentValue; - double prevK = i >= 1 ? kList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevOut = i >= 1 ? outList[i - 1] : currentValue; + var prevK = i >= 1 ? kList[i - 1] : 0; - double src = currentValue + (currentValue - prevOut); + var src = currentValue + (currentValue - prevOut); srcList.AddRounded(src); - double outVal = prevOut + (prevK * (src - prevOut)); + var outVal = prevOut + (prevK * (src - prevOut)); outList.AddRounded(outVal); - double srcSma = srcList.TakeLastExt(length).Average(); - double srcDev = Pow(src - srcSma, 2); + var srcSma = srcList.TakeLastExt(length).Average(); + var srcDev = Pow(src - srcSma, 2); srcDevList.AddRounded(srcDev); - double srcStdDev = Sqrt(srcDevList.TakeLastExt(length).Average()); - double k = src - outVal != 0 ? Math.Abs(src - outVal) / (Math.Abs(src - outVal) + (srcStdDev * length)) : 0; + var srcStdDev = Sqrt(srcDevList.TakeLastExt(length).Average()); + var k = src - outVal != 0 ? Math.Abs(src - outVal) / (Math.Abs(src - outVal) + (srcStdDev * length)) : 0; kList.AddRounded(k); var signal = GetCompareSignal(currentValue - outVal, prevValue - prevOut); @@ -6114,23 +6114,23 @@ public static StockData CalculateDynamicallyAdjustableMovingAverage(this StockDa var shortStdDevList = CalculateStandardDeviationVolatility(stockData, length: fastLength).CustomValuesList; var longStdDevList = CalculateStandardDeviationVolatility(stockData, length: slowLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = shortStdDevList[i]; - double b = longStdDevList[i]; - double v = a != 0 ? (b / a) + fastLength : fastLength; + var a = shortStdDevList[i]; + var b = longStdDevList[i]; + var v = a != 0 ? (b / a) + fastLength : fastLength; - double prevValue = tempList.LastOrDefault(); - double currentValue = inputList[i]; + var prevValue = tempList.LastOrDefault(); + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - int p = (int)Math.Round(MinOrMax(v, slowLength, fastLength)); - double prevK = i >= p ? kList[i - p] : 0; - double k = tempList.Sum(); + var p = (int)Math.Round(MinOrMax(v, slowLength, fastLength)); + var prevK = i >= p ? kList[i - p] : 0; + var k = tempList.Sum(); kList.AddRounded(k); - double prevAma = amaList.LastOrDefault(); - double ama = p != 0 ? (k - prevK) / p : 0; + var prevAma = amaList.LastOrDefault(); + var ama = p != 0 ? (k - prevK) / p : 0; amaList.AddRounded(ama); var signal = GetCompareSignal(currentValue - ama, prevValue - prevAma); @@ -6159,13 +6159,13 @@ public static StockData CalculateSpencer21PointMovingAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= 20; j++) + for (var j = 0; j <= 20; j++) { var weight = j switch { @@ -6192,14 +6192,14 @@ public static StockData CalculateSpencer21PointMovingAverage(this StockData stoc 20 => -1, _ => 0, }; - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevSpma = spmaList.LastOrDefault(); - double spma = weightedSum != 0 ? sum / weightedSum : 0; + var prevSpma = spmaList.LastOrDefault(); + var spma = weightedSum != 0 ? sum / weightedSum : 0; spmaList.AddRounded(spma); var signal = GetCompareSignal(currentValue - spma, prevVal - prevSpma); @@ -6228,13 +6228,13 @@ public static StockData CalculateSpencer15PointMovingAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= 14; j++) + for (var j = 0; j <= 14; j++) { var weight = j switch { @@ -6255,14 +6255,14 @@ public static StockData CalculateSpencer15PointMovingAverage(this StockData stoc 14 => -3, _ => 0, }; - double prevValue = i >= j ? inputList[i - j] : 0; + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevSpma = spmaList.LastOrDefault(); - double spma = weightedSum != 0 ? sum / weightedSum : 0; + var prevSpma = spmaList.LastOrDefault(); + var spma = weightedSum != 0 ? sum / weightedSum : 0; spmaList.AddRounded(spma); var signal = GetCompareSignal(currentValue - spma, prevVal - prevSpma); @@ -6292,23 +6292,23 @@ public static StockData CalculateSquareRootWeightedMovingAverage(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Pow(length - j, 0.5); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Pow(length - j, 0.5); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevSrwma = srwmaList.LastOrDefault(); - double srwma = weightedSum != 0 ? sum / weightedSum : 0; + var prevSrwma = srwmaList.LastOrDefault(); + var srwma = weightedSum != 0 ? sum / weightedSum : 0; srwmaList.AddRounded(srwma); var signal = GetCompareSignal(currentValue - srwma, prevVal - prevSrwma); @@ -6339,19 +6339,19 @@ public static StockData CalculateShapeshiftingMovingAverage(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sumX = 0, weightedSumX = 0, sumN = 0, weightedSumN = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double x = (double)j / (length - 1); - double n = -1 + (x * 2); - double wx = 1 - (2 * x / (Pow(x, 4) + 1)); - double wn = 1 - (2 * Pow(n, 2) / (Pow(n, 4 - (4 % 2)) + 1)); - double prevValue = i >= j ? inputList[i - j] : 0; + var x = (double)j / (length - 1); + var n = -1 + (x * 2); + var wx = 1 - (2 * x / (Pow(x, 4) + 1)); + var wn = 1 - (2 * Pow(n, 2) / (Pow(n, 4 - (4 % 2)) + 1)); + var prevValue = i >= j ? inputList[i - j] : 0; sumX += prevValue * wx; weightedSumX += wx; @@ -6359,11 +6359,11 @@ public static StockData CalculateShapeshiftingMovingAverage(this StockData stock weightedSumN += wn; } - double prevFiltX = filtXList.LastOrDefault(); - double filtX = weightedSumX != 0 ? sumX / weightedSumX : 0; + var prevFiltX = filtXList.LastOrDefault(); + var filtX = weightedSumX != 0 ? sumX / weightedSumX : 0; filtXList.AddRounded(filtX); - double filtN = weightedSumN != 0 ? sumN / weightedSumN : 0; + var filtN = weightedSumN != 0 ? sumN / weightedSumN : 0; filtNList.AddRounded(filtN); var signal = GetCompareSignal(currentValue - filtX, prevVal - prevFiltX); @@ -6393,22 +6393,22 @@ public static StockData CalculateSelfWeightedMovingAverage(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double pValue = i >= j ? inputList[i - j] : 0; - double weight = i >= length + j ? inputList[i - (length + j)] : 0; + var pValue = i >= j ? inputList[i - j] : 0; + var weight = i >= length + j ? inputList[i - (length + j)] : 0; weightSum += weight; sum += weight * pValue; } - double prevWma = wmaList.LastOrDefault(); - double wma = weightSum != 0 ? sum / weightSum : 0; + var prevWma = wmaList.LastOrDefault(); + var wma = weightSum != 0 ? sum / weightSum : 0; wmaList.AddRounded(wma); var signal = GetCompareSignal(currentValue - wma, prevValue - prevWma); @@ -6438,23 +6438,23 @@ public static StockData CalculateSineWeightedMovingAverage(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double sum = 0, weightedSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double weight = Math.Sin((j + 1) * Math.PI / (length + 1)); - double prevValue = i >= j ? inputList[i - j] : 0; + var weight = Math.Sin((j + 1) * Math.PI / (length + 1)); + var prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } - double prevSwma = swmaList.LastOrDefault(); - double swma = weightedSum != 0 ? sum / weightedSum : 0; + var prevSwma = swmaList.LastOrDefault(); + var swma = weightedSum != 0 ? sum / weightedSum : 0; swmaList.AddRounded(swma); var signal = GetCompareSignal(currentValue - swma, prevVal - prevSwma); @@ -6488,25 +6488,25 @@ public static StockData CalculateSimplifiedWeightedMovingAverage(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double cml = tempList.Sum(); + var cml = tempList.Sum(); cmlList.AddRounded(cml); - double prevCmlSum = i >= length ? cmlSumList[i - length] : 0; - double cmlSum = cmlList.Sum(); + var prevCmlSum = i >= length ? cmlSumList[i - length] : 0; + var cmlSum = cmlList.Sum(); cmlSumList.AddRounded(cmlSum); - double prevSum = sumList.LastOrDefault(); - double sum = cmlSum - prevCmlSum; + var prevSum = sumList.LastOrDefault(); + var sum = cmlSum - prevCmlSum; sumList.AddRounded(sum); - double prevWma = wmaList.LastOrDefault(); - double wma = ((length * cml) - prevSum) / (length * (double)(length + 1) / 2); + var prevWma = wmaList.LastOrDefault(); + var wma = ((length * cml) - prevSum) / (length * (double)(length + 1) / 2); wmaList.AddRounded(wma); var signal = GetCompareSignal(currentValue - wma, prevValue - prevWma); @@ -6540,27 +6540,27 @@ public static StockData CalculateSimplifiedLeastSquaresMovingAverage(this StockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevCml = i >= length ? cmlList[i - length] : 0; - double cml = tempList.Sum(); + var prevCml = i >= length ? cmlList[i - length] : 0; + var cml = tempList.Sum(); cmlList.AddRounded(cml); - double prevCmlSum = i >= length ? cmlSumList[i - length] : 0; - double cmlSum = cmlList.Sum(); + var prevCmlSum = i >= length ? cmlSumList[i - length] : 0; + var cmlSum = cmlList.Sum(); cmlSumList.AddRounded(cmlSum); - double prevSum = sumList.LastOrDefault(); - double sum = cmlSum - prevCmlSum; + var prevSum = sumList.LastOrDefault(); + var sum = cmlSum - prevCmlSum; sumList.AddRounded(sum); - double wma = ((length * cml) - prevSum) / (length * (double)(length + 1) / 2); - double prevLsma = lsmaList.LastOrDefault(); - double lsma = length != 0 ? (3 * wma) - (2 * (cml - prevCml) / length) : 0; + var wma = ((length * cml) - prevSum) / (length * (double)(length + 1) / 2); + var prevLsma = lsmaList.LastOrDefault(); + var lsma = length != 0 ? (3 * wma) - (2 * (cml - prevCml) / length) : 0; lsmaList.AddRounded(lsma); var signal = GetCompareSignal(currentValue - lsma, prevValue - prevLsma); @@ -6593,22 +6593,22 @@ public static StockData CalculateSharpModifiedMovingAverage(this StockData stock var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; double slope = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; double factor = 1 + (2 * (j - 1)); slope += prevValue * (length - factor) / 2; } - double prevShmma = shmmaList.LastOrDefault(); - double shmma = currentSma + (6 * slope / ((length + 1) * length)); + var prevShmma = shmmaList.LastOrDefault(); + var shmma = currentSma + (6 * slope / ((length + 1) * length)); shmmaList.AddRounded(shmma); var signal = GetCompareSignal(currentValue - shmma, prevVal - prevShmma); @@ -6638,20 +6638,20 @@ public static StockData CalculateSlowSmoothedMovingAverage(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int w2 = MinOrMax((int)Math.Ceiling((double)length / 3)); - int w1 = MinOrMax((int)Math.Ceiling((double)(length - w2) / 2)); - int w3 = MinOrMax((int)Math.Floor((double)(length - w2) / 2)); + var w2 = MinOrMax((int)Math.Ceiling((double)length / 3)); + var w1 = MinOrMax((int)Math.Ceiling((double)(length - w2) / 2)); + var w3 = MinOrMax((int)Math.Floor((double)(length - w2) / 2)); var l1List = GetMovingAverageList(stockData, maType, w1, inputList); var l2List = GetMovingAverageList(stockData, maType, w2, l1List); var l3List = GetMovingAverageList(stockData, maType, w3, l2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double l3 = l3List[i]; - double prevL3 = i >= 1 ? l3List[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var l3 = l3List[i]; + var prevL3 = i >= 1 ? l3List[i - 1] : 0; var signal = GetCompareSignal(currentValue - l3, prevValue - prevL3); signalsList.Add(signal); @@ -6685,20 +6685,20 @@ public static StockData CalculateSequentiallyFilteredMovingAverage(this StockDat var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = smaList[i]; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; + var prevSma = i >= 1 ? smaList[i - 1] : 0; double a = Math.Sign(sma - prevSma); signList.AddRounded(a); - double sum = signList.TakeLastExt(length).Sum(); + var sum = signList.TakeLastExt(length).Sum(); double alpha = Math.Abs(sum) == length ? 1 : 0; - double prevSfma = i >= 1 ? sfmaList[i - 1] : sma; - double sfma = (alpha * sma) + ((1 - alpha) * prevSfma); + var prevSfma = i >= 1 ? sfmaList[i - 1] : sma; + var sfma = (alpha * sma) + ((1 - alpha) * prevSfma); sfmaList.AddRounded(sfma); var signal = GetCompareSignal(currentValue - sfma, prevValue - prevSfma); @@ -6731,29 +6731,29 @@ public static StockData CalculateSvama(this StockData stockData, int length = 14 List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double a = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var a = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevH = i >= 1 ? hList[i - 1] : a; - double h = a > prevH ? a : prevH; + var prevH = i >= 1 ? hList[i - 1] : a; + var h = a > prevH ? a : prevH; hList.AddRounded(h); - double prevL = i >= 1 ? lList[i - 1] : a; - double l = a < prevL ? a : prevL; + var prevL = i >= 1 ? lList[i - 1] : a; + var l = a < prevL ? a : prevL; lList.AddRounded(l); - double bMax = h != 0 ? a / h : 0; - double bMin = a != 0 ? l / a : 0; + var bMax = h != 0 ? a / h : 0; + var bMin = a != 0 ? l / a : 0; - double prevCMax = i >= 1 ? cMaxList[i - 1] : currentValue; - double cMax = (bMax * currentValue) + ((1 - bMax) * prevCMax); + var prevCMax = i >= 1 ? cMaxList[i - 1] : currentValue; + var cMax = (bMax * currentValue) + ((1 - bMax) * prevCMax); cMaxList.AddRounded(cMax); - double prevCMin = i >= 1 ? cMinList[i - 1] : currentValue; - double cMin = (bMin * currentValue) + ((1 - bMin) * prevCMin); + var prevCMin = i >= 1 ? cMinList[i - 1] : currentValue; + var cMin = (bMin * currentValue) + ((1 - bMin) * prevCMin); cMinList.AddRounded(cMin); var signal = GetCompareSignal(currentValue - cMax, prevValue - prevCMax); @@ -6784,22 +6784,22 @@ public static StockData CalculateSettingLessTrendStepFiltering(this StockData st List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double prevA = aList.LastOrDefault(); - double sc = Math.Abs(currentValue - prevB) + prevA != 0 ? Math.Abs(currentValue - prevB) / (Math.Abs(currentValue - prevB) + prevA) : 0; - double sltsf = (sc * currentValue) + ((1 - sc) * prevB); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var prevA = aList.LastOrDefault(); + var sc = Math.Abs(currentValue - prevB) + prevA != 0 ? Math.Abs(currentValue - prevB) / (Math.Abs(currentValue - prevB) + prevA) : 0; + var sltsf = (sc * currentValue) + ((1 - sc) * prevB); - double chg = Math.Abs(sltsf - prevB); + var chg = Math.Abs(sltsf - prevB); chgList.AddRounded(chg); - double a = chgList.Average() * (1 + sc); + var a = chgList.Average() * (1 + sc); aList.AddRounded(a); - double b = sltsf > prevB + a ? sltsf : sltsf < prevB - a ? sltsf : prevB; + var b = sltsf > prevB + a ? sltsf : sltsf < prevB - a ? sltsf : prevB; bList.AddRounded(b); var signal = GetCompareSignal(currentValue - b, prevValue - prevB); @@ -6834,16 +6834,16 @@ public static StockData CalculateElasticVolumeWeightedMovingAverageV1(this Stock var volumeSmaList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentAvgVolume = volumeSmaList[i]; - double currentVolume = volumeList[i]; - double n = currentAvgVolume * mult; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentAvgVolume = volumeSmaList[i]; + var currentVolume = volumeList[i]; + var n = currentAvgVolume * mult; - double prevEVWMA = i >= 1 ? evwmaList.LastOrDefault() : currentValue; - double evwma = n > 0 ? (((n - currentVolume) * prevEVWMA) + (currentVolume * currentValue)) / n : 0; ; + var prevEVWMA = i >= 1 ? evwmaList.LastOrDefault() : currentValue; + var evwma = n > 0 ? (((n - currentVolume) * prevEVWMA) + (currentVolume * currentValue)) / n : 0; ; evwmaList.AddRounded(evwma); var signal = GetCompareSignal(currentValue - evwma, prevValue - prevEVWMA); @@ -6874,17 +6874,17 @@ public static StockData CalculateElasticVolumeWeightedMovingAverageV2(this Stock List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; + var currentVolume = volumeList[i]; tempList.AddRounded(currentVolume); - double volumeSum = tempList.TakeLastExt(length).Sum(); - double prevEvwma = evwmaList.LastOrDefault(); - double evwma = volumeSum != 0 ? (((volumeSum - currentVolume) * prevEvwma) + (currentVolume * currentValue)) / volumeSum : 0; + var volumeSum = tempList.TakeLastExt(length).Sum(); + var prevEvwma = evwmaList.LastOrDefault(); + var evwma = volumeSum != 0 ? (((volumeSum - currentVolume) * prevEvwma) + (currentVolume * currentValue)) / volumeSum : 0; evwmaList.AddRounded(evwma); var signal = GetCompareSignal(currentValue - evwma, prevValue - prevEvwma); @@ -6920,28 +6920,28 @@ public static StockData CalculateEquityMovingAverage(this StockData stockData, M var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = smaList[i]; - double prevEqma = i >= 1 ? eqmaList[i - 1] : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; + var prevEqma = i >= 1 ? eqmaList[i - 1] : currentValue; - double prevX = xList.LastOrDefault(); + var prevX = xList.LastOrDefault(); double x = Math.Sign(currentValue - sma); xList.AddRounded(x); - double chgX = MinPastValues(i, 1, currentValue - prevValue) * prevX; + var chgX = MinPastValues(i, 1, currentValue - prevValue) * prevX; chgXList.AddRounded(chgX); - double chgXCum = MinPastValues(i, 1, currentValue - prevValue) * x; + var chgXCum = MinPastValues(i, 1, currentValue - prevValue) * x; chgXCumList.AddRounded(chgXCum); - double opteq = chgXCumList.Sum(); - double req = chgXList.TakeLastExt(length).Sum(); - double alpha = opteq != 0 ? MinOrMax(req / opteq, 0.99, 0.01) : 0.99; + var opteq = chgXCumList.Sum(); + var req = chgXList.TakeLastExt(length).Sum(); + var alpha = opteq != 0 ? MinOrMax(req / opteq, 0.99, 0.01) : 0.99; - double eqma = (alpha * currentValue) + ((1 - alpha) * prevEqma); + var eqma = (alpha * currentValue) + ((1 - alpha) * prevEqma); eqmaList.AddRounded(eqma); var signal = GetCompareSignal(currentValue - eqma, prevValue - prevEqma); @@ -6981,47 +6981,47 @@ public static StockData CalculateEdgePreservingFilter(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; + var currentValue = inputList[i]; + var sma = smaList[i]; - double os = currentValue - sma; + var os = currentValue - sma; osList.AddRounded(os); - double absOs = Math.Abs(os); + var absOs = Math.Abs(os); absOsList.AddRounded(absOs); } stockData.CustomValuesList = absOsList; var pList = CalculateLinearRegression(stockData, smoothLength).CustomValuesList; var (highestList, _) = GetMaxAndMinValuesList(pList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double p = pList[i]; - double highest = highestList[i]; - double os = osList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var p = pList[i]; + var highest = highestList[i]; + var os = osList[i]; - double prevH = hList.LastOrDefault(); - double h = highest != 0 ? p / highest : 0; + var prevH = hList.LastOrDefault(); + var h = highest != 0 ? p / highest : 0; hList.AddRounded(h); double cnd = h == 1 && prevH != 1 ? 1 : 0; double sign = cnd == 1 && os < 0 ? 1 : cnd == 1 && os > 0 ? -1 : 0; - bool condition = sign != 0; + var condition = sign != 0; - double prevA = i >= 1 ? aList[i - 1] : 1; - double a = condition ? 1 : prevA + 1; + var prevA = i >= 1 ? aList[i - 1] : 1; + var a = condition ? 1 : prevA + 1; aList.AddRounded(a); - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double b = a == 1 ? currentValue : prevB + currentValue; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var b = a == 1 ? currentValue : prevB + currentValue; bList.AddRounded(b); - double prevC = cList.LastOrDefault(); - double c = a != 0 ? b / a : 0; + var prevC = cList.LastOrDefault(); + var c = a != 0 ? b / a : 0; cList.AddRounded(c); var signal = GetCompareSignal(currentValue - c, prevValue - prevC); @@ -7051,20 +7051,20 @@ public static StockData CalculateEhlers2PoleSuperSmootherFilterV2(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); - double b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); - double c2 = b; - double c3 = -a * a; - double c1 = 1 - c2 - c3; + var a = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); + var b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); + var c2 = b; + var c3 = -a * a; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double filt = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filt = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); @@ -7094,24 +7094,24 @@ public static StockData CalculateEhlers3PoleSuperSmootherFilter(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double arg = MinOrMax(Math.PI / length, 0.99, 0.01); - double a1 = Exp(-arg); - double b1 = 2 * a1 * Math.Cos(1.738 * arg); - double c1 = a1 * a1; - double coef2 = b1 + c1; - double coef3 = -(c1 + (b1 * c1)); - double coef4 = c1 * c1; - double coef1 = 1 - coef2 - coef3 - coef4; + var arg = MinOrMax(Math.PI / length, 0.99, 0.01); + var a1 = Exp(-arg); + var b1 = 2 * a1 * Math.Cos(1.738 * arg); + var c1 = a1 * a1; + var coef2 = b1 + c1; + var coef3 = -(c1 + (b1 * c1)); + var coef4 = c1 * c1; + var coef1 = 1 - coef2 - coef3 - coef4; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double prevFilter3 = i >= 3 ? filtList[i - 3] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var prevFilter3 = i >= 3 ? filtList[i - 3] : 0; - double filt = i < 4 ? currentValue : (coef1 * currentValue) + (coef2 * prevFilter1) + (coef3 * prevFilter2) + (coef4 * prevFilter3); + var filt = i < 4 ? currentValue : (coef1 * currentValue) + (coef2 * prevFilter1) + (coef3 * prevFilter2) + (coef4 * prevFilter3); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); @@ -7141,20 +7141,20 @@ public static StockData CalculateEhlers2PoleButterworthFilterV1(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); - double b = 2 * a * Math.Cos(MinOrMax(1.414 * 1.25 * Math.PI / length, 0.99, 0.01)); - double c2 = b; - double c3 = -a * a; - double c1 = 1 - c2 - c3; + var a = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); + var b = 2 * a * Math.Cos(MinOrMax(1.414 * 1.25 * Math.PI / length, 0.99, 0.01)); + var c2 = b; + var c3 = -a * a; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double filt = (c1 * currentValue) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filt = (c1 * currentValue) + (c2 * prevFilter1) + (c3 * prevFilter2); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); @@ -7184,21 +7184,21 @@ public static StockData CalculateEhlers2PoleButterworthFilterV2(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); - double b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); - double c2 = b; - double c3 = -a * a; - double c1 = (1 - b + Pow(a, 2)) / 4; + var a = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); + var b = 2 * a * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); + var c2 = b; + var c3 = -a * a; + var c1 = (1 - b + Pow(a, 2)) / 4; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var currentValue = inputList[i]; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; - double filt = i < 3 ? currentValue : (c1 * (currentValue + (2 * prevValue1) + prevValue3)) + (c2 * prevFilter1) + (c3 * prevFilter2); + var filt = i < 3 ? currentValue : (c1 * (currentValue + (2 * prevValue1) + prevValue3)) + (c2 * prevFilter1) + (c3 * prevFilter2); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue1 - prevFilter1); @@ -7228,23 +7228,23 @@ public static StockData CalculateEhlers3PoleButterworthFilterV1(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a = Exp(MinOrMax(-Math.PI / length, -0.01, -0.99)); - double b = 2 * a * Math.Cos(MinOrMax(1.738 * Math.PI / length, 0.99, 0.01)); - double c = a * a; - double d2 = b + c; - double d3 = -(c + (b * c)); - double d4 = c * c; - double d1 = 1 - d2 - d3 - d4; + var a = Exp(MinOrMax(-Math.PI / length, -0.01, -0.99)); + var b = 2 * a * Math.Cos(MinOrMax(1.738 * Math.PI / length, 0.99, 0.01)); + var c = a * a; + var d2 = b + c; + var d3 = -(c + (b * c)); + var d4 = c * c; + var d1 = 1 - d2 - d3 - d4; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double prevFilter3 = i >= 3 ? filtList[i - 3] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var prevFilter3 = i >= 3 ? filtList[i - 3] : 0; - double filt = (d1 * currentValue) + (d2 * prevFilter1) + (d3 * prevFilter2) + (d4 * prevFilter3); + var filt = (d1 * currentValue) + (d2 * prevFilter1) + (d3 * prevFilter2) + (d4 * prevFilter3); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); @@ -7274,26 +7274,26 @@ public static StockData CalculateEhlers3PoleButterworthFilterV2(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(MinOrMax(-Math.PI / length, -0.01, -0.99)); - double b1 = 2 * a1 * Math.Cos(MinOrMax(1.738 * Math.PI / length, 0.99, 0.01)); - double c1 = a1 * a1; - double coef2 = b1 + c1; - double coef3 = -(c1 + (b1 * c1)); - double coef4 = c1 * c1; - double coef1 = (1 - b1 + c1) * (1 - c1) / 8; + var a1 = Exp(MinOrMax(-Math.PI / length, -0.01, -0.99)); + var b1 = 2 * a1 * Math.Cos(MinOrMax(1.738 * Math.PI / length, 0.99, 0.01)); + var c1 = a1 * a1; + var coef2 = b1 + c1; + var coef3 = -(c1 + (b1 * c1)); + var coef4 = c1 * c1; + var coef1 = (1 - b1 + c1) * (1 - c1) / 8; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double prevFilter3 = i >= 3 ? filtList[i - 3] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var prevFilter3 = i >= 3 ? filtList[i - 3] : 0; - double filt = i < 4 ? currentValue : (coef1 * (currentValue + (3 * prevValue1) + (3 * prevValue2) + prevValue3)) + (coef2 * prevFilter1) + - (coef3 * prevFilter2) + (coef4 * prevFilter3); + var filt = i < 4 ? currentValue : (coef1 * (currentValue + (3 * prevValue1) + (3 * prevValue2) + prevValue3)) + (coef2 * prevFilter1) + + (coef3 * prevFilter2) + (coef4 * prevFilter3); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue1 - prevFilter1); @@ -7326,42 +7326,42 @@ public static StockData CalculateEhlersGaussianFilter(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double cosVal = MinOrMax(2 * Math.PI / length, 0.99, 0.01); - double beta1 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 1) - 1); - double beta2 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 2) - 1); - double beta3 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 3) - 1); - double beta4 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 4) - 1); - double alpha1 = -beta1 + Sqrt(Pow(beta1, 2) + (2 * beta1)); - double alpha2 = -beta2 + Sqrt(Pow(beta2, 2) + (2 * beta2)); - double alpha3 = -beta3 + Sqrt(Pow(beta3, 2) + (2 * beta3)); - double alpha4 = -beta4 + Sqrt(Pow(beta4, 2) + (2 * beta4)); - - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevGf1 = i >= 1 ? gf1List[i - 1] : 0; - double prevGf2_1 = i >= 1 ? gf2List[i - 1] : 0; - double prevGf2_2 = i >= 2 ? gf2List[i - 2] : 0; - double prevGf3_1 = i >= 1 ? gf3List[i - 1] : 0; - double prevGf4_1 = i >= 1 ? gf4List[i - 1] : 0; - double prevGf3_2 = i >= 2 ? gf3List[i - 2] : 0; - double prevGf4_2 = i >= 2 ? gf4List[i - 2] : 0; - double prevGf3_3 = i >= 3 ? gf3List[i - 3] : 0; - double prevGf4_3 = i >= 3 ? gf4List[i - 3] : 0; - double prevGf4_4 = i >= 4 ? gf4List[i - 4] : 0; - - double gf1 = (alpha1 * currentValue) + ((1 - alpha1) * prevGf1); + var cosVal = MinOrMax(2 * Math.PI / length, 0.99, 0.01); + var beta1 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 1) - 1); + var beta2 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 2) - 1); + var beta3 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 3) - 1); + var beta4 = (1 - Math.Cos(cosVal)) / (Pow(2, (double)1 / 4) - 1); + var alpha1 = -beta1 + Sqrt(Pow(beta1, 2) + (2 * beta1)); + var alpha2 = -beta2 + Sqrt(Pow(beta2, 2) + (2 * beta2)); + var alpha3 = -beta3 + Sqrt(Pow(beta3, 2) + (2 * beta3)); + var alpha4 = -beta4 + Sqrt(Pow(beta4, 2) + (2 * beta4)); + + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevGf1 = i >= 1 ? gf1List[i - 1] : 0; + var prevGf2_1 = i >= 1 ? gf2List[i - 1] : 0; + var prevGf2_2 = i >= 2 ? gf2List[i - 2] : 0; + var prevGf3_1 = i >= 1 ? gf3List[i - 1] : 0; + var prevGf4_1 = i >= 1 ? gf4List[i - 1] : 0; + var prevGf3_2 = i >= 2 ? gf3List[i - 2] : 0; + var prevGf4_2 = i >= 2 ? gf4List[i - 2] : 0; + var prevGf3_3 = i >= 3 ? gf3List[i - 3] : 0; + var prevGf4_3 = i >= 3 ? gf4List[i - 3] : 0; + var prevGf4_4 = i >= 4 ? gf4List[i - 4] : 0; + + var gf1 = (alpha1 * currentValue) + ((1 - alpha1) * prevGf1); gf1List.AddRounded(gf1); - double gf2 = (Pow(alpha2, 2) * currentValue) + (2 * (1 - alpha2) * prevGf2_1) - (Pow(1 - alpha2, 2) * prevGf2_2); + var gf2 = (Pow(alpha2, 2) * currentValue) + (2 * (1 - alpha2) * prevGf2_1) - (Pow(1 - alpha2, 2) * prevGf2_2); gf2List.AddRounded(gf2); - double gf3 = (Pow(alpha3, 3) * currentValue) + (3 * (1 - alpha3) * prevGf3_1) - (3 * Pow(1 - alpha3, 2) * prevGf3_2) + - (Pow(1 - alpha3, 3) * prevGf3_3); + var gf3 = (Pow(alpha3, 3) * currentValue) + (3 * (1 - alpha3) * prevGf3_1) - (3 * Pow(1 - alpha3, 2) * prevGf3_2) + + (Pow(1 - alpha3, 3) * prevGf3_3); gf3List.AddRounded(gf3); - double gf4 = (Pow(alpha4, 4) * currentValue) + (4 * (1 - alpha4) * prevGf4_1) - (6 * Pow(1 - alpha4, 2) * prevGf4_2) + + var gf4 = (Pow(alpha4, 4) * currentValue) + (4 * (1 - alpha4) * prevGf4_1) - (6 * Pow(1 - alpha4, 2) * prevGf4_2) + (4 * Pow(1 - alpha4, 3) * prevGf4_3) - (Pow(1 - alpha4, 4) * prevGf4_4); gf4List.AddRounded(gf4); @@ -7397,19 +7397,19 @@ public static StockData CalculateEhlersRecursiveMedianFilter(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alphaArg = MinOrMax(2 * Math.PI / length2, 0.99, 0.01); - double alphaArgCos = Math.Cos(alphaArg); - double alpha = alphaArgCos != 0 ? (alphaArgCos + Math.Sin(alphaArg) - 1) / alphaArgCos : 0; + var alphaArg = MinOrMax(2 * Math.PI / length2, 0.99, 0.01); + var alphaArgCos = Math.Cos(alphaArg); + var alpha = alphaArgCos != 0 ? (alphaArgCos + Math.Sin(alphaArg) - 1) / alphaArgCos : 0; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = tempList.LastOrDefault(); - double currentValue = inputList[i]; + var prevValue = tempList.LastOrDefault(); + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double median = tempList.TakeLastExt(length1).Median(); - double prevRmf = rmfList.LastOrDefault(); - double rmf = (alpha * median) + ((1 - alpha) * prevRmf); + var median = tempList.TakeLastExt(length1).Median(); + var prevRmf = rmfList.LastOrDefault(); + var rmf = (alpha * median) + ((1 - alpha) * prevRmf); rmfList.AddRounded(rmf); var signal = GetCompareSignal(currentValue - rmf, prevValue - prevRmf); @@ -7439,21 +7439,21 @@ public static StockData CalculateEhlersSuperSmootherFilter(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); - double b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); - double coeff2 = b1; - double coeff3 = -1 * a1 * a1; - double coeff1 = 1 - coeff2 - coeff3; + var a1 = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); + var b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); + var coeff2 = b1; + var coeff3 = -1 * a1 * a1; + var coeff1 = 1 - coeff2 - coeff3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double prevFilt = filtList.LastOrDefault(); - double filt = (coeff1 * ((currentValue + prevValue) / 2)) + (coeff2 * prevFilter1) + (coeff3 * prevFilter2); + var prevFilt = filtList.LastOrDefault(); + var filt = (coeff1 * ((currentValue + prevValue) / 2)) + (coeff2 * prevFilter1) + (coeff3 * prevFilter2); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); @@ -7483,20 +7483,20 @@ public static StockData CalculateEhlers2PoleSuperSmootherFilterV1(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); - double b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); - double coef2 = b1; - double coef3 = -a1 * a1; - double coef1 = 1 - coef2 - coef3; + var a1 = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); + var b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); + var coef2 = b1; + var coef3 = -a1 * a1; + var coef1 = 1 - coef2 - coef3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevFilter1 = i >= 1 ? filtList[i - 1] : 0; - double prevFilter2 = i >= 2 ? filtList[i - 2] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + var prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double filt = i < 3 ? currentValue : (coef1 * currentValue) + (coef2 * prevFilter1) + (coef3 * prevFilter2); + var filt = i < 3 ? currentValue : (coef1 * currentValue) + (coef2 * prevFilter1) + (coef3 * prevFilter2); filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); @@ -7528,29 +7528,29 @@ public static StockData CalculateEhlersAverageErrorFilter(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a1 = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); - double b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); - double c2 = b1; - double c3 = -1 * a1 * a1; - double c1 = 1 - c2 - c3; + var a1 = Exp(MinOrMax(-1.414 * Math.PI / length, -0.01, -0.99)); + var b1 = 2 * a1 * Math.Cos(MinOrMax(1.414 * Math.PI / length, 0.99, 0.01)); + var c2 = b1; + var c3 = -1 * a1 * a1; + var c1 = 1 - c2 - c3; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevE11 = i >= 1 ? e1List[i - 1] : 0; - double prevE12 = i >= 2 ? e1List[i - 2] : 0; - double prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; - double prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevE11 = i >= 1 ? e1List[i - 1] : 0; + var prevE12 = i >= 2 ? e1List[i - 2] : 0; + var prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; + var prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; - double ssf = i < 3 ? currentValue : (0.5 * c1 * (currentValue + prevValue)) + (c2 * prevSsf1) + (c3 * prevSsf2); + var ssf = i < 3 ? currentValue : (0.5 * c1 * (currentValue + prevValue)) + (c2 * prevSsf1) + (c3 * prevSsf2); ssfList.AddRounded(ssf); - double e1 = i < 3 ? 0 : (c1 * (currentValue - ssf)) + (c2 * prevE11) + (c3 * prevE12); + var e1 = i < 3 ? 0 : (c1 * (currentValue - ssf)) + (c2 * prevE11) + (c3 * prevE12); e1List.AddRounded(e1); - double prevFilt = filtList.LastOrDefault(); - double filt = ssf + e1; + var prevFilt = filtList.LastOrDefault(); + var filt = ssf + e1; filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); @@ -7585,35 +7585,35 @@ public static StockData CalculateEhlersLaguerreFilter(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevP1 = i >= 1 ? inputList[i - 1] : 0; - double prevP2 = i >= 2 ? inputList[i - 2] : 0; - double prevP3 = i >= 3 ? inputList[i - 3] : 0; - double prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; - double prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; - double prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; - double prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; + var currentValue = inputList[i]; + var prevP1 = i >= 1 ? inputList[i - 1] : 0; + var prevP2 = i >= 2 ? inputList[i - 2] : 0; + var prevP3 = i >= 3 ? inputList[i - 3] : 0; + var prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; + var prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; + var prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; + var prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; - double l0 = (alpha * currentValue) + ((1 - alpha) * prevL0); + var l0 = (alpha * currentValue) + ((1 - alpha) * prevL0); l0List.AddRounded(l0); - double l1 = (-1 * (1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); + var l1 = (-1 * (1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); l1List.AddRounded(l1); - double l2 = (-1 * (1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); + var l2 = (-1 * (1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); l2List.AddRounded(l2); - double l3 = (-1 * (1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); + var l3 = (-1 * (1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); l3List.AddRounded(l3); - double prevFilter = filterList.LastOrDefault(); - double filter = (l0 + (2 * l1) + (2 * l2) + l3) / 6; + var prevFilter = filterList.LastOrDefault(); + var filter = (l0 + (2 * l1) + (2 * l2) + l3) / 6; filterList.AddRounded(filter); - double prevFir = firList.LastOrDefault(); - double fir = (currentValue + (2 * prevP1) + (2 * prevP2) + prevP3) / 6; + var prevFir = firList.LastOrDefault(); + var fir = (currentValue + (2 * prevP1) + (2 * prevP2) + prevP3) / 6; firList.AddRounded(fir); var signal = GetCompareSignal(filter - fir, prevFilter - prevFir); @@ -7651,43 +7651,43 @@ public static StockData CalculateEhlersAdaptiveLaguerreFilter(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; - double prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; - double prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; - double prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; - double prevFilter = i >= 1 ? filterList.LastOrDefault() : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; + var prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; + var prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; + var prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; + var prevFilter = i >= 1 ? filterList.LastOrDefault() : currentValue; - double diff = Math.Abs(currentValue - prevFilter); + var diff = Math.Abs(currentValue - prevFilter); diffList.AddRounded(diff); var list = diffList.TakeLastExt(length1).ToList(); - double highestHigh = list.Max(); - double lowestLow = list.Min(); + var highestHigh = list.Max(); + var lowestLow = list.Min(); - double mid = highestHigh - lowestLow != 0 ? (diff - lowestLow) / (highestHigh - lowestLow) : 0; + var mid = highestHigh - lowestLow != 0 ? (diff - lowestLow) / (highestHigh - lowestLow) : 0; midList.AddRounded(mid); - double prevAlpha = i >= 1 ? alphaList.LastOrDefault() : (double)2 / (length1 + 1); - double alpha = mid != 0 ? midList.TakeLastExt(length2).Median() : prevAlpha; + var prevAlpha = i >= 1 ? alphaList.LastOrDefault() : (double)2 / (length1 + 1); + var alpha = mid != 0 ? midList.TakeLastExt(length2).Median() : prevAlpha; alphaList.AddRounded(alpha); - double l0 = (alpha * currentValue) + ((1 - alpha) * prevL0); + var l0 = (alpha * currentValue) + ((1 - alpha) * prevL0); l0List.AddRounded(l0); - double l1 = (-1 * (1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); + var l1 = (-1 * (1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); l1List.AddRounded(l1); - double l2 = (-1 * (1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); + var l2 = (-1 * (1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); l2List.AddRounded(l2); - double l3 = (-1 * (1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); + var l3 = (-1 * (1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); l3List.AddRounded(l3); - double filter = (l0 + (2 * l1) + (2 * l2) + l3) / 6; + var filter = (l0 + (2 * l1) + (2 * l2) + l3) / 6; filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter); @@ -7719,17 +7719,17 @@ public static StockData CalculateEhlersLeadingIndicator(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevLead = leadList.LastOrDefault(); - double lead = (2 * currentValue) + ((alpha1 - 2) * prevValue) + ((1 - alpha1) * prevLead); + var prevLead = leadList.LastOrDefault(); + var lead = (2 * currentValue) + ((alpha1 - 2) * prevValue) + ((1 - alpha1) * prevLead); leadList.AddRounded(lead); - double prevLeadIndicator = leadIndicatorList.LastOrDefault(); - double leadIndicator = (alpha2 * lead) + ((1 - alpha2) * prevLeadIndicator); + var prevLeadIndicator = leadIndicatorList.LastOrDefault(); + var leadIndicator = (alpha2 * lead) + ((1 - alpha2) * prevLeadIndicator); leadIndicatorList.AddRounded(leadIndicator); var signal = GetCompareSignal(currentValue - leadIndicator, prevValue - prevLeadIndicator); @@ -7758,15 +7758,15 @@ public static StockData CalculateEhlersOptimumEllipticFilter(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevOef1 = i >= 1 ? oefList[i - 1] : 0; - double prevOef2 = i >= 2 ? oefList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevOef1 = i >= 1 ? oefList[i - 1] : 0; + var prevOef2 = i >= 2 ? oefList[i - 2] : 0; - double oef = (0.13785 * currentValue) + (0.0007 * prevValue1) + (0.13785 * prevValue2) + (1.2103 * prevOef1) - (0.4867 * prevOef2); + var oef = (0.13785 * currentValue) + (0.0007 * prevValue1) + (0.13785 * prevValue2) + (1.2103 * prevOef1) - (0.4867 * prevOef2); oefList.AddRounded(oef); var signal = GetCompareSignal(currentValue - oef, prevValue1 - prevOef1); @@ -7795,16 +7795,16 @@ public static StockData CalculateEhlersModifiedOptimumEllipticFilter(this StockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : currentValue; - double prevValue2 = i >= 2 ? inputList[i - 2] : prevValue1; - double prevValue3 = i >= 3 ? inputList[i - 3] : prevValue2; - double prevMoef1 = i >= 1 ? moefList[i - 1] : currentValue; - double prevMoef2 = i >= 2 ? moefList[i - 2] : prevMoef1; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : currentValue; + var prevValue2 = i >= 2 ? inputList[i - 2] : prevValue1; + var prevValue3 = i >= 3 ? inputList[i - 3] : prevValue2; + var prevMoef1 = i >= 1 ? moefList[i - 1] : currentValue; + var prevMoef2 = i >= 2 ? moefList[i - 2] : prevMoef1; - double moef = (0.13785 * ((2 * currentValue) - prevValue1)) + (0.0007 * ((2 * prevValue1) - prevValue2)) + + var moef = (0.13785 * ((2 * currentValue) - prevValue1)) + (0.0007 * ((2 * prevValue1) - prevValue2)) + (0.13785 * ((2 * prevValue2) - prevValue3)) + (1.2103 * prevMoef1) - (0.4867 * prevMoef2); moefList.AddRounded(moef); @@ -7836,24 +7836,24 @@ public static StockData CalculateEhlersFilter(this StockData stockData, int leng List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double num = 0, sumC = 0; - for (int j = 0; j <= length1 - 1; j++) + for (var j = 0; j <= length1 - 1; j++) { - double currentPrice = i >= j ? inputList[i - j] : 0; - double prevPrice = i >= j + length2 ? inputList[i - (j + length2)] : 0; - double priceDiff = Math.Abs(currentPrice - prevPrice); + var currentPrice = i >= j ? inputList[i - j] : 0; + var prevPrice = i >= j + length2 ? inputList[i - (j + length2)] : 0; + var priceDiff = Math.Abs(currentPrice - prevPrice); num += priceDiff * currentPrice; sumC += priceDiff; } - double prevEhlersFilter = filterList.LastOrDefault(); - double ehlersFilter = sumC != 0 ? num / sumC : 0; + var prevEhlersFilter = filterList.LastOrDefault(); + var ehlersFilter = sumC != 0 ? num / sumC : 0; filterList.AddRounded(ehlersFilter); var signal = GetCompareSignal(currentValue - ehlersFilter, prevValue - prevEhlersFilter); @@ -7883,20 +7883,20 @@ public static StockData CalculateEhlersDistanceCoefficientFilter(this StockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double srcSum = 0, coefSum = 0; - for (int count = 0; count <= length - 1; count++) + for (var count = 0; count <= length - 1; count++) { - double prevCount = i >= count ? inputList[i - count] : 0; + var prevCount = i >= count ? inputList[i - count] : 0; double distance = 0; - for (int lookBack = 1; lookBack <= length - 1; lookBack++) + for (var lookBack = 1; lookBack <= length - 1; lookBack++) { - double prevCountLookBack = i >= count + lookBack ? inputList[i - (count + lookBack)] : 0; + var prevCountLookBack = i >= count + lookBack ? inputList[i - (count + lookBack)] : 0; distance += Pow(prevCount - prevCountLookBack, 2); } @@ -7904,8 +7904,8 @@ public static StockData CalculateEhlersDistanceCoefficientFilter(this StockData coefSum += distance; } - double prevFilter = filterList.LastOrDefault(); - double filter = coefSum != 0 ? srcSum / coefSum : 0; + var prevFilter = filterList.LastOrDefault(); + var filter = coefSum != 0 ? srcSum / coefSum : 0; filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter); @@ -7942,21 +7942,21 @@ public static StockData CalculateEhlersFiniteImpulseResponseFilter(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double coefSum = coef1 + coef2 + coef3 + coef4 + coef5 + coef6 + coef7; + var coefSum = coef1 + coef2 + coef3 + coef4 + coef5 + coef6 + coef7; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; - double prevValue4 = i >= 4 ? inputList[i - 4] : 0; - double prevValue5 = i >= 5 ? inputList[i - 5] : 0; - double prevValue6 = i >= 6 ? inputList[i - 6] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var prevValue4 = i >= 4 ? inputList[i - 4] : 0; + var prevValue5 = i >= 5 ? inputList[i - 5] : 0; + var prevValue6 = i >= 6 ? inputList[i - 6] : 0; - double prevFilter = filterList.LastOrDefault(); - double filter = ((coef1 * currentValue) + (coef2 * prevValue1) + (coef3 * prevValue2) + (coef4 * prevValue3) + - (coef5 * prevValue4) + (coef6 * prevValue5) + (coef7 * prevValue6)) / coefSum; + var prevFilter = filterList.LastOrDefault(); + var filter = ((coef1 * currentValue) + (coef2 * prevValue1) + (coef3 * prevValue2) + (coef4 * prevValue3) + + (coef5 * prevValue4) + (coef6 * prevValue5) + (coef7 * prevValue6)) / coefSum; filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue1 - prevFilter); @@ -7986,16 +7986,16 @@ public static StockData CalculateEhlersInfiniteImpulseResponseFilter(this StockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)2 / (length + 1); - int lag = MinOrMax((int)Math.Ceiling((1 / alpha) - 1)); + var alpha = (double)2 / (length + 1); + var lag = MinOrMax((int)Math.Ceiling((1 / alpha) - 1)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= lag ? inputList[i - lag] : 0; - double prevFilter1 = i >= 1 ? filterList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= lag ? inputList[i - lag] : 0; + var prevFilter1 = i >= 1 ? filterList[i - 1] : 0; - double filter = (alpha * (currentValue + MinPastValues(i, lag, currentValue - prevValue))) + ((1 - alpha) * prevFilter1); + var filter = (alpha * (currentValue + MinPastValues(i, lag, currentValue - prevValue))) + ((1 - alpha) * prevFilter1); filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter1); @@ -8031,36 +8031,36 @@ public static StockData CalculateEhlersDeviationScaledMovingAverage(this StockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 2 ? inputList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 2 ? inputList[i - 2] : 0; - double prevZeros = zerosList.LastOrDefault(); - double zeros = MinPastValues(i, 2, currentValue - prevValue); + var prevZeros = zerosList.LastOrDefault(); + var zeros = MinPastValues(i, 2, currentValue - prevValue); zerosList.AddRounded(zeros); - double avgZeros = (zeros + prevZeros) / 2; + var avgZeros = (zeros + prevZeros) / 2; avgZerosList.AddRounded(avgZeros); } var ssf2PoleList = GetMovingAverageList(stockData, maType, fastLength, avgZerosList); stockData.CustomValuesList = ssf2PoleList; var ssf2PoleStdDevList = CalculateStandardDeviationVolatility(stockData, length: slowLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSsf2Pole = ssf2PoleList[i]; - double currentSsf2PoleStdDev = ssf2PoleStdDevList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentSsf2Pole = ssf2PoleList[i]; + var currentSsf2PoleStdDev = ssf2PoleStdDevList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevScaledFilter2Pole = scaledFilter2PoleList.LastOrDefault(); - double scaledFilter2Pole = currentSsf2PoleStdDev != 0 ? currentSsf2Pole / currentSsf2PoleStdDev : prevScaledFilter2Pole; + var prevScaledFilter2Pole = scaledFilter2PoleList.LastOrDefault(); + var scaledFilter2Pole = currentSsf2PoleStdDev != 0 ? currentSsf2Pole / currentSsf2PoleStdDev : prevScaledFilter2Pole; scaledFilter2PoleList.AddRounded(scaledFilter2Pole); - double alpha2Pole = MinOrMax(5 * Math.Abs(scaledFilter2Pole) / slowLength, 0.99, 0.01); - double prevEdsma2pole = edsma2PoleList.LastOrDefault(); - double edsma2Pole = (alpha2Pole * currentValue) + ((1 - alpha2Pole) * prevEdsma2pole); + var alpha2Pole = MinOrMax(5 * Math.Abs(scaledFilter2Pole) / slowLength, 0.99, 0.01); + var prevEdsma2pole = edsma2PoleList.LastOrDefault(); + var edsma2Pole = (alpha2Pole * currentValue) + ((1 - alpha2Pole) * prevEdsma2pole); edsma2PoleList.AddRounded(edsma2Pole); var signal = GetCompareSignal(currentValue - edsma2Pole, prevValue - prevEdsma2pole); @@ -8090,22 +8090,22 @@ public static StockData CalculateEhlersHannMovingAverage(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevFilt = i >= 1 ? filtList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevFilt = i >= 1 ? filtList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double filtSum = 0, coefSum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevV = i >= j - 1 ? inputList[i - (j - 1)] : 0; - double cos = 1 - Math.Cos(2 * Math.PI * ((double)j / (length + 1))); + var prevV = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var cos = 1 - Math.Cos(2 * Math.PI * ((double)j / (length + 1))); filtSum += cos * prevV; coefSum += cos; } - double filt = coefSum != 0 ? filtSum / coefSum : 0; + var filt = coefSum != 0 ? filtSum / coefSum : 0; filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); @@ -8140,39 +8140,39 @@ public static StockData CalculateEhlersDeviationScaledSuperSmoother(this StockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int hannLength = (int)Math.Ceiling(length1 / 1.4m); + var hannLength = (int)Math.Ceiling(length1 / 1.4m); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double priorValue = i >= length1 ? inputList[i - length1] : 0; + var currentValue = inputList[i]; + var priorValue = i >= length1 ? inputList[i - length1] : 0; - double mom = currentValue - priorValue; + var mom = currentValue - priorValue; momList.AddRounded(mom); } var filtList = GetMovingAverageList(stockData, maType, hannLength, momList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double filt = filtList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevDsss1 = i >= 1 ? dsssList[i - 1] : 0; - double prevDsss2 = i >= 2 ? dsssList[i - 2] : 0; + var filt = filtList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevDsss1 = i >= 1 ? dsssList[i - 1] : 0; + var prevDsss2 = i >= 2 ? dsssList[i - 2] : 0; - double filtPow = Pow(filt, 2); + var filtPow = Pow(filt, 2); filtPowList.AddRounded(filtPow); - double filtPowMa = filtPowList.TakeLastExt(length2).Average(); - double rms = filtPowMa > 0 ? Sqrt(filtPowMa) : 0; - double scaledFilt = rms != 0 ? filt / rms : 0; - double a1 = Exp(-1.414 * Math.PI * Math.Abs(scaledFilt) / length1); - double b1 = 2 * a1 * Math.Cos(1.414 * Math.PI * Math.Abs(scaledFilt) / length1); - double c2 = b1; - double c3 = -a1 * a1; - double c1 = 1 - c2 - c3; + var filtPowMa = filtPowList.TakeLastExt(length2).Average(); + var rms = filtPowMa > 0 ? Sqrt(filtPowMa) : 0; + var scaledFilt = rms != 0 ? filt / rms : 0; + var a1 = Exp(-1.414 * Math.PI * Math.Abs(scaledFilt) / length1); + var b1 = 2 * a1 * Math.Cos(1.414 * Math.PI * Math.Abs(scaledFilt) / length1); + var c2 = b1; + var c3 = -a1 * a1; + var c1 = 1 - c2 - c3; - double dsss = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevDsss1) + (c3 * prevDsss2); + var dsss = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevDsss1) + (c3 * prevDsss2); dsssList.AddRounded(dsss); var signal = GetCompareSignal(currentValue - dsss, prevValue - prevDsss1); @@ -8204,24 +8204,24 @@ public static StockData CalculateEhlersZeroLagExponentialMovingAverage(this Stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int lag = MinOrMax((int)Math.Floor((double)(length - 1) / 2)); + var lag = MinOrMax((int)Math.Floor((double)(length - 1) / 2)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= lag ? inputList[i - lag] : 0; + var currentValue = inputList[i]; + var prevValue = i >= lag ? inputList[i - lag] : 0; - double d = currentValue + MinPastValues(i, lag, currentValue - prevValue); + var d = currentValue + MinPastValues(i, lag, currentValue - prevValue); dList.AddRounded(d); } var zemaList = GetMovingAverageList(stockData, maType, length, dList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double zema = zemaList[i]; - double prevZema = i >= 1 ? zemaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var zema = zemaList[i]; + var prevZema = i >= 1 ? zemaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - zema, prevValue - prevZema); signalsList.Add(signal); @@ -8258,28 +8258,28 @@ public static StockData CalculateEhlersVariableIndexDynamicAverage(this StockDat var shortAvgList = GetMovingAverageList(stockData, maType, fastLength, inputList); var longAvgList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double shortAvg = shortAvgList[i]; - double longAvg = longAvgList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var shortAvg = shortAvgList[i]; + var longAvg = longAvgList[i]; - double shortPow = Pow(currentValue - shortAvg, 2); + var shortPow = Pow(currentValue - shortAvg, 2); shortPowList.AddRounded(shortPow); - double shortMa = shortPowList.TakeLastExt(fastLength).Average(); - double shortRms = shortMa > 0 ? Sqrt(shortMa) : 0; + var shortMa = shortPowList.TakeLastExt(fastLength).Average(); + var shortRms = shortMa > 0 ? Sqrt(shortMa) : 0; - double longPow = Pow(currentValue - longAvg, 2); + var longPow = Pow(currentValue - longAvg, 2); longPowList.AddRounded(longPow); - double longMa = longPowList.TakeLastExt(slowLength).Average(); - double longRms = longMa > 0 ? Sqrt(longMa) : 0; - double kk = longRms != 0 ? MinOrMax(0.2 * shortRms / longRms, 0.99, 0.01) : 0; + var longMa = longPowList.TakeLastExt(slowLength).Average(); + var longRms = longMa > 0 ? Sqrt(longMa) : 0; + var kk = longRms != 0 ? MinOrMax(0.2 * shortRms / longRms, 0.99, 0.01) : 0; - double prevVidya = vidyaList.LastOrDefault(); - double vidya = (kk * currentValue) + ((1 - kk) * prevVidya); + var prevVidya = vidyaList.LastOrDefault(); + var vidya = (kk * currentValue) + ((1 - kk) * prevVidya); vidyaList.AddRounded(vidya); var signal = GetCompareSignal(currentValue - vidya, prevValue - prevVidya); @@ -8309,25 +8309,25 @@ public static StockData CalculateEhlersKaufmanAdaptiveMovingAverage(this StockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorValue = i >= length - 1 ? inputList[i - (length - 1)] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorValue = i >= length - 1 ? inputList[i - (length - 1)] : 0; double deltaSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double cValue = i >= j ? inputList[i - j] : 0; - double pValue = i >= j + 1 ? inputList[i - (j + 1)] : 0; + var cValue = i >= j ? inputList[i - j] : 0; + var pValue = i >= j + 1 ? inputList[i - (j + 1)] : 0; deltaSum += Math.Abs(cValue - pValue); } - double ef = deltaSum != 0 ? Math.Min(Math.Abs(currentValue - priorValue) / deltaSum, 1) : 0; - double s = Pow((0.6667 * ef) + 0.0645, 2); + var ef = deltaSum != 0 ? Math.Min(Math.Abs(currentValue - priorValue) / deltaSum, 1) : 0; + var s = Pow((0.6667 * ef) + 0.0645, 2); - double prevKama = kamaList.LastOrDefault(); - double kama = (s * currentValue) + ((1 - s) * prevKama); + var prevKama = kamaList.LastOrDefault(); + var kama = (s * currentValue) + ((1 - s) * prevKama); kamaList.AddRounded(kama); var signal = GetCompareSignal(currentValue - kama, prevValue - prevKama); @@ -8358,20 +8358,20 @@ public static StockData CalculateEhlersAllPassPhaseShifter(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a2 = qq != 0 && length != 0 ? -2 * Math.Cos(2 * Math.PI / length) / qq : 0; - double a3 = qq != 0 ? Pow(1 / qq, 2) : 0; - double b2 = length != 0 ? -2 * qq * Math.Cos(2 * Math.PI / length) : 0; - double b3 = Pow(qq, 2); + var a2 = qq != 0 && length != 0 ? -2 * Math.Cos(2 * Math.PI / length) / qq : 0; + var a3 = qq != 0 ? Pow(1 / qq, 2) : 0; + var b2 = length != 0 ? -2 * qq * Math.Cos(2 * Math.PI / length) : 0; + var b3 = Pow(qq, 2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevPhaser1 = i >= 1 ? phaserList[i - 1] : 0; - double prevPhaser2 = i >= 2 ? phaserList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevPhaser1 = i >= 1 ? phaserList[i - 1] : 0; + var prevPhaser2 = i >= 2 ? phaserList[i - 2] : 0; - double phaser = (b3 * (currentValue + (a2 * prevValue1) + (a3 * prevValue2))) - (b2 * prevPhaser1) - (b3 * prevPhaser2); + var phaser = (b3 * (currentValue + (a2 * prevValue1) + (a3 * prevValue2))) - (b2 * prevPhaser1) - (b3 * prevPhaser2); phaserList.AddRounded(phaser); var signal = GetCompareSignal(currentValue - phaser, prevValue1 - prevPhaser1); @@ -8417,100 +8417,100 @@ public static StockData CalculateEhlersChebyshevLowPassFilter(this StockData sto List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevV1Neg2_1 = i >= 1 ? v1Neg2List[i - 1] : 0; - double prevV1Neg2_2 = i >= 2 ? v1Neg2List[i - 2] : 0; - double prevWaveNeg2_1 = i >= 1 ? waveNeg2List[i - 1] : 0; - double prevWaveNeg2_2 = i >= 2 ? waveNeg2List[i - 2] : 0; - double prevV1Neg1_1 = i >= 1 ? v1Neg1List[i - 1] : 0; - double prevV1Neg1_2 = i >= 2 ? v1Neg1List[i - 2] : 0; - double prevWaveNeg1_1 = i >= 1 ? waveNeg1List[i - 1] : 0; - double prevWaveNeg1_2 = i >= 2 ? waveNeg1List[i - 2] : 0; - double prevV10_1 = i >= 1 ? v10List[i - 1] : 0; - double prevV10_2 = i >= 2 ? v10List[i - 2] : 0; - double prevWave0_1 = i >= 1 ? wave0List[i - 1] : 0; - double prevWave0_2 = i >= 2 ? wave0List[i - 2] : 0; - double prevV11_1 = i >= 1 ? v11List[i - 1] : 0; - double prevV11_2 = i >= 2 ? v11List[i - 2] : 0; - double prevWave1_1 = i >= 1 ? wave1List[i - 1] : 0; - double prevWave1_2 = i >= 2 ? wave1List[i - 2] : 0; - double prevV12_1 = i >= 1 ? v12List[i - 1] : 0; - double prevV12_2 = i >= 2 ? v12List[i - 2] : 0; - double prevWave2_1 = i >= 1 ? wave2List[i - 1] : 0; - double prevWave2_2 = i >= 2 ? wave2List[i - 2] : 0; - double prevV13_1 = i >= 1 ? v13List[i - 1] : 0; - double prevV13_2 = i >= 2 ? v13List[i - 2] : 0; - double prevWave3_1 = i >= 1 ? wave3List[i - 1] : 0; - double prevWave3_2 = i >= 2 ? wave3List[i - 2] : 0; - double prevV14_1 = i >= 1 ? v14List[i - 1] : 0; - double prevV14_2 = i >= 2 ? v14List[i - 2] : 0; - double prevWave4_1 = i >= 1 ? wave4List[i - 1] : 0; - double prevWave4_2 = i >= 2 ? wave4List[i - 2] : 0; - double prevV15_1 = i >= 1 ? v15List[i - 1] : 0; - double prevV15_2 = i >= 2 ? v15List[i - 2] : 0; - double prevWave5_1 = i >= 1 ? wave5List[i - 1] : 0; - double prevWave5_2 = i >= 2 ? wave5List[i - 2] : 0; - double prevV16_1 = i >= 1 ? v16List[i - 1] : 0; - double prevV16_2 = i >= 2 ? v16List[i - 2] : 0; - double prevWave6_1 = i >= 1 ? wave6List[i - 1] : 0; - double prevWave6_2 = i >= 2 ? wave6List[i - 2] : 0; - - double v1Neg2 = (0.080778 * (currentValue + (1.907 * prevValue1) + prevValue2)) + (0.293 * prevV1Neg2_1) - (0.063 * prevV1Neg2_2); + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevV1Neg2_1 = i >= 1 ? v1Neg2List[i - 1] : 0; + var prevV1Neg2_2 = i >= 2 ? v1Neg2List[i - 2] : 0; + var prevWaveNeg2_1 = i >= 1 ? waveNeg2List[i - 1] : 0; + var prevWaveNeg2_2 = i >= 2 ? waveNeg2List[i - 2] : 0; + var prevV1Neg1_1 = i >= 1 ? v1Neg1List[i - 1] : 0; + var prevV1Neg1_2 = i >= 2 ? v1Neg1List[i - 2] : 0; + var prevWaveNeg1_1 = i >= 1 ? waveNeg1List[i - 1] : 0; + var prevWaveNeg1_2 = i >= 2 ? waveNeg1List[i - 2] : 0; + var prevV10_1 = i >= 1 ? v10List[i - 1] : 0; + var prevV10_2 = i >= 2 ? v10List[i - 2] : 0; + var prevWave0_1 = i >= 1 ? wave0List[i - 1] : 0; + var prevWave0_2 = i >= 2 ? wave0List[i - 2] : 0; + var prevV11_1 = i >= 1 ? v11List[i - 1] : 0; + var prevV11_2 = i >= 2 ? v11List[i - 2] : 0; + var prevWave1_1 = i >= 1 ? wave1List[i - 1] : 0; + var prevWave1_2 = i >= 2 ? wave1List[i - 2] : 0; + var prevV12_1 = i >= 1 ? v12List[i - 1] : 0; + var prevV12_2 = i >= 2 ? v12List[i - 2] : 0; + var prevWave2_1 = i >= 1 ? wave2List[i - 1] : 0; + var prevWave2_2 = i >= 2 ? wave2List[i - 2] : 0; + var prevV13_1 = i >= 1 ? v13List[i - 1] : 0; + var prevV13_2 = i >= 2 ? v13List[i - 2] : 0; + var prevWave3_1 = i >= 1 ? wave3List[i - 1] : 0; + var prevWave3_2 = i >= 2 ? wave3List[i - 2] : 0; + var prevV14_1 = i >= 1 ? v14List[i - 1] : 0; + var prevV14_2 = i >= 2 ? v14List[i - 2] : 0; + var prevWave4_1 = i >= 1 ? wave4List[i - 1] : 0; + var prevWave4_2 = i >= 2 ? wave4List[i - 2] : 0; + var prevV15_1 = i >= 1 ? v15List[i - 1] : 0; + var prevV15_2 = i >= 2 ? v15List[i - 2] : 0; + var prevWave5_1 = i >= 1 ? wave5List[i - 1] : 0; + var prevWave5_2 = i >= 2 ? wave5List[i - 2] : 0; + var prevV16_1 = i >= 1 ? v16List[i - 1] : 0; + var prevV16_2 = i >= 2 ? v16List[i - 2] : 0; + var prevWave6_1 = i >= 1 ? wave6List[i - 1] : 0; + var prevWave6_2 = i >= 2 ? wave6List[i - 2] : 0; + + var v1Neg2 = (0.080778 * (currentValue + (1.907 * prevValue1) + prevValue2)) + (0.293 * prevV1Neg2_1) - (0.063 * prevV1Neg2_2); v1Neg2List.AddRounded(v1Neg2); - double waveNeg2 = v1Neg2 + (0.513 * prevV1Neg2_1) + prevV1Neg2_2 + (0.451 * prevWaveNeg2_1) - (0.481 * prevWaveNeg2_2); + var waveNeg2 = v1Neg2 + (0.513 * prevV1Neg2_1) + prevV1Neg2_2 + (0.451 * prevWaveNeg2_1) - (0.481 * prevWaveNeg2_2); waveNeg2List.AddRounded(waveNeg2); - double v1Neg1 = (0.021394 * (currentValue + (1.777 * prevValue1) + prevValue2)) + (0.731 * prevV1Neg1_1) - (0.166 * prevV1Neg1_2); + var v1Neg1 = (0.021394 * (currentValue + (1.777 * prevValue1) + prevValue2)) + (0.731 * prevV1Neg1_1) - (0.166 * prevV1Neg1_2); v1Neg1List.AddRounded(v1Neg1); - double waveNeg1 = v1Neg1 + (0.977 * prevV1Neg1_1) + prevV1Neg1_2 + (1.008 * prevWaveNeg1_1) - (0.561 * prevWaveNeg1_2); + var waveNeg1 = v1Neg1 + (0.977 * prevV1Neg1_1) + prevV1Neg1_2 + (1.008 * prevWaveNeg1_1) - (0.561 * prevWaveNeg1_2); waveNeg1List.AddRounded(waveNeg1); - double v10 = (0.0095822 * (currentValue + (1.572 * prevValue1) + prevValue2)) + (1.026 * prevV10_1) - (0.282 * prevV10_2); + var v10 = (0.0095822 * (currentValue + (1.572 * prevValue1) + prevValue2)) + (1.026 * prevV10_1) - (0.282 * prevV10_2); v10List.AddRounded(v10); - double wave0 = v10 + (0.356 * prevV10_1) + prevV10_2 + (1.329 * prevWave0_1) - (0.644 * prevWave0_2); + var wave0 = v10 + (0.356 * prevV10_1) + prevV10_2 + (1.329 * prevWave0_1) - (0.644 * prevWave0_2); wave0List.AddRounded(wave0); - double v11 = (0.00461 * (currentValue + (1.192 * prevValue1) + prevValue2)) + (1.281 * prevV11_1) - (0.426 * prevV11_2); + var v11 = (0.00461 * (currentValue + (1.192 * prevValue1) + prevValue2)) + (1.281 * prevV11_1) - (0.426 * prevV11_2); v11List.AddRounded(v11); - double wave1 = v11 - (0.384 * prevV11_1) + prevV11_2 + (1.565 * prevWave1_1) - (0.729 * prevWave1_2); + var wave1 = v11 - (0.384 * prevV11_1) + prevV11_2 + (1.565 * prevWave1_1) - (0.729 * prevWave1_2); wave1List.AddRounded(wave1); - double v12 = (0.0026947 * (currentValue + (0.681 * prevValue1) + prevValue2)) + (1.46 * prevV12_1) - (0.543 * prevV12_2); + var v12 = (0.0026947 * (currentValue + (0.681 * prevValue1) + prevValue2)) + (1.46 * prevV12_1) - (0.543 * prevV12_2); v12List.AddRounded(v12); - double wave2 = v12 - (0.966 * prevV12_1) + prevV12_2 + (1.703 * prevWave2_1) - (0.793 * prevWave2_2); + var wave2 = v12 - (0.966 * prevV12_1) + prevV12_2 + (1.703 * prevWave2_1) - (0.793 * prevWave2_2); wave2List.AddRounded(wave2); - double v13 = (0.0017362 * (currentValue + (0.012 * prevValue1) + prevValue2)) + (1.606 * prevV13_1) - (0.65 * prevV13_2); + var v13 = (0.0017362 * (currentValue + (0.012 * prevValue1) + prevValue2)) + (1.606 * prevV13_1) - (0.65 * prevV13_2); v13List.AddRounded(v13); - double wave3 = v13 - (1.408 * prevV13_1) + prevV13_2 + (1.801 * prevWave3_1) - (0.848 * prevWave3_2); + var wave3 = v13 - (1.408 * prevV13_1) + prevV13_2 + (1.801 * prevWave3_1) - (0.848 * prevWave3_2); wave3List.AddRounded(wave3); - double v14 = (0.0013738 * (currentValue - (0.669 * prevValue1) + prevValue2)) + (1.716 * prevV14_1) - (0.74 * prevV14_2); + var v14 = (0.0013738 * (currentValue - (0.669 * prevValue1) + prevValue2)) + (1.716 * prevV14_1) - (0.74 * prevV14_2); v14List.AddRounded(v14); - double wave4 = v14 - (1.685 * prevV14_1) + prevV14_2 + (1.866 * prevWave4_1) - (0.89 * prevWave4_2); + var wave4 = v14 - (1.685 * prevV14_1) + prevV14_2 + (1.866 * prevWave4_1) - (0.89 * prevWave4_2); wave4List.AddRounded(wave4); - double v15 = (0.0010794 * (currentValue - (1.226 * prevValue1) + prevValue2)) + (1.8 * prevV15_1) - (0.811 * prevV15_2); + var v15 = (0.0010794 * (currentValue - (1.226 * prevValue1) + prevValue2)) + (1.8 * prevV15_1) - (0.811 * prevV15_2); v15List.AddRounded(v15); - double wave5 = v15 - (1.842 * prevV15_1) + prevV15_2 + (1.91 * prevWave5_1) - (0.922 * prevWave5_2); + var wave5 = v15 - (1.842 * prevV15_1) + prevV15_2 + (1.91 * prevWave5_1) - (0.922 * prevWave5_2); wave5List.AddRounded(wave5); - double v16 = (0.001705 * (currentValue - (1.659 * prevValue1) + prevValue2)) + (1.873 * prevV16_1) - (0.878 * prevV16_2); + var v16 = (0.001705 * (currentValue - (1.659 * prevValue1) + prevValue2)) + (1.873 * prevV16_1) - (0.878 * prevV16_2); v16List.AddRounded(v16); - double wave6 = v16 - (1.957 * prevV16_1) + prevV16_2 + (1.946 * prevWave6_1) - (0.951 * prevWave6_2); + var wave6 = v16 - (1.957 * prevV16_1) + prevV16_2 + (1.946 * prevWave6_1) - (0.951 * prevWave6_2); wave6List.AddRounded(wave6); var signal = GetCompareSignal(currentValue - waveNeg2, prevValue1 - prevWaveNeg2_1); @@ -8549,20 +8549,20 @@ public static StockData CalculateEhlersBetterExponentialMovingAverage(this Stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double val = length != 0 ? Math.Cos(2 * Math.PI / length) + Math.Sin(2 * Math.PI / length) : 0; - double alpha = val != 0 ? MinOrMax((val - 1) / val, 0.99, 0.01) : 0.01; + var val = length != 0 ? Math.Cos(2 * Math.PI / length) + Math.Sin(2 * Math.PI / length) : 0; + var alpha = val != 0 ? MinOrMax((val - 1) / val, 0.99, 0.01) : 0.01; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevEma1 = i >= 1 ? emaList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevEma1 = i >= 1 ? emaList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double ema = (alpha * currentValue) + ((1 - alpha) * prevEma1); + var ema = (alpha * currentValue) + ((1 - alpha) * prevEma1); emaList.AddRounded(ema); - double prevBEma = bEmaList.LastOrDefault(); - double bEma = (alpha * ((currentValue + prevValue) / 2)) + ((1 - alpha) * prevEma1); + var prevBEma = bEmaList.LastOrDefault(); + var bEma = (alpha * ((currentValue + prevValue) / 2)) + ((1 - alpha) * prevEma1); bEmaList.AddRounded(bEma); var signal = GetCompareSignal(currentValue - bEma, prevValue - prevBEma); @@ -8593,22 +8593,22 @@ public static StockData CalculateEhlersHammingMovingAverage(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevFilt = i >= 1 ? filtList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevFilt = i >= 1 ? filtList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double filtSum = 0, coefSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double prevV = i >= j ? inputList[i - j] : 0; - double sine = Math.Sin(pedestal + ((Math.PI - (2 * pedestal)) * ((double)j / (length - 1)))); + var prevV = i >= j ? inputList[i - j] : 0; + var sine = Math.Sin(pedestal + ((Math.PI - (2 * pedestal)) * ((double)j / (length - 1)))); filtSum += sine * prevV; coefSum += sine; } - double filt = coefSum != 0 ? filtSum / coefSum : 0; + var filt = coefSum != 0 ? filtSum / coefSum : 0; filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); @@ -8638,24 +8638,24 @@ public static StockData CalculateEhlersTriangleMovingAverage(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double l2 = (double)length / 2; + var l2 = (double)length / 2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevFilt = i >= 1 ? filtList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevFilt = i >= 1 ? filtList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double filtSum = 0, coefSum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevV = i >= j - 1 ? inputList[i - (j - 1)] : 0; - double c = j < l2 ? j : j > l2 ? length + 1 - j : l2; + var prevV = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var c = j < l2 ? j : j > l2 ? length + 1 - j : l2; filtSum += c * prevV; coefSum += c; } - double filt = coefSum != 0 ? filtSum / coefSum : 0; + var filt = coefSum != 0 ? filtSum / coefSum : 0; filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); diff --git a/src/Calculations/Oscillator.cs b/src/Calculations/Oscillator.cs index 7adf455..4cdd8ca 100644 --- a/src/Calculations/Oscillator.cs +++ b/src/Calculations/Oscillator.cs @@ -31,25 +31,25 @@ public static StockData CalculateCommodityChannelIndex(this StockData stockData, var (inputList, _, _, _, _, _) = GetInputValuesList(inputName, stockData); var tpSmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double tpSma = tpSmaList[i]; + var currentValue = inputList[i]; + var tpSma = tpSmaList[i]; - double tpDevDiff = Math.Abs(currentValue - tpSma); + var tpDevDiff = Math.Abs(currentValue - tpSma); tpDevDiffList.AddRounded(tpDevDiff); } var tpMeanDevList = GetMovingAverageList(stockData, maType, length, tpDevDiffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevCci1 = i >= 1 ? cciList[i - 1] : 0; - double prevCci2 = i >= 2 ? cciList[i - 2] : 0; - double tpMeanDev = tpMeanDevList[i]; - double currentValue = inputList[i]; - double tpSma = tpSmaList[i]; + var prevCci1 = i >= 1 ? cciList[i - 1] : 0; + var prevCci2 = i >= 2 ? cciList[i - 2] : 0; + var tpMeanDev = tpMeanDevList[i]; + var currentValue = inputList[i]; + var tpSma = tpSmaList[i]; - double cci = tpMeanDev != 0 ? (currentValue - tpSma) / (constant * tpMeanDev) : 0; + var cci = tpMeanDev != 0 ? (currentValue - tpSma) / (constant * tpMeanDev) : 0; cciList.AddRounded(cci); var signal = GetRsiSignal(cci - prevCci1, prevCci1 - prevCci2, cci, prevCci1, 100, -100); @@ -86,13 +86,13 @@ public static StockData CalculateAwesomeOscillator(this StockData stockData, Mov var fastSmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowSmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastSma = fastSmaList[i]; - double slowSma = slowSmaList[i]; + var fastSma = fastSmaList[i]; + var slowSma = slowSmaList[i]; - double prevAo = aoList.LastOrDefault(); - double ao = fastSma - slowSma; + var prevAo = aoList.LastOrDefault(); + var ao = fastSma - slowSma; aoList.AddRounded(ao); var signal = GetCompareSignal(ao, prevAo); @@ -129,13 +129,13 @@ public static StockData CalculateAcceleratorOscillator(this StockData stockData, var awesomeOscList = CalculateAwesomeOscillator(stockData, maType, inputName, fastLength, slowLength).CustomValuesList; var awesomeOscMaList = GetMovingAverageList(stockData, maType, smoothLength, awesomeOscList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ao = awesomeOscList[i]; - double aoSma = awesomeOscMaList[i]; + var ao = awesomeOscList[i]; + var aoSma = awesomeOscMaList[i]; - double prevAc = acList.LastOrDefault(); - double ac = ao - aoSma; + var prevAc = acList.LastOrDefault(); + var ac = ao - aoSma; acList.AddRounded(ac); var signal = GetCompareSignal(ac, prevAc); @@ -167,19 +167,19 @@ public static StockData CalculateUlcerIndex(this StockData stockData, int length var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, _) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double maxValue = highestList[i]; - double prevUlcerIndex1 = i >= 1 ? ulcerIndexList[i - 1] : 0; - double prevUlcerIndex2 = i >= 2 ? ulcerIndexList[i - 2] : 0; + var currentValue = inputList[i]; + var maxValue = highestList[i]; + var prevUlcerIndex1 = i >= 1 ? ulcerIndexList[i - 1] : 0; + var prevUlcerIndex2 = i >= 2 ? ulcerIndexList[i - 2] : 0; - double pctDrawdownSquared = maxValue != 0 ? Pow((currentValue - maxValue) / maxValue * 100, 2) : 0; + var pctDrawdownSquared = maxValue != 0 ? Pow((currentValue - maxValue) / maxValue * 100, 2) : 0; pctDrawdownSquaredList.AddRounded(pctDrawdownSquared); - double squaredAvg = pctDrawdownSquaredList.TakeLastExt(length).Average(); + var squaredAvg = pctDrawdownSquaredList.TakeLastExt(length).Average(); - double ulcerIndex = squaredAvg >= 0 ? Sqrt(squaredAvg) : 0; + var ulcerIndex = squaredAvg >= 0 ? Sqrt(squaredAvg) : 0; ulcerIndexList.AddRounded(ulcerIndex); var signal = GetCompareSignal(ulcerIndex - prevUlcerIndex1, prevUlcerIndex1 - prevUlcerIndex2, true); @@ -210,24 +210,24 @@ public static StockData CalculateBalanceOfPower(this StockData stockData, Moving List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double balanceOfPower = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; + var balanceOfPower = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; balanceOfPowerList.AddRounded(balanceOfPower); } var bopSignalList = GetMovingAverageList(stockData, maType, length, balanceOfPowerList); - for (int i = 0; i < stockData.ClosePrices.Count; i++) + for (var i = 0; i < stockData.ClosePrices.Count; i++) { - double bop = balanceOfPowerList[i]; - double bopMa = bopSignalList[i]; - double prevBop = i >= 1 ? balanceOfPowerList[i - 1] : 0; - double prevBopMa = i >= 1 ? bopSignalList[i - 1] : 0; + var bop = balanceOfPowerList[i]; + var bopMa = bopSignalList[i]; + var prevBop = i >= 1 ? balanceOfPowerList[i - 1] : 0; + var prevBopMa = i >= 1 ? bopSignalList[i - 1] : 0; var signal = GetCompareSignal(bop - bopMa, prevBop - prevBopMa); signalsList.Add(signal); @@ -257,14 +257,14 @@ public static StockData CalculateRateOfChange(this StockData stockData, int leng List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double prevRoc1 = i >= 1 ? rocList[i - 1] : 0; - double prevRoc2 = i >= 2 ? rocList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var prevRoc1 = i >= 1 ? rocList[i - 1] : 0; + var prevRoc2 = i >= 2 ? rocList[i - 2] : 0; - double roc = prevValue != 0 ? MinPastValues(i, length, currentValue - prevValue) / prevValue * 100 : 0; + var roc = prevValue != 0 ? MinPastValues(i, length, currentValue - prevValue) / prevValue * 100 : 0; rocList.AddRounded(roc); var signal = GetCompareSignal(roc - prevRoc1, prevRoc1 - prevRoc2); @@ -300,13 +300,13 @@ public static StockData CalculateChaikinOscillator(this StockData stockData, Mov var adl3EmaList = GetMovingAverageList(stockData, maType, fastLength, adlList); var adl10EmaList = GetMovingAverageList(stockData, maType, slowLength, adlList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double adl3Ema = adl3EmaList[i]; - double adl10Ema = adl10EmaList[i]; + var adl3Ema = adl3EmaList[i]; + var adl10Ema = adl10EmaList[i]; - double prevChaikinOscillator = chaikinOscillatorList.LastOrDefault(); - double chaikinOscillator = adl3Ema - adl10Ema; + var prevChaikinOscillator = chaikinOscillatorList.LastOrDefault(); + var chaikinOscillator = adl3Ema - adl10Ema; chaikinOscillatorList.AddRounded(chaikinOscillator); var signal = GetCompareSignal(chaikinOscillator, prevChaikinOscillator); @@ -345,27 +345,27 @@ public static StockData CalculateIchimokuCloud(this StockData stockData, int ten var (kijunHighList, kijunLowList) = GetMaxAndMinValuesList(highList, lowList, kijunLength); var (senkouHighList, senkouLowList) = GetMaxAndMinValuesList(highList, lowList, senkouLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest1 = tenkanHighList[i]; - double lowest1 = tenkanLowList[i]; - double highest2 = kijunHighList[i]; - double lowest2 = kijunLowList[i]; - double highest3 = senkouHighList[i]; - double lowest3 = senkouLowList[i]; + var highest1 = tenkanHighList[i]; + var lowest1 = tenkanLowList[i]; + var highest2 = kijunHighList[i]; + var lowest2 = kijunLowList[i]; + var highest3 = senkouHighList[i]; + var lowest3 = senkouLowList[i]; - double prevTenkanSen = tenkanSenList.LastOrDefault(); - double tenkanSen = (highest1 + lowest1) / 2; + var prevTenkanSen = tenkanSenList.LastOrDefault(); + var tenkanSen = (highest1 + lowest1) / 2; tenkanSenList.AddRounded(tenkanSen); - double prevKijunSen = kijunSenList.LastOrDefault(); - double kijunSen = (highest2 + lowest2) / 2; + var prevKijunSen = kijunSenList.LastOrDefault(); + var kijunSen = (highest2 + lowest2) / 2; kijunSenList.AddRounded(kijunSen); - double senkouSpanA = (tenkanSen + kijunSen) / 2; + var senkouSpanA = (tenkanSen + kijunSen) / 2; senkouSpanAList.AddRounded(senkouSpanA); - double senkouSpanB = (highest3 + lowest3) / 2; + var senkouSpanB = (highest3 + lowest3) / 2; senkouSpanBList.AddRounded(senkouSpanB); var signal = GetCompareSignal(tenkanSen - kijunSen, prevTenkanSen - prevKijunSen); @@ -413,18 +413,18 @@ public static StockData CalculateAlligatorIndex(this StockData stockData, InputN var teethList = GetMovingAverageList(stockData, maType, teethLength, inputList); var lipsList = GetMovingAverageList(stockData, maType, lipsLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevJaw = displacedJawList.LastOrDefault(); - double displacedJaw = i >= jawOffset ? jawList[i - jawOffset] : 0; + var prevJaw = displacedJawList.LastOrDefault(); + var displacedJaw = i >= jawOffset ? jawList[i - jawOffset] : 0; displacedJawList.AddRounded(displacedJaw); - double prevTeeth = displacedTeethList.LastOrDefault(); - double displacedTeeth = i >= teethOffset ? teethList[i - teethOffset] : 0; + var prevTeeth = displacedTeethList.LastOrDefault(); + var displacedTeeth = i >= teethOffset ? teethList[i - teethOffset] : 0; displacedTeethList.AddRounded(displacedTeeth); - double prevLips = displacedLipsList.LastOrDefault(); - double displacedLips = i >= lipsOffset ? lipsList[i - lipsOffset] : 0; + var prevLips = displacedLipsList.LastOrDefault(); + var displacedLips = i >= lipsOffset ? lipsList[i - lipsOffset] : 0; displacedLipsList.AddRounded(displacedLips); var signal = GetBullishBearishSignal(displacedLips - Math.Max(displacedJaw, displacedTeeth), prevLips - Math.Max(prevJaw, prevTeeth), @@ -471,18 +471,18 @@ public static StockData CalculateGatorOscillator(this StockData stockData, Input var teethList = alligatorList["Teeth"]; var lipsList = alligatorList["Lips"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double jaw = jawList[i]; - double teeth = teethList[i]; - double lips = lipsList[i]; + var jaw = jawList[i]; + var teeth = teethList[i]; + var lips = lipsList[i]; - double prevTop = topList.LastOrDefault(); - double top = Math.Abs(jaw - teeth); + var prevTop = topList.LastOrDefault(); + var top = Math.Abs(jaw - teeth); topList.AddRounded(top); - double prevBottom = bottomList.LastOrDefault(); - double bottom = -Math.Abs(teeth - lips); + var prevBottom = bottomList.LastOrDefault(); + var bottom = -Math.Abs(teeth - lips); bottomList.AddRounded(bottom); var signal = GetCompareSignal(top - bottom, prevTop - prevBottom); @@ -517,34 +517,34 @@ public static StockData CalculateUltimateOscillator(this StockData stockData, in List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double minValue = Math.Min(currentLow, prevClose); - double maxValue = Math.Max(currentHigh, prevClose); - double prevUo1 = i >= 1 ? uoList[i - 1] : 0; - double prevUo2 = i >= 2 ? uoList[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var minValue = Math.Min(currentLow, prevClose); + var maxValue = Math.Max(currentHigh, prevClose); + var prevUo1 = i >= 1 ? uoList[i - 1] : 0; + var prevUo2 = i >= 2 ? uoList[i - 2] : 0; - double buyingPressure = currentClose - minValue; + var buyingPressure = currentClose - minValue; bpList.AddRounded(buyingPressure); - double trueRange = maxValue - minValue; + var trueRange = maxValue - minValue; trList.AddRounded(trueRange); - double bp7Sum = bpList.TakeLastExt(length1).Sum(); - double bp14Sum = bpList.TakeLastExt(length2).Sum(); - double bp28Sum = bpList.TakeLastExt(length3).Sum(); - double tr7Sum = trList.TakeLastExt(length1).Sum(); - double tr14Sum = trList.TakeLastExt(length2).Sum(); - double tr28Sum = trList.TakeLastExt(length3).Sum(); - double avg7 = tr7Sum != 0 ? bp7Sum / tr7Sum : 0; - double avg14 = tr14Sum != 0 ? bp14Sum / tr14Sum : 0; - double avg28 = tr28Sum != 0 ? bp28Sum / tr28Sum : 0; - - double ultimateOscillator = MinOrMax(100 * (((4 * avg7) + (2 * avg14) + avg28) / (4 + 2 + 1)), 100, 0); + var bp7Sum = bpList.TakeLastExt(length1).Sum(); + var bp14Sum = bpList.TakeLastExt(length2).Sum(); + var bp28Sum = bpList.TakeLastExt(length3).Sum(); + var tr7Sum = trList.TakeLastExt(length1).Sum(); + var tr14Sum = trList.TakeLastExt(length2).Sum(); + var tr28Sum = trList.TakeLastExt(length3).Sum(); + var avg7 = tr7Sum != 0 ? bp7Sum / tr7Sum : 0; + var avg14 = tr14Sum != 0 ? bp14Sum / tr14Sum : 0; + var avg28 = tr28Sum != 0 ? bp28Sum / tr28Sum : 0; + + var ultimateOscillator = MinOrMax(100 * (((4 * avg7) + (2 * avg14) + avg28) / (4 + 2 + 1)), 100, 0); uoList.AddRounded(ultimateOscillator); var signal = GetRsiSignal(ultimateOscillator - prevUo1, prevUo1 - prevUo2, ultimateOscillator, prevUo1, 70, 30); @@ -578,33 +578,33 @@ public static StockData CalculateVortexIndicator(this StockData stockData, int l List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; - double vmPlus = Math.Abs(currentHigh - prevLow); + var vmPlus = Math.Abs(currentHigh - prevLow); vmPlusList.AddRounded(vmPlus); - double vmMinus = Math.Abs(currentLow - prevHigh); + var vmMinus = Math.Abs(currentLow - prevHigh); vmMinusList.AddRounded(vmMinus); - double trueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); + var trueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); trueRangeList.AddRounded(trueRange); - double vmPlus14 = vmPlusList.TakeLastExt(length).Sum(); - double vmMinus14 = vmMinusList.TakeLastExt(length).Sum(); - double trueRange14 = trueRangeList.TakeLastExt(length).Sum(); + var vmPlus14 = vmPlusList.TakeLastExt(length).Sum(); + var vmMinus14 = vmMinusList.TakeLastExt(length).Sum(); + var trueRange14 = trueRangeList.TakeLastExt(length).Sum(); - double prevViPlus14 = viPlus14List.LastOrDefault(); - double viPlus14 = trueRange14 != 0 ? vmPlus14 / trueRange14 : 0; + var prevViPlus14 = viPlus14List.LastOrDefault(); + var viPlus14 = trueRange14 != 0 ? vmPlus14 / trueRange14 : 0; viPlus14List.AddRounded(viPlus14); - double prevViMinus14 = viMinus14List.LastOrDefault(); - double viMinus14 = trueRange14 != 0 ? vmMinus14 / trueRange14 : 0; + var prevViMinus14 = viMinus14List.LastOrDefault(); + var viMinus14 = trueRange14 != 0 ? vmMinus14 / trueRange14 : 0; viMinus14List.AddRounded(viMinus14); var signal = GetCompareSignal(viPlus14 - viMinus14, prevViPlus14 - prevViMinus14); @@ -642,22 +642,22 @@ public static StockData CalculateTrix(this StockData stockData, MovingAvgType ma var ema2List = GetMovingAverageList(stockData, maType, length, ema1List); var ema3List = GetMovingAverageList(stockData, maType, length, ema2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema3 = ema3List[i]; - double prevEma3 = i >= 1 ? ema3List[i - 1] : 0; + var ema3 = ema3List[i]; + var prevEma3 = i >= 1 ? ema3List[i - 1] : 0; - double trix = CalculatePercentChange(ema3, prevEma3); + var trix = CalculatePercentChange(ema3, prevEma3); trixList.AddRounded(trix); } var trixSignalList = GetMovingAverageList(stockData, maType, signalLength, trixList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double trix = trixList[i]; - double trixSignal = trixSignalList[i]; - double prevTrix = i >= 1 ? trixList[i - 1] : 0; - double prevTrixSignal = i >= 1 ? trixSignalList[i - 1] : 0; + var trix = trixList[i]; + var trixSignal = trixSignalList[i]; + var prevTrix = i >= 1 ? trixList[i - 1] : 0; + var prevTrixSignal = i >= 1 ? trixSignalList[i - 1] : 0; var signal = GetCompareSignal(trix - trixSignal, prevTrix - prevTrixSignal); signalsList.Add(signal); @@ -687,15 +687,15 @@ public static StockData CalculateWilliamsR(this StockData stockData, int length var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevWilliamsR1 = i >= 1 ? williamsRList[i - 1] : 0; - double prevWilliamsR2 = i >= 2 ? williamsRList[i - 2] : 0; + var currentClose = inputList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevWilliamsR1 = i >= 1 ? williamsRList[i - 1] : 0; + var prevWilliamsR2 = i >= 2 ? williamsRList[i - 2] : 0; - double williamsR = highestHigh - lowestLow != 0 ? -100 * (highestHigh - currentClose) / (highestHigh - lowestLow) : -100; + var williamsR = highestHigh - lowestLow != 0 ? -100 * (highestHigh - currentClose) / (highestHigh - lowestLow) : -100; williamsRList.AddRounded(williamsR); var signal = GetRsiSignal(williamsR - prevWilliamsR1, prevWilliamsR1 - prevWilliamsR2, williamsR, prevWilliamsR1, -20, -80); @@ -731,15 +731,15 @@ public static StockData CalculateTrueStrengthIndex(this StockData stockData, Mov List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double pc = MinPastValues(i, 1, currentValue - prevValue); + var pc = MinPastValues(i, 1, currentValue - prevValue); pcList.AddRounded(pc); - double absPC = Math.Abs(pc); + var absPC = Math.Abs(pc); absPCList.AddRounded(absPC); } @@ -747,22 +747,22 @@ public static StockData CalculateTrueStrengthIndex(this StockData stockData, Mov var pcSmooth2List = GetMovingAverageList(stockData, maType, length2, pcSmooth1List); var absPCSmooth1List = GetMovingAverageList(stockData, maType, length1, absPCList); var absPCSmooth2List = GetMovingAverageList(stockData, maType, length2, absPCSmooth1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double absSmooth2PC = absPCSmooth2List[i]; - double smooth2PC = pcSmooth2List[i]; + var absSmooth2PC = absPCSmooth2List[i]; + var smooth2PC = pcSmooth2List[i]; - double tsi = absSmooth2PC != 0 ? MinOrMax(100 * smooth2PC / absSmooth2PC, 100, -100) : 0; + var tsi = absSmooth2PC != 0 ? MinOrMax(100 * smooth2PC / absSmooth2PC, 100, -100) : 0; tsiList.AddRounded(tsi); } var tsiSignalList = GetMovingAverageList(stockData, maType, signalLength, tsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tsi = tsiList[i]; - double tsiSignal = tsiSignalList[i]; - double prevTsi = i >= 1 ? tsiList[i - 1] : 0; - double prevTsiSignal = i >= 1 ? tsiSignalList[i - 1] : 0; + var tsi = tsiList[i]; + var tsiSignal = tsiSignalList[i]; + var prevTsi = i >= 1 ? tsiList[i - 1] : 0; + var prevTsiSignal = i >= 1 ? tsiSignalList[i - 1] : 0; var signal = GetRsiSignal(tsi - tsiSignal, prevTsi - prevTsiSignal, tsi, prevTsi, 25, -25); signalsList.Add(signal); @@ -797,18 +797,18 @@ public static StockData CalculateElderRayIndex(this StockData stockData, MovingA var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentEma = emaList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentEma = emaList[i]; - double prevBullPower = bullPowerList.LastOrDefault(); - double bullPower = currentHigh - currentEma; + var prevBullPower = bullPowerList.LastOrDefault(); + var bullPower = currentHigh - currentEma; bullPowerList.AddRounded(bullPower); - double prevBearPower = bearPowerList.LastOrDefault(); - double bearPower = currentLow - currentEma; + var prevBearPower = bearPowerList.LastOrDefault(); + var bearPower = currentLow - currentEma; bearPowerList.AddRounded(bearPower); var signal = GetCompareSignal(bullPower - bearPower, prevBullPower - prevBearPower); @@ -845,13 +845,13 @@ public static StockData CalculateAbsolutePriceOscillator(this StockData stockDat var fastEmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowEmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastEma = fastEmaList[i]; - double slowEma = slowEmaList[i]; + var fastEma = fastEmaList[i]; + var slowEma = slowEmaList[i]; - double prevApo = apoList.LastOrDefault(); - double apo = fastEma - slowEma; + var prevApo = apoList.LastOrDefault(); + var apo = fastEma - slowEma; apoList.AddRounded(apo); var signal = GetCompareSignal(apo, prevApo); @@ -883,22 +883,22 @@ public static StockData CalculateAroonOscillator(this StockData stockData, int l var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; + var currentPrice = inputList[i]; tempList.AddRounded(currentPrice); - double maxPrice = highestList[i]; - int maxIndex = tempList.LastIndexOf(maxPrice); - double minPrice = lowestList[i]; - int minIndex = tempList.LastIndexOf(minPrice); - int daysSinceMax = i - maxIndex; - int daysSinceMin = i - minIndex; - double aroonUp = (double)(length - daysSinceMax) / length * 100; - double aroonDown = (double)(length - daysSinceMin) / length * 100; - - double prevAroonOscillator = aroonOscillatorList.LastOrDefault(); - double aroonOscillator = aroonUp - aroonDown; + var maxPrice = highestList[i]; + var maxIndex = tempList.LastIndexOf(maxPrice); + var minPrice = lowestList[i]; + var minIndex = tempList.LastIndexOf(minPrice); + var daysSinceMax = i - maxIndex; + var daysSinceMin = i - minIndex; + var aroonUp = (double)(length - daysSinceMax) / length * 100; + var aroonDown = (double)(length - daysSinceMin) / length * 100; + + var prevAroonOscillator = aroonOscillatorList.LastOrDefault(); + var aroonOscillator = aroonUp - aroonDown; aroonOscillatorList.AddRounded(aroonOscillator); var signal = GetCompareSignal(aroonOscillator, prevAroonOscillator); @@ -936,41 +936,41 @@ public static StockData CalculateAbsoluteStrengthIndex(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alp = (double)2 / (signalLength + 1); + var alp = (double)2 / (signalLength + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevA = AList.LastOrDefault(); - double A = currentValue > prevValue && prevValue != 0 ? prevA + ((currentValue / prevValue) - 1) : prevA; + var prevA = AList.LastOrDefault(); + var A = currentValue > prevValue && prevValue != 0 ? prevA + ((currentValue / prevValue) - 1) : prevA; AList.AddRounded(A); - double prevM = MList.LastOrDefault(); - double M = currentValue == prevValue ? prevM + ((double)1 / length) : prevM; + var prevM = MList.LastOrDefault(); + var M = currentValue == prevValue ? prevM + ((double)1 / length) : prevM; MList.AddRounded(M); - double prevD = DList.LastOrDefault(); - double D = currentValue < prevValue && currentValue != 0 ? prevD + ((prevValue / currentValue) - 1) : prevD; + var prevD = DList.LastOrDefault(); + var D = currentValue < prevValue && currentValue != 0 ? prevD + ((prevValue / currentValue) - 1) : prevD; DList.AddRounded(D); - double abssi = (D + M) / 2 != 0 ? 1 - (1 / (1 + ((A + M) / 2 / ((D + M) / 2)))) : 1; - double abssiEma = CalculateEMA(abssi, abssiEmaList.LastOrDefault(), maLength); + var abssi = (D + M) / 2 != 0 ? 1 - (1 / (1 + ((A + M) / 2 / ((D + M) / 2)))) : 1; + var abssiEma = CalculateEMA(abssi, abssiEmaList.LastOrDefault(), maLength); abssiEmaList.AddRounded(abssiEma); - double abssio = abssi - abssiEma; - double prevMt = mtList.LastOrDefault(); - double mt = (alp * abssio) + ((1 - alp) * prevMt); + var abssio = abssi - abssiEma; + var prevMt = mtList.LastOrDefault(); + var mt = (alp * abssio) + ((1 - alp) * prevMt); mtList.AddRounded(mt); - double prevUt = utList.LastOrDefault(); - double ut = (alp * mt) + ((1 - alp) * prevUt); + var prevUt = utList.LastOrDefault(); + var ut = (alp * mt) + ((1 - alp) * prevUt); utList.AddRounded(ut); - double s = (2 - alp) * (mt - ut) / (1 - alp); - double prevd = dList.LastOrDefault(); - double d = abssio - s; + var s = (2 - alp) * (mt - ut) / (1 - alp); + var prevd = dList.LastOrDefault(); + var d = abssio - s; dList.AddRounded(d); var signal = GetCompareSignal(d, prevd); @@ -1001,36 +1001,36 @@ public static StockData CalculateAccumulativeSwingIndex(this StockData stockData List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentClose = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevOpen = i >= 1 ? openList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHighCurrentClose = prevHigh - currentClose; - double prevLowCurrentClose = prevLow - currentClose; - double prevClosePrevOpen = prevClose - prevOpen; - double currentHighPrevClose = currentHigh - prevClose; - double currentLowPrevClose = currentLow - prevClose; - double t = currentHigh - currentLow; - double k = Math.Max(Math.Abs(prevHighCurrentClose), Math.Abs(prevLowCurrentClose)); - double r = currentHighPrevClose > Math.Max(currentLowPrevClose, t) ? currentHighPrevClose - (0.5 * currentLowPrevClose) + (0.25 * prevClosePrevOpen) : + for (var i = 0; i < stockData.Count; i++) + { + var currentClose = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevOpen = i >= 1 ? openList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHighCurrentClose = prevHigh - currentClose; + var prevLowCurrentClose = prevLow - currentClose; + var prevClosePrevOpen = prevClose - prevOpen; + var currentHighPrevClose = currentHigh - prevClose; + var currentLowPrevClose = currentLow - prevClose; + var t = currentHigh - currentLow; + var k = Math.Max(Math.Abs(prevHighCurrentClose), Math.Abs(prevLowCurrentClose)); + var r = currentHighPrevClose > Math.Max(currentLowPrevClose, t) ? currentHighPrevClose - (0.5 * currentLowPrevClose) + (0.25 * prevClosePrevOpen) : currentLowPrevClose > Math.Max(currentHighPrevClose, t) ? currentLowPrevClose - (0.5 * currentHighPrevClose) + (0.25 * prevClosePrevOpen) : t > Math.Max(currentHighPrevClose, currentLowPrevClose) ? t + (0.25 * prevClosePrevOpen) : 0; - double swingIndex = r != 0 && t != 0 ? 50 * ((prevClose - currentClose + (0.5 * prevClosePrevOpen) + - (0.25 * (currentClose - currentOpen))) / r) * (k / t) : 0; + var swingIndex = r != 0 && t != 0 ? 50 * ((prevClose - currentClose + (0.5 * prevClosePrevOpen) + + (0.25 * (currentClose - currentOpen))) / r) * (k / t) : 0; - double prevSwingIndex = accumulativeSwingIndexList.LastOrDefault(); - double accumulativeSwingIndex = prevSwingIndex + swingIndex; + var prevSwingIndex = accumulativeSwingIndexList.LastOrDefault(); + var accumulativeSwingIndex = prevSwingIndex + swingIndex; accumulativeSwingIndexList.AddRounded(accumulativeSwingIndex); } var asiOscillatorList = GetMovingAverageList(stockData, maType, length, accumulativeSwingIndexList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var asi = accumulativeSwingIndexList[i]; var prevAsi = i >= 1 ? accumulativeSwingIndexList[i - 1] : 0; @@ -1071,42 +1071,42 @@ public static StockData CalculateAdaptiveErgodicCandlestickOscillator(this Stock List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - double mep = (double)2 / (smoothLength + 1); + var mep = (double)2 / (smoothLength + 1); double ce = (stochLength + smoothLength) * 2; var stochList = CalculateStochasticOscillator(stockData, maType, length: stochLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stoch = stochList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double vrb = Math.Abs(stoch - 50) / 50; + var stoch = stochList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var vrb = Math.Abs(stoch - 50) / 50; - double prevCame1 = came1List.LastOrDefault(); - double came1 = i < ce ? currentClose - currentOpen : prevCame1 + (mep * vrb * (currentClose - currentOpen - prevCame1)); + var prevCame1 = came1List.LastOrDefault(); + var came1 = i < ce ? currentClose - currentOpen : prevCame1 + (mep * vrb * (currentClose - currentOpen - prevCame1)); came1List.AddRounded(came1); - double prevCame2 = came2List.LastOrDefault(); - double came2 = i < ce ? currentHigh - currentLow : prevCame2 + (mep * vrb * (currentHigh - currentLow - prevCame2)); + var prevCame2 = came2List.LastOrDefault(); + var came2 = i < ce ? currentHigh - currentLow : prevCame2 + (mep * vrb * (currentHigh - currentLow - prevCame2)); came2List.AddRounded(came2); - double prevCame11 = came11List.LastOrDefault(); - double came11 = i < ce ? came1 : prevCame11 + (mep * vrb * (came1 - prevCame11)); + var prevCame11 = came11List.LastOrDefault(); + var came11 = i < ce ? came1 : prevCame11 + (mep * vrb * (came1 - prevCame11)); came11List.AddRounded(came11); - double prevCame22 = came22List.LastOrDefault(); - double came22 = i < ce ? came2 : prevCame22 + (mep * vrb * (came2 - prevCame22)); + var prevCame22 = came22List.LastOrDefault(); + var came22 = i < ce ? came2 : prevCame22 + (mep * vrb * (came2 - prevCame22)); came22List.AddRounded(came22); - double eco = came22 != 0 ? came11 / came22 * 100 : 0; + var eco = came22 != 0 ? came11 / came22 * 100 : 0; ecoList.AddRounded(eco); } var seList = GetMovingAverageList(stockData, maType, signalLength, ecoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var eco = ecoList[i]; var se = seList[i]; @@ -1151,53 +1151,53 @@ public static StockData CalculateAbsoluteStrengthMTFIndicator(this StockData sto var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; prevValuesList.AddRounded(prevValue); } var price1List = GetMovingAverageList(stockData, maType, length, inputList); var price2List = GetMovingAverageList(stockData, maType, length, prevValuesList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double price1 = price1List[i]; - double price2 = price2List[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double high = highList[i]; - double low = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; + var price1 = price1List[i]; + var price2 = price2List[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var high = highList[i]; + var low = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; - double bulls0 = 0.5 * (Math.Abs(price1 - price2) + (price1 - price2)); + var bulls0 = 0.5 * (Math.Abs(price1 - price2) + (price1 - price2)); bulls0List.AddRounded(bulls0); - double bears0 = 0.5 * (Math.Abs(price1 - price2) - (price1 - price2)); + var bears0 = 0.5 * (Math.Abs(price1 - price2) - (price1 - price2)); bears0List.AddRounded(bears0); - double bulls1 = price1 - lowest; + var bulls1 = price1 - lowest; bulls1List.AddRounded(bulls1); - double bears1 = highest - price1; + var bears1 = highest - price1; bears1List.AddRounded(bears1); - double bulls2 = 0.5 * (Math.Abs(high - prevHigh) + (high - prevHigh)); + var bulls2 = 0.5 * (Math.Abs(high - prevHigh) + (high - prevHigh)); bulls2List.AddRounded(bulls2); - double bears2 = 0.5 * (Math.Abs(prevLow - low) + (prevLow - low)); + var bears2 = 0.5 * (Math.Abs(prevLow - low) + (prevLow - low)); bears2List.AddRounded(bears2); } var smthBulls0List = GetMovingAverageList(stockData, maType, smoothLength, bulls0List); var smthBears0List = GetMovingAverageList(stockData, maType, smoothLength, bears0List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double bulls = smthBulls0List[i]; - double bears = smthBears0List[i]; - double prevBulls = i >= 1 ? smthBulls0List[i - 1] : 0; - double prevBears = i >= 1 ? smthBears0List[i - 1] : 0; + var bulls = smthBulls0List[i]; + var bears = smthBears0List[i]; + var prevBulls = i >= 1 ? smthBulls0List[i - 1] : 0; + var prevBears = i >= 1 ? smthBears0List[i - 1] : 0; var signal = GetCompareSignal(bulls - bears, prevBulls - prevBears); signalsList.Add(signal); @@ -1229,7 +1229,7 @@ public static StockData CalculateJapaneseCorrelationCoefficient(this StockData s List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - int length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); + var length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); var hList = GetMovingAverageList(stockData, maType, length1, highList); var lList = GetMovingAverageList(stockData, maType, length1, lowList); @@ -1237,17 +1237,17 @@ public static StockData CalculateJapaneseCorrelationCoefficient(this StockData s var highestList = GetMaxAndMinValuesList(hList, length1).Item1; var lowestList = GetMaxAndMinValuesList(lList, length1).Item2; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double c = cList[i]; - double prevC = i >= length ? cList[i - length] : 0; - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevJo1 = i >= 1 ? joList[i - 1] : 0; - double prevJo2 = i >= 2 ? joList[i - 2] : 0; - double cChg = c - prevC; + var c = cList[i]; + var prevC = i >= length ? cList[i - length] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevJo1 = i >= 1 ? joList[i - 1] : 0; + var prevJo2 = i >= 2 ? joList[i - 2] : 0; + var cChg = c - prevC; - double jo = highest - lowest != 0 ? cChg / (highest - lowest) : 0; + var jo = highest - lowest != 0 ? cChg / (highest - lowest) : 0; joList.AddRounded(jo); var signal = GetCompareSignal(jo - prevJo1, prevJo1 - prevJo2); @@ -1292,86 +1292,86 @@ public static StockData CalculateJmaRsxClone(this StockData stockData, int lengt List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double f18 = (double)3 / (length + 2); - double f20 = 1 - f18; + var f18 = (double)3 / (length + 2); + var f20 = 1 - f18; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevRsx1 = i >= 1 ? rsxList[i - 1] : 0; - double prevRsx2 = i >= 2 ? rsxList[i - 2] : 0; + var currentValue = inputList[i]; + var prevRsx1 = i >= 1 ? rsxList[i - 1] : 0; + var prevRsx2 = i >= 2 ? rsxList[i - 2] : 0; - double prevF8 = f8List.LastOrDefault(); - double f8 = 100 * currentValue; + var prevF8 = f8List.LastOrDefault(); + var f8 = 100 * currentValue; f8List.AddRounded(f8); - double f10 = prevF8; - double v8 = f8 - f10; + var f10 = prevF8; + var v8 = f8 - f10; - double prevF28 = f28List.LastOrDefault(); - double f28 = (f20 * prevF28) + (f18 * v8); + var prevF28 = f28List.LastOrDefault(); + var f28 = (f20 * prevF28) + (f18 * v8); f28List.AddRounded(f28); - double prevF30 = f30List.LastOrDefault(); - double f30 = (f18 * f28) + (f20 * prevF30); + var prevF30 = f30List.LastOrDefault(); + var f30 = (f18 * f28) + (f20 * prevF30); f30List.AddRounded(f30); - double vC = (f28 * 1.5) - (f30 * 0.5); - double prevF38 = f38List.LastOrDefault(); - double f38 = (f20 * prevF38) + (f18 * vC); + var vC = (f28 * 1.5) - (f30 * 0.5); + var prevF38 = f38List.LastOrDefault(); + var f38 = (f20 * prevF38) + (f18 * vC); f38List.AddRounded(f38); - double prevF40 = f40List.LastOrDefault(); - double f40 = (f18 * f38) + (f20 * prevF40); + var prevF40 = f40List.LastOrDefault(); + var f40 = (f18 * f38) + (f20 * prevF40); f40List.AddRounded(f40); - double v10 = (f38 * 1.5) - (f40 * 0.5); - double prevF48 = f48List.LastOrDefault(); - double f48 = (f20 * prevF48) + (f18 * v10); + var v10 = (f38 * 1.5) - (f40 * 0.5); + var prevF48 = f48List.LastOrDefault(); + var f48 = (f20 * prevF48) + (f18 * v10); f48List.AddRounded(f48); - double prevF50 = f50List.LastOrDefault(); - double f50 = (f18 * f48) + (f20 * prevF50); + var prevF50 = f50List.LastOrDefault(); + var f50 = (f18 * f48) + (f20 * prevF50); f50List.AddRounded(f50); - double v14 = (f48 * 1.5) - (f50 * 0.5); - double prevF58 = f58List.LastOrDefault(); - double f58 = (f20 * prevF58) + (f18 * Math.Abs(v8)); + var v14 = (f48 * 1.5) - (f50 * 0.5); + var prevF58 = f58List.LastOrDefault(); + var f58 = (f20 * prevF58) + (f18 * Math.Abs(v8)); f58List.AddRounded(f58); - double prevF60 = f60List.LastOrDefault(); - double f60 = (f18 * f58) + (f20 * prevF60); + var prevF60 = f60List.LastOrDefault(); + var f60 = (f18 * f58) + (f20 * prevF60); f60List.AddRounded(f60); - double v18 = (f58 * 1.5) - (f60 * 0.5); - double prevF68 = f68List.LastOrDefault(); - double f68 = (f20 * prevF68) + (f18 * v18); + var v18 = (f58 * 1.5) - (f60 * 0.5); + var prevF68 = f68List.LastOrDefault(); + var f68 = (f20 * prevF68) + (f18 * v18); f68List.AddRounded(f68); - double prevF70 = f70List.LastOrDefault(); - double f70 = (f18 * f68) + (f20 * prevF70); + var prevF70 = f70List.LastOrDefault(); + var f70 = (f18 * f68) + (f20 * prevF70); f70List.AddRounded(f70); - double v1C = (f68 * 1.5) - (f70 * 0.5); - double prevF78 = f78List.LastOrDefault(); - double f78 = (f20 * prevF78) + (f18 * v1C); + var v1C = (f68 * 1.5) - (f70 * 0.5); + var prevF78 = f78List.LastOrDefault(); + var f78 = (f20 * prevF78) + (f18 * v1C); f78List.AddRounded(f78); - double prevF80 = f80List.LastOrDefault(); - double f80 = (f18 * f78) + (f20 * prevF80); + var prevF80 = f80List.LastOrDefault(); + var f80 = (f18 * f78) + (f20 * prevF80); f80List.AddRounded(f80); - double v20 = (f78 * 1.5) - (f80 * 0.5); - double prevF88 = f88List.LastOrDefault(); - double prevF90_ = f90_List.LastOrDefault(); - double f90_ = prevF90_ == 0 ? 1 : prevF88 <= prevF90_ ? prevF88 + 1 : prevF90_ + 1; + var v20 = (f78 * 1.5) - (f80 * 0.5); + var prevF88 = f88List.LastOrDefault(); + var prevF90_ = f90_List.LastOrDefault(); + var f90_ = prevF90_ == 0 ? 1 : prevF88 <= prevF90_ ? prevF88 + 1 : prevF90_ + 1; f90_List.AddRounded(f90_); double f88 = prevF90_ == 0 && length - 1 >= 5 ? length - 1 : 5; double f0 = f88 >= f90_ && f8 != f10 ? 1 : 0; - double f90 = f88 == f90_ && f0 == 0 ? 0 : f90_; - double v4_ = f88 < f90 && v20 > 0 ? MinOrMax(((v14 / v20) + 1) * 50, 100, 0) : 50; - double rsx = v4_ > 100 ? 100 : v4_ < 0 ? 0 : v4_; + var f90 = f88 == f90_ && f0 == 0 ? 0 : f90_; + var v4_ = f88 < f90 && v20 > 0 ? MinOrMax(((v14 / v20) + 1) * 50, 100, 0) : 50; + var rsx = v4_ > 100 ? 100 : v4_ < 0 ? 0 : v4_; rsxList.AddRounded(rsx); var signal = GetRsiSignal(rsx - prevRsx1, prevRsx1 - prevRsx2, rsx, prevRsx1, 70, 30); @@ -1407,42 +1407,42 @@ public static StockData CalculateJrcFractalDimension(this StockData stockData, M List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - int wind1 = MinOrMax((length2 - 1) * length1); - int wind2 = MinOrMax(length2 * length1); - double nLog = Math.Log(length2); + var wind1 = MinOrMax((length2 - 1) * length1); + var wind2 = MinOrMax(length2 * length1); + var nLog = Math.Log(length2); var (highest1List, lowest1List) = GetMaxAndMinValuesList(highList, lowList, length1); var (highest2List, lowest2List) = GetMaxAndMinValuesList(highList, lowList, wind2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest1 = highest1List[i]; - double lowest1 = lowest1List[i]; - double prevValue1 = i >= length1 ? inputList[i - length1] : 0; - double highest2 = highest2List[i]; - double lowest2 = lowest2List[i]; - double prevValue2 = i >= wind2 ? inputList[i - wind2] : 0; - double bigRange = Math.Max(prevValue2, highest2) - Math.Min(prevValue2, lowest2); + var highest1 = highest1List[i]; + var lowest1 = lowest1List[i]; + var prevValue1 = i >= length1 ? inputList[i - length1] : 0; + var highest2 = highest2List[i]; + var lowest2 = lowest2List[i]; + var prevValue2 = i >= wind2 ? inputList[i - wind2] : 0; + var bigRange = Math.Max(prevValue2, highest2) - Math.Min(prevValue2, lowest2); - double prevSmallRange = i >= wind1 ? smallRangeList[i - wind1] : 0; - double smallRange = Math.Max(prevValue1, highest1) - Math.Min(prevValue1, lowest1); + var prevSmallRange = i >= wind1 ? smallRangeList[i - wind1] : 0; + var smallRange = Math.Max(prevValue1, highest1) - Math.Min(prevValue1, lowest1); smallRangeList.AddRounded(smallRange); - double prevSmallSum = i >= 1 ? smallSumList.LastOrDefault() : smallRange; - double smallSum = prevSmallSum + smallRange - prevSmallRange; + var prevSmallSum = i >= 1 ? smallSumList.LastOrDefault() : smallRange; + var smallSum = prevSmallSum + smallRange - prevSmallRange; smallSumList.AddRounded(smallSum); - double value1 = wind1 != 0 ? smallSum / wind1 : 0; - double value2 = value1 != 0 ? bigRange / value1 : 0; - double temp = value2 > 0 ? Math.Log(value2) : 0; + var value1 = wind1 != 0 ? smallSum / wind1 : 0; + var value2 = value1 != 0 ? bigRange / value1 : 0; + var temp = value2 > 0 ? Math.Log(value2) : 0; - double fd = nLog != 0 ? 2 - (temp / nLog) : 0; + var fd = nLog != 0 ? 2 - (temp / nLog) : 0; fdList.AddRounded(fd); } var jrcfdList = GetMovingAverageList(stockData, maType, smoothLength, fdList); var jrcfdSignalList = GetMovingAverageList(stockData, maType, smoothLength, jrcfdList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var jrcfd = jrcfdList[i]; var jrcfdSignal = jrcfdSignalList[i]; @@ -1481,10 +1481,10 @@ public static StockData CalculateZweigMarketBreadthIndicator(this StockData stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double advance = currentValue > prevValue ? 1 : 0; advancesList.AddRounded(advance); @@ -1492,19 +1492,19 @@ public static StockData CalculateZweigMarketBreadthIndicator(this StockData stoc double decline = currentValue < prevValue ? 1 : 0; declinesList.AddRounded(decline); - double advSum = advancesList.TakeLastExt(length).Sum(); - double decSum = declinesList.TakeLastExt(length).Sum(); + var advSum = advancesList.TakeLastExt(length).Sum(); + var decSum = declinesList.TakeLastExt(length).Sum(); - double advDiff = advSum + decSum != 0 ? advSum / (advSum + decSum) : 0; + var advDiff = advSum + decSum != 0 ? advSum / (advSum + decSum) : 0; advDiffList.AddRounded(advDiff); } var zmbtiList = GetMovingAverageList(stockData, maType, length, advDiffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevZmbti1 = i >= 1 ? zmbtiList[i - 1] : 0; - double prevZmbti2 = i >= 2 ? zmbtiList[i - 2] : 0; - double zmbti = zmbtiList[i]; + var prevZmbti1 = i >= 1 ? zmbtiList[i - 1] : 0; + var prevZmbti2 = i >= 2 ? zmbtiList[i - 2] : 0; + var zmbti = zmbtiList[i]; var signal = GetRsiSignal(zmbti - prevZmbti1, prevZmbti1 - prevZmbti2, zmbti, prevZmbti1, 0.615, 0.4); signalsList.Add(signal); @@ -1539,15 +1539,15 @@ public static StockData CalculateZDistanceFromVwapIndicator(this StockData stock stockData.CustomValuesList = vwapList; var vwapSdList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevZScore1 = i >= 1 ? zscoreList[i - 1] : 0; - double prevZScore2 = i >= 2 ? zscoreList[i - 2] : 0; - double mean = vwapList[i]; - double vwapsd = vwapSdList[i]; + var currentValue = inputList[i]; + var prevZScore1 = i >= 1 ? zscoreList[i - 1] : 0; + var prevZScore2 = i >= 2 ? zscoreList[i - 2] : 0; + var mean = vwapList[i]; + var vwapsd = vwapSdList[i]; - double zscore = vwapsd != 0 ? (currentValue - mean) / vwapsd : 0; + var zscore = vwapsd != 0 ? (currentValue - mean) / vwapsd : 0; zscoreList.AddRounded(zscore); var signal = GetRsiSignal(zscore - prevZScore1, prevZScore1 - prevZScore2, zscore, prevZScore1, 2, -2); @@ -1581,15 +1581,15 @@ public static StockData CalculateZScore(this StockData stockData, MovingAvgType var smaList = GetMovingAverageList(stockData, maType, length, inputList); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double dev = currentValue - sma; - double stdDevPopulation = stdDevList[i]; + var currentValue = inputList[i]; + var sma = smaList[i]; + var dev = currentValue - sma; + var stdDevPopulation = stdDevList[i]; - double prevZScorePopulation = zScorePopulationList.LastOrDefault(); - double zScorePopulation = stdDevPopulation != 0 ? dev / stdDevPopulation : 0; + var prevZScorePopulation = zScorePopulationList.LastOrDefault(); + var zScorePopulation = stdDevPopulation != 0 ? dev / stdDevPopulation : 0; zScorePopulationList.AddRounded(zScorePopulation); var signal = GetCompareSignal(zScorePopulation, prevZScorePopulation); @@ -1626,79 +1626,79 @@ public static StockData CalculateZeroLagSmoothedCycle(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); + var length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); var linregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double linreg = linregList[i]; + var currentValue = inputList[i]; + var linreg = linregList[i]; - double ax1 = currentValue - linreg; + var ax1 = currentValue - linreg; ax1List.AddRounded(ax1); } stockData.CustomValuesList = ax1List; var ax1LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ax1 = ax1List[i]; - double ax1Linreg = ax1LinregList[i]; + var ax1 = ax1List[i]; + var ax1Linreg = ax1LinregList[i]; - double lx1 = ax1 + (ax1 - ax1Linreg); + var lx1 = ax1 + (ax1 - ax1Linreg); lx1List.AddRounded(lx1); } stockData.CustomValuesList = lx1List; var lx1LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double lx1 = lx1List[i]; - double lx1Linreg = lx1LinregList[i]; + var lx1 = lx1List[i]; + var lx1Linreg = lx1LinregList[i]; - double ax2 = lx1 - lx1Linreg; + var ax2 = lx1 - lx1Linreg; ax2List.AddRounded(ax2); } stockData.CustomValuesList = ax2List; var ax2LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ax2 = ax2List[i]; - double ax2Linreg = ax2LinregList[i]; + var ax2 = ax2List[i]; + var ax2Linreg = ax2LinregList[i]; - double lx2 = ax2 + (ax2 - ax2Linreg); + var lx2 = ax2 + (ax2 - ax2Linreg); lx2List.AddRounded(lx2); } stockData.CustomValuesList = lx2List; var lx2LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double lx2 = lx2List[i]; - double lx2Linreg = lx2LinregList[i]; + var lx2 = lx2List[i]; + var lx2Linreg = lx2LinregList[i]; - double ax3 = lx2 - lx2Linreg; + var ax3 = lx2 - lx2Linreg; ax3List.AddRounded(ax3); } stockData.CustomValuesList = ax3List; var ax3LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ax3 = ax3List[i]; - double ax3Linreg = ax3LinregList[i]; + var ax3 = ax3List[i]; + var ax3Linreg = ax3LinregList[i]; - double prevLco = lcoList.LastOrDefault(); - double lco = ax3 + (ax3 - ax3Linreg); + var prevLco = lcoList.LastOrDefault(); + var lco = ax3 + (ax3 - ax3Linreg); lcoList.AddRounded(lco); - double lcoSma1 = lcoList.TakeLastExt(length1).Average(); + var lcoSma1 = lcoList.TakeLastExt(length1).Average(); lcoSma1List.AddRounded(lcoSma1); - double lcoSma2 = lcoSma1List.TakeLastExt(length1).Average(); - double prevFilter = filterList.LastOrDefault(); - double filter = -lcoSma2 * 2; + var lcoSma2 = lcoSma1List.TakeLastExt(length1).Average(); + var prevFilter = filterList.LastOrDefault(); + var filter = -lcoSma2 * 2; filterList.AddRounded(filter); var signal = GetCompareSignal(lco - filter, prevLco - prevFilter); @@ -1745,58 +1745,58 @@ public static StockData CalculateBayesianOscillator(this StockData stockData, Mo var upperBbList = bbList.OutputValues["UpperBand"]; var basisList = bbList.OutputValues["MiddleBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double upperBb = upperBbList[i]; - double basis = basisList[i]; + var currentValue = inputList[i]; + var upperBb = upperBbList[i]; + var basis = basisList[i]; double probBbUpperUpSeq = currentValue > upperBb ? 1 : 0; probBbUpperUpSeqList.AddRounded(probBbUpperUpSeq); - double probBbUpperUp = probBbUpperUpSeqList.TakeLastExt(length).Average(); + var probBbUpperUp = probBbUpperUpSeqList.TakeLastExt(length).Average(); double probBbUpperDownSeq = currentValue < upperBb ? 1 : 0; probBbUpperDownSeqList.AddRounded(probBbUpperDownSeq); - double probBbUpperDown = probBbUpperDownSeqList.TakeLastExt(length).Average(); - double probUpBbUpper = probBbUpperUp + probBbUpperDown != 0 ? probBbUpperUp / (probBbUpperUp + probBbUpperDown) : 0; - double probDownBbUpper = probBbUpperUp + probBbUpperDown != 0 ? probBbUpperDown / (probBbUpperUp + probBbUpperDown) : 0; + var probBbUpperDown = probBbUpperDownSeqList.TakeLastExt(length).Average(); + var probUpBbUpper = probBbUpperUp + probBbUpperDown != 0 ? probBbUpperUp / (probBbUpperUp + probBbUpperDown) : 0; + var probDownBbUpper = probBbUpperUp + probBbUpperDown != 0 ? probBbUpperDown / (probBbUpperUp + probBbUpperDown) : 0; double probBbBasisUpSeq = currentValue > basis ? 1 : 0; probBbBasisUpSeqList.AddRounded(probBbBasisUpSeq); - double probBbBasisUp = probBbBasisUpSeqList.TakeLastExt(length).Average(); + var probBbBasisUp = probBbBasisUpSeqList.TakeLastExt(length).Average(); probBbBasisUpList.AddRounded(probBbBasisUp); double probBbBasisDownSeq = currentValue < basis ? 1 : 0; probBbBasisDownSeqList.AddRounded(probBbBasisDownSeq); - double probBbBasisDown = probBbBasisDownSeqList.TakeLastExt(length).Average(); + var probBbBasisDown = probBbBasisDownSeqList.TakeLastExt(length).Average(); probBbBasisDownList.AddRounded(probBbBasisDown); - double probUpBbBasis = probBbBasisUp + probBbBasisDown != 0 ? probBbBasisUp / (probBbBasisUp + probBbBasisDown) : 0; - double probDownBbBasis = probBbBasisUp + probBbBasisDown != 0 ? probBbBasisDown / (probBbBasisUp + probBbBasisDown) : 0; + var probUpBbBasis = probBbBasisUp + probBbBasisDown != 0 ? probBbBasisUp / (probBbBasisUp + probBbBasisDown) : 0; + var probDownBbBasis = probBbBasisUp + probBbBasisDown != 0 ? probBbBasisDown / (probBbBasisUp + probBbBasisDown) : 0; - double prevSigmaProbsDown = sigmaProbsDownList.LastOrDefault(); - double sigmaProbsDown = probUpBbUpper != 0 && probUpBbBasis != 0 ? ((probUpBbUpper * probUpBbBasis) / (probUpBbUpper * probUpBbBasis)) + - ((1 - probUpBbUpper) * (1 - probUpBbBasis)) : 0; + var prevSigmaProbsDown = sigmaProbsDownList.LastOrDefault(); + var sigmaProbsDown = probUpBbUpper != 0 && probUpBbBasis != 0 ? ((probUpBbUpper * probUpBbBasis) / (probUpBbUpper * probUpBbBasis)) + + ((1 - probUpBbUpper) * (1 - probUpBbBasis)) : 0; sigmaProbsDownList.AddRounded(sigmaProbsDown); - double prevSigmaProbsUp = sigmaProbsUpList.LastOrDefault(); - double sigmaProbsUp = probDownBbUpper != 0 && probDownBbBasis != 0 ? ((probDownBbUpper * probDownBbBasis) / (probDownBbUpper * probDownBbBasis)) + - ((1 - probDownBbUpper) * (1 - probDownBbBasis)) : 0; + var prevSigmaProbsUp = sigmaProbsUpList.LastOrDefault(); + var sigmaProbsUp = probDownBbUpper != 0 && probDownBbBasis != 0 ? ((probDownBbUpper * probDownBbBasis) / (probDownBbUpper * probDownBbBasis)) + + ((1 - probDownBbUpper) * (1 - probDownBbBasis)) : 0; sigmaProbsUpList.AddRounded(sigmaProbsUp); - double prevProbPrime = probPrimeList.LastOrDefault(); - double probPrime = sigmaProbsDown != 0 && sigmaProbsUp != 0 ? ((sigmaProbsDown * sigmaProbsUp) / (sigmaProbsDown * sigmaProbsUp)) + - ((1 - sigmaProbsDown) * (1 - sigmaProbsUp)) : 0; + var prevProbPrime = probPrimeList.LastOrDefault(); + var probPrime = sigmaProbsDown != 0 && sigmaProbsUp != 0 ? ((sigmaProbsDown * sigmaProbsUp) / (sigmaProbsDown * sigmaProbsUp)) + + ((1 - sigmaProbsDown) * (1 - sigmaProbsUp)) : 0; probPrimeList.AddRounded(probPrime); - bool longUsingProbPrime = probPrime > lowerThreshold / 100 && prevProbPrime == 0; - bool longUsingSigmaProbsUp = sigmaProbsUp < 1 && prevSigmaProbsUp == 1; - bool shortUsingProbPrime = probPrime == 0 && prevProbPrime > lowerThreshold / 100; - bool shortUsingSigmaProbsDown = sigmaProbsDown < 1 && prevSigmaProbsDown == 1; + var longUsingProbPrime = probPrime > lowerThreshold / 100 && prevProbPrime == 0; + var longUsingSigmaProbsUp = sigmaProbsUp < 1 && prevSigmaProbsUp == 1; + var shortUsingProbPrime = probPrime == 0 && prevProbPrime > lowerThreshold / 100; + var shortUsingSigmaProbsDown = sigmaProbsDown < 1 && prevSigmaProbsDown == 1; var signal = GetConditionSignal(longUsingProbPrime || longUsingSigmaProbsUp, shortUsingProbPrime || shortUsingSigmaProbsDown); signalsList.Add(signal); @@ -1828,15 +1828,15 @@ public static StockData CalculateBearPowerIndicator(this StockData stockData, Mo List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double open = openList[i]; - double high = highList[i]; - double low = lowList[i]; + var close = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var open = openList[i]; + var high = highList[i]; + var low = lowList[i]; - double bpi = close < open ? high - low : prevClose > open ? Math.Max(close - open, high - low) : + var bpi = close < open ? high - low : prevClose > open ? Math.Max(close - open, high - low) : close > open ? Math.Max(open - low, high - close) : prevClose > open ? Math.Max(prevClose - low, high - close) : high - close > close - low ? high - low : prevClose > open ? Math.Max(prevClose - open, high - low) : high - close < close - low ? open - low : close > open ? Math.Max(close - low, high - close) : @@ -1845,7 +1845,7 @@ public static StockData CalculateBearPowerIndicator(this StockData stockData, Mo } var bpiEmaList = GetMovingAverageList(stockData, maType, length, bpiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var bpi = bpiList[i]; var bpiEma = bpiEmaList[i]; @@ -1881,15 +1881,15 @@ public static StockData CalculateBullPowerIndicator(this StockData stockData, Mo List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double open = openList[i]; - double high = highList[i]; - double low = lowList[i]; + var close = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var open = openList[i]; + var high = highList[i]; + var low = lowList[i]; - double bpi = close < open ? Math.Max(high - open, close - low) : prevClose < open ? Math.Max(high - prevClose, close - low) : + var bpi = close < open ? Math.Max(high - open, close - low) : prevClose < open ? Math.Max(high - prevClose, close - low) : close > open ? Math.Max(open - prevClose, high - low) : prevClose > open ? high - low : high - close > close - low ? high - open : prevClose < open ? Math.Max(high - prevClose, close - low) : high - close < close - low ? Math.Max(open - close, high - low) : prevClose > open ? high - low : @@ -1898,7 +1898,7 @@ public static StockData CalculateBullPowerIndicator(this StockData stockData, Mo } var bpiEmaList = GetMovingAverageList(stockData, maType, length, bpiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var bpi = bpiList[i]; var bpiEma = bpiEmaList[i]; @@ -1932,27 +1932,27 @@ public static StockData CalculateBelkhayateTiming(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh1 = i >= 1 ? highList[i - 1] : 0; - double prevLow1 = i >= 1 ? lowList[i - 1] : 0; - double prevHigh2 = i >= 2 ? highList[i - 2] : 0; - double prevLow2 = i >= 2 ? lowList[i - 2] : 0; - double prevHigh3 = i >= 3 ? highList[i - 3] : 0; - double prevLow3 = i >= 3 ? lowList[i - 3] : 0; - double prevHigh4 = i >= 4 ? highList[i - 4] : 0; - double prevLow4 = i >= 4 ? lowList[i - 4] : 0; - double prevB1 = i >= 1 ? bList[i - 1] : 0; - double prevB2 = i >= 2 ? bList[i - 2] : 0; - double middle = (((currentHigh + currentLow) / 2) + ((prevHigh1 + prevLow1) / 2) + ((prevHigh2 + prevLow2) / 2) + - ((prevHigh3 + prevLow3) / 2) + ((prevHigh4 + prevLow4) / 2)) / 5; - double scale = ((currentHigh - currentLow + (prevHigh1 - prevLow1) + (prevHigh2 - prevLow2) + (prevHigh3 - prevLow3) + - (prevHigh4 - prevLow4)) / 5) * 0.2; - - double b = scale != 0 ? (currentValue - middle) / scale : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh1 = i >= 1 ? highList[i - 1] : 0; + var prevLow1 = i >= 1 ? lowList[i - 1] : 0; + var prevHigh2 = i >= 2 ? highList[i - 2] : 0; + var prevLow2 = i >= 2 ? lowList[i - 2] : 0; + var prevHigh3 = i >= 3 ? highList[i - 3] : 0; + var prevLow3 = i >= 3 ? lowList[i - 3] : 0; + var prevHigh4 = i >= 4 ? highList[i - 4] : 0; + var prevLow4 = i >= 4 ? lowList[i - 4] : 0; + var prevB1 = i >= 1 ? bList[i - 1] : 0; + var prevB2 = i >= 2 ? bList[i - 2] : 0; + var middle = (((currentHigh + currentLow) / 2) + ((prevHigh1 + prevLow1) / 2) + ((prevHigh2 + prevLow2) / 2) + + ((prevHigh3 + prevLow3) / 2) + ((prevHigh4 + prevLow4) / 2)) / 5; + var scale = ((currentHigh - currentLow + (prevHigh1 - prevLow1) + (prevHigh2 - prevLow2) + (prevHigh3 - prevLow3) + + (prevHigh4 - prevLow4)) / 5) * 0.2; + + var b = scale != 0 ? (currentValue - middle) / scale : 0; bList.AddRounded(b); var signal = GetRsiSignal(b - prevB1, prevB1 - prevB2, b, prevB1, 4, -4); @@ -1990,13 +1990,13 @@ public static StockData CalculateUltimateTraderOscillator(this StockData stockDa var (inputList, highList, lowList, openList, volumeList) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, rangeLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; - double tr = CalculateTrueRange(currentHigh, currentLow, prevClose); + var tr = CalculateTrueRange(currentHigh, currentLow, prevClose); trList.AddRounded(tr); } @@ -2004,45 +2004,45 @@ public static StockData CalculateUltimateTraderOscillator(this StockData stockDa var trStoList = CalculateStochasticOscillator(stockData, maType, length: lbLength).CustomValuesList; stockData.CustomValuesList = volumeList; var vStoList = CalculateStochasticOscillator(stockData, maType, length: lbLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double close = inputList[i]; - double body = close - openList[i]; - double high = highList[i]; - double low = lowList[i]; - double range = high - low; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double c = close - prevClose; + for (var i = 0; i < stockData.Count; i++) + { + var close = inputList[i]; + var body = close - openList[i]; + var high = highList[i]; + var low = lowList[i]; + var range = high - low; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var c = close - prevClose; double sign = Math.Sign(c); - double highest = highestList[i]; - double lowest = lowestList[i]; - double vSto = vStoList[i]; - double trSto = trStoList[i]; - double k1 = range != 0 ? body / range * 100 : 0; - double k2 = range == 0 ? 0 : ((close - low) / range * 100 * 2) - 100; - double k3 = c == 0 || highest - lowest == 0 ? 0 : ((close - lowest) / (highest - lowest) * 100 * 2) - 100; - double k4 = highest - lowest != 0 ? c / (highest - lowest) * 100 : 0; - double k5 = sign * trSto; - double k6 = sign * vSto; - double bullScore = Math.Max(0, k1) + Math.Max(0, k2) + Math.Max(0, k3) + Math.Max(0, k4) + Math.Max(0, k5) + Math.Max(0, k6); - double bearScore = -1 * (Math.Min(0, k1) + Math.Min(0, k2) + Math.Min(0, k3) + Math.Min(0, k4) + Math.Min(0, k5) + Math.Min(0, k6)); - - double dx = bearScore != 0 ? bullScore / bearScore : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var vSto = vStoList[i]; + var trSto = trStoList[i]; + var k1 = range != 0 ? body / range * 100 : 0; + var k2 = range == 0 ? 0 : ((close - low) / range * 100 * 2) - 100; + var k3 = c == 0 || highest - lowest == 0 ? 0 : ((close - lowest) / (highest - lowest) * 100 * 2) - 100; + var k4 = highest - lowest != 0 ? c / (highest - lowest) * 100 : 0; + var k5 = sign * trSto; + var k6 = sign * vSto; + var bullScore = Math.Max(0, k1) + Math.Max(0, k2) + Math.Max(0, k3) + Math.Max(0, k4) + Math.Max(0, k5) + Math.Max(0, k6); + var bearScore = -1 * (Math.Min(0, k1) + Math.Min(0, k2) + Math.Min(0, k3) + Math.Min(0, k4) + Math.Min(0, k5) + Math.Min(0, k6)); + + var dx = bearScore != 0 ? bullScore / bearScore : 0; dxList.AddRounded(dx); - double dxi = (2 * (100 - (100 / (1 + dx)))) - 100; + var dxi = (2 * (100 - (100 / (1 + dx)))) - 100; dxiList.AddRounded(dxi); } var dxiavgList = GetMovingAverageList(stockData, maType, lbLength, dxiList); var dxisList = GetMovingAverageList(stockData, maType, smoothLength, dxiavgList); var dxissList = GetMovingAverageList(stockData, maType, smoothLength, dxisList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dxis = dxisList[i]; - double dxiss = dxissList[i]; - double prevDxis = i >= 1 ? dxisList[i - 1] : 0; - double prevDxiss = i >= 1 ? dxissList[i - 1] : 0; + var dxis = dxisList[i]; + var dxiss = dxissList[i]; + var prevDxis = i >= 1 ? dxisList[i - 1] : 0; + var prevDxiss = i >= 1 ? dxissList[i - 1] : 0; var signal = GetCompareSignal(dxis - dxiss, prevDxis - prevDxiss); signalsList.Add(signal); @@ -2078,22 +2078,22 @@ public static StockData CalculateUhlMaCrossoverSystem(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); var varList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double prevVar = i >= length ? varList[i - length] : 0; - double prevCma = i >= 1 ? cmaList.LastOrDefault() : currentValue; - double prevCts = i >= 1 ? ctsList.LastOrDefault() : currentValue; - double secma = Pow(sma - prevCma, 2); - double sects = Pow(currentValue - prevCts, 2); - double ka = prevVar < secma && secma != 0 ? 1 - (prevVar / secma) : 0; - double kb = prevVar < sects && sects != 0 ? 1 - (prevVar / sects) : 0; + var currentValue = inputList[i]; + var sma = smaList[i]; + var prevVar = i >= length ? varList[i - length] : 0; + var prevCma = i >= 1 ? cmaList.LastOrDefault() : currentValue; + var prevCts = i >= 1 ? ctsList.LastOrDefault() : currentValue; + var secma = Pow(sma - prevCma, 2); + var sects = Pow(currentValue - prevCts, 2); + var ka = prevVar < secma && secma != 0 ? 1 - (prevVar / secma) : 0; + var kb = prevVar < sects && sects != 0 ? 1 - (prevVar / sects) : 0; - double cma = (ka * sma) + ((1 - ka) * prevCma); + var cma = (ka * sma) + ((1 - ka) * prevCma); cmaList.AddRounded(cma); - double cts = (kb * currentValue) + ((1 - kb) * prevCts); + var cts = (kb * currentValue) + ((1 - kb) * prevCts); ctsList.AddRounded(cts); var signal = GetCompareSignal(cts - cma, prevCts - prevCma); @@ -2133,10 +2133,10 @@ public static StockData CalculateMcClellanOscillator(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double advance = currentValue > prevValue ? 1 : 0; advancesList.AddRounded(advance); @@ -2144,13 +2144,13 @@ public static StockData CalculateMcClellanOscillator(this StockData stockData, M double decline = currentValue < prevValue ? 1 : 0; declinesList.AddRounded(decline); - double advanceSum = advancesList.TakeLastExt(fastLength).Sum(); + var advanceSum = advancesList.TakeLastExt(fastLength).Sum(); advancesSumList.AddRounded(advanceSum); - double declineSum = declinesList.TakeLastExt(fastLength).Sum(); + var declineSum = declinesList.TakeLastExt(fastLength).Sum(); declinesSumList.AddRounded(declineSum); - double rana = advanceSum + declineSum != 0 ? mult * (advanceSum - declineSum) / (advanceSum + declineSum) : 0; + var rana = advanceSum + declineSum != 0 ? mult * (advanceSum - declineSum) / (advanceSum + declineSum) : 0; ranaList.AddRounded(rana); } @@ -2159,10 +2159,10 @@ public static StockData CalculateMcClellanOscillator(this StockData stockData, M var mcclellanOscillatorList = moList.OutputValues["Macd"]; var mcclellanSignalLineList = moList.OutputValues["Signal"]; var mcclellanHistogramList = moList.OutputValues["Histogram"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mcclellanHistogram = mcclellanHistogramList[i]; - double prevMcclellanHistogram = i >= 1 ? mcclellanHistogramList[i - 1] : 0; + var mcclellanHistogram = mcclellanHistogramList[i]; + var prevMcclellanHistogram = i >= 1 ? mcclellanHistogramList[i - 1] : 0; var signal = GetCompareSignal(mcclellanHistogram, prevMcclellanHistogram); signalsList.Add(signal); @@ -2200,13 +2200,13 @@ public static StockData CalculateWoodieCommodityChannelIndex(this StockData stoc var cciList = CalculateCommodityChannelIndex(stockData, maType: maType, length: slowLength).CustomValuesList; var turboCciList = CalculateCommodityChannelIndex(stockData, maType: maType, length: fastLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double cci = cciList[i]; - double cciTurbo = turboCciList[i]; + var cci = cciList[i]; + var cciTurbo = turboCciList[i]; - double prevCciHistogram = histogramList.LastOrDefault(); - double cciHistogram = cciTurbo - cci; + var prevCciHistogram = histogramList.LastOrDefault(); + var cciHistogram = cciTurbo - cci; histogramList.AddRounded(cciHistogram); var signal = GetCompareSignal(cciHistogram, prevCciHistogram); @@ -2239,28 +2239,28 @@ public static StockData CalculateWilliamsFractals(this StockData stockData, int List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double prevHigh = i >= length - 2 ? highList[i - (length - 2)] : 0; - double prevHigh1 = i >= length - 1 ? highList[i - (length - 1)] : 0; - double prevHigh2 = i >= length ? highList[i - length] : 0; - double prevHigh3 = i >= length + 1 ? highList[i - (length + 1)] : 0; - double prevHigh4 = i >= length + 2 ? highList[i - (length + 2)] : 0; - double prevHigh5 = i >= length + 3 ? highList[i - (length + 3)] : 0; - double prevHigh6 = i >= length + 4 ? highList[i - (length + 4)] : 0; - double prevHigh7 = i >= length + 5 ? highList[i - (length + 5)] : 0; - double prevHigh8 = i >= length + 8 ? highList[i - (length + 6)] : 0; - double prevLow = i >= length - 2 ? lowList[i - (length - 2)] : 0; - double prevLow1 = i >= length - 1 ? lowList[i - (length - 1)] : 0; - double prevLow2 = i >= length ? lowList[i - length] : 0; - double prevLow3 = i >= length + 1 ? lowList[i - (length + 1)] : 0; - double prevLow4 = i >= length + 2 ? lowList[i - (length + 2)] : 0; - double prevLow5 = i >= length + 3 ? lowList[i - (length + 3)] : 0; - double prevLow6 = i >= length + 4 ? lowList[i - (length + 4)] : 0; - double prevLow7 = i >= length + 5 ? lowList[i - (length + 5)] : 0; - double prevLow8 = i >= length + 8 ? lowList[i - (length + 6)] : 0; - - double prevUpFractal = upFractalList.LastOrDefault(); + for (var i = 0; i < stockData.Count; i++) + { + var prevHigh = i >= length - 2 ? highList[i - (length - 2)] : 0; + var prevHigh1 = i >= length - 1 ? highList[i - (length - 1)] : 0; + var prevHigh2 = i >= length ? highList[i - length] : 0; + var prevHigh3 = i >= length + 1 ? highList[i - (length + 1)] : 0; + var prevHigh4 = i >= length + 2 ? highList[i - (length + 2)] : 0; + var prevHigh5 = i >= length + 3 ? highList[i - (length + 3)] : 0; + var prevHigh6 = i >= length + 4 ? highList[i - (length + 4)] : 0; + var prevHigh7 = i >= length + 5 ? highList[i - (length + 5)] : 0; + var prevHigh8 = i >= length + 8 ? highList[i - (length + 6)] : 0; + var prevLow = i >= length - 2 ? lowList[i - (length - 2)] : 0; + var prevLow1 = i >= length - 1 ? lowList[i - (length - 1)] : 0; + var prevLow2 = i >= length ? lowList[i - length] : 0; + var prevLow3 = i >= length + 1 ? lowList[i - (length + 1)] : 0; + var prevLow4 = i >= length + 2 ? lowList[i - (length + 2)] : 0; + var prevLow5 = i >= length + 3 ? lowList[i - (length + 3)] : 0; + var prevLow6 = i >= length + 4 ? lowList[i - (length + 4)] : 0; + var prevLow7 = i >= length + 5 ? lowList[i - (length + 5)] : 0; + var prevLow8 = i >= length + 8 ? lowList[i - (length + 6)] : 0; + + var prevUpFractal = upFractalList.LastOrDefault(); double upFractal = (prevHigh4 < prevHigh2 && prevHigh3 < prevHigh2 && prevHigh1 < prevHigh2 && prevHigh < prevHigh2) || (prevHigh5 < prevHigh2 && prevHigh4 < prevHigh2 && prevHigh3 == prevHigh2 && prevHigh1 < prevHigh2) || (prevHigh6 < prevHigh2 && prevHigh5 < prevHigh2 && prevHigh4 == prevHigh2 && prevHigh3 <= prevHigh2 && prevHigh1 < prevHigh2 && @@ -2270,7 +2270,7 @@ public static StockData CalculateWilliamsFractals(this StockData stockData, int prevHigh < prevHigh2) ? 1 : 0; upFractalList.AddRounded(upFractal); - double prevDnFractal = dnFractalList.LastOrDefault(); + var prevDnFractal = dnFractalList.LastOrDefault(); double dnFractal = (prevLow4 > prevLow2 && prevLow3 > prevLow2 && prevLow1 > prevLow2 && prevLow > prevLow2) || (prevLow5 > prevLow2 && prevLow4 > prevLow2 && prevLow3 == prevLow2 && prevLow1 > prevLow2 && prevLow > prevLow2) || (prevLow6 > prevLow2 && prevLow5 > prevLow2 && prevLow4 == prevLow2 && prevLow3 >= prevLow2 && prevLow1 > prevLow2 && prevLow > prevLow2) || @@ -2306,15 +2306,15 @@ public static StockData CalculateWilliamsAccumulationDistribution(this StockData List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; + var close = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevWad = wadList.LastOrDefault(); - double wad = close > prevClose ? prevWad + close - prevLow : close < prevClose ? prevWad + close - prevHigh : 0; + var prevWad = wadList.LastOrDefault(); + var wad = close > prevClose ? prevWad + close - prevLow : close < prevClose ? prevWad + close - prevHigh : 0; wadList.AddRounded(wad); var signal = GetCompareSignal(wad, prevWad); @@ -2347,22 +2347,22 @@ public static StockData CalculateWamiOscillator(this StockData stockData, Moving List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double diff = MinPastValues(i, 1, currentValue - prevValue); + var diff = MinPastValues(i, 1, currentValue - prevValue); diffList.AddRounded(diff); } var wma1List = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, length2, diffList); var ema2List = GetMovingAverageList(stockData, maType, length1, wma1List); var wamiList = GetMovingAverageList(stockData, maType, length1, ema2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wami = wamiList[i]; - double prevWami = i >= 1 ? wamiList[i - 1] : 0; + var wami = wamiList[i]; + var prevWami = i >= 1 ? wamiList[i - 1] : 0; var signal = GetCompareSignal(wami, prevWami); signalsList.Add(signal); @@ -2405,15 +2405,15 @@ public static StockData CalculateWaddahAttarExplosion(this StockData stockData, var upperBollingerBandList = bbList.OutputValues["UpperBand"]; var lowerBollingerBandList = bbList.OutputValues["LowerBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; temp1List.AddRounded(prevValue1); - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; temp2List.AddRounded(prevValue2); - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; temp3List.AddRounded(prevValue3); } @@ -2423,30 +2423,30 @@ public static StockData CalculateWaddahAttarExplosion(this StockData stockData, var macd3List = CalculateMovingAverageConvergenceDivergence(stockData, fastLength: fastLength, slowLength: slowLength).CustomValuesList; stockData.CustomValuesList = temp3List; var macd4List = CalculateMovingAverageConvergenceDivergence(stockData, fastLength: fastLength, slowLength: slowLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentMacd1 = macd1List[i]; - double currentMacd2 = macd2List[i]; - double currentMacd3 = macd3List[i]; - double currentMacd4 = macd4List[i]; - double currentUpperBB = upperBollingerBandList[i]; - double currentLowerBB = lowerBollingerBandList[i]; + var currentMacd1 = macd1List[i]; + var currentMacd2 = macd2List[i]; + var currentMacd3 = macd3List[i]; + var currentMacd4 = macd4List[i]; + var currentUpperBB = upperBollingerBandList[i]; + var currentLowerBB = lowerBollingerBandList[i]; - double t1 = (currentMacd1 - currentMacd2) * sensitivity; + var t1 = (currentMacd1 - currentMacd2) * sensitivity; t1List.AddRounded(t1); - double t2 = (currentMacd3 - currentMacd4) * sensitivity; + var t2 = (currentMacd3 - currentMacd4) * sensitivity; t2List.AddRounded(t2); - double prevE1 = e1List.LastOrDefault(); - double e1 = currentUpperBB - currentLowerBB; + var prevE1 = e1List.LastOrDefault(); + var e1 = currentUpperBB - currentLowerBB; e1List.AddRounded(e1); - double prevTrendUp = trendUpList.LastOrDefault(); - double trendUp = (t1 >= 0) ? t1 : 0; + var prevTrendUp = trendUpList.LastOrDefault(); + var trendUp = (t1 >= 0) ? t1 : 0; trendUpList.AddRounded(trendUp); - double trendDown = (t1 < 0) ? (-1 * t1) : 0; + var trendDown = (t1 < 0) ? (-1 * t1) : 0; trendDnList.AddRounded(trendDown); var signal = GetConditionSignal(trendUp > prevTrendUp && trendUp > e1 && e1 > prevE1 && trendUp > fastLength && e1 > fastLength, @@ -2488,33 +2488,33 @@ public static StockData CalculateQuantitativeQualitativeEstimation(this StockDat List slowAtrRsiList = new(); List signalsList = new(); - int wildersLength = (length * 2) - 1; + var wildersLength = (length * 2) - 1; var rsiValueList = CalculateRelativeStrengthIndex(stockData, maType, length, smoothLength); var rsiEmaList = rsiValueList.OutputValues["Signal"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRsiEma = rsiEmaList[i]; - double prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; + var currentRsiEma = rsiEmaList[i]; + var prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; - double atrRsi = Math.Abs(currentRsiEma - prevRsiEma); + var atrRsi = Math.Abs(currentRsiEma - prevRsiEma); atrRsiList.AddRounded(atrRsi); } var atrRsiEmaList = GetMovingAverageList(stockData, maType, wildersLength, atrRsiList); var atrRsiEmaSmoothList = GetMovingAverageList(stockData, maType, wildersLength, atrRsiEmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double atrRsiEmaSmooth = atrRsiEmaSmoothList[i]; - double prevAtrRsiEmaSmooth = i >= 1 ? atrRsiEmaSmoothList[i - 1] : 0; + var atrRsiEmaSmooth = atrRsiEmaSmoothList[i]; + var prevAtrRsiEmaSmooth = i >= 1 ? atrRsiEmaSmoothList[i - 1] : 0; - double prevFastTl = fastAtrRsiList.LastOrDefault(); - double fastTl = atrRsiEmaSmooth * fastFactor; + var prevFastTl = fastAtrRsiList.LastOrDefault(); + var fastTl = atrRsiEmaSmooth * fastFactor; fastAtrRsiList.AddRounded(fastTl); - double prevSlowTl = slowAtrRsiList.LastOrDefault(); - double slowTl = atrRsiEmaSmooth * slowFactor; + var prevSlowTl = slowAtrRsiList.LastOrDefault(); + var slowTl = atrRsiEmaSmooth * slowFactor; slowAtrRsiList.AddRounded(slowTl); var signal = GetBullishBearishSignal(atrRsiEmaSmooth - Math.Max(fastTl, slowTl), prevAtrRsiEmaSmooth - Math.Max(prevFastTl, prevSlowTl), @@ -2551,13 +2551,13 @@ public static StockData CalculateQuasiWhiteNoise(this StockData stockData, Movin List signalsList = new(); var connorsRsiList = CalculateConnorsRelativeStrengthIndex(stockData, maType, noiseLength, noiseLength, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double connorsRsi = connorsRsiList[i]; - double prevConnorsRsi1 = i >= 1 ? connorsRsiList[i - 1] : 0; - double prevConnorsRsi2 = i >= 2 ? connorsRsiList[i - 2] : 0; + var connorsRsi = connorsRsiList[i]; + var prevConnorsRsi1 = i >= 1 ? connorsRsiList[i - 1] : 0; + var prevConnorsRsi2 = i >= 2 ? connorsRsiList[i - 2] : 0; - double whiteNoise = (connorsRsi - 50) * (1 / divisor); + var whiteNoise = (connorsRsi - 50) * (1 / divisor); whiteNoiseList.AddRounded(whiteNoise); var signal = GetRsiSignal(connorsRsi - prevConnorsRsi1, prevConnorsRsi1 - prevConnorsRsi2, connorsRsi, prevConnorsRsi1, 70, 30); @@ -2567,11 +2567,11 @@ public static StockData CalculateQuasiWhiteNoise(this StockData stockData, Movin var whiteNoiseSmaList = GetMovingAverageList(stockData, maType, noiseLength, whiteNoiseList); stockData.CustomValuesList = whiteNoiseList; var whiteNoiseStdDevList = CalculateStandardDeviationVolatility(stockData, maType, noiseLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double whiteNoiseStdDev = whiteNoiseStdDevList[i]; + var whiteNoiseStdDev = whiteNoiseStdDevList[i]; - double whiteNoiseVariance = Pow(whiteNoiseStdDev, 2); + var whiteNoiseVariance = Pow(whiteNoiseStdDev, 2); whiteNoiseVarianceList.AddRounded(whiteNoiseVariance); } @@ -2610,23 +2610,23 @@ public static StockData CalculateLBRPaintBars(this StockData stockData, MovingAv var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double currentAtr = atrList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var currentAtr = atrList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double aatr = atrMult * currentAtr; + var aatr = atrMult * currentAtr; aatrList.AddRounded(aatr); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = lowest + aatr; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = lowest + aatr; lowerBandList.AddRounded(lowerBand); - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = highest - aatr; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = highest - aatr; upperBandList.AddRounded(upperBand); var signal = GetBullishBearishSignal(currentValue - Math.Max(lowerBand, upperBand), prevValue - Math.Max(prevLowerBand, prevUpperBand), @@ -2665,24 +2665,24 @@ public static StockData CalculateLinearQuadraticConvergenceDivergenceOscillator( var linregList = CalculateLinearRegression(stockData, length).CustomValuesList; var yList = CalculateQuadraticRegression(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double linreg = linregList[i]; - double y = yList[i]; + var linreg = linregList[i]; + var y = yList[i]; - double lqcd = y - linreg; + var lqcd = y - linreg; lqcdList.AddRounded(lqcd); } var signList = GetMovingAverageList(stockData, maType, signalLength, lqcdList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sign = signList[i]; - double lqcd = lqcdList[i]; - double osc = lqcd - sign; + var sign = signList[i]; + var lqcd = lqcdList[i]; + var osc = lqcd - sign; - double prevHist = histList.LastOrDefault(); - double hist = osc - sign; + var prevHist = histList.LastOrDefault(); + var hist = osc - sign; histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); @@ -2716,9 +2716,9 @@ public static StockData CalculateLogisticCorrelation(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); double index = i; @@ -2729,13 +2729,13 @@ public static StockData CalculateLogisticCorrelation(this StockData stockData, i corrList.AddRounded((double)corr); } - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double corr = corrList[i]; - double prevLog1 = i >= 1 ? logList[i - 1] : 0; - double prevLog2 = i >= 2 ? logList[i - 2] : 0; + var corr = corrList[i]; + var prevLog1 = i >= 1 ? logList[i - 1] : 0; + var prevLog2 = i >= 2 ? logList[i - 2] : 0; - double log = 1 / (1 + Exp(k * -corr)); + var log = 1 / (1 + Exp(k * -corr)); logList.AddRounded(log); var signal = GetCompareSignal(log - prevLog1, prevLog1 - prevLog2); @@ -2775,32 +2775,32 @@ public static StockData CalculateLindaRaschke3_10Oscillator(this StockData stock var fastSmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowSmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma3 = fastSmaList[i]; - double sma10 = slowSmaList[i]; + var sma3 = fastSmaList[i]; + var sma10 = slowSmaList[i]; - double ppo = sma10 != 0 ? (sma3 - sma10) / sma10 * 100 : 0; + var ppo = sma10 != 0 ? (sma3 - sma10) / sma10 * 100 : 0; ppoList.AddRounded(ppo); - double macd = sma3 - sma10; + var macd = sma3 - sma10; macdList.AddRounded(macd); } var macdSignalLineList = GetMovingAverageList(stockData, maType, smoothLength, macdList); var ppoSignalLineList = GetMovingAverageList(stockData, maType, smoothLength, ppoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo = ppoList[i]; - double ppoSignalLine = ppoSignalLineList[i]; - double macd = macdList[i]; - double macdSignalLine = macdSignalLineList[i]; + var ppo = ppoList[i]; + var ppoSignalLine = ppoSignalLineList[i]; + var macd = macdList[i]; + var macdSignalLine = macdSignalLineList[i]; - double ppoHistogram = ppo - ppoSignalLine; + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); - double prevMacdHistogram = macdHistogramList.LastOrDefault(); - double macdHistogram = macd - macdSignalLine; + var prevMacdHistogram = macdHistogramList.LastOrDefault(); + var macdHistogram = macd - macdSignalLine; macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); @@ -2842,30 +2842,30 @@ public static StockData CalculateRelativeVolatilityIndexV1(this StockData stockD var stdDeviationList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentStdDeviation = stdDeviationList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentStdDeviation = stdDeviationList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double up = currentValue > prevValue ? currentStdDeviation : 0; + var up = currentValue > prevValue ? currentStdDeviation : 0; upList.AddRounded(up); - double down = currentValue < prevValue ? currentStdDeviation : 0; + var down = currentValue < prevValue ? currentStdDeviation : 0; downList.AddRounded(down); } var upAvgList = GetMovingAverageList(stockData, maType, smoothLength, upList); var downAvgList = GetMovingAverageList(stockData, maType, smoothLength, downList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double avgUp = upAvgList[i]; - double avgDown = downAvgList[i]; - double prevRvi1 = i >= 1 ? rviOriginalList[i - 1] : 0; - double prevRvi2 = i >= 2 ? rviOriginalList[i - 2] : 0; - double rs = avgDown != 0 ? avgUp / avgDown : 0; + var avgUp = upAvgList[i]; + var avgDown = downAvgList[i]; + var prevRvi1 = i >= 1 ? rviOriginalList[i - 1] : 0; + var prevRvi2 = i >= 2 ? rviOriginalList[i - 2] : 0; + var rs = avgDown != 0 ? avgUp / avgDown : 0; - double rvi = avgDown == 0 ? 100 : avgUp == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rvi = avgDown == 0 ? 100 : avgUp == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rviOriginalList.AddRounded(rvi); var signal = GetRsiSignal(rvi - prevRvi1, prevRvi1 - prevRvi2, rvi, prevRvi1, 70, 30); @@ -2903,14 +2903,14 @@ public static StockData CalculateRelativeVolatilityIndexV2(this StockData stockD stockData.CustomValuesList = lowList; var rviLowList = CalculateRelativeVolatilityIndexV1(stockData, maType, length, smoothLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rviOriginalHigh = rviHighList[i]; - double rviOriginalLow = rviLowList[i]; - double prevRvi1 = i >= 1 ? rviList[i - 1] : 0; - double prevRvi2 = i >= 2 ? rviList[i - 2] : 0; + var rviOriginalHigh = rviHighList[i]; + var rviOriginalLow = rviLowList[i]; + var prevRvi1 = i >= 1 ? rviList[i - 1] : 0; + var prevRvi2 = i >= 2 ? rviList[i - 2] : 0; - double rvi = (rviOriginalHigh + rviOriginalLow) / 2; + var rvi = (rviOriginalHigh + rviOriginalLow) / 2; rviList.AddRounded(rvi); var signal = GetRsiSignal(rvi - prevRvi1, prevRvi1 - prevRvi2, rvi, prevRvi1, 70, 30); @@ -2943,11 +2943,11 @@ public static StockData CalculateInertiaIndicator(this StockData stockData, Movi var rviList = CalculateRelativeVolatilityIndexV2(stockData).CustomValuesList; var inertiaList = GetMovingAverageList(stockData, maType, length, rviList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double inertiaIndicator = inertiaList[i]; - double prevInertiaIndicator1 = i >= 1 ? inertiaList[i - 1] : 0; - double prevInertiaIndicator2 = i >= 2 ? inertiaList[i - 2] : 0; + var inertiaIndicator = inertiaList[i]; + var prevInertiaIndicator1 = i >= 1 ? inertiaList[i - 1] : 0; + var prevInertiaIndicator2 = i >= 2 ? inertiaList[i - 2] : 0; var signal = GetCompareSignal(inertiaIndicator - prevInertiaIndicator1, prevInertiaIndicator1 - prevInertiaIndicator2); signalsList.Add(signal); @@ -2979,21 +2979,21 @@ public static StockData CalculateInternalBarStrengthIndicator(this StockData sto List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double high = highList[i]; - double low = lowList[i]; + var close = inputList[i]; + var high = highList[i]; + var low = lowList[i]; - double ibs = high - low != 0 ? (close - low) / (high - low) * 100 : 0; + var ibs = high - low != 0 ? (close - low) / (high - low) * 100 : 0; ibsList.AddRounded(ibs); - double prevIbsi = ibsiList.LastOrDefault(); - double ibsi = ibsList.TakeLastExt(length).Average(); + var prevIbsi = ibsiList.LastOrDefault(); + var ibsi = ibsList.TakeLastExt(length).Average(); ibsiList.AddRounded(ibsi); - double prevIbsiEma = ibsEmaList.LastOrDefault(); - double ibsiEma = CalculateEMA(ibsi, prevIbsiEma, smoothLength); + var prevIbsiEma = ibsEmaList.LastOrDefault(); + var ibsiEma = CalculateEMA(ibsi, prevIbsiEma, smoothLength); ibsEmaList.AddRounded(ibsiEma); var signal = GetRsiSignal(ibsi - ibsiEma, prevIbsi - prevIbsiEma, ibsi, prevIbsi, 70, 30); @@ -3026,7 +3026,7 @@ public static StockData CalculateInverseFisherFastZScore(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); + var length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); var smaList = GetMovingAverageList(stockData, maType, length, inputList); stockData.CustomValuesList = smaList; @@ -3036,16 +3036,16 @@ public static StockData CalculateInverseFisherFastZScore(this StockData stockDat stockData.CustomValuesList = smaList; var linreg2List = CalculateLinearRegression(stockData, length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double linreg1 = linreg1List[i]; - double linreg2 = linreg2List[i]; - double stdDev = stdDevList[i]; - double fz = stdDev != 0 ? (linreg2 - linreg1) / stdDev / 2 : 0; - double prevIfz1 = i >= 1 ? ifzList[i - 1] : 0; - double prevIfz2 = i >= 2 ? ifzList[i - 2] : 0; + var linreg1 = linreg1List[i]; + var linreg2 = linreg2List[i]; + var stdDev = stdDevList[i]; + var fz = stdDev != 0 ? (linreg2 - linreg1) / stdDev / 2 : 0; + var prevIfz1 = i >= 1 ? ifzList[i - 1] : 0; + var prevIfz2 = i >= 2 ? ifzList[i - 2] : 0; - double ifz = Exp(10 * fz) + 1 != 0 ? (Exp(10 * fz) - 1) / (Exp(10 * fz) + 1) : 0; + var ifz = Exp(10 * fz) + 1 != 0 ? (Exp(10 * fz) - 1) / (Exp(10 * fz) + 1) : 0; ifzList.AddRounded(ifz); var signal = GetCompareSignal(ifz - prevIfz1, prevIfz1 - prevIfz2); @@ -3080,17 +3080,17 @@ public static StockData CalculateInverseFisherZScore(this StockData stockData, M var smaList = GetMovingAverageList(stockData, maType, length, inputList); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double stdDev = stdDevList[i]; - double prevF1 = i >= 1 ? fList[i - 1] : 0; - double prevF2 = i >= 2 ? fList[i - 2] : 0; - double z = stdDev != 0 ? (currentValue - sma) / stdDev : 0; - double expZ = Exp(2 * z); + var currentValue = inputList[i]; + var sma = smaList[i]; + var stdDev = stdDevList[i]; + var prevF1 = i >= 1 ? fList[i - 1] : 0; + var prevF2 = i >= 2 ? fList[i - 2] : 0; + var z = stdDev != 0 ? (currentValue - sma) / stdDev : 0; + var expZ = Exp(2 * z); - double f = expZ + 1 != 0 ? MinOrMax((((expZ - 1) / (expZ + 1)) + 1) * 50, 100, 0) : 0; + var f = expZ + 1 != 0 ? MinOrMax((((expZ - 1) / (expZ + 1)) + 1) * 50, 100, 0) : 0; fList.AddRounded(f); var signal = GetRsiSignal(f - prevF1, prevF1 - prevF2, f, prevF1, 80, 20); @@ -3158,60 +3158,60 @@ public static StockData CalculateInsyncIndex(this StockData stockData, MovingAvg var stochDList = stochasticList.OutputValues["SlowD"]; var emvList = CalculateEaseOfMovement(stockData, length: emoLength, divisor: divisor).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double bolins2 = bbIndicatorList[i]; - double prevPdoinss10 = i >= smaLength ? pdoinssList[i - smaLength] : 0; - double prevPdoinsb10 = i >= smaLength ? pdoinsbList[i - smaLength] : 0; - double cci = cciList[i]; - double mfi = mfiList[i]; - double rsi = rsiList[i]; - double stochD = stochDList[i]; - double stochK = stochKList[i]; - double prevIidx1 = i >= 1 ? iidxList[i - 1] : 0; - double prevIidx2 = i >= 2 ? iidxList[i - 2] : 0; + for (var i = 0; i < stockData.Count; i++) + { + var bolins2 = bbIndicatorList[i]; + var prevPdoinss10 = i >= smaLength ? pdoinssList[i - smaLength] : 0; + var prevPdoinsb10 = i >= smaLength ? pdoinsbList[i - smaLength] : 0; + var cci = cciList[i]; + var mfi = mfiList[i]; + var rsi = rsiList[i]; + var stochD = stochDList[i]; + var stochK = stochKList[i]; + var prevIidx1 = i >= 1 ? iidxList[i - 1] : 0; + var prevIidx2 = i >= 2 ? iidxList[i - 2] : 0; double bolinsll = bolins2 < 0.05 ? -5 : bolins2 > 0.95 ? 5 : 0; double cciins = cci > 100 ? 5 : cci < -100 ? -5 : 0; - double emo = emvList[i]; + var emo = emvList[i]; emoList.AddRounded(emo); - double emoSma = emoList.TakeLastExt(smaLength).Average(); + var emoSma = emoList.TakeLastExt(smaLength).Average(); emoSmaList.AddRounded(emoSma); - double emvins2 = emo - emoSma; + var emvins2 = emo - emoSma; double emvinsb = emvins2 < 0 ? emoSma < 0 ? -5 : 0 : emoSma > 0 ? 5 : 0; - double macd = macdList[i]; + var macd = macdList[i]; tempMacdList.AddRounded(macd); - double macdSma = tempMacdList.TakeLastExt(smaLength).Average(); - double macdins2 = macd - macdSma; + var macdSma = tempMacdList.TakeLastExt(smaLength).Average(); + var macdins2 = macd - macdSma; double macdinsb = macdins2 < 0 ? macdSma < 0 ? -5 : 0 : macdSma > 0 ? 5 : 0; double mfiins = mfi > 80 ? 5 : mfi < 20 ? -5 : 0; - double dpo = dpoList[i]; + var dpo = dpoList[i]; tempDpoList.AddRounded(dpo); - double dpoSma = tempDpoList.TakeLastExt(smaLength).Average(); - double pdoins2 = dpo - dpoSma; + var dpoSma = tempDpoList.TakeLastExt(smaLength).Average(); + var pdoins2 = dpo - dpoSma; double pdoinsb = pdoins2 < 0 ? dpoSma < 0 ? -5 : 0 : dpoSma > 0 ? 5 : 0; pdoinsbList.AddRounded(pdoinsb); double pdoinss = pdoins2 > 0 ? dpoSma > 0 ? 5 : 0 : dpoSma < 0 ? -5 : 0; pdoinssList.AddRounded(pdoinss); - double roc = rocList[i]; + var roc = rocList[i]; tempRocList.AddRounded(roc); - double rocSma = tempRocList.TakeLastExt(smaLength).Average(); - double rocins2 = roc - rocSma; + var rocSma = tempRocList.TakeLastExt(smaLength).Average(); + var rocins2 = roc - rocSma; double rocinsb = rocins2 < 0 ? rocSma < 0 ? -5 : 0 : rocSma > 0 ? 5 : 0; double rsiins = rsi > 70 ? 5 : rsi < 30 ? -5 : 0; double stopdins = stochD > 80 ? 5 : stochD < 20 ? -5 : 0; double stopkins = stochK > 80 ? 5 : stochK < 20 ? -5 : 0; - double iidx = 50 + cciins + bolinsll + rsiins + stopkins + stopdins + mfiins + emvinsb + rocinsb + prevPdoinss10 + prevPdoinsb10 + macdinsb; + var iidx = 50 + cciins + bolinsll + rsiins + stopkins + stopdins + mfiins + emvinsb + rocinsb + prevPdoinss10 + prevPdoinsb10 + macdinsb; iidxList.AddRounded(iidx); var signal = GetRsiSignal(iidx - prevIidx1, prevIidx1 - prevIidx2, iidx, prevIidx1, 95, 5); @@ -3243,17 +3243,17 @@ public static StockData CalculateDetrendedPriceOscillator(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int prevPeriods = MinOrMax((int)Math.Ceiling(((double)length / 2) + 1)); + var prevPeriods = MinOrMax((int)Math.Ceiling(((double)length / 2) + 1)); var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentSma = smaList[i]; - double prevValue = i >= prevPeriods ? inputList[i - prevPeriods] : 0; + var currentSma = smaList[i]; + var prevValue = i >= prevPeriods ? inputList[i - prevPeriods] : 0; - double prevDpo = dpoList.LastOrDefault(); - double dpo = prevValue - currentSma; + var prevDpo = dpoList.LastOrDefault(); + var dpo = prevValue - currentSma; dpoList.AddRounded(dpo); var signal = GetCompareSignal(dpo, prevDpo); @@ -3286,24 +3286,24 @@ public static StockData CalculateOceanIndicator(this StockData stockData, Moving List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevLn = i >= length ? lnList[i - length] : 0; + var currentValue = inputList[i]; + var prevLn = i >= length ? lnList[i - length] : 0; - double ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; + var ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; lnList.AddRounded(ln); - double oi = (ln - prevLn) / Sqrt(length) * 100; + var oi = (ln - prevLn) / Sqrt(length) * 100; oiList.AddRounded(oi); } var oiEmaList = GetMovingAverageList(stockData, maType, length, oiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double oiEma = oiEmaList[i]; - double prevOiEma1 = i >= 1 ? oiEmaList[i - 1] : 0; - double prevOiEma2 = i >= 2 ? oiEmaList[i - 2] : 0; + var oiEma = oiEmaList[i]; + var prevOiEma1 = i >= 1 ? oiEmaList[i - 1] : 0; + var prevOiEma2 = i >= 2 ? oiEmaList[i - 2] : 0; var signal = GetCompareSignal(oiEma - prevOiEma1, prevOiEma1 - prevOiEma2); signalsList.Add(signal); @@ -3334,16 +3334,16 @@ public static StockData CalculateOscarIndicator(this StockData stockData, int le var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double rough = highest - lowest != 0 ? MinOrMax((currentValue - lowest) / (highest - lowest) * 100, 100, 0) : 0; - double prevOscar1 = i >= 1 ? oscarList[i - 1] : 0; - double prevOscar2 = i >= 2 ? oscarList[i - 2] : 0; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var rough = highest - lowest != 0 ? MinOrMax((currentValue - lowest) / (highest - lowest) * 100, 100, 0) : 0; + var prevOscar1 = i >= 1 ? oscarList[i - 1] : 0; + var prevOscar2 = i >= 2 ? oscarList[i - 2] : 0; - double oscar = (prevOscar1 / 6) + (rough / 3); + var oscar = (prevOscar1 / 6) + (rough / 3); oscarList.AddRounded(oscar); var signal = GetRsiSignal(oscar - prevOscar1, prevOscar1 - prevOscar2, oscar, prevOscar1, 80, 20); @@ -3378,13 +3378,13 @@ public static StockData CalculateOCHistogram(this StockData stockData, MovingAvg var openEmaList = GetMovingAverageList(stockData, maType, length, openList); var closeEmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentCloseEma = closeEmaList[i]; - double currentOpenEma = openEmaList[i]; + var currentCloseEma = closeEmaList[i]; + var currentOpenEma = openEmaList[i]; - double prevOcHistogram = ocHistogramList.LastOrDefault(); - double ocHistogram = currentCloseEma - currentOpenEma; + var prevOcHistogram = ocHistogramList.LastOrDefault(); + var ocHistogram = currentCloseEma - currentOpenEma; ocHistogramList.AddRounded(ocHistogram); var signal = GetCompareSignal(ocHistogram, prevOcHistogram); @@ -3420,14 +3420,14 @@ public static StockData CalculateOscOscillator(this StockData stockData, MovingA var fastSmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowSmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastSma = fastSmaList[i]; - double slowSma = slowSmaList[i]; - double prevOsc1 = i >= 1 ? oscList[i - 1] : 0; - double prevOsc2 = i >= 2 ? oscList[i - 2] : 0; + var fastSma = fastSmaList[i]; + var slowSma = slowSmaList[i]; + var prevOsc1 = i >= 1 ? oscList[i - 1] : 0; + var prevOsc2 = i >= 2 ? oscList[i - 2] : 0; - double osc = slowSma - fastSma; + var osc = slowSma - fastSma; oscList.AddRounded(osc); var signal = GetCompareSignal(osc - prevOsc1, prevOsc1 - prevOsc2); @@ -3462,15 +3462,15 @@ public static StockData CalculateNaturalDirectionalCombo(this StockData stockDat var ndxList = CalculateNaturalDirectionalIndex(stockData, maType, length, smoothLength).CustomValuesList; var nstList = CalculateNaturalStochasticIndicator(stockData, maType, length, smoothLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ndx = ndxList[i]; - double nst = nstList[i]; - double prevNxc1 = i >= 1 ? nxcList[i - 1] : 0; - double prevNxc2 = i >= 2 ? nxcList[i - 2] : 0; - double v3 = Math.Sign(ndx) != Math.Sign(nst) ? ndx * nst : ((Math.Abs(ndx) * nst) + (Math.Abs(nst) * ndx)) / 2; + var ndx = ndxList[i]; + var nst = nstList[i]; + var prevNxc1 = i >= 1 ? nxcList[i - 1] : 0; + var prevNxc2 = i >= 2 ? nxcList[i - 2] : 0; + var v3 = Math.Sign(ndx) != Math.Sign(nst) ? ndx * nst : ((Math.Abs(ndx) * nst) + (Math.Abs(nst) * ndx)) / 2; - double nxc = Math.Sign(v3) * Sqrt(Math.Abs(v3)); + var nxc = Math.Sign(v3) * Sqrt(Math.Abs(v3)); nxcList.AddRounded(nxc); var signal = GetCompareSignal(nxc - prevNxc1, prevNxc1 - prevNxc2); @@ -3504,36 +3504,36 @@ public static StockData CalculateNaturalDirectionalIndex(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; + var ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; lnList.AddRounded(ln); double weightSum = 0, denomSum = 0, absSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; - double currLn = i >= j ? lnList[i - j] : 0; - double diff = prevLn - currLn; + var prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; + var currLn = i >= j ? lnList[i - j] : 0; + var diff = prevLn - currLn; absSum += Math.Abs(diff); - double frac = absSum != 0 ? (ln - currLn) / absSum : 0; - double ratio = 1 / Sqrt(j + 1); + var frac = absSum != 0 ? (ln - currLn) / absSum : 0; + var ratio = 1 / Sqrt(j + 1); weightSum += frac * ratio; denomSum += ratio; } - double rawNdx = denomSum != 0 ? weightSum / denomSum * 100 : 0; + var rawNdx = denomSum != 0 ? weightSum / denomSum * 100 : 0; rawNdxList.AddRounded(rawNdx); } var ndxList = GetMovingAverageList(stockData, maType, smoothLength, rawNdxList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ndx = ndxList[i]; - double prevNdx1 = i >= 1 ? ndxList[i - 1] : 0; - double prevNdx2 = i >= 2 ? ndxList[i - 2] : 0; + var ndx = ndxList[i]; + var prevNdx1 = i >= 1 ? ndxList[i - 1] : 0; + var prevNdx2 = i >= 2 ? ndxList[i - 2] : 0; var signal = GetCompareSignal(ndx - prevNdx1, prevNdx1 - prevNdx2); signalsList.Add(signal); @@ -3565,30 +3565,30 @@ public static StockData CalculateNaturalMarketMirror(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; + var ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; lnList.AddRounded(ln); double oiSum = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevLn = i >= j ? lnList[i - j] : 0; + var prevLn = i >= j ? lnList[i - j] : 0; oiSum += (ln - prevLn) / Sqrt(j) * 100; } - double oiAvg = oiSum / length; + var oiAvg = oiSum / length; oiAvgList.AddRounded(oiAvg); } var nmmList = GetMovingAverageList(stockData, maType, length, oiAvgList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nmm = nmmList[i]; - double prevNmm1 = i >= 1 ? nmmList[i - 1] : 0; - double prevNmm2 = i >= 2 ? nmmList[i - 2] : 0; + var nmm = nmmList[i]; + var prevNmm1 = i >= 1 ? nmmList[i - 1] : 0; + var prevNmm2 = i >= 2 ? nmmList[i - 2] : 0; var signal = GetCompareSignal(nmm - prevNmm1, prevNmm1 - prevNmm2); signalsList.Add(signal); @@ -3620,18 +3620,18 @@ public static StockData CalculateNaturalMarketRiver(this StockData stockData, Mo List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; + var ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; lnList.AddRounded(ln); double oiSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double currentLn = i >= j ? lnList[i - j] : 0; - double prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; + var currentLn = i >= j ? lnList[i - j] : 0; + var prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; oiSum += (prevLn - currentLn) * (Sqrt(j) - Sqrt(j + 1)); } @@ -3639,11 +3639,11 @@ public static StockData CalculateNaturalMarketRiver(this StockData stockData, Mo } var nmrList = GetMovingAverageList(stockData, maType, length, oiSumList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nmr = nmrList[i]; - double prevNmr1 = i >= 1 ? nmrList[i - 1] : 0; - double prevNmr2 = i >= 2 ? nmrList[i - 2] : 0; + var nmr = nmrList[i]; + var prevNmr1 = i >= 1 ? nmrList[i - 1] : 0; + var prevNmr2 = i >= 2 ? nmrList[i - 2] : 0; var signal = GetCompareSignal(nmr - prevNmr1, prevNmr1 - prevNmr2); signalsList.Add(signal); @@ -3677,22 +3677,22 @@ public static StockData CalculateNaturalMarketCombo(this StockData stockData, Mo var nmrList = CalculateNaturalMarketRiver(stockData, maType, length).CustomValuesList; var nmmList = CalculateNaturalMarketMirror(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nmr = nmrList[i]; - double nmm = nmmList[i]; - double v3 = Math.Sign(nmm) != Math.Sign(nmr) ? nmm * nmr : ((Math.Abs(nmm) * nmr) + (Math.Abs(nmr) * nmm)) / 2; + var nmr = nmrList[i]; + var nmm = nmmList[i]; + var v3 = Math.Sign(nmm) != Math.Sign(nmr) ? nmm * nmr : ((Math.Abs(nmm) * nmr) + (Math.Abs(nmr) * nmm)) / 2; - double nmc = Math.Sign(v3) * Sqrt(Math.Abs(v3)); + var nmc = Math.Sign(v3) * Sqrt(Math.Abs(v3)); nmcList.AddRounded(nmc); } var nmcMaList = GetMovingAverageList(stockData, maType, smoothLength, nmcList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nmc = nmcMaList[i]; - double prevNmc1 = i >= 1 ? nmcMaList[i - 1] : 0; - double prevNmc2 = i >= 2 ? nmcMaList[i - 2] : 0; + var nmc = nmcMaList[i]; + var prevNmc1 = i >= 1 ? nmcMaList[i - 1] : 0; + var prevNmc2 = i >= 2 ? nmcMaList[i - 2] : 0; var signal = GetCompareSignal(nmc - prevNmc1, prevNmc1 - prevNmc2); signalsList.Add(signal); @@ -3722,24 +3722,24 @@ public static StockData CalculateNaturalMarketSlope(this StockData stockData, in List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; + var ln = currentValue > 0 ? Math.Log(currentValue) * 1000 : 0; lnList.AddRounded(ln); } stockData.CustomValuesList = lnList; var linRegList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double linReg = linRegList[i]; - double prevLinReg = i >= 1 ? linRegList[i - 1] : 0; - double prevNms1 = i >= 1 ? nmsList[i - 1] : 0; - double prevNms2 = i >= 2 ? nmsList[i - 2] : 0; + var linReg = linRegList[i]; + var prevLinReg = i >= 1 ? linRegList[i - 1] : 0; + var prevNms1 = i >= 1 ? nmsList[i - 1] : 0; + var prevNms2 = i >= 2 ? nmsList[i - 2] : 0; - double nms = (linReg - prevLinReg) * Math.Log(length); + var nms = (linReg - prevLinReg) * Math.Log(length); nmsList.AddRounded(nms); var signal = GetCompareSignal(nms - prevNms1, prevNms1 - prevNms2); @@ -3769,18 +3769,18 @@ public static StockData CalculateNarrowBandpassFilter(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevSum1 = i >= 1 ? sumList[i - 1] : 0; - double prevSum2 = i >= 2 ? sumList[i - 2] : 0; + var prevSum1 = i >= 1 ? sumList[i - 1] : 0; + var prevSum2 = i >= 2 ? sumList[i - 2] : 0; double sum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double prevValue = i >= j ? inputList[i - j] : 0; - double x = j / (double)(length - 1); - double win = 0.42 - (0.5 * Math.Cos(2 * Math.PI * x)) + (0.08 * Math.Cos(4 * Math.PI * x)); - double w = Math.Sin(2 * Math.PI * j / length) * win; + var prevValue = i >= j ? inputList[i - j] : 0; + var x = j / (double)(length - 1); + var win = 0.42 - (0.5 * Math.Cos(2 * Math.PI * x)) + (0.08 * Math.Cos(4 * Math.PI * x)); + var w = Math.Sin(2 * Math.PI * j / length) * win; sum += prevValue * w; } sumList.AddRounded(sum); @@ -3813,21 +3813,21 @@ public static StockData CalculateNthOrderDifferencingOscillator(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; double sum = 0, w = 1; - for (int j = 0; j <= lbLength; j++) + for (var j = 0; j <= lbLength; j++) { - double prevValue = i >= length * (j + 1) ? inputList[i - (length * (j + 1))] : 0; + var prevValue = i >= length * (j + 1) ? inputList[i - (length * (j + 1))] : 0; double x = Math.Sign(((j + 1) % 2) - 0.5); w *= (lbLength - j) / (double)(j + 1); sum += prevValue * w * x; } - double prevNodo = nodoList.LastOrDefault(); - double nodo = currentValue - sum; + var prevNodo = nodoList.LastOrDefault(); + var nodo = currentValue - sum; nodoList.AddRounded(nodo); var signal = GetCompareSignal(nodo, prevNodo); @@ -3865,47 +3865,47 @@ public static StockData CalculateNormalizedRelativeVigorIndex(this StockData sto List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double closeOpen = currentClose - currentOpen; + var closeOpen = currentClose - currentOpen; closeOpenList.AddRounded(closeOpen); - double highLow = currentHigh - currentLow; + var highLow = currentHigh - currentLow; highLowList.AddRounded(highLow); } var swmaCloseOpenList = GetMovingAverageList(stockData, maType, length, closeOpenList); var swmaHighLowList = GetMovingAverageList(stockData, maType, length, highLowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double swmaCloseOpen = swmaCloseOpenList[i]; + var swmaCloseOpen = swmaCloseOpenList[i]; tempCloseOpenList.AddRounded(swmaCloseOpen); - double closeOpenSum = tempCloseOpenList.TakeLastExt(length).Sum(); + var closeOpenSum = tempCloseOpenList.TakeLastExt(length).Sum(); swmaCloseOpenSumList.AddRounded(closeOpenSum); - double swmaHighLow = swmaHighLowList[i]; + var swmaHighLow = swmaHighLowList[i]; tempHighLowList.AddRounded(swmaHighLow); - double highLowSum = tempHighLowList.TakeLastExt(length).Sum(); + var highLowSum = tempHighLowList.TakeLastExt(length).Sum(); swmaHighLowSumList.AddRounded(highLowSum); - double rvgi = highLowSum != 0 ? closeOpenSum / highLowSum * 100 : 0; + var rvgi = highLowSum != 0 ? closeOpenSum / highLowSum * 100 : 0; rvgiList.AddRounded(rvgi); } var rvgiSignalList = GetMovingAverageList(stockData, maType, length, rvgiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rvgi = rvgiList[i]; - double rvgiSig = rvgiSignalList[i]; - double prevRvgi = i >= 1 ? rvgiList[i - 1] : 0; - double prevRvgiSig = i >= 1 ? rvgiSignalList[i - 1] : 0; + var rvgi = rvgiList[i]; + var rvgiSig = rvgiSignalList[i]; + var prevRvgi = i >= 1 ? rvgiList[i - 1] : 0; + var prevRvgiSig = i >= 1 ? rvgiSignalList[i - 1] : 0; var signal = GetCompareSignal(rvgi - rvgiSig, prevRvgi - prevRvgiSig); signalsList.Add(signal); @@ -3936,17 +3936,17 @@ public static StockData CalculateGannSwingOscillator(this StockData stockData, i var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevHighest1 = i >= 1 ? highestList[i - 1] : 0; - double prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; - double prevHighest2 = i >= 2 ? highestList[i - 2] : 0; - double prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevHighest1 = i >= 1 ? highestList[i - 1] : 0; + var prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; + var prevHighest2 = i >= 2 ? highestList[i - 2] : 0; + var prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; - double prevGso = gannSwingOscillatorList.LastOrDefault(); - double gso = prevHighest2 > prevHighest1 && highestHigh > prevHighest1 ? 1 : + var prevGso = gannSwingOscillatorList.LastOrDefault(); + var gso = prevHighest2 > prevHighest1 && highestHigh > prevHighest1 ? 1 : prevLowest2 < prevLowest1 && lowestLow < prevLowest1 ? -1 : prevGso; gannSwingOscillatorList.AddRounded(gso); @@ -3982,17 +3982,17 @@ public static StockData CalculateGannHiLoActivator(this StockData stockData, Mov var highMaList = GetMovingAverageList(stockData, maType, length, highList); var lowMaList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highMa = highMaList[i]; - double lowMa = lowMaList[i]; - double prevHighMa = i >= 1 ? highMaList[i - 1] : 0; - double prevLowMa = i >= 1 ? lowMaList[i - 1] : 0; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var highMa = highMaList[i]; + var lowMa = lowMaList[i]; + var prevHighMa = i >= 1 ? highMaList[i - 1] : 0; + var prevLowMa = i >= 1 ? lowMaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevGhla = ghlaList.LastOrDefault(); - double ghla = currentValue > prevHighMa ? lowMa : currentValue < prevLowMa ? highMa : prevGhla; + var prevGhla = ghlaList.LastOrDefault(); + var ghla = currentValue > prevHighMa ? lowMa : currentValue < prevLowMa ? highMa : prevGhla; ghlaList.AddRounded(ghla); var signal = GetCompareSignal(currentValue - ghla, prevValue - prevGhla); @@ -4029,28 +4029,28 @@ public static StockData CalculateGroverLlorensCycleOscillator(this StockData sto var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double atr = atrList[i]; - double prevTs = i >= 1 ? tsList[i - 1] : currentValue; - double diff = currentValue - prevTs; + var currentValue = inputList[i]; + var atr = atrList[i]; + var prevTs = i >= 1 ? tsList[i - 1] : currentValue; + var diff = currentValue - prevTs; - double ts = diff > 0 ? prevTs - (atr * mult) : diff < 0 ? prevTs + (atr * mult) : prevTs; + var ts = diff > 0 ? prevTs - (atr * mult) : diff < 0 ? prevTs + (atr * mult) : prevTs; tsList.AddRounded(ts); - double osc = currentValue - ts; + var osc = currentValue - ts; oscList.AddRounded(osc); } var smoList = GetMovingAverageList(stockData, maType, smoothLength, oscList); stockData.CustomValuesList = smoList; var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length: smoothLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; - double prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; + var rsi = rsiList[i]; + var prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; + var prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; var signal = GetRsiSignal(rsi - prevRsi1, prevRsi1 - prevRsi2, rsi, prevRsi1, 80, 20); signalsList.Add(signal); @@ -4085,19 +4085,19 @@ public static StockData CalculateGroverLlorensActivator(this StockData stockData var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double atr = atrList[i]; - double prevTs = i >= 1 ? tsList[i - 1] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var atr = atrList[i]; + var prevTs = i >= 1 ? tsList[i - 1] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; prevTs = prevTs == 0 ? prevValue : prevTs; - double prevDiff = diffList.LastOrDefault(); - double diff = currentValue - prevTs; + var prevDiff = diffList.LastOrDefault(); + var diff = currentValue - prevTs; diffList.AddRounded(diff); - double ts = diff > 0 ? prevTs - (atr * mult) : diff < 0 ? prevTs + (atr * mult) : prevTs; + var ts = diff > 0 ? prevTs - (atr * mult) : diff < 0 ? prevTs + (atr * mult) : prevTs; tsList.AddRounded(ts); var signal = GetCompareSignal(diff, prevDiff); @@ -4128,26 +4128,26 @@ public static StockData CalculateGuppyCountBackLine(this StockData stockData, in var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double hh = highestList[i]; - double ll = lowestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var hh = highestList[i]; + var ll = lowestList[i]; - double prevCbl = cblList.LastOrDefault(); + var prevCbl = cblList.LastOrDefault(); int hCount = 0, lCount = 0; - double cbl = currentValue; - for (int j = 0; j <= length; j++) + var cbl = currentValue; + for (var j = 0; j <= length; j++) { - double currentLow = i >= j ? lowList[i - j] : 0; - double currentHigh = i >= j ? highList[i - j] : 0; + var currentLow = i >= j ? lowList[i - j] : 0; + var currentHigh = i >= j ? highList[i - j] : 0; if (currentLow == ll) { - for (int k = j + 1; k <= j + length; k++) + for (var k = j + 1; k <= j + length; k++) { - double prevHigh = i >= k ? highList[i - k] : 0; + var prevHigh = i >= k ? highList[i - k] : 0; lCount += prevHigh > currentHigh ? 1 : 0; if (lCount == 2) { @@ -4159,9 +4159,9 @@ public static StockData CalculateGuppyCountBackLine(this StockData stockData, in if (currentHigh == hh) { - for (int k = j + 1; k <= j + length; k++) + for (var k = j + 1; k <= j + length; k++) { - double prevLow = i >= k ? lowList[i - k] : 0; + var prevLow = i >= k ? lowList[i - k] : 0; hCount += prevLow > currentLow ? 1 : 0; if (hCount == 2) { @@ -4274,57 +4274,57 @@ public static StockData CalculateGuppyMultipleMovingAverage(this StockData stock var ema67List = GetMovingAverageList(stockData, maType, length34, inputList); var ema70List = GetMovingAverageList(stockData, maType, length35, inputList); - for (int i = 0; i < stockData.Count; i++) - { - double emaF1 = ema3List[i]; - double emaF2 = ema5List[i]; - double emaF3 = ema7List[i]; - double emaF4 = ema9List[i]; - double emaF5 = ema11List[i]; - double emaF6 = ema13List[i]; - double emaF7 = ema15List[i]; - double emaF8 = ema17List[i]; - double emaF9 = ema19List[i]; - double emaF10 = ema21List[i]; - double emaF11 = ema23List[i]; - double emaS1 = ema25List[i]; - double emaS2 = ema28List[i]; - double emaS3 = ema31List[i]; - double emaS4 = ema34List[i]; - double emaS5 = ema37List[i]; - double emaS6 = ema40List[i]; - double emaS7 = ema43List[i]; - double emaS8 = ema46List[i]; - double emaS9 = ema49List[i]; - double emaS10 = ema52List[i]; - double emaS11 = ema55List[i]; - double emaS12 = ema58List[i]; - double emaS13 = ema61List[i]; - double emaS14 = ema64List[i]; - double emaS15 = ema67List[i]; - double emaS16 = ema70List[i]; - - double superGmmaFast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11) / 11; + for (var i = 0; i < stockData.Count; i++) + { + var emaF1 = ema3List[i]; + var emaF2 = ema5List[i]; + var emaF3 = ema7List[i]; + var emaF4 = ema9List[i]; + var emaF5 = ema11List[i]; + var emaF6 = ema13List[i]; + var emaF7 = ema15List[i]; + var emaF8 = ema17List[i]; + var emaF9 = ema19List[i]; + var emaF10 = ema21List[i]; + var emaF11 = ema23List[i]; + var emaS1 = ema25List[i]; + var emaS2 = ema28List[i]; + var emaS3 = ema31List[i]; + var emaS4 = ema34List[i]; + var emaS5 = ema37List[i]; + var emaS6 = ema40List[i]; + var emaS7 = ema43List[i]; + var emaS8 = ema46List[i]; + var emaS9 = ema49List[i]; + var emaS10 = ema52List[i]; + var emaS11 = ema55List[i]; + var emaS12 = ema58List[i]; + var emaS13 = ema61List[i]; + var emaS14 = ema64List[i]; + var emaS15 = ema67List[i]; + var emaS16 = ema70List[i]; + + var superGmmaFast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11) / 11; superGmmaFastList.AddRounded(superGmmaFast); - double superGmmaSlow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + - emaS14 + emaS15 + emaS16) / 16; + var superGmmaSlow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + + emaS14 + emaS15 + emaS16) / 16; superGmmaSlowList.AddRounded(superGmmaSlow); - double superGmmaOscRaw = superGmmaSlow != 0 ? (superGmmaFast - superGmmaSlow) / superGmmaSlow * 100 : 0; + var superGmmaOscRaw = superGmmaSlow != 0 ? (superGmmaFast - superGmmaSlow) / superGmmaSlow * 100 : 0; superGmmaOscRawList.AddRounded(superGmmaOscRaw); - double superGmmaOsc = superGmmaOscRawList.TakeLastExt(smoothLength).Average(); + var superGmmaOsc = superGmmaOscRawList.TakeLastExt(smoothLength).Average(); superGmmaOscList.AddRounded(superGmmaOsc); } var superGmmaSignalList = GetMovingAverageList(stockData, maType, signalLength, superGmmaOscRawList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double superGmmaOsc = superGmmaOscList[i]; - double superGmmaSignal = superGmmaSignalList[i]; - double prevSuperGmmaOsc = i >= 1 ? superGmmaOscList[i - 1] : 0; - double prevSuperGmmaSignal = i >= 1 ? superGmmaSignalList[i - 1] : 0; + var superGmmaOsc = superGmmaOscList[i]; + var superGmmaSignal = superGmmaSignalList[i]; + var prevSuperGmmaOsc = i >= 1 ? superGmmaOscList[i - 1] : 0; + var prevSuperGmmaSignal = i >= 1 ? superGmmaSignalList[i - 1] : 0; var signal = GetCompareSignal(superGmmaOsc - superGmmaSignal, prevSuperGmmaOsc - prevSuperGmmaSignal); signalsList.Add(signal); @@ -4382,41 +4382,41 @@ public static StockData CalculateGuppyDistanceIndicator(this StockData stockData var ema50List = GetMovingAverageList(stockData, maType, length11, inputList); var ema60List = GetMovingAverageList(stockData, maType, length12, inputList); - for (int i = 0; i < stockData.Count; i++) - { - double ema1 = ema3List[i]; - double ema2 = ema5List[i]; - double ema3 = ema8List[i]; - double ema4 = ema10List[i]; - double ema5 = ema12List[i]; - double ema6 = ema15List[i]; - double ema7 = ema30List[i]; - double ema8 = ema35List[i]; - double ema9 = ema40List[i]; - double ema10 = ema45List[i]; - double ema11 = ema50List[i]; - double ema12 = ema60List[i]; - double diff12 = Math.Abs(ema1 - ema2); - double diff23 = Math.Abs(ema2 - ema3); - double diff34 = Math.Abs(ema3 - ema4); - double diff45 = Math.Abs(ema4 - ema5); - double diff56 = Math.Abs(ema5 - ema6); - double diff78 = Math.Abs(ema7 - ema8); - double diff89 = Math.Abs(ema8 - ema9); - double diff910 = Math.Abs(ema9 - ema10); - double diff1011 = Math.Abs(ema10 - ema11); - double diff1112 = Math.Abs(ema11 - ema12); - - double fastDistance = diff12 + diff23 + diff34 + diff45 + diff56; + for (var i = 0; i < stockData.Count; i++) + { + var ema1 = ema3List[i]; + var ema2 = ema5List[i]; + var ema3 = ema8List[i]; + var ema4 = ema10List[i]; + var ema5 = ema12List[i]; + var ema6 = ema15List[i]; + var ema7 = ema30List[i]; + var ema8 = ema35List[i]; + var ema9 = ema40List[i]; + var ema10 = ema45List[i]; + var ema11 = ema50List[i]; + var ema12 = ema60List[i]; + var diff12 = Math.Abs(ema1 - ema2); + var diff23 = Math.Abs(ema2 - ema3); + var diff34 = Math.Abs(ema3 - ema4); + var diff45 = Math.Abs(ema4 - ema5); + var diff56 = Math.Abs(ema5 - ema6); + var diff78 = Math.Abs(ema7 - ema8); + var diff89 = Math.Abs(ema8 - ema9); + var diff910 = Math.Abs(ema9 - ema10); + var diff1011 = Math.Abs(ema10 - ema11); + var diff1112 = Math.Abs(ema11 - ema12); + + var fastDistance = diff12 + diff23 + diff34 + diff45 + diff56; fastDistanceList.AddRounded(fastDistance); - double slowDistance = diff78 + diff89 + diff910 + diff1011 + diff1112; + var slowDistance = diff78 + diff89 + diff910 + diff1011 + diff1112; slowDistanceList.AddRounded(slowDistance); - bool colFastL = ema1 > ema2 && ema2 > ema3 && ema3 > ema4 && ema4 > ema5 && ema5 > ema6; - bool colFastS = ema1 < ema2 && ema2 < ema3 && ema3 < ema4 && ema4 < ema5 && ema5 < ema6; - bool colSlowL = ema7 > ema8 && ema8 > ema9 && ema9 > ema10 && ema10 > ema11 && ema11 > ema12; - bool colSlowS = ema7 < ema8 && ema8 < ema9 && ema9 < ema10 && ema10 < ema11 && ema11 < ema12; + var colFastL = ema1 > ema2 && ema2 > ema3 && ema3 > ema4 && ema4 > ema5 && ema5 > ema6; + var colFastS = ema1 < ema2 && ema2 < ema3 && ema3 < ema4 && ema4 < ema5 && ema5 < ema6; + var colSlowL = ema7 > ema8 && ema8 > ema9 && ema9 > ema10 && ema10 > ema11 && ema11 > ema12; + var colSlowS = ema7 < ema8 && ema8 < ema9 && ema9 < ema10 && ema10 < ema11 && ema11 < ema12; var signal = GetConditionSignal(colSlowL || colFastL, colSlowS || colFastS); signalsList.Add(signal); @@ -4447,17 +4447,17 @@ public static StockData CalculateGOscillator(this StockData stockData, int lengt List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevBSum1 = i >= 1 ? bSumList[i - 1] : 0; - double prevBSum2 = i >= 2 ? bSumList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevBSum1 = i >= 1 ? bSumList[i - 1] : 0; + var prevBSum2 = i >= 2 ? bSumList[i - 2] : 0; - double b = currentValue > prevValue ? (double)100 / length : 0; + var b = currentValue > prevValue ? (double)100 / length : 0; bList.AddRounded(b); - double bSum = bList.TakeLastExt(length).Sum(); + var bSum = bList.TakeLastExt(length).Sum(); bSumList.AddRounded(bSum); var signal = GetRsiSignal(bSum - prevBSum1, prevBSum1 - prevBSum2, bSum, prevBSum1, 80, 20); @@ -4490,18 +4490,18 @@ public static StockData CalculateGainLossMovingAverage(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double gainLoss = currentValue + prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / ((currentValue + prevValue) / 2) * 100 : 0; + var gainLoss = currentValue + prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / ((currentValue + prevValue) / 2) * 100 : 0; gainLossList.AddRounded(gainLoss); } var gainLossAvgList = GetMovingAverageList(stockData, maType, length, gainLossList); var gainLossAvgSignalList = GetMovingAverageList(stockData, maType, signalLength, gainLossAvgList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var gainLossSignal = gainLossAvgSignalList[i]; var prevGainLossSignal1 = i >= 1 ? gainLossAvgSignalList[i - 1] : 0; @@ -4541,12 +4541,12 @@ public static StockData CalculateHighLowIndex(this StockData stockData, MovingAv var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevHighest = i >= 1 ? highestList[i - 1] : 0; - double prevLowest = i >= 1 ? lowestList[i - 1] : 0; - double highest = highestList[i]; - double lowest = lowestList[i]; + var prevHighest = i >= 1 ? highestList[i - 1] : 0; + var prevLowest = i >= 1 ? lowestList[i - 1] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; double adv = highest > prevHighest ? 1 : 0; advList.AddRounded(adv); @@ -4554,19 +4554,19 @@ public static StockData CalculateHighLowIndex(this StockData stockData, MovingAv double lo = lowest < prevLowest ? 1 : 0; loList.AddRounded(lo); - double advSum = advList.TakeLastExt(length).Sum(); - double loSum = loList.TakeLastExt(length).Sum(); + var advSum = advList.TakeLastExt(length).Sum(); + var loSum = loList.TakeLastExt(length).Sum(); - double advDiff = advSum + loSum != 0 ? MinOrMax(advSum / (advSum + loSum) * 100, 100, 0) : 0; + var advDiff = advSum + loSum != 0 ? MinOrMax(advSum / (advSum + loSum) * 100, 100, 0) : 0; advDiffList.AddRounded(advDiff); } var zmbtiList = GetMovingAverageList(stockData, maType, length, advDiffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double zmbti = zmbtiList[i]; - double prevZmbti1 = i >= 1 ? hliList[i - 1] : 0; - double prevZmbti2 = i >= 2 ? hliList[i - 2] : 0; + var zmbti = zmbtiList[i]; + var prevZmbti1 = i >= 1 ? hliList[i - 1] : 0; + var prevZmbti2 = i >= 2 ? hliList[i - 2] : 0; var signal = GetRsiSignal(zmbti - prevZmbti1, prevZmbti1 - prevZmbti2, zmbti, prevZmbti1, 70, 30); signalsList.Add(signal); @@ -4597,17 +4597,17 @@ public static StockData CalculateForecastOscillator(this StockData stockData, Mo List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double pf = currentValue != 0 ? 100 * MinPastValues(i, 1, currentValue - prevValue) / currentValue : 0; + var pf = currentValue != 0 ? 100 * MinPastValues(i, 1, currentValue - prevValue) / currentValue : 0; pfList.AddRounded(pf); } var pfSmaList = GetMovingAverageList(stockData, maType, length, pfList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var pfSma = pfSmaList[i]; var prevPfSma = i >= 1 ? pfSmaList[i - 1] : 0; @@ -4644,27 +4644,27 @@ public static StockData CalculateFastandSlowKurtosisOscillator(this StockData st List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; - double prevMomentum = momentumList.LastOrDefault(); - double momentum = MinPastValues(i, length, currentValue - prevValue); + var prevMomentum = momentumList.LastOrDefault(); + var momentum = MinPastValues(i, length, currentValue - prevValue); momentumList.AddRounded(momentum); - double prevFsk = fskList.LastOrDefault(); - double fsk = (ratio * (momentum - prevMomentum)) + ((1 - ratio) * prevFsk); + var prevFsk = fskList.LastOrDefault(); + var fsk = (ratio * (momentum - prevMomentum)) + ((1 - ratio) * prevFsk); fskList.AddRounded(fsk); } var fskSignalList = GetMovingAverageList(stockData, maType, length, fskList); - for (int i = 0; i < fskSignalList.Count; i++) + for (var i = 0; i < fskSignalList.Count; i++) { - double fsk = fskList[i]; - double fskSignal = fskSignalList[i]; - double prevFsk = i >= 1 ? fskList[i - 1] : 0; - double prevFskSignal = i >= 1 ? fskSignalList[i - 1] : 0; + var fsk = fskList[i]; + var fskSignal = fskSignalList[i]; + var prevFsk = i >= 1 ? fskList[i - 1] : 0; + var prevFskSignal = i >= 1 ? fskSignalList[i - 1] : 0; var signal = GetCompareSignal(fsk - fskSignal, prevFsk - prevFskSignal); signalsList.Add(signal); @@ -4702,22 +4702,22 @@ public static StockData CalculateFastandSlowRelativeStrengthIndexOscillator(this var fskList = CalculateFastandSlowKurtosisOscillator(stockData, maType, length: length1).CustomValuesList; var v4List = GetMovingAverageList(stockData, maType, length2, fskList); - for (int i = 0; i < v4List.Count; i++) + for (var i = 0; i < v4List.Count; i++) { - double rsi = rsiList[i]; - double v4 = v4List[i]; + var rsi = rsiList[i]; + var v4 = v4List[i]; - double fsrsi = (10000 * v4) + rsi; + var fsrsi = (10000 * v4) + rsi; fsrsiList.AddRounded(fsrsi); } var fsrsiSignalList = GetMovingAverageList(stockData, maType, length4, fsrsiList); - for (int i = 0; i < fsrsiSignalList.Count; i++) + for (var i = 0; i < fsrsiSignalList.Count; i++) { - double fsrsi = fsrsiList[i]; - double fsrsiSignal = fsrsiSignalList[i]; - double prevFsrsi = i >= 1 ? fsrsiList[i - 1] : 0; - double prevFsrsiSignal = i >= 1 ? fsrsiSignalList[i - 1] : 0; + var fsrsi = fsrsiList[i]; + var fsrsiSignal = fsrsiSignalList[i]; + var prevFsrsi = i >= 1 ? fsrsiList[i - 1] : 0; + var prevFsrsiSignal = i >= 1 ? fsrsiSignalList[i - 1] : 0; var signal = GetCompareSignal(fsrsi - fsrsiSignal, prevFsrsi - prevFsrsiSignal); signalsList.Add(signal); @@ -4760,58 +4760,58 @@ public static StockData CalculateFastSlowDegreeOscillator(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double fastF1x = (double)(i + 1) / length; - double fastF1b = (double)1 / (i + 1) * Math.Sin(fastF1x * (i + 1) * Math.PI); + var fastF1x = (double)(i + 1) / length; + var fastF1b = (double)1 / (i + 1) * Math.Sin(fastF1x * (i + 1) * Math.PI); fastF1bList.AddRounded(fastF1b); - double fastF1bSum = fastF1bList.TakeLastExt(fastLength).Sum(); - double fastF1pol = (fastF1x * fastF1x) + fastF1bSum; - double fastF2x = length != 0 ? (double)i / length : 0; - double fastF2b = (double)1 / (i + 1) * Math.Sin(fastF2x * (i + 1) * Math.PI); + var fastF1bSum = fastF1bList.TakeLastExt(fastLength).Sum(); + var fastF1pol = (fastF1x * fastF1x) + fastF1bSum; + var fastF2x = length != 0 ? (double)i / length : 0; + var fastF2b = (double)1 / (i + 1) * Math.Sin(fastF2x * (i + 1) * Math.PI); fastF2bList.AddRounded(fastF2b); - double fastF2bSum = fastF2bList.TakeLastExt(fastLength).Sum(); - double fastF2pol = (fastF2x * fastF2x) + fastF2bSum; - double fastW = fastF1pol - fastF2pol; - double fastVW = prevValue * fastW; + var fastF2bSum = fastF2bList.TakeLastExt(fastLength).Sum(); + var fastF2pol = (fastF2x * fastF2x) + fastF2bSum; + var fastW = fastF1pol - fastF2pol; + var fastVW = prevValue * fastW; fastVWList.AddRounded(fastVW); - double fastVWSum = fastVWList.TakeLastExt(length).Sum(); - double slowF1x = length != 0 ? (double)(i + 1) / length : 0; - double slowF1b = (double)1 / (i + 1) * Math.Sin(slowF1x * (i + 1) * Math.PI); + var fastVWSum = fastVWList.TakeLastExt(length).Sum(); + var slowF1x = length != 0 ? (double)(i + 1) / length : 0; + var slowF1b = (double)1 / (i + 1) * Math.Sin(slowF1x * (i + 1) * Math.PI); slowF1bList.AddRounded(slowF1b); - double slowF1bSum = slowF1bList.TakeLastExt(slowLength).Sum(); - double slowF1pol = (slowF1x * slowF1x) + slowF1bSum; - double slowF2x = length != 0 ? (double)i / length : 0; - double slowF2b = (double)1 / (i + 1) * Math.Sin(slowF2x * (i + 1) * Math.PI); + var slowF1bSum = slowF1bList.TakeLastExt(slowLength).Sum(); + var slowF1pol = (slowF1x * slowF1x) + slowF1bSum; + var slowF2x = length != 0 ? (double)i / length : 0; + var slowF2b = (double)1 / (i + 1) * Math.Sin(slowF2x * (i + 1) * Math.PI); slowF2bList.AddRounded(slowF2b); - double slowF2bSum = slowF2bList.TakeLastExt(slowLength).Sum(); - double slowF2pol = (slowF2x * slowF2x) + slowF2bSum; - double slowW = slowF1pol - slowF2pol; - double slowVW = prevValue * slowW; + var slowF2bSum = slowF2bList.TakeLastExt(slowLength).Sum(); + var slowF2pol = (slowF2x * slowF2x) + slowF2bSum; + var slowW = slowF1pol - slowF2pol; + var slowVW = prevValue * slowW; slowVWList.AddRounded(slowVW); - double slowVWSum = slowVWList.TakeLastExt(length).Sum(); + var slowVWSum = slowVWList.TakeLastExt(length).Sum(); slowVWSumList.AddRounded(slowVWSum); - double os = fastVWSum - slowVWSum; + var os = fastVWSum - slowVWSum; osList.AddRounded(os); } var osSignalList = GetMovingAverageList(stockData, maType, signalLength, osList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double os = osList[i]; - double osSignal = osSignalList[i]; + var os = osList[i]; + var osSignal = osSignalList[i]; - double prevHist = histList.LastOrDefault(); - double hist = os - osSignal; + var prevHist = histList.LastOrDefault(); + var hist = os - osSignal; histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); @@ -4845,14 +4845,14 @@ public static StockData CalculateFractalChaosOscillator(this StockData stockData var upperBandList = fractalChaosBandsList.OutputValues["UpperBand"]; var lowerBandList = fractalChaosBandsList.OutputValues["LowerBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double upperBand = upperBandList[i]; - double prevUpperBand = i >= 1 ? upperBandList[i - 1] : 0; - double lowerBand = lowerBandList[i]; - double prevLowerBand = i >= 1 ? lowerBandList[i - 1] : 0; + var upperBand = upperBandList[i]; + var prevUpperBand = i >= 1 ? upperBandList[i - 1] : 0; + var lowerBand = lowerBandList[i]; + var prevLowerBand = i >= 1 ? lowerBandList[i - 1] : 0; - double prevFco = fcoList.LastOrDefault(); + var prevFco = fcoList.LastOrDefault(); double fco = upperBand != prevUpperBand ? 1 : lowerBand != prevLowerBand ? -1 : 0; fcoList.AddRounded(fco); @@ -4889,42 +4889,42 @@ public static StockData CalculateFireflyOscillator(this StockData stockData, Mov List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; - double v2 = (currentHigh + currentLow + (currentClose * 2)) / 4; + var v2 = (currentHigh + currentLow + (currentClose * 2)) / 4; v2List.AddRounded(v2); } var v3List = GetMovingAverageList(stockData, maType, length, v2List); stockData.CustomValuesList = v2List; var v4List = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double v2 = v2List[i]; - double v3 = v3List[i]; - double v4 = v4List[i]; + var v2 = v2List[i]; + var v3 = v3List[i]; + var v4 = v4List[i]; - double v5 = v4 == 0 ? (v2 - v3) * 100 : (v2 - v3) * 100 / v4; + var v5 = v4 == 0 ? (v2 - v3) * 100 : (v2 - v3) * 100 / v4; v5List.AddRounded(v5); } var v6List = GetMovingAverageList(stockData, maType, smoothLength, v5List); var v7List = GetMovingAverageList(stockData, maType, smoothLength, v6List); var wwZLagEmaList = GetMovingAverageList(stockData, maType, length, v7List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wwZlagEma = wwZLagEmaList[i]; - double prevWw1 = i >= 1 ? wwList[i - 1] : 0; - double prevWw2 = i >= 2 ? wwList[i - 2] : 0; + var wwZlagEma = wwZLagEmaList[i]; + var prevWw1 = i >= 1 ? wwList[i - 1] : 0; + var prevWw2 = i >= 2 ? wwList[i - 2] : 0; - double ww = ((wwZlagEma + 100) / 2) - 4; + var ww = ((wwZlagEma + 100) / 2) - 4; wwList.AddRounded(ww); - double mm = wwList.TakeLastExt(smoothLength).Max(); + var mm = wwList.TakeLastExt(smoothLength).Max(); mmList.AddRounded(mm); var signal = GetRsiSignal(ww - prevWw1, prevWw1 - prevWw2, ww, prevWw1, 80, 20); @@ -4963,20 +4963,20 @@ public static StockData CalculateFibonacciRetrace(this StockData stockData, Movi var wmaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wma = wmaList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevWma = i >= 1 ? wmaList[i - 1] : 0; - double retrace = (highest - lowest) * factor; + var wma = wmaList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevWma = i >= 1 ? wmaList[i - 1] : 0; + var retrace = (highest - lowest) * factor; - double prevHret = hretList.LastOrDefault(); - double hret = highest - retrace; + var prevHret = hretList.LastOrDefault(); + var hret = highest - retrace; hretList.AddRounded(hret); - double prevLret = lretList.LastOrDefault(); - double lret = lowest + retrace; + var prevLret = lretList.LastOrDefault(); + var lret = lowest + retrace; lretList.AddRounded(lret); var signal = GetBullishBearishSignal(wma - hret, prevWma - prevHret, wma - lret, prevWma - prevLret); @@ -5016,48 +5016,48 @@ public static StockData CalculateFXSniperIndicator(this StockData stockData, Mov List fxSniperList = new(); List signalsList = new(); - double b2 = b * b; - double b3 = b2 * b; - double c1 = -b3; - double c2 = 3 * (b2 + b3); - double c3 = -3 * ((2 * b2) + b + b3); - double c4 = 1 + (3 * b) + b3 + (3 * b2); - double nr = 1 + (0.5 * (t3Length - 1)); - double w1 = 2 / (nr + 1); - double w2 = 1 - w1; + var b2 = b * b; + var b3 = b2 * b; + var c1 = -b3; + var c2 = 3 * (b2 + b3); + var c3 = -3 * ((2 * b2) + b + b3); + var c4 = 1 + (3 * b) + b3 + (3 * b2); + var nr = 1 + (0.5 * (t3Length - 1)); + var w1 = 2 / (nr + 1); + var w2 = 1 - w1; var cciList = CalculateCommodityChannelIndex(stockData, maType: maType, length: cciLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double cci = cciList[i]; + var cci = cciList[i]; - double prevE1 = e1List.LastOrDefault(); - double e1 = (w1 * cci) + (w2 * prevE1); + var prevE1 = e1List.LastOrDefault(); + var e1 = (w1 * cci) + (w2 * prevE1); e1List.AddRounded(e1); - double prevE2 = e2List.LastOrDefault(); - double e2 = (w1 * e1) + (w2 * prevE2); + var prevE2 = e2List.LastOrDefault(); + var e2 = (w1 * e1) + (w2 * prevE2); e2List.AddRounded(e2); - double prevE3 = e3List.LastOrDefault(); - double e3 = (w1 * e2) + (w2 * prevE3); + var prevE3 = e3List.LastOrDefault(); + var e3 = (w1 * e2) + (w2 * prevE3); e3List.AddRounded(e3); - double prevE4 = e4List.LastOrDefault(); - double e4 = (w1 * e3) + (w2 * prevE4); + var prevE4 = e4List.LastOrDefault(); + var e4 = (w1 * e3) + (w2 * prevE4); e4List.AddRounded(e4); - double prevE5 = e5List.LastOrDefault(); - double e5 = (w1 * e4) + (w2 * prevE5); + var prevE5 = e5List.LastOrDefault(); + var e5 = (w1 * e4) + (w2 * prevE5); e5List.AddRounded(e5); - double prevE6 = e6List.LastOrDefault(); - double e6 = (w1 * e5) + (w2 * prevE6); + var prevE6 = e6List.LastOrDefault(); + var e6 = (w1 * e5) + (w2 * prevE6); e6List.AddRounded(e6); - double prevFxSniper = fxSniperList.LastOrDefault(); - double fxsniper = (c1 * e6) + (c2 * e5) + (c3 * e4) + (c4 * e3); + var prevFxSniper = fxSniperList.LastOrDefault(); + var fxsniper = (c1 * e6) + (c2 * e5) + (c3 * e4) + (c4 * e3); fxSniperList.AddRounded(fxsniper); var signal = GetCompareSignal(fxsniper, prevFxSniper); @@ -5093,18 +5093,18 @@ public static StockData CalculateFearAndGreedIndicator(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - double trUp = currentValue > prevValue ? tr : 0; + var trUp = currentValue > prevValue ? tr : 0; trUpList.AddRounded(trUp); - double trDn = currentValue < prevValue ? tr : 0; + var trDn = currentValue < prevValue ? tr : 0; trDnList.AddRounded(trDn); } @@ -5112,24 +5112,24 @@ public static StockData CalculateFearAndGreedIndicator(this StockData stockData, var fastTrDnList = GetMovingAverageList(stockData, maType, fastLength, trDnList); var slowTrUpList = GetMovingAverageList(stockData, maType, slowLength, trUpList); var slowTrDnList = GetMovingAverageList(stockData, maType, slowLength, trDnList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastTrUp = fastTrUpList[i]; - double fastTrDn = fastTrDnList[i]; - double slowTrUp = slowTrUpList[i]; - double slowTrDn = slowTrDnList[i]; - double fastDiff = fastTrUp - fastTrDn; - double slowDiff = slowTrUp - slowTrDn; + var fastTrUp = fastTrUpList[i]; + var fastTrDn = fastTrDnList[i]; + var slowTrUp = slowTrUpList[i]; + var slowTrDn = slowTrDnList[i]; + var fastDiff = fastTrUp - fastTrDn; + var slowDiff = slowTrUp - slowTrDn; - double fgi = fastDiff - slowDiff; + var fgi = fastDiff - slowDiff; fgiList.AddRounded(fgi); } var fgiEmaList = GetMovingAverageList(stockData, maType, smoothLength, fgiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fgiEma = fgiEmaList[i]; - double prevFgiEma = i >= 1 ? fgiEmaList[i - 1] : 0; + var fgiEma = fgiEmaList[i]; + var prevFgiEma = i >= 1 ? fgiEmaList[i - 1] : 0; var signal = GetCompareSignal(fgiEma, prevFgiEma); signalsList.Add(signal); @@ -5170,16 +5170,16 @@ public static StockData CalculateFunctionToCandles(this StockData stockData, Mov stockData.CustomValuesList = lowList; var rsiLList = CalculateRelativeStrengthIndex(stockData, maType, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsiC = rsiCList[i]; - double rsiO = rsiOList[i]; - double rsiH = rsiHList[i]; - double rsiL = rsiLList[i]; - double prevTp1 = i >= 1 ? tpList[i - 1] : 0; - double prevTp2 = i >= 2 ? tpList[i - 2] : 0; + var rsiC = rsiCList[i]; + var rsiO = rsiOList[i]; + var rsiH = rsiHList[i]; + var rsiL = rsiLList[i]; + var prevTp1 = i >= 1 ? tpList[i - 1] : 0; + var prevTp2 = i >= 2 ? tpList[i - 2] : 0; - double tp = (rsiC + rsiO + rsiH + rsiL) / 4; + var tp = (rsiC + rsiO + rsiH + rsiL) / 4; tpList.AddRounded(tp); var signal = GetCompareSignal(tp - prevTp1, prevTp1 - prevTp2); @@ -5218,31 +5218,31 @@ public static StockData CalculateKarobeinOscillator(this StockData stockData, Mo var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var ema = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double a = ema < prevEma && prevEma != 0 ? ema / prevEma : 0; + var a = ema < prevEma && prevEma != 0 ? ema / prevEma : 0; aList.AddRounded(a); - double b = ema > prevEma && prevEma != 0 ? ema / prevEma : 0; + var b = ema > prevEma && prevEma != 0 ? ema / prevEma : 0; bList.AddRounded(b); } var aEmaList = GetMovingAverageList(stockData, maType, length, aList); var bEmaList = GetMovingAverageList(stockData, maType, length, bList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double a = aEmaList[i]; - double b = bEmaList[i]; - double prevD1 = i >= 1 ? dList[i - 1] : 0; - double prevD2 = i >= 2 ? dList[i - 2] : 0; - double c = prevEma != 0 && ema != 0 ? MinOrMax(ema / prevEma / ((ema / prevEma) + b), 1, 0) : 0; + var ema = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var a = aEmaList[i]; + var b = bEmaList[i]; + var prevD1 = i >= 1 ? dList[i - 1] : 0; + var prevD2 = i >= 2 ? dList[i - 2] : 0; + var c = prevEma != 0 && ema != 0 ? MinOrMax(ema / prevEma / ((ema / prevEma) + b), 1, 0) : 0; - double d = prevEma != 0 && ema != 0 ? MinOrMax((2 * (ema / prevEma / ((ema / prevEma) + (c * a)))) - 1, 1, 0) : 0; + var d = prevEma != 0 && ema != 0 ? MinOrMax((2 * (ema / prevEma / ((ema / prevEma) + (c * a)))) - 1, 1, 0) : 0; dList.AddRounded(d); var signal = GetRsiSignal(d - prevD1, prevD1 - prevD2, d, prevD1, 0.8, 0.2); @@ -5274,21 +5274,21 @@ public static StockData CalculateKasePeakOscillatorV1(this StockData stockData, List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - double sqrt = Sqrt(length); + var sqrt = Sqrt(length); var atrList = CalculateAverageTrueRange(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentAtr = atrList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevLow = i >= length ? lowList[i - length] : 0; - double prevHigh = i >= length ? highList[i - length] : 0; - double rwh = currentAtr != 0 ? (currentHigh - prevLow) / currentAtr * sqrt : 0; - double rwl = currentAtr != 0 ? (prevHigh - currentLow) / currentAtr * sqrt : 0; + var currentAtr = atrList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevLow = i >= length ? lowList[i - length] : 0; + var prevHigh = i >= length ? highList[i - length] : 0; + var rwh = currentAtr != 0 ? (currentHigh - prevLow) / currentAtr * sqrt : 0; + var rwl = currentAtr != 0 ? (prevHigh - currentLow) / currentAtr * sqrt : 0; - double diff = rwh - rwl; + var diff = rwh - rwl; diffList.AddRounded(diff); } @@ -5296,17 +5296,17 @@ public static StockData CalculateKasePeakOscillatorV1(this StockData stockData, var mnList = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, length, pkList); stockData.CustomValuesList = pkList; var sdList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pk = pkList[i]; - double mn = mnList[i]; - double sd = sdList[i]; - double prevPk = i >= 1 ? pkList[i - 1] : 0; - double v1 = mn + (1.33 * sd) > 2.08 ? mn + (1.33 * sd) : 2.08; - double v2 = mn - (1.33 * sd) < -1.92 ? mn - (1.33 * sd) : -1.92; + var pk = pkList[i]; + var mn = mnList[i]; + var sd = sdList[i]; + var prevPk = i >= 1 ? pkList[i - 1] : 0; + var v1 = mn + (1.33 * sd) > 2.08 ? mn + (1.33 * sd) : 2.08; + var v2 = mn - (1.33 * sd) < -1.92 ? mn - (1.33 * sd) : -1.92; - double prevLn = lnList.LastOrDefault(); - double ln = prevPk >= 0 && pk > 0 ? v1 : prevPk <= 0 && pk < 0 ? v2 : 0; + var prevLn = lnList.LastOrDefault(); + var ln = prevPk >= 0 && pk > 0 ? v1 : prevPk <= 0 && pk < 0 ? v2 : 0; lnList.AddRounded(ln); var signal = GetCompareSignal(ln, prevLn); @@ -5354,74 +5354,74 @@ public static StockData CalculateKasePeakOscillatorV2(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double temp = prevValue != 0 ? currentValue / prevValue : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var temp = prevValue != 0 ? currentValue / prevValue : 0; - double ccLog = temp > 0 ? Math.Log(temp) : 0; + var ccLog = temp > 0 ? Math.Log(temp) : 0; ccLogList.AddRounded(ccLog); } stockData.CustomValuesList = ccLogList; var ccDevList = CalculateStandardDeviationVolatility(stockData, maType, length1).CustomValuesList; var ccDevAvgList = GetMovingAverageList(stockData, maType, length2, ccDevList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double avg = ccDevAvgList[i]; - double currentLow = lowList[i]; - double currentHigh = highList[i]; + var avg = ccDevAvgList[i]; + var currentLow = lowList[i]; + var currentHigh = highList[i]; double max1 = 0, max2 = 0; - for (int j = fastLength; j < slowLength; j++) + for (var j = fastLength; j < slowLength; j++) { - double sqrtK = Sqrt(j); - double prevLow = i >= j ? lowList[i - j] : 0; - double prevHigh = i >= j ? highList[i - j] : 0; - double temp1 = prevLow != 0 ? currentHigh / prevLow : 0; - double log1 = temp1 > 0 ? Math.Log(temp1) : 0; + var sqrtK = Sqrt(j); + var prevLow = i >= j ? lowList[i - j] : 0; + var prevHigh = i >= j ? highList[i - j] : 0; + var temp1 = prevLow != 0 ? currentHigh / prevLow : 0; + var log1 = temp1 > 0 ? Math.Log(temp1) : 0; max1 = Math.Max(log1 / sqrtK, max1); - double temp2 = currentLow != 0 ? prevHigh / currentLow : 0; - double log2 = temp2 > 0 ? Math.Log(temp2) : 0; + var temp2 = currentLow != 0 ? prevHigh / currentLow : 0; + var log2 = temp2 > 0 ? Math.Log(temp2) : 0; max2 = Math.Max(log2 / sqrtK, max2); } - double x1 = avg != 0 ? max1 / avg : 0; + var x1 = avg != 0 ? max1 / avg : 0; x1List.AddRounded(x1); - double x2 = avg != 0 ? max2 / avg : 0; + var x2 = avg != 0 ? max2 / avg : 0; x2List.AddRounded(x2); - double xp = sensitivity * (x1List.TakeLastExt(smoothLength).Average() - x2List.TakeLastExt(smoothLength).Average()); + var xp = sensitivity * (x1List.TakeLastExt(smoothLength).Average() - x2List.TakeLastExt(smoothLength).Average()); xpList.AddRounded(xp); - double xpAbs = Math.Abs(xp); + var xpAbs = Math.Abs(xp); xpAbsList.AddRounded(xpAbs); - double xpAbsAvg = xpAbsList.TakeLastExt(length3).Average(); + var xpAbsAvg = xpAbsList.TakeLastExt(length3).Average(); xpAbsAvgList.AddRounded(xpAbsAvg); } stockData.CustomValuesList = xpAbsList; var xpAbsStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length3).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double xpAbsAvg = xpAbsAvgList[i]; - double xpAbsStdDev = xpAbsStdDevList[i]; - double prevKpoBuffer1 = i >= 1 ? kpoBufferList[i - 1] : 0; - double prevKpoBuffer2 = i >= 2 ? kpoBufferList[i - 2] : 0; + var xpAbsAvg = xpAbsAvgList[i]; + var xpAbsStdDev = xpAbsStdDevList[i]; + var prevKpoBuffer1 = i >= 1 ? kpoBufferList[i - 1] : 0; + var prevKpoBuffer2 = i >= 2 ? kpoBufferList[i - 2] : 0; - double tmpVal = xpAbsAvg + (devFactor * xpAbsStdDev); - double maxVal = Math.Max(90, tmpVal); + var tmpVal = xpAbsAvg + (devFactor * xpAbsStdDev); + var maxVal = Math.Max(90, tmpVal); - double prevKpoBuffer = kpoBufferList.LastOrDefault(); - double kpoBuffer = xpList[i]; + var prevKpoBuffer = kpoBufferList.LastOrDefault(); + var kpoBuffer = xpList[i]; kpoBufferList.AddRounded(kpoBuffer); - double kppBuffer = prevKpoBuffer1 > 0 && prevKpoBuffer1 > kpoBuffer && prevKpoBuffer1 >= prevKpoBuffer2 && - prevKpoBuffer1 >= maxVal ? prevKpoBuffer1 : prevKpoBuffer1 < 0 && prevKpoBuffer1 < kpoBuffer && - prevKpoBuffer1 <= prevKpoBuffer2 && prevKpoBuffer1 <= maxVal * -1 ? prevKpoBuffer1 : + var kppBuffer = prevKpoBuffer1 > 0 && prevKpoBuffer1 > kpoBuffer && prevKpoBuffer1 >= prevKpoBuffer2 && + prevKpoBuffer1 >= maxVal ? prevKpoBuffer1 : prevKpoBuffer1 < 0 && prevKpoBuffer1 < kpoBuffer && + prevKpoBuffer1 <= prevKpoBuffer2 && prevKpoBuffer1 <= maxVal * -1 ? prevKpoBuffer1 : prevKpoBuffer1 > 0 && prevKpoBuffer1 > kpoBuffer && prevKpoBuffer1 >= prevKpoBuffer2 ? prevKpoBuffer1 : prevKpoBuffer1 < 0 && prevKpoBuffer1 < kpoBuffer && prevKpoBuffer1 <= prevKpoBuffer2 ? prevKpoBuffer1 : 0; kppBufferList.AddRounded(kppBuffer); @@ -5455,36 +5455,36 @@ public static StockData CalculateKaseSerialDependencyIndex(this StockData stockD List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double temp = prevValue != 0 ? currentValue / prevValue : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var temp = prevValue != 0 ? currentValue / prevValue : 0; - double tempLog = temp > 0 ? Math.Log(temp) : 0; + var tempLog = temp > 0 ? Math.Log(temp) : 0; tempList.AddRounded(tempLog); } stockData.CustomValuesList = tempList; var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double volatility = stdDevList[i]; - double prevHigh = i >= length ? highList[i - length] : 0; - double prevLow = i >= length ? lowList[i - length] : 0; - double ksdiUpTemp = prevLow != 0 ? currentHigh / prevLow : 0; - double ksdiDownTemp = prevHigh != 0 ? currentLow / prevHigh : 0; - double ksdiUpLog = ksdiUpTemp > 0 ? Math.Log(ksdiUpTemp) : 0; - double ksdiDownLog = ksdiDownTemp > 0 ? Math.Log(ksdiDownTemp) : 0; - - double prevKsdiUp = ksdiUpList.LastOrDefault(); - double ksdiUp = volatility != 0 ? ksdiUpLog / volatility : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var volatility = stdDevList[i]; + var prevHigh = i >= length ? highList[i - length] : 0; + var prevLow = i >= length ? lowList[i - length] : 0; + var ksdiUpTemp = prevLow != 0 ? currentHigh / prevLow : 0; + var ksdiDownTemp = prevHigh != 0 ? currentLow / prevHigh : 0; + var ksdiUpLog = ksdiUpTemp > 0 ? Math.Log(ksdiUpTemp) : 0; + var ksdiDownLog = ksdiDownTemp > 0 ? Math.Log(ksdiDownTemp) : 0; + + var prevKsdiUp = ksdiUpList.LastOrDefault(); + var ksdiUp = volatility != 0 ? ksdiUpLog / volatility : 0; ksdiUpList.AddRounded(ksdiUp); - double prevKsdiDown = ksdiDownList.LastOrDefault(); - double ksdiDown = volatility != 0 ? ksdiDownLog / volatility : 0; + var prevKsdiDown = ksdiDownList.LastOrDefault(); + var ksdiDown = volatility != 0 ? ksdiDownLog / volatility : 0; ksdiDownList.AddRounded(ksdiDown); var signal = GetCompareSignal(ksdiUp - ksdiDown, prevKsdiUp - prevKsdiDown); @@ -5525,39 +5525,39 @@ public static StockData CalculateKaufmanBinaryWave(this StockData stockData, int var efRatioList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double efRatio = efRatioList[i]; - double prevAma = i >= 1 ? amaList[i - 1] : currentValue; - double smooth = Pow((efRatio * fastSc) + slowSc, 2); + var currentValue = inputList[i]; + var efRatio = efRatioList[i]; + var prevAma = i >= 1 ? amaList[i - 1] : currentValue; + var smooth = Pow((efRatio * fastSc) + slowSc, 2); - double ama = prevAma + (smooth * (currentValue - prevAma)); + var ama = prevAma + (smooth * (currentValue - prevAma)); amaList.AddRounded(ama); - double diff = ama - prevAma; + var diff = ama - prevAma; diffList.AddRounded(diff); } stockData.CustomValuesList = diffList; var diffStdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ama = amaList[i]; - double diffStdDev = diffStdDevList[i]; - double prevAma = i >= 1 ? amaList[i - 1] : currentValue; - double filter = filterPct / 100 * diffStdDev; + var currentValue = inputList[i]; + var ama = amaList[i]; + var diffStdDev = diffStdDevList[i]; + var prevAma = i >= 1 ? amaList[i - 1] : currentValue; + var filter = filterPct / 100 * diffStdDev; - double prevAmaLow = amaLowList.LastOrDefault(); - double amaLow = ama < prevAma ? ama : prevAmaLow; + var prevAmaLow = amaLowList.LastOrDefault(); + var amaLow = ama < prevAma ? ama : prevAmaLow; amaLowList.AddRounded(amaLow); - double prevAmaHigh = amaHighList.LastOrDefault(); - double amaHigh = ama > prevAma ? ama : prevAmaHigh; + var prevAmaHigh = amaHighList.LastOrDefault(); + var amaHigh = ama > prevAma ? ama : prevAmaHigh; amaHighList.AddRounded(amaHigh); - double prevBw = bwList.LastOrDefault(); + var prevBw = bwList.LastOrDefault(); double bw = ama - amaLow > filter ? 1 : amaHigh - ama > filter ? -1 : 0; bwList.AddRounded(bw); @@ -5593,25 +5593,25 @@ public static StockData CalculateKurtosisIndicator(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length1 ? inputList[i - length1] : 0; - double prevDiff = i >= length2 ? diffList[i - length2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length1 ? inputList[i - length1] : 0; + var prevDiff = i >= length2 ? diffList[i - length2] : 0; - double diff = MinPastValues(i, length1, currentValue - prevValue); + var diff = MinPastValues(i, length1, currentValue - prevValue); diffList.AddRounded(diff); - double k = MinPastValues(i, length2, diff - prevDiff); + var k = MinPastValues(i, length2, diff - prevDiff); kList.AddRounded(k); } var fkList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, slowLength, kList); var fskList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, fastLength, fkList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fsk = fskList[i]; - double prevFsk = i >= 1 ? fskList[i - 1] : 0; + var fsk = fskList[i]; + var prevFsk = i >= 1 ? fskList[i - 1] : 0; var signal = GetCompareSignal(fsk, prevFsk); signalsList.Add(signal); @@ -5651,20 +5651,20 @@ public static StockData CalculateKaufmanAdaptiveCorrelationOscillator(this Stock var kamaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; double index = i; indexList.AddRounded(index); - double indexSrc = i * currentValue; + var indexSrc = i * currentValue; indexSrcList.AddRounded(indexSrc); - double srcSrc = currentValue * currentValue; + var srcSrc = currentValue * currentValue; src2List.AddRounded(srcSrc); - double indexIndex = index * index; + var indexIndex = index * index; index2List.AddRounded(indexIndex); } @@ -5672,28 +5672,28 @@ public static StockData CalculateKaufmanAdaptiveCorrelationOscillator(this Stock var indexSrcMaList = GetMovingAverageList(stockData, maType, length, indexSrcList); var index2MaList = GetMovingAverageList(stockData, maType, length, index2List); var src2MaList = GetMovingAverageList(stockData, maType, length, src2List); - for (int i = 0; i < stockData.Count; i++) - { - double srcMa = kamaList[i]; - double indexMa = indexMaList[i]; - double indexSrcMa = indexSrcMaList[i]; - double index2Ma = index2MaList[i]; - double src2Ma = src2MaList[i]; - double prevR1 = i >= 1 ? rList[i - 1] : 0; - double prevR2 = i >= 2 ? rList[i - 2] : 0; - - double indexSqrt = index2Ma - Pow(indexMa, 2); - double indexSt = indexSqrt >= 0 ? Sqrt(indexSqrt) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var srcMa = kamaList[i]; + var indexMa = indexMaList[i]; + var indexSrcMa = indexSrcMaList[i]; + var index2Ma = index2MaList[i]; + var src2Ma = src2MaList[i]; + var prevR1 = i >= 1 ? rList[i - 1] : 0; + var prevR2 = i >= 2 ? rList[i - 2] : 0; + + var indexSqrt = index2Ma - Pow(indexMa, 2); + var indexSt = indexSqrt >= 0 ? Sqrt(indexSqrt) : 0; indexStList.AddRounded(indexSt); - double srcSqrt = src2Ma - Pow(srcMa, 2); - double srcSt = srcSqrt >= 0 ? Sqrt(srcSqrt) : 0; + var srcSqrt = src2Ma - Pow(srcMa, 2); + var srcSt = srcSqrt >= 0 ? Sqrt(srcSqrt) : 0; srcStList.AddRounded(srcSt); - double a = indexSrcMa - (indexMa * srcMa); - double b = indexSt * srcSt; + var a = indexSrcMa - (indexMa * srcMa); + var b = indexSt * srcSt; - double r = b != 0 ? a / b : 0; + var r = b != 0 ? a / b : 0; rList.AddRounded(r); var signal = GetRsiSignal(r - prevR1, prevR1 - prevR2, r, prevR1, 0.5, -0.5); @@ -5748,24 +5748,24 @@ public static StockData CalculateKnowSureThing(this StockData stockData, MovingA var roc3SmaList = GetMovingAverageList(stockData, maType, length3, roc3List); var roc4SmaList = GetMovingAverageList(stockData, maType, length4, roc4List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roc1 = roc1SmaList[i]; - double roc2 = roc2SmaList[i]; - double roc3 = roc3SmaList[i]; - double roc4 = roc4SmaList[i]; + var roc1 = roc1SmaList[i]; + var roc2 = roc2SmaList[i]; + var roc3 = roc3SmaList[i]; + var roc4 = roc4SmaList[i]; - double kst = (roc1 * weight1) + (roc2 * weight2) + (roc3 * weight3) + (roc4 * weight4); + var kst = (roc1 * weight1) + (roc2 * weight2) + (roc3 * weight3) + (roc4 * weight4); kstList.AddRounded(kst); } var kstSignalList = GetMovingAverageList(stockData, maType, signalLength, kstList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double kst = kstList[i]; - double kstSignal = kstSignalList[i]; - double prevKst = i >= 1 ? kstList[i - 1] : 0; - double prevKstSignal = i >= 1 ? kstSignalList[i - 1] : 0; + var kst = kstList[i]; + var kstSignal = kstSignalList[i]; + var prevKst = i >= 1 ? kstList[i - 1] : 0; + var prevKstSignal = i >= 1 ? kstSignalList[i - 1] : 0; var signal = GetCompareSignal(kst - kstSignal, prevKst - prevKstSignal); signalsList.Add(signal); @@ -5797,27 +5797,27 @@ public static StockData CalculateKaseIndicator(this StockData stockData, MovingA List signalsList = new(); var (_, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - double sqrtPeriod = Sqrt(length); + var sqrtPeriod = Sqrt(length); var volumeSmaList = GetMovingAverageList(stockData, maType, length, volumeList); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double avgTrueRange = atrList[i]; - double avgVolSma = volumeSmaList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double ratio = avgVolSma * sqrtPeriod; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var avgTrueRange = atrList[i]; + var avgVolSma = volumeSmaList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var ratio = avgVolSma * sqrtPeriod; - double prevKUp = kUpList.LastOrDefault(); - double kUp = avgTrueRange > 0 && ratio != 0 && currentLow != 0 ? prevHigh / currentLow / ratio : prevKUp; + var prevKUp = kUpList.LastOrDefault(); + var kUp = avgTrueRange > 0 && ratio != 0 && currentLow != 0 ? prevHigh / currentLow / ratio : prevKUp; kUpList.AddRounded(kUp); - double prevKDown = kDownList.LastOrDefault(); - double kDown = avgTrueRange > 0 && ratio != 0 && prevLow != 0 ? currentHigh / prevLow / ratio : prevKDown; + var prevKDown = kDownList.LastOrDefault(); + var kDown = avgTrueRange > 0 && ratio != 0 && prevLow != 0 ? currentHigh / prevLow / ratio : prevKDown; kDownList.AddRounded(kDown); var signal = GetCompareSignal(kUp - kDown, prevKUp - prevKDown); @@ -5854,15 +5854,15 @@ public static StockData CalculateKendallRankCorrelationCoefficient(this StockDat var linRegList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevKendall1 = i >= 1 ? kendallCorrelationList[i - 1] : 0; - double prevKendall2 = i >= 2 ? kendallCorrelationList[i - 2] : 0; + var prevKendall1 = i >= 1 ? kendallCorrelationList[i - 1] : 0; + var prevKendall2 = i >= 2 ? kendallCorrelationList[i - 2] : 0; - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double linReg = linRegList[i]; + var linReg = linRegList[i]; tempLinRegList.AddRounded(linReg); var pearsonCorrelation = Correlation.Pearson(tempLinRegList.TakeLastExt(length).Select(x => (double)x), @@ -5870,21 +5870,21 @@ public static StockData CalculateKendallRankCorrelationCoefficient(this StockDat pearsonCorrelation = IsValueNullOrInfinity(pearsonCorrelation) ? 0 : pearsonCorrelation; pearsonCorrelationList.AddRounded((double)pearsonCorrelation); - double totalPairs = length * (double)(length - 1) / 2; + var totalPairs = length * (double)(length - 1) / 2; double numerator = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - for (int k = 0; k <= j; k++) + for (var k = 0; k <= j; k++) { - double prevValueJ = i >= j ? inputList[i - j] : 0; - double prevValueK = i >= k ? inputList[i - k] : 0; - double prevLinRegJ = i >= j ? linRegList[i - j] : 0; - double prevLinRegK = i >= k ? linRegList[i - k] : 0; + var prevValueJ = i >= j ? inputList[i - j] : 0; + var prevValueK = i >= k ? inputList[i - k] : 0; + var prevLinRegJ = i >= j ? linRegList[i - j] : 0; + var prevLinRegK = i >= k ? linRegList[i - k] : 0; numerator += Math.Sign(prevLinRegJ - prevLinRegK) * Math.Sign(prevValueJ - prevValueK); } } - double kendallCorrelation = numerator / totalPairs; + var kendallCorrelation = numerator / totalPairs; kendallCorrelationList.AddRounded(kendallCorrelation); var signal = GetCompareSignal(kendallCorrelation - prevKendall1, prevKendall1 - prevKendall2); @@ -5922,27 +5922,27 @@ public static StockData CalculateKwanIndicator(this StockData stockData, MovingA var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double priorClose = i >= length ? inputList[i - length] : 0; - double mom = priorClose != 0 ? currentClose / priorClose * 100 : 0; - double rsi = rsiList[i]; - double hh = highestList[i]; - double ll = lowestList[i]; - double sto = hh - ll != 0 ? (currentClose - ll) / (hh - ll) * 100 : 0; - double prevVr = i >= smoothLength ? vrList[i - smoothLength] : 0; - double prevKnrp1 = i >= 1 ? knrpList[i - 1] : 0; - double prevKnrp2 = i >= 2 ? knrpList[i - 2] : 0; + var currentClose = inputList[i]; + var priorClose = i >= length ? inputList[i - length] : 0; + var mom = priorClose != 0 ? currentClose / priorClose * 100 : 0; + var rsi = rsiList[i]; + var hh = highestList[i]; + var ll = lowestList[i]; + var sto = hh - ll != 0 ? (currentClose - ll) / (hh - ll) * 100 : 0; + var prevVr = i >= smoothLength ? vrList[i - smoothLength] : 0; + var prevKnrp1 = i >= 1 ? knrpList[i - 1] : 0; + var prevKnrp2 = i >= 2 ? knrpList[i - 2] : 0; - double vr = mom != 0 ? sto * rsi / mom : 0; + var vr = mom != 0 ? sto * rsi / mom : 0; vrList.AddRounded(vr); - double prev = prevVr; + var prev = prevVr; prevList.AddRounded(prev); - double vrSum = prevList.Sum(); - double knrp = vrSum / smoothLength; + var vrSum = prevList.Sum(); + var knrp = vrSum / smoothLength; knrpList.AddRounded(knrp); var signal = GetCompareSignal(knrp - prevKnrp1, prevKnrp1 - prevKnrp2); @@ -5979,30 +5979,30 @@ public static StockData CalculateKaufmanStressIndicator(this StockData stockData if (stockData.Count == marketData.Count) { - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highestHigh1 = highestList1[i]; - double lowestLow1 = lowestList1[i]; - double highestHigh2 = highestList2[i]; - double lowestLow2 = lowestList2[i]; - double currentValue1 = inputList1[i]; - double currentValue2 = inputList2[i]; - double prevSv1 = i >= 1 ? svList[i - 1] : 0; - double prevSv2 = i >= 2 ? svList[i - 2] : 0; - double r1 = highestHigh1 - lowestLow1; - double r2 = highestHigh2 - lowestLow2; - double s1 = r1 != 0 ? (currentValue1 - lowestLow1) / r1 : 50; - double s2 = r2 != 0 ? (currentValue2 - lowestLow2) / r2 : 50; - - double d = s1 - s2; + var highestHigh1 = highestList1[i]; + var lowestLow1 = lowestList1[i]; + var highestHigh2 = highestList2[i]; + var lowestLow2 = lowestList2[i]; + var currentValue1 = inputList1[i]; + var currentValue2 = inputList2[i]; + var prevSv1 = i >= 1 ? svList[i - 1] : 0; + var prevSv2 = i >= 2 ? svList[i - 2] : 0; + var r1 = highestHigh1 - lowestLow1; + var r2 = highestHigh2 - lowestLow2; + var s1 = r1 != 0 ? (currentValue1 - lowestLow1) / r1 : 50; + var s2 = r2 != 0 ? (currentValue2 - lowestLow2) / r2 : 50; + + var d = s1 - s2; dList.AddRounded(d); var list = dList.TakeLastExt(length).ToList(); - double highestD = list.Max(); - double lowestD = list.Min(); - double r11 = highestD - lowestD; + var highestD = list.Max(); + var lowestD = list.Min(); + var r11 = highestD - lowestD; - double sv = r11 != 0 ? MinOrMax(100 * (d - lowestD) / r11, 100, 0) : 50; + var sv = r11 != 0 ? MinOrMax(100 * (d - lowestD) / r11, 100, 0) : 50; svList.AddRounded(sv); var signal = GetRsiSignal(sv - prevSv1, prevSv1 - prevSv2, sv, prevSv1, 90, 10); @@ -6043,35 +6043,35 @@ public static StockData CalculateVostroIndicator(this StockData stockData, Movin var wmaList = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double wma = wmaList[i]; - double prevBuff109_1 = i >= 1 ? iBuff109List[i - 1] : 0; - double prevBuff109_2 = i >= 2 ? iBuff109List[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var wma = wmaList[i]; + var prevBuff109_1 = i >= 1 ? iBuff109List[i - 1] : 0; + var prevBuff109_2 = i >= 2 ? iBuff109List[i - 2] : 0; - double medianPrice = inputList[i]; + var medianPrice = inputList[i]; tempList.AddRounded(medianPrice); - double range = currentHigh - currentLow; + var range = currentHigh - currentLow; rangeList.AddRounded(range); - double gd120 = tempList.TakeLastExt(length1).Sum(); - double gd128 = gd120 * 0.2; - double gd121 = rangeList.TakeLastExt(length1).Sum(); - double gd136 = gd121 * 0.2 * 0.2; + var gd120 = tempList.TakeLastExt(length1).Sum(); + var gd128 = gd120 * 0.2; + var gd121 = rangeList.TakeLastExt(length1).Sum(); + var gd136 = gd121 * 0.2 * 0.2; - double prevIBuff116 = iBuff116List.LastOrDefault(); - double iBuff116 = gd136 != 0 ? (currentLow - gd128) / gd136 : 0; + var prevIBuff116 = iBuff116List.LastOrDefault(); + var iBuff116 = gd136 != 0 ? (currentLow - gd128) / gd136 : 0; iBuff116List.AddRounded(iBuff116); - double prevIBuff112 = iBuff112List.LastOrDefault(); - double iBuff112 = gd136 != 0 ? (currentHigh - gd128) / gd136 : 0; + var prevIBuff112 = iBuff112List.LastOrDefault(); + var iBuff112 = gd136 != 0 ? (currentHigh - gd128) / gd136 : 0; iBuff112List.AddRounded(iBuff112); double iBuff108 = iBuff112 > level && currentHigh > wma ? 90 : iBuff116 < -level && currentLow < wma ? -90 : 0; - double iBuff109 = (iBuff112 > level && prevIBuff112 > level) || (iBuff116 < -level && prevIBuff116 < -level) ? 0 : iBuff108; + var iBuff109 = (iBuff112 > level && prevIBuff112 > level) || (iBuff116 < -level && prevIBuff116 < -level) ? 0 : iBuff108; iBuff109List.AddRounded(iBuff109); var signal = GetRsiSignal(iBuff109 - prevBuff109_1, prevBuff109_1 - prevBuff109_2, iBuff109, prevBuff109_1, 80, -80); @@ -6107,67 +6107,67 @@ public static StockData CalculateValueChartIndicator(this StockData stockData, M List signalsList = new(); var (inputList, highList, lowList, openList, closeList, _) = GetInputValuesList(inputName, stockData); - int varp = MinOrMax((int)Math.Ceiling((double)length / 5)); + var varp = MinOrMax((int)Math.Ceiling((double)length / 5)); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, varp); var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) - { - double currentClose = closeList[i]; - double prevClose1 = i >= 1 ? closeList[i - 1] : 0; - double prevHighest1 = i >= 1 ? highestList[i - 1] : 0; - double prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; - double prevClose2 = i >= 2 ? closeList[i - 2] : 0; - double prevHighest2 = i >= 2 ? highestList[i - 2] : 0; - double prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; - double prevClose3 = i >= 3 ? closeList[i - 3] : 0; - double prevHighest3 = i >= 3 ? highestList[i - 3] : 0; - double prevLowest3 = i >= 3 ? lowestList[i - 3] : 0; - double prevClose4 = i >= 4 ? closeList[i - 4] : 0; - double prevHighest4 = i >= 4 ? highestList[i - 4] : 0; - double prevLowest4 = i >= 4 ? lowestList[i - 4] : 0; - double prevClose5 = i >= 5 ? closeList[i - 5] : 0; - double mba = smaList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double vara = highest - lowest; - double varr1 = vara == 0 && varp == 1 ? Math.Abs(currentClose - prevClose1) : vara; - double varb = prevHighest1 - prevLowest1; - double varr2 = varb == 0 && varp == 1 ? Math.Abs(prevClose1 - prevClose2) : varb; - double varc = prevHighest2 - prevLowest2; - double varr3 = varc == 0 && varp == 1 ? Math.Abs(prevClose2 - prevClose3) : varc; - double vard = prevHighest3 - prevLowest3; - double varr4 = vard == 0 && varp == 1 ? Math.Abs(prevClose3 - prevClose4) : vard; - double vare = prevHighest4 - prevLowest4; - double varr5 = vare == 0 && varp == 1 ? Math.Abs(prevClose4 - prevClose5) : vare; - double cdelta = Math.Abs(currentClose - prevClose1); - double var0 = cdelta > currentHigh - currentLow || currentHigh == currentLow ? cdelta : currentHigh - currentLow; - double lRange = (varr1 + varr2 + varr3 + varr4 + varr5) / 5 * 0.2; - - double vClose = lRange != 0 ? (currentClose - mba) / lRange : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentClose = closeList[i]; + var prevClose1 = i >= 1 ? closeList[i - 1] : 0; + var prevHighest1 = i >= 1 ? highestList[i - 1] : 0; + var prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; + var prevClose2 = i >= 2 ? closeList[i - 2] : 0; + var prevHighest2 = i >= 2 ? highestList[i - 2] : 0; + var prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; + var prevClose3 = i >= 3 ? closeList[i - 3] : 0; + var prevHighest3 = i >= 3 ? highestList[i - 3] : 0; + var prevLowest3 = i >= 3 ? lowestList[i - 3] : 0; + var prevClose4 = i >= 4 ? closeList[i - 4] : 0; + var prevHighest4 = i >= 4 ? highestList[i - 4] : 0; + var prevLowest4 = i >= 4 ? lowestList[i - 4] : 0; + var prevClose5 = i >= 5 ? closeList[i - 5] : 0; + var mba = smaList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var vara = highest - lowest; + var varr1 = vara == 0 && varp == 1 ? Math.Abs(currentClose - prevClose1) : vara; + var varb = prevHighest1 - prevLowest1; + var varr2 = varb == 0 && varp == 1 ? Math.Abs(prevClose1 - prevClose2) : varb; + var varc = prevHighest2 - prevLowest2; + var varr3 = varc == 0 && varp == 1 ? Math.Abs(prevClose2 - prevClose3) : varc; + var vard = prevHighest3 - prevLowest3; + var varr4 = vard == 0 && varp == 1 ? Math.Abs(prevClose3 - prevClose4) : vard; + var vare = prevHighest4 - prevLowest4; + var varr5 = vare == 0 && varp == 1 ? Math.Abs(prevClose4 - prevClose5) : vare; + var cdelta = Math.Abs(currentClose - prevClose1); + var var0 = cdelta > currentHigh - currentLow || currentHigh == currentLow ? cdelta : currentHigh - currentLow; + var lRange = (varr1 + varr2 + varr3 + varr4 + varr5) / 5 * 0.2; + + var vClose = lRange != 0 ? (currentClose - mba) / lRange : 0; vCloseList.AddRounded(vClose); - double vOpen = lRange != 0 ? (currentOpen - mba) / lRange : 0; + var vOpen = lRange != 0 ? (currentOpen - mba) / lRange : 0; vOpenList.AddRounded(vOpen); - double vHigh = lRange != 0 ? (currentHigh - mba) / lRange : 0; + var vHigh = lRange != 0 ? (currentHigh - mba) / lRange : 0; vHighList.AddRounded(vHigh); - double vLow = lRange != 0 ? (currentLow - mba) / lRange : 0; + var vLow = lRange != 0 ? (currentLow - mba) / lRange : 0; vLowList.AddRounded(vLow); } var vValueEmaList = GetMovingAverageList(stockData, maType, length, vCloseList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vValue = vCloseList[i]; - double vValueEma = vValueEmaList[i]; - double prevVvalue = i >= 1 ? vCloseList[i - 1] : 0; - double prevVValueEma = i >= 1 ? vValueEmaList[i - 1] : 0; + var vValue = vCloseList[i]; + var vValueEma = vValueEmaList[i]; + var prevVvalue = i >= 1 ? vCloseList[i - 1] : 0; + var prevVValueEma = i >= 1 ? vValueEmaList[i - 1] : 0; var signal = GetRsiSignal(vValue - vValueEma, prevVvalue - prevVValueEma, vValue, prevVvalue, 4, -4); signalsList.Add(signal); @@ -6222,31 +6222,31 @@ public static StockData CalculateVervoortSmoothedOscillator(this StockData stock var r9List = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, length3, r8List); var r10List = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, length3, r9List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double r1 = r1List[i]; - double r2 = r2List[i]; - double r3 = r3List[i]; - double r4 = r4List[i]; - double r5 = r5List[i]; - double r6 = r6List[i]; - double r7 = r7List[i]; - double r8 = r8List[i]; - double r9 = r9List[i]; - double r10 = r10List[i]; + var r1 = r1List[i]; + var r2 = r2List[i]; + var r3 = r3List[i]; + var r4 = r4List[i]; + var r5 = r5List[i]; + var r6 = r6List[i]; + var r7 = r7List[i]; + var r8 = r8List[i]; + var r9 = r9List[i]; + var r10 = r10List[i]; - double rainbow = ((5 * r1) + (4 * r2) + (3 * r3) + (2 * r4) + r5 + r6 + r7 + r8 + r9 + r10) / 20; + var rainbow = ((5 * r1) + (4 * r2) + (3 * r3) + (2 * r4) + r5 + r6 + r7 + r8 + r9 + r10) / 20; rainbowList.AddRounded(rainbow); } var ema1List = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, smoothLength, rainbowList); var ema2List = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, smoothLength, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema1 = ema1List[i]; - double ema2 = ema2List[i]; + var ema1 = ema1List[i]; + var ema2 = ema2List[i]; - double zlrb = (2 * ema1) - ema2; + var zlrb = (2 * ema1) - ema2; zlrbList.AddRounded(zlrb); } @@ -6254,32 +6254,32 @@ public static StockData CalculateVervoortSmoothedOscillator(this StockData stock stockData.CustomValuesList = tzList; var hwidthList = CalculateStandardDeviationVolatility(stockData, length: length1).CustomValuesList; var wmatzList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, length1, tzList); - for (int i = 0; i < stockData.Count; i++) - { - double currentTypicalPrice = inputList[i]; - double rainbow = rainbowList[i]; - double tz = tzList[i]; - double hwidth = hwidthList[i]; - double wmatz = wmatzList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - - double prevZlrbpercb = zlrbpercbList.LastOrDefault(); - double zlrbpercb = hwidth != 0 ? (tz + (stdDevMult * hwidth) - wmatz) / (2 * stdDevMult * hwidth * 100) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentTypicalPrice = inputList[i]; + var rainbow = rainbowList[i]; + var tz = tzList[i]; + var hwidth = hwidthList[i]; + var wmatz = wmatzList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + + var prevZlrbpercb = zlrbpercbList.LastOrDefault(); + var zlrbpercb = hwidth != 0 ? (tz + (stdDevMult * hwidth) - wmatz) / (2 * stdDevMult * hwidth * 100) : 0; zlrbpercbList.AddRounded(zlrbpercb); - double rbc = (rainbow + currentTypicalPrice) / 2; + var rbc = (rainbow + currentTypicalPrice) / 2; rbcList.AddRounded(rbc); - double lowestRbc = rbcList.TakeLastExt(length2).Min(); - double nom = rbc - lowest; - double den = highest - lowestRbc; + var lowestRbc = rbcList.TakeLastExt(length2).Min(); + var nom = rbc - lowest; + var den = highest - lowestRbc; - double fastK = den != 0 ? MinOrMax(100 * nom / den, 100, 0) : 0; + var fastK = den != 0 ? MinOrMax(100 * nom / den, 100, 0) : 0; fastKList.AddRounded(fastK); - double prevSk = skList.LastOrDefault(); - double sk = fastKList.TakeLastExt(smoothLength).Average(); + var prevSk = skList.LastOrDefault(); + var sk = fastKList.TakeLastExt(smoothLength).Average(); skList.AddRounded(sk); var signal = GetConditionSignal(sk > prevSk && zlrbpercb > prevZlrbpercb, sk < prevSk && zlrbpercb < prevZlrbpercb); @@ -6324,21 +6324,21 @@ public static StockData CalculateVervoortHeikenAshiLongTermCandlestickOscillator List signalsList = new(); var (inputList, highList, lowList, openList, closeList, _) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHao = haoList.LastOrDefault(); - double hao = (prevValue + prevHao) / 2; + var prevHao = haoList.LastOrDefault(); + var hao = (prevValue + prevHao) / 2; haoList.AddRounded(hao); - double hac = (currentValue + hao + Math.Max(currentHigh, hao) + Math.Min(currentLow, hao)) / 4; + var hac = (currentValue + hao + Math.Max(currentHigh, hao) + Math.Min(currentLow, hao)) / 4; hacList.AddRounded(hac); - double medianPrice = (currentHigh + currentLow) / 2; + var medianPrice = (currentHigh + currentLow) / 2; medianPriceList.AddRounded(medianPrice); } @@ -6346,57 +6346,57 @@ public static StockData CalculateVervoortHeikenAshiLongTermCandlestickOscillator var thl2List = GetMovingAverageList(stockData, maType, length, medianPriceList); var tacTemaList = GetMovingAverageList(stockData, maType, length, tacList); var thl2TemaList = GetMovingAverageList(stockData, maType, length, thl2List); - for (int i = 0; i < stockData.Count; i++) - { - double tac = tacList[i]; - double tacTema = tacTemaList[i]; - double thl2 = thl2List[i]; - double thl2Tema = thl2TemaList[i]; - double currentOpen = openList[i]; - double currentClose = closeList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double hac = hacList[i]; - double hao = haoList[i]; - double prevHac = i >= 1 ? hacList[i - 1] : 0; - double prevHao = i >= 1 ? haoList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 1 ? closeList[i - 1] : 0; - double hacSmooth = (2 * tac) - tacTema; - double hl2Smooth = (2 * thl2) - thl2Tema; - - bool shortCandle = Math.Abs(currentClose - currentOpen) < (currentHigh - currentLow) * factor; - bool prevKeepN1 = keepN1List.LastOrDefault(); - bool keepN1 = ((hac >= hao) && (prevHac >= prevHao)) || currentClose >= hac || currentHigh > prevHigh || currentLow > prevLow || hl2Smooth >= hacSmooth; + for (var i = 0; i < stockData.Count; i++) + { + var tac = tacList[i]; + var tacTema = tacTemaList[i]; + var thl2 = thl2List[i]; + var thl2Tema = thl2TemaList[i]; + var currentOpen = openList[i]; + var currentClose = closeList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var hac = hacList[i]; + var hao = haoList[i]; + var prevHac = i >= 1 ? hacList[i - 1] : 0; + var prevHao = i >= 1 ? haoList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 1 ? closeList[i - 1] : 0; + var hacSmooth = (2 * tac) - tacTema; + var hl2Smooth = (2 * thl2) - thl2Tema; + + var shortCandle = Math.Abs(currentClose - currentOpen) < (currentHigh - currentLow) * factor; + var prevKeepN1 = keepN1List.LastOrDefault(); + var keepN1 = ((hac >= hao) && (prevHac >= prevHao)) || currentClose >= hac || currentHigh > prevHigh || currentLow > prevLow || hl2Smooth >= hacSmooth; keepN1List.Add(keepN1); - bool prevKeepAll1 = keepAll1List.LastOrDefault(); - bool keepAll1 = keepN1 || (prevKeepN1 && (currentClose >= currentOpen || currentClose >= prevClose)); + var prevKeepAll1 = keepAll1List.LastOrDefault(); + var keepAll1 = keepN1 || (prevKeepN1 && (currentClose >= currentOpen || currentClose >= prevClose)); keepAll1List.Add(keepAll1); - bool keep13 = shortCandle && currentHigh >= prevLow; - bool prevUtr = utrList.LastOrDefault(); - bool utr = keepAll1 || (prevKeepAll1 && keep13); + var keep13 = shortCandle && currentHigh >= prevLow; + var prevUtr = utrList.LastOrDefault(); + var utr = keepAll1 || (prevKeepAll1 && keep13); utrList.Add(utr); - bool prevKeepN2 = keepN2List.LastOrDefault(); - bool keepN2 = (hac < hao && prevHac < prevHao) || hl2Smooth < hacSmooth; + var prevKeepN2 = keepN2List.LastOrDefault(); + var keepN2 = (hac < hao && prevHac < prevHao) || hl2Smooth < hacSmooth; keepN2List.Add(keepN2); - bool keep23 = shortCandle && currentLow <= prevHigh; - bool prevKeepAll2 = keepAll2List.LastOrDefault(); - bool keepAll2 = keepN2 || (prevKeepN2 && (currentClose < currentOpen || currentClose < prevClose)); + var keep23 = shortCandle && currentLow <= prevHigh; + var prevKeepAll2 = keepAll2List.LastOrDefault(); + var keepAll2 = keepN2 || (prevKeepN2 && (currentClose < currentOpen || currentClose < prevClose)); keepAll2List.Add(keepAll2); - bool prevDtr = dtrList.LastOrDefault(); - bool dtr = (keepAll2 || prevKeepAll2) && keep23; + var prevDtr = dtrList.LastOrDefault(); + var dtr = (keepAll2 || prevKeepAll2) && keep23; dtrList.Add(dtr); - bool upw = dtr == false && prevDtr && utr; - bool dnw = utr == false && prevUtr && dtr; - double prevHaco = hacoList.LastOrDefault(); - double haco = upw ? 1 : dnw ? -1 : prevHaco; + var upw = dtr == false && prevDtr && utr; + var dnw = utr == false && prevUtr && dtr; + var prevHaco = hacoList.LastOrDefault(); + var haco = upw ? 1 : dnw ? -1 : prevHaco; hacoList.AddRounded(haco); var signal = GetCompareSignal(haco, prevHaco); @@ -6432,13 +6432,13 @@ public static StockData CalculateVixTradingSystem(this StockData stockData, Movi var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double vixts = smaList[i]; + var currentValue = inputList[i]; + var vixts = smaList[i]; - double prevCount = countList.LastOrDefault(); - double count = currentValue > vixts && prevCount >= 0 ? prevCount + 1 : currentValue <= vixts && prevCount <= 0 ? + var prevCount = countList.LastOrDefault(); + var count = currentValue > vixts && prevCount >= 0 ? prevCount + 1 : currentValue <= vixts && prevCount <= 0 ? prevCount - 1 : prevCount; countList.AddRounded(count); @@ -6474,28 +6474,28 @@ public static StockData CalculateVaradiOscillator(this StockData stockData, Movi List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double median = (currentHigh + currentLow) / 2; + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var median = (currentHigh + currentLow) / 2; - double ratio = median != 0 ? currentValue / median : 0; + var ratio = median != 0 ? currentValue / median : 0; ratioList.AddRounded(ratio); } var aList = GetMovingAverageList(stockData, maType, length, ratioList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = aList[i]; - double prevDvo1 = i >= 1 ? dvoList[i - 1] : 0; - double prevDvo2 = i >= 2 ? dvoList[i - 2] : 0; + var a = aList[i]; + var prevDvo1 = i >= 1 ? dvoList[i - 1] : 0; + var prevDvo2 = i >= 2 ? dvoList[i - 2] : 0; - double prevA = i >= 1 ? aList[i - 1] : 0; + var prevA = i >= 1 ? aList[i - 1] : 0; tempList.AddRounded(prevA); - double dvo = MinOrMax((double)tempList.TakeLastExt(length).Where(i => i <= a).Count() / length * 100, 100, 0); + var dvo = MinOrMax((double)tempList.TakeLastExt(length).Where(i => i <= a).Count() / length * 100, 100, 0); dvoList.AddRounded(dvo); var signal = GetRsiSignal(dvo - prevDvo1, prevDvo1 - prevDvo2, dvo, prevDvo1, 80, 20); @@ -6526,26 +6526,26 @@ public static StockData CalculateVanillaABCDPattern(this StockData stockData) List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentValue = inputList[i]; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevValue3 = i >= 3 ? inputList[i - 3] : 0; + var currentOpen = openList[i]; + var currentValue = inputList[i]; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevValue3 = i >= 3 ? inputList[i - 3] : 0; double up = prevValue3 > prevValue2 && prevValue1 > prevValue2 && currentValue < prevValue2 ? 1 : 0; double dn = prevValue3 < prevValue2 && prevValue1 < prevValue2 && currentValue > prevValue2 ? 1 : 0; - double prevOs = osList.LastOrDefault(); - double os = up == 1 ? 1 : dn == 1 ? 0 : prevOs; + var prevOs = osList.LastOrDefault(); + var os = up == 1 ? 1 : dn == 1 ? 0 : prevOs; osList.AddRounded(os); - double prevF = fList.LastOrDefault(); - double f = os == 1 && currentValue > currentOpen ? 1 : os == 0 && currentValue < currentOpen ? 0 : prevF; + var prevF = fList.LastOrDefault(); + var f = os == 1 && currentValue > currentOpen ? 1 : os == 0 && currentValue < currentOpen ? 0 : prevF; fList.AddRounded(f); - double prevDos = dosList.LastOrDefault(); - double dos = os - prevOs; + var prevDos = dosList.LastOrDefault(); + var dos = os - prevOs; dosList.AddRounded(dos); var signal = GetCompareSignal(dos, prevDos); @@ -6587,21 +6587,21 @@ public static StockData CalculateVervoortHeikenAshiCandlestickOscillator(this St List signalsList = new(); var (inputList, highList, lowList, openList, closeList, _) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHao = haoList.LastOrDefault(); - double hao = (prevValue + prevHao) / 2; + var prevHao = haoList.LastOrDefault(); + var hao = (prevValue + prevHao) / 2; haoList.AddRounded(hao); - double hac = (currentValue + hao + Math.Max(currentHigh, hao) + Math.Min(currentLow, hao)) / 4; + var hac = (currentValue + hao + Math.Max(currentHigh, hao) + Math.Min(currentLow, hao)) / 4; hacList.AddRounded(hac); - double medianPrice = (currentHigh + currentLow) / 2; + var medianPrice = (currentHigh + currentLow) / 2; medianPriceList.AddRounded(medianPrice); } @@ -6609,65 +6609,65 @@ public static StockData CalculateVervoortHeikenAshiCandlestickOscillator(this St var tma2List = GetMovingAverageList(stockData, maType, length, tma1List); var tma12List = GetMovingAverageList(stockData, maType, length, medianPriceList); var tma22List = GetMovingAverageList(stockData, maType, length, tma12List); - for (int i = 0; i < stockData.Count; i++) - { - double tma1 = tma1List[i]; - double tma2 = tma2List[i]; - double tma12 = tma12List[i]; - double tma22 = tma22List[i]; - double hao = haoList[i]; - double hac = hacList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = closeList[i]; - double prevHao = i >= 1 ? haoList[i - 1] : 0; - double prevHac = i >= 1 ? hacList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 1 ? closeList[i - 1] : 0; - double diff = tma1 - tma2; - double zlHa = tma1 + diff; - double diff2 = tma12 - tma22; - double zlCl = tma12 + diff2; - double zlDiff = zlCl - zlHa; - bool dnKeep1 = hac < hao && prevHac < prevHao; - bool dnKeep2 = zlDiff < 0; - bool dnKeep3 = Math.Abs(currentClose - currentOpen) < (currentHigh - currentLow) * 0.35 && currentLow <= prevHigh; - - bool prevDnKeeping = dnKeepingList.LastOrDefault(); - bool dnKeeping = dnKeep1 || dnKeep2; + for (var i = 0; i < stockData.Count; i++) + { + var tma1 = tma1List[i]; + var tma2 = tma2List[i]; + var tma12 = tma12List[i]; + var tma22 = tma22List[i]; + var hao = haoList[i]; + var hac = hacList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = closeList[i]; + var prevHao = i >= 1 ? haoList[i - 1] : 0; + var prevHac = i >= 1 ? hacList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 1 ? closeList[i - 1] : 0; + var diff = tma1 - tma2; + var zlHa = tma1 + diff; + var diff2 = tma12 - tma22; + var zlCl = tma12 + diff2; + var zlDiff = zlCl - zlHa; + var dnKeep1 = hac < hao && prevHac < prevHao; + var dnKeep2 = zlDiff < 0; + var dnKeep3 = Math.Abs(currentClose - currentOpen) < (currentHigh - currentLow) * 0.35 && currentLow <= prevHigh; + + var prevDnKeeping = dnKeepingList.LastOrDefault(); + var dnKeeping = dnKeep1 || dnKeep2; dnKeepingList.Add(dnKeeping); - bool prevDnKeepAll = dnKeepAllList.LastOrDefault(); - bool dnKeepAll = (dnKeeping || prevDnKeeping) && ((currentClose < currentOpen) || (currentClose < prevClose)); + var prevDnKeepAll = dnKeepAllList.LastOrDefault(); + var dnKeepAll = (dnKeeping || prevDnKeeping) && ((currentClose < currentOpen) || (currentClose < prevClose)); dnKeepAllList.Add(dnKeepAll); - bool prevDnTrend = dnTrendList.LastOrDefault(); - bool dnTrend = dnKeepAll || (prevDnKeepAll && dnKeep3); + var prevDnTrend = dnTrendList.LastOrDefault(); + var dnTrend = dnKeepAll || (prevDnKeepAll && dnKeep3); dnTrendList.Add(dnTrend); - bool upKeep1 = hac >= hao && prevHac >= prevHao; - bool upKeep2 = zlDiff >= 0; - bool upKeep3 = Math.Abs(currentClose - currentOpen) < (currentHigh - currentLow) * 0.35 && currentHigh >= prevLow; + var upKeep1 = hac >= hao && prevHac >= prevHao; + var upKeep2 = zlDiff >= 0; + var upKeep3 = Math.Abs(currentClose - currentOpen) < (currentHigh - currentLow) * 0.35 && currentHigh >= prevLow; - bool prevUpKeeping = upKeepingList.LastOrDefault(); - bool upKeeping = upKeep1 || upKeep2; + var prevUpKeeping = upKeepingList.LastOrDefault(); + var upKeeping = upKeep1 || upKeep2; upKeepingList.Add(upKeeping); - bool prevUpKeepAll = upKeepAllList.LastOrDefault(); - bool upKeepAll = (upKeeping || prevUpKeeping) && ((currentClose >= currentOpen) || (currentClose >= prevClose)); + var prevUpKeepAll = upKeepAllList.LastOrDefault(); + var upKeepAll = (upKeeping || prevUpKeeping) && ((currentClose >= currentOpen) || (currentClose >= prevClose)); upKeepAllList.Add(upKeepAll); - bool prevUpTrend = upTrendList.LastOrDefault(); - bool upTrend = upKeepAll || (prevUpKeepAll && upKeep3); + var prevUpTrend = upTrendList.LastOrDefault(); + var upTrend = upKeepAll || (prevUpKeepAll && upKeep3); upTrendList.Add(upTrend); - bool upw = dnTrend == false && prevDnTrend && upTrend; - bool dnw = upTrend == false && prevUpTrend && dnTrend; + var upw = dnTrend == false && prevDnTrend && upTrend; + var dnw = upTrend == false && prevUpTrend && dnTrend; - double prevHaco = hacoList.LastOrDefault(); - double haco = upw ? 1 : dnw ? -1 : prevHaco; + var prevHaco = hacoList.LastOrDefault(); + var haco = upw ? 1 : dnw ? -1 : prevHaco; hacoList.AddRounded(haco); var signal = GetCompareSignal(haco, prevHaco); @@ -6706,27 +6706,27 @@ public static StockData CalculateChartmillValueIndicator(this StockData stockDat var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; var fList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double v = atrList[i]; - double f = fList[i]; - double prevCmvc1 = i >= 1 ? cmvCList[i - 1] : 0; - double prevCmvc2 = i >= 2 ? cmvCList[i - 2] : 0; - double currentClose = closeList[i]; - double currentOpen = openList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var v = atrList[i]; + var f = fList[i]; + var prevCmvc1 = i >= 1 ? cmvCList[i - 1] : 0; + var prevCmvc2 = i >= 2 ? cmvCList[i - 2] : 0; + var currentClose = closeList[i]; + var currentOpen = openList[i]; - double cmvC = v != 0 ? MinOrMax((currentClose - f) / (v * Pow(length, 0.5)), 1, -1) : 0; + var cmvC = v != 0 ? MinOrMax((currentClose - f) / (v * Pow(length, 0.5)), 1, -1) : 0; cmvCList.AddRounded(cmvC); - double cmvO = v != 0 ? MinOrMax((currentOpen - f) / (v * Pow(length, 0.5)), 1, -1) : 0; + var cmvO = v != 0 ? MinOrMax((currentOpen - f) / (v * Pow(length, 0.5)), 1, -1) : 0; cmvOList.AddRounded(cmvO); - double cmvH = v != 0 ? MinOrMax((currentHigh - f) / (v * Pow(length, 0.5)), 1, -1) : 0; + var cmvH = v != 0 ? MinOrMax((currentHigh - f) / (v * Pow(length, 0.5)), 1, -1) : 0; cmvHList.AddRounded(cmvH); - double cmvL = v != 0 ? MinOrMax((currentLow - f) / (v * Pow(length, 0.5)), 1, -1) : 0; + var cmvL = v != 0 ? MinOrMax((currentLow - f) / (v * Pow(length, 0.5)), 1, -1) : 0; cmvLList.AddRounded(cmvL); var signal = GetRsiSignal(cmvC - prevCmvc1, prevCmvc1 - prevCmvc2, cmvC, prevCmvc1, 0.5, -0.5); @@ -6762,25 +6762,25 @@ public static StockData CalculateConditionalAccumulator(this StockData stockData List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevValue = valueList.LastOrDefault(); - double value = currentLow >= prevHigh ? prevValue + increment : currentHigh <= prevLow ? prevValue - increment : prevValue; + var prevValue = valueList.LastOrDefault(); + var value = currentLow >= prevHigh ? prevValue + increment : currentHigh <= prevLow ? prevValue - increment : prevValue; valueList.AddRounded(value); } var valueEmaList = GetMovingAverageList(stockData, maType, length, valueList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double value = valueList[i]; - double valueEma = valueEmaList[i]; - double prevValue = i >= 1 ? valueList[i - 1] : 0; - double prevValueEma = i >= 1 ? valueEmaList[i - 1] : 0; + var value = valueList[i]; + var valueEma = valueEmaList[i]; + var prevValue = i >= 1 ? valueList[i - 1] : 0; + var prevValueEma = i >= 1 ? valueEmaList[i - 1] : 0; var signal = GetCompareSignal(value - valueEma, prevValue - prevValueEma); signalsList.Add(signal); @@ -6810,17 +6810,17 @@ public static StockData CalculateContractHighLow(this StockData stockData) List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double prevConHi = conHiList.LastOrDefault(); - double conHi = i >= 1 ? Math.Max(prevConHi, currentHigh) : currentHigh; + var prevConHi = conHiList.LastOrDefault(); + var conHi = i >= 1 ? Math.Max(prevConHi, currentHigh) : currentHigh; conHiList.AddRounded(conHi); - double prevConLow = conLowList.LastOrDefault(); - double conLow = i >= 1 ? Math.Min(prevConLow, currentLow) : currentLow; + var prevConLow = conLowList.LastOrDefault(); + var conLow = i >= 1 ? Math.Min(prevConLow, currentLow) : currentLow; conLowList.AddRounded(conLow); var signal = GetConditionSignal(conHi > prevConHi, conLow < prevConLow); @@ -6858,20 +6858,20 @@ public static StockData CalculateChopZone(this StockData stockData, MovingAvgTyp var emaList = GetMovingAverageList(stockData, maType, length2, closeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double ema = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double range = highest - lowest != 0 ? 25 / (highest - lowest) * lowest : 0; - double avg = inputList[i]; - double y = avg != 0 && range != 0 ? (prevEma - ema) / avg * range : 0; - double c = Sqrt(1 + (y * y)); - double emaAngle1 = c != 0 ? Math.Round(Math.Acos(1 / c).ToDegrees()) : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var ema = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var range = highest - lowest != 0 ? 25 / (highest - lowest) * lowest : 0; + var avg = inputList[i]; + var y = avg != 0 && range != 0 ? (prevEma - ema) / avg * range : 0; + var c = Sqrt(1 + (y * y)); + var emaAngle1 = c != 0 ? Math.Round(Math.Acos(1 / c).ToDegrees()) : 0; - double prevEmaAngle = emaAngleList.LastOrDefault(); - double emaAngle = y > 0 ? -emaAngle1 : emaAngle1; + var prevEmaAngle = emaAngleList.LastOrDefault(); + var emaAngle = y > 0 ? -emaAngle1 : emaAngle1; emaAngleList.AddRounded(emaAngle); var signal = GetCompareSignal(emaAngle, prevEmaAngle); @@ -6902,16 +6902,16 @@ public static StockData CalculateCenterOfLinearity(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorValue = i >= length ? inputList[i - length] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorValue = i >= length ? inputList[i - length] : 0; - double a = (i + 1) * (priorValue - prevValue); + var a = (i + 1) * (priorValue - prevValue); aList.AddRounded(a); - double prevCol = colList.LastOrDefault(); - double col = aList.TakeLastExt(length).Sum(); + var prevCol = colList.LastOrDefault(); + var col = aList.TakeLastExt(length).Sum(); colList.AddRounded(col); var signal = GetCompareSignal(col, prevCol); @@ -6945,23 +6945,23 @@ public static StockData CalculateChaikinVolatility(this StockData stockData, Mov List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double highLow = currentHigh - currentLow; + var highLow = currentHigh - currentLow; highLowList.AddRounded(highLow); } var highLowEmaList = GetMovingAverageList(stockData, maType, length1, highLowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highLowEma = highLowEmaList[i]; - double prevHighLowEma = i >= length2 ? highLowEmaList[i - length2] : 0; + var highLowEma = highLowEmaList[i]; + var prevHighLowEma = i >= length2 ? highLowEmaList[i - length2] : 0; - double prevChaikinVolatility = chaikinVolatilityList.LastOrDefault(); - double chaikinVolatility = prevHighLowEma != 0 ? (highLowEma - prevHighLowEma) / prevHighLowEma * 100 : 0; + var prevChaikinVolatility = chaikinVolatilityList.LastOrDefault(); + var chaikinVolatility = prevHighLowEma != 0 ? (highLowEma - prevHighLowEma) / prevHighLowEma * 100 : 0; chaikinVolatilityList.AddRounded(chaikinVolatility); var signal = GetCompareSignal(chaikinVolatility, prevChaikinVolatility, true); @@ -7001,16 +7001,16 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, closeList, _) = GetInputValuesList(inputName, stockData); - int stl = (int)Math.Ceiling((length * 2) - 1 - 0.5m); - int itl = (int)Math.Ceiling((stl * 2) - 1 - 0.5m); - int ltl = (int)Math.Ceiling((itl * 2) - 1 - 0.5m); - int hoff = (int)Math.Ceiling(((double)length / 2) - 0.5); - int soff = (int)Math.Ceiling(((double)stl / 2) - 0.5); - int ioff = (int)Math.Ceiling(((double)itl / 2) - 0.5); - int hLength = MinOrMax(length - 1); - int sLength = stl - 1; - int iLength = itl - 1; - int lLength = ltl - 1; + var stl = (int)Math.Ceiling((length * 2) - 1 - 0.5m); + var itl = (int)Math.Ceiling((stl * 2) - 1 - 0.5m); + var ltl = (int)Math.Ceiling((itl * 2) - 1 - 0.5m); + var hoff = (int)Math.Ceiling(((double)length / 2) - 0.5); + var soff = (int)Math.Ceiling(((double)stl / 2) - 0.5); + var ioff = (int)Math.Ceiling(((double)itl / 2) - 0.5); + var hLength = MinOrMax(length - 1); + var sLength = stl - 1; + var iLength = itl - 1; + var lLength = ltl - 1; var hAvgList = GetMovingAverageList(stockData, maType, length, closeList); var sAvgList = GetMovingAverageList(stockData, maType, stl, closeList); @@ -7022,98 +7022,98 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M var l2AvgList = GetMovingAverageList(stockData, maType, lLength, closeList); var ftpAvgList = GetMovingAverageList(stockData, maType, lLength, inputList); - for (int i = 0; i < stockData.Count; i++) - { - double sAvg = sAvgList[i]; - double priorSAvg = i >= soff ? sAvgList[i - soff] : 0; - double priorHAvg = i >= hoff ? hAvgList[i - hoff] : 0; - double iAvg = iAvgList[i]; - double priorIAvg = i >= ioff ? iAvgList[i - ioff] : 0; - double lAvg = lAvgList[i]; - double hAvg = hAvgList[i]; - double prevSAvg = i >= 1 ? sAvgList[i - 1] : 0; - double prevHAvg = i >= 1 ? hAvgList[i - 1] : 0; - double prevIAvg = i >= 1 ? iAvgList[i - 1] : 0; - double prevLAvg = i >= 1 ? lAvgList[i - 1] : 0; - double h2 = h2AvgList[i]; - double s2 = s2AvgList[i]; - double i2 = i2AvgList[i]; - double l2 = l2AvgList[i]; - double ftpAvg = ftpAvgList[i]; - double priorValue5 = i >= hoff ? value5List[i - hoff] : 0; - double priorValue6 = i >= soff ? value6List[i - soff] : 0; - double priorValue7 = i >= ioff ? value7List[i - ioff] : 0; - double priorSum = i >= soff ? sumList[i - soff] : 0; - double priorHAvg2 = i >= soff ? hAvgList[i - soff] : 0; - double prevErrSum = i >= 1 ? errSumList[i - 1] : 0; - double prevMom = i >= 1 ? momList[i - 1] : 0; - double prevValue70 = i >= 1 ? value70List[i - 1] : 0; - double prevConfluence1 = i >= 1 ? confluenceList[i - 1] : 0; - double prevConfluence2 = i >= 2 ? confluenceList[i - 2] : 0; - double value2 = sAvg - priorHAvg; - double value3 = iAvg - priorSAvg; - double value12 = lAvg - priorIAvg; - double momSig = value2 + value3 + value12; - double derivH = (hAvg * 2) - prevHAvg; - double derivS = (sAvg * 2) - prevSAvg; - double derivI = (iAvg * 2) - prevIAvg; - double derivL = (lAvg * 2) - prevLAvg; - double sumDH = length * derivH; - double sumDS = stl * derivS; - double sumDI = itl * derivI; - double sumDL = ltl * derivL; - double n1h = h2 * hLength; - double n1s = s2 * sLength; - double n1i = i2 * iLength; - double n1l = l2 * lLength; - double drh = sumDH - n1h; - double drs = sumDS - n1s; - double dri = sumDI - n1i; - double drl = sumDL - n1l; - double hSum = h2 * (length - 1); - double sSum = s2 * (stl - 1); - double iSum = i2 * (itl - 1); - double lSum = ftpAvg * (ltl - 1); - - double value5 = (hSum + drh) / length; + for (var i = 0; i < stockData.Count; i++) + { + var sAvg = sAvgList[i]; + var priorSAvg = i >= soff ? sAvgList[i - soff] : 0; + var priorHAvg = i >= hoff ? hAvgList[i - hoff] : 0; + var iAvg = iAvgList[i]; + var priorIAvg = i >= ioff ? iAvgList[i - ioff] : 0; + var lAvg = lAvgList[i]; + var hAvg = hAvgList[i]; + var prevSAvg = i >= 1 ? sAvgList[i - 1] : 0; + var prevHAvg = i >= 1 ? hAvgList[i - 1] : 0; + var prevIAvg = i >= 1 ? iAvgList[i - 1] : 0; + var prevLAvg = i >= 1 ? lAvgList[i - 1] : 0; + var h2 = h2AvgList[i]; + var s2 = s2AvgList[i]; + var i2 = i2AvgList[i]; + var l2 = l2AvgList[i]; + var ftpAvg = ftpAvgList[i]; + var priorValue5 = i >= hoff ? value5List[i - hoff] : 0; + var priorValue6 = i >= soff ? value6List[i - soff] : 0; + var priorValue7 = i >= ioff ? value7List[i - ioff] : 0; + var priorSum = i >= soff ? sumList[i - soff] : 0; + var priorHAvg2 = i >= soff ? hAvgList[i - soff] : 0; + var prevErrSum = i >= 1 ? errSumList[i - 1] : 0; + var prevMom = i >= 1 ? momList[i - 1] : 0; + var prevValue70 = i >= 1 ? value70List[i - 1] : 0; + var prevConfluence1 = i >= 1 ? confluenceList[i - 1] : 0; + var prevConfluence2 = i >= 2 ? confluenceList[i - 2] : 0; + var value2 = sAvg - priorHAvg; + var value3 = iAvg - priorSAvg; + var value12 = lAvg - priorIAvg; + var momSig = value2 + value3 + value12; + var derivH = (hAvg * 2) - prevHAvg; + var derivS = (sAvg * 2) - prevSAvg; + var derivI = (iAvg * 2) - prevIAvg; + var derivL = (lAvg * 2) - prevLAvg; + var sumDH = length * derivH; + var sumDS = stl * derivS; + var sumDI = itl * derivI; + var sumDL = ltl * derivL; + var n1h = h2 * hLength; + var n1s = s2 * sLength; + var n1i = i2 * iLength; + var n1l = l2 * lLength; + var drh = sumDH - n1h; + var drs = sumDS - n1s; + var dri = sumDI - n1i; + var drl = sumDL - n1l; + var hSum = h2 * (length - 1); + var sSum = s2 * (stl - 1); + var iSum = i2 * (itl - 1); + var lSum = ftpAvg * (ltl - 1); + + var value5 = (hSum + drh) / length; value5List.AddRounded(value5); - double value6 = (sSum + drs) / stl; + var value6 = (sSum + drs) / stl; value6List.AddRounded(value6); - double value7 = (iSum + dri) / itl; + var value7 = (iSum + dri) / itl; value7List.AddRounded(value7); - double value13 = (lSum + drl) / ltl; - double value9 = value6 - priorValue5; - double value10 = value7 - priorValue6; - double value14 = value13 - priorValue7; + var value13 = (lSum + drl) / ltl; + var value9 = value6 - priorValue5; + var value10 = value7 - priorValue6; + var value14 = value13 - priorValue7; - double mom = value9 + value10 + value14; + var mom = value9 + value10 + value14; momList.AddRounded(mom); - double ht = Math.Sin(value5 * 2 * Math.PI / 360) + Math.Cos(value5 * 2 * Math.PI / 360); - double hta = Math.Sin(hAvg * 2 * Math.PI / 360) + Math.Cos(hAvg * 2 * Math.PI / 360); - double st = Math.Sin(value6 * 2 * Math.PI / 360) + Math.Cos(value6 * 2 * Math.PI / 360); - double sta = Math.Sin(sAvg * 2 * Math.PI / 360) + Math.Cos(sAvg * 2 * Math.PI / 360); - double it = Math.Sin(value7 * 2 * Math.PI / 360) + Math.Cos(value7 * 2 * Math.PI / 360); - double ita = Math.Sin(iAvg * 2 * Math.PI / 360) + Math.Cos(iAvg * 2 * Math.PI / 360); + var ht = Math.Sin(value5 * 2 * Math.PI / 360) + Math.Cos(value5 * 2 * Math.PI / 360); + var hta = Math.Sin(hAvg * 2 * Math.PI / 360) + Math.Cos(hAvg * 2 * Math.PI / 360); + var st = Math.Sin(value6 * 2 * Math.PI / 360) + Math.Cos(value6 * 2 * Math.PI / 360); + var sta = Math.Sin(sAvg * 2 * Math.PI / 360) + Math.Cos(sAvg * 2 * Math.PI / 360); + var it = Math.Sin(value7 * 2 * Math.PI / 360) + Math.Cos(value7 * 2 * Math.PI / 360); + var ita = Math.Sin(iAvg * 2 * Math.PI / 360) + Math.Cos(iAvg * 2 * Math.PI / 360); - double sum = ht + st + it; + var sum = ht + st + it; sumList.AddRounded(sum); - double err = hta + sta + ita; + var err = hta + sta + ita; double cond2 = (sum > priorSum && hAvg < priorHAvg2) || (sum < priorSum && hAvg > priorHAvg2) ? 1 : 0; double phase = cond2 == 1 ? -1 : 1; - double errSum = (sum - err) * phase; + var errSum = (sum - err) * phase; errSumList.AddRounded(errSum); - double value70 = value5 - value13; + var value70 = value5 - value13; value70List.AddRounded(value70); - double errSig = errSumList.TakeLastExt(soff).Average(); - double value71 = value70List.TakeLastExt(length).Average(); + var errSig = errSumList.TakeLastExt(soff).Average(); + var value71 = value70List.TakeLastExt(length).Average(); double errNum = errSum > 0 && errSum < prevErrSum && errSum < errSig ? 1 : errSum > 0 && errSum < prevErrSum && errSum > errSig ? 2 : errSum > 0 && errSum > prevErrSum && errSum < errSig ? 2 : errSum > 0 && errSum > prevErrSum && errSum > errSig ? 3 : errSum < 0 && errSum > prevErrSum && errSum > errSig ? -1 : errSum < 0 && errSum < prevErrSum && errSum > errSig ? -2 : @@ -7126,15 +7126,15 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M value70 > 0 && value70 > prevValue70 && value70 < value71 ? 2 : value70 > 0 && value70 > prevValue70 && value70 > value71 ? 3 : value70 < 0 && value70 > prevValue70 && value70 > value71 ? -1 : value70 < 0 && value70 < prevValue70 && value70 > value71 ? -2 : value70 < 0 && value70 > prevValue70 && value70 < value71 ? -2 : value70 < 0 && value70 < prevValue70 && value70 < value71 ? -3 : 0; - double value42 = errNum + momNum + tcNum; + var value42 = errNum + momNum + tcNum; - double confluence = value42 > 0 && value70 > 0 ? value42 : value42 < 0 && value70 < 0 ? value42 : + var confluence = value42 > 0 && value70 > 0 ? value42 : value42 < 0 && value70 < 0 ? value42 : (value42 > 0 && value70 < 0) || (value42 < 0 && value70 > 0) ? value42 / 10 : 0; confluenceList.AddRounded(confluence); - double res1 = confluence >= 1 ? confluence : 0; - double res2 = confluence <= -1 ? confluence : 0; - double res3 = confluence == 0 ? 0 : confluence > -1 && confluence < 1 ? 10 * confluence : 0; + var res1 = confluence >= 1 ? confluence : 0; + var res2 = confluence <= -1 ? confluence : 0; + var res3 = confluence == 0 ? 0 : confluence > -1 && confluence < 1 ? 10 * confluence : 0; var signal = GetCompareSignal(confluence - prevConfluence1, prevConfluence1 - prevConfluence2); signalsList.Add(signal); @@ -7169,20 +7169,20 @@ public static StockData CalculateCoppockCurve(this StockData stockData, MovingAv var roc11List = CalculateRateOfChange(stockData, fastLength).CustomValuesList; var roc14List = CalculateRateOfChange(stockData, slowLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRoc11 = roc11List[i]; - double currentRoc14 = roc14List[i]; + var currentRoc11 = roc11List[i]; + var currentRoc14 = roc14List[i]; - double rocTotal = currentRoc11 + currentRoc14; + var rocTotal = currentRoc11 + currentRoc14; rocTotalList.AddRounded(rocTotal); } var coppockCurveList = GetMovingAverageList(stockData, maType, length, rocTotalList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double coppockCurve = coppockCurveList[i]; - double prevCoppockCurve = i >= 1 ? coppockCurveList[i - 1] : 0; + var coppockCurve = coppockCurveList[i]; + var prevCoppockCurve = i >= 1 ? coppockCurveList[i - 1] : 0; var signal = GetCompareSignal(coppockCurve, prevCoppockCurve); signalsList.Add(signal); @@ -7222,29 +7222,29 @@ public static StockData CalculateConstanceBrownCompositeIndex(this StockData sto var rsi2List = CalculateRelativeStrengthIndex(stockData, length: smoothLength).CustomValuesList; var rsiSmaList = GetMovingAverageList(stockData, maType, smoothLength, rsi2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsiSma = rsiSmaList[i]; - double rsiDelta = i >= length2 ? rsi1List[i - length2] : 0; + var rsiSma = rsiSmaList[i]; + var rsiDelta = i >= length2 ? rsi1List[i - length2] : 0; - double s = rsiDelta + rsiSma; + var s = rsiDelta + rsiSma; sList.AddRounded(s); } var sFastSmaList = GetMovingAverageList(stockData, maType, fastLength, sList); var sSlowSmaList = GetMovingAverageList(stockData, maType, slowLength, sList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double s = sList[i]; - double sFastSma = sFastSmaList[i]; - double sSlowSma = sSlowSmaList[i]; + var s = sList[i]; + var sFastSma = sFastSmaList[i]; + var sSlowSma = sSlowSmaList[i]; - double prevBullSlope = bullSlopeList.LastOrDefault(); - double bullSlope = s - Math.Max(sFastSma, sSlowSma); + var prevBullSlope = bullSlopeList.LastOrDefault(); + var bullSlope = s - Math.Max(sFastSma, sSlowSma); bullSlopeList.AddRounded(bullSlope); - double prevBearSlope = bearSlopeList.LastOrDefault(); - double bearSlope = s - Math.Min(sFastSma, sSlowSma); + var prevBearSlope = bearSlopeList.LastOrDefault(); + var bearSlope = s - Math.Min(sFastSma, sSlowSma); bearSlopeList.AddRounded(bearSlope); var signal = GetBullishBearishSignal(bullSlope, prevBullSlope, bearSlope, prevBearSlope); @@ -7281,22 +7281,22 @@ public static StockData CalculateCommoditySelectionIndex(this StockData stockDat List csiSmaList = new(); List signalsList = new(); - double k = 100 * (pointValue / Sqrt(margin) / (150 + commission)); + var k = 100 * (pointValue / Sqrt(margin) / (150 + commission)); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; var adxList = CalculateAverageDirectionalIndex(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double atr = atrList[i]; - double adxRating = adxList[i]; + var atr = atrList[i]; + var adxRating = adxList[i]; - double prevCsi = csiList.LastOrDefault(); - double csi = k * atr * adxRating; + var prevCsi = csiList.LastOrDefault(); + var csi = k * atr * adxRating; csiList.AddRounded(csi); - double prevCsiSma = csiSmaList.LastOrDefault(); - double csiSma = csiList.TakeLastExt(length).Average(); + var prevCsiSma = csiSmaList.LastOrDefault(); + var csiSma = csiList.TakeLastExt(length).Average(); csiSmaList.AddRounded(csiSma); var signal = GetCompareSignal(csi - csiSma, prevCsi - prevCsiSma, true); @@ -7333,15 +7333,15 @@ public static StockData CalculatePivotDetectorOscillator(this StockData stockDat var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length2).CustomValuesList; var smaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double rsi = rsiList[i]; - double prevPdo1 = i >= 1 ? pdoList[i - 1] : 0; - double prevPdo2 = i >= 2 ? pdoList[i - 2] : 0; + var currentValue = inputList[i]; + var sma = smaList[i]; + var rsi = rsiList[i]; + var prevPdo1 = i >= 1 ? pdoList[i - 1] : 0; + var prevPdo2 = i >= 2 ? pdoList[i - 2] : 0; - double pdo = currentValue > sma ? (rsi - 35) / (85 - 35) * 100 : currentValue <= sma ? (rsi - 20) / (70 - 20) * 100 : 0; + var pdo = currentValue > sma ? (rsi - 35) / (85 - 35) * 100 : currentValue <= sma ? (rsi - 20) / (70 - 20) * 100 : 0; pdoList.AddRounded(pdo); var signal = GetCompareSignal(pdo - prevPdo1, prevPdo1 - prevPdo2); @@ -7373,23 +7373,23 @@ public static StockData CalculatePercentChangeOscillator(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevPcc = percentChangeList.LastOrDefault(); - double pcc = prevValue - 1 != 0 ? prevPcc + (currentValue / (prevValue - 1)) : 0; + var prevPcc = percentChangeList.LastOrDefault(); + var pcc = prevValue - 1 != 0 ? prevPcc + (currentValue / (prevValue - 1)) : 0; percentChangeList.AddRounded(pcc); } var pctChgWmaList = GetMovingAverageList(stockData, maType, length, percentChangeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pcc = percentChangeList[i]; - double pccWma = pctChgWmaList[i]; - double prevPcc = i >= 1 ? percentChangeList[i - 1] : 0; - double prevPccWma = i >= 1 ? pctChgWmaList[i - 1] : 0; + var pcc = percentChangeList[i]; + var pccWma = pctChgWmaList[i]; + var prevPcc = i >= 1 ? percentChangeList[i - 1] : 0; + var prevPccWma = i >= 1 ? pctChgWmaList[i - 1] : 0; var signal = GetCompareSignal(pcc - pccWma, prevPcc - prevPccWma); signalsList.Add(signal); @@ -7421,20 +7421,20 @@ public static StockData CalculatePrimeNumberOscillator(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ratio = currentValue * length / 100; - long convertedValue = (long)Math.Round(currentValue); - long sqrtValue = currentValue >= 0 ? (long)Math.Round(Sqrt(currentValue)) : 0; - long maxValue = (long)Math.Round(currentValue + ratio); - long minValue = (long)Math.Round(currentValue - ratio); + var currentValue = inputList[i]; + var ratio = currentValue * length / 100; + var convertedValue = (long)Math.Round(currentValue); + var sqrtValue = currentValue >= 0 ? (long)Math.Round(Sqrt(currentValue)) : 0; + var maxValue = (long)Math.Round(currentValue + ratio); + var minValue = (long)Math.Round(currentValue - ratio); double pno1 = 0, pno2 = 0; - for (long j = convertedValue; j <= maxValue; j++) + for (var j = convertedValue; j <= maxValue; j++) { pno1 = j; - for (int k = 2; k <= sqrtValue; k++) + for (var k = 2; k <= sqrtValue; k++) { pno1 = j % k == 0 ? 0 : j; if (pno1 == 0) @@ -7451,10 +7451,10 @@ public static StockData CalculatePrimeNumberOscillator(this StockData stockData, pno1 = pno1 == 0 ? pno1List.LastOrDefault() : pno1; pno1List.AddRounded(pno1); - for (long l = convertedValue; l >= minValue; l--) + for (var l = convertedValue; l >= minValue; l--) { pno2 = l; - for (int m = 2; m <= sqrtValue; m++) + for (var m = 2; m <= sqrtValue; m++) { pno2 = l % m == 0 ? 0 : l; if (pno2 == 0) @@ -7471,8 +7471,8 @@ public static StockData CalculatePrimeNumberOscillator(this StockData stockData, pno2 = pno2 == 0 ? pno2List.LastOrDefault() : pno2; pno2List.AddRounded(pno2); - double prevPno = pnoList.LastOrDefault(); - double pno = pno1 - currentValue < currentValue - pno2 ? pno1 - currentValue : pno2 - currentValue; + var prevPno = pnoList.LastOrDefault(); + var pno = pno1 - currentValue < currentValue - pno2 ? pno1 - currentValue : pno2 - currentValue; pno = pno == 0 ? prevPno : pno; pnoList.AddRounded(pno); @@ -7544,33 +7544,33 @@ public static StockData CalculatePringSpecialK(this StockData stockData, MovingA var roc390SmaList = GetMovingAverageList(stockData, maType, length10, roc390List); var roc530SmaList = GetMovingAverageList(stockData, maType, length11, roc530List); - for (int i = 0; i < stockData.Count; i++) - { - double roc10Sma = roc10SmaList[i]; - double roc15Sma = roc15SmaList[i]; - double roc20Sma = roc20SmaList[i]; - double roc30Sma = roc30SmaList[i]; - double roc40Sma = roc40SmaList[i]; - double roc65Sma = roc65SmaList[i]; - double roc75Sma = roc75SmaList[i]; - double roc100Sma = roc100SmaList[i]; - double roc195Sma = roc195SmaList[i]; - double roc265Sma = roc265SmaList[i]; - double roc390Sma = roc390SmaList[i]; - double roc530Sma = roc530SmaList[i]; - - double specialK = (roc10Sma * 1) + (roc15Sma * 2) + (roc20Sma * 3) + (roc30Sma * 4) + (roc40Sma * 1) + (roc65Sma * 2) + (roc75Sma * 3) + - (roc100Sma * 4) + (roc195Sma * 1) + (roc265Sma * 2) + (roc390Sma * 3) + (roc530Sma * 4); + for (var i = 0; i < stockData.Count; i++) + { + var roc10Sma = roc10SmaList[i]; + var roc15Sma = roc15SmaList[i]; + var roc20Sma = roc20SmaList[i]; + var roc30Sma = roc30SmaList[i]; + var roc40Sma = roc40SmaList[i]; + var roc65Sma = roc65SmaList[i]; + var roc75Sma = roc75SmaList[i]; + var roc100Sma = roc100SmaList[i]; + var roc195Sma = roc195SmaList[i]; + var roc265Sma = roc265SmaList[i]; + var roc390Sma = roc390SmaList[i]; + var roc530Sma = roc530SmaList[i]; + + var specialK = (roc10Sma * 1) + (roc15Sma * 2) + (roc20Sma * 3) + (roc30Sma * 4) + (roc40Sma * 1) + (roc65Sma * 2) + (roc75Sma * 3) + + (roc100Sma * 4) + (roc195Sma * 1) + (roc265Sma * 2) + (roc390Sma * 3) + (roc530Sma * 4); specialKList.AddRounded(specialK); } var specialKSignalList = GetMovingAverageList(stockData, maType, smoothLength, specialKList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double specialK = specialKList[i]; - double specialKSignal = specialKSignalList[i]; - double prevSpecialK = i >= 1 ? specialKList[i - 1] : 0; - double prevSpecialKSignal = i >= 1 ? specialKSignalList[i - 1] : 0; + var specialK = specialKList[i]; + var specialKSignal = specialKSignalList[i]; + var prevSpecialK = i >= 1 ? specialKList[i - 1] : 0; + var prevSpecialKSignal = i >= 1 ? specialKSignalList[i - 1] : 0; var signal = GetCompareSignal(specialK - specialKSignal, prevSpecialK - prevSpecialKSignal); signalsList.Add(signal); @@ -7605,24 +7605,24 @@ public static StockData CalculatePriceZoneOscillator(this StockData stockData, M var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double dvol = Math.Sign(MinPastValues(i, 1, currentValue - prevValue)) * currentValue; + var dvol = Math.Sign(MinPastValues(i, 1, currentValue - prevValue)) * currentValue; dvolList.AddRounded(dvol); } var dvmaList = GetMovingAverageList(stockData, maType, length, dvolList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vma = emaList[i]; - double dvma = dvmaList[i]; - double prevPzo1 = i >= 1 ? pzoList[i - 1] : 0; - double prevPzo2 = i >= 2 ? pzoList[i - 2] : 0; + var vma = emaList[i]; + var dvma = dvmaList[i]; + var prevPzo1 = i >= 1 ? pzoList[i - 1] : 0; + var prevPzo2 = i >= 2 ? pzoList[i - 2] : 0; - double pzo = vma != 0 ? MinOrMax(100 * dvma / vma, 100, -100) : 0; + var pzo = vma != 0 ? MinOrMax(100 * dvma / vma, 100, -100) : 0; pzoList.AddRounded(pzo); var signal = GetRsiSignal(pzo - prevPzo1, prevPzo1 - prevPzo2, pzo, prevPzo1, 40, -40); @@ -7652,13 +7652,13 @@ public static StockData CalculatePerformanceIndex(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; - double prevKpi = kpiList.LastOrDefault(); - double kpi = prevValue != 0 ? MinPastValues(i, length, currentValue - prevValue) * 100 / prevValue : 0; + var prevKpi = kpiList.LastOrDefault(); + var kpi = prevValue != 0 ? MinPastValues(i, length, currentValue - prevValue) * 100 / prevValue : 0; kpiList.AddRounded(kpi); var signal = GetCompareSignal(kpi, prevKpi); @@ -7692,28 +7692,28 @@ public static StockData CalculatePolarizedFractalEfficiency(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priorValue = i >= length ? inputList[i - length] : 0; - double pfe = Sqrt(Pow(MinPastValues(i, length, currentValue - priorValue), 2) + 100); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priorValue = i >= length ? inputList[i - length] : 0; + var pfe = Sqrt(Pow(MinPastValues(i, length, currentValue - priorValue), 2) + 100); - double c2c = Sqrt(Pow(MinPastValues(i, 1, currentValue - prevValue), 2) + 1); + var c2c = Sqrt(Pow(MinPastValues(i, 1, currentValue - prevValue), 2) + 1); c2cList.AddRounded(c2c); - double c2cSum = c2cList.TakeLastExt(length).Sum(); - double efRatio = c2cSum != 0 ? pfe / c2cSum * 100 : 0; + var c2cSum = c2cList.TakeLastExt(length).Sum(); + var efRatio = c2cSum != 0 ? pfe / c2cSum * 100 : 0; - double fracEff = i >= length && currentValue - priorValue > 0 ? efRatio : -efRatio; + var fracEff = i >= length && currentValue - priorValue > 0 ? efRatio : -efRatio; fracEffList.AddRounded(fracEff); } var emaList = GetMovingAverageList(stockData, maType, smoothLength, fracEffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var ema = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; var signal = GetCompareSignal(ema, prevEma); signalsList.Add(signal); @@ -7747,14 +7747,14 @@ public static StockData CalculatePrettyGoodOscillator(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double atr = atrList[i]; + var currentValue = inputList[i]; + var sma = smaList[i]; + var atr = atrList[i]; - double prevPgo = pgoList.LastOrDefault(); - double pgo = atr != 0 ? (currentValue - sma) / atr : 0; + var prevPgo = pgoList.LastOrDefault(); + var pgo = atr != 0 ? (currentValue - sma) / atr : 0; pgoList.AddRounded(pgo); var signal = GetCompareSignal(pgo, prevPgo); @@ -7789,24 +7789,24 @@ public static StockData CalculatePriceCycleOscillator(this StockData stockData, var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentLow = lowList[i]; - double diff = currentClose - currentLow; + var diff = currentClose - currentLow; diffList.AddRounded(diff); } var diffSmaList = GetMovingAverageList(stockData, maType, length, diffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentAtr = atrList[i]; - double prevPco1 = i >= 1 ? pcoList[i - 1] : 0; - double prevPco2 = i >= 2 ? pcoList[i - 2] : 0; - double diffSma = diffSmaList[i]; + var currentAtr = atrList[i]; + var prevPco1 = i >= 1 ? pcoList[i - 1] : 0; + var prevPco2 = i >= 2 ? pcoList[i - 2] : 0; + var diffSma = diffSmaList[i]; - double pco = currentAtr != 0 ? diffSma / currentAtr * 100 : 0; + var pco = currentAtr != 0 ? diffSma / currentAtr * 100 : 0; pcoList.AddRounded(pco); var signal = GetCompareSignal(pco - prevPco1, prevPco1 - prevPco2); @@ -7839,33 +7839,33 @@ public static StockData CalculatePhaseChangeIndex(this StockData stockData, Movi List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double mom = MinPastValues(i, length, currentValue - prevValue); + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var mom = MinPastValues(i, length, currentValue - prevValue); double positiveSum = 0, negativeSum = 0; - for (int j = 0; j <= length - 1; j++) + for (var j = 0; j <= length - 1; j++) { - double prevValue2 = i >= length - j ? inputList[i - (length - j)] : 0; - double gradient = prevValue + (mom * (length - j) / (length - 1)); - double deviation = prevValue2 - gradient; + var prevValue2 = i >= length - j ? inputList[i - (length - j)] : 0; + var gradient = prevValue + (mom * (length - j) / (length - 1)); + var deviation = prevValue2 - gradient; positiveSum = deviation > 0 ? positiveSum + deviation : positiveSum + 0; negativeSum = deviation < 0 ? negativeSum - deviation : negativeSum + 0; } - double sum = positiveSum + negativeSum; + var sum = positiveSum + negativeSum; - double pci = sum != 0 ? MinOrMax(100 * positiveSum / sum, 100, 0) : 0; + var pci = sum != 0 ? MinOrMax(100 * positiveSum / sum, 100, 0) : 0; pciList.AddRounded(pci); } var pciSmoothedList = GetMovingAverageList(stockData, maType, smoothLength, pciList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pciSmoothed = pciSmoothedList[i]; - double prevPciSmoothed1 = i >= 1 ? pciSmoothedList[i - 1] : 0; - double prevPciSmoothed2 = i >= 2 ? pciSmoothedList[i - 2] : 0; + var pciSmoothed = pciSmoothedList[i]; + var prevPciSmoothed1 = i >= 1 ? pciSmoothedList[i - 1] : 0; + var prevPciSmoothed2 = i >= 2 ? pciSmoothedList[i - 2] : 0; var signal = GetRsiSignal(pciSmoothed - prevPciSmoothed1, prevPciSmoothed1 - prevPciSmoothed2, pciSmoothed, prevPciSmoothed1, 80, 20); signalsList.Add(signal); @@ -7905,29 +7905,29 @@ public static StockData CalculatePeakValleyEstimation(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; + var currentValue = inputList[i]; + var sma = smaList[i]; - double os = currentValue - sma; + var os = currentValue - sma; osList.AddRounded(os); - double absOs = Math.Abs(os); + var absOs = Math.Abs(os); absOsList.AddRounded(absOs); } stockData.CustomValuesList = absOsList; var pList = CalculateLinearRegression(stockData, smoothLength).CustomValuesList; var (highestList, _) = GetMaxAndMinValuesList(pList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double os = osList[i]; - double p = pList[i]; - double highest = highestList[i]; + var os = osList[i]; + var p = pList[i]; + var highest = highestList[i]; - double prevH = i >= 1 ? hList[i - 1] : 0; - double h = highest != 0 ? p / highest : 0; + var prevH = i >= 1 ? hList[i - 1] : 0; + var h = highest != 0 ? p / highest : 0; hList.AddRounded(h); double mod1 = h == 1 && prevH != 1 ? 1 : 0; @@ -7973,18 +7973,18 @@ public static StockData CalculatePsychologicalLine(this StockData stockData, int List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevPsy1 = i >= 1 ? psyList[i - 1] : 0; - double prevPsy2 = i >= 2 ? psyList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevPsy1 = i >= 1 ? psyList[i - 1] : 0; + var prevPsy2 = i >= 2 ? psyList[i - 2] : 0; double cond = currentValue > prevValue ? 1 : 0; condList.AddRounded(cond); - double condSum = condList.TakeLastExt(length).Sum(); - double psy = length != 0 ? condSum / length * 100 : 0; + var condSum = condList.TakeLastExt(length).Sum(); + var psy = length != 0 ? condSum / length * 100 : 0; psyList.AddRounded(psy); var signal = GetCompareSignal(psy - prevPsy1, prevPsy1 - prevPsy2); @@ -8025,47 +8025,47 @@ public static StockData CalculateTurboTrigger(this StockData stockData, MovingAv var hList = GetMovingAverageList(stockData, maType, smoothLength, highList); var lList = GetMovingAverageList(stockData, maType, smoothLength, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double c = cList[i]; - double o = oList[i]; + var c = cList[i]; + var o = oList[i]; - double avg = (c + o) / 2; + var avg = (c + o) / 2; avgList.AddRounded(avg); } var yList = GetMovingAverageList(stockData, maType, length, avgList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double y = yList[i]; - double h = hList[i]; - double l = lList[i]; + var y = yList[i]; + var h = hList[i]; + var l = lList[i]; - double hy = h - y; + var hy = h - y; hyList.AddRounded(hy); - double yl = y - l; + var yl = y - l; ylList.AddRounded(yl); } var aList = GetMovingAverageList(stockData, maType, length, hyList); var bList = GetMovingAverageList(stockData, maType, length, ylList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = aList[i]; - double b = bList[i]; + var a = aList[i]; + var b = bList[i]; - double ab = a - b; + var ab = a - b; abList.AddRounded(ab); } var oscList = GetMovingAverageList(stockData, maType, length, abList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double osc = oscList[i]; - double prevOsc = i >= 1 ? oscList[i - 1] : 0; - double a = aList[i]; - double prevA = i >= 1 ? aList[i - 1] : 0; + var osc = oscList[i]; + var prevOsc = i >= 1 ? oscList[i - 1] : 0; + var a = aList[i]; + var prevA = i >= 1 ? aList[i - 1] : 0; var signal = GetCompareSignal(osc - a, prevOsc - prevA); signalsList.Add(signal); @@ -8105,10 +8105,10 @@ public static StockData CalculateTotalPowerIndicator(this StockData stockData, M var bullPowerList = elderPowerList.OutputValues["BullPower"]; var bearPowerList = elderPowerList.OutputValues["BearPower"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double bullPower = bullPowerList[i]; - double bearPower = bearPowerList[i]; + var bullPower = bullPowerList[i]; + var bearPower = bearPowerList[i]; double bullCount = bullPower > 0 ? 1 : 0; bullCountList.AddRounded(bullCount); @@ -8116,18 +8116,18 @@ public static StockData CalculateTotalPowerIndicator(this StockData stockData, M double bearCount = bearPower < 0 ? 1 : 0; bearCountList.AddRounded(bearCount); - double bullCountSum = bullCountList.TakeLastExt(length1).Sum(); - double bearCountSum = bearCountList.TakeLastExt(length1).Sum(); + var bullCountSum = bullCountList.TakeLastExt(length1).Sum(); + var bearCountSum = bearCountList.TakeLastExt(length1).Sum(); - double totalPower = length1 != 0 ? 100 * Math.Abs(bullCountSum - bearCountSum) / length1 : 0; + var totalPower = length1 != 0 ? 100 * Math.Abs(bullCountSum - bearCountSum) / length1 : 0; totalPowerList.AddRounded(totalPower); - double prevAdjBullCount = adjBullCountList.LastOrDefault(); - double adjBullCount = length1 != 0 ? 100 * bullCountSum / length1 : 0; + var prevAdjBullCount = adjBullCountList.LastOrDefault(); + var adjBullCount = length1 != 0 ? 100 * bullCountSum / length1 : 0; adjBullCountList.AddRounded(adjBullCount); - double prevAdjBearCount = adjBearCountList.LastOrDefault(); - double adjBearCount = length1 != 0 ? 100 * bearCountSum / length1 : 0; + var prevAdjBearCount = adjBearCountList.LastOrDefault(); + var adjBearCount = length1 != 0 ? 100 * bearCountSum / length1 : 0; adjBearCountList.AddRounded(adjBearCount); var signal = GetCompareSignal(adjBullCount - adjBearCount, prevAdjBullCount - prevAdjBearCount); @@ -8168,38 +8168,38 @@ public static StockData CalculateTurboScaler(this StockData stockData, MovingAvg var smaList = GetMovingAverageList(stockData, maType, length, inputList); var sma2List = GetMovingAverageList(stockData, maType, length, smaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double sma2 = sma2List[i]; + var currentValue = inputList[i]; + var sma = smaList[i]; + var sma2 = sma2List[i]; - double smoSma = (alpha * sma) + ((1 - alpha) * sma2); + var smoSma = (alpha * sma) + ((1 - alpha) * sma2); smoSmaList.AddRounded(smoSma); - double smo = (alpha * currentValue) + ((1 - alpha) * sma); + var smo = (alpha * currentValue) + ((1 - alpha) * sma); smoList.AddRounded(smo); - double smoSmaHighest = smoSmaList.TakeLastExt(length).Max(); - double smoSmaLowest = smoSmaList.TakeLastExt(length).Min(); - double smoHighest = smoList.TakeLastExt(length).Max(); - double smoLowest = smoList.TakeLastExt(length).Min(); + var smoSmaHighest = smoSmaList.TakeLastExt(length).Max(); + var smoSmaLowest = smoSmaList.TakeLastExt(length).Min(); + var smoHighest = smoList.TakeLastExt(length).Max(); + var smoLowest = smoList.TakeLastExt(length).Min(); - double a = smoHighest - smoLowest != 0 ? (currentValue - smoLowest) / (smoHighest - smoLowest) : 0; + var a = smoHighest - smoLowest != 0 ? (currentValue - smoLowest) / (smoHighest - smoLowest) : 0; aList.AddRounded(a); - double b = smoSmaHighest - smoSmaLowest != 0 ? (sma - smoSmaLowest) / (smoSmaHighest - smoSmaLowest) : 0; + var b = smoSmaHighest - smoSmaLowest != 0 ? (sma - smoSmaLowest) / (smoSmaHighest - smoSmaLowest) : 0; bList.AddRounded(b); } var aSmaList = GetMovingAverageList(stockData, maType, length, aList); var bSmaList = GetMovingAverageList(stockData, maType, length, bList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = aSmaList[i]; - double b = bSmaList[i]; - double prevA = i >= 1 ? aSmaList[i - 1] : 0; - double prevB = i >= 1 ? bSmaList[i - 1] : 0; + var a = aSmaList[i]; + var b = bSmaList[i]; + var prevA = i >= 1 ? aSmaList[i - 1] : 0; + var prevB = i >= 1 ? bSmaList[i - 1] : 0; var signal = GetCompareSignal(a - b, prevA - prevB); signalsList.Add(signal); @@ -8246,28 +8246,28 @@ public static StockData CalculateTechnicalRank(this StockData stockData, int len var ppoHistList = CalculatePercentagePriceOscillator(stockData, MovingAvgType.ExponentialMovingAverage, length5, length6, length7). OutputValues["Histogram"]; - for (int i = 0; i < stockData.Count; i++) - { - double currentEma200 = ma1List[i]; - double currentEma50 = ma2List[i]; - double currentRoc125 = ltRocList[i]; - double currentRoc20 = mtRocList[i]; - double currentPpoHistogram = ppoHistList[i]; - double currentRsi = rsiList[i]; - double currentPrice = inputList[i]; - double prevTr1 = i >= 1 ? trList[i - 1] : 0; - double prevTr2 = i >= 2 ? trList[i - 2] : 0; - double ltMa = currentEma200 != 0 ? 0.3 * 100 * (currentPrice - currentEma200) / currentEma200 : 0; - double ltRoc = 0.3 * 100 * currentRoc125; - double mtMa = currentEma50 != 0 ? 0.15 * 100 * (currentPrice - currentEma50) / currentEma50 : 0; - double mtRoc = 0.15 * 100 * currentRoc20; - double currentValue = currentPpoHistogram; - double prevValue = i >= length8 ? ppoHistList[i - length8] : 0; - double slope = length8 != 0 ? MinPastValues(i, length8, currentValue - prevValue) / length8 : 0; - double stPpo = 0.05 * 100 * slope; - double stRsi = 0.05 * currentRsi; - - double tr = Math.Min(100, Math.Max(0, ltMa + ltRoc + mtMa + mtRoc + stPpo + stRsi)); + for (var i = 0; i < stockData.Count; i++) + { + var currentEma200 = ma1List[i]; + var currentEma50 = ma2List[i]; + var currentRoc125 = ltRocList[i]; + var currentRoc20 = mtRocList[i]; + var currentPpoHistogram = ppoHistList[i]; + var currentRsi = rsiList[i]; + var currentPrice = inputList[i]; + var prevTr1 = i >= 1 ? trList[i - 1] : 0; + var prevTr2 = i >= 2 ? trList[i - 2] : 0; + var ltMa = currentEma200 != 0 ? 0.3 * 100 * (currentPrice - currentEma200) / currentEma200 : 0; + var ltRoc = 0.3 * 100 * currentRoc125; + var mtMa = currentEma50 != 0 ? 0.15 * 100 * (currentPrice - currentEma50) / currentEma50 : 0; + var mtRoc = 0.15 * 100 * currentRoc20; + var currentValue = currentPpoHistogram; + var prevValue = i >= length8 ? ppoHistList[i - length8] : 0; + var slope = length8 != 0 ? MinPastValues(i, length8, currentValue - prevValue) / length8 : 0; + var stPpo = 0.05 * 100 * slope; + var stRsi = 0.05 * currentRsi; + + var tr = Math.Min(100, Math.Max(0, ltMa + ltRoc + mtMa + mtRoc + stPpo + stRsi)); trList.AddRounded(tr); var signal = GetCompareSignal(tr - prevTr1, prevTr1 - prevTr2); @@ -8299,26 +8299,26 @@ public static StockData CalculateTrigonometricOscillator(this StockData stockDat var sList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double s = sList[i]; - double prevS = i >= 1 ? sList[i - 1] : 0; - double wa = Math.Asin(Math.Sign(s - prevS)) * 2; - double wb = Math.Asin(Math.Sign(1)) * 2; + var s = sList[i]; + var prevS = i >= 1 ? sList[i - 1] : 0; + var wa = Math.Asin(Math.Sign(s - prevS)) * 2; + var wb = Math.Asin(Math.Sign(1)) * 2; - double u = wa + (2 * Math.PI * Math.Round((wa - wb) / (2 * Math.PI))); + var u = wa + (2 * Math.PI * Math.Round((wa - wb) / (2 * Math.PI))); uList.AddRounded(u); } stockData.CustomValuesList = uList; var uLinregList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double u = uLinregList[i]; - double prevO1 = i >= 1 ? oList[i - 1] : 0; - double prevO2 = i >= 2 ? oList[i - 2] : 0; + var u = uLinregList[i]; + var prevO1 = i >= 1 ? oList[i - 1] : 0; + var prevO2 = i >= 2 ? oList[i - 2] : 0; - double o = Math.Atan(u); + var o = Math.Atan(u); oList.AddRounded(o); var signal = GetRsiSignal(o - prevO1, prevO1 - prevO2, o, prevO1, 1, -1); @@ -8359,19 +8359,19 @@ public static StockData CalculateTradingMadeMoreSimplerOscillator(this StockData var stochastic1List = CalculateStochasticOscillator(stockData, maType, length: length2, smoothLength, smoothLength).OutputValues["FastD"]; var stochastic2List = CalculateStochasticOscillator(stockData, maType, length: length1, smoothLength, smoothLength).OutputValues["FastD"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double stoch1 = stochastic1List[i]; - double stoch2 = stochastic2List[i]; - double bufRsi = rsi - threshold; - double bufStoch1 = stoch1 - threshold; - double bufStoch2 = stoch2 - threshold; - double bufHistUp = bufRsi > limit && bufStoch1 > limit && bufStoch2 > limit ? bufStoch2 : 0; - double bufHistDn = bufRsi < limit && bufStoch1 < limit && bufStoch2 < limit ? bufStoch2 : 0; + var rsi = rsiList[i]; + var stoch1 = stochastic1List[i]; + var stoch2 = stochastic2List[i]; + var bufRsi = rsi - threshold; + var bufStoch1 = stoch1 - threshold; + var bufStoch2 = stoch2 - threshold; + var bufHistUp = bufRsi > limit && bufStoch1 > limit && bufStoch2 > limit ? bufStoch2 : 0; + var bufHistDn = bufRsi < limit && bufStoch1 < limit && bufStoch2 < limit ? bufStoch2 : 0; - double prevBufHistNo = bufHistNoList.LastOrDefault(); - double bufHistNo = bufHistUp - bufHistDn; + var prevBufHistNo = bufHistNoList.LastOrDefault(); + var bufHistNo = bufHistUp - bufHistDn; bufHistNoList.AddRounded(bufHistNo); var signal = GetCompareSignal(bufHistNo, prevBufHistNo); @@ -8415,25 +8415,25 @@ public static StockData CalculateTradersDynamicIndex(this StockData stockData, M var mabList = GetMovingAverageList(stockData, maType, length3, rList); var mbbList = GetMovingAverageList(stockData, maType, length4, rList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsiSma = maList[i]; - double stdDev = stdDevList[i]; - double mab = mabList[i]; - double mbb = mbbList[i]; - double prevMab = i >= 1 ? mabList[i - 1] : 0; - double prevMbb = i >= 1 ? mbbList[i - 1] : 0; - double offs = 1.6185 * stdDev; + var rsiSma = maList[i]; + var stdDev = stdDevList[i]; + var mab = mabList[i]; + var mbb = mbbList[i]; + var prevMab = i >= 1 ? mabList[i - 1] : 0; + var prevMbb = i >= 1 ? mbbList[i - 1] : 0; + var offs = 1.6185 * stdDev; - double prevUp = upList.LastOrDefault(); - double up = rsiSma + offs; + var prevUp = upList.LastOrDefault(); + var up = rsiSma + offs; upList.AddRounded(up); - double prevDn = dnList.LastOrDefault(); - double dn = rsiSma - offs; + var prevDn = dnList.LastOrDefault(); + var dn = rsiSma - offs; dnList.AddRounded(dn); - double mid = (up + dn) / 2; + var mid = (up + dn) / 2; midList.AddRounded(mid); var signal = GetBollingerBandsSignal(mab - mbb, prevMab - prevMbb, mab, prevMab, up, prevUp, dn, prevDn); @@ -8475,15 +8475,15 @@ public static StockData CalculateTopsAndBottomsFinder(this StockData stockData, var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = emaList[i]; - double prevA = i >= 1 ? emaList[i - 1] : 0; + var a = emaList[i]; + var prevA = i >= 1 ? emaList[i - 1] : 0; - double b = a > prevA ? a : 0; + var b = a > prevA ? a : 0; bList.AddRounded(b); - double c = a < prevA ? a : 0; + var c = a < prevA ? a : 0; cList.AddRounded(c); } @@ -8491,18 +8491,18 @@ public static StockData CalculateTopsAndBottomsFinder(this StockData stockData, var bStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; stockData.CustomValuesList = cList; var cStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = emaList[i]; - double b = bStdDevList[i]; - double c = cStdDevList[i]; + var a = emaList[i]; + var b = bStdDevList[i]; + var c = cStdDevList[i]; - double prevUp = upList.LastOrDefault(); - double up = a + b != 0 ? a / (a + b) : 0; + var prevUp = upList.LastOrDefault(); + var up = a + b != 0 ? a / (a + b) : 0; upList.AddRounded(up); - double prevDn = dnList.LastOrDefault(); - double dn = a + c != 0 ? a / (a + c) : 0; + var prevDn = dnList.LastOrDefault(); + var dn = a + c != 0 ? a / (a + c) : 0; dnList.AddRounded(dn); double os = prevUp == 1 && up != 1 ? 1 : prevDn == 1 && dn != 1 ? -1 : 0; @@ -8542,43 +8542,43 @@ public static StockData CalculateTraderPressureIndex(this StockData stockData, M var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length2); - for (int i = 0; i < stockData.Count; i++) - { - double high = highList[i]; - double low = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double hiup = Math.Max(high - prevHigh, 0); - double loup = Math.Max(low - prevLow, 0); - double hidn = Math.Min(high - prevHigh, 0); - double lodn = Math.Min(low - prevLow, 0); - double highest = highestList[i]; - double lowest = lowestList[i]; - double range = highest - lowest; - - double bulls = range != 0 ? Math.Min((hiup + loup) / range, 1) * 100 : 0; + for (var i = 0; i < stockData.Count; i++) + { + var high = highList[i]; + var low = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var hiup = Math.Max(high - prevHigh, 0); + var loup = Math.Max(low - prevLow, 0); + var hidn = Math.Min(high - prevHigh, 0); + var lodn = Math.Min(low - prevLow, 0); + var highest = highestList[i]; + var lowest = lowestList[i]; + var range = highest - lowest; + + var bulls = range != 0 ? Math.Min((hiup + loup) / range, 1) * 100 : 0; bullsList.AddRounded(bulls); - double bears = range != 0 ? Math.Max((hidn + lodn) / range, -1) * -100 : 0; + var bears = range != 0 ? Math.Max((hidn + lodn) / range, -1) * -100 : 0; bearsList.AddRounded(bears); } var avgBullsList = GetMovingAverageList(stockData, maType, length1, bullsList); var avgBearsList = GetMovingAverageList(stockData, maType, length1, bearsList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double avgBulls = avgBullsList[i]; - double avgBears = avgBearsList[i]; + var avgBulls = avgBullsList[i]; + var avgBears = avgBearsList[i]; - double net = avgBulls - avgBears; + var net = avgBulls - avgBears; netList.AddRounded(net); } var tpxList = GetMovingAverageList(stockData, maType, smoothLength, netList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tpx = tpxList[i]; - double prevTpx = i >= 1 ? tpxList[i - 1] : 0; + var tpx = tpxList[i]; + var prevTpx = i >= 1 ? tpxList[i - 1] : 0; var signal = GetCompareSignal(tpx, prevTpx); signalsList.Add(signal); @@ -8682,55 +8682,55 @@ public static StockData CalculateTechnicalRatings(this StockData stockData, Movi var stoRsiKList = stoRsiList.CustomValuesList; var stoRsiDList = stoRsiList.OutputValues["FastD"]; - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double rsi = rsiList[i]; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double ma10 = ma10List[i]; - double ma20 = ma20List[i]; - double ma30 = ma30List[i]; - double ma50 = ma50List[i]; - double ma100 = ma100List[i]; - double ma200 = ma200List[i]; - double hullMa = hullMaList[i]; - double vwma = vwmaList[i]; - double conLine = tenkanList[i]; - double baseLine = kijunList[i]; - double leadLine1 = senkouAList[i]; - double leadLine2 = senkouBList[i]; - double kSto = stoKList[i]; - double prevKSto = i >= 1 ? stoKList[i - 1] : 0; - double dSto = stoDList[i]; - double prevDSto = i >= 1 ? stoDList[i - 1] : 0; - double cci = cciList[i]; - double prevCci = i >= 1 ? cciList[i - 1] : 0; - double adx = adxList[i]; - double adxPlus = adxPlusList[i]; - double prevAdxPlus = i >= 1 ? adxPlusList[i - 1] : 0; - double adxMinus = adxMinusList[i]; - double prevAdxMinus = i >= 1 ? adxMinusList[i - 1] : 0; - double ao = aoList[i]; - double prevAo1 = i >= 1 ? aoList[i - 1] : 0; - double prevAo2 = i >= 2 ? aoList[i - 2] : 0; - double mom = momentumList[i]; - double prevMom = i >= 1 ? momentumList[i - 1] : 0; - double macd = macdList[i]; - double macdSig = macdSignalList[i]; - double kStoRsi = stoRsiKList[i]; - double prevKStoRsi = i >= 1 ? stoRsiKList[i - 1] : 0; - double dStoRsi = stoRsiDList[i]; - double prevDStoRsi = i >= 1 ? stoRsiDList[i - 1] : 0; - bool upTrend = currentValue > ma50; - bool dnTrend = currentValue < ma50; - double wr = williamsPctList[i]; - double prevWr = i >= 1 ? williamsPctList[i - 1] : 0; - double bullPower = bullPowerList[i]; - double prevBullPower = i >= 1 ? bullPowerList[i - 1] : 0; - double bearPower = bearPowerList[i]; - double prevBearPower = i >= 1 ? bearPowerList[i - 1] : 0; - double uo = uoList[i]; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var rsi = rsiList[i]; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var ma10 = ma10List[i]; + var ma20 = ma20List[i]; + var ma30 = ma30List[i]; + var ma50 = ma50List[i]; + var ma100 = ma100List[i]; + var ma200 = ma200List[i]; + var hullMa = hullMaList[i]; + var vwma = vwmaList[i]; + var conLine = tenkanList[i]; + var baseLine = kijunList[i]; + var leadLine1 = senkouAList[i]; + var leadLine2 = senkouBList[i]; + var kSto = stoKList[i]; + var prevKSto = i >= 1 ? stoKList[i - 1] : 0; + var dSto = stoDList[i]; + var prevDSto = i >= 1 ? stoDList[i - 1] : 0; + var cci = cciList[i]; + var prevCci = i >= 1 ? cciList[i - 1] : 0; + var adx = adxList[i]; + var adxPlus = adxPlusList[i]; + var prevAdxPlus = i >= 1 ? adxPlusList[i - 1] : 0; + var adxMinus = adxMinusList[i]; + var prevAdxMinus = i >= 1 ? adxMinusList[i - 1] : 0; + var ao = aoList[i]; + var prevAo1 = i >= 1 ? aoList[i - 1] : 0; + var prevAo2 = i >= 2 ? aoList[i - 2] : 0; + var mom = momentumList[i]; + var prevMom = i >= 1 ? momentumList[i - 1] : 0; + var macd = macdList[i]; + var macdSig = macdSignalList[i]; + var kStoRsi = stoRsiKList[i]; + var prevKStoRsi = i >= 1 ? stoRsiKList[i - 1] : 0; + var dStoRsi = stoRsiDList[i]; + var prevDStoRsi = i >= 1 ? stoRsiDList[i - 1] : 0; + var upTrend = currentValue > ma50; + var dnTrend = currentValue < ma50; + var wr = williamsPctList[i]; + var prevWr = i >= 1 ? williamsPctList[i - 1] : 0; + var bullPower = bullPowerList[i]; + var prevBullPower = i >= 1 ? bullPowerList[i - 1] : 0; + var bearPower = bearPowerList[i]; + var prevBearPower = i >= 1 ? bearPowerList[i - 1] : 0; + var uo = uoList[i]; double maRating = 0; maRating += currentValue > ma10 ? 1 : currentValue < ma10 ? -1 : 0; @@ -8766,7 +8766,7 @@ public static StockData CalculateTechnicalRatings(this StockData stockData, Movi oscRating /= 11; oscRatingList.AddRounded(oscRating); - double totalRating = (maRating + oscRating) / 2; + var totalRating = (maRating + oscRating) / 2; totalRatingList.AddRounded(totalRating); var signal = GetConditionSignal(totalRating > 0.1, totalRating < -0.1); @@ -8799,27 +8799,27 @@ public static StockData CalculateTTMScalperIndicator(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double prevClose1 = i >= 1 ? inputList[i - 1] : 0; - double prevClose2 = i >= 2 ? inputList[i - 2] : 0; - double prevClose3 = i >= 3 ? inputList[i - 3] : 0; - double high = highList[i]; - double low = lowList[i]; + var close = inputList[i]; + var prevClose1 = i >= 1 ? inputList[i - 1] : 0; + var prevClose2 = i >= 2 ? inputList[i - 2] : 0; + var prevClose3 = i >= 3 ? inputList[i - 3] : 0; + var high = highList[i]; + var low = lowList[i]; double triggerSell = prevClose1 < close && (prevClose2 < prevClose1 || prevClose3 < prevClose1) ? 1 : 0; double triggerBuy = prevClose1 > close && (prevClose2 > prevClose1 || prevClose3 > prevClose1) ? 1 : 0; - double prevBuySellSwitch = buySellSwitchList.LastOrDefault(); - double buySellSwitch = triggerSell == 1 ? 1 : triggerBuy == 1 ? 0 : prevBuySellSwitch; + var prevBuySellSwitch = buySellSwitchList.LastOrDefault(); + var buySellSwitch = triggerSell == 1 ? 1 : triggerBuy == 1 ? 0 : prevBuySellSwitch; buySellSwitchList.AddRounded(buySellSwitch); - double prevSbs = sbsList.LastOrDefault(); - double sbs = triggerSell == 1 && prevBuySellSwitch == 0 ? high : triggerBuy == 1 && prevBuySellSwitch == 1 ? low : prevSbs; + var prevSbs = sbsList.LastOrDefault(); + var sbs = triggerSell == 1 && prevBuySellSwitch == 0 ? high : triggerBuy == 1 && prevBuySellSwitch == 1 ? low : prevSbs; sbsList.AddRounded(sbs); - double prevClrs = clrsList.LastOrDefault(); - double clrs = triggerSell == 1 && prevBuySellSwitch == 0 ? 1 : triggerBuy == 1 && prevBuySellSwitch == 1 ? -1 : prevClrs; + var prevClrs = clrsList.LastOrDefault(); + var clrs = triggerSell == 1 && prevBuySellSwitch == 0 ? 1 : triggerBuy == 1 && prevBuySellSwitch == 1 ? -1 : prevClrs; clrsList.AddRounded(clrs); var signal = GetCompareSignal(clrs, prevClrs); @@ -8850,15 +8850,15 @@ public static StockData CalculateTFSTetherLineIndicator(this StockData stockData var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevTetherLine = tetherLineList.LastOrDefault(); - double tetherLine = (highest + lowest) / 2; + var prevTetherLine = tetherLineList.LastOrDefault(); + var tetherLine = (highest + lowest) / 2; tetherLineList.AddRounded(tetherLine); var signal = GetCompareSignal(currentValue - tetherLine, prevValue - prevTetherLine); @@ -8892,31 +8892,31 @@ public static StockData CalculateTheRangeIndicator(this StockData stockData, Mov List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - double v1 = i >= 1 && currentValue > prevValue ? tr / MinPastValues(i, 1, currentValue - prevValue) : tr; + var v1 = i >= 1 && currentValue > prevValue ? tr / MinPastValues(i, 1, currentValue - prevValue) : tr; v1List.AddRounded(v1); var lbList = v1List.TakeLastExt(length).ToList(); - double v2 = lbList.Min(); - double v3 = lbList.Max(); + var v2 = lbList.Min(); + var v3 = lbList.Max(); - double stoch = v3 - v2 != 0 ? MinOrMax(100 * (v1 - v2) / (v3 - v2), 100, 0) : MinOrMax(100 * (v1 - v2), 100, 0); + var stoch = v3 - v2 != 0 ? MinOrMax(100 * (v1 - v2) / (v3 - v2), 100, 0) : MinOrMax(100 * (v1 - v2), 100, 0); stochList.AddRounded(stoch); } var triList = GetMovingAverageList(stockData, maType, length, stochList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tri = triList[i]; - double prevTri1 = i >= 1 ? triList[i - 1] : 0; - double prevTri2 = i >= 2 ? triList[i - 2] : 0; + var tri = triList[i]; + var prevTri1 = i >= 1 ? triList[i - 1] : 0; + var prevTri2 = i >= 2 ? triList[i - 2] : 0; var signal = GetRsiSignal(tri - prevTri1, prevTri1 - prevTri2, tri, prevTri1, 80, 20); signalsList.Add(signal); @@ -8949,12 +8949,12 @@ public static StockData CalculateTimePriceIndicator(this StockData stockData, in var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double highest = i >= 1 ? highestList[i - 1] : 0; - double lowest = i >= 1 ? lowestList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var highest = i >= 1 ? highestList[i - 1] : 0; + var lowest = i >= 1 ? lowestList[i - 1] : 0; double rising = currentHigh > highest ? 1 : 0; risingList.AddRounded(rising); @@ -8965,12 +8965,12 @@ public static StockData CalculateTimePriceIndicator(this StockData stockData, in double a = i - risingList.LastIndexOf(1); double b = i - fallingList.LastIndexOf(1); - double prevUpper = upperList.LastOrDefault(); - double upper = length != 0 ? ((a > length ? length : a) / length) - 0.5 : 0; + var prevUpper = upperList.LastOrDefault(); + var upper = length != 0 ? ((a > length ? length : a) / length) - 0.5 : 0; upperList.AddRounded(upper); - double prevLower = lowerList.LastOrDefault(); - double lower = length != 0 ? ((b > length ? length : b) / length) - 0.5 : 0; + var prevLower = lowerList.LastOrDefault(); + var lower = length != 0 ? ((b > length ? length : b) / length) - 0.5 : 0; lowerList.AddRounded(lower); var signal = GetCompareSignal((lower * -1) - (upper * -1), (prevLower * -1) - (prevUpper * -1)); @@ -9017,34 +9017,34 @@ public static StockData CalculateRahulMohindarOscillator(this StockData stockDat var r9List = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, length1, r8List); var r10List = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, length1, r9List); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double r1 = r1List[i]; - double r2 = r2List[i]; - double r3 = r3List[i]; - double r4 = r4List[i]; - double r5 = r5List[i]; - double r6 = r6List[i]; - double r7 = r7List[i]; - double r8 = r8List[i]; - double r9 = r9List[i]; - double r10 = r10List[i]; - - double swingTrd1 = highest - lowest != 0 ? 100 * (currentValue - ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10)) / - (highest - lowest) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var r1 = r1List[i]; + var r2 = r2List[i]; + var r3 = r3List[i]; + var r4 = r4List[i]; + var r5 = r5List[i]; + var r6 = r6List[i]; + var r7 = r7List[i]; + var r8 = r8List[i]; + var r9 = r9List[i]; + var r10 = r10List[i]; + + var swingTrd1 = highest - lowest != 0 ? 100 * (currentValue - ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10)) / + (highest - lowest) : 0; swingTrd1List.AddRounded(swingTrd1); } var swingTrd2List = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length3, swingTrd1List); var swingTrd3List = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length3, swingTrd2List); var rmoList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length4, swingTrd1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rmo = rmoList[i]; - double prevRmo = i >= 1 ? rmoList[i - 1] : 0; + var rmo = rmoList[i]; + var prevRmo = i >= 1 ? rmoList[i - 1] : 0; var signal = GetCompareSignal(rmo, prevRmo); signalsList.Add(signal); @@ -9093,35 +9093,35 @@ public static StockData CalculateRainbowOscillator(this StockData stockData, Mov var r9List = GetMovingAverageList(stockData, maType, length1, r8List); var r10List = GetMovingAverageList(stockData, maType, length1, r9List); - for (int i = 0; i < stockData.Count; i++) - { - double highest = highestList[i]; - double lowest = lowestList[i]; - double currentValue = inputList[i]; - double r1 = r1List[i]; - double r2 = r2List[i]; - double r3 = r3List[i]; - double r4 = r4List[i]; - double r5 = r5List[i]; - double r6 = r6List[i]; - double r7 = r7List[i]; - double r8 = r8List[i]; - double r9 = r9List[i]; - double r10 = r10List[i]; - double highestRainbow = Math.Max(r1, Math.Max(r2, Math.Max(r3, Math.Max(r4, Math.Max(r5, Math.Max(r6, Math.Max(r7, Math.Max(r8, + for (var i = 0; i < stockData.Count; i++) + { + var highest = highestList[i]; + var lowest = lowestList[i]; + var currentValue = inputList[i]; + var r1 = r1List[i]; + var r2 = r2List[i]; + var r3 = r3List[i]; + var r4 = r4List[i]; + var r5 = r5List[i]; + var r6 = r6List[i]; + var r7 = r7List[i]; + var r8 = r8List[i]; + var r9 = r9List[i]; + var r10 = r10List[i]; + var highestRainbow = Math.Max(r1, Math.Max(r2, Math.Max(r3, Math.Max(r4, Math.Max(r5, Math.Max(r6, Math.Max(r7, Math.Max(r8, Math.Max(r9, r10))))))))); - double lowestRainbow = Math.Min(r1, Math.Min(r2, Math.Min(r3, Math.Min(r4, Math.Min(r5, Math.Min(r6, Math.Min(r7, Math.Min(r8, + var lowestRainbow = Math.Min(r1, Math.Min(r2, Math.Min(r3, Math.Min(r4, Math.Min(r5, Math.Min(r6, Math.Min(r7, Math.Min(r8, Math.Min(r9, r10))))))))); - double prevRainbowOscillator = rainbowOscillatorList.LastOrDefault(); - double rainbowOscillator = highest - lowest != 0 ? 100 * ((currentValue - ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10)) / - (highest - lowest)) : 0; + var prevRainbowOscillator = rainbowOscillatorList.LastOrDefault(); + var rainbowOscillator = highest - lowest != 0 ? 100 * ((currentValue - ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10)) / + (highest - lowest)) : 0; rainbowOscillatorList.AddRounded(rainbowOscillator); - double upperBand = highest - lowest != 0 ? 100 * ((highestRainbow - lowestRainbow) / (highest - lowest)) : 0; + var upperBand = highest - lowest != 0 ? 100 * ((highestRainbow - lowestRainbow) / (highest - lowest)) : 0; upperBandList.AddRounded(upperBand); - double lowerBand = -upperBand; + var lowerBand = -upperBand; lowerBandList.AddRounded(lowerBand); var signal = GetCompareSignal(rainbowOscillator, prevRainbowOscillator); @@ -9157,23 +9157,23 @@ public static StockData CalculateRandomWalkIndex(this StockData stockData, Movin var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - double sqrt = Sqrt(length); + var sqrt = Sqrt(length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentAtr = atrList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh = i >= length ? highList[i - length] : 0; - double prevLow = i >= length ? lowList[i - length] : 0; - double bottom = currentAtr * sqrt; + var currentAtr = atrList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh = i >= length ? highList[i - length] : 0; + var prevLow = i >= length ? lowList[i - length] : 0; + var bottom = currentAtr * sqrt; - double prevRwiLow = rwiLowList.LastOrDefault(); - double rwiLow = bottom != 0 ? (prevHigh - currentLow) / bottom : 0; + var prevRwiLow = rwiLowList.LastOrDefault(); + var rwiLow = bottom != 0 ? (prevHigh - currentLow) / bottom : 0; rwiLowList.AddRounded(rwiLow); - double prevRwiHigh = rwiHighList.LastOrDefault(); - double rwiHigh = bottom != 0 ? (currentHigh - prevLow) / bottom : 0; + var prevRwiHigh = rwiHighList.LastOrDefault(); + var rwiHigh = bottom != 0 ? (currentHigh - prevLow) / bottom : 0; rwiHighList.AddRounded(rwiHigh); var signal = GetCompareSignal(rwiHigh - rwiLow, prevRwiHigh - prevRwiLow); @@ -9210,14 +9210,14 @@ public static StockData CalculateRangeActionVerificationIndex(this StockData sto var smaFastList = GetMovingAverageList(stockData, maType, fastLength, inputList); var smaSlowList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastMA = smaFastList[i]; - double slowMA = smaSlowList[i]; - double prevRavi1 = i >= 1 ? raviList[i - 1] : 0; - double prevRavi2 = i >= 2 ? raviList[i - 2] : 0; + var fastMA = smaFastList[i]; + var slowMA = smaSlowList[i]; + var prevRavi1 = i >= 1 ? raviList[i - 1] : 0; + var prevRavi2 = i >= 2 ? raviList[i - 2] : 0; - double ravi = slowMA != 0 ? (fastMA - slowMA) / slowMA * 100 : 0; + var ravi = slowMA != 0 ? (fastMA - slowMA) / slowMA * 100 : 0; raviList.AddRounded(ravi); var signal = GetCompareSignal(ravi - prevRavi1, prevRavi1 - prevRavi2); @@ -9252,23 +9252,23 @@ public static StockData CalculateReallySimpleIndicator(this StockData stockData, var maList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentLow = lowList[i]; - double currentMa = maList[i]; + var currentValue = inputList[i]; + var currentLow = lowList[i]; + var currentMa = maList[i]; - double rsi = currentValue != 0 ? (currentLow - currentMa) / currentValue * 100 : 0; + var rsi = currentValue != 0 ? (currentLow - currentMa) / currentValue * 100 : 0; rsiList.AddRounded(rsi); } var rsiMaList = GetMovingAverageList(stockData, maType, smoothLength, rsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiMaList[i]; - double prevRsiMa = i >= 1 ? rsiMaList[i - 1] : 0; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double rsiMa = rsiMaList[i]; + var rsi = rsiMaList[i]; + var prevRsiMa = i >= 1 ? rsiMaList[i - 1] : 0; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var rsiMa = rsiMaList[i]; var signal = GetCompareSignal(rsi - rsiMa, prevRsi - prevRsiMa); signalsList.Add(signal); @@ -9306,18 +9306,18 @@ public static StockData CalculateRecursiveDifferenciator(this StockData stockDat stockData.CustomValuesList = emaList; var rsiList = CalculateRelativeStrengthIndex(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double priorB = i >= length ? bList[i - length] : 0; - double a = rsi / 100; - double prevBChg1 = i >= 1 ? bChgList[i - 1] : a; - double prevBChg2 = i >= 2 ? bChgList[i - 2] : 0; + var rsi = rsiList[i]; + var priorB = i >= length ? bList[i - length] : 0; + var a = rsi / 100; + var prevBChg1 = i >= 1 ? bChgList[i - 1] : a; + var prevBChg2 = i >= 2 ? bChgList[i - 2] : 0; - double b = (alpha * a) + ((1 - alpha) * prevBChg1); + var b = (alpha * a) + ((1 - alpha) * prevBChg1); bList.AddRounded(b); - double bChg = b - priorB; + var bChg = b - priorB; bChgList.AddRounded(bChg); var signal = GetCompareSignal(bChg - prevBChg1, prevBChg1 - prevBChg2); @@ -9349,13 +9349,13 @@ public static StockData CalculateRegressionOscillator(this StockData stockData, var linRegList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentLinReg = linRegList[i]; + var currentValue = inputList[i]; + var currentLinReg = linRegList[i]; - double prevRosc = roscList.LastOrDefault(); - double rosc = currentLinReg != 0 ? 100 * ((currentValue / currentLinReg) - 1) : 0; + var prevRosc = roscList.LastOrDefault(); + var rosc = currentLinReg != 0 ? 100 * ((currentValue / currentLinReg) - 1) : 0; roscList.AddRounded(rosc); var signal = GetCompareSignal(rosc, prevRosc); @@ -9388,10 +9388,10 @@ public static StockData CalculateRelativeDifferenceOfSquaresOscillator(this Stoc List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double a = currentValue > prevValue ? 1 : 0; aList.AddRounded(a); @@ -9402,11 +9402,11 @@ public static StockData CalculateRelativeDifferenceOfSquaresOscillator(this Stoc double n = currentValue == prevValue ? 1 : 0; nList.AddRounded(n); - double prevRdos = rdosList.LastOrDefault(); - double aSum = aList.TakeLastExt(length).Sum(); - double dSum = dList.TakeLastExt(length).Sum(); - double nSum = nList.TakeLastExt(length).Sum(); - double rdos = aSum > 0 || dSum > 0 || nSum > 0 ? (Pow(aSum, 2) - Pow(dSum, 2)) / Pow(aSum + nSum + dSum, 2) : 0; + var prevRdos = rdosList.LastOrDefault(); + var aSum = aList.TakeLastExt(length).Sum(); + var dSum = dList.TakeLastExt(length).Sum(); + var nSum = nList.TakeLastExt(length).Sum(); + var rdos = aSum > 0 || dSum > 0 || nSum > 0 ? (Pow(aSum, 2) - Pow(dSum, 2)) / Pow(aSum + nSum + dSum, 2) : 0; rdosList.AddRounded(rdos); var signal = GetCompareSignal(rdos, prevRdos); @@ -9444,23 +9444,23 @@ public static StockData CalculateRelativeSpreadStrength(this StockData stockData var fastEmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowEmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastEma = fastEmaList[i]; - double slowEma = slowEmaList[i]; + var fastEma = fastEmaList[i]; + var slowEma = slowEmaList[i]; - double spread = fastEma - slowEma; + var spread = fastEma - slowEma; spreadList.AddRounded(spread); } stockData.CustomValuesList = spreadList; var rsList = CalculateRelativeStrengthIndex(stockData, length: length).CustomValuesList; var rssList = GetMovingAverageList(stockData, maType, smoothLength, rsList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rss = rssList[i]; - double prevRss1 = i >= 1 ? rssList[i - 1] : 0; - double prevRss2 = i >= 2 ? rssList[i - 2] : 0; + var rss = rssList[i]; + var prevRss1 = i >= 1 ? rssList[i - 1] : 0; + var prevRss2 = i >= 2 ? rssList[i - 2] : 0; var signal = GetRsiSignal(rss - prevRss1, prevRss1 - prevRss2, rss, prevRss1, 80, 20); signalsList.Add(signal); @@ -9503,13 +9503,13 @@ public static StockData CalculateRelativeStrength3DIndicator(this StockData stoc if (stockData.Count == marketData.Count) { - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSp = spInputList[i]; + var currentValue = inputList[i]; + var currentSp = spInputList[i]; - double prevR1 = r1List.LastOrDefault(); - double r1 = currentSp != 0 ? currentValue / currentSp * 100 : prevR1; + var prevR1 = r1List.LastOrDefault(); + var r1 = currentSp != 0 ? currentValue / currentSp * 100 : prevR1; r1List.AddRounded(r1); } @@ -9517,33 +9517,33 @@ public static StockData CalculateRelativeStrength3DIndicator(this StockData stoc var medMaList = GetMovingAverageList(stockData, maType, length2, fastMaList); var slowMaList = GetMovingAverageList(stockData, maType, length4, fastMaList); var vSlowMaList = GetMovingAverageList(stockData, maType, length5, slowMaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastMa = fastMaList[i]; - double medMa = medMaList[i]; - double slowMa = slowMaList[i]; - double vSlowMa = vSlowMaList[i]; + var fastMa = fastMaList[i]; + var medMa = medMaList[i]; + var slowMa = slowMaList[i]; + var vSlowMa = vSlowMaList[i]; double t1 = fastMa >= medMa && medMa >= slowMa && slowMa >= vSlowMa ? 10 : 0; double t2 = fastMa >= medMa && medMa >= slowMa && slowMa < vSlowMa ? 9 : 0; double t3 = fastMa < medMa && medMa >= slowMa && slowMa >= vSlowMa ? 9 : 0; double t4 = fastMa < medMa && medMa >= slowMa && slowMa < vSlowMa ? 5 : 0; - double rs2 = t1 + t2 + t3 + t4; + var rs2 = t1 + t2 + t3 + t4; rs2List.AddRounded(rs2); } var rs2MaList = GetMovingAverageList(stockData, maType, length1, rs2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rs2 = rs2List[i]; - double rs2Ma = rs2MaList[i]; - double prevRs3_1 = i >= 1 ? rs3List[i - 1] : 0; - double prevRs3_2 = i >= 2 ? rs3List[i - 1] : 0; + var rs2 = rs2List[i]; + var rs2Ma = rs2MaList[i]; + var prevRs3_1 = i >= 1 ? rs3List[i - 1] : 0; + var prevRs3_2 = i >= 2 ? rs3List[i - 1] : 0; double x = rs2 >= 5 ? 1 : 0; xList.AddRounded(x); - double rs3 = rs2 >= 5 || rs2 > rs2Ma ? xList.TakeLastExt(length4).Sum() / length4 * 100 : 0; + var rs3 = rs2 >= 5 || rs2 > rs2Ma ? xList.TakeLastExt(length4).Sum() / length4 * 100 : 0; rs3List.AddRounded(rs3); var signal = GetCompareSignal(rs3 - prevRs3_1, prevRs3_1 - prevRs3_2); @@ -9579,52 +9579,52 @@ public static StockData CalculateRelativeVigorIndex(this StockData stockData, Mo List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevOpen1 = i >= 1 ? openList[i - 1] : 0; - double prevClose1 = i >= 1 ? inputList[i - 1] : 0; - double prevHigh1 = i >= 1 ? highList[i - 1] : 0; - double prevOpen2 = i >= 2 ? openList[i - 2] : 0; - double prevClose2 = i >= 2 ? inputList[i - 2] : 0; - double prevHigh2 = i >= 2 ? highList[i - 2] : 0; - double prevOpen3 = i >= 3 ? openList[i - 3] : 0; - double prevClose3 = i >= 3 ? inputList[i - 3] : 0; - double prevHigh3 = i >= 3 ? highList[i - 3] : 0; - double a = currentClose - currentOpen; - double b = prevClose1 - prevOpen1; - double c = prevClose2 - prevOpen2; - double d = prevClose3 - prevOpen3; - double e = currentHigh - currentLow; - double f = prevHigh1 - prevOpen1; - double g = prevHigh2 - prevOpen2; - double h = prevHigh3 - prevOpen3; - - double numerator = (a + (2 * b) + (2 * c) + d) / 6; + for (var i = 0; i < stockData.Count; i++) + { + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevOpen1 = i >= 1 ? openList[i - 1] : 0; + var prevClose1 = i >= 1 ? inputList[i - 1] : 0; + var prevHigh1 = i >= 1 ? highList[i - 1] : 0; + var prevOpen2 = i >= 2 ? openList[i - 2] : 0; + var prevClose2 = i >= 2 ? inputList[i - 2] : 0; + var prevHigh2 = i >= 2 ? highList[i - 2] : 0; + var prevOpen3 = i >= 3 ? openList[i - 3] : 0; + var prevClose3 = i >= 3 ? inputList[i - 3] : 0; + var prevHigh3 = i >= 3 ? highList[i - 3] : 0; + var a = currentClose - currentOpen; + var b = prevClose1 - prevOpen1; + var c = prevClose2 - prevOpen2; + var d = prevClose3 - prevOpen3; + var e = currentHigh - currentLow; + var f = prevHigh1 - prevOpen1; + var g = prevHigh2 - prevOpen2; + var h = prevHigh3 - prevOpen3; + + var numerator = (a + (2 * b) + (2 * c) + d) / 6; numeratorList.AddRounded(numerator); - double denominator = (e + (2 * f) + (2 * g) + h) / 6; + var denominator = (e + (2 * f) + (2 * g) + h) / 6; denominatorList.AddRounded(denominator); } var numeratorAvgList = GetMovingAverageList(stockData, maType, length, numeratorList); var denominatorAvgList = GetMovingAverageList(stockData, maType, length, denominatorList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double numeratorAvg = numeratorAvgList[i]; - double denominatorAvg = denominatorAvgList[i]; - double k = i >= 1 ? rviList[i - 1] : 0; - double l = i >= 2 ? rviList[i - 2] : 0; - double m = i >= 3 ? rviList[i - 3] : 0; + var numeratorAvg = numeratorAvgList[i]; + var denominatorAvg = denominatorAvgList[i]; + var k = i >= 1 ? rviList[i - 1] : 0; + var l = i >= 2 ? rviList[i - 2] : 0; + var m = i >= 3 ? rviList[i - 3] : 0; - double rvi = denominatorAvg != 0 ? numeratorAvg / denominatorAvg : 0; + var rvi = denominatorAvg != 0 ? numeratorAvg / denominatorAvg : 0; rviList.AddRounded(rvi); - double prevSignalLine = signalLineList.LastOrDefault(); - double signalLine = (rvi + (2 * k) + (2 * l) + m) / 6; + var prevSignalLine = signalLineList.LastOrDefault(); + var signalLine = (rvi + (2 * k) + (2 * l) + m) / 6; signalLineList.AddRounded(signalLine); var signal = GetCompareSignal(rvi - signalLine, k - prevSignalLine); @@ -9659,38 +9659,38 @@ public static StockData CalculateRepulse(this StockData stockData, MovingAvgType var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double lowestLow = lowestList[i]; - double highestHigh = highestList[i]; - double prevOpen = i >= 1 ? openList[i - 1] : 0; + var currentClose = inputList[i]; + var lowestLow = lowestList[i]; + var highestHigh = highestList[i]; + var prevOpen = i >= 1 ? openList[i - 1] : 0; - double bullPower = currentClose != 0 ? 100 * ((3 * currentClose) - (2 * lowestLow) - prevOpen) / currentClose : 0; + var bullPower = currentClose != 0 ? 100 * ((3 * currentClose) - (2 * lowestLow) - prevOpen) / currentClose : 0; bullPowerList.AddRounded(bullPower); - double bearPower = currentClose != 0 ? 100 * (prevOpen + (2 * highestHigh) - (3 * currentClose)) / currentClose : 0; + var bearPower = currentClose != 0 ? 100 * (prevOpen + (2 * highestHigh) - (3 * currentClose)) / currentClose : 0; bearPowerList.AddRounded(bearPower); } var bullPowerEmaList = GetMovingAverageList(stockData, maType, length * 5, bullPowerList); var bearPowerEmaList = GetMovingAverageList(stockData, maType, length * 5, bearPowerList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double bullPowerEma = bullPowerEmaList[i]; - double bearPowerEma = bearPowerEmaList[i]; + var bullPowerEma = bullPowerEmaList[i]; + var bearPowerEma = bearPowerEmaList[i]; - double repulse = bullPowerEma - bearPowerEma; + var repulse = bullPowerEma - bearPowerEma; repulseList.AddRounded(repulse); } var repulseEmaList = GetMovingAverageList(stockData, maType, length, repulseList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double repulse = repulseList[i]; - double prevRepulse = i >= 1 ? repulseList[i - 1] : 0; - double repulseEma = repulseEmaList[i]; - double prevRepulseEma = i >= 1 ? repulseEmaList[i - 1] : 0; + var repulse = repulseList[i]; + var prevRepulse = i >= 1 ? repulseList[i - 1] : 0; + var repulseEma = repulseEmaList[i]; + var prevRepulseEma = i >= 1 ? repulseEmaList[i - 1] : 0; var signal = GetCompareSignal(repulse - repulseEma, prevRepulse - prevRepulseEma); signalsList.Add(signal); @@ -9722,37 +9722,37 @@ public static StockData CalculateRetrospectiveCandlestickChart(this StockData st List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double currentOpen = openList[i]; - double prevK1 = i >= 1 ? kList[i - 1] : 0; - double prevK2 = i >= 2 ? kList[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentOpen = openList[i]; + var prevK1 = i >= 1 ? kList[i - 1] : 0; + var prevK2 = i >= 2 ? kList[i - 2] : 0; - double absChg = Math.Abs(currentClose - prevClose); + var absChg = Math.Abs(currentClose - prevClose); absChgList.AddRounded(absChg); var lbList = absChgList.TakeLastExt(length).ToList(); - double highest = lbList.Max(); - double lowest = lbList.Min(); - double s = highest - lowest != 0 ? (absChg - lowest) / (highest - lowest) * 100 : 0; - double weight = s / 100; + var highest = lbList.Max(); + var lowest = lbList.Min(); + var s = highest - lowest != 0 ? (absChg - lowest) / (highest - lowest) * 100 : 0; + var weight = s / 100; - double prevC = i >= 1 ? cList[i - 1] : currentClose; - double c = (weight * currentClose) + ((1 - weight) * prevC); + var prevC = i >= 1 ? cList[i - 1] : currentClose; + var c = (weight * currentClose) + ((1 - weight) * prevC); cList.AddRounded(c); - double prevH = i >= 1 ? prevC : currentHigh; - double h = (weight * currentHigh) + ((1 - weight) * prevH); - double prevL = i >= 1 ? prevC : currentLow; - double l = (weight * currentLow) + ((1 - weight) * prevL); - double prevO = i >= 1 ? prevC : currentOpen; - double o = (weight * currentOpen) + ((1 - weight) * prevO); + var prevH = i >= 1 ? prevC : currentHigh; + var h = (weight * currentHigh) + ((1 - weight) * prevH); + var prevL = i >= 1 ? prevC : currentLow; + var l = (weight * currentLow) + ((1 - weight) * prevL); + var prevO = i >= 1 ? prevC : currentOpen; + var o = (weight * currentOpen) + ((1 - weight) * prevO); - double k = (c + h + l + o) / 4; + var k = (c + h + l + o) / 4; kList.AddRounded(k); var signal = GetCompareSignal(k - prevK1, prevK1 - prevK2); @@ -9784,25 +9784,25 @@ public static StockData CalculateRexOscillator(this StockData stockData, MovingA List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double open = openList[i]; - double high = highList[i]; - double low = lowList[i]; + var close = inputList[i]; + var open = openList[i]; + var high = highList[i]; + var low = lowList[i]; - double tvb = (3 * close) - (low + open + high); + var tvb = (3 * close) - (low + open + high); tvbList.AddRounded(tvb); } var roList = GetMovingAverageList(stockData, maType, length, tvbList); var roEmaList = GetMovingAverageList(stockData, maType, length, roList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ro = roList[i]; - double roEma = roEmaList[i]; - double prevRo = i >= 1 ? roList[i - 1] : 0; - double prevRoEma = i >= 1 ? roEmaList[i - 1] : 0; + var ro = roList[i]; + var roEma = roEmaList[i]; + var prevRo = i >= 1 ? roList[i - 1] : 0; + var prevRoEma = i >= 1 ? roEmaList[i - 1] : 0; var signal = GetCompareSignal(ro - roEma, prevRo - prevRoEma); signalsList.Add(signal); @@ -9837,12 +9837,12 @@ public static StockData CalculateRobustWeightingOscillator(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double index = i; indexList.AddRounded(index); - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); var corr = GoodnessOfFit.R(indexList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); @@ -9855,27 +9855,27 @@ public static StockData CalculateRobustWeightingOscillator(this StockData stockD var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; stockData.CustomValuesList = indexList; var indexStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double corr = corrList[i]; - double stdDev = stdDevList[i]; - double indexStdDev = indexStdDevList[i]; - double sma = smaList[i]; - double indexSma = indexSmaList[i]; - double a = indexStdDev != 0 ? corr * (stdDev / indexStdDev) : 0; - double b = sma - (a * indexSma); - - double l = currentValue - a - (b * currentValue); + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var corr = corrList[i]; + var stdDev = stdDevList[i]; + var indexStdDev = indexStdDevList[i]; + var sma = smaList[i]; + var indexSma = indexSmaList[i]; + var a = indexStdDev != 0 ? corr * (stdDev / indexStdDev) : 0; + var b = sma - (a * indexSma); + + var l = currentValue - a - (b * currentValue); lList.AddRounded(l); } var lSmaList = GetMovingAverageList(stockData, maType, length, lList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double l = lSmaList[i]; - double prevL1 = i >= 1 ? lSmaList[i - 1] : 0; - double prevL2 = i >= 2 ? lSmaList[i - 2] : 0; + var l = lSmaList[i]; + var prevL1 = i >= 1 ? lSmaList[i - 1] : 0; + var prevL2 = i >= 2 ? lSmaList[i - 2] : 0; var signal = GetCompareSignal(l - prevL1, prevL1 - prevL2); signalsList.Add(signal); @@ -9910,50 +9910,50 @@ public static StockData CalculateRSINGIndicator(this StockData stockData, Moving var maList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double high = highList[i]; - double low = lowList[i]; + var high = highList[i]; + var low = lowList[i]; - double range = high - low; + var range = high - low; rangeList.AddRounded(range); } stockData.CustomValuesList = rangeList; var stdevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentVolume = volumeList[i]; - double ma = maList[i]; - double stdev = stdevList[i]; - double range = rangeList[i]; - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double vwr = ma != 0 ? currentVolume / ma : 0; - double blr = stdev != 0 ? range / stdev : 0; - bool isUp = currentValue > prevValue; - bool isDn = currentValue < prevValue; - bool isEq = currentValue == prevValue; - - double prevUpCount = upList.LastOrDefault(); - double upCount = isEq ? 0 : isUp ? (prevUpCount <= 0 ? 1 : prevUpCount + 1) : (prevUpCount >= 0 ? -1 : prevUpCount - 1); + for (var i = 0; i < stockData.Count; i++) + { + var currentVolume = volumeList[i]; + var ma = maList[i]; + var stdev = stdevList[i]; + var range = rangeList[i]; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var vwr = ma != 0 ? currentVolume / ma : 0; + var blr = stdev != 0 ? range / stdev : 0; + var isUp = currentValue > prevValue; + var isDn = currentValue < prevValue; + var isEq = currentValue == prevValue; + + var prevUpCount = upList.LastOrDefault(); + var upCount = isEq ? 0 : isUp ? (prevUpCount <= 0 ? 1 : prevUpCount + 1) : (prevUpCount >= 0 ? -1 : prevUpCount - 1); upList.AddRounded(upCount); - double prevDnCount = dnList.LastOrDefault(); - double dnCount = isEq ? 0 : isDn ? (prevDnCount <= 0 ? 1 : prevDnCount + 1) : (prevDnCount >= 0 ? -1 : prevDnCount - 1); + var prevDnCount = dnList.LastOrDefault(); + var dnCount = isEq ? 0 : isDn ? (prevDnCount <= 0 ? 1 : prevDnCount + 1) : (prevDnCount >= 0 ? -1 : prevDnCount - 1); dnList.AddRounded(dnCount); - double pmo = MinPastValues(i, length, currentValue - prevValue); - double rsing = vwr * blr * pmo; + var pmo = MinPastValues(i, length, currentValue - prevValue); + var rsing = vwr * blr * pmo; rsingList.AddRounded(rsing); } var rsingMaList = GetMovingAverageList(stockData, maType, length, rsingList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsing = rsingMaList[i]; - double prevRsing1 = i >= 1 ? rsingMaList[i - 1] : 0; - double prevRsing2 = i >= 2 ? rsingMaList[i - 2] : 0; + var rsing = rsingMaList[i]; + var prevRsing1 = i >= 1 ? rsingMaList[i - 1] : 0; + var prevRsing2 = i >= 2 ? rsingMaList[i - 2] : 0; var signal = GetCompareSignal(rsing - prevRsing1, prevRsing1 - prevRsing2); signalsList.Add(signal); @@ -9992,26 +9992,26 @@ public static StockData CalculateRSMKIndicator(this StockData stockData, StockDa if (stockData.Count == marketData.Count) { - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double spValue = spInputList[i]; - double prevLogRatio = i >= length ? logRatioList[i - length] : 0; + var currentValue = inputList[i]; + var spValue = spInputList[i]; + var prevLogRatio = i >= length ? logRatioList[i - length] : 0; - double logRatio = spValue != 0 ? currentValue / spValue : 0; + var logRatio = spValue != 0 ? currentValue / spValue : 0; logRatioList.AddRounded(logRatio); - double logDiff = logRatio - prevLogRatio; + var logDiff = logRatio - prevLogRatio; logDiffList.AddRounded(logDiff); } var logDiffEmaList = GetMovingAverageList(stockData, maType, smoothLength, logDiffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double logDiffEma = logDiffEmaList[i]; + var logDiffEma = logDiffEmaList[i]; - double prevRsmk = rsmkList.LastOrDefault(); - double rsmk = logDiffEma * 100; + var prevRsmk = rsmkList.LastOrDefault(); + var rsmk = logDiffEma * 100; rsmkList.AddRounded(rsmk); var signal = GetCompareSignal(rsmk, prevRsmk); @@ -10047,21 +10047,21 @@ public static StockData CalculateRunningEquity(this StockData stockData, MovingA var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; - double prevX = xList.LastOrDefault(); + var prevX = xList.LastOrDefault(); double x = Math.Sign(currentValue - sma); xList.AddRounded(x); - double chgX = MinPastValues(i, 1, currentValue - prevValue) * prevX; + var chgX = MinPastValues(i, 1, currentValue - prevValue) * prevX; chgXList.AddRounded(chgX); - double prevReq = reqList.LastOrDefault(); - double req = chgXList.TakeLastExt(length).Sum(); + var prevReq = reqList.LastOrDefault(); + var req = chgXList.TakeLastExt(length).Sum(); reqList.AddRounded(req); var signal = GetCompareSignal(req, prevReq); @@ -10098,36 +10098,36 @@ public static StockData CalculateMassIndex(this StockData stockData, MovingAvgTy List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double highLow = currentHigh - currentLow; + var highLow = currentHigh - currentLow; highLowList.AddRounded(highLow); } var firstEmaList = GetMovingAverageList(stockData, maType, length1, highLowList); var secondEmaList = GetMovingAverageList(stockData, maType, length2, firstEmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double firstEma = firstEmaList[i]; - double secondEma = secondEmaList[i]; + var firstEma = firstEmaList[i]; + var secondEma = secondEmaList[i]; - double ratio = secondEma != 0 ? firstEma / secondEma : 0; + var ratio = secondEma != 0 ? firstEma / secondEma : 0; ratioList.AddRounded(ratio); - double massIndex = ratioList.TakeLastExt(length3).Sum(); + var massIndex = ratioList.TakeLastExt(length3).Sum(); massIndexList.AddRounded(massIndex); } var massIndexSignalList = GetMovingAverageList(stockData, maType, signalLength, massIndexList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double massIndex = massIndexList[i]; - double massIndexEma = massIndexSignalList[i]; - double prevMassIndex = i >= 1 ? massIndexList[i - 1] : 0; - double prevMassIndexEma = i >= 1 ? massIndexSignalList[i - 1] : 0; + var massIndex = massIndexList[i]; + var massIndexEma = massIndexSignalList[i]; + var prevMassIndex = i >= 1 ? massIndexList[i - 1] : 0; + var prevMassIndexEma = i >= 1 ? massIndexSignalList[i - 1] : 0; var signal = GetCompareSignal(massIndex - massIndexEma, prevMassIndex - prevMassIndexEma); signalsList.Add(signal); @@ -10165,47 +10165,47 @@ public static StockData CalculateMassThrustOscillator(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = volumeList[i]; - double adv = i >= 1 && currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; + var adv = i >= 1 && currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; advList.AddRounded(adv); - double dec = i >= 1 && currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; + var dec = i >= 1 && currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; decList.AddRounded(dec); - double advSum = advList.TakeLastExt(length).Sum(); - double decSum = decList.TakeLastExt(length).Sum(); + var advSum = advList.TakeLastExt(length).Sum(); + var decSum = decList.TakeLastExt(length).Sum(); - double advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; + var advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; advVolList.AddRounded(advVol); - double decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; + var decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; decVolList.AddRounded(decVol); - double advVolSum = advVolList.TakeLastExt(length).Sum(); - double decVolSum = decVolList.TakeLastExt(length).Sum(); + var advVolSum = advVolList.TakeLastExt(length).Sum(); + var decVolSum = decVolList.TakeLastExt(length).Sum(); - double top = (advSum * advVolSum) - (decSum * decVolSum); + var top = (advSum * advVolSum) - (decSum * decVolSum); topList.AddRounded(top); - double bot = (advSum * advVolSum) + (decSum * decVolSum); + var bot = (advSum * advVolSum) + (decSum * decVolSum); botList.AddRounded(bot); - double mto = bot != 0 ? 100 * top / bot : 0; + var mto = bot != 0 ? 100 * top / bot : 0; mtoList.AddRounded(mto); } var mtoEmaList = GetMovingAverageList(stockData, maType, length, mtoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mto = mtoList[i]; - double mtoEma = mtoEmaList[i]; - double prevMto = i >= 1 ? mtoList[i - 1] : 0; - double prevMtoEma = i >= 1 ? mtoEmaList[i - 1] : 0; + var mto = mtoList[i]; + var mtoEma = mtoEmaList[i]; + var prevMto = i >= 1 ? mtoList[i - 1] : 0; + var prevMtoEma = i >= 1 ? mtoEmaList[i - 1] : 0; var signal = GetRsiSignal(mto - mtoEma, prevMto - prevMtoEma, mto, prevMto, 50, -50); signalsList.Add(signal); @@ -10239,23 +10239,23 @@ public static StockData CalculateMidpointOscillator(this StockData stockData, Mo var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double hh = highestList[i]; - double ll = lowestList[i]; + var currentValue = inputList[i]; + var hh = highestList[i]; + var ll = lowestList[i]; - double mo = hh - ll != 0 ? MinOrMax(100 * ((2 * currentValue) - hh - ll) / (hh - ll), 100, -100) : 0; + var mo = hh - ll != 0 ? MinOrMax(100 * ((2 * currentValue) - hh - ll) / (hh - ll), 100, -100) : 0; moList.AddRounded(mo); } var moEmaList = GetMovingAverageList(stockData, maType, signalLength, moList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mo = moList[i]; - double moEma = moEmaList[i]; - double prevMo = i >= 1 ? moList[i - 1] : 0; - double prevMoEma = i >= 1 ? moEmaList[i - 1] : 0; + var mo = moList[i]; + var moEma = moEmaList[i]; + var prevMo = i >= 1 ? moList[i - 1] : 0; + var prevMoEma = i >= 1 ? moEmaList[i - 1] : 0; var signal = GetRsiSignal(mo - moEma, prevMo - prevMoEma, mo, prevMo, 70, -70); signalsList.Add(signal); @@ -10286,16 +10286,16 @@ public static StockData CalculateMorphedSineWave(this StockData stockData, int l List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double p = length / (2 * Math.PI); + var p = length / (2 * Math.PI); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevS1 = i >= 1 ? sList[i - 1] : 0; - double prevS2 = i >= 2 ? sList[i - 2] : 0; - double c = (currentValue * power) + Math.Sin(i / p); + var currentValue = inputList[i]; + var prevS1 = i >= 1 ? sList[i - 1] : 0; + var prevS2 = i >= 2 ? sList[i - 2] : 0; + var c = (currentValue * power) + Math.Sin(i / p); - double s = c / power; + var s = c / power; sList.AddRounded(s); var signal = GetCompareSignal(s - prevS1, prevS1 - prevS2); @@ -10325,17 +10325,17 @@ public static StockData CalculateMoveTracker(this StockData stockData) List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMt = mtList.LastOrDefault(); - double mt = MinPastValues(i, 1, currentValue - prevValue); + var prevMt = mtList.LastOrDefault(); + var mt = MinPastValues(i, 1, currentValue - prevValue); mtList.AddRounded(mt); - double prevMtSignal = mtSignalList.LastOrDefault(); - double mtSignal = mt - prevMt; + var prevMtSignal = mtSignalList.LastOrDefault(); + var mtSignal = mt - prevMt; mtSignalList.AddRounded(mtSignal); var signal = GetCompareSignal(mt - mtSignal, prevMt - prevMtSignal); @@ -10367,15 +10367,15 @@ public static StockData CalculateMultiLevelIndicator(this StockData stockData, i List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevOpen = i >= length ? openList[i - length] : 0; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double prevZ1 = i >= 1 ? zList[i - 1] : 0; - double prevZ2 = i >= 2 ? zList[i - 2] : 0; + var prevOpen = i >= length ? openList[i - length] : 0; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var prevZ1 = i >= 1 ? zList[i - 1] : 0; + var prevZ2 = i >= 2 ? zList[i - 2] : 0; - double z = (currentClose - currentOpen - (currentClose - prevOpen)) * factor; + var z = (currentClose - currentOpen - (currentClose - prevOpen)) * factor; zList.AddRounded(z); var signal = GetRsiSignal(z - prevZ1, prevZ1 - prevZ2, z, prevZ1, 5, -5); @@ -10412,39 +10412,39 @@ public static StockData CalculateModifiedGannHiloActivator(this StockData stockD var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double max = Math.Max(currentClose, currentOpen); - double min = Math.Min(currentClose, currentOpen); - double a = highestHigh - max; - double b = min - lowestLow; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var max = Math.Max(currentClose, currentOpen); + var min = Math.Min(currentClose, currentOpen); + var a = highestHigh - max; + var b = min - lowestLow; - double c = max + (a * mult); + var c = max + (a * mult); cList.AddRounded(c); - double d = min - (b * mult); + var d = min - (b * mult); dList.AddRounded(d); } var eList = GetMovingAverageList(stockData, maType, length, cList); var fList = GetMovingAverageList(stockData, maType, length, dList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double f = fList[i]; - double e = eList[i]; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var f = fList[i]; + var e = eList[i]; - double prevG = gList.LastOrDefault(); - double g = currentClose > e ? 1 : currentClose > f ? 0 : prevG; + var prevG = gList.LastOrDefault(); + var g = currentClose > e ? 1 : currentClose > f ? 0 : prevG; gList.AddRounded(g); - double prevGannHilo = gannHiloList.LastOrDefault(); - double gannHilo = (g * f) + ((1 - g) * e); + var prevGannHilo = gannHiloList.LastOrDefault(); + var gannHilo = (g * f) + ((1 - g) * e); gannHiloList.AddRounded(gannHilo); var signal = GetCompareSignal(currentClose - gannHilo, prevClose - prevGannHilo); @@ -10477,21 +10477,21 @@ public static StockData CalculateMarketDirectionIndicator(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double len1Sum = tempList.TakeLastExt(fastLength - 1).Sum(); - double len2Sum = tempList.TakeLastExt(slowLength - 1).Sum(); + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var len1Sum = tempList.TakeLastExt(fastLength - 1).Sum(); + var len2Sum = tempList.TakeLastExt(slowLength - 1).Sum(); - double prevCp2 = cp2List.LastOrDefault(); - double cp2 = ((fastLength * len2Sum) - (slowLength * len1Sum)) / (slowLength - fastLength); + var prevCp2 = cp2List.LastOrDefault(); + var cp2 = ((fastLength * len2Sum) - (slowLength * len1Sum)) / (slowLength - fastLength); cp2List.AddRounded(cp2); - double prevMdi = mdiList.LastOrDefault(); - double mdi = currentValue + prevValue != 0 ? 100 * (prevCp2 - cp2) / ((currentValue + prevValue) / 2) : 0; + var prevMdi = mdiList.LastOrDefault(); + var mdi = currentValue + prevValue != 0 ? 100 * (prevCp2 - cp2) / ((currentValue + prevValue) / 2) : 0; mdiList.AddRounded(mdi); var signal = GetCompareSignal(mdi, prevMdi); @@ -10526,27 +10526,27 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double hMax = highestList[i]; - double lMin = lowestList[i]; - double prevC = i >= length2 ? inputList[i - length2] : 0; - double rx = length1 != 0 ? (hMax - lMin) / length1 : 0; + var hMax = highestList[i]; + var lMin = lowestList[i]; + var prevC = i >= length2 ? inputList[i - length2] : 0; + var rx = length1 != 0 ? (hMax - lMin) / length1 : 0; - int imx = 1; + var imx = 1; double pdfmx = 0, pdfc = 0, rx1, bu, bl, bu1, bl1, pdf; - for (int j = 1; j <= length1; j++) + for (var j = 1; j <= length1; j++) { bu = lMin + (j * rx); bl = bu - rx; - double currHigh = i >= j ? highList[i - j] : 0; - double currLow = i >= j ? lowList[i - j] : 0; + var currHigh = i >= j ? highList[i - j] : 0; + var currLow = i >= j ? lowList[i - j] : 0; double hMax1 = currHigh, lMin1 = currLow; - for (int k = 2; k < length2; k++) + for (var k = 2; k < length2; k++) { - double high = i >= j + k ? highList[i - (j + k)] : 0; - double low = i >= j + k ? lowList[i - (j + k)] : 0; + var high = i >= j + k ? highList[i - (j + k)] : 0; + var low = i >= j + k ? lowList[i - (j + k)] : 0; hMax1 = Math.Max(high, hMax1); lMin1 = Math.Min(low, lMin1); } @@ -10556,10 +10556,10 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo bu1 = lMin1 + (j * rx1); pdf = 0; - for (int k = 1; k <= length2; k++) + for (var k = 1; k <= length2; k++) { - double high = i >= j + k ? highList[i - (j + k)] : 0; - double low = i >= j + k ? lowList[i - (j + k)] : 0; + var high = i >= j + k ? highList[i - (j + k)] : 0; + var low = i >= j + k ? lowList[i - (j + k)] : 0; if (high <= bu1) { @@ -10594,20 +10594,20 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo pdfc = prevC > bl && prevC <= bu ? pdf : pdfc; } - double pmo = lMin + ((imx - 0.5) * rx); - double mo = pdfmx != 0 ? 100 * (1 - (pdfc / pdfmx)) : 0; + var pmo = lMin + ((imx - 0.5) * rx); + var mo = pdfmx != 0 ? 100 * (1 - (pdfc / pdfmx)) : 0; mo = prevC < pmo ? -mo : mo; moList.AddRounded(-mo); } var moWmaList = GetMovingAverageList(stockData, maType, signalLength, moList); var moSigList = GetMovingAverageList(stockData, maType, signalLength, moWmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mo = moWmaList[i]; - double moSig = moSigList[i]; - double prevMo = i >= 1 ? moWmaList[i - 1] : 0; - double prevMoSig = i >= 1 ? moSigList[i - 1] : 0; + var mo = moWmaList[i]; + var moSig = moSigList[i]; + var prevMo = i >= 1 ? moWmaList[i - 1] : 0; + var prevMoSig = i >= 1 ? moSigList[i - 1] : 0; var signal = GetCompareSignal(mo - moSig, prevMo - prevMoSig); signalsList.Add(signal); @@ -10643,39 +10643,39 @@ public static StockData CalculateMassThrustIndicator(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = volumeList[i]; - double adv = i >= 1 && currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; + var adv = i >= 1 && currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; advList.AddRounded(adv); - double dec = i >= 1 && currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; + var dec = i >= 1 && currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; decList.AddRounded(dec); - double advSum = advList.TakeLastExt(length).Sum(); - double decSum = decList.TakeLastExt(length).Sum(); + var advSum = advList.TakeLastExt(length).Sum(); + var decSum = decList.TakeLastExt(length).Sum(); - double advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; + var advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; advVolList.AddRounded(advVol); - double decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; + var decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; decVolList.AddRounded(decVol); - double advVolSum = advVolList.TakeLastExt(length).Sum(); - double decVolSum = decVolList.TakeLastExt(length).Sum(); + var advVolSum = advVolList.TakeLastExt(length).Sum(); + var decVolSum = decVolList.TakeLastExt(length).Sum(); - double mti = ((advSum * advVolSum) - (decSum * decVolSum)) / 1000000; + var mti = ((advSum * advVolSum) - (decSum * decVolSum)) / 1000000; mtiList.AddRounded(mti); } var mtiEmaList = GetMovingAverageList(stockData, maType, length, mtiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mtiEma = mtiEmaList[i]; - double prevMtiEma = i >= 1 ? mtiEmaList[i - 1] : 0; + var mtiEma = mtiEmaList[i]; + var prevMtiEma = i >= 1 ? mtiEmaList[i - 1] : 0; var signal = GetCompareSignal(mtiEma, prevMtiEma); signalsList.Add(signal); @@ -10707,26 +10707,26 @@ public static StockData CalculateDecisionPointBreadthSwenlinTradingOscillator(th List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double advance = currentValue > prevValue ? 1 : 0; double decline = currentValue < prevValue ? 1 : 0; - double iVal = advance + decline != 0 ? 1000 * (advance - decline) / (advance + decline) : 0; + var iVal = advance + decline != 0 ? 1000 * (advance - decline) / (advance + decline) : 0; iList.AddRounded(iVal); } var ivalEmaList = GetMovingAverageList(stockData, maType, length, iList); var stoList = GetMovingAverageList(stockData, maType, length, ivalEmaList); var stoEmaList = GetMovingAverageList(stockData, maType, length, stoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sto = stoList[i]; - double stoEma = stoEmaList[i]; - double prevSto = i >= 1 ? stoList[i - 1] : 0; - double prevStoEma = i >= 1 ? stoEmaList[i - 1] : 0; + var sto = stoList[i]; + var stoEma = stoEmaList[i]; + var prevSto = i >= 1 ? stoList[i - 1] : 0; + var prevStoEma = i >= 1 ? stoEmaList[i - 1] : 0; var signal = GetCompareSignal(sto - stoEma, prevSto - prevStoEma); signalsList.Add(signal); @@ -10760,23 +10760,23 @@ public static StockData CalculateDeltaMovingAverage(this StockData stockData, Mo List signalsList = new(); var (inputList, _, _, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double prevOpen = i >= length2 ? openList[i - length2] : 0; + var currentClose = inputList[i]; + var prevOpen = i >= length2 ? openList[i - length2] : 0; - double delta = currentClose - prevOpen; + var delta = currentClose - prevOpen; deltaList.AddRounded(delta); } var deltaSmaList = GetMovingAverageList(stockData, maType, length1, deltaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double delta = deltaList[i]; - double deltaSma = deltaSmaList[i]; + var delta = deltaList[i]; + var deltaSma = deltaSmaList[i]; - double prevDeltaHistogram = deltaHistogramList.LastOrDefault(); - double deltaHistogram = delta - deltaSma; + var prevDeltaHistogram = deltaHistogramList.LastOrDefault(); + var deltaHistogram = delta - deltaSma; deltaHistogramList.AddRounded(deltaHistogram); var signal = GetCompareSignal(deltaHistogram, prevDeltaHistogram); @@ -10810,28 +10810,28 @@ public static StockData CalculateDetrendedSyntheticPrice(this StockData stockDat List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - double alpha = length > 2 ? (double)2 / (length + 1) : 0.67; + var alpha = length > 2 ? (double)2 / (length + 1) : 0.67; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double high = Math.Max(currentHigh, prevHigh); - double low = Math.Min(currentLow, prevLow); - double price = (high + low) / 2; - double prevEma1 = i >= 1 ? ema1List[i - 1] : price; - double prevEma2 = i >= 1 ? ema2List[i - 1] : price; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var high = Math.Max(currentHigh, prevHigh); + var low = Math.Min(currentLow, prevLow); + var price = (high + low) / 2; + var prevEma1 = i >= 1 ? ema1List[i - 1] : price; + var prevEma2 = i >= 1 ? ema2List[i - 1] : price; - double ema1 = (alpha * price) + ((1 - alpha) * prevEma1); + var ema1 = (alpha * price) + ((1 - alpha) * prevEma1); ema1List.AddRounded(ema1); - double ema2 = (alpha / 2 * price) + ((1 - (alpha / 2)) * prevEma2); + var ema2 = (alpha / 2 * price) + ((1 - (alpha / 2)) * prevEma2); ema2List.AddRounded(ema2); - double prevDsp = dspList.LastOrDefault(); - double dsp = ema1 - ema2; + var prevDsp = dspList.LastOrDefault(); + var dsp = ema1 - ema2; dspList.AddRounded(dsp); var signal = GetCompareSignal(dsp, prevDsp); @@ -10871,17 +10871,17 @@ public static StockData CalculateDerivativeOscillator(this StockData stockData, var rsiEma1List = GetMovingAverageList(stockData, maType, length3, rsiList); var rsiEma2List = GetMovingAverageList(stockData, maType, length4, rsiEma1List); - for (int i = 0; i < rsiList.Count; i++) + for (var i = 0; i < rsiList.Count; i++) { - double prevS1 = s1List.LastOrDefault(); - double s1 = rsiEma2List[i]; + var prevS1 = s1List.LastOrDefault(); + var s1 = rsiEma2List[i]; s1List.AddRounded(s1); - double prevS1Sma = s1SmaList.LastOrDefault(); - double s1Sma = s1List.TakeLastExt(length2).Average(); + var prevS1Sma = s1SmaList.LastOrDefault(); + var s1Sma = s1List.TakeLastExt(length2).Average(); s1SmaList.AddRounded(s1Sma); - double s2 = s1 - s1Sma; + var s2 = s1 - s1Sma; s2List.AddRounded(s2); var signal = GetCompareSignal(s1 - s1Sma, prevS1 - prevS1Sma); @@ -10917,40 +10917,40 @@ public static StockData CalculateDemandOscillator(this StockData stockData, Movi var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; - double range = highest - lowest; + var range = highest - lowest; rangeList.AddRounded(range); } var vaList = GetMovingAverageList(stockData, maType, length1, rangeList); - for (int i = 0; i < stockData.Count; i++) - { - double va = vaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double pctChg = prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / Math.Abs(prevValue) * 100 : 0; - double currentVolume = stockData.Volumes[i]; - double k = va != 0 ? (3 * currentValue) / va : 0; - double pctK = pctChg * k; - double volPctK = pctK != 0 ? currentVolume / pctK : 0; - double bp = currentValue > prevValue ? currentVolume : volPctK; - double sp = currentValue > prevValue ? volPctK : currentVolume; - - double dosc = bp - sp; + for (var i = 0; i < stockData.Count; i++) + { + var va = vaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var pctChg = prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / Math.Abs(prevValue) * 100 : 0; + var currentVolume = stockData.Volumes[i]; + var k = va != 0 ? (3 * currentValue) / va : 0; + var pctK = pctChg * k; + var volPctK = pctK != 0 ? currentVolume / pctK : 0; + var bp = currentValue > prevValue ? currentVolume : volPctK; + var sp = currentValue > prevValue ? volPctK : currentVolume; + + var dosc = bp - sp; doList.AddRounded(dosc); } var doEmaList = GetMovingAverageList(stockData, maType, length3, doList); var doSigList = GetMovingAverageList(stockData, maType, length1, doEmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double doSig = doSigList[i]; - double prevSig1 = i >= 1 ? doSigList[i - 1] : 0; - double prevSig2 = i >= 2 ? doSigList[i - 1] : 0; + var doSig = doSigList[i]; + var prevSig1 = i >= 1 ? doSigList[i - 1] : 0; + var prevSig2 = i >= 2 ? doSigList[i - 1] : 0; var signal = GetCompareSignal(doSig - prevSig1, prevSig1 - prevSig2); signalsList.Add(signal); @@ -10987,16 +10987,16 @@ public static StockData CalculateDoubleSmoothedMomenta(this StockData stockData, var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double hc = highestList[i]; - double lc = lowestList[i]; + var currentValue = inputList[i]; + var hc = highestList[i]; + var lc = lowestList[i]; - double srcLc = currentValue - lc; + var srcLc = currentValue - lc; srcLcList.AddRounded(srcLc); - double hcLc = hc - lc; + var hcLc = hc - lc; hcLcList.AddRounded(hcLc); } @@ -11004,22 +11004,22 @@ public static StockData CalculateDoubleSmoothedMomenta(this StockData stockData, var topEma2List = GetMovingAverageList(stockData, maType, length3, topEma1List); var botEma1List = GetMovingAverageList(stockData, maType, length2, hcLcList); var botEma2List = GetMovingAverageList(stockData, maType, length3, botEma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double top = topEma2List[i]; - double bot = botEma2List[i]; + var top = topEma2List[i]; + var bot = botEma2List[i]; - double mom = bot != 0 ? MinOrMax(100 * top / bot, 100, 0) : 0; + var mom = bot != 0 ? MinOrMax(100 * top / bot, 100, 0) : 0; momList.AddRounded(mom); } var momEmaList = GetMovingAverageList(stockData, maType, length3, momList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mom = momList[i]; - double momEma = momEmaList[i]; - double prevMom = i >= 1 ? momList[i - 1] : 0; - double prevMomEma = i >= 1 ? momEmaList[i - 1] : 0; + var mom = momList[i]; + var momEma = momEmaList[i]; + var prevMom = i >= 1 ? momList[i - 1] : 0; + var prevMomEma = i >= 1 ? momEmaList[i - 1] : 0; var signal = GetCompareSignal(mom - momEma, prevMom - prevMomEma); signalsList.Add(signal); @@ -11058,18 +11058,18 @@ public static StockData CalculateDidiIndex(this StockData stockData, MovingAvgTy var shortSmaList = GetMovingAverageList(stockData, maType, length1, inputList); var longSmaList = GetMovingAverageList(stockData, maType, length3, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mediumSma = mediumSmaList[i]; - double shortSma = shortSmaList[i]; - double longSma = longSmaList[i]; + var mediumSma = mediumSmaList[i]; + var shortSma = shortSmaList[i]; + var longSma = longSmaList[i]; - double prevCurta = curtaList.LastOrDefault(); - double curta = mediumSma != 0 ? shortSma / mediumSma : 0; + var prevCurta = curtaList.LastOrDefault(); + var curta = mediumSma != 0 ? shortSma / mediumSma : 0; curtaList.AddRounded(curta); - double prevLonga = longaList.LastOrDefault(); - double longa = mediumSma != 0 ? longSma / mediumSma : 0; + var prevLonga = longaList.LastOrDefault(); + var longa = mediumSma != 0 ? longSma / mediumSma : 0; longaList.AddRounded(longa); var signal = GetCompareSignal(curta - longa, prevCurta - prevLonga); @@ -11104,13 +11104,13 @@ public static StockData CalculateDisparityIndex(this StockData stockData, Moving var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; + var currentValue = inputList[i]; + var currentSma = smaList[i]; - double prevDisparityIndex = disparityIndexList.LastOrDefault(); - double disparityIndex = currentSma != 0 ? (currentValue - currentSma) / currentSma * 100 : 0; + var prevDisparityIndex = disparityIndexList.LastOrDefault(); + var disparityIndex = currentSma != 0 ? (currentValue - currentSma) / currentSma * 100 : 0; disparityIndexList.AddRounded(disparityIndex); var signal = GetCompareSignal(disparityIndex, prevDisparityIndex); @@ -11146,26 +11146,26 @@ public static StockData CalculateDampingIndex(this StockData stockData, MovingAv var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; - double range = currentHigh - currentLow; + var range = currentHigh - currentLow; rangeList.AddRounded(range); } var rangeSmaList = GetMovingAverageList(stockData, maType, length, rangeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevSma1 = i >= 1 ? rangeSmaList[i - 1] : 0; - double prevSma6 = i >= 6 ? rangeSmaList[i - 6] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; - double currentSma = smaList[i]; + var currentValue = inputList[i]; + var prevSma1 = i >= 1 ? rangeSmaList[i - 1] : 0; + var prevSma6 = i >= 6 ? rangeSmaList[i - 6] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentSma = smaList[i]; - double di = prevSma6 != 0 ? prevSma1 / prevSma6 : 0; + var di = prevSma6 != 0 ? prevSma1 / prevSma6 : 0; diList.AddRounded(di); var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, di, threshold); @@ -11201,19 +11201,19 @@ public static StockData CalculateDirectionalTrendIndex(this StockData stockData, List signalsList = new(); var (_, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double hmu = currentHigh - prevHigh > 0 ? currentHigh - prevHigh : 0; - double lmd = currentLow - prevLow < 0 ? (currentLow - prevLow) * -1 : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var hmu = currentHigh - prevHigh > 0 ? currentHigh - prevHigh : 0; + var lmd = currentLow - prevLow < 0 ? (currentLow - prevLow) * -1 : 0; - double diff = hmu - lmd; + var diff = hmu - lmd; diffList.AddRounded(diff); - double absDiff = Math.Abs(diff); + var absDiff = Math.Abs(diff); absDiffList.AddRounded(absDiff); } @@ -11223,14 +11223,14 @@ public static StockData CalculateDirectionalTrendIndex(this StockData stockData, var absDiffEma2List = GetMovingAverageList(stockData, maType, length2, absDiffEma1List); var diffEma3List = GetMovingAverageList(stockData, maType, length3, diffEma2List); var absDiffEma3List = GetMovingAverageList(stockData, maType, length3, absDiffEma2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double diffEma3 = diffEma3List[i]; - double absDiffEma3 = absDiffEma3List[i]; - double prevDti1 = i >= 1 ? dtiList[i - 1] : 0; - double prevDti2 = i >= 2 ? dtiList[i - 2] : 0; + var diffEma3 = diffEma3List[i]; + var absDiffEma3 = absDiffEma3List[i]; + var prevDti1 = i >= 1 ? dtiList[i - 1] : 0; + var prevDti2 = i >= 2 ? dtiList[i - 2] : 0; - double dti = absDiffEma3 != 0 ? MinOrMax(100 * diffEma3 / absDiffEma3, 100, -100) : 0; + var dti = absDiffEma3 != 0 ? MinOrMax(100 * diffEma3 / absDiffEma3, 100, -100) : 0; dtiList.AddRounded(dti); var signal = GetRsiSignal(dti - prevDti1, prevDti1 - prevDti2, dti, prevDti1, 25, -25); @@ -11267,42 +11267,42 @@ public static StockData CalculateDrunkardWalk(this StockData stockData, int leng var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; + var currentHigh = highList[i]; tempHighList.AddRounded(currentHigh); - double currentLow = lowList[i]; + var currentLow = lowList[i]; tempLowList.AddRounded(currentLow); - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - int maxIndex = tempHighList.LastIndexOf(highestHigh); - int minIndex = tempLowList.LastIndexOf(lowestLow); - int dnRun = i - maxIndex; - int upRun = i - minIndex; + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var maxIndex = tempHighList.LastIndexOf(highestHigh); + var minIndex = tempLowList.LastIndexOf(lowestLow); + var dnRun = i - maxIndex; + var upRun = i - minIndex; - double prevAtrUp = upAtrList.LastOrDefault(); - double upK = upRun != 0 ? (double)1 / upRun : 0; - double atrUp = (tr * upK) + (prevAtrUp * (1 - upK)); + var prevAtrUp = upAtrList.LastOrDefault(); + var upK = upRun != 0 ? (double)1 / upRun : 0; + var atrUp = (tr * upK) + (prevAtrUp * (1 - upK)); upAtrList.AddRounded(atrUp); - double prevAtrDn = dnAtrList.LastOrDefault(); + var prevAtrDn = dnAtrList.LastOrDefault(); var dnK = dnRun != 0 ? (double)1 / dnRun : 0; - double atrDn = (tr * dnK) + (prevAtrDn * (1 - dnK)); + var atrDn = (tr * dnK) + (prevAtrDn * (1 - dnK)); dnAtrList.AddRounded(atrDn); - double upDen = atrUp > 0 ? atrUp : 1; - double prevUpWalk = upwalkList.LastOrDefault(); - double upWalk = upRun > 0 ? (currentHigh - lowestLow) / (Sqrt(upRun) * upDen) : 0; + var upDen = atrUp > 0 ? atrUp : 1; + var prevUpWalk = upwalkList.LastOrDefault(); + var upWalk = upRun > 0 ? (currentHigh - lowestLow) / (Sqrt(upRun) * upDen) : 0; upwalkList.AddRounded(upWalk); - double dnDen = atrDn > 0 ? atrDn : 1; - double prevDnWalk = dnwalkList.LastOrDefault(); - double dnWalk = dnRun > 0 ? (highestHigh - currentLow) / (Sqrt(dnRun) * dnDen) : 0; + var dnDen = atrDn > 0 ? atrDn : 1; + var prevDnWalk = dnwalkList.LastOrDefault(); + var dnWalk = dnRun > 0 ? (highestHigh - currentLow) / (Sqrt(dnRun) * dnDen) : 0; dnwalkList.AddRounded(dnWalk); var signal = GetCompareSignal(upWalk - dnWalk, prevUpWalk - prevDnWalk); @@ -11343,21 +11343,21 @@ public static StockData CalculateDTOscillator(this StockData stockData, MovingAv var wilderMovingAvgList = GetMovingAverageList(stockData, maType, length1, inputList); var (highestList, lowestList) = GetMaxAndMinValuesList(wilderMovingAvgList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wima = wilderMovingAvgList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevSd1 = i >= 1 ? sdList[i - 1] : 0; - double prevSd2 = i >= 2 ? sdList[i - 2] : 0; + var wima = wilderMovingAvgList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevSd1 = i >= 1 ? sdList[i - 1] : 0; + var prevSd2 = i >= 2 ? sdList[i - 2] : 0; - double stoRsi = highest - lowest != 0 ? MinOrMax(100 * (wima - lowest) / (highest - lowest), 100, 0) : 0; + var stoRsi = highest - lowest != 0 ? MinOrMax(100 * (wima - lowest) / (highest - lowest), 100, 0) : 0; stoRsiList.AddRounded(stoRsi); - double sk = stoRsiList.TakeLastExt(length3).Average(); + var sk = stoRsiList.TakeLastExt(length3).Average(); skList.AddRounded(sk); - double sd = skList.TakeLastExt(length4).Average(); + var sd = skList.TakeLastExt(length4).Average(); sdList.AddRounded(sd); var signal = GetRsiSignal(sd - prevSd1, prevSd1 - prevSd2, sd, prevSd1, 70, 30); @@ -11393,29 +11393,29 @@ public static StockData CalculateSmoothedDeltaRatioOscillator(this StockData sto var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double sma = smaList[i]; - double prevSma = i >= length ? smaList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var sma = smaList[i]; + var prevSma = i >= length ? smaList[i - length] : 0; - double absChg = Math.Abs(MinPastValues(i, length, currentValue - prevValue)); + var absChg = Math.Abs(MinPastValues(i, length, currentValue - prevValue)); absChgList.AddRounded(absChg); - double b = MinPastValues(i, length, sma - prevSma); + var b = MinPastValues(i, length, sma - prevSma); bList.AddRounded(b); } var aList = GetMovingAverageList(stockData, maType, length, absChgList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = aList[i]; - double b = bList[i]; - double prevC1 = i >= 1 ? cList[i - 1] : 0; - double prevC2 = i >= 2 ? cList[i - 2] : 0; + var a = aList[i]; + var b = bList[i]; + var prevC1 = i >= 1 ? cList[i - 1] : 0; + var prevC2 = i >= 2 ? cList[i - 2] : 0; - double c = a != 0 ? MinOrMax(b / a, 1, 0) : 0; + var c = a != 0 ? MinOrMax(b / a, 1, 0) : 0; cList.AddRounded(c); var signal = GetRsiSignal(c - prevC1, prevC1 - prevC2, c, prevC1, 0.8, 0.2); @@ -11444,18 +11444,18 @@ public static StockData CalculateSupportAndResistanceOscillator(this StockData s List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double tr = CalculateTrueRange(currentHigh, currentLow, prevClose); - double prevSro1 = i >= 1 ? sroList[i - 1] : 0; - double prevSro2 = i >= 2 ? sroList[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var tr = CalculateTrueRange(currentHigh, currentLow, prevClose); + var prevSro1 = i >= 1 ? sroList[i - 1] : 0; + var prevSro2 = i >= 2 ? sroList[i - 2] : 0; - double sro = tr != 0 ? MinOrMax((currentHigh - currentOpen + (currentClose - currentLow)) / (2 * tr), 1, 0) : 0; + var sro = tr != 0 ? MinOrMax((currentHigh - currentOpen + (currentClose - currentLow)) / (2 * tr), 1, 0) : 0; sroList.AddRounded(sro); var signal = GetRsiSignal(sro - prevSro1, prevSro1 - prevSro2, sro, prevSro1, 0.7, 0.3); @@ -11490,27 +11490,27 @@ public static StockData CalculateStationaryExtrapolatedLevelsOscillator(this Sto var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double prevY = i >= length ? yList[i - length] : 0; - double prevY2 = i >= length * 2 ? yList[i - (length * 2)] : 0; + var currentValue = inputList[i]; + var sma = smaList[i]; + var prevY = i >= length ? yList[i - length] : 0; + var prevY2 = i >= length * 2 ? yList[i - (length * 2)] : 0; - double y = currentValue - sma; + var y = currentValue - sma; yList.AddRounded(y); - double ext = ((2 * prevY) - prevY2) / 2; + var ext = ((2 * prevY) - prevY2) / 2; extList.AddRounded(ext); } stockData.CustomValuesList = extList; var oscList = CalculateStochasticOscillator(stockData, maType, length: length * 2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double osc = oscList[i]; - double prevOsc1 = i >= 1 ? oscList[i - 1] : 0; - double prevOsc2 = i >= 2 ? oscList[i - 2] : 0; + var osc = oscList[i]; + var prevOsc1 = i >= 1 ? oscList[i - 1] : 0; + var prevOsc2 = i >= 2 ? oscList[i - 2] : 0; var signal = GetRsiSignal(osc - prevOsc1, prevOsc1 - prevOsc2, osc, prevOsc1, 80, 20); signalsList.Add(signal); @@ -11540,27 +11540,27 @@ public static StockData CalculateSellGravitationIndex(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double v1 = currentClose - currentOpen; - double v2 = currentHigh - currentLow; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var v1 = currentClose - currentOpen; + var v2 = currentHigh - currentLow; - double v3 = v2 != 0 ? v1 / v2 : 0; + var v3 = v2 != 0 ? v1 / v2 : 0; v3List.AddRounded(v3); } var sgiList = GetMovingAverageList(stockData, maType, length, v3List); var sgiEmaList = GetMovingAverageList(stockData, maType, length, sgiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sgi = sgiList[i]; - double sgiEma = sgiEmaList[i]; - double prevSgi = i >= 1 ? sgiList[i - 1] : 0; - double prevSgiEma = i >= 1 ? sgiEmaList[i - 1] : 0; + var sgi = sgiList[i]; + var sgiEma = sgiEmaList[i]; + var prevSgi = i >= 1 ? sgiList[i - 1] : 0; + var prevSgiEma = i >= 1 ? sgiEmaList[i - 1] : 0; var signal = GetCompareSignal(sgi - sgiEma, prevSgi - prevSgiEma); signalsList.Add(signal); @@ -11595,33 +11595,33 @@ public static StockData CalculateStrengthOfMovement(this StockData stockData, Mo List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length2 - 1 ? inputList[i - (length2 - 1)] : 0; - double moveSe = MinPastValues(i, length2 - 1, currentValue - prevValue); - double avgMoveSe = moveSe / (length2 - 1); + var currentValue = inputList[i]; + var prevValue = i >= length2 - 1 ? inputList[i - (length2 - 1)] : 0; + var moveSe = MinPastValues(i, length2 - 1, currentValue - prevValue); + var avgMoveSe = moveSe / (length2 - 1); - double aaSe = prevValue != 0 ? avgMoveSe / prevValue : 0; + var aaSe = prevValue != 0 ? avgMoveSe / prevValue : 0; aaSeList.AddRounded(aaSe); } var bList = GetMovingAverageList(stockData, maType, length1, aaSeList); stockData.CustomValuesList = bList; var stoList = CalculateStochasticOscillator(stockData, maType, length: length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double bSto = stoList[i]; + var bSto = stoList[i]; - double sSe = (bSto * 2) - 100; + var sSe = (bSto * 2) - 100; sSeList.AddRounded(sSe); } var ssSeList = GetMovingAverageList(stockData, maType, smoothingLength, sSeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ssSe = ssSeList[i]; - double prevSsse = i >= 1 ? ssSeList[i - 1] : 0; + var ssSe = ssSeList[i]; + var prevSsse = i >= 1 ? ssSeList[i - 1] : 0; var signal = GetCompareSignal(ssSe, prevSsse); signalsList.Add(signal); @@ -11654,9 +11654,9 @@ public static StockData CalculateSpearmanIndicator(this StockData stockData, Mov List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); var enumerableList = tempList.TakeLastExt(length).Select(x => (double)x); @@ -11668,12 +11668,12 @@ public static StockData CalculateSpearmanIndicator(this StockData stockData, Mov } var sigList = GetMovingAverageList(stockData, maType, signalLength, coefCorrList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sc = coefCorrList[i]; - double prevSc = i >= 1 ? coefCorrList[i - 1] : 0; - double sig = sigList[i]; - double prevSig = i >= 1 ? sigList[i - 1] : 0; + var sc = coefCorrList[i]; + var prevSc = i >= 1 ? coefCorrList[i - 1] : 0; + var sig = sigList[i]; + var prevSig = i >= 1 ? sigList[i - 1] : 0; var signal = GetCompareSignal(sc - sig, prevSc - prevSig); signalsList.Add(signal); @@ -11706,12 +11706,12 @@ public static StockData CalculateSmoothedWilliamsAccumulationDistribution(this S var wadList = CalculateWilliamsAccumulationDistribution(stockData).CustomValuesList; var wadSignalList = GetMovingAverageList(stockData, maType, length, wadList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wad = wadList[i]; - double wadSma = wadSignalList[i]; - double prevWad = i >= 1 ? wadList[i - 1] : 0; - double prevWadSma = i >= 1 ? wadSignalList[i - 1] : 0; + var wad = wadList[i]; + var wadSma = wadSignalList[i]; + var prevWad = i >= 1 ? wadList[i - 1] : 0; + var prevWadSma = i >= 1 ? wadSignalList[i - 1] : 0; var signal = GetCompareSignal(wad - wadSma, prevWad - prevWadSma); signalsList.Add(signal); @@ -11746,14 +11746,14 @@ public static StockData CalculateSmoothedRateOfChange(this StockData stockData, var maList = GetMovingAverageList(stockData, maType, smoothingLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentMa = maList[i]; - double prevMa = i >= length ? maList[i - length] : 0; - double mom = currentMa - prevMa; + var currentMa = maList[i]; + var prevMa = i >= length ? maList[i - length] : 0; + var mom = currentMa - prevMa; - double prevSroc = srocList.LastOrDefault(); - double sroc = prevMa != 0 ? 100 * mom / prevMa : 100; + var prevSroc = srocList.LastOrDefault(); + var sroc = prevMa != 0 ? 100 * mom / prevMa : 100; srocList.AddRounded(sroc); var signal = GetCompareSignal(sroc, prevSroc); @@ -11788,35 +11788,35 @@ public static StockData CalculateSentimentZoneOscillator(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; double r = currentValue > prevValue ? 1 : -1; rList.AddRounded(r); } var spList = GetMovingAverageList(stockData, maType, fastLength, rList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sp = spList[i]; + var sp = spList[i]; - double szo = fastLength != 0 ? 100 * sp / fastLength : 0; + var szo = fastLength != 0 ? 100 * sp / fastLength : 0; szoList.AddRounded(szo); } var (highestList, lowestList) = GetMaxAndMinValuesList(szoList, slowLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double range = highest - lowest; - double ob = lowest + (range * factor); - double os = highest - (range * factor); - double szo = szoList[i]; - double prevSzo1 = i >= 1 ? szoList[i - 1] : 0; - double prevSzo2 = i >= 2 ? szoList[i - 2] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var range = highest - lowest; + var ob = lowest + (range * factor); + var os = highest - (range * factor); + var szo = szoList[i]; + var prevSzo1 = i >= 1 ? szoList[i - 1] : 0; + var prevSzo2 = i >= 2 ? szoList[i - 2] : 0; var signal = GetRsiSignal(szo - prevSzo1, prevSzo1 - prevSzo2, szo, prevSzo1, ob, os, true); signalsList.Add(signal); @@ -11847,23 +11847,23 @@ public static StockData CalculateSimpleCycle(this StockData stockData, int lengt List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double a = (double)1 / length; + var a = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevC1 = i >= 1 ? cList[i - 1] : 0; - double prevC2 = i >= 2 ? cList[i - 2] : 0; - double prevSrc = i >= length ? srcList[i - length] : 0; + var currentValue = inputList[i]; + var prevC1 = i >= 1 ? cList[i - 1] : 0; + var prevC2 = i >= 2 ? cList[i - 2] : 0; + var prevSrc = i >= length ? srcList[i - length] : 0; - double src = currentValue + prevC1; + var src = currentValue + prevC1; srcList.AddRounded(src); - double cEma = CalculateEMA(prevC1, cEmaList.LastOrDefault(), length); + var cEma = CalculateEMA(prevC1, cEmaList.LastOrDefault(), length); cEmaList.AddRounded(cEma); - double b = prevC1 - cEma; - double c = (a * (src - prevSrc)) + ((1 - a) * b); + var b = prevC1 - cEma; + var c = (a * (src - prevSrc)) + ((1 - a) * b); cList.AddRounded(c); var signal = GetCompareSignal(c - prevC1, prevC1 - prevC2); @@ -11902,26 +11902,26 @@ public static StockData CalculateStiffnessIndicator(this StockData stockData, Mo var smaList = GetMovingAverageList(stockData, maType, length1, inputList); var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double stdDev = stdDevList[i]; - double bound = sma - (0.2 * stdDev); + var currentValue = inputList[i]; + var sma = smaList[i]; + var stdDev = stdDevList[i]; + var bound = sma - (0.2 * stdDev); double above = currentValue > bound ? 1 : 0; aboveList.AddRounded(above); - double aboveSum = aboveList.TakeLastExt(length2).Sum(); - double stiffValue = length2 != 0 ? aboveSum * 100 / length2 : 0; + var aboveSum = aboveList.TakeLastExt(length2).Sum(); + var stiffValue = length2 != 0 ? aboveSum * 100 / length2 : 0; stiffValueList.AddRounded(stiffValue); } var stiffnessList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, smoothingLength, stiffValueList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stiffness = stiffnessList[i]; - double prevStiffness = i >= 1 ? stiffnessList[i - 1] : 0; + var stiffness = stiffnessList[i]; + var prevStiffness = i >= 1 ? stiffnessList[i - 1] : 0; var signal = GetCompareSignal(stiffness - threshold, prevStiffness - threshold); signalsList.Add(signal); @@ -11958,37 +11958,37 @@ public static StockData CalculateSuperTrendFilter(this StockData stockData, int double p = Pow(length, 2), a = 2 / (p + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevTsl1 = i >= 1 ? tslList[i - 1] : currentValue; - double prevTsl2 = i >= 2 ? tslList[i - 2] : 0; - double d = Math.Abs(currentValue - prevTsl1); + var currentValue = inputList[i]; + var prevTsl1 = i >= 1 ? tslList[i - 1] : currentValue; + var prevTsl2 = i >= 2 ? tslList[i - 2] : 0; + var d = Math.Abs(currentValue - prevTsl1); - double prevT = i >= 1 ? tList[i - 1] : d; - double t = (a * d) + ((1 - a) * prevT); + var prevT = i >= 1 ? tList[i - 1] : d; + var t = (a * d) + ((1 - a) * prevT); tList.AddRounded(t); - double prevSrc = srcList.LastOrDefault(); - double src = (factor * prevTsl1) + ((1 - factor) * currentValue); + var prevSrc = srcList.LastOrDefault(); + var src = (factor * prevTsl1) + ((1 - factor) * currentValue); srcList.AddRounded(src); - double up = prevTsl1 - t; - double dn = prevTsl1 + t; + var up = prevTsl1 - t; + var dn = prevTsl1 + t; - double prevTrendUp = trendUpList.LastOrDefault(); - double trendUp = prevSrc > prevTrendUp ? Math.Max(up, prevTrendUp) : up; + var prevTrendUp = trendUpList.LastOrDefault(); + var trendUp = prevSrc > prevTrendUp ? Math.Max(up, prevTrendUp) : up; trendUpList.AddRounded(trendUp); - double prevTrendDn = trendDnList.LastOrDefault(); - double trendDn = prevSrc < prevTrendDn ? Math.Min(dn, prevTrendDn) : dn; + var prevTrendDn = trendDnList.LastOrDefault(); + var trendDn = prevSrc < prevTrendDn ? Math.Min(dn, prevTrendDn) : dn; trendDnList.AddRounded(trendDn); - double prevTrend = i >= 1 ? trendList[i - 1] : 1; - double trend = src > prevTrendDn ? 1 : src < prevTrendUp ? -1 : prevTrend; + var prevTrend = i >= 1 ? trendList[i - 1] : 1; + var trend = src > prevTrendDn ? 1 : src < prevTrendUp ? -1 : prevTrend; trendList.AddRounded(trend); - double tsl = trend == 1 ? trendDn : trendUp; + var tsl = trend == 1 ? trendDn : trendUp; tslList.AddRounded(tsl); var signal = GetCompareSignal(tsl - prevTsl1, prevTsl1 - prevTsl2); @@ -12024,15 +12024,15 @@ public static StockData CalculateSMIErgodicIndicator(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double pc = MinPastValues(i, 1, currentValue - prevValue); + var pc = MinPastValues(i, 1, currentValue - prevValue); pcList.AddRounded(pc); - double absPC = Math.Abs(pc); + var absPC = Math.Abs(pc); absPCList.AddRounded(absPC); } @@ -12040,22 +12040,22 @@ public static StockData CalculateSMIErgodicIndicator(this StockData stockData, M var pcSmooth2List = GetMovingAverageList(stockData, maType, slowLength, pcSmooth1List); var absPCSmooth1List = GetMovingAverageList(stockData, maType, fastLength, absPCList); var absPCSmooth2List = GetMovingAverageList(stockData, maType, slowLength, absPCSmooth1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double absSmooth2PC = absPCSmooth2List[i]; - double smooth2PC = pcSmooth2List[i]; + var absSmooth2PC = absPCSmooth2List[i]; + var smooth2PC = pcSmooth2List[i]; - double smi = absSmooth2PC != 0 ? MinOrMax(100 * smooth2PC / absSmooth2PC, 100, -100) : 0; + var smi = absSmooth2PC != 0 ? MinOrMax(100 * smooth2PC / absSmooth2PC, 100, -100) : 0; smiList.AddRounded(smi); } var smiSignalList = GetMovingAverageList(stockData, maType, signalLength, smiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double smi = smiList[i]; - double smiSignal = smiSignalList[i]; - double prevSmi = i >= 1 ? smiList[i - 1] : 0; - double prevSmiSignal = i >= 1 ? smiSignalList[i - 1] : 0; + var smi = smiList[i]; + var smiSignal = smiSignalList[i]; + var prevSmi = i >= 1 ? smiList[i - 1] : 0; + var prevSmiSignal = i >= 1 ? smiSignalList[i - 1] : 0; var signal = GetRsiSignal(smi - smiSignal, prevSmi - prevSmiSignal, smi, prevSmi, 10, -10); signalsList.Add(signal); @@ -12086,17 +12086,17 @@ public static StockData CalculateSimpleLines(this StockData stockData, int lengt List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double s = 0.01 * 100 * ((double)1 / length); + var s = 0.01 * 100 * ((double)1 / length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double prevA2 = i >= 2 ? aList[i - 2] : currentValue; - double x = currentValue + ((prevA - prevA2) * mult); + var currentValue = inputList[i]; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var prevA2 = i >= 2 ? aList[i - 2] : currentValue; + var x = currentValue + ((prevA - prevA2) * mult); prevA = i >= 1 ? aList[i - 1] : x; - double a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; + var a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; aList.AddRounded(a); var signal = GetCompareSignal(a - prevA, prevA - prevA2); @@ -12136,25 +12136,25 @@ public static StockData CalculateSectorRotationModel(this StockData stockData, S var bear1List = CalculateRateOfChange(marketData, length1).CustomValuesList; var bear2List = CalculateRateOfChange(marketData, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double bull1 = bull1List[i]; - double bull2 = bull2List[i]; - double bear1 = bear1List[i]; - double bear2 = bear2List[i]; - double bull = (bull1 + bull2) / 2; - double bear = (bear1 + bear2) / 2; - - double osc = 100 * (bull - bear); + var bull1 = bull1List[i]; + var bull2 = bull2List[i]; + var bear1 = bear1List[i]; + var bear2 = bear2List[i]; + var bull = (bull1 + bull2) / 2; + var bear = (bear1 + bear2) / 2; + + var osc = 100 * (bull - bear); oscList.AddRounded(osc); } var oscEmaList = GetMovingAverageList(stockData, maType, length1, oscList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double oscEma = oscEmaList[i]; - double prevOscEma1 = i >= 1 ? oscEmaList[i - 1] : 0; - double prevOscEma2 = i >= 2 ? oscEmaList[i - 2] : 0; + var oscEma = oscEmaList[i]; + var prevOscEma1 = i >= 1 ? oscEmaList[i - 1] : 0; + var prevOscEma2 = i >= 2 ? oscEmaList[i - 2] : 0; var signal = GetCompareSignal(oscEma - prevOscEma1, prevOscEma1 - prevOscEma2); signalsList.Add(signal); @@ -12190,39 +12190,39 @@ public static StockData CalculateEnhancedWilliamsR(this StockData stockData, Mov var (highestList1, lowestList1) = GetMaxAndMinValuesList(inputList, length); var (highestList2, lowestList2) = GetMaxAndMinValuesList(volumeList, length); - double af = length < 10 ? 0.25 : ((double)length / 32) - 0.0625; - int smaLength = MinOrMax((int)Math.Ceiling((double)length / 2)); + var af = length < 10 ? 0.25 : ((double)length / 32) - 0.0625; + var smaLength = MinOrMax((int)Math.Ceiling((double)length / 2)); var srcSmaList = GetMovingAverageList(stockData, maType, smaLength, inputList); var volSmaList = GetMovingAverageList(stockData, maType, smaLength, volumeList); - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double maxVol = highestList2[i]; - double minVol = lowestList2[i]; - double maxSrc = highestList1[i]; - double minSrc = lowestList1[i]; - double srcSma = srcSmaList[i]; - double volSma = volSmaList[i]; - double volume = volumeList[i]; - double volWr = maxVol - minVol != 0 ? 2 * ((volume - volSma) / (maxVol - minVol)) : 0; - double srcWr = maxSrc - minSrc != 0 ? 2 * ((currentValue - srcSma) / (maxSrc - minSrc)) : 0; - double srcSwr = maxSrc - minSrc != 0 ? 2 * (MinPastValues(i, 1, currentValue - prevValue) / (maxSrc - minSrc)) : 0; - - double ewr = ((volWr > 0 && srcWr > 0 && currentValue > prevValue) || (volWr > 0 && srcWr < 0 && currentValue < prevValue)) && srcSwr + af != 0 ? + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var maxVol = highestList2[i]; + var minVol = lowestList2[i]; + var maxSrc = highestList1[i]; + var minSrc = lowestList1[i]; + var srcSma = srcSmaList[i]; + var volSma = volSmaList[i]; + var volume = volumeList[i]; + var volWr = maxVol - minVol != 0 ? 2 * ((volume - volSma) / (maxVol - minVol)) : 0; + var srcWr = maxSrc - minSrc != 0 ? 2 * ((currentValue - srcSma) / (maxSrc - minSrc)) : 0; + var srcSwr = maxSrc - minSrc != 0 ? 2 * (MinPastValues(i, 1, currentValue - prevValue) / (maxSrc - minSrc)) : 0; + + var ewr = ((volWr > 0 && srcWr > 0 && currentValue > prevValue) || (volWr > 0 && srcWr < 0 && currentValue < prevValue)) && srcSwr + af != 0 ? ((50 * (srcWr * (srcSwr + af) * volWr)) + srcSwr + af) / (srcSwr + af) : 25 * ((srcWr * (volWr + 1)) + 2); ewrList.AddRounded(ewr); } var ewrSignalList = GetMovingAverageList(stockData, maType, signalLength, ewrList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ewr = ewrList[i]; - double ewrSignal = ewrSignalList[i]; - double prevEwr = i >= 1 ? ewrList[i - 1] : 0; - double prevEwrSignal = i >= 1 ? ewrSignalList[i - 1] : 0; + var ewr = ewrList[i]; + var ewrSignal = ewrSignalList[i]; + var prevEwr = i >= 1 ? ewrList[i - 1] : 0; + var prevEwrSignal = i >= 1 ? ewrSignalList[i - 1] : 0; var signal = GetRsiSignal(ewr - ewrSignal, prevEwr - prevEwrSignal, ewr, prevEwr, 100, -100); signalsList.Add(signal); @@ -12253,21 +12253,21 @@ public static StockData CalculateEarningSupportResistanceLevels(this StockData s List signalsList = new(); var (inputList, highList, lowList, _, closeList, _) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double prevClose = i >= 1 ? closeList[i - 1] : 0; - double prevLow = i >= 2 ? lowList[i - 2] : 0; - double prevValue2 = i >= 2 ? inputList[i - 2] : 0; - double prevValue1 = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var prevClose = i >= 1 ? closeList[i - 1] : 0; + var prevLow = i >= 2 ? lowList[i - 2] : 0; + var prevValue2 = i >= 2 ? inputList[i - 2] : 0; + var prevValue1 = i >= 1 ? inputList[i - 1] : 0; - double prevMode1 = mode1List.LastOrDefault(); - double mode1 = (prevLow + currentHigh) / 2; + var prevMode1 = mode1List.LastOrDefault(); + var mode1 = (prevLow + currentHigh) / 2; mode1List.AddRounded(mode1); - double prevMode2 = mode2List.LastOrDefault(); - double mode2 = (prevValue2 + currentValue + prevClose) / 3; + var prevMode2 = mode2List.LastOrDefault(); + var mode2 = (prevValue2 + currentValue + prevClose) / 3; mode2List.AddRounded(mode2); var signal = GetBullishBearishSignal(currentValue - Math.Max(mode1, mode2), prevValue1 - Math.Max(prevMode1, prevMode2), @@ -12301,27 +12301,27 @@ public static StockData CalculateElderMarketThermometer(this StockData stockData var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; - double emt = currentHigh < prevHigh && currentLow > prevLow ? 0 : currentHigh - prevHigh > prevLow - currentLow ? Math.Abs(currentHigh - prevHigh) : + var emt = currentHigh < prevHigh && currentLow > prevLow ? 0 : currentHigh - prevHigh > prevLow - currentLow ? Math.Abs(currentHigh - prevHigh) : Math.Abs(prevLow - currentLow); emtList.AddRounded(emt); } var aemtList = GetMovingAverageList(stockData, maType, length, emtList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double emt = emtList[i]; - double emtEma = aemtList[i]; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var emt = emtList[i]; + var emtEma = aemtList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, emt, emtEma); signalsList.Add(signal); @@ -12358,23 +12358,23 @@ public static StockData CalculateElliottWaveOscillator(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var sma34List = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentSma5 = smaList[i]; - double currentSma34 = sma34List[i]; + var currentSma5 = smaList[i]; + var currentSma34 = sma34List[i]; - double ewo = currentSma5 - currentSma34; + var ewo = currentSma5 - currentSma34; ewoList.AddRounded(ewo); } var ewoSignalLineList = GetMovingAverageList(stockData, maType, fastLength, ewoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ewo = ewoList[i]; - double ewoSignalLine = ewoSignalLineList[i]; + var ewo = ewoList[i]; + var ewoSignalLine = ewoSignalLineList[i]; - double prevEwoHistogram = ewoHistogramList.LastOrDefault(); - double ewoHistogram = ewo - ewoSignalLine; + var prevEwoHistogram = ewoHistogramList.LastOrDefault(); + var ewoHistogram = ewo - ewoSignalLine; ewoHistogramList.AddRounded(ewoHistogram); var signal = GetCompareSignal(ewoHistogram, prevEwoHistogram); @@ -12411,17 +12411,17 @@ public static StockData CalculateErgodicCandlestickOscillator(this StockData sto List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; - double xco = currentClose - currentOpen; + var xco = currentClose - currentOpen; xcoList.AddRounded(xco); - double xhl = currentHigh - currentLow; + var xhl = currentHigh - currentLow; xhlList.AddRounded(xhl); } @@ -12429,22 +12429,22 @@ public static StockData CalculateErgodicCandlestickOscillator(this StockData sto var xcoEma2List = GetMovingAverageList(stockData, maType, length2, xcoEma1List); var xhlEma1List = GetMovingAverageList(stockData, maType, length1, xhlList); var xhlEma2List = GetMovingAverageList(stockData, maType, length2, xhlEma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double xhlEma2 = xhlEma2List[i]; - double xcoEma2 = xcoEma2List[i]; + var xhlEma2 = xhlEma2List[i]; + var xcoEma2 = xcoEma2List[i]; - double eco = xhlEma2 != 0 ? 100 * xcoEma2 / xhlEma2 : 0; + var eco = xhlEma2 != 0 ? 100 * xcoEma2 / xhlEma2 : 0; ecoList.AddRounded(eco); } var ecoSignalList = GetMovingAverageList(stockData, maType, length2, ecoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double eco = ecoList[i]; - double ecoEma = ecoSignalList[i]; - double prevEco = i >= 1 ? ecoList[i - 1] : 0; - double prevEcoEma = i >= 1 ? ecoSignalList[i - 1] : 0; + var eco = ecoList[i]; + var ecoEma = ecoSignalList[i]; + var prevEco = i >= 1 ? ecoList[i - 1] : 0; + var prevEcoEma = i >= 1 ? ecoSignalList[i - 1] : 0; var signal = GetCompareSignal(eco - ecoEma, prevEco - prevEcoEma); signalsList.Add(signal); @@ -12481,15 +12481,15 @@ public static StockData CalculateErgodicTrueStrengthIndexV1(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double priceDiff = MinPastValues(i, 1, currentValue - prevValue); + var priceDiff = MinPastValues(i, 1, currentValue - prevValue); priceDiffList.AddRounded(priceDiff); - double absPriceDiff = Math.Abs(priceDiff); + var absPriceDiff = Math.Abs(priceDiff); absPriceDiffList.AddRounded(absPriceDiff); } @@ -12499,22 +12499,22 @@ public static StockData CalculateErgodicTrueStrengthIndexV1(this StockData stock var absDiffEma2List = GetMovingAverageList(stockData, maType, length2, absDiffEma1List); var diffEma3List = GetMovingAverageList(stockData, maType, length3, diffEma2List); var absDiffEma3List = GetMovingAverageList(stockData, maType, length3, absDiffEma2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double diffEma3 = diffEma3List[i]; - double absDiffEma3 = absDiffEma3List[i]; + var diffEma3 = diffEma3List[i]; + var absDiffEma3 = absDiffEma3List[i]; - double etsi = absDiffEma3 != 0 ? MinOrMax(100 * diffEma3 / absDiffEma3, 100, -100) : 0; + var etsi = absDiffEma3 != 0 ? MinOrMax(100 * diffEma3 / absDiffEma3, 100, -100) : 0; etsiList.AddRounded(etsi); } var etsiSignalList = GetMovingAverageList(stockData, maType, signalLength, etsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double etsi = etsiList[i]; - double etsiSignal = etsiSignalList[i]; - double prevEtsi = i >= 1 ? etsiList[i - 1] : 0; - double prevEtsiSignal = i >= 1 ? etsiSignalList[i - 1] : 0; + var etsi = etsiList[i]; + var etsiSignal = etsiSignalList[i]; + var prevEtsi = i >= 1 ? etsiList[i - 1] : 0; + var prevEtsiSignal = i >= 1 ? etsiSignalList[i - 1] : 0; var signal = GetCompareSignal(etsi - etsiSignal, prevEtsi - prevEtsiSignal); signalsList.Add(signal); @@ -12555,15 +12555,15 @@ public static StockData CalculateErgodicTrueStrengthIndexV2(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double priceDiff = MinPastValues(i, 1, currentValue - prevValue); + var priceDiff = MinPastValues(i, 1, currentValue - prevValue); priceDiffList.AddRounded(priceDiff); - double absPriceDiff = Math.Abs(priceDiff); + var absPriceDiff = Math.Abs(priceDiff); absPriceDiffList.AddRounded(absPriceDiff); } @@ -12579,27 +12579,27 @@ public static StockData CalculateErgodicTrueStrengthIndexV2(this StockData stock var absDiffEma3List = GetMovingAverageList(stockData, maType, length3, absDiffEma2List); var diffEma6List = GetMovingAverageList(stockData, maType, length6, diffEma5List); var absDiffEma6List = GetMovingAverageList(stockData, maType, length6, absDiffEma5List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double diffEma6 = diffEma6List[i]; - double absDiffEma6 = absDiffEma6List[i]; - double diffEma3 = diffEma3List[i]; - double absDiffEma3 = absDiffEma3List[i]; + var diffEma6 = diffEma6List[i]; + var absDiffEma6 = absDiffEma6List[i]; + var diffEma3 = diffEma3List[i]; + var absDiffEma3 = absDiffEma3List[i]; - double etsi1 = absDiffEma3 != 0 ? MinOrMax(diffEma3 / absDiffEma3 * 100, 100, -100) : 0; + var etsi1 = absDiffEma3 != 0 ? MinOrMax(diffEma3 / absDiffEma3 * 100, 100, -100) : 0; etsi1List.AddRounded(etsi1); - double etsi2 = absDiffEma6 != 0 ? MinOrMax(diffEma6 / absDiffEma6 * 100, 100, -100) : 0; + var etsi2 = absDiffEma6 != 0 ? MinOrMax(diffEma6 / absDiffEma6 * 100, 100, -100) : 0; etsi2List.AddRounded(etsi2); } var etsi2SignalList = GetMovingAverageList(stockData, maType, signalLength, etsi2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double etsi2 = etsi2List[i]; - double etsi2Signal = etsi2SignalList[i]; - double prevEtsi2 = i >= 1 ? etsi2List[i - 1] : 0; - double prevEtsi2Signal = i >= 1 ? etsi2SignalList[i - 1] : 0; + var etsi2 = etsi2List[i]; + var etsi2Signal = etsi2SignalList[i]; + var prevEtsi2 = i >= 1 ? etsi2List[i - 1] : 0; + var prevEtsi2Signal = i >= 1 ? etsi2SignalList[i - 1] : 0; var signal = GetCompareSignal(etsi2 - etsi2Signal, prevEtsi2 - prevEtsi2Signal); signalsList.Add(signal); @@ -12634,32 +12634,32 @@ public static StockData CalculateErgodicCommoditySelectionIndex(this StockData s List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - double k = 100 * (pointValue / Sqrt(length) / (150 + smoothLength)); + var k = 100 * (pointValue / Sqrt(length) / (150 + smoothLength)); var adxList = CalculateAverageDirectionalIndex(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = inputList[i]; - double adx = adxList[i]; - double prevAdx = i >= 1 ? adxList[i - 1] : 0; - double adxR = (adx + prevAdx) * 0.5; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - double csi = length + tr > 0 ? k * adxR * tr / length : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = inputList[i]; + var adx = adxList[i]; + var prevAdx = i >= 1 ? adxList[i - 1] : 0; + var adxR = (adx + prevAdx) * 0.5; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var csi = length + tr > 0 ? k * adxR * tr / length : 0; - double ergodicCsi = currentValue > 0 ? csi / currentValue : 0; + var ergodicCsi = currentValue > 0 ? csi / currentValue : 0; ergodicCsiList.AddRounded(ergodicCsi); } var ergodicCsiSmaList = GetMovingAverageList(stockData, maType, smoothLength, ergodicCsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ergodicCsiSma = ergodicCsiSmaList[i]; - double prevErgodicCsiSma1 = i >= 1 ? ergodicCsiSmaList[i - 1] : 0; - double prevErgodicCsiSma2 = i >= 2 ? ergodicCsiSmaList[i - 2] : 0; + var ergodicCsiSma = ergodicCsiSmaList[i]; + var prevErgodicCsiSma1 = i >= 1 ? ergodicCsiSmaList[i - 1] : 0; + var prevErgodicCsiSma2 = i >= 2 ? ergodicCsiSmaList[i - 2] : 0; var signal = GetCompareSignal(ergodicCsiSma - prevErgodicCsiSma1, prevErgodicCsiSma1 - prevErgodicCsiSma2); signalsList.Add(signal); @@ -12693,29 +12693,29 @@ public static StockData CalculateEnhancedIndex(this StockData stockData, MovingA var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - int smaLength = MinOrMax((int)Math.Ceiling((double)length / 2)); + var smaLength = MinOrMax((int)Math.Ceiling((double)length / 2)); var smaList = GetMovingAverageList(stockData, maType, smaLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double dnm = highest - lowest; - double sma = smaList[i]; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var dnm = highest - lowest; + var sma = smaList[i]; - double closewr = dnm != 0 ? 2 * (currentValue - sma) / dnm : 0; + var closewr = dnm != 0 ? 2 * (currentValue - sma) / dnm : 0; closewrList.AddRounded(closewr); } var closewrSmaList = GetMovingAverageList(stockData, maType, signalLength, closewrList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double closewr = closewrList[i]; - double closewrSma = closewrSmaList[i]; - double prevCloseWr = i >= 1 ? closewrList[i - 1] : 0; - double prevCloseWrSma = i >= 1 ? closewrSmaList[i - 1] : 0; + var closewr = closewrList[i]; + var closewrSma = closewrSmaList[i]; + var prevCloseWr = i >= 1 ? closewrList[i - 1] : 0; + var prevCloseWrSma = i >= 1 ? closewrSmaList[i - 1] : 0; var signal = GetCompareSignal(closewr - closewrSma, prevCloseWr - prevCloseWrSma); signalsList.Add(signal); @@ -12754,31 +12754,31 @@ public static StockData CalculateEmaWaveIndicator(this StockData stockData, int var emaBList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length2, inputList); var emaCList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length3, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double emaA = emaAList[i]; - double emaB = emaBList[i]; - double emaC = emaCList[i]; + var currentValue = inputList[i]; + var emaA = emaAList[i]; + var emaB = emaBList[i]; + var emaC = emaCList[i]; - double emaADiff = currentValue - emaA; + var emaADiff = currentValue - emaA; emaADiffList.AddRounded(emaADiff); - double emaBDiff = currentValue - emaB; + var emaBDiff = currentValue - emaB; emaBDiffList.AddRounded(emaBDiff); - double emaCDiff = currentValue - emaC; + var emaCDiff = currentValue - emaC; emaCDiffList.AddRounded(emaCDiff); } var waList = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, smoothLength, emaADiffList); var wbList = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, smoothLength, emaBDiffList); var wcList = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, smoothLength, emaCDiffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wa = waList[i]; - double wb = wbList[i]; - double wc = wcList[i]; + var wa = waList[i]; + var wb = wbList[i]; + var wc = wcList[i]; var signal = GetConditionSignal(wa > 0 && wb > 0 && wc > 0, wa < 0 && wb < 0 && wc < 0); signalsList.Add(signal); @@ -12816,24 +12816,24 @@ public static StockData CalculateErgodicMeanDeviationIndicator(this StockData st var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; + var currentValue = inputList[i]; + var currentEma = emaList[i]; - double ma1 = currentValue - currentEma; + var ma1 = currentValue - currentEma; ma1List.AddRounded(ma1); } var ma1EmaList = GetMovingAverageList(stockData, maType, length2, ma1List); var emdiList = GetMovingAverageList(stockData, maType, length3, ma1EmaList); var emdiSignalList = GetMovingAverageList(stockData, maType, signalLength, emdiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double emdi = emdiList[i]; - double emdiSignal = emdiSignalList[i]; - double prevEmdi = i >= 1 ? emdiList[i - 1] : 0; - double prevEmdiSignal = i >= 1 ? emdiSignalList[i - 1] : 0; + var emdi = emdiList[i]; + var emdiSignal = emdiSignalList[i]; + var prevEmdi = i >= 1 ? emdiList[i - 1] : 0; + var prevEmdiSignal = i >= 1 ? emdiSignalList[i - 1] : 0; var signal = GetCompareSignal(emdi - emdiSignal, prevEmdi - prevEmdiSignal); signalsList.Add(signal); @@ -12866,18 +12866,18 @@ public static StockData CalculateEfficientPrice(this StockData stockData, int le var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double er = erList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double prevEp1 = i >= 1 ? epList[i - 1] : 0; - double prevEp2 = i >= 2 ? epList[i - 2] : 0; + var currentValue = inputList[i]; + var er = erList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var prevEp1 = i >= 1 ? epList[i - 1] : 0; + var prevEp2 = i >= 2 ? epList[i - 2] : 0; - double chgEr = MinPastValues(i, length, currentValue - prevValue) * er; + var chgEr = MinPastValues(i, length, currentValue - prevValue) * er; chgErList.AddRounded(chgEr); - double ep = chgErList.Sum(); + var ep = chgErList.Sum(); epList.AddRounded(ep); var signal = GetCompareSignal(ep - prevEp1, prevEp1 - prevEp2); @@ -12911,15 +12911,15 @@ public static StockData CalculateEfficientAutoLine(this StockData stockData, int var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double er = erList[i]; - double dev = (er * fastAlpha) + ((1 - er) * slowAlpha); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var er = erList[i]; + var dev = (er * fastAlpha) + ((1 - er) * slowAlpha); - double prevA = aList.LastOrDefault(); - double a = i < 9 ? currentValue : currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; + var prevA = aList.LastOrDefault(); + var a = i < 9 ? currentValue : currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; aList.AddRounded(a); var signal = GetCompareSignal(currentValue - a, prevValue - prevA); diff --git a/src/Calculations/PivotPoint.cs b/src/Calculations/PivotPoint.cs index 22ea958..5e076f4 100644 --- a/src/Calculations/PivotPoint.cs +++ b/src/Calculations/PivotPoint.cs @@ -36,54 +36,54 @@ public static StockData CalculateStandardPivotPoints(this StockData stockData, I List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevOpen = i >= 1 ? openList[i - 1] : 0; - - double prevPivot = pivotList.LastOrDefault(); - double range = prevHigh - prevLow; - double pivot = (prevHigh + prevLow + prevClose + prevOpen) / 4; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevOpen = i >= 1 ? openList[i - 1] : 0; + + var prevPivot = pivotList.LastOrDefault(); + var range = prevHigh - prevLow; + var pivot = (prevHigh + prevLow + prevClose + prevOpen) / 4; pivotList.AddRounded(pivot); - double supportLevel1 = (pivot * 2) - prevHigh; + var supportLevel1 = (pivot * 2) - prevHigh; supportLevel1List.AddRounded(supportLevel1); - double resistanceLevel1 = (pivot * 2) - prevLow; + var resistanceLevel1 = (pivot * 2) - prevLow; resistanceLevel1List.AddRounded(resistanceLevel1); - double range2 = resistanceLevel1 - supportLevel1; - double supportLevel2 = pivot - range; + var range2 = resistanceLevel1 - supportLevel1; + var supportLevel2 = pivot - range; supportLevel2List.AddRounded(supportLevel2); - double resistanceLevel2 = pivot + range; + var resistanceLevel2 = pivot + range; resistanceLevel2List.AddRounded(resistanceLevel2); - double supportLevel3 = pivot - range2; + var supportLevel3 = pivot - range2; supportLevel3List.AddRounded(supportLevel3); - double resistanceLevel3 = pivot + range2; + var resistanceLevel3 = pivot + range2; resistanceLevel3List.AddRounded(resistanceLevel3); - double midpoint1 = (supportLevel3 + supportLevel2) / 2; + var midpoint1 = (supportLevel3 + supportLevel2) / 2; midpoint1List.AddRounded(midpoint1); - double midpoint2 = (supportLevel2 + supportLevel1) / 2; + var midpoint2 = (supportLevel2 + supportLevel1) / 2; midpoint2List.AddRounded(midpoint2); - double midpoint3 = (supportLevel1 + pivot) / 2; + var midpoint3 = (supportLevel1 + pivot) / 2; midpoint3List.AddRounded(midpoint3); - double midpoint4 = (resistanceLevel1 + pivot) / 2; + var midpoint4 = (resistanceLevel1 + pivot) / 2; midpoint4List.AddRounded(midpoint4); - double midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; + var midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; midpoint5List.AddRounded(midpoint5); - double midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; + var midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; midpoint6List.AddRounded(midpoint6); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); @@ -137,52 +137,52 @@ public static StockData CalculateWoodiePivotPoints(this StockData stockData, Inp List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentClose = inputList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - - double prevPivot = pivotList.LastOrDefault(); - double range = prevHigh - prevLow; - double pivot = (prevHigh + prevLow + (prevClose * 2)) / 4; + var currentClose = inputList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + + var prevPivot = pivotList.LastOrDefault(); + var range = prevHigh - prevLow; + var pivot = (prevHigh + prevLow + (prevClose * 2)) / 4; pivotList.AddRounded(pivot); - double supportLevel1 = (pivot * 2) - prevHigh; + var supportLevel1 = (pivot * 2) - prevHigh; supportLevel1List.AddRounded(supportLevel1); - double resistanceLevel1 = (pivot * 2) - prevLow; + var resistanceLevel1 = (pivot * 2) - prevLow; resistanceLevel1List.AddRounded(resistanceLevel1); - double supportLevel2 = pivot - range; + var supportLevel2 = pivot - range; supportLevel2List.AddRounded(supportLevel2); - double resistanceLevel2 = pivot + range; + var resistanceLevel2 = pivot + range; resistanceLevel2List.AddRounded(resistanceLevel2); - double supportLevel3 = prevLow - (2 * (prevHigh - pivot)); + var supportLevel3 = prevLow - (2 * (prevHigh - pivot)); supportLevel3List.AddRounded(supportLevel3); - double resistanceLevel3 = prevHigh + (2 * (pivot - prevLow)); + var resistanceLevel3 = prevHigh + (2 * (pivot - prevLow)); resistanceLevel3List.AddRounded(resistanceLevel3); - double supportLevel4 = supportLevel3 - range; + var supportLevel4 = supportLevel3 - range; supportLevel4List.AddRounded(supportLevel4); - double resistanceLevel4 = resistanceLevel3 + range; + var resistanceLevel4 = resistanceLevel3 + range; resistanceLevel4List.AddRounded(resistanceLevel4); - double midpoint1 = (supportLevel1 + supportLevel2) / 2; + var midpoint1 = (supportLevel1 + supportLevel2) / 2; midpoint1List.AddRounded(midpoint1); - double midpoint2 = (pivot + supportLevel1) / 2; + var midpoint2 = (pivot + supportLevel1) / 2; midpoint2List.AddRounded(midpoint2); - double midpoint3 = (resistanceLevel1 + pivot) / 2; + var midpoint3 = (resistanceLevel1 + pivot) / 2; midpoint3List.AddRounded(midpoint3); - double midpoint4 = (resistanceLevel1 + resistanceLevel2) / 2; + var midpoint4 = (resistanceLevel1 + resistanceLevel2) / 2; midpoint4List.AddRounded(midpoint4); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); @@ -236,53 +236,53 @@ public static StockData CalculateFloorPivotPoints(this StockData stockData, Inpu List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentClose = inputList[i]; - double prevHigh = i >= 1 ? highList[i] : 0; - double prevLow = i >= 1 ? lowList[i] : 0; - double prevClose = i >= 1 ? inputList[i] : 0; + var currentClose = inputList[i]; + var prevHigh = i >= 1 ? highList[i] : 0; + var prevLow = i >= 1 ? lowList[i] : 0; + var prevClose = i >= 1 ? inputList[i] : 0; - double range = prevHigh - prevLow; - double pivot = (prevHigh + prevLow + prevClose) / 3; + var range = prevHigh - prevLow; + var pivot = (prevHigh + prevLow + prevClose) / 3; pivotList.AddRounded(pivot); - double prevSupportLevel1 = supportLevel1List.LastOrDefault(); - double supportLevel1 = (pivot * 2) - prevHigh; + var prevSupportLevel1 = supportLevel1List.LastOrDefault(); + var supportLevel1 = (pivot * 2) - prevHigh; supportLevel1List.AddRounded(supportLevel1); - double prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); - double resistanceLevel1 = (pivot * 2) - prevLow; + var prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); + var resistanceLevel1 = (pivot * 2) - prevLow; resistanceLevel1List.AddRounded(resistanceLevel1); - double supportLevel2 = pivot - range; + var supportLevel2 = pivot - range; supportLevel2List.AddRounded(supportLevel2); - double resistanceLevel2 = pivot + range; + var resistanceLevel2 = pivot + range; resistanceLevel2List.AddRounded(resistanceLevel2); - double supportLevel3 = supportLevel1 - range; + var supportLevel3 = supportLevel1 - range; supportLevel3List.AddRounded(supportLevel3); - double resistanceLevel3 = resistanceLevel1 + range; + var resistanceLevel3 = resistanceLevel1 + range; resistanceLevel3List.AddRounded(resistanceLevel3); - double midpoint1 = (supportLevel3 + supportLevel2) / 2; + var midpoint1 = (supportLevel3 + supportLevel2) / 2; midpoint1List.AddRounded(midpoint1); - double midpoint2 = (supportLevel2 + supportLevel1) / 2; + var midpoint2 = (supportLevel2 + supportLevel1) / 2; midpoint2List.AddRounded(midpoint2); - double midpoint3 = (supportLevel1 + pivot) / 2; + var midpoint3 = (supportLevel1 + pivot) / 2; midpoint3List.AddRounded(midpoint3); - double midpoint4 = (resistanceLevel1 + pivot) / 2; + var midpoint4 = (resistanceLevel1 + pivot) / 2; midpoint4List.AddRounded(midpoint4); - double midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; + var midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; midpoint5List.AddRounded(midpoint5); - double midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; + var midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; midpoint6List.AddRounded(midpoint6); var signal = GetBullishBearishSignal(currentClose - resistanceLevel1, prevClose - prevResistanceLevel1, @@ -337,52 +337,52 @@ public static StockData CalculateFibonacciPivotPoints(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - - double prevPivot = pivotList.LastOrDefault(); - double range = prevHigh - prevLow; - double pivot = (prevHigh + prevLow + prevClose) / 3; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + + var prevPivot = pivotList.LastOrDefault(); + var range = prevHigh - prevLow; + var pivot = (prevHigh + prevLow + prevClose) / 3; pivotList.AddRounded(pivot); - double supportLevel1 = pivot - (range * 0.382); + var supportLevel1 = pivot - (range * 0.382); supportLevel1List.AddRounded(supportLevel1); - double supportLevel2 = pivot - (range * 0.618); + var supportLevel2 = pivot - (range * 0.618); supportLevel2List.AddRounded(supportLevel2); - double supportLevel3 = pivot - (range * 1); + var supportLevel3 = pivot - (range * 1); supportLevel3List.AddRounded(supportLevel3); - double resistanceLevel1 = pivot + (range * 0.382); + var resistanceLevel1 = pivot + (range * 0.382); resistanceLevel1List.AddRounded(resistanceLevel1); - double resistanceLevel2 = pivot + (range * 0.618); + var resistanceLevel2 = pivot + (range * 0.618); resistanceLevel2List.AddRounded(resistanceLevel2); - double resistanceLevel3 = pivot + (range * 1); + var resistanceLevel3 = pivot + (range * 1); resistanceLevel3List.AddRounded(resistanceLevel3); - double midpoint1 = (supportLevel3 + supportLevel2) / 2; + var midpoint1 = (supportLevel3 + supportLevel2) / 2; midpoint1List.AddRounded(midpoint1); - double midpoint2 = (supportLevel2 + supportLevel1) / 2; + var midpoint2 = (supportLevel2 + supportLevel1) / 2; midpoint2List.AddRounded(midpoint2); - double midpoint3 = (supportLevel1 + pivot) / 2; + var midpoint3 = (supportLevel1 + pivot) / 2; midpoint3List.AddRounded(midpoint3); - double midpoint4 = (resistanceLevel1 + pivot) / 2; + var midpoint4 = (resistanceLevel1 + pivot) / 2; midpoint4List.AddRounded(midpoint4); - double midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; + var midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; midpoint5List.AddRounded(midpoint5); - double midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; + var midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; midpoint6List.AddRounded(midpoint6); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); @@ -440,67 +440,67 @@ public static StockData CalculateCamarillaPivotPoints(this StockData stockData, List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double currentClose = i >= 1 ? prevClose : inputList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double currentHigh = i >= 1 ? prevHigh : highList[i]; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double currentLow = i >= 1 ? prevLow : lowList[i]; - double range = currentHigh - currentLow; - - double pivot = (prevHigh + prevLow + prevClose) / 3; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentClose = i >= 1 ? prevClose : inputList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var currentHigh = i >= 1 ? prevHigh : highList[i]; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var currentLow = i >= 1 ? prevLow : lowList[i]; + var range = currentHigh - currentLow; + + var pivot = (prevHigh + prevLow + prevClose) / 3; pivotList.AddRounded(pivot); - double prevSupportLevel1 = supportLevel1List.LastOrDefault(); - double supportLevel1 = currentClose - (0.0916 * range); + var prevSupportLevel1 = supportLevel1List.LastOrDefault(); + var supportLevel1 = currentClose - (0.0916 * range); supportLevel1List.AddRounded(supportLevel1); - double supportLevel2 = currentClose - (0.183 * range); + var supportLevel2 = currentClose - (0.183 * range); supportLevel2List.AddRounded(supportLevel2); - double supportLevel3 = currentClose - (0.275 * range); + var supportLevel3 = currentClose - (0.275 * range); supportLevel3List.AddRounded(supportLevel3); - double supportLevel4 = currentClose - (0.55 * range); + var supportLevel4 = currentClose - (0.55 * range); supportLevel4List.AddRounded(supportLevel4); - double prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); - double resistanceLevel1 = currentClose + (0.0916 * range); + var prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); + var resistanceLevel1 = currentClose + (0.0916 * range); resistanceLevel1List.AddRounded(resistanceLevel1); - double resistanceLevel2 = currentClose + (0.183 * range); + var resistanceLevel2 = currentClose + (0.183 * range); resistanceLevel2List.AddRounded(resistanceLevel2); - double resistanceLevel3 = currentClose + (0.275 * range); + var resistanceLevel3 = currentClose + (0.275 * range); resistanceLevel3List.AddRounded(resistanceLevel3); - double resistanceLevel4 = currentClose + (0.55 * range); + var resistanceLevel4 = currentClose + (0.55 * range); resistanceLevel4List.AddRounded(resistanceLevel4); - double resistanceLevel5 = currentLow != 0 ? currentHigh / currentLow * currentClose : 0; + var resistanceLevel5 = currentLow != 0 ? currentHigh / currentLow * currentClose : 0; resistanceLevel5List.AddRounded(resistanceLevel5); - double supportLevel5 = currentClose - (resistanceLevel5 - currentClose); + var supportLevel5 = currentClose - (resistanceLevel5 - currentClose); supportLevel5List.AddRounded(supportLevel5); - double midpoint1 = (supportLevel3 + supportLevel2) / 2; + var midpoint1 = (supportLevel3 + supportLevel2) / 2; midpoint1List.AddRounded(midpoint1); - double midpoint2 = (supportLevel2 + supportLevel1) / 2; + var midpoint2 = (supportLevel2 + supportLevel1) / 2; midpoint2List.AddRounded(midpoint2); - double midpoint3 = (resistanceLevel2 + resistanceLevel1) / 2; + var midpoint3 = (resistanceLevel2 + resistanceLevel1) / 2; midpoint3List.AddRounded(midpoint3); - double midpoint4 = (resistanceLevel3 + resistanceLevel2) / 2; + var midpoint4 = (resistanceLevel3 + resistanceLevel2) / 2; midpoint4List.AddRounded(midpoint4); - double midpoint5 = (resistanceLevel3 + resistanceLevel4) / 2; + var midpoint5 = (resistanceLevel3 + resistanceLevel4) / 2; midpoint5List.AddRounded(midpoint5); - double midpoint6 = (supportLevel4 + supportLevel3) / 2; + var midpoint6 = (supportLevel4 + supportLevel3) / 2; midpoint6List.AddRounded(midpoint6); var signal = GetBullishBearishSignal(currentClose - resistanceLevel1, prevClose - prevResistanceLevel1, currentClose - supportLevel1, @@ -551,32 +551,32 @@ public static StockData CalculatePivotPointAverage(this StockData stockData, Mov List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentOpen = openList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentOpen = openList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 1 ? inputList[i - 1] : 0; - double pp1 = (prevHigh + prevLow + prevClose) / 3; + var pp1 = (prevHigh + prevLow + prevClose) / 3; pp1List.AddRounded(pp1); - double pp2 = (prevHigh + prevLow + prevClose + currentOpen) / 4; + var pp2 = (prevHigh + prevLow + prevClose + currentOpen) / 4; pp2List.AddRounded(pp2); - double pp3 = (prevHigh + prevLow + currentOpen) / 3; + var pp3 = (prevHigh + prevLow + currentOpen) / 3; pp3List.AddRounded(pp3); } var ppav1List = GetMovingAverageList(stockData, maType, length, pp1List); var ppav2List = GetMovingAverageList(stockData, maType, length, pp2List); var ppav3List = GetMovingAverageList(stockData, maType, length, pp3List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pp1 = pp1List[i]; - double ppav1 = ppav1List[i]; - double prevPp1 = i >= 1 ? pp1List[i - 1] : 0; - double prevPpav1 = i >= 1 ? ppav1List[i - 1] : 0; + var pp1 = pp1List[i]; + var ppav1 = ppav1List[i]; + var prevPp1 = i >= 1 ? pp1List[i - 1] : 0; + var prevPpav1 = i >= 1 ? ppav1List[i - 1] : 0; var signal = GetCompareSignal(pp1 - ppav1, prevPp1 - prevPpav1); signalsList.Add(signal); @@ -612,25 +612,25 @@ public static StockData CalculateDemarkPivotPoints(this StockData stockData, Inp List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevOpen = i >= 1 ? openList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double x = prevClose < prevOpen ? prevHigh + (2 * prevLow) + prevClose : prevClose > prevOpen ? (2 * prevHigh) + prevLow + prevClose : + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevOpen = i >= 1 ? openList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var x = prevClose < prevOpen ? prevHigh + (2 * prevLow) + prevClose : prevClose > prevOpen ? (2 * prevHigh) + prevLow + prevClose : prevClose == prevOpen ? prevHigh + prevLow + (2 * prevClose) : prevClose; - double prevPivot = pivotList.LastOrDefault(); - double pivot = x / 4; + var prevPivot = pivotList.LastOrDefault(); + var pivot = x / 4; pivotList.AddRounded(pivot); - double ratio = x / 2; - double supportLevel1 = ratio - prevHigh; + var ratio = x / 2; + var supportLevel1 = ratio - prevHigh; supportLevel1List.AddRounded(supportLevel1); - double resistanceLevel1 = ratio - prevLow; + var resistanceLevel1 = ratio - prevLow; resistanceLevel1List.AddRounded(resistanceLevel1); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); @@ -664,22 +664,22 @@ public static StockData CalculateDynamicPivotPoints(this StockData stockData, In List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData, inputLength); - for (int i = 0; i < inputList.Count; i++) + for (var i = 0; i < inputList.Count; i++) { - double currentClose = inputList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentClose = inputList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 1 ? inputList[i - 1] : 0; - double pivot = (prevHigh + prevLow + prevClose) / 3; + var pivot = (prevHigh + prevLow + prevClose) / 3; pivotList.AddRounded(pivot); - double prevSupportLevel1 = supportLevel1List.LastOrDefault(); - double supportLevel1 = pivot - (prevHigh - pivot); + var prevSupportLevel1 = supportLevel1List.LastOrDefault(); + var supportLevel1 = pivot - (prevHigh - pivot); supportLevel1List.AddRounded(supportLevel1); - double prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); - double resistanceLevel1 = pivot + (pivot - prevLow); + var prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); + var resistanceLevel1 = pivot + (pivot - prevLow); resistanceLevel1List.AddRounded(resistanceLevel1); var signal = GetBullishBearishSignal(currentClose - resistanceLevel1, prevClose - prevResistanceLevel1, diff --git a/src/Calculations/Ppo.cs b/src/Calculations/Ppo.cs index 3ad09a2..35ef05e 100644 --- a/src/Calculations/Ppo.cs +++ b/src/Calculations/Ppo.cs @@ -32,23 +32,23 @@ public static StockData CalculatePercentagePriceOscillator(this StockData stockD var fastEmaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowEmaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastEma = fastEmaList[i]; - double slowEma = slowEmaList[i]; + var fastEma = fastEmaList[i]; + var slowEma = slowEmaList[i]; - double ppo = slowEma != 0 ? 100 * (fastEma - slowEma) / slowEma : 0; + var ppo = slowEma != 0 ? 100 * (fastEma - slowEma) / slowEma : 0; ppoList.AddRounded(ppo); } var ppoSignalList = GetMovingAverageList(stockData, maType, signalLength, ppoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo = ppoList[i]; - double ppoSignalLine = ppoSignalList[i]; + var ppo = ppoList[i]; + var ppoSignalLine = ppoSignalList[i]; - double prevPpoHistogram = ppoHistogramList.LastOrDefault(); - double ppoHistogram = ppo - ppoSignalLine; + var prevPpoHistogram = ppoHistogramList.LastOrDefault(); + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); @@ -88,23 +88,23 @@ public static StockData CalculatePercentageVolumeOscillator(this StockData stock var fastEmaList = GetMovingAverageList(stockData, maType, fastLength, volumeList); var slowEmaList = GetMovingAverageList(stockData, maType, slowLength, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastEma = fastEmaList[i]; - double slowEma = slowEmaList[i]; + var fastEma = fastEmaList[i]; + var slowEma = slowEmaList[i]; - double pvo = slowEma != 0 ? 100 * (fastEma - slowEma) / slowEma : 0; + var pvo = slowEma != 0 ? 100 * (fastEma - slowEma) / slowEma : 0; pvoList.AddRounded(pvo); } var pvoSignalList = GetMovingAverageList(stockData, maType, signalLength, pvoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pvo = pvoList[i]; - double pvoSignalLine = pvoSignalList[i]; + var pvo = pvoList[i]; + var pvoSignalLine = pvoSignalList[i]; - double prevPvoHistogram = pvoHistogramList.LastOrDefault(); - double pvoHistogram = pvo - pvoSignalLine; + var prevPvoHistogram = pvoHistogramList.LastOrDefault(); + var pvoHistogram = pvo - pvoSignalLine; pvoHistogramList.AddRounded(pvoHistogram); var signal = GetCompareSignal(pvoHistogram, prevPvoHistogram); @@ -158,29 +158,29 @@ public static StockData Calculate4PercentagePriceOscillator(this StockData stock var ema14List = GetMovingAverageList(stockData, maType, length5, inputList); var ema16List = GetMovingAverageList(stockData, maType, length6, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema5 = ema5List[i]; - double ema8 = ema8List[i]; - double ema10 = ema10List[i]; - double ema14 = ema14List[i]; - double ema16 = ema16List[i]; - double ema17 = ema17List[i]; - double macd1 = ema17 - ema14; - double macd2 = ema17 - ema8; - double macd3 = ema10 - ema16; - double macd4 = ema5 - ema10; - - double ppo1 = ema14 != 0 ? macd1 / ema14 * 100 : 0; + var ema5 = ema5List[i]; + var ema8 = ema8List[i]; + var ema10 = ema10List[i]; + var ema14 = ema14List[i]; + var ema16 = ema16List[i]; + var ema17 = ema17List[i]; + var macd1 = ema17 - ema14; + var macd2 = ema17 - ema8; + var macd3 = ema10 - ema16; + var macd4 = ema5 - ema10; + + var ppo1 = ema14 != 0 ? macd1 / ema14 * 100 : 0; ppo1List.AddRounded(ppo1); - double ppo2 = ema8 != 0 ? macd2 / ema8 * 100 : 0; + var ppo2 = ema8 != 0 ? macd2 / ema8 * 100 : 0; ppo2List.AddRounded(ppo2); - double ppo3 = ema16 != 0 ? macd3 / ema16 * 100 : 0; + var ppo3 = ema16 != 0 ? macd3 / ema16 * 100 : 0; ppo3List.AddRounded(ppo3); - double ppo4 = ema10 != 0 ? macd4 / ema10 * 100 : 0; + var ppo4 = ema10 != 0 ? macd4 / ema10 * 100 : 0; ppo4List.AddRounded(ppo4); } @@ -188,34 +188,34 @@ public static StockData Calculate4PercentagePriceOscillator(this StockData stock var ppo2SignalLineList = GetMovingAverageList(stockData, maType, length1, ppo2List); //-V3056 var ppo3SignalLineList = GetMovingAverageList(stockData, maType, length1, ppo3List); var ppo4SignalLineList = GetMovingAverageList(stockData, maType, length1, ppo4List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo1 = ppo1List[i]; - double ppo1SignalLine = ppo1SignalLineList[i]; - double ppo2 = ppo2List[i]; - double ppo2SignalLine = ppo2SignalLineList[i]; - double ppo3 = ppo3List[i]; - double ppo3SignalLine = ppo3SignalLineList[i]; - double ppo4 = ppo4List[i]; - double ppo4SignalLine = ppo4SignalLineList[i]; - double ppo1Histogram = ppo1 - ppo1SignalLine; - double ppoBlue = blueMult * ppo1Histogram; - - double prevPpo2Histogram = ppo2HistogramList.LastOrDefault(); - double ppo2Histogram = ppo2 - ppo2SignalLine; + var ppo1 = ppo1List[i]; + var ppo1SignalLine = ppo1SignalLineList[i]; + var ppo2 = ppo2List[i]; + var ppo2SignalLine = ppo2SignalLineList[i]; + var ppo3 = ppo3List[i]; + var ppo3SignalLine = ppo3SignalLineList[i]; + var ppo4 = ppo4List[i]; + var ppo4SignalLine = ppo4SignalLineList[i]; + var ppo1Histogram = ppo1 - ppo1SignalLine; + var ppoBlue = blueMult * ppo1Histogram; + + var prevPpo2Histogram = ppo2HistogramList.LastOrDefault(); + var ppo2Histogram = ppo2 - ppo2SignalLine; ppo2HistogramList.AddRounded(ppo2Histogram); - double ppo3Histogram = ppo3 - ppo3SignalLine; - double ppoYellow = yellowMult * ppo3Histogram; + var ppo3Histogram = ppo3 - ppo3SignalLine; + var ppoYellow = yellowMult * ppo3Histogram; - double prevPpo4Histogram = ppo4HistogramList.LastOrDefault(); - double ppo4Histogram = ppo4 - ppo4SignalLine; + var prevPpo4Histogram = ppo4HistogramList.LastOrDefault(); + var ppo4Histogram = ppo4 - ppo4SignalLine; ppo4HistogramList.AddRounded(ppo4Histogram); - double maxPpo = Math.Max(ppoBlue, Math.Max(ppoYellow, Math.Max(ppo2Histogram, ppo4Histogram))); - double minPpo = Math.Min(ppoBlue, Math.Min(ppoYellow, Math.Min(ppo2Histogram, ppo4Histogram))); - double currentPpo = (ppoBlue + ppoYellow + ppo2Histogram + ppo4Histogram) / 4; - double ppoStochastic = maxPpo - minPpo != 0 ? MinOrMax((currentPpo - minPpo) / (maxPpo - minPpo) * 100, 100, 0) : 0; + var maxPpo = Math.Max(ppoBlue, Math.Max(ppoYellow, Math.Max(ppo2Histogram, ppo4Histogram))); + var minPpo = Math.Min(ppoBlue, Math.Min(ppoYellow, Math.Min(ppo2Histogram, ppo4Histogram))); + var currentPpo = (ppoBlue + ppoYellow + ppo2Histogram + ppo4Histogram) / 4; + var ppoStochastic = maxPpo - minPpo != 0 ? MinOrMax((currentPpo - minPpo) / (maxPpo - minPpo) * 100, 100, 0) : 0; var signal = GetCompareSignal(ppo4Histogram - ppo2Histogram, prevPpo4Histogram - prevPpo2Histogram); signalsList.Add(signal); @@ -259,21 +259,21 @@ public static StockData CalculateImpulsePercentagePriceOscillator(this StockData var wellesWilderHighMovingAvgList = GetMovingAverageList(stockData, maType, length, highList); var wellesWilderLowMovingAvgList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double hi = wellesWilderHighMovingAvgList[i]; - double lo = wellesWilderLowMovingAvgList[i]; - double mi = typicalPriceZeroLagEmaList[i]; - double macd = mi > hi ? mi - hi : mi < lo ? mi - lo : 0; + var hi = wellesWilderHighMovingAvgList[i]; + var lo = wellesWilderLowMovingAvgList[i]; + var mi = typicalPriceZeroLagEmaList[i]; + var macd = mi > hi ? mi - hi : mi < lo ? mi - lo : 0; - double ppo = mi > hi && hi != 0 ? macd / hi * 100 : mi < lo && lo != 0 ? macd / lo * 100 : 0; + var ppo = mi > hi && hi != 0 ? macd / hi * 100 : mi < lo && lo != 0 ? macd / lo * 100 : 0; ppoList.AddRounded(ppo); - double ppoSignalLine = ppoList.TakeLastExt(signalLength).Average(); + var ppoSignalLine = ppoList.TakeLastExt(signalLength).Average(); ppoSignalLineList.AddRounded(ppoSignalLine); - double prevPpoHistogram = ppoHistogramList.LastOrDefault(); - double ppoHistogram = ppo - ppoSignalLine; + var prevPpoHistogram = ppoHistogramList.LastOrDefault(); + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); @@ -313,24 +313,24 @@ public static StockData CalculatePercentagePriceOscillatorLeader(this StockData var i1List = macdLeaderList.OutputValues["I1"]; var i2List = macdLeaderList.OutputValues["I2"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double i1 = i1List[i]; - double i2 = i2List[i]; - double macd = i1 - i2; + var i1 = i1List[i]; + var i2 = i2List[i]; + var macd = i1 - i2; - double ppo = i2 != 0 ? macd / i2 * 100 : 0; + var ppo = i2 != 0 ? macd / i2 * 100 : 0; ppoList.AddRounded(ppo); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, signalLength, ppoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo = ppoList[i]; - double ppoSignalLine = ppoSignalLineList[i]; + var ppo = ppoList[i]; + var ppoSignalLine = ppoSignalLineList[i]; - double prevPpoHistogram = ppoHistogramList.LastOrDefault(); - double ppoHistogram = ppo - ppoSignalLine; + var prevPpoHistogram = ppoHistogramList.LastOrDefault(); + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); @@ -370,24 +370,24 @@ public static StockData CalculateTFSMboPercentagePriceOscillator(this StockData var mob1List = GetMovingAverageList(stockData, maType, fastLength, inputList); var mob2List = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mob1 = mob1List[i]; - double mob2 = mob2List[i]; - double tfsMob = mob1 - mob2; + var mob1 = mob1List[i]; + var mob2 = mob2List[i]; + var tfsMob = mob1 - mob2; - double ppo = mob2 != 0 ? tfsMob / mob2 * 100 : 0; + var ppo = mob2 != 0 ? tfsMob / mob2 * 100 : 0; ppoList.AddRounded(ppo); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, signalLength, ppoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo = ppoList[i]; - double ppoSignalLine = ppoSignalLineList[i]; + var ppo = ppoList[i]; + var ppoSignalLine = ppoSignalLineList[i]; - double prevPpoHistogram = ppoHistogramList.LastOrDefault(); - double ppoHistogram = ppo - ppoSignalLine; + var prevPpoHistogram = ppoHistogramList.LastOrDefault(); + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); @@ -428,34 +428,34 @@ public static StockData CalculateMirroredPercentagePriceOscillator(this StockDat var emaOpenList = GetMovingAverageList(stockData, maType, length, openList); var emaCloseList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mao = emaOpenList[i]; - double mac = emaCloseList[i]; - double macd = mac - mao; - double macdMirror = mao - mac; + var mao = emaOpenList[i]; + var mac = emaCloseList[i]; + var macd = mac - mao; + var macdMirror = mao - mac; - double ppo = mao != 0 ? macd / mao * 100 : 0; + var ppo = mao != 0 ? macd / mao * 100 : 0; ppoList.AddRounded(ppo); - double ppoMirror = mac != 0 ? macdMirror / mac * 100 : 0; + var ppoMirror = mac != 0 ? macdMirror / mac * 100 : 0; ppoMirrorList.AddRounded(ppoMirror); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, signalLength, ppoList); var ppoMirrorSignalLineList = GetMovingAverageList(stockData, maType, signalLength, ppoMirrorList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo = ppoList[i]; - double ppoSignalLine = ppoSignalLineList[i]; - double ppoMirror = ppoMirrorList[i]; - double ppoMirrorSignalLine = ppoMirrorSignalLineList[i]; + var ppo = ppoList[i]; + var ppoSignalLine = ppoSignalLineList[i]; + var ppoMirror = ppoMirrorList[i]; + var ppoMirrorSignalLine = ppoMirrorSignalLineList[i]; - double prevPpoHistogram = ppoHistogramList.LastOrDefault(); - double ppoHistogram = ppo - ppoSignalLine; + var prevPpoHistogram = ppoHistogramList.LastOrDefault(); + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); - double ppoMirrorHistogram = ppoMirror - ppoMirrorSignalLine; + var ppoMirrorHistogram = ppoMirror - ppoMirrorSignalLine; ppoMirrorHistogramList.AddRounded(ppoMirrorHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); @@ -498,22 +498,22 @@ public static StockData CalculateDiNapoliPercentagePriceOscillator(this StockDat var ssList = dinapoliMacdList.OutputValues["SlowS"]; var rList = dinapoliMacdList.OutputValues["Macd"]; - double spAlpha = 2 / (1 + sp); + var spAlpha = 2 / (1 + sp); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ss = ssList[i]; - double r = rList[i]; + var ss = ssList[i]; + var r = rList[i]; - double ppo = ss != 0 ? 100 * r / ss : 0; + var ppo = ss != 0 ? 100 * r / ss : 0; ppoList.AddRounded(ppo); - double prevS = sList.LastOrDefault(); - double s = prevS + (spAlpha * (ppo - prevS)); + var prevS = sList.LastOrDefault(); + var s = prevS + (spAlpha * (ppo - prevS)); sList.AddRounded(s); - double prevH = hList.LastOrDefault(); - double h = ppo - s; + var prevH = hList.LastOrDefault(); + var h = ppo - s; hList.AddRounded(h); var signal = GetCompareSignal(h, prevH); @@ -553,24 +553,24 @@ public static StockData CalculateErgodicPercentagePriceOscillator(this StockData var period1EmaList = GetMovingAverageList(stockData, maType, length1, inputList); var period2EmaList = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema1 = period1EmaList[i]; - double ema2 = period2EmaList[i]; - double macd = ema1 - ema2; + var ema1 = period1EmaList[i]; + var ema2 = period2EmaList[i]; + var macd = ema1 - ema2; - double ppo = ema2 != 0 ? macd / ema2 * 100 : 0; + var ppo = ema2 != 0 ? macd / ema2 * 100 : 0; ppoList.AddRounded(ppo); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, length3, ppoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ppo = ppoList[i]; - double ppoSignalLine = ppoSignalLineList[i]; + var ppo = ppoList[i]; + var ppoSignalLine = ppoSignalLineList[i]; - double prevPpoHistogram = ppoHistogramList.LastOrDefault(); - double ppoHistogram = ppo - ppoSignalLine; + var prevPpoHistogram = ppoHistogramList.LastOrDefault(); + var ppoHistogram = ppo - ppoSignalLine; ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); diff --git a/src/Calculations/PriceChannel.cs b/src/Calculations/PriceChannel.cs index d4238d3..40e5ce8 100644 --- a/src/Calculations/PriceChannel.cs +++ b/src/Calculations/PriceChannel.cs @@ -31,20 +31,20 @@ public static StockData CalculatePriceChannel(this StockData stockData, MovingAv var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double upperPriceChannel = currentEma * (1 + pct); + var upperPriceChannel = currentEma * (1 + pct); upperPriceChannelList.AddRounded(upperPriceChannel); - double lowerPriceChannel = currentEma * (1 - pct); + var lowerPriceChannel = currentEma * (1 - pct); lowerPriceChannelList.AddRounded(lowerPriceChannel); - double prevMidPriceChannel = midPriceChannelList.LastOrDefault(); - double midPriceChannel = (upperPriceChannel + lowerPriceChannel) / 2; + var prevMidPriceChannel = midPriceChannelList.LastOrDefault(); + var midPriceChannel = (upperPriceChannel + lowerPriceChannel) / 2; midPriceChannelList.AddRounded(midPriceChannel); var signal = GetCompareSignal(currentValue - midPriceChannel, prevValue - prevMidPriceChannel); @@ -79,19 +79,19 @@ public static StockData CalculateDonchianChannels(this StockData stockData, int var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double upperChannel = highestList[i]; + var upperChannel = highestList[i]; upperChannelList.AddRounded(upperChannel); - double lowerChannel = lowestList[i]; + var lowerChannel = lowestList[i]; lowerChannelList.AddRounded(lowerChannel); - double prevMiddleChannel = middleChannelList.LastOrDefault(); - double middleChannel = (upperChannel + lowerChannel) / 2; + var prevMiddleChannel = middleChannelList.LastOrDefault(); + var middleChannel = (upperChannel + lowerChannel) / 2; middleChannelList.AddRounded(middleChannel); var signal = GetCompareSignal(currentValue - middleChannel, prevValue - prevMiddleChannel); @@ -128,23 +128,23 @@ public static StockData CalculateStandardDeviationChannel(this StockData stockDa var stdDeviationList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; var regressionList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = regressionList[i]; - double currentValue = inputList[i]; - double currentStdDev = stdDeviationList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? regressionList[i - 1] : 0; + var middleBand = regressionList[i]; + var currentValue = inputList[i]; + var currentStdDev = stdDeviationList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? regressionList[i - 1] : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (currentStdDev * stdDevMult); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (currentStdDev * stdDevMult); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (currentStdDev * stdDevMult); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (currentStdDev * stdDevMult); lowerBandList.AddRounded(lowerBand); - Signal signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); + var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); signalsList.Add(signal); } @@ -180,23 +180,23 @@ public static StockData CalculateStollerAverageRangeChannels(this StockData stoc var smaList = GetMovingAverageList(stockData, maType, length, inputList); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = smaList[i]; - double currentValue = inputList[i]; - double currentAtr = atrList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; + var middleBand = smaList[i]; + var currentValue = inputList[i]; + var currentAtr = atrList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (currentAtr * atrMult); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (currentAtr * atrMult); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (currentAtr * atrMult); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (currentAtr * atrMult); lowerBandList.AddRounded(lowerBand); - Signal signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); + var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); signalsList.Add(signal); } @@ -229,15 +229,15 @@ public static StockData CalculateMovingAverageChannel(this StockData stockData, var highMaList = GetMovingAverageList(stockData, maType, length, highList); var lowMaList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double upperChannel = highMaList[i]; - double lowerChannel = lowMaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var upperChannel = highMaList[i]; + var lowerChannel = lowMaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMidChannel = midChannelList.LastOrDefault(); - double midChannel = (upperChannel + lowerChannel) / 2; + var prevMidChannel = midChannelList.LastOrDefault(); + var midChannel = (upperChannel + lowerChannel) / 2; midChannelList.AddRounded(midChannel); var signal = GetCompareSignal(currentValue - midChannel, prevValue - prevMidChannel); @@ -275,18 +275,18 @@ public static StockData CalculateMovingAverageEnvelope(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentSma20 = smaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma20 = i >= 1 ? smaList[i - 1] : 0; - double factor = currentSma20 * mult; + var currentSma20 = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma20 = i >= 1 ? smaList[i - 1] : 0; + var factor = currentSma20 * mult; - double upperEnvelope = currentSma20 + factor; + var upperEnvelope = currentSma20 + factor; upperEnvelopeList.AddRounded(upperEnvelope); - double lowerEnvelope = currentSma20 - factor; + var lowerEnvelope = currentSma20 - factor; lowerEnvelopeList.AddRounded(lowerEnvelope); var signal = GetCompareSignal(currentValue - currentSma20, prevValue - prevSma20); @@ -319,31 +319,31 @@ public static StockData CalculateFractalChaosBands(this StockData stockData) List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevHigh1 = i >= 1 ? highList[i - 1] : 0; - double prevHigh2 = i >= 2 ? highList[i - 2] : 0; - double prevHigh3 = i >= 3 ? highList[i - 3] : 0; - double prevLow1 = i >= 1 ? lowList[i - 1] : 0; - double prevLow2 = i >= 2 ? lowList[i - 2] : 0; - double prevLow3 = i >= 3 ? lowList[i - 3] : 0; - double currentClose = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevHigh1 = i >= 1 ? highList[i - 1] : 0; + var prevHigh2 = i >= 2 ? highList[i - 2] : 0; + var prevHigh3 = i >= 3 ? highList[i - 3] : 0; + var prevLow1 = i >= 1 ? lowList[i - 1] : 0; + var prevLow2 = i >= 2 ? lowList[i - 2] : 0; + var prevLow3 = i >= 3 ? lowList[i - 3] : 0; + var currentClose = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; double oklUpper = prevHigh1 < prevHigh2 ? 1 : 0; double okrUpper = prevHigh3 < prevHigh2 ? 1 : 0; double oklLower = prevLow1 > prevLow2 ? 1 : 0; double okrLower = prevLow3 > prevLow2 ? 1 : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = oklUpper == 1 && okrUpper == 1 ? prevHigh2 : prevUpperBand; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = oklUpper == 1 && okrUpper == 1 ? prevHigh2 : prevUpperBand; upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = oklLower == 1 && okrLower == 1 ? prevLow2 : prevLowerBand; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = oklLower == 1 && okrLower == 1 ? prevLow2 : prevLowerBand; lowerBandList.AddRounded(lowerBand); - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (upperBand + lowerBand) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (upperBand + lowerBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentClose - middleBand, prevClose - prevMiddleBand, currentClose, prevClose, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -382,20 +382,20 @@ public static StockData CalculateAverageTrueRangeChannel(this StockData stockDat var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double atr = atrList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = smaList[i]; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentValue = inputList[i]; + var atr = atrList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = smaList[i]; + var prevSma = i >= 1 ? smaList[i - 1] : 0; - double prevTopInner = innerTopAtrChannelList.LastOrDefault(); - double topInner = Math.Round(currentValue + (atr * mult)); + var prevTopInner = innerTopAtrChannelList.LastOrDefault(); + var topInner = Math.Round(currentValue + (atr * mult)); innerTopAtrChannelList.AddRounded(topInner); - double prevBottomInner = innerBottomAtrChannelList.LastOrDefault(); - double bottomInner = Math.Round(currentValue - (atr * mult)); + var prevBottomInner = innerBottomAtrChannelList.LastOrDefault(); + var bottomInner = Math.Round(currentValue - (atr * mult)); innerBottomAtrChannelList.AddRounded(bottomInner); var signal = GetBollingerBandsSignal(currentValue - sma, prevValue - prevSma, currentValue, prevValue, topInner, @@ -436,20 +436,20 @@ public static StockData CalculateUltimateMovingAverageBands(this StockData stock var umaList = CalculateUltimateMovingAverage(stockData, maType, minLength, maxLength, 1).CustomValuesList; var stdevList = CalculateStandardDeviationVolatility(stockData, maType, minLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevVal = i >= 1 ? inputList[i - 1] : 0; - double uma = umaList[i]; - double prevUma = i >= 1 ? umaList[i - 1] : 0; - double stdev = stdevList[i]; + var currentValue = inputList[i]; + var prevVal = i >= 1 ? inputList[i - 1] : 0; + var uma = umaList[i]; + var prevUma = i >= 1 ? umaList[i - 1] : 0; + var stdev = stdevList[i]; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = uma + (stdDevMult * stdev); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = uma + (stdDevMult * stdev); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = uma - (stdDevMult * stdev); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = uma - (stdDevMult * stdev); lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - uma, prevVal - prevUma, currentValue, prevVal, upperBand, prevUpperBand, @@ -490,19 +490,19 @@ public static StockData CalculateUniChannel(this StockData stockData, MovingAvgT var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentSma = smaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentSma = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; - double prevUb = upperBandList.LastOrDefault(); - double ub = type1 ? currentSma + ubFac : currentSma + (currentSma * ubFac); + var prevUb = upperBandList.LastOrDefault(); + var ub = type1 ? currentSma + ubFac : currentSma + (currentSma * ubFac); upperBandList.AddRounded(ub); - double prevLb = lowerBandList.LastOrDefault(); - double lb = type1 ? currentSma - lbFac : currentSma - (currentSma * lbFac); + var prevLb = lowerBandList.LastOrDefault(); + var lb = type1 ? currentSma - lbFac : currentSma - (currentSma * lbFac); lowerBandList.AddRounded(lb); var signal = GetBollingerBandsSignal(currentValue - currentSma, prevValue - prevSma, currentValue, prevValue, ub, prevUb, lb, prevLb); @@ -550,20 +550,20 @@ public static StockData CalculateWilsonRelativePriceChannel(this StockData stock var (inputList, _, _, _, _) = GetInputValuesList(stockData); var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length, smoothLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; + var rsi = rsiList[i]; - double rsiOverbought = rsi - overbought; + var rsiOverbought = rsi - overbought; rsiOverboughtList.AddRounded(rsiOverbought); - double rsiOversold = rsi - oversold; + var rsiOversold = rsi - oversold; rsiOversoldList.AddRounded(rsiOversold); - double rsiUpperNeutralZone = rsi - upperNeutralZone; + var rsiUpperNeutralZone = rsi - upperNeutralZone; rsiUpperNeutralZoneList.AddRounded(rsiUpperNeutralZone); - double rsiLowerNeutralZone = rsi - lowerNeutralZone; + var rsiLowerNeutralZone = rsi - lowerNeutralZone; rsiLowerNeutralZoneList.AddRounded(rsiLowerNeutralZone); } @@ -571,29 +571,29 @@ public static StockData CalculateWilsonRelativePriceChannel(this StockData stock var osList = GetMovingAverageList(stockData, maType, smoothLength, rsiOversoldList); var nzuList = GetMovingAverageList(stockData, maType, smoothLength, rsiUpperNeutralZoneList); var nzlList = GetMovingAverageList(stockData, maType, smoothLength, rsiLowerNeutralZoneList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ob = obList[i]; - double os = osList[i]; - double nzu = nzuList[i]; - double nzl = nzlList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var ob = obList[i]; + var os = osList[i]; + var nzu = nzuList[i]; + var nzl = nzlList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevS1 = s1List.LastOrDefault(); - double s1 = currentValue - (currentValue * os / 100); + var prevS1 = s1List.LastOrDefault(); + var s1 = currentValue - (currentValue * os / 100); s1List.AddRounded(s1); - double prevU1 = u1List.LastOrDefault(); - double u1 = currentValue - (currentValue * ob / 100); + var prevU1 = u1List.LastOrDefault(); + var u1 = currentValue - (currentValue * ob / 100); u1List.AddRounded(u1); - double prevU2 = u2List.LastOrDefault(); - double u2 = currentValue - (currentValue * nzu / 100); + var prevU2 = u2List.LastOrDefault(); + var u2 = currentValue - (currentValue * nzu / 100); u2List.AddRounded(u2); - double prevS2 = s2List.LastOrDefault(); - double s2 = currentValue - (currentValue * nzl / 100); + var prevS2 = s2List.LastOrDefault(); + var s2 = currentValue - (currentValue * nzl / 100); s2List.AddRounded(s2); var signal = GetBullishBearishSignal(currentValue - Math.Min(u1, u2), prevValue - Math.Min(prevU1, prevU2), @@ -630,28 +630,28 @@ public static StockData CalculateLinearChannels(this StockData stockData, int le List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double s = (double)1 / length; + var s = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double prevA2 = i >= 2 ? aList[i - 2] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double x = currentValue + ((prevA - prevA2) * mult); + var currentValue = inputList[i]; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var prevA2 = i >= 2 ? aList[i - 2] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var x = currentValue + ((prevA - prevA2) * mult); - double a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; + var a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; aList.AddRounded(a); - double up = a + (Math.Abs(a - prevA) * mult); - double dn = a - (Math.Abs(a - prevA) * mult); + var up = a + (Math.Abs(a - prevA) * mult); + var dn = a - (Math.Abs(a - prevA) * mult); - double prevUpper = upperList.LastOrDefault(); - double upper = up == a ? prevUpper : up; + var prevUpper = upperList.LastOrDefault(); + var upper = up == a ? prevUpper : up; upperList.AddRounded(upper); - double prevLower = lowerList.LastOrDefault(); - double lower = dn == a ? prevLower : dn; + var prevLower = lowerList.LastOrDefault(); + var lower = dn == a ? prevLower : dn; lowerList.AddRounded(lower); var signal = GetBollingerBandsSignal(currentValue - a, prevValue - prevA, currentValue, prevValue, upper, prevUpper, lower, prevLower); @@ -689,22 +689,22 @@ public static StockData CalculateInterquartileRangeBands(this StockData stockDat var q1List = trimeanList.OutputValues["Q1"]; var q3List = trimeanList.OutputValues["Q3"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double q1 = q1List[i]; - double q3 = q3List[i]; - double iqr = q3 - q1; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var q1 = q1List[i]; + var q3 = q3List[i]; + var iqr = q3 - q1; - double upperBand = q3 + (mult * iqr); + var upperBand = q3 + (mult * iqr); upperBandList.AddRounded(upperBand); - double lowerBand = q1 - (mult * iqr); + var lowerBand = q1 - (mult * iqr); lowerBandList.AddRounded(lowerBand); - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (upperBand + lowerBand) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (upperBand + lowerBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetCompareSignal(currentValue - middleBand, prevValue - prevMiddleBand); @@ -768,22 +768,22 @@ public static StockData CalculateGChannels(this StockData stockData, int length List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevA = aList.LastOrDefault(); - double prevB = bList.LastOrDefault(); - double factor = length != 0 ? (prevA - prevB) / length : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevA = aList.LastOrDefault(); + var prevB = bList.LastOrDefault(); + var factor = length != 0 ? (prevA - prevB) / length : 0; - double a = Math.Max(currentValue, prevA) - factor; + var a = Math.Max(currentValue, prevA) - factor; aList.AddRounded(a); - double b = Math.Min(currentValue, prevB) + factor; + var b = Math.Min(currentValue, prevB) + factor; bList.AddRounded(b); - double prevMid = midList.LastOrDefault(); - double mid = (a + b) / 2; + var prevMid = midList.LastOrDefault(); + var mid = (a + b) / 2; midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); @@ -821,15 +821,15 @@ public static StockData CalculateHighLowMovingAverage(this StockData stockData, var upperBandList = GetMovingAverageList(stockData, maType, length, highestList); var lowerBandList = GetMovingAverageList(stockData, maType, length, lowestList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double upperBand = upperBandList[i]; - double lowerBand = lowerBandList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var upperBand = upperBandList[i]; + var lowerBand = lowerBandList[i]; - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (upperBand + lowerBand) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (upperBand + lowerBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetCompareSignal(currentValue - middleBand, prevValue - prevMiddleBand); @@ -868,19 +868,19 @@ public static StockData CalculateHighLowBands(this StockData stockData, MovingAv var tmaList1 = GetMovingAverageList(stockData, maType, length, inputList); var tmaList2 = GetMovingAverageList(stockData, maType, length, tmaList1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double tma = tmaList2[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevTma = i >= 1 ? tmaList2[i - 1] : 0; + var currentValue = inputList[i]; + var tma = tmaList2[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevTma = i >= 1 ? tmaList2[i - 1] : 0; - double prevHighBand = highBandList.LastOrDefault(); - double highBand = tma + (tma * pctShift / 100); + var prevHighBand = highBandList.LastOrDefault(); + var highBand = tma + (tma * pctShift / 100); highBandList.AddRounded(highBand); - double prevLowBand = lowBandList.LastOrDefault(); - double lowBand = tma - (tma * pctShift / 100); + var prevLowBand = lowBandList.LastOrDefault(); + var lowBand = tma - (tma * pctShift / 100); lowBandList.AddRounded(lowBand); var signal = GetBollingerBandsSignal(currentValue - tma, prevValue - prevTma, currentValue, prevValue, highBand, prevHighBand, @@ -925,51 +925,51 @@ public static StockData CalculateHurstCycleChannel(this StockData stockData, Mov List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int scl = MinOrMax((int)Math.Ceiling((double)fastLength / 2)); - int mcl = MinOrMax((int)Math.Ceiling((double)slowLength / 2)); - int scl_2 = MinOrMax((int)Math.Ceiling((double)scl / 2)); - int mcl_2 = MinOrMax((int)Math.Ceiling((double)mcl / 2)); + var scl = MinOrMax((int)Math.Ceiling((double)fastLength / 2)); + var mcl = MinOrMax((int)Math.Ceiling((double)slowLength / 2)); + var scl_2 = MinOrMax((int)Math.Ceiling((double)scl / 2)); + var mcl_2 = MinOrMax((int)Math.Ceiling((double)mcl / 2)); var sclAtrList = CalculateAverageTrueRange(stockData, maType, scl).CustomValuesList; var mclAtrList = CalculateAverageTrueRange(stockData, maType, mcl).CustomValuesList; var sclRmaList = GetMovingAverageList(stockData, maType, scl, inputList); var mclRmaList = GetMovingAverageList(stockData, maType, mcl, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sclAtr = sclAtrList[i]; - double mclAtr = mclAtrList[i]; - double prevSclRma = i >= scl_2 ? sclRmaList[i - scl_2] : currentValue; - double prevMclRma = i >= mcl_2 ? mclRmaList[i - mcl_2] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double scm_off = fastMult * sclAtr; - double mcm_off = slowMult * mclAtr; + var currentValue = inputList[i]; + var sclAtr = sclAtrList[i]; + var mclAtr = mclAtrList[i]; + var prevSclRma = i >= scl_2 ? sclRmaList[i - scl_2] : currentValue; + var prevMclRma = i >= mcl_2 ? mclRmaList[i - mcl_2] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var scm_off = fastMult * sclAtr; + var mcm_off = slowMult * mclAtr; - double prevSct = sctList.LastOrDefault(); - double sct = prevSclRma + scm_off; + var prevSct = sctList.LastOrDefault(); + var sct = prevSclRma + scm_off; sctList.AddRounded(sct); - double prevScb = scbList.LastOrDefault(); - double scb = prevSclRma - scm_off; + var prevScb = scbList.LastOrDefault(); + var scb = prevSclRma - scm_off; scbList.AddRounded(scb); - double mct = prevMclRma + mcm_off; + var mct = prevMclRma + mcm_off; mctList.AddRounded(mct); - double mcb = prevMclRma - mcm_off; + var mcb = prevMclRma - mcm_off; mcbList.AddRounded(mcb); - double scmm = (sct + scb) / 2; + var scmm = (sct + scb) / 2; scmmList.AddRounded(scmm); - double mcmm = (mct + mcb) / 2; + var mcmm = (mct + mcb) / 2; mcmmList.AddRounded(mcmm); - double omed = mct - mcb != 0 ? (scmm - mcb) / (mct - mcb) : 0; + var omed = mct - mcb != 0 ? (scmm - mcb) / (mct - mcb) : 0; omedList.AddRounded(omed); - double oshort = mct - mcb != 0 ? (currentValue - mcb) / (mct - mcb) : 0; + var oshort = mct - mcb != 0 ? (currentValue - mcb) / (mct - mcb) : 0; oshortList.AddRounded(oshort); var signal = GetBullishBearishSignal(currentValue - sct, prevValue - prevSct, currentValue - scb, prevValue - prevScb); @@ -1017,41 +1017,41 @@ public static StockData CalculateHurstBands(this StockData stockData, int length List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int displacement = MinOrMax((int)Math.Ceiling((double)length / 2) + 1); + var displacement = MinOrMax((int)Math.Ceiling((double)length / 2) + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevCma1 = i >= 1 ? cmaList[i - 1] : 0; - double prevCma2 = i >= 2 ? cmaList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevCma1 = i >= 1 ? cmaList[i - 1] : 0; + var prevCma2 = i >= 2 ? cmaList[i - 2] : 0; - double dPrice = i >= displacement ? inputList[i - displacement] : 0; + var dPrice = i >= displacement ? inputList[i - displacement] : 0; dPriceList.AddRounded(dPrice); - double cma = dPrice == 0 ? prevCma1 + (prevCma1 - prevCma2) : dPriceList.TakeLastExt(length).Average(); + var cma = dPrice == 0 ? prevCma1 + (prevCma1 - prevCma2) : dPriceList.TakeLastExt(length).Average(); cmaList.AddRounded(cma); - double extremeBand = cma * extremeMult / 100; - double outerBand = cma * outerMult / 100; - double innerBand = cma * innerMult / 100; + var extremeBand = cma * extremeMult / 100; + var outerBand = cma * outerMult / 100; + var innerBand = cma * innerMult / 100; - double upperExtremeBand = cma + extremeBand; + var upperExtremeBand = cma + extremeBand; upperExtremeBandList.AddRounded(upperExtremeBand); - double lowerExtremeBand = cma - extremeBand; + var lowerExtremeBand = cma - extremeBand; lowerExtremeBandList.AddRounded(lowerExtremeBand); - double upperInnerBand = cma + innerBand; + var upperInnerBand = cma + innerBand; upperInnerBandList.AddRounded(upperInnerBand); - double lowerInnerBand = cma - innerBand; + var lowerInnerBand = cma - innerBand; lowerInnerBandList.AddRounded(lowerInnerBand); - double upperOuterBand = cma + outerBand; + var upperOuterBand = cma + outerBand; upperOuterBandList.AddRounded(upperOuterBand); - double lowerOuterBand = cma - outerBand; + var lowerOuterBand = cma - outerBand; lowerOuterBandList.AddRounded(lowerOuterBand); var signal = GetCompareSignal(currentValue - cma, prevValue - prevCma1); @@ -1098,58 +1098,58 @@ public static StockData CalculateHirashimaSugitaRS(this StockData stockData, Mov var emaList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ema = emaList[i]; + var currentValue = inputList[i]; + var ema = emaList[i]; - double d1 = currentValue - ema; + var d1 = currentValue - ema; d1List.AddRounded(d1); - double absD1 = Math.Abs(d1); + var absD1 = Math.Abs(d1); absD1List.AddRounded(absD1); } var wmaList = GetMovingAverageList(stockData, maType, length, absD1List); stockData.CustomValuesList = d1List; var s1List = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema = emaList[i]; - double s1 = s1List[i]; - double currentValue = inputList[i]; - double x = ema + s1; + var ema = emaList[i]; + var s1 = s1List[i]; + var currentValue = inputList[i]; + var x = ema + s1; - double d2 = currentValue - x; + var d2 = currentValue - x; d2List.AddRounded(d2); } stockData.CustomValuesList = d2List; var s2List = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double ema = emaList[i]; - double s1 = s1List[i]; - double s2 = s2List[i]; - double prevS2 = i >= 1 ? s2List[i - 1] : 0; - double wma = wmaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - - double prevBasis = basisList.LastOrDefault(); - double basis = ema + s1 + (s2 - prevS2); + for (var i = 0; i < stockData.Count; i++) + { + var ema = emaList[i]; + var s1 = s1List[i]; + var s2 = s2List[i]; + var prevS2 = i >= 1 ? s2List[i - 1] : 0; + var wma = wmaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + + var prevBasis = basisList.LastOrDefault(); + var basis = ema + s1 + (s2 - prevS2); basisList.AddRounded(basis); - double upper1 = basis + wma; + var upper1 = basis + wma; upper1List.AddRounded(upper1); - double lower1 = basis - wma; + var lower1 = basis - wma; lower1List.AddRounded(lower1); - double upper2 = upper1 + wma; + var upper2 = upper1 + wma; upper2List.AddRounded(upper2); - double lower2 = lower1 - wma; + var lower2 = lower1 - wma; lower2List.AddRounded(lower2); var signal = GetCompareSignal(currentValue - basis, prevValue - prevBasis); @@ -1189,35 +1189,35 @@ public static StockData CalculateFlaggingBands(this StockData stockData, int len var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double stdDev = stdDevList[i]; - double prevA1 = i >= 1 ? aList[i - 1] : currentValue; - double prevB1 = i >= 1 ? bList[i - 1] : currentValue; - double prevA2 = i >= 2 ? aList[i - 2] : currentValue; - double prevB2 = i >= 2 ? bList[i - 2] : currentValue; - double prevA3 = i >= 3 ? aList[i - 3] : currentValue; - double prevB3 = i >= 3 ? bList[i - 3] : currentValue; - double l = stdDev != 0 ? (double)1 / length * stdDev : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var stdDev = stdDevList[i]; + var prevA1 = i >= 1 ? aList[i - 1] : currentValue; + var prevB1 = i >= 1 ? bList[i - 1] : currentValue; + var prevA2 = i >= 2 ? aList[i - 2] : currentValue; + var prevB2 = i >= 2 ? bList[i - 2] : currentValue; + var prevA3 = i >= 3 ? aList[i - 3] : currentValue; + var prevB3 = i >= 3 ? bList[i - 3] : currentValue; + var l = stdDev != 0 ? (double)1 / length * stdDev : 0; - double a = currentValue > prevA1 ? prevA1 + (currentValue - prevA1) : prevA2 == prevA3 ? prevA2 - l : prevA2; + var a = currentValue > prevA1 ? prevA1 + (currentValue - prevA1) : prevA2 == prevA3 ? prevA2 - l : prevA2; aList.AddRounded(a); - double b = currentValue < prevB1 ? prevB1 + (currentValue - prevB1) : prevB2 == prevB3 ? prevB2 + l : prevB2; + var b = currentValue < prevB1 ? prevB1 + (currentValue - prevB1) : prevB2 == prevB3 ? prevB2 + l : prevB2; bList.AddRounded(b); - double prevTos = tosList.LastOrDefault(); - double tos = currentValue > prevA2 ? 1 : currentValue < prevB2 ? 0 : prevTos; + var prevTos = tosList.LastOrDefault(); + var tos = currentValue > prevA2 ? 1 : currentValue < prevB2 ? 0 : prevTos; tosList.AddRounded(tos); - double prevTavg = tavgList.LastOrDefault(); - double avg = (a + b) / 2; - double tavg = tos == 1 ? (a + avg) / 2 : (b + avg) / 2; + var prevTavg = tavgList.LastOrDefault(); + var avg = (a + b) / 2; + var tavg = tos == 1 ? (a + avg) / 2 : (b + avg) / 2; tavgList.AddRounded(tavg); - double ts = (tos * b) + ((1 - tos) * a); + var ts = (tos * b) + ((1 - tos) * a); tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - tavg, prevValue - prevTavg); @@ -1260,28 +1260,28 @@ public static StockData CalculateKirshenbaumBands(this StockData stockData, Movi var emaList = GetMovingAverageList(stockData, maType, length1, inputList); var linRegList = CalculateLinearRegression(stockData, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEma = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempInputList.AddRounded(currentValue); - double currentLinReg = linRegList[i]; + var currentLinReg = linRegList[i]; tempLinRegList.AddRounded(currentLinReg); var stdError = GoodnessOfFit.PopulationStandardError(tempLinRegList.TakeLastExt(length2).Select(x => (double)x), tempInputList.TakeLastExt(length2).Select(x => (double)x)); stdError = IsValueNullOrInfinity(stdError) ? 0 : stdError; - double ratio = (double)stdError * stdDevFactor; + var ratio = (double)stdError * stdDevFactor; - double prevTop = topList.LastOrDefault(); - double top = currentEma + ratio; + var prevTop = topList.LastOrDefault(); + var top = currentEma + ratio; topList.AddRounded(top); - double prevBottom = bottomList.LastOrDefault(); - double bottom = currentEma - ratio; + var prevBottom = bottomList.LastOrDefault(); + var bottom = currentEma - ratio; bottomList.AddRounded(bottom); var signal = GetBullishBearishSignal(currentValue - top, prevValue - prevTop, currentValue - bottom, prevValue - prevBottom); @@ -1319,27 +1319,27 @@ public static StockData CalculateKaufmanAdaptiveBands(this StockData stockData, var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double er = Pow(erList[i], stdDevFactor); - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var er = Pow(erList[i], stdDevFactor); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (currentValue * er) + ((1 - er) * prevMiddleBand); + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (currentValue * er) + ((1 - er) * prevMiddleBand); middleBandList.AddRounded(middleBand); - double prevPowMa = powMaList.LastOrDefault(); - double powMa = (Pow(currentValue, 2) * er) + ((1 - er) * prevPowMa); + var prevPowMa = powMaList.LastOrDefault(); + var powMa = (Pow(currentValue, 2) * er) + ((1 - er) * prevPowMa); powMaList.AddRounded(powMa); - double kaufmanDev = powMa - Pow(middleBand, 2) >= 0 ? Sqrt(powMa - Pow(middleBand, 2)) : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + kaufmanDev; + var kaufmanDev = powMa - Pow(middleBand, 2) >= 0 ? Sqrt(powMa - Pow(middleBand, 2)) : 0; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + kaufmanDev; upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - kaufmanDev; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - kaufmanDev; lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, @@ -1381,21 +1381,21 @@ public static StockData CalculateKeltnerChannels(this StockData stockData, Movin var emaList = GetMovingAverageList(stockData, maType, length1, inputList); var atrList = CalculateAverageTrueRange(stockData, maType, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentEma20Day = emaList[i]; - double currentAtr10Day = atrList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma20Day = emaList[i]; + var currentAtr10Day = atrList[i]; - double upperChannel = currentEma20Day + (multFactor * currentAtr10Day); + var upperChannel = currentEma20Day + (multFactor * currentAtr10Day); upperChannelList.AddRounded(upperChannel); - double lowerChannel = currentEma20Day - (multFactor * currentAtr10Day); + var lowerChannel = currentEma20Day - (multFactor * currentAtr10Day); lowerChannelList.AddRounded(lowerChannel); - double prevMidChannel = midChannelList.LastOrDefault(); - double midChannel = (upperChannel + lowerChannel) / 2; + var prevMidChannel = midChannelList.LastOrDefault(); + var midChannel = (upperChannel + lowerChannel) / 2; midChannelList.AddRounded(midChannel); var signal = GetCompareSignal(currentValue - midChannel, prevValue - prevMidChannel); @@ -1433,26 +1433,26 @@ public static StockData CalculateVortexBands(this StockData stockData, MovingAvg var basisList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double basis = basisList[i]; - double currentValue = inputList[i]; + var basis = basisList[i]; + var currentValue = inputList[i]; - double diff = currentValue - basis; + var diff = currentValue - basis; diffList.AddRounded(diff); } var diffMaList = GetMovingAverageList(stockData, maType, length, diffList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double diffMa = diffMaList[i]; - double basis = basisList[i]; - double dev = 2 * diffMa; + var diffMa = diffMaList[i]; + var basis = basisList[i]; + var dev = 2 * diffMa; - double upper = basis + dev; + var upper = basis + dev; upperList.AddRounded(upper); - double lower = basis - dev; + var lower = basis - dev; lowerList.AddRounded(lower); var signal = GetConditionSignal(upper > lower && upper > basis, lower > upper && lower > basis); @@ -1490,32 +1490,32 @@ public static StockData CalculateVolumeAdaptiveBands(this StockData stockData, M var aList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double a = Math.Max(aList[i], 1); - double b = a * -1; + var currentValue = inputList[i]; + var a = Math.Max(aList[i], 1); + var b = a * -1; - double prevUp = i >= 1 ? upList[i - 1] : currentValue; - double up = a != 0 ? (prevUp + (currentValue * a)) / a : 0; + var prevUp = i >= 1 ? upList[i - 1] : currentValue; + var up = a != 0 ? (prevUp + (currentValue * a)) / a : 0; upList.AddRounded(up); - double prevDn = i >= 1 ? dnList[i - 1] : currentValue; - double dn = b != 0 ? (prevDn + (currentValue * b)) / b : 0; + var prevDn = i >= 1 ? dnList[i - 1] : currentValue; + var dn = b != 0 ? (prevDn + (currentValue * b)) / b : 0; dnList.AddRounded(dn); } var upSmaList = GetMovingAverageList(stockData, maType, length, upList); var dnSmaList = GetMovingAverageList(stockData, maType, length, dnList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double upperBand = upSmaList[i]; - double lowerBand = dnSmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var upperBand = upSmaList[i]; + var lowerBand = dnSmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (upperBand + lowerBand) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (upperBand + lowerBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetCompareSignal(currentValue - middleBand, prevValue - prevMiddleBand); @@ -1554,21 +1554,21 @@ public static StockData CalculateVariableMovingAverageBands(this StockData stock var maList = GetMovingAverageList(stockData, maType, length, inputList); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentAtr = atrList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double vma = maList[i]; - double prevVma = i >= 1 ? maList[i - 1] : 0; - double o = mult * currentAtr; + var currentValue = inputList[i]; + var currentAtr = atrList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var vma = maList[i]; + var prevVma = i >= 1 ? maList[i - 1] : 0; + var o = mult * currentAtr; - double prevUband = ubandList.LastOrDefault(); - double uband = vma + o; + var prevUband = ubandList.LastOrDefault(); + var uband = vma + o; ubandList.AddRounded(uband); - double prevLband = lbandList.LastOrDefault(); - double lband = vma - o; + var prevLband = lbandList.LastOrDefault(); + var lband = vma - o; lbandList.AddRounded(lband); var signal = GetBollingerBandsSignal(currentValue - vma, prevValue - prevVma, currentValue, prevValue, uband, prevUband, lband, prevLband); @@ -1613,44 +1613,44 @@ public static StockData CalculateVervoortVolatilityBands(this StockData stockDat var medianAvgList = GetMovingAverageList(stockData, maType, length1, inputList); var medianAvgEmaList = GetMovingAverageList(stockData, maType, length1, medianAvgList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double medianAvg = medianAvgList[i]; + var medianAvg = medianAvgList[i]; tempList.AddRounded(medianAvg); - double currentValue = inputList[i]; - double currentLow = lowList[i]; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentLow = lowList[i]; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double typical = currentValue >= prevValue ? currentValue - prevLow : prevValue - currentLow; + var typical = currentValue >= prevValue ? currentValue - prevLow : prevValue - currentLow; typicalList.AddRounded(typical); - double typicalSma = typicalList.TakeLastExt(length2).Average(); - double deviation = devMult * typicalSma; + var typicalSma = typicalList.TakeLastExt(length2).Average(); + var deviation = devMult * typicalSma; deviationList.AddRounded(deviation); - double medianAvgSma = tempList.TakeLastExt(length1).Average(); + var medianAvgSma = tempList.TakeLastExt(length1).Average(); medianAvgSmaList.AddRounded(medianAvgSma); } var devHighList = GetMovingAverageList(stockData, maType, length1, deviationList); - for (int i = 0; i < stockData.Count; i++) - { - double devHigh = devHighList[i]; - double midline = medianAvgSmaList[i]; - double medianAvgEma = medianAvgEmaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMidline = i >= 1 ? medianAvgSmaList[i - 1] : 0; - double devLow = lowBandMult * devHigh; - - double prevUb = ubList.LastOrDefault(); - double ub = medianAvgEma + devHigh; + for (var i = 0; i < stockData.Count; i++) + { + var devHigh = devHighList[i]; + var midline = medianAvgSmaList[i]; + var medianAvgEma = medianAvgEmaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMidline = i >= 1 ? medianAvgSmaList[i - 1] : 0; + var devLow = lowBandMult * devHigh; + + var prevUb = ubList.LastOrDefault(); + var ub = medianAvgEma + devHigh; ubList.AddRounded(ub); - double prevLb = lbList.LastOrDefault(); - double lb = medianAvgEma - devLow; + var prevLb = lbList.LastOrDefault(); + var lb = medianAvgEma - devLow; lbList.AddRounded(lb); var signal = GetBollingerBandsSignal(currentValue - midline, prevValue - prevMidline, currentValue, prevValue, ub, prevUb, lb, prevLb); @@ -1688,31 +1688,31 @@ public static StockData CalculatePriceHeadleyAccelerationBands(this StockData st var middleBandList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double mult = currentHigh + currentLow != 0 ? 4 * factor * 1000 * (currentHigh - currentLow) / (currentHigh + currentLow) : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var mult = currentHigh + currentLow != 0 ? 4 * factor * 1000 * (currentHigh - currentLow) / (currentHigh + currentLow) : 0; - double outerUb = currentHigh * (1 + mult); + var outerUb = currentHigh * (1 + mult); ubList.AddRounded(outerUb); - double outerLb = currentLow * (1 - mult); + var outerLb = currentLow * (1 - mult); lbList.AddRounded(outerLb); } var suList = GetMovingAverageList(stockData, maType, length, ubList); var slList = GetMovingAverageList(stockData, maType, length, lbList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double middleBand = middleBandList[i]; - double prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; - double outerUbSma = suList[i]; - double prevOuterUbSma = i >= 1 ? suList[i - 1] : 0; - double outerLbSma = slList[i]; - double prevOuterLbSma = i >= 1 ? slList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var middleBand = middleBandList[i]; + var prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; + var outerUbSma = suList[i]; + var prevOuterUbSma = i >= 1 ? suList[i - 1] : 0; + var outerLbSma = slList[i]; + var prevOuterLbSma = i >= 1 ? slList[i - 1] : 0; var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, outerUbSma, prevOuterUbSma, outerLbSma, prevOuterLbSma); @@ -1752,44 +1752,44 @@ public static StockData CalculatePseudoPolynomialChannel(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double y = inputList[i]; - double prevK = i >= length ? kList[i - length] : y; - double prevK2 = i >= length * 2 ? kList[i - (length * 2)] : y; - double prevIndex = i >= length ? indexList[i - length] : 0; - double prevIndex2 = i >= length * 2 ? indexList[i - (length * 2)] : 0; - double ky = (morph * prevK) + ((1 - morph) * y); - double ky2 = (morph * prevK2) + ((1 - morph) * y); + var y = inputList[i]; + var prevK = i >= length ? kList[i - length] : y; + var prevK2 = i >= length * 2 ? kList[i - (length * 2)] : y; + var prevIndex = i >= length ? indexList[i - length] : 0; + var prevIndex2 = i >= length * 2 ? indexList[i - (length * 2)] : 0; + var ky = (morph * prevK) + ((1 - morph) * y); + var ky2 = (morph * prevK2) + ((1 - morph) * y); double index = i; indexList.AddRounded(i); - double k = prevIndex2 - prevIndex != 0 ? ky + ((index - prevIndex) / (prevIndex2 - prevIndex) * (ky2 - ky)) : 0; + var k = prevIndex2 - prevIndex != 0 ? ky + ((index - prevIndex) / (prevIndex2 - prevIndex) * (ky2 - ky)) : 0; kList.AddRounded(k); } var k1List = GetMovingAverageList(stockData, maType, length, kList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double k1 = k1List[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var k1 = k1List[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double yk1 = Math.Abs(currentValue - k1); + var yk1 = Math.Abs(currentValue - k1); yK1List.AddRounded(yk1); - double er = i != 0 ? yK1List.Sum() / i : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = k1 + er; + var er = i != 0 ? yK1List.Sum() / i : 0; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = k1 + er; upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = k1 - er; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = k1 - er; lowerBandList.AddRounded(lowerBand); - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (upperBand + lowerBand) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (upperBand + lowerBand) / 2; middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, @@ -1827,28 +1827,28 @@ public static StockData CalculateProjectedSupportAndResistance(this StockData st var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double range = highestHigh - lowestLow; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var range = highestHigh - lowestLow; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double support1 = lowestLow - (0.25 * range); + var support1 = lowestLow - (0.25 * range); support1List.AddRounded(support1); - double support2 = lowestLow - (0.5 * range); + var support2 = lowestLow - (0.5 * range); support2List.AddRounded(support2); - double resistance1 = highestHigh + (0.25 * range); + var resistance1 = highestHigh + (0.25 * range); resistance1List.AddRounded(resistance1); - double resistance2 = highestHigh + (0.5 * range); + var resistance2 = highestHigh + (0.5 * range); resistance2List.AddRounded(resistance2); - double prevMiddle = middleList.LastOrDefault(); - double middle = (support1 + support2 + resistance1 + resistance2) / 4; + var prevMiddle = middleList.LastOrDefault(); + var middle = (support1 + support2 + resistance1 + resistance2) / 4; middleList.AddRounded(middle); var signal = GetCompareSignal(currentValue - middle, prevValue - prevMiddle); @@ -1888,14 +1888,14 @@ public static StockData CalculatePrimeNumberBands(this StockData stockData, int var (upperBandList, _) = GetMaxAndMinValuesList(pnoUpBandList, length); var (_, lowerBandList) = GetMaxAndMinValuesList(pnoDnBandList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double prevUpBand1 = i >= 1 ? upperBandList[i - 1] : 0; - double prevUpBand2 = i >= 2 ? upperBandList[i - 1] : 0; - double prevDnBand1 = i >= 1 ? lowerBandList[i - 1] : 0; - double prevDnBand2 = i >= 2 ? lowerBandList[i - 1] : 0; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var close = inputList[i]; + var prevUpBand1 = i >= 1 ? upperBandList[i - 1] : 0; + var prevUpBand2 = i >= 2 ? upperBandList[i - 1] : 0; + var prevDnBand1 = i >= 1 ? lowerBandList[i - 1] : 0; + var prevDnBand2 = i >= 2 ? lowerBandList[i - 1] : 0; + var prevClose = i >= 1 ? inputList[i - 1] : 0; var signal = GetBullishBearishSignal(close - prevUpBand1, prevClose - prevUpBand2, close - prevDnBand1, prevClose - prevDnBand2); signalsList.Add(signal); @@ -1943,83 +1943,83 @@ public static StockData CalculatePeriodicChannel(this StockData stockData, int l List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = tempList.LastOrDefault(); - double currentValue = inputList[i]; + var prevValue = tempList.LastOrDefault(); + var currentValue = inputList[i]; tempList.AddRounded(currentValue); double index = i; indexList.AddRounded(index); - double indexCum = i != 0 ? indexList.Sum() / i : 0; - double indexCumDiff = i - indexCum; - double absIndexCumDiff = Math.Abs(i - indexCum); + var indexCum = i != 0 ? indexList.Sum() / i : 0; + var indexCumDiff = i - indexCum; + var absIndexCumDiff = Math.Abs(i - indexCum); absIndexCumDiffList.AddRounded(absIndexCumDiff); - double absIndexCum = i != 0 ? absIndexCumDiffList.Sum() / i : 0; - double z = absIndexCum != 0 ? indexCumDiff / absIndexCum : 0; + var absIndexCum = i != 0 ? absIndexCumDiffList.Sum() / i : 0; + var z = absIndexCum != 0 ? indexCumDiff / absIndexCum : 0; var corr = GoodnessOfFit.R(indexList.TakeLastExt(length2).Select(x => (double)x), tempList.TakeLastExt(length2).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; corrList.AddRounded((double)corr); double s = i * Math.Sign(corrList.Sum()); - double sin = Math.Sin(s / length1); + var sin = Math.Sin(s / length1); sinList.AddRounded(sin); - double inSin = Math.Sin(s / length1) * -1; + var inSin = Math.Sin(s / length1) * -1; inSinList.AddRounded(inSin); - double sinCum = i != 0 ? sinList.Sum() / i : 0; - double inSinCum = i != 0 ? inSinList.Sum() / i : 0; - double sinCumDiff = sin - sinCum; - double inSinCumDiff = inSin - inSinCum; + var sinCum = i != 0 ? sinList.Sum() / i : 0; + var inSinCum = i != 0 ? inSinList.Sum() / i : 0; + var sinCumDiff = sin - sinCum; + var inSinCumDiff = inSin - inSinCum; - double absSinCumDiff = Math.Abs(sin - sinCum); + var absSinCumDiff = Math.Abs(sin - sinCum); absSinCumDiffList.AddRounded(absSinCumDiff); - double absSinCum = i != 0 ? absSinCumDiffList.Sum() / i : 0; - double absInSinCumDiff = Math.Abs(inSin - inSinCum); + var absSinCum = i != 0 ? absSinCumDiffList.Sum() / i : 0; + var absInSinCumDiff = Math.Abs(inSin - inSinCum); absInSinCumDiffList.AddRounded(absInSinCumDiff); - double absInSinCum = i != 0 ? absInSinCumDiffList.Sum() / i : 0; - double zs = absSinCum != 0 ? sinCumDiff / absSinCum : 0; - double inZs = absInSinCum != 0 ? inSinCumDiff / absInSinCum : 0; - double cum = i != 0 ? tempList.Sum() / i : 0; + var absInSinCum = i != 0 ? absInSinCumDiffList.Sum() / i : 0; + var zs = absSinCum != 0 ? sinCumDiff / absSinCum : 0; + var inZs = absInSinCum != 0 ? inSinCumDiff / absInSinCum : 0; + var cum = i != 0 ? tempList.Sum() / i : 0; - double absDiff = Math.Abs(currentValue - cum); + var absDiff = Math.Abs(currentValue - cum); absDiffList.AddRounded(absDiff); - double absDiffCum = i != 0 ? absDiffList.Sum() / i : 0; - double prevK = kList.LastOrDefault(); - double k = cum + ((z + zs) * absDiffCum); + var absDiffCum = i != 0 ? absDiffList.Sum() / i : 0; + var prevK = kList.LastOrDefault(); + var k = cum + ((z + zs) * absDiffCum); kList.AddRounded(k); - double inK = cum + ((z + inZs) * absDiffCum); - double absKDiff = Math.Abs(currentValue - k); + var inK = cum + ((z + inZs) * absDiffCum); + var absKDiff = Math.Abs(currentValue - k); absKDiffList.AddRounded(absKDiff); - double absInKDiff = Math.Abs(currentValue - inK); - double os = i != 0 ? absKDiffList.Sum() / i : 0; + var absInKDiff = Math.Abs(currentValue - inK); + var os = i != 0 ? absKDiffList.Sum() / i : 0; osList.AddRounded(os); - double ap = k + os; + var ap = k + os; apList.AddRounded(ap); - double bp = ap + os; + var bp = ap + os; bpList.AddRounded(bp); - double cp = bp + os; + var cp = bp + os; cpList.AddRounded(cp); - double al = k - os; + var al = k - os; alList.AddRounded(al); - double bl = al - os; + var bl = al - os; blList.AddRounded(bl); - double cl = bl - os; + var cl = bl - os; clList.AddRounded(cl); var signal = GetCompareSignal(currentValue - k, prevValue - prevK); @@ -2065,36 +2065,36 @@ public static StockData CalculatePriceLineChannel(this StockData stockData, Movi var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double atr = atrList[i]; - double prevA1 = i >= 1 ? aList[i - 1] : currentValue; - double prevB1 = i >= 1 ? bList[i - 1] : currentValue; - double prevA2 = i >= 2 ? aList[i - 2] : 0; - double prevB2 = i >= 2 ? bList[i - 2] : 0; - double prevSizeA = i >= 1 ? sizeAList[i - 1] : atr / length; - double prevSizeB = i >= 1 ? sizeBList[i - 1] : atr / length; - double prevSizeC = i >= 1 ? sizeCList[i - 1] : atr / length; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var atr = atrList[i]; + var prevA1 = i >= 1 ? aList[i - 1] : currentValue; + var prevB1 = i >= 1 ? bList[i - 1] : currentValue; + var prevA2 = i >= 2 ? aList[i - 2] : 0; + var prevB2 = i >= 2 ? bList[i - 2] : 0; + var prevSizeA = i >= 1 ? sizeAList[i - 1] : atr / length; + var prevSizeB = i >= 1 ? sizeBList[i - 1] : atr / length; + var prevSizeC = i >= 1 ? sizeCList[i - 1] : atr / length; - double sizeA = prevA1 - prevA2 > 0 ? atr : prevSizeA; + var sizeA = prevA1 - prevA2 > 0 ? atr : prevSizeA; sizeAList.AddRounded(sizeA); - double sizeB = prevB1 - prevB2 < 0 ? atr : prevSizeB; + var sizeB = prevB1 - prevB2 < 0 ? atr : prevSizeB; sizeBList.AddRounded(sizeB); - double sizeC = prevA1 - prevA2 > 0 || prevB1 - prevB2 < 0 ? atr : prevSizeC; + var sizeC = prevA1 - prevA2 > 0 || prevB1 - prevB2 < 0 ? atr : prevSizeC; sizeCList.AddRounded(sizeC); - double a = Math.Max(currentValue, prevA1) - (sizeA / length); + var a = Math.Max(currentValue, prevA1) - (sizeA / length); aList.AddRounded(a); - double b = Math.Min(currentValue, prevB1) + (sizeB / length); + var b = Math.Min(currentValue, prevB1) + (sizeB / length); bList.AddRounded(b); - double prevMid = midList.LastOrDefault(); - double mid = (a + b) / 2; + var prevMid = midList.LastOrDefault(); + var mid = (a + b) / 2; midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); @@ -2135,18 +2135,18 @@ public static StockData CalculatePriceCurveChannel(this StockData stockData, Mov var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double atr = atrList[i]; - double prevA1 = i >= 1 ? aList[i - 1] : currentValue; - double prevB1 = i >= 1 ? bList[i - 1] : currentValue; - double prevA2 = i >= 2 ? aList[i - 2] : 0; - double prevB2 = i >= 2 ? bList[i - 2] : 0; - double prevSize = i >= 1 ? sizeList[i - 1] : atr / length; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var atr = atrList[i]; + var prevA1 = i >= 1 ? aList[i - 1] : currentValue; + var prevB1 = i >= 1 ? bList[i - 1] : currentValue; + var prevA2 = i >= 2 ? aList[i - 2] : 0; + var prevB2 = i >= 2 ? bList[i - 2] : 0; + var prevSize = i >= 1 ? sizeList[i - 1] : atr / length; - double size = prevA1 - prevA2 > 0 || prevB1 - prevB2 < 0 ? atr : prevSize; + var size = prevA1 - prevA2 > 0 || prevB1 - prevB2 < 0 ? atr : prevSize; sizeList.AddRounded(size); double aChg = prevA1 > prevA2 ? 1 : 0; @@ -2155,19 +2155,19 @@ public static StockData CalculatePriceCurveChannel(this StockData stockData, Mov double bChg = prevB1 < prevB2 ? 1 : 0; bChgList.AddRounded(bChg); - int maxIndexA = aChgList.LastIndexOf(1); - int maxIndexB = bChgList.LastIndexOf(1); - int barsSinceA = aChgList.Count - 1 - maxIndexA; - int barsSinceB = bChgList.Count - 1 - maxIndexB; + var maxIndexA = aChgList.LastIndexOf(1); + var maxIndexB = bChgList.LastIndexOf(1); + var barsSinceA = aChgList.Count - 1 - maxIndexA; + var barsSinceB = bChgList.Count - 1 - maxIndexB; - double a = Math.Max(currentValue, prevA1) - (size / Pow(length, 2) * (barsSinceA + 1)); + var a = Math.Max(currentValue, prevA1) - (size / Pow(length, 2) * (barsSinceA + 1)); aList.AddRounded(a); - double b = Math.Min(currentValue, prevB1) + (size / Pow(length, 2) * (barsSinceB + 1)); + var b = Math.Min(currentValue, prevB1) + (size / Pow(length, 2) * (barsSinceB + 1)); bList.AddRounded(b); - double prevMid = midList.LastOrDefault(); - double mid = (a + b) / 2; + var prevMid = midList.LastOrDefault(); + var mid = (a + b) / 2; midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); @@ -2206,32 +2206,32 @@ public static StockData CalculateProjectionBands(this StockData stockData, int l stockData.CustomValuesList = highList; var highSlopeList = CalculateLinearRegression(stockData, length).OutputValues["Slope"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevPu = i >= 1 ? puList[i - 1] : 0; - double prevPl = i >= 1 ? plList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevPu = i >= 1 ? puList[i - 1] : 0; + var prevPl = i >= 1 ? plList[i - 1] : 0; double pu = currentHigh, pl = currentLow; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double highSlope = i >= j ? highSlopeList[i - j] : 0; - double lowSlope = i >= j ? lowSlopeList[i - j] : 0; - double pHigh = i >= j - 1 ? highList[i - (j - 1)] : 0; - double pLow = i >= j - 1 ? lowList[i - (j - 1)] : 0; - double vHigh = pHigh + (highSlope * j); - double vLow = pLow + (lowSlope * j); + var highSlope = i >= j ? highSlopeList[i - j] : 0; + var lowSlope = i >= j ? lowSlopeList[i - j] : 0; + var pHigh = i >= j - 1 ? highList[i - (j - 1)] : 0; + var pLow = i >= j - 1 ? lowList[i - (j - 1)] : 0; + var vHigh = pHigh + (highSlope * j); + var vLow = pLow + (lowSlope * j); pu = Math.Max(pu, vHigh); pl = Math.Min(pl, vLow); } puList.AddRounded(pu); plList.AddRounded(pl); - double prevMiddleBand = middleBandList.LastOrDefault(); - double middleBand = (pu + pl) / 2; + var prevMiddleBand = middleBandList.LastOrDefault(); + var middleBand = (pu + pl) / 2; middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, pu, prevPu, pl, prevPl); @@ -2272,34 +2272,34 @@ public static StockData CalculateTrendTraderBands(this StockData stockData, Movi var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double close = inputList[i]; - double prevHighest = i >= 1 ? highestList[i - 1] : 0; - double prevLowest = i >= 1 ? lowestList[i - 1] : 0; - double prevAtr = i >= 1 ? atrList[i - 1] : 0; - double atrMult = prevAtr * mult; - double highLimit = prevHighest - atrMult; - double lowLimit = prevLowest + atrMult; + var close = inputList[i]; + var prevHighest = i >= 1 ? highestList[i - 1] : 0; + var prevLowest = i >= 1 ? lowestList[i - 1] : 0; + var prevAtr = i >= 1 ? atrList[i - 1] : 0; + var atrMult = prevAtr * mult; + var highLimit = prevHighest - atrMult; + var lowLimit = prevLowest + atrMult; - double ret = close > highLimit && close > lowLimit ? highLimit : close < lowLimit && close < highLimit ? lowLimit : retList.LastOrDefault(); + var ret = close > highLimit && close > lowLimit ? highLimit : close < lowLimit && close < highLimit ? lowLimit : retList.LastOrDefault(); retList.AddRounded(ret); } var retEmaList = GetMovingAverageList(stockData, maType, length, retList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double retEma = retEmaList[i]; - double close = inputList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevRetEma = i >= 1 ? retEmaList[i - 1] : 0; + var retEma = retEmaList[i]; + var close = inputList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevRetEma = i >= 1 ? retEmaList[i - 1] : 0; - double prevOuterUpperBand = outerUpperBandList.LastOrDefault(); - double outerUpperBand = retEma + bandStep; + var prevOuterUpperBand = outerUpperBandList.LastOrDefault(); + var outerUpperBand = retEma + bandStep; outerUpperBandList.AddRounded(outerUpperBand); - double prevOuterLowerBand = outerLowerBandList.LastOrDefault(); - double outerLowerBand = retEma - bandStep; + var prevOuterLowerBand = outerLowerBandList.LastOrDefault(); + var outerLowerBand = retEma - bandStep; outerLowerBandList.AddRounded(outerLowerBand); var signal = GetBollingerBandsSignal(close - retEma, prevClose - prevRetEma, close, prevClose, outerUpperBand, @@ -2344,62 +2344,62 @@ public static StockData CalculateTimeAndMoneyChannel(this StockData stockData, M List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int halfLength = MinOrMax((int)Math.Ceiling((double)length1 / 2)); + var halfLength = MinOrMax((int)Math.Ceiling((double)length1 / 2)); var smaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevBasis = i >= halfLength ? smaList[i - halfLength] : 0; + var currentValue = inputList[i]; + var prevBasis = i >= halfLength ? smaList[i - halfLength] : 0; - double yom = prevBasis != 0 ? 100 * (currentValue - prevBasis) / prevBasis : 0; + var yom = prevBasis != 0 ? 100 * (currentValue - prevBasis) / prevBasis : 0; yomList.AddRounded(yom); - double yomSquared = Pow(yom, 2); + var yomSquared = Pow(yom, 2); yomSquaredList.AddRounded(yomSquared); } var avyomList = GetMovingAverageList(stockData, maType, length2, yomList); var yomSquaredSmaList = GetMovingAverageList(stockData, maType, length2, yomSquaredList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevVaryom = i >= halfLength ? varyomList[i - halfLength] : 0; - double avyom = avyomList[i]; - double yomSquaredSma = yomSquaredSmaList[i]; + var prevVaryom = i >= halfLength ? varyomList[i - halfLength] : 0; + var avyom = avyomList[i]; + var yomSquaredSma = yomSquaredSmaList[i]; - double varyom = yomSquaredSma - (avyom * avyom); + var varyom = yomSquaredSma - (avyom * avyom); varyomList.AddRounded(varyom); - double som = prevVaryom >= 0 ? Sqrt(prevVaryom) : 0; + var som = prevVaryom >= 0 ? Sqrt(prevVaryom) : 0; somList.AddRounded(som); } var sigomList = GetMovingAverageList(stockData, maType, length1, somList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double som = somList[i]; - double prevSom = i >= 1 ? somList[i - 1] : 0; - double sigom = sigomList[i]; - double prevSigom = i >= 1 ? sigomList[i - 1] : 0; - double basis = smaList[i]; + var som = somList[i]; + var prevSom = i >= 1 ? somList[i - 1] : 0; + var sigom = sigomList[i]; + var prevSigom = i >= 1 ? sigomList[i - 1] : 0; + var basis = smaList[i]; - double chPlus1 = basis * (1 + (0.01 * sigom)); + var chPlus1 = basis * (1 + (0.01 * sigom)); chPlus1List.AddRounded(chPlus1); - double chMinus1 = basis * (1 - (0.01 * sigom)); + var chMinus1 = basis * (1 - (0.01 * sigom)); chMinus1List.AddRounded(chMinus1); - double chPlus2 = basis * (1 + (0.02 * sigom)); + var chPlus2 = basis * (1 + (0.02 * sigom)); chPlus2List.AddRounded(chPlus2); - double chMinus2 = basis * (1 - (0.02 * sigom)); + var chMinus2 = basis * (1 - (0.02 * sigom)); chMinus2List.AddRounded(chMinus2); - double chPlus3 = basis * (1 + (0.03 * sigom)); + var chPlus3 = basis * (1 + (0.03 * sigom)); chPlus3List.AddRounded(chPlus3); - double chMinus3 = basis * (1 - (0.03 * sigom)); + var chMinus3 = basis * (1 - (0.03 * sigom)); chMinus3List.AddRounded(chMinus3); var signal = GetCompareSignal(som - sigom, prevSom - prevSigom); @@ -2443,36 +2443,36 @@ public static StockData CalculateTironeLevels(this StockData stockData, int leng var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double hh = highestList[i]; - double ll = lowestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var hh = highestList[i]; + var ll = lowestList[i]; - double tlh = hh - ((hh - ll) / 3); + var tlh = hh - ((hh - ll) / 3); tlhList.AddRounded(tlh); - double clh = ll + ((hh - ll) / 2); + var clh = ll + ((hh - ll) / 2); clhList.AddRounded(clh); - double blh = ll + ((hh - ll) / 3); + var blh = ll + ((hh - ll) / 3); blhList.AddRounded(blh); - double prevAm = amList.LastOrDefault(); - double am = (hh + ll + currentValue) / 3; + var prevAm = amList.LastOrDefault(); + var am = (hh + ll + currentValue) / 3; amList.AddRounded(am); - double eh = am + (hh - ll); + var eh = am + (hh - ll); ehList.AddRounded(eh); - double el = am - (hh - ll); + var el = am - (hh - ll); elList.AddRounded(el); - double rh = (2 * am) - ll; + var rh = (2 * am) - ll; rhList.AddRounded(rh); - double rl = (2 * am) - hh; + var rl = (2 * am) - hh; rlList.AddRounded(rl); var signal = GetCompareSignal(currentValue - am, prevValue - prevAm); @@ -2513,23 +2513,23 @@ public static StockData CalculateTimeSeriesForecast(this StockData stockData, in var tsList = CalculateLinearRegression(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ts = tsList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevTs = i >= 1 ? tsList[i - 1] : 0; + var currentValue = inputList[i]; + var ts = tsList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevTs = i >= 1 ? tsList[i - 1] : 0; - double absDiff = Math.Abs(currentValue - ts); + var absDiff = Math.Abs(currentValue - ts); absDiffList.AddRounded(absDiff); - double e = i != 0 ? absDiffList.Sum() / i : 0; - double prevA = aList.LastOrDefault(); - double a = ts + e; + var e = i != 0 ? absDiffList.Sum() / i : 0; + var prevA = aList.LastOrDefault(); + var a = ts + e; aList.AddRounded(a); - double prevB = bList.LastOrDefault(); - double b = ts - e; + var prevB = bList.LastOrDefault(); + var b = ts - e; bList.AddRounded(b); var signal = GetBollingerBandsSignal(currentValue - ts, prevValue - prevTs, currentValue, prevValue, a, prevA, b, prevB); @@ -2568,22 +2568,22 @@ public static StockData CalculateRangeBands(this StockData stockData, double std var smaList = GetMovingAverageList(stockData, maType, length, inputList); var (highestList, lowestList) = GetMaxAndMinValuesList(smaList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = smaList[i]; - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; - double rangeDev = highest - lowest; + var middleBand = smaList[i]; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; + var rangeDev = highest - lowest; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (rangeDev * stdDevFactor); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (rangeDev * stdDevFactor); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (rangeDev * stdDevFactor); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (rangeDev * stdDevFactor); lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, @@ -2618,23 +2618,23 @@ public static StockData CalculateRangeIdentifier(this StockData stockData, int l List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevUp = upList.LastOrDefault(); - double prevDown = downList.LastOrDefault(); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevUp = upList.LastOrDefault(); + var prevDown = downList.LastOrDefault(); - double up = currentValue < prevUp && currentValue > prevDown ? prevUp : currentHigh; + var up = currentValue < prevUp && currentValue > prevDown ? prevUp : currentHigh; upList.AddRounded(up); - double down = currentValue < prevUp && currentValue > prevDown ? prevDown : currentLow; + var down = currentValue < prevUp && currentValue > prevDown ? prevDown : currentLow; downList.AddRounded(down); - double prevMid = midList.LastOrDefault(); - double mid = (up + down) / 2; + var prevMid = midList.LastOrDefault(); + var mid = (up + down) / 2; midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); @@ -2673,23 +2673,23 @@ public static StockData CalculateRateOfChangeBands(this StockData stockData, Mov var rocList = CalculateRateOfChange(stockData, length).CustomValuesList; var middleBandList = GetMovingAverageList(stockData, maType, smoothLength, rocList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double roc = rocList[i]; - double middleBand = middleBandList[i]; - double prevMiddleBand1 = i >= 1 ? middleBandList[i - 1] : 0; - double prevMiddleBand2 = i >= 2 ? middleBandList[i - 2] : 0; + var roc = rocList[i]; + var middleBand = middleBandList[i]; + var prevMiddleBand1 = i >= 1 ? middleBandList[i - 1] : 0; + var prevMiddleBand2 = i >= 2 ? middleBandList[i - 2] : 0; - double rocSquared = Pow(roc, 2); + var rocSquared = Pow(roc, 2); rocSquaredList.AddRounded(rocSquared); - double squaredAvg = rocSquaredList.TakeLastExt(length).Average(); - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = Sqrt(squaredAvg); + var squaredAvg = rocSquaredList.TakeLastExt(length).Average(); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = Sqrt(squaredAvg); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = -upperBand; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = -upperBand; lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(middleBand - prevMiddleBand1, prevMiddleBand1 - prevMiddleBand2, middleBand, prevMiddleBand1, @@ -2729,31 +2729,31 @@ public static StockData CalculateRootMovingAverageSquaredErrorBands(this StockDa var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma = smaList[i]; - double currentValue = inputList[i]; + var sma = smaList[i]; + var currentValue = inputList[i]; - double pow = Pow(currentValue - sma, 2); + var pow = Pow(currentValue - sma, 2); powList.AddRounded(pow); } var powSmaList = GetMovingAverageList(stockData, maType, length, powList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = smaList[i]; - double currentValue = inputList[i]; - double powSma = powSmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; - double rmaseDev = Sqrt(powSma); + var middleBand = smaList[i]; + var currentValue = inputList[i]; + var powSma = powSmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; + var rmaseDev = Sqrt(powSma); - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (rmaseDev * stdDevFactor); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (rmaseDev * stdDevFactor); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (rmaseDev * stdDevFactor); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (rmaseDev * stdDevFactor); lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, @@ -2795,24 +2795,24 @@ public static StockData CalculateMovingAverageBands(this StockData stockData, Mo var fastMaList = GetMovingAverageList(stockData, maType, fastLength, inputList); var slowMaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastMa = fastMaList[i]; - double slowMa = slowMaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevFastMa = i >= 1 ? fastMaList[i - 1] : 0; + var fastMa = fastMaList[i]; + var slowMa = slowMaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevFastMa = i >= 1 ? fastMaList[i - 1] : 0; - double sq = Pow(slowMa - fastMa, 2); + var sq = Pow(slowMa - fastMa, 2); sqList.AddRounded(sq); - double dev = Sqrt(sqList.TakeLastExt(fastLength).Average()) * mult; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = slowMa + dev; + var dev = Sqrt(sqList.TakeLastExt(fastLength).Average()) * mult; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = slowMa + dev; upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = slowMa - dev; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = slowMa - dev; lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - fastMa, prevValue - prevFastMa, currentValue, prevValue, @@ -2849,21 +2849,21 @@ public static StockData CalculateMovingAverageSupportResistance(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double supportLevel = 1 + (factor / 100); + var supportLevel = 1 + (factor / 100); var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentSma = smaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentSma = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; - double top = currentSma * supportLevel; + var top = currentSma * supportLevel; topList.AddRounded(top); - double bottom = supportLevel != 0 ? currentSma / supportLevel : 0; + var bottom = supportLevel != 0 ? currentSma / supportLevel : 0; bottomList.AddRounded(bottom); var signal = GetCompareSignal(currentValue - currentSma, prevValue - prevSma); @@ -2901,40 +2901,40 @@ public static StockData CalculateMotionToAttractionChannels(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alpha = (double)1 / length; + var alpha = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevAMa = i >= 1 ? aMaList[i - 1] : currentValue; - double prevBMa = i >= 1 ? bMaList[i - 1] : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevAMa = i >= 1 ? aMaList[i - 1] : currentValue; + var prevBMa = i >= 1 ? bMaList[i - 1] : currentValue; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double a = currentValue > prevAMa ? currentValue : prevA; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var a = currentValue > prevAMa ? currentValue : prevA; aList.AddRounded(a); - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double b = currentValue < prevBMa ? currentValue : prevB; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var b = currentValue < prevBMa ? currentValue : prevB; bList.AddRounded(b); - double prevC = cList.LastOrDefault(); - double c = b - prevB != 0 ? prevC + alpha : a - prevA != 0 ? 0 : prevC; + var prevC = cList.LastOrDefault(); + var c = b - prevB != 0 ? prevC + alpha : a - prevA != 0 ? 0 : prevC; cList.AddRounded(c); - double prevD = dList.LastOrDefault(); - double d = a - prevA != 0 ? prevD + alpha : b - prevB != 0 ? 0 : prevD; + var prevD = dList.LastOrDefault(); + var d = a - prevA != 0 ? prevD + alpha : b - prevB != 0 ? 0 : prevD; dList.AddRounded(d); - double avg = (a + b) / 2; - double aMa = (c * avg) + ((1 - c) * a); + var avg = (a + b) / 2; + var aMa = (c * avg) + ((1 - c) * a); aMaList.AddRounded(aMa); - double bMa = (d * avg) + ((1 - d) * b); + var bMa = (d * avg) + ((1 - d) * b); bMaList.AddRounded(bMa); - double prevAvgMa = avgMaList.LastOrDefault(); - double avgMa = (aMa + bMa) / 2; + var prevAvgMa = avgMaList.LastOrDefault(); + var avgMa = (aMa + bMa) / 2; avgMaList.AddRounded(avgMa); var signal = GetCompareSignal(currentValue - avgMa, prevValue - prevAvgMa); @@ -2973,23 +2973,23 @@ public static StockData CalculateMeanAbsoluteErrorBands(this StockData stockData var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = smaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; + var middleBand = smaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; - double dev = Math.Abs(currentValue - middleBand); + var dev = Math.Abs(currentValue - middleBand); devList.AddRounded(dev); - double maeDev = i != 0 ? devList.Sum() / i : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (maeDev * stdDevFactor); + var maeDev = i != 0 ? devList.Sum() / i : 0; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (maeDev * stdDevFactor); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (maeDev * stdDevFactor); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (maeDev * stdDevFactor); lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, @@ -3029,20 +3029,20 @@ public static StockData CalculateMeanAbsoluteDeviationBands(this StockData stock var smaList = GetMovingAverageList(stockData, maType, length, inputList); var devList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double middleBand = smaList[i]; - double currentValue = inputList[i]; - double currentStdDeviation = devList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; + var middleBand = smaList[i]; + var currentValue = inputList[i]; + var currentStdDeviation = devList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = middleBand + (currentStdDeviation * stdDevFactor); + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = middleBand + (currentStdDeviation * stdDevFactor); upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = middleBand - (currentStdDeviation * stdDevFactor); + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = middleBand - (currentStdDeviation * stdDevFactor); lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, @@ -3083,22 +3083,22 @@ public static StockData CalculateMovingAverageDisplacedEnvelope(this StockData s var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= length2 ? emaList[i - length2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= length2 ? emaList[i - length2] : 0; - double prevUpperEnvelope = upperEnvelopeList.LastOrDefault(); - double upperEnvelope = prevEma * ((100 + pct) / 100); + var prevUpperEnvelope = upperEnvelopeList.LastOrDefault(); + var upperEnvelope = prevEma * ((100 + pct) / 100); upperEnvelopeList.AddRounded(upperEnvelope); - double prevLowerEnvelope = lowerEnvelopeList.LastOrDefault(); - double lowerEnvelope = prevEma * ((100 - pct) / 100); + var prevLowerEnvelope = lowerEnvelopeList.LastOrDefault(); + var lowerEnvelope = prevEma * ((100 - pct) / 100); lowerEnvelopeList.AddRounded(lowerEnvelope); - double prevMiddleEnvelope = middleEnvelopeList.LastOrDefault(); - double middleEnvelope = (upperEnvelope + lowerEnvelope) / 2; + var prevMiddleEnvelope = middleEnvelopeList.LastOrDefault(); + var middleEnvelope = (upperEnvelope + lowerEnvelope) / 2; middleEnvelopeList.AddRounded(middleEnvelope); var signal = GetBollingerBandsSignal(currentValue - middleEnvelope, prevValue - prevMiddleEnvelope, currentValue, prevValue, @@ -3138,12 +3138,12 @@ public static StockData CalculateDema2Lines(this StockData stockData, MovingAvgT var dema1List = GetMovingAverageList(stockData, maType, fastLength, ema1List); var dema2List = GetMovingAverageList(stockData, maType, slowLength, ema2List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dema1 = dema1List[i]; - double dema2 = dema2List[i]; - double prevDema1 = i >= 1 ? dema1List[i - 1] : 0; - double prevDema2 = i >= 1 ? dema2List[i - 1] : 0; + var dema1 = dema1List[i]; + var dema2 = dema2List[i]; + var prevDema1 = i >= 1 ? dema1List[i - 1] : 0; + var prevDema2 = i >= 1 ? dema2List[i - 1] : 0; var signal = GetCompareSignal(dema1 - dema2, prevDema1 - prevDema2); signalsList.Add(signal); @@ -3178,26 +3178,26 @@ public static StockData CalculateDynamicSupportAndResistance(this StockData stoc var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - double mult = Sqrt(length); + var mult = Sqrt(length); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentAvgTrueRange = atrList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentAvgTrueRange = atrList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double support = highestHigh - (currentAvgTrueRange * mult); + var support = highestHigh - (currentAvgTrueRange * mult); supportList.AddRounded(support); - double resistance = lowestLow + (currentAvgTrueRange * mult); + var resistance = lowestLow + (currentAvgTrueRange * mult); resistanceList.AddRounded(resistance); - double prevMiddle = middleList.LastOrDefault(); - double middle = (support + resistance) / 2; + var prevMiddle = middleList.LastOrDefault(); + var middle = (support + resistance) / 2; middleList.AddRounded(middle); var signal = GetCompareSignal(currentValue - middle, prevValue - prevMiddle); @@ -3234,20 +3234,20 @@ public static StockData CalculateDailyAveragePriceDelta(this StockData stockData var smaHighList = GetMovingAverageList(stockData, maType, length, highList); var smaLowList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double high = highList[i]; - double low = lowList[i]; - double highSma = smaHighList[i]; - double lowSma = smaLowList[i]; - double dapd = highSma - lowSma; + var high = highList[i]; + var low = lowList[i]; + var highSma = smaHighList[i]; + var lowSma = smaLowList[i]; + var dapd = highSma - lowSma; - double prevTop = topList.LastOrDefault(); - double top = high + dapd; + var prevTop = topList.LastOrDefault(); + var top = high + dapd; topList.AddRounded(top); - double prevBottom = bottomList.LastOrDefault(); - double bottom = low - dapd; + var prevBottom = bottomList.LastOrDefault(); + var bottom = low - dapd; bottomList.AddRounded(bottom); var signal = GetConditionSignal(high > prevTop, low < prevBottom); @@ -3285,40 +3285,40 @@ public static StockData CalculateDEnvelope(this StockData stockData, int length List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double alp = (double)2 / (length + 1); + var alp = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMt = mtList.LastOrDefault(); - double mt = (alp * currentValue) + ((1 - alp) * prevMt); + var prevMt = mtList.LastOrDefault(); + var mt = (alp * currentValue) + ((1 - alp) * prevMt); mtList.AddRounded(mt); - double prevUt = utList.LastOrDefault(); - double ut = (alp * mt) + ((1 - alp) * prevUt); + var prevUt = utList.LastOrDefault(); + var ut = (alp * mt) + ((1 - alp) * prevUt); utList.AddRounded(ut); - double prevDt = dtList.LastOrDefault(); - double dt = (2 - alp) * (mt - ut) / (1 - alp); + var prevDt = dtList.LastOrDefault(); + var dt = (2 - alp) * (mt - ut) / (1 - alp); dtList.AddRounded(dt); - double prevMt2 = mt2List.LastOrDefault(); - double mt2 = (alp * Math.Abs(currentValue - dt)) + ((1 - alp) * prevMt2); + var prevMt2 = mt2List.LastOrDefault(); + var mt2 = (alp * Math.Abs(currentValue - dt)) + ((1 - alp) * prevMt2); mt2List.AddRounded(mt2); - double prevUt2 = ut2List.LastOrDefault(); - double ut2 = (alp * mt2) + ((1 - alp) * prevUt2); + var prevUt2 = ut2List.LastOrDefault(); + var ut2 = (alp * mt2) + ((1 - alp) * prevUt2); ut2List.AddRounded(ut2); - double dt2 = (2 - alp) * (mt2 - ut2) / (1 - alp); - double prevBut = butList.LastOrDefault(); - double but = dt + (devFactor * dt2); + var dt2 = (2 - alp) * (mt2 - ut2) / (1 - alp); + var prevBut = butList.LastOrDefault(); + var but = dt + (devFactor * dt2); butList.AddRounded(but); - double prevBlt = bltList.LastOrDefault(); - double blt = dt - (devFactor * dt2); + var prevBlt = bltList.LastOrDefault(); + var blt = dt - (devFactor * dt2); bltList.AddRounded(blt); var signal = GetBollingerBandsSignal(currentValue - dt, prevValue - prevDt, currentValue, prevValue, but, prevBut, blt, prevBlt); @@ -3355,30 +3355,30 @@ public static StockData CalculateSmartEnvelope(this StockData stockData, int len List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double prevASignal = aSignalList.LastOrDefault(); - double prevBSignal = bSignalList.LastOrDefault(); - double diff = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var prevASignal = aSignalList.LastOrDefault(); + var prevBSignal = bSignalList.LastOrDefault(); + var diff = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); - double a = Math.Max(currentValue, prevA) - (Math.Min(Math.Abs(currentValue - prevA), diff) / length * prevASignal); + var a = Math.Max(currentValue, prevA) - (Math.Min(Math.Abs(currentValue - prevA), diff) / length * prevASignal); aList.AddRounded(a); - double b = Math.Min(currentValue, prevB) + (Math.Min(Math.Abs(currentValue - prevB), diff) / length * prevBSignal); + var b = Math.Min(currentValue, prevB) + (Math.Min(Math.Abs(currentValue - prevB), diff) / length * prevBSignal); bList.AddRounded(b); - double aSignal = b < prevB ? -factor : factor; + var aSignal = b < prevB ? -factor : factor; aSignalList.AddRounded(aSignal); - double bSignal = a > prevA ? -factor : factor; + var bSignal = a > prevA ? -factor : factor; bSignalList.AddRounded(bSignal); - double prevAvg = avgList.LastOrDefault(); - double avg = (a + b) / 2; + var prevAvg = avgList.LastOrDefault(); + var avg = (a + b) / 2; avgList.AddRounded(avg); var signal = GetCompareSignal(currentValue - avg, prevValue - prevAvg); @@ -3415,22 +3415,22 @@ public static StockData CalculateSupportResistance(this StockData stockData, Mov var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double sma = i >= 1 ? smaList[i - 1] : 0; - bool crossAbove = prevValue < sma && currentValue >= sma; - bool crossBelow = prevValue > sma && currentValue <= sma; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var sma = i >= 1 ? smaList[i - 1] : 0; + var crossAbove = prevValue < sma && currentValue >= sma; + var crossBelow = prevValue > sma && currentValue <= sma; - double prevRes = resList.LastOrDefault(); - double res = crossBelow ? highest : i >= 1 ? prevRes : highest; + var prevRes = resList.LastOrDefault(); + var res = crossBelow ? highest : i >= 1 ? prevRes : highest; resList.AddRounded(res); - double prevSupp = suppList.LastOrDefault(); - double supp = crossAbove ? lowest : i >= 1 ? prevSupp : lowest; + var prevSupp = suppList.LastOrDefault(); + var supp = crossAbove ? lowest : i >= 1 ? prevSupp : lowest; suppList.AddRounded(supp); var signal = GetBullishBearishSignal(currentValue - res, prevValue - prevRes, currentValue - supp, prevValue - prevSupp); @@ -3466,33 +3466,33 @@ public static StockData CalculateStationaryExtrapolatedLevels(this StockData sto var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double priorY = i >= length ? yList[i - length] : 0; - double priorY2 = i >= length * 2 ? yList[i - (length * 2)] : 0; - double priorX = i >= length ? xList[i - length] : 0; - double priorX2 = i >= length * 2 ? xList[i - (length * 2)] : 0; + var currentValue = inputList[i]; + var sma = smaList[i]; + var priorY = i >= length ? yList[i - length] : 0; + var priorY2 = i >= length * 2 ? yList[i - (length * 2)] : 0; + var priorX = i >= length ? xList[i - length] : 0; + var priorX2 = i >= length * 2 ? xList[i - (length * 2)] : 0; double x = i; xList.AddRounded(i); - double y = currentValue - sma; + var y = currentValue - sma; yList.AddRounded(y); - double ext = priorX2 - priorX != 0 && priorY2 - priorY != 0 ? (priorY + ((x - priorX) / (priorX2 - priorX) * (priorY2 - priorY))) / 2 : 0; + var ext = priorX2 - priorX != 0 && priorY2 - priorY != 0 ? (priorY + ((x - priorX) / (priorX2 - priorX) * (priorY2 - priorY))) / 2 : 0; extList.AddRounded(ext); } var (highestList1, lowestList1) = GetMaxAndMinValuesList(extList, length); var (upperBandList, lowerBandList) = GetMaxAndMinValuesList(highestList1, lowestList1, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double y = yList[i]; - double ext = extList[i]; - double prevY = i >= 1 ? yList[i - 1] : 0; - double prevExt = i >= 1 ? extList[i - 1] : 0; + var y = yList[i]; + var ext = extList[i]; + var prevY = i >= 1 ? yList[i - 1] : 0; + var prevExt = i >= 1 ? extList[i - 1] : 0; var signal = GetCompareSignal(y - ext, prevY - prevExt); signalsList.Add(signal); @@ -3530,15 +3530,15 @@ public static StockData CalculateScalpersChannel(this StockData stockData, Movin var smaList = GetMovingAverageList(stockData, maType, length2, inputList); var atrList = CalculateAverageTrueRange(stockData, maType, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentSma = smaList[i]; - double currentAtr = atrList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentSma = smaList[i]; + var currentAtr = atrList[i]; - double prevScalper = scalperList.LastOrDefault(); - double scalper = Math.PI * currentAtr > 0 ? currentSma - Math.Log(Math.PI * currentAtr) : currentSma; + var prevScalper = scalperList.LastOrDefault(); + var scalper = Math.PI * currentAtr > 0 ? currentSma - Math.Log(Math.PI * currentAtr) : currentSma; scalperList.AddRounded(scalper); var signal = GetCompareSignal(currentValue - scalper, prevValue - prevScalper); @@ -3576,28 +3576,28 @@ public static StockData CalculateSmoothedVolatilityBands(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int atrPeriod = (length1 * 2) - 1; + var atrPeriod = (length1 * 2) - 1; var atrList = CalculateAverageTrueRange(stockData, maType, atrPeriod).CustomValuesList; var maList = GetMovingAverageList(stockData, maType, length1, inputList); var middleBandList = GetMovingAverageList(stockData, maType, length2, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double atr = atrList[i]; - double middleBand = middleBandList[i]; - double ma = maList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; - double atrBuf = atr * deviation; + var atr = atrList[i]; + var middleBand = middleBandList[i]; + var ma = maList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; + var atrBuf = atr * deviation; - double prevUpperBand = upperBandList.LastOrDefault(); - double upperBand = currentValue != 0 ? ma + (ma * atrBuf / currentValue) : ma; + var prevUpperBand = upperBandList.LastOrDefault(); + var upperBand = currentValue != 0 ? ma + (ma * atrBuf / currentValue) : ma; upperBandList.AddRounded(upperBand); - double prevLowerBand = lowerBandList.LastOrDefault(); - double lowerBand = currentValue != 0 ? ma - (ma * atrBuf * bandAdjust / currentValue) : ma; + var prevLowerBand = lowerBandList.LastOrDefault(); + var lowerBand = currentValue != 0 ? ma - (ma * atrBuf * bandAdjust / currentValue) : ma; lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, @@ -3632,23 +3632,23 @@ public static StockData CalculateExtendedRecursiveBands(this StockData stockData List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double sc = (double)2 / (length + 1); + var sc = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevAClassic = i >= 1 ? aClassicList[i - 1] : currentValue; - double prevBClassic = i >= 1 ? bClassicList[i - 1] : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevAClassic = i >= 1 ? aClassicList[i - 1] : currentValue; + var prevBClassic = i >= 1 ? bClassicList[i - 1] : currentValue; - double aClassic = Math.Max(prevAClassic, currentValue) - (sc * Math.Abs(currentValue - prevAClassic)); + var aClassic = Math.Max(prevAClassic, currentValue) - (sc * Math.Abs(currentValue - prevAClassic)); aClassicList.AddRounded(aClassic); - double bClassic = Math.Min(prevBClassic, currentValue) + (sc * Math.Abs(currentValue - prevBClassic)); + var bClassic = Math.Min(prevBClassic, currentValue) + (sc * Math.Abs(currentValue - prevBClassic)); bClassicList.AddRounded(bClassic); - double prevCClassic = cClassicList.LastOrDefault(); - double cClassic = (aClassic + bClassic) / 2; + var prevCClassic = cClassicList.LastOrDefault(); + var cClassic = (aClassic + bClassic) / 2; cClassicList.AddRounded(cClassic); var signal = GetCompareSignal(currentValue - cClassic, prevValue - prevCClassic); @@ -3687,11 +3687,11 @@ public static StockData CalculateEfficientTrendStepChannel(this StockData stockD var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length).OutputValues["Er"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double val2 = currentValue * 2; + var val2 = currentValue * 2; val2List.AddRounded(val2); } @@ -3699,25 +3699,25 @@ public static StockData CalculateEfficientTrendStepChannel(this StockData stockD var stdDevFastList = CalculateStandardDeviationVolatility(stockData, length: fastLength).CustomValuesList; stockData.CustomValuesList = val2List; var stdDevSlowList = CalculateStandardDeviationVolatility(stockData, length: slowLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double er = erList[i]; - double fastStdDev = stdDevFastList[i]; - double slowStdDev = stdDevSlowList[i]; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double dev = (er * fastStdDev) + ((1 - er) * slowStdDev); + var currentValue = inputList[i]; + var er = erList[i]; + var fastStdDev = stdDevFastList[i]; + var slowStdDev = stdDevSlowList[i]; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var dev = (er * fastStdDev) + ((1 - er) * slowStdDev); - double a = currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; + var a = currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; aList.AddRounded(a); - double prevUpper = upperList.LastOrDefault(); - double upper = a + dev; + var prevUpper = upperList.LastOrDefault(); + var upper = a + dev; upperList.AddRounded(upper); - double prevLower = lowerList.LastOrDefault(); - double lower = a - dev; + var prevLower = lowerList.LastOrDefault(); + var lower = a - dev; lowerList.AddRounded(lower); var signal = GetBollingerBandsSignal(currentValue - a, prevValue - prevA, currentValue, prevValue, upper, prevUpper, lower, prevLower); diff --git a/src/Calculations/Ratio.cs b/src/Calculations/Ratio.cs index 8889169..8417960 100644 --- a/src/Calculations/Ratio.cs +++ b/src/Calculations/Ratio.cs @@ -32,30 +32,30 @@ public static StockData CalculateMartinRatio(this StockData stockData, MovingAvg double barMin = 60 * 24; double minPerYr = 60 * 24 * 30 * 12; - double barsPerYr = minPerYr / barMin; + var barsPerYr = minPerYr / barMin; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; benchList.AddRounded(bench); - double ret = prevValue != 0 ? (100 * (currentValue / prevValue)) - 1 - (bench * 100) : 0; + var ret = prevValue != 0 ? (100 * (currentValue / prevValue)) - 1 - (bench * 100) : 0; retList.AddRounded(ret); } var retSmaList = GetMovingAverageList(stockData, maType, length, retList); stockData.CustomValuesList = retList; var ulcerIndexList = CalculateUlcerIndex(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ulcerIndex = ulcerIndexList[i]; - double retSma = retSmaList[i]; + var ulcerIndex = ulcerIndexList[i]; + var retSma = retSmaList[i]; - double prevMartin = martinList.LastOrDefault(); - double martin = ulcerIndex != 0 ? retSma / ulcerIndex : 0; + var prevMartin = martinList.LastOrDefault(); + var martin = ulcerIndex != 0 ? retSma / ulcerIndex : 0; martinList.AddRounded(martin); var signal = GetCompareSignal(martin - 2, prevMartin - 2); @@ -89,28 +89,28 @@ public static StockData CalculateUpsidePotentialRatio(this StockData stockData, double barMin = 60 * 24; double minPerYr = 60 * 24 * 30 * 12; - double barsPerYr = minPerYr / barMin; - double ratio = (double)1 / length; + var barsPerYr = minPerYr / barMin; + var ratio = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; retList.AddRounded(ret); double downSide = 0, upSide = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double iValue = i >= j ? retList[i - j] : 0; + var iValue = i >= j ? retList[i - j] : 0; downSide += iValue < bench ? Pow(iValue - bench, 2) * ratio : 0; upSide += iValue > bench ? (iValue - bench) * ratio : 0; } - double prevUpsidePotential = upsidePotentialList.LastOrDefault(); - double upsidePotential = downSide >= 0 ? upSide / Sqrt(downSide) : 0; + var prevUpsidePotential = upsidePotentialList.LastOrDefault(); + var upsidePotential = downSide >= 0 ? upSide / Sqrt(downSide) : 0; upsidePotentialList.AddRounded(upsidePotential); var signal = GetCompareSignal(upsidePotential - 5, prevUpsidePotential - 5); @@ -145,28 +145,28 @@ public static StockData CalculateInformationRatio(this StockData stockData, Movi double barMin = 60 * 24; double minPerYr = 60 * 24 * 30 * 12; - double barsPerYr = minPerYr / barMin; + var barsPerYr = minPerYr / barMin; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; retList.AddRounded(ret); } stockData.CustomValuesList = retList; var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var retSmaList = GetMovingAverageList(stockData, maType, length, retList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDeviation = stdDevList[i]; - double retSma = retSmaList[i]; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var stdDeviation = stdDevList[i]; + var retSma = retSmaList[i]; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; - double prevInfo = infoList.LastOrDefault(); - double info = stdDeviation != 0 ? (retSma - bench) / stdDeviation : 0; + var prevInfo = infoList.LastOrDefault(); + var info = stdDeviation != 0 ? (retSma - bench) / stdDeviation : 0; infoList.AddRounded(info); var signal = GetCompareSignal(info - 5, prevInfo - 5); @@ -200,27 +200,27 @@ public static StockData CalculateOmegaRatio(this StockData stockData, int length double barMin = 60 * 24; double minPerYr = 60 * 24 * 30 * 12; - double barsPerYr = minPerYr / barMin; + var barsPerYr = minPerYr / barMin; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; retList.AddRounded(ret); double downSide = 0, upSide = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double iValue = i >= j ? retList[i - j] : 0; + var iValue = i >= j ? retList[i - j] : 0; downSide += iValue < bench ? bench - iValue : 0; upSide += iValue > bench ? iValue - bench : 0; } - double prevOmega = omegaList.LastOrDefault(); - double omega = downSide != 0 ? upSide / downSide : 0; + var prevOmega = omegaList.LastOrDefault(); + var omega = downSide != 0 ? upSide / downSide : 0; omegaList.AddRounded(omega); var signal = GetCompareSignal(omega - 5, prevOmega - 5); @@ -256,22 +256,22 @@ public static StockData CalculateVolatilityRatio(this StockData stockData, Movin var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double prevHighest = i >= 1 ? highestList[i - 1] : 0; - double prevLowest = i >= 1 ? lowestList[i - 1] : 0; - double priorValue = i >= length + 1 ? inputList[i - (length + 1)] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - double max = priorValue != 0 ? Math.Max(prevHighest, priorValue) : prevHighest; - double min = priorValue != 0 ? Math.Min(prevLowest, priorValue) : prevLowest; - - double vr = max - min != 0 ? tr / (max - min) : 0; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var prevHighest = i >= 1 ? highestList[i - 1] : 0; + var prevLowest = i >= 1 ? lowestList[i - 1] : 0; + var priorValue = i >= length + 1 ? inputList[i - (length + 1)] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var max = priorValue != 0 ? Math.Max(prevHighest, priorValue) : prevHighest; + var min = priorValue != 0 ? Math.Min(prevLowest, priorValue) : prevLowest; + + var vr = max - min != 0 ? tr / (max - min) : 0; vrList.AddRounded(vr); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, vr, breakoutLevel); @@ -305,24 +305,24 @@ public static StockData CalculateCalmarRatio(this StockData stockData, int lengt double barMin = 60 * 24; double minPerYr = 60 * 24 * 30 * 12; - double barsPerYr = minPerYr / barMin; - double power = barsPerYr / (length * 15); + var barsPerYr = minPerYr / barMin; + var power = barsPerYr / (length * 15); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double maxDn = highestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var maxDn = highestList[i]; - double dd = maxDn != 0 ? (currentValue - maxDn) / maxDn : 0; + var dd = maxDn != 0 ? (currentValue - maxDn) / maxDn : 0; ddList.AddRounded(dd); - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; - double annualReturn = 1 + ret >= 0 ? Pow(1 + ret, power) - 1 : 0; - double maxDd = ddList.TakeLastExt(length).Min(); + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; + var annualReturn = 1 + ret >= 0 ? Pow(1 + ret, power) - 1 : 0; + var maxDd = ddList.TakeLastExt(length).Min(); - double prevCalmar = calmarList.LastOrDefault(); - double calmar = maxDd != 0 ? annualReturn / Math.Abs(maxDd) : 0; + var prevCalmar = calmarList.LastOrDefault(); + var calmar = maxDd != 0 ? annualReturn / Math.Abs(maxDd) : 0; calmarList.AddRounded(calmar); var signal = GetCompareSignal(calmar - 2, prevCalmar - 2); @@ -357,18 +357,18 @@ public static StockData CalculateTreynorRatio(this StockData stockData, int leng double barMin = 60 * 24, minPerYr = 60 * 24 * 30 * 12, barsPerYr = minPerYr / barMin; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; retList.AddRounded(ret); - double retSma = retList.TakeLastExt(length).Average(); - double prevTreynor = treynorList.LastOrDefault(); - double treynor = beta != 0 ? (retSma - bench) / beta : 0; + var retSma = retList.TakeLastExt(length).Average(); + var prevTreynor = treynorList.LastOrDefault(); + var treynor = beta != 0 ? (retSma - bench) / beta : 0; treynorList.AddRounded(treynor); var signal = GetCompareSignal(treynor - 2, prevTreynor - 2); @@ -405,36 +405,36 @@ public static StockData CalculateSortinoRatio(this StockData stockData, MovingAv double minPerYr = 60 * 24 * 30 * 12, barMin = 60 * 24, barsPerYr = minPerYr / barMin; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 - bench : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 - bench : 0; retList.AddRounded(ret); } var retSmaList = GetMovingAverageList(stockData, maType, length, retList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ret = retList[i]; - double retSma = retSmaList[i]; - double currentDeviation = Math.Min(ret - retSma, 0); + var ret = retList[i]; + var retSma = retSmaList[i]; + var currentDeviation = Math.Min(ret - retSma, 0); - double deviationSquared = Pow(currentDeviation, 2); + var deviationSquared = Pow(currentDeviation, 2); deviationSquaredList.AddRounded(deviationSquared); } var divisionOfSumList = GetMovingAverageList(stockData, maType, length, deviationSquaredList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double divisionOfSum = divisionOfSumList[i]; - double stdDeviation = Sqrt(divisionOfSum); - double retSma = retSmaList[i]; + var divisionOfSum = divisionOfSumList[i]; + var stdDeviation = Sqrt(divisionOfSum); + var retSma = retSmaList[i]; - double prevSortino = sortinoList.LastOrDefault(); - double sortino = stdDeviation != 0 ? retSma / stdDeviation : 0; + var prevSortino = sortinoList.LastOrDefault(); + var sortino = stdDeviation != 0 ? retSma / stdDeviation : 0; sortinoList.AddRounded(sortino); var signal = GetCompareSignal(sortino - 2, prevSortino - 2); @@ -470,26 +470,26 @@ public static StockData CalculateSharpeRatio(this StockData stockData, MovingAvg double minPerYr = 60 * 24 * 30 * 12, barMin = 60 * 24, barsPerYr = minPerYr / barMin; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; - double bench = Pow(1 + bmk, length / barsPerYr) - 1; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; + var bench = Pow(1 + bmk, length / barsPerYr) - 1; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 - bench : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 - bench : 0; retList.AddRounded(ret); } var retSmaList = GetMovingAverageList(stockData, maType, length, retList); stockData.CustomValuesList = retList; var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDeviation = stdDevList[i]; - double retSma = retSmaList[i]; + var stdDeviation = stdDevList[i]; + var retSma = retSmaList[i]; - double prevSharpe = sharpeList.LastOrDefault(); - double sharpe = stdDeviation != 0 ? retSma / stdDeviation : 0; + var prevSharpe = sharpeList.LastOrDefault(); + var sharpe = stdDeviation != 0 ? retSma / stdDeviation : 0; sharpeList.AddRounded(sharpe); var signal = GetCompareSignal(sharpe - 2, prevSharpe - 2); @@ -524,35 +524,35 @@ public static StockData CalculateShinoharaIntensityRatio(this StockData stockDat List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double high = highList[i]; + var high = highList[i]; tempHighList.AddRounded(high); - double low = lowList[i]; + var low = lowList[i]; tempLowList.AddRounded(low); - double open = openList[i]; + var open = openList[i]; tempOpenList.AddRounded(open); - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevClose = i >= 1 ? inputList[i - 1] : 0; prevCloseList.AddRounded(prevClose); - double highSum = tempHighList.TakeLastExt(length).Sum(); - double lowSum = tempLowList.TakeLastExt(length).Sum(); - double openSum = openList.TakeLastExt(length).Sum(); - double prevCloseSum = prevCloseList.TakeLastExt(length).Sum(); - double bullA = highSum - openSum; - double bearA = openSum - lowSum; - double bullB = highSum - prevCloseSum; - double bearB = prevCloseSum - lowSum; - - double prevRatioA = ratioAList.LastOrDefault(); - double ratioA = bearA != 0 ? bullA / bearA * 100 : 0; + var highSum = tempHighList.TakeLastExt(length).Sum(); + var lowSum = tempLowList.TakeLastExt(length).Sum(); + var openSum = openList.TakeLastExt(length).Sum(); + var prevCloseSum = prevCloseList.TakeLastExt(length).Sum(); + var bullA = highSum - openSum; + var bearA = openSum - lowSum; + var bullB = highSum - prevCloseSum; + var bearB = prevCloseSum - lowSum; + + var prevRatioA = ratioAList.LastOrDefault(); + var ratioA = bearA != 0 ? bullA / bearA * 100 : 0; ratioAList.AddRounded(ratioA); - double prevRatioB = ratioBList.LastOrDefault(); - double ratioB = bearB != 0 ? bullB / bearB * 100 : 0; + var prevRatioB = ratioBList.LastOrDefault(); + var ratioB = bearB != 0 ? bullB / bearB * 100 : 0; ratioBList.AddRounded(ratioB); var signal = GetCompareSignal(ratioA - ratioB, prevRatioA - prevRatioB); diff --git a/src/Calculations/Rsi.cs b/src/Calculations/Rsi.cs index 07169cd..37d146d 100644 --- a/src/Calculations/Rsi.cs +++ b/src/Calculations/Rsi.cs @@ -30,40 +30,40 @@ public static StockData CalculateRelativeStrengthIndex(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priceChg = MinPastValues(i, 1, currentValue - prevValue); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priceChg = MinPastValues(i, 1, currentValue - prevValue); - double loss = priceChg < 0 ? Math.Abs(priceChg) : 0; + var loss = priceChg < 0 ? Math.Abs(priceChg) : 0; lossList.AddRounded(loss); - double gain = priceChg > 0 ? priceChg : 0; + var gain = priceChg > 0 ? priceChg : 0; gainList.AddRounded(gain); } var avgGainList = GetMovingAverageList(stockData, movingAvgType, length, gainList); var avgLossList = GetMovingAverageList(stockData, movingAvgType, length, lossList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double avgGain = avgGainList[i]; - double avgLoss = avgLossList[i]; - double rs = avgLoss != 0 ? avgGain / avgLoss : 0; + var avgGain = avgGainList[i]; + var avgLoss = avgLossList[i]; + var rs = avgLoss != 0 ? avgGain / avgLoss : 0; - double rsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rsiList.AddRounded(rsi); } var rsiSignalList = GetMovingAverageList(stockData, movingAvgType, signalLength, rsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double rsiSignal = rsiSignalList[i]; + var rsi = rsiList[i]; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var rsiSignal = rsiSignalList[i]; - double prevRsiHistogram = rsiHistogramList.LastOrDefault(); - double rsiHistogram = rsi - rsiSignal; + var prevRsiHistogram = rsiHistogramList.LastOrDefault(); + var rsiHistogram = rsi - rsiSignal; rsiHistogramList.AddRounded(rsiHistogram); var signal = GetRsiSignal(rsiHistogram, prevRsiHistogram, rsi, prevRsi, 70, 30); @@ -105,36 +105,36 @@ public static StockData CalculateConnorsRelativeStrengthIndex(this StockData sto var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length2, length2).CustomValuesList; var rocList = CalculateRateOfChange(stockData, length3).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double roc = rocList[i]; + var roc = rocList[i]; tempList.AddRounded(roc); var lookBackList = tempList.TakeLastExt(length3).Take(length3 - 1).ToList(); - int count = lookBackList.Where(x => x <= roc).Count(); - double pctRank = MinOrMax((double)count / length3 * 100, 100, 0); + var count = lookBackList.Where(x => x <= roc).Count(); + var pctRank = MinOrMax((double)count / length3 * 100, 100, 0); pctRankList.AddRounded(pctRank); - double prevStreak = streakList.LastOrDefault(); - double streak = currentValue > prevValue ? prevStreak >= 0 ? prevStreak + 1 : 1 : currentValue < prevValue ? prevStreak <= 0 ? + var prevStreak = streakList.LastOrDefault(); + var streak = currentValue > prevValue ? prevStreak >= 0 ? prevStreak + 1 : 1 : currentValue < prevValue ? prevStreak <= 0 ? prevStreak - 1 : -1 : 0; streakList.AddRounded(streak); } stockData.CustomValuesList = streakList; var rsiStreakList = CalculateRelativeStrengthIndex(stockData, maType, length1, length1).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRsi = rsiList[i]; - double percentRank = pctRankList[i]; - double streakRsi = rsiStreakList[i]; - double prevConnorsRsi1 = i >= 1 ? connorsRsiList[i - 1] : 0; - double prevConnorsRsi2 = i >= 2 ? connorsRsiList[i - 2] : 0; + var currentRsi = rsiList[i]; + var percentRank = pctRankList[i]; + var streakRsi = rsiStreakList[i]; + var prevConnorsRsi1 = i >= 1 ? connorsRsiList[i - 1] : 0; + var prevConnorsRsi2 = i >= 2 ? connorsRsiList[i - 2] : 0; - double connorsRsi = MinOrMax((currentRsi + percentRank + streakRsi) / 3, 100, 0); + var connorsRsi = MinOrMax((currentRsi + percentRank + streakRsi) / 3, 100, 0); connorsRsiList.AddRounded(connorsRsi); var signal = GetRsiSignal(connorsRsi - prevConnorsRsi1, prevConnorsRsi1 - prevConnorsRsi2, connorsRsi, prevConnorsRsi1, 70, 30); @@ -170,34 +170,34 @@ public static StockData CalculateAsymmetricalRelativeStrengthIndex(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevArsi1 = i >= 1 ? arsiList[i - 1] : 0; - double prevArsi2 = i >= 2 ? arsiList[i - 2] : 0; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevArsi1 = i >= 1 ? arsiList[i - 1] : 0; + var prevArsi2 = i >= 2 ? arsiList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double roc = prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / prevValue * 100 : 0; + var roc = prevValue != 0 ? MinPastValues(i, 1, currentValue - prevValue) / prevValue * 100 : 0; rocList.AddRounded(roc); double upCount = rocList.TakeLastExt(length).Where(x => x >= 0).Count(); - double upAlpha = upCount != 0 ? 1 / upCount : 0; - double posRoc = roc > 0 ? roc : 0; - double negRoc = roc < 0 ? Math.Abs(roc) : 0; + var upAlpha = upCount != 0 ? 1 / upCount : 0; + var posRoc = roc > 0 ? roc : 0; + var negRoc = roc < 0 ? Math.Abs(roc) : 0; - double prevUpSum = upSumList.LastOrDefault(); - double upSum = (upAlpha * posRoc) + ((1 - upAlpha) * prevUpSum); + var prevUpSum = upSumList.LastOrDefault(); + var upSum = (upAlpha * posRoc) + ((1 - upAlpha) * prevUpSum); upSumList.AddRounded(upSum); - double downCount = length - upCount; - double downAlpha = downCount != 0 ? 1 / downCount : 0; + var downCount = length - upCount; + var downAlpha = downCount != 0 ? 1 / downCount : 0; - double prevDownSum = downSumList.LastOrDefault(); - double downSum = (downAlpha * negRoc) + ((1 - downAlpha) * prevDownSum); + var prevDownSum = downSumList.LastOrDefault(); + var downSum = (downAlpha * negRoc) + ((1 - downAlpha) * prevDownSum); downSumList.AddRounded(downSum); - double ars = downSum != 0 ? upSum / downSum : 0; - double arsi = downSum == 0 ? 100 : upSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + ars)), 100, 0); + var ars = downSum != 0 ? upSum / downSum : 0; + var arsi = downSum == 0 ? 100 : upSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + ars)), 100, 0); arsiList.AddRounded(arsi); var signal = GetRsiSignal(arsi - prevArsi1, prevArsi1 - prevArsi2, arsi, prevArsi1, 70, 30); @@ -231,15 +231,15 @@ public static StockData CalculateAdaptiveRelativeStrengthIndex(this StockData st var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double alpha = 2 * Math.Abs((rsi / 100) - 0.5); + var rsi = rsiList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var alpha = 2 * Math.Abs((rsi / 100) - 0.5); - double prevArsi = arsiList.LastOrDefault(); - double arsi = (alpha * currentValue) + ((1 - alpha) * prevArsi); + var prevArsi = arsiList.LastOrDefault(); + var arsi = (alpha * currentValue) + ((1 - alpha) * prevArsi); arsiList.AddRounded(arsi); var signal = GetCompareSignal(currentValue - arsi, prevValue - prevArsi); @@ -272,26 +272,26 @@ public static StockData CalculateAverageAbsoluteErrorNormalization(this StockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevY = i >= 1 ? yList[i - 1] : currentValue; - double prevA1 = i >= 1 ? aList[i - 1] : 0; - double prevA2 = i >= 2 ? aList[i - 2] : 0; + var currentValue = inputList[i]; + var prevY = i >= 1 ? yList[i - 1] : currentValue; + var prevA1 = i >= 1 ? aList[i - 1] : 0; + var prevA2 = i >= 2 ? aList[i - 2] : 0; - double e = currentValue - prevY; + var e = currentValue - prevY; eList.AddRounded(e); - double eAbs = Math.Abs(e); + var eAbs = Math.Abs(e); eAbsList.AddRounded(eAbs); - double eAbsSma = eAbsList.TakeLastExt(length).Average(); - double eSma = eList.TakeLastExt(length).Average(); + var eAbsSma = eAbsList.TakeLastExt(length).Average(); + var eSma = eList.TakeLastExt(length).Average(); - double a = eAbsSma != 0 ? MinOrMax(eSma / eAbsSma, 1, -1) : 0; + var a = eAbsSma != 0 ? MinOrMax(eSma / eAbsSma, 1, -1) : 0; aList.AddRounded(a); - double y = currentValue + (a * eAbsSma); + var y = currentValue + (a * eAbsSma); yList.AddRounded(y); var signal = GetRsiSignal(a - prevA1, prevA1 - prevA2, a, prevA1, 0.8, -0.8); @@ -328,29 +328,29 @@ public static StockData CalculateApirineSlowRelativeStrengthIndex(this StockData var emaList = GetMovingAverageList(stockData, maType, smoothLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double r1 = emaList[i]; + var currentValue = inputList[i]; + var r1 = emaList[i]; - double r2 = currentValue > r1 ? currentValue - r1 : 0; + var r2 = currentValue > r1 ? currentValue - r1 : 0; r2List.AddRounded(r2); - double r3 = currentValue < r1 ? r1 - currentValue : 0; + var r3 = currentValue < r1 ? r1 - currentValue : 0; r3List.AddRounded(r3); } var r4List = GetMovingAverageList(stockData, maType, length, r2List); var r5List = GetMovingAverageList(stockData, maType, length, r3List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double r4 = r4List[i]; - double r5 = r5List[i]; - double prevRr1 = i >= 1 ? rrList[i - 1] : 0; - double prevRr2 = i >= 2 ? rrList[i - 2] : 0; - double rs = r5 != 0 ? r4 / r5 : 0; + var r4 = r4List[i]; + var r5 = r5List[i]; + var prevRr1 = i >= 1 ? rrList[i - 1] : 0; + var prevRr2 = i >= 2 ? rrList[i - 2] : 0; + var rs = r5 != 0 ? r4 / r5 : 0; - double rr = r5 == 0 ? 100 : r4 == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rr = r5 == 0 ? 100 : r4 == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rrList.AddRounded(rr); var signal = GetRsiSignal(rr - prevRr1, prevRr1 - prevRr2, rr, prevRr1, 70, 30); @@ -387,37 +387,37 @@ public static StockData CalculateBreakoutRelativeStrengthIndex(this StockData st List signalsList = new(); var (inputList, highList, lowList, openList, closeList, volumeList) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = closeList[i]; - double currentOpen = openList[i]; - double prevBrsi1 = i >= 1 ? brsiList[i - 1] : 0; - double prevBrsi2 = i >= 2 ? brsiList[i - 2] : 0; - - double currentVolume = volumeList[i]; + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = closeList[i]; + var currentOpen = openList[i]; + var prevBrsi1 = i >= 1 ? brsiList[i - 1] : 0; + var prevBrsi2 = i >= 2 ? brsiList[i - 2] : 0; + + var currentVolume = volumeList[i]; tempList.AddRounded(currentVolume); - double boVolume = tempList.TakeLastExt(lbLength).Sum(); - double boStrength = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; + var boVolume = tempList.TakeLastExt(lbLength).Sum(); + var boStrength = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; - double prevBoPower = boPowerList.LastOrDefault(); - double boPower = currentValue * boStrength * boVolume; + var prevBoPower = boPowerList.LastOrDefault(); + var boPower = currentValue * boStrength * boVolume; boPowerList.AddRounded(boPower); - double posPower = boPower > prevBoPower ? Math.Abs(boPower) : 0; + var posPower = boPower > prevBoPower ? Math.Abs(boPower) : 0; posPowerList.AddRounded(posPower); - double negPower = boPower < prevBoPower ? Math.Abs(boPower) : 0; + var negPower = boPower < prevBoPower ? Math.Abs(boPower) : 0; negPowerList.AddRounded(negPower); - double posPowerSum = posPowerList.TakeLastExt(length).Sum(); - double negPowerSum = negPowerList.TakeLastExt(length).Sum(); - double boRatio = negPowerSum != 0 ? posPowerSum / negPowerSum : 0; + var posPowerSum = posPowerList.TakeLastExt(length).Sum(); + var negPowerSum = negPowerList.TakeLastExt(length).Sum(); + var boRatio = negPowerSum != 0 ? posPowerSum / negPowerSum : 0; - double brsi = negPowerSum == 0 ? 100 : posPowerSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + boRatio)), 100, 0); + var brsi = negPowerSum == 0 ? 100 : posPowerSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + boRatio)), 100, 0); brsiList.AddRounded(brsi); var signal = GetRsiSignal(brsi - prevBrsi1, prevBrsi1 - prevBrsi2, brsi, prevBrsi1, 80, 20); @@ -449,30 +449,30 @@ public static StockData CalculateLiquidRelativeStrengthIndex(this StockData stoc List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - double k = (double)1 / length; + var k = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; - double prevVolume = i >= 1 ? volumeList[i - 1] : 0; - double a = MinPastValues(i, 1, currentValue - prevValue); - double b = MinPastValues(i, 1, currentVolume - prevVolume); - double prevC1 = i >= 1 ? cList[i - 1] : 0; - double prevC2 = i >= 2 ? cList[i - 2] : 0; - double num = Math.Max(a, 0) * Math.Max(b, 0); - double den = Math.Abs(a) * Math.Abs(b); - - double prevNumEma = numEmaList.LastOrDefault(); - double numEma = (num * k) + (prevNumEma * (1 - k)); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = volumeList[i]; + var prevVolume = i >= 1 ? volumeList[i - 1] : 0; + var a = MinPastValues(i, 1, currentValue - prevValue); + var b = MinPastValues(i, 1, currentVolume - prevVolume); + var prevC1 = i >= 1 ? cList[i - 1] : 0; + var prevC2 = i >= 2 ? cList[i - 2] : 0; + var num = Math.Max(a, 0) * Math.Max(b, 0); + var den = Math.Abs(a) * Math.Abs(b); + + var prevNumEma = numEmaList.LastOrDefault(); + var numEma = (num * k) + (prevNumEma * (1 - k)); numEmaList.AddRounded(numEma); - double prevDenEma = denEmaList.LastOrDefault(); - double denEma = (den * k) + (prevDenEma * (1 - k)); + var prevDenEma = denEmaList.LastOrDefault(); + var denEma = (den * k) + (prevDenEma * (1 - k)); denEmaList.AddRounded(denEma); - double c = denEma != 0 ? MinOrMax(100 * numEma / denEma, 100, 0) : 0; + var c = denEma != 0 ? MinOrMax(100 * numEma / denEma, 100, 0) : 0; cList.AddRounded(c); var signal = GetRsiSignal(c - prevC1, prevC1 - prevC2, c, prevC1, 80, 20); @@ -506,24 +506,24 @@ public static StockData CalculateFoldedRelativeStrengthIndex(this StockData stoc var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; + var rsi = rsiList[i]; - double absRsi = 2 * Math.Abs(rsi - 50); + var absRsi = 2 * Math.Abs(rsi - 50); absRsiList.AddRounded(absRsi); - double frsi = absRsiList.TakeLastExt(length).Sum(); + var frsi = absRsiList.TakeLastExt(length).Sum(); frsiList.AddRounded(frsi); } var frsiMaList = GetMovingAverageList(stockData, maType, length, frsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double frsi = frsiList[i]; - double frsiMa = frsiMaList[i]; - double prevFrsi = i >= 1 ? frsiList[i - 1] : 0; - double prevFrsiMa = i >= 1 ? frsiMaList[i - 1] : 0; + var frsi = frsiList[i]; + var frsiMa = frsiMaList[i]; + var prevFrsi = i >= 1 ? frsiList[i - 1] : 0; + var prevFrsiMa = i >= 1 ? frsiMaList[i - 1] : 0; var signal = GetRsiSignal(frsi - frsiMa, prevFrsi - prevFrsiMa, frsi, prevFrsi, 50, 10); signalsList.Add(signal); @@ -558,37 +558,37 @@ public static StockData CalculateVolumeWeightedRelativeStrengthIndex(this StockD List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double volume = volumeList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var volume = volumeList[i]; - double max = Math.Max(MinPastValues(i, 1, currentValue - prevValue) * volume, 0); + var max = Math.Max(MinPastValues(i, 1, currentValue - prevValue) * volume, 0); maxList.AddRounded(max); - double min = -Math.Min(MinPastValues(i, 1, currentValue - prevValue) * volume, 0); + var min = -Math.Min(MinPastValues(i, 1, currentValue - prevValue) * volume, 0); minList.AddRounded(min); } var upList = GetMovingAverageList(stockData, maType, length, maxList); var dnList = GetMovingAverageList(stockData, maType, length, minList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double up = upList[i]; - double dn = dnList[i]; - double rsiRaw = dn == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + (up / dn))); + var up = upList[i]; + var dn = dnList[i]; + var rsiRaw = dn == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + (up / dn))); - double rsiScale = (rsiRaw * 2) - 100; + var rsiScale = (rsiRaw * 2) - 100; rsiScaledList.AddRounded(rsiScale); } var rsiList = GetMovingAverageList(stockData, maType, smoothLength, rsiScaledList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; - double prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; + var rsi = rsiList[i]; + var prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; + var prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; var signal = GetCompareSignal(rsi - prevRsi1, prevRsi1 - prevRsi2); signalsList.Add(signal); @@ -621,32 +621,32 @@ public static StockData CalculateRapidRelativeStrengthIndex(this StockData stock List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double chg = MinPastValues(i, 1, currentValue - prevValue); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var chg = MinPastValues(i, 1, currentValue - prevValue); - double upChg = i >= 1 && chg > 0 ? chg : 0; + var upChg = i >= 1 && chg > 0 ? chg : 0; upChgList.AddRounded(upChg); - double downChg = i >= 1 && chg < 0 ? Math.Abs(chg) : 0; + var downChg = i >= 1 && chg < 0 ? Math.Abs(chg) : 0; downChgList.AddRounded(downChg); - double upChgSum = upChgList.TakeLastExt(length).Sum(); - double downChgSum = downChgList.TakeLastExt(length).Sum(); - double rs = downChgSum != 0 ? upChgSum / downChgSum : 0; + var upChgSum = upChgList.TakeLastExt(length).Sum(); + var downChgSum = downChgList.TakeLastExt(length).Sum(); + var rs = downChgSum != 0 ? upChgSum / downChgSum : 0; - double rapidRsi = downChgSum == 0 ? 100 : upChgSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rapidRsi = downChgSum == 0 ? 100 : upChgSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rapidRsiList.AddRounded(rapidRsi); } var rrsiEmaList = GetMovingAverageList(stockData, maType, length, rapidRsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rapidRsi = rrsiEmaList[i]; - double prevRapidRsi1 = i >= 1 ? rrsiEmaList[i - 1] : 0; - double prevRapidRsi2 = i >= 2 ? rrsiEmaList[i - 2] : 0; + var rapidRsi = rrsiEmaList[i]; + var prevRapidRsi1 = i >= 1 ? rrsiEmaList[i - 1] : 0; + var prevRapidRsi2 = i >= 2 ? rrsiEmaList[i - 2] : 0; var signal = GetRsiSignal(rapidRsi - prevRapidRsi1, prevRapidRsi1 - prevRapidRsi2, rapidRsi, prevRapidRsi1, 70, 30); signalsList.Add(signal); @@ -683,41 +683,41 @@ public static StockData CalculateRecursiveRelativeStrengthIndex(this StockData s List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; - double chg = MinPastValues(i, length, currentValue - prevValue); + var chg = MinPastValues(i, length, currentValue - prevValue); chgList.AddRounded(chg); } var srcList = GetMovingAverageList(stockData, maType, length, chgList); stockData.CustomValuesList = srcList; var rsiList = CalculateRelativeStrengthIndex(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double src = srcList[i]; - double prevB1 = i >= 1 ? bList[i - 1] : 0; - double prevB2 = i >= 2 ? bList[i - 2] : 0; + var rsi = rsiList[i]; + var src = srcList[i]; + var prevB1 = i >= 1 ? bList[i - 1] : 0; + var prevB2 = i >= 2 ? bList[i - 2] : 0; double b = 0, avg = 0, gain = 0, loss = 0, avgRsi = 0; - for (int j = 1; j <= length; j++) + for (var j = 1; j <= length; j++) { - double prevB = i >= j ? bList[i - j] : src; - double prevAvg = i >= j ? avgList[i - j] : 0; - double prevGain = i >= j ? gainList[i - j] : 0; - double prevLoss = i >= j ? lossList[i - j] : 0; - double k = (double)j / length; - double a = rsi * ((double)length / j); + var prevB = i >= j ? bList[i - j] : src; + var prevAvg = i >= j ? avgList[i - j] : 0; + var prevGain = i >= j ? gainList[i - j] : 0; + var prevLoss = i >= j ? lossList[i - j] : 0; + var k = (double)j / length; + var a = rsi * ((double)length / j); avg = (a + prevB) / 2; - double avgChg = avg - prevAvg; + var avgChg = avg - prevAvg; gain = avgChg > 0 ? avgChg : 0; loss = avgChg < 0 ? Math.Abs(avgChg) : 0; - double avgGain = (gain * k) + (prevGain * (1 - k)); - double avgLoss = (loss * k) + (prevLoss * (1 - k)); - double rs = avgLoss != 0 ? avgGain / avgLoss : 0; + var avgGain = (gain * k) + (prevGain * (1 - k)); + var avgLoss = (loss * k) + (prevLoss * (1 - k)); + var rs = avgLoss != 0 ? avgGain / avgLoss : 0; avgRsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 1, 0); b = avgRsiList.Count >= length ? avgRsiList.TakeLastExt(length).Average() : avgRsi; } @@ -760,38 +760,38 @@ public static StockData CalculateMomentaRelativeStrengthIndex(this StockData sto var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double hc = highestList[i]; - double lc = lowestList[i]; + var currentValue = inputList[i]; + var hc = highestList[i]; + var lc = lowestList[i]; - double srcLc = currentValue - lc; + var srcLc = currentValue - lc; srcLcList.AddRounded(srcLc); - double hcSrc = hc - currentValue; + var hcSrc = hc - currentValue; hcSrcList.AddRounded(hcSrc); } var topList = GetMovingAverageList(stockData, maType, length2, srcLcList); var botList = GetMovingAverageList(stockData, maType, length2, hcSrcList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double top = topList[i]; - double bot = botList[i]; - double rs = bot != 0 ? MinOrMax(top / bot, 1, 0) : 0; + var top = topList[i]; + var bot = botList[i]; + var rs = bot != 0 ? MinOrMax(top / bot, 1, 0) : 0; - double rsi = bot == 0 ? 100 : top == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rsi = bot == 0 ? 100 : top == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rsiList.AddRounded(rsi); } var rsiEmaList = GetMovingAverageList(stockData, maType, length2, rsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double rsiEma = rsiEmaList[i]; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; + var rsi = rsiList[i]; + var rsiEma = rsiEmaList[i]; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; var signal = GetRsiSignal(rsi - rsiEma, prevRsi - prevRsiEma, rsi, prevRsi, 80, 20); signalsList.Add(signal); @@ -828,16 +828,16 @@ public static StockData CalculateDoubleSmoothedRelativeStrengthIndex(this StockD var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double hc = highestList[i]; - double lc = lowestList[i]; + var currentValue = inputList[i]; + var hc = highestList[i]; + var lc = lowestList[i]; - double srcLc = currentValue - lc; + var srcLc = currentValue - lc; srcLcList.AddRounded(srcLc); - double hcSrc = hc - currentValue; + var hcSrc = hc - currentValue; hcSrcList.AddRounded(hcSrc); } @@ -845,23 +845,23 @@ public static StockData CalculateDoubleSmoothedRelativeStrengthIndex(this StockD var topEma2List = GetMovingAverageList(stockData, maType, length3, topEma1List); var botEma1List = GetMovingAverageList(stockData, maType, length2, hcSrcList); var botEma2List = GetMovingAverageList(stockData, maType, length3, botEma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double top = topEma2List[i]; - double bot = botEma2List[i]; - double rs = bot != 0 ? MinOrMax(top / bot, 1, 0) : 0; + var top = topEma2List[i]; + var bot = botEma2List[i]; + var rs = bot != 0 ? MinOrMax(top / bot, 1, 0) : 0; - double rsi = bot == 0 ? 100 : top == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); + var rsi = bot == 0 ? 100 : top == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); rsiList.AddRounded(rsi); } var rsiEmaList = GetMovingAverageList(stockData, maType, length3, rsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsi = rsiList[i]; - double rsiEma = rsiEmaList[i]; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; + var rsi = rsiList[i]; + var rsiEma = rsiEmaList[i]; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; var signal = GetRsiSignal(rsi - rsiEma, prevRsi - prevRsiEma, rsi, prevRsi, 80, 20); signalsList.Add(signal); @@ -895,27 +895,27 @@ public static StockData CalculateDominantCycleTunedRelativeStrengthIndex(this St var v1List = CalculateEhlersAdaptiveCyberCycle(stockData, length).OutputValues["Period"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double v1 = v1List[i]; - double p = v1 != 0 ? 1 / v1 : 0.07; - double price = inputList[i]; - double prevPrice = i >= 1 ? inputList[i - 1] : 0; - double aChg = price > prevPrice ? Math.Abs(price - prevPrice) : 0; - double bChg = price < prevPrice ? Math.Abs(price - prevPrice) : 0; - double prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; - double prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; - - double prevA = i >= 1 ? aList[i - 1] : aChg; - double a = (p * aChg) + ((1 - p) * prevA); + var v1 = v1List[i]; + var p = v1 != 0 ? 1 / v1 : 0.07; + var price = inputList[i]; + var prevPrice = i >= 1 ? inputList[i - 1] : 0; + var aChg = price > prevPrice ? Math.Abs(price - prevPrice) : 0; + var bChg = price < prevPrice ? Math.Abs(price - prevPrice) : 0; + var prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; + var prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; + + var prevA = i >= 1 ? aList[i - 1] : aChg; + var a = (p * aChg) + ((1 - p) * prevA); aList.AddRounded(a); - double prevB = i >= 1 ? bList[i - 1] : bChg; - double b = (p * bChg) + ((1 - p) * prevB); + var prevB = i >= 1 ? bList[i - 1] : bChg; + var b = (p * bChg) + ((1 - p) * prevB); bList.AddRounded(b); - double r = b != 0 ? a / b : 0; - double rsi = b == 0 ? 100 : a == 0 ? 0 : MinOrMax(100 - (100 / (1 + r)), 100, 0); + var r = b != 0 ? a / b : 0; + var rsi = b == 0 ? 100 : a == 0 ? 0 : MinOrMax(100 - (100 / (1 + r)), 100, 0); rsiList.AddRounded(rsi); var signal = GetRsiSignal(rsi - prevRsi1, prevRsi1 - prevRsi2, rsi, prevRsi1, 70, 30); @@ -954,19 +954,19 @@ public static StockData CalculateSelfAdjustingRelativeStrengthIndex(this StockDa var rsiStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var rsiSmaList = GetMovingAverageList(stockData, maType, smoothingLength, rsiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double rsiStdDev = rsiStdDevList[i]; - double rsi = rsiList[i]; - double prevRsi = i >= 1 ? rsiList[i - 1] : 0; - double adjustingStdDev = mult * rsiStdDev; - double rsiSma = rsiSmaList[i]; - double prevRsiSma = i >= 1 ? rsiSmaList[i - 1] : 0; - - double obStdDev = 50 + adjustingStdDev; + var rsiStdDev = rsiStdDevList[i]; + var rsi = rsiList[i]; + var prevRsi = i >= 1 ? rsiList[i - 1] : 0; + var adjustingStdDev = mult * rsiStdDev; + var rsiSma = rsiSmaList[i]; + var prevRsiSma = i >= 1 ? rsiSmaList[i - 1] : 0; + + var obStdDev = 50 + adjustingStdDev; obList.AddRounded(obStdDev); - double osStdDev = 50 - adjustingStdDev; + var osStdDev = 50 - adjustingStdDev; osList.AddRounded(osStdDev); var signal = GetRsiSignal(rsi - rsiSma, prevRsi - prevRsiSma, rsi, prevRsi, obStdDev, osStdDev); @@ -1009,12 +1009,12 @@ public static StockData CalculateStochasticConnorsRelativeStrengthIndex(this Sto var fastDList = stochasticList.OutputValues["FastD"]; var slowDList = stochasticList.OutputValues["SlowD"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double smaK = fastDList[i]; - double smaD = slowDList[i]; - double prevSmak = i >= 1 ? fastDList[i - 1] : 0; - double prevSmad = i >= 1 ? slowDList[i - 1] : 0; + var smaK = fastDList[i]; + var smaD = slowDList[i]; + var prevSmak = i >= 1 ? fastDList[i - 1] : 0; + var prevSmad = i >= 1 ? slowDList[i - 1] : 0; var signal = GetRsiSignal(smaK - smaD, prevSmak - prevSmad, smaK, prevSmak, 70, 30); signalsList.Add(signal); @@ -1070,63 +1070,63 @@ public static StockData CalculateCCTStochRSI(this StockData stockData, MovingAvg var rsi14List = CalculateRelativeStrengthIndex(stockData, maType, length: length4).CustomValuesList; var rsi21List = CalculateRelativeStrengthIndex(stockData, maType, length: length5).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRSI5 = rsi5List[i]; + var currentRSI5 = rsi5List[i]; tempRsi5List.AddRounded(currentRSI5); - double currentRSI8 = rsi8List[i]; + var currentRSI8 = rsi8List[i]; tempRsi8List.AddRounded(currentRSI8); - double currentRSI13 = rsi13List[i]; + var currentRSI13 = rsi13List[i]; tempRsi13List.AddRounded(currentRSI13); - double currentRSI14 = rsi14List[i]; + var currentRSI14 = rsi14List[i]; tempRsi14List.AddRounded(currentRSI14); - double currentRSI21 = rsi21List[i]; + var currentRSI21 = rsi21List[i]; tempRsi21List.AddRounded(currentRSI21); - double lowestX1 = tempRsi21List.TakeLastExt(length2).Min(); - double lowestZ1 = tempRsi21List.TakeLastExt(length3).Min(); - double highestY1 = tempRsi21List.TakeLastExt(length3).Max(); - double lowestX2 = tempRsi21List.TakeLastExt(length5).Min(); - double lowestZ2 = tempRsi21List.TakeLastExt(length5).Min(); - double highestY2 = tempRsi21List.TakeLastExt(length5).Max(); - double lowestX3 = tempRsi14List.TakeLastExt(length4).Min(); - double lowestZ3 = tempRsi14List.TakeLastExt(length4).Min(); - double highestY3 = tempRsi14List.TakeLastExt(length4).Max(); - double lowestX4 = tempRsi21List.TakeLastExt(length3).Min(); - double lowestZ4 = tempRsi21List.TakeLastExt(length3).Min(); - double highestY4 = tempRsi21List.TakeLastExt(length2).Max(); - double lowestX5 = tempRsi5List.TakeLastExt(length1).Min(); - double lowestZ5 = tempRsi5List.TakeLastExt(length1).Min(); - double highestY5 = tempRsi5List.TakeLastExt(length1).Max(); - double lowestX6 = tempRsi13List.TakeLastExt(length3).Min(); - double lowestZ6 = tempRsi13List.TakeLastExt(length3).Min(); - double highestY6 = tempRsi13List.TakeLastExt(length3).Max(); - double lowestCustom = tempRsi8List.TakeLastExt(length2).Min(); - double highestCustom = tempRsi8List.TakeLastExt(length2).Max(); - - double stochRSI1 = highestY1 - lowestZ1 != 0 ? (currentRSI21 - lowestX1) / (highestY1 - lowestZ1) * 100 : 0; + var lowestX1 = tempRsi21List.TakeLastExt(length2).Min(); + var lowestZ1 = tempRsi21List.TakeLastExt(length3).Min(); + var highestY1 = tempRsi21List.TakeLastExt(length3).Max(); + var lowestX2 = tempRsi21List.TakeLastExt(length5).Min(); + var lowestZ2 = tempRsi21List.TakeLastExt(length5).Min(); + var highestY2 = tempRsi21List.TakeLastExt(length5).Max(); + var lowestX3 = tempRsi14List.TakeLastExt(length4).Min(); + var lowestZ3 = tempRsi14List.TakeLastExt(length4).Min(); + var highestY3 = tempRsi14List.TakeLastExt(length4).Max(); + var lowestX4 = tempRsi21List.TakeLastExt(length3).Min(); + var lowestZ4 = tempRsi21List.TakeLastExt(length3).Min(); + var highestY4 = tempRsi21List.TakeLastExt(length2).Max(); + var lowestX5 = tempRsi5List.TakeLastExt(length1).Min(); + var lowestZ5 = tempRsi5List.TakeLastExt(length1).Min(); + var highestY5 = tempRsi5List.TakeLastExt(length1).Max(); + var lowestX6 = tempRsi13List.TakeLastExt(length3).Min(); + var lowestZ6 = tempRsi13List.TakeLastExt(length3).Min(); + var highestY6 = tempRsi13List.TakeLastExt(length3).Max(); + var lowestCustom = tempRsi8List.TakeLastExt(length2).Min(); + var highestCustom = tempRsi8List.TakeLastExt(length2).Max(); + + var stochRSI1 = highestY1 - lowestZ1 != 0 ? (currentRSI21 - lowestX1) / (highestY1 - lowestZ1) * 100 : 0; type1List.AddRounded(stochRSI1); - double stochRSI2 = highestY2 - lowestZ2 != 0 ? (currentRSI21 - lowestX2) / (highestY2 - lowestZ2) * 100 : 0; + var stochRSI2 = highestY2 - lowestZ2 != 0 ? (currentRSI21 - lowestX2) / (highestY2 - lowestZ2) * 100 : 0; type2List.AddRounded(stochRSI2); - double stochRSI3 = highestY3 - lowestZ3 != 0 ? (currentRSI14 - lowestX3) / (highestY3 - lowestZ3) * 100 : 0; + var stochRSI3 = highestY3 - lowestZ3 != 0 ? (currentRSI14 - lowestX3) / (highestY3 - lowestZ3) * 100 : 0; type3List.AddRounded(stochRSI3); - double stochRSI4 = highestY4 - lowestZ4 != 0 ? (currentRSI21 - lowestX4) / (highestY4 - lowestZ4) * 100 : 0; + var stochRSI4 = highestY4 - lowestZ4 != 0 ? (currentRSI21 - lowestX4) / (highestY4 - lowestZ4) * 100 : 0; type4List.AddRounded(stochRSI4); - double stochRSI5 = highestY5 - lowestZ5 != 0 ? (currentRSI5 - lowestX5) / (highestY5 - lowestZ5) * 100 : 0; + var stochRSI5 = highestY5 - lowestZ5 != 0 ? (currentRSI5 - lowestX5) / (highestY5 - lowestZ5) * 100 : 0; type5List.AddRounded(stochRSI5); - double stochRSI6 = highestY6 - lowestZ6 != 0 ? (currentRSI13 - lowestX6) / (highestY6 - lowestZ6) * 100 : 0; + var stochRSI6 = highestY6 - lowestZ6 != 0 ? (currentRSI13 - lowestX6) / (highestY6 - lowestZ6) * 100 : 0; type6List.AddRounded(stochRSI6); - double stochCustom = highestCustom - lowestCustom != 0 ? (currentRSI8 - lowestCustom) / (highestCustom - lowestCustom) * 100 : 0; + var stochCustom = highestCustom - lowestCustom != 0 ? (currentRSI8 - lowestCustom) / (highestCustom - lowestCustom) * 100 : 0; typeCustomList.AddRounded(stochCustom); } @@ -1135,7 +1135,7 @@ public static StockData CalculateCCTStochRSI(this StockData stockData, MovingAvg var rsiEma6List = GetMovingAverageList(stockData, maType, smoothLength1, type6List); var rsiEmaCustomList = GetMovingAverageList(stockData, maType, smoothLength1, typeCustomList); var rsiSignalList = GetMovingAverageList(stockData, maType, signalLength, type1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var rsi = type1List[i]; var prevRsi = i >= 1 ? type1List[i - 1] : 0; @@ -1184,12 +1184,12 @@ public static StockData CalculateStochasticRelativeStrengthIndex(this StockData var stochRsiList = stoRsiList.OutputValues["FastD"]; var stochRsiSignalList = stoRsiList.OutputValues["SlowD"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentRSI = stochRsiList[i]; - double prevStochRsi = i >= 1 ? stochRsiList[i - 1] : 0; - double currentRsiSignal = stochRsiSignalList[i]; - double prevRsiSignal = i >= 1 ? stochRsiSignalList[i - 1] : 0; + var currentRSI = stochRsiList[i]; + var prevStochRsi = i >= 1 ? stochRsiList[i - 1] : 0; + var currentRsiSignal = stochRsiSignalList[i]; + var prevRsiSignal = i >= 1 ? stochRsiSignalList[i - 1] : 0; var signal = GetRsiSignal(currentRSI - currentRsiSignal, prevStochRsi - prevRsiSignal, currentRSI, prevStochRsi, 80, 20); signalsList.Add(signal); diff --git a/src/Calculations/Stochastic.cs b/src/Calculations/Stochastic.cs index e624089..079d98e 100644 --- a/src/Calculations/Stochastic.cs +++ b/src/Calculations/Stochastic.cs @@ -29,24 +29,24 @@ public static StockData CalculateStochasticOscillator(this StockData stockData, var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; + var currentValue = inputList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; - double fastK = highestHigh - lowestLow != 0 ? MinOrMax((currentValue - lowestLow) / (highestHigh - lowestLow) * 100, 100, 0) : 0; + var fastK = highestHigh - lowestLow != 0 ? MinOrMax((currentValue - lowestLow) / (highestHigh - lowestLow) * 100, 100, 0) : 0; fastKList.AddRounded(fastK); } var fastDList = GetMovingAverageList(stockData, maType, smoothLength1, fastKList); var slowDList = GetMovingAverageList(stockData, maType, smoothLength2, fastDList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double slowK = fastDList[i]; - double slowD = slowDList[i]; - double prevSlowk = i >= 1 ? fastDList[i - 1] : 0; - double prevSlowd = i >= 1 ? slowDList[i - 1] : 0; + var slowK = fastDList[i]; + var slowD = slowDList[i]; + var prevSlowk = i >= 1 ? fastDList[i - 1] : 0; + var prevSlowd = i >= 1 ? slowDList[i - 1] : 0; var signal = GetRsiSignal(slowK - slowD, prevSlowk - prevSlowd, slowK, prevSlowk, 80, 20); signalsList.Add(signal); @@ -83,20 +83,20 @@ public static StockData CalculateAdaptiveStochastic(this StockData stockData, in var (highest1List, lowest1List) = GetMaxAndMinValuesList(srcList, fastLength); var (highest2List, lowest2List) = GetMaxAndMinValuesList(srcList, slowLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double er = erList[i]; - double src = srcList[i]; - double highest1 = highest1List[i]; - double lowest1 = lowest1List[i]; - double highest2 = highest2List[i]; - double lowest2 = lowest2List[i]; - double prevStc1 = i >= 1 ? stcList[i - 1] : 0; - double prevStc2 = i >= 2 ? stcList[i - 2] : 0; - double a = (er * highest1) + ((1 - er) * highest2); - double b = (er * lowest1) + ((1 - er) * lowest2); - - double stc = a - b != 0 ? MinOrMax((src - b) / (a - b), 1, 0) : 0; + var er = erList[i]; + var src = srcList[i]; + var highest1 = highest1List[i]; + var lowest1 = lowest1List[i]; + var highest2 = highest2List[i]; + var lowest2 = lowest2List[i]; + var prevStc1 = i >= 1 ? stcList[i - 1] : 0; + var prevStc2 = i >= 2 ? stcList[i - 2] : 0; + var a = (er * highest1) + ((1 - er) * highest2); + var b = (er * lowest1) + ((1 - er) * lowest2); + + var stc = a - b != 0 ? MinOrMax((src - b) / (a - b), 1, 0) : 0; stcList.AddRounded(stc); var signal = GetRsiSignal(stc - prevStc1, prevStc1 - prevStc2, stc, prevStc1, 0.8, 0.2); @@ -135,39 +135,39 @@ public static StockData CalculateBilateralStochasticOscillator(this StockData st var smaList = GetMovingAverageList(stockData, maType, length, inputList); var (highestList, lowestList) = GetMaxAndMinValuesList(smaList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; - double range = highest - lowest; + var range = highest - lowest; rangeList.AddRounded(range); } var rangeSmaList = GetMovingAverageList(stockData, maType, length, rangeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sma = smaList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double rangeSma = rangeSmaList[i]; + var sma = smaList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var rangeSma = rangeSmaList[i]; - double bull = rangeSma != 0 ? (sma / rangeSma) - (lowest / rangeSma) : 0; + var bull = rangeSma != 0 ? (sma / rangeSma) - (lowest / rangeSma) : 0; bullList.AddRounded(bull); - double bear = rangeSma != 0 ? Math.Abs((sma / rangeSma) - (highest / rangeSma)) : 0; + var bear = rangeSma != 0 ? Math.Abs((sma / rangeSma) - (highest / rangeSma)) : 0; bearList.AddRounded(bear); - double max = Math.Max(bull, bear); + var max = Math.Max(bull, bear); maxList.AddRounded(max); } var signalList = GetMovingAverageList(stockData, maType, signalLength, maxList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double bull = bullList[i]; - double bear = bearList[i]; - double sig = signalList[i]; + var bull = bullList[i]; + var bear = bearList[i]; + var sig = signalList[i]; var signal = GetConditionSignal(bull > bear || bull > sig, bear > bull || bull < sig); signalsList.Add(signal); @@ -203,31 +203,31 @@ public static StockData CalculateNaturalStochasticIndicator(this StockData stock var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { double weightSum = 0, denomSum = 0; - for (int j = 0; j < length; j++) + for (var j = 0; j < length; j++) { - double hh = i >= j ? highestList[i - j] : 0; - double ll = i >= j ? lowestList[i - j] : 0; - double c = i >= j ? inputList[i - j] : 0; - double range = hh - ll; - double frac = range != 0 ? (c - ll) / range : 0; - double ratio = 1 / Sqrt(j + 1); + var hh = i >= j ? highestList[i - j] : 0; + var ll = i >= j ? lowestList[i - j] : 0; + var c = i >= j ? inputList[i - j] : 0; + var range = hh - ll; + var frac = range != 0 ? (c - ll) / range : 0; + var ratio = 1 / Sqrt(j + 1); weightSum += frac * ratio; denomSum += ratio; } - double rawNst = denomSum != 0 ? (200 * weightSum / denomSum) - 100 : 0; + var rawNst = denomSum != 0 ? (200 * weightSum / denomSum) - 100 : 0; rawNstList.AddRounded(rawNst); } var nstList = GetMovingAverageList(stockData, maType, smoothLength, rawNstList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nst = nstList[i]; - double prevNst1 = i >= 1 ? nstList[i - 1] : 0; - double prevNst2 = i >= 2 ? nstList[i - 2] : 0; + var nst = nstList[i]; + var prevNst1 = i >= 1 ? nstList[i - 1] : 0; + var prevNst2 = i >= 2 ? nstList[i - 2] : 0; var signal = GetCompareSignal(nst - prevNst1, prevNst1 - prevNst2); signalsList.Add(signal); @@ -274,44 +274,44 @@ public static StockData CalculateFisherTransformStochasticOscillator(this StockD var wma9List = GetMovingAverageList(stockData, maType, length, wma8List); var wma10List = GetMovingAverageList(stockData, maType, length, wma9List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double wma1 = wmaList[i]; - double wma2 = wma2List[i]; - double wma3 = wma3List[i]; - double wma4 = wma4List[i]; - double wma5 = wma5List[i]; - double wma6 = wma6List[i]; - double wma7 = wma7List[i]; - double wma8 = wma8List[i]; - double wma9 = wma9List[i]; - double wma10 = wma10List[i]; - - double rbw = ((wma1 * 5) + (wma2 * 4) + (wma3 * 3) + (wma4 * 2) + wma5 + wma6 + wma7 + wma8 + wma9 + wma10) / 20; + var wma1 = wmaList[i]; + var wma2 = wma2List[i]; + var wma3 = wma3List[i]; + var wma4 = wma4List[i]; + var wma5 = wma5List[i]; + var wma6 = wma6List[i]; + var wma7 = wma7List[i]; + var wma8 = wma8List[i]; + var wma9 = wma9List[i]; + var wma10 = wma10List[i]; + + var rbw = ((wma1 * 5) + (wma2 * 4) + (wma3 * 3) + (wma4 * 2) + wma5 + wma6 + wma7 + wma8 + wma9 + wma10) / 20; rbwList.AddRounded(rbw); } var (highestList, lowestList) = GetMaxAndMinValuesList(rbwList, stochLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double rbw = rbwList[i]; - double prevFtso1 = i >= 1 ? ftsoList[i - 1] : 0; - double prevFtso2 = i >= 2 ? ftsoList[i - 2] : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var rbw = rbwList[i]; + var prevFtso1 = i >= 1 ? ftsoList[i - 1] : 0; + var prevFtso2 = i >= 2 ? ftsoList[i - 2] : 0; - double num = rbw - lowest; + var num = rbw - lowest; numList.AddRounded(num); - double denom = highest - lowest; + var denom = highest - lowest; denomList.AddRounded(denom); - double numSum = numList.TakeLastExt(smoothLength).Sum(); - double denomSum = denomList.TakeLastExt(smoothLength).Sum(); - double rbws = denomSum + 0.0001 != 0 ? MinOrMax(numSum / (denomSum + 0.0001) * 100, 100, 0) : 0; - double x = 0.1 * (rbws - 50); + var numSum = numList.TakeLastExt(smoothLength).Sum(); + var denomSum = denomList.TakeLastExt(smoothLength).Sum(); + var rbws = denomSum + 0.0001 != 0 ? MinOrMax(numSum / (denomSum + 0.0001) * 100, 100, 0) : 0; + var x = 0.1 * (rbws - 50); - double ftso = MinOrMax((((Exp(2 * x) - 1) / (Exp(2 * x) + 1)) + 1) * 50, 100, 0); + var ftso = MinOrMax((((Exp(2 * x) - 1) / (Exp(2 * x) + 1)) + 1) * 50, 100, 0); ftsoList.AddRounded(ftso); var signal = GetRsiSignal(ftso - prevFtso1, prevFtso1 - prevFtso2, ftso, prevFtso1, 70, 30); @@ -350,22 +350,22 @@ public static StockData CalculateFastandSlowStochasticOscillator(this StockData var fastKList = CalculateStochasticOscillator(stockData, maType, length: length3).CustomValuesList; var slowKList = GetMovingAverageList(stockData, maType, length3, fastKList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double v4 = v4List[i]; - double slowK = slowKList[i]; + var v4 = v4List[i]; + var slowK = slowKList[i]; - double fsst = (500 * v4) + slowK; + var fsst = (500 * v4) + slowK; fsstList.AddRounded(fsst); } var wfsstList = GetMovingAverageList(stockData, maType, length4, fsstList); - for (int i = 0; i < wfsstList.Count; i++) + for (var i = 0; i < wfsstList.Count; i++) { - double fsst = fsstList[i]; - double wfsst = wfsstList[i]; - double prevFsst = i >= 1 ? fsstList[i - 1] : 0; - double prevWfsst = i >= 1 ? wfsstList[i - 1] : 0; + var fsst = fsstList[i]; + var wfsst = wfsstList[i]; + var prevFsst = i >= 1 ? fsstList[i - 1] : 0; + var prevWfsst = i >= 1 ? wfsstList[i - 1] : 0; var signal = GetCompareSignal(fsst - wfsst, prevFsst - prevWfsst); signalsList.Add(signal); @@ -398,28 +398,28 @@ public static StockData CalculatePremierStochasticOscillator(this StockData stoc List psoList = new(); List signalsList = new(); - int len = MinOrMax((int)Math.Ceiling(Sqrt(smoothLength))); + var len = MinOrMax((int)Math.Ceiling(Sqrt(smoothLength))); var stochasticRsiList = CalculateStochasticOscillator(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sk = stochasticRsiList[i]; + var sk = stochasticRsiList[i]; - double nsk = 0.1 * (sk - 50); + var nsk = 0.1 * (sk - 50); nskList.AddRounded(nsk); } var nskEmaList = GetMovingAverageList(stockData, maType, len, nskList); var ssList = GetMovingAverageList(stockData, maType, len, nskEmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ss = ssList[i]; - double prevPso1 = i >= 1 ? psoList[i - 1] : 0; - double prevPso2 = i >= 2 ? psoList[i - 2] : 0; - double expss = Exp(ss); + var ss = ssList[i]; + var prevPso1 = i >= 1 ? psoList[i - 1] : 0; + var prevPso2 = i >= 2 ? psoList[i - 2] : 0; + var expss = Exp(ss); - double pso = expss + 1 != 0 ? MinOrMax((expss - 1) / (expss + 1), 1, -1) : 0; + var pso = expss + 1 != 0 ? MinOrMax((expss - 1) / (expss + 1), 1, -1) : 0; psoList.AddRounded(pso); var signal = GetRsiSignal(pso - prevPso1, prevPso1 - prevPso2, pso, prevPso1, 0.9, -0.9); @@ -451,7 +451,7 @@ public static StockData CalculateTurboStochasticsFast(this StockData stockData, { List signalsList = new(); - int turbo = turboLength < 0 ? Math.Max(turboLength, length2 * -1) : turboLength > 0 ? Math.Min(turboLength, length2) : 0; + var turbo = turboLength < 0 ? Math.Max(turboLength, length2 * -1) : turboLength > 0 ? Math.Min(turboLength, length2) : 0; var fastKList = CalculateStochasticOscillator(stockData, maType, length: length1).CustomValuesList; var fastDList = GetMovingAverageList(stockData, maType, length1, fastKList); @@ -460,12 +460,12 @@ public static StockData CalculateTurboStochasticsFast(this StockData stockData, stockData.CustomValuesList = fastDList; var tsfDList = CalculateLinearRegression(stockData, length2 + turbo).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tsfD = tsfDList[i]; - double tsfK = tsfKList[i]; - double prevTsfk = i >= 1 ? tsfKList[i - 1] : 0; - double prevTsfd = i >= 1 ? tsfDList[i - 1] : 0; + var tsfD = tsfDList[i]; + var tsfK = tsfKList[i]; + var prevTsfk = i >= 1 ? tsfKList[i - 1] : 0; + var prevTsfd = i >= 1 ? tsfDList[i - 1] : 0; var signal = GetRsiSignal(tsfK - tsfD, prevTsfk - prevTsfd, tsfK, prevTsfk, 70, 30); signalsList.Add(signal); @@ -499,7 +499,7 @@ public static StockData CalculateTurboStochasticsSlow(this StockData stockData, List tssKList = new(); List signalsList = new(); - int turbo = turboLength < 0 ? Math.Max(turboLength, length2 * -1) : turboLength > 0 ? Math.Min(turboLength, length2) : 0; + var turbo = turboLength < 0 ? Math.Max(turboLength, length2 * -1) : turboLength > 0 ? Math.Min(turboLength, length2) : 0; var fastKList = CalculateStochasticOscillator(stockData, maType, length: length1).CustomValuesList; var slowKList = GetMovingAverageList(stockData, maType, length1, fastKList); @@ -509,12 +509,12 @@ public static StockData CalculateTurboStochasticsSlow(this StockData stockData, stockData.CustomValuesList = slowDList; var tsfDList = CalculateLinearRegression(stockData, length2 + turbo).CustomValuesList; - for (int i = 0; i < tssDList.Count; i++) + for (var i = 0; i < tssDList.Count; i++) { - double tssD = tssDList[i]; - double tssK = tssKList[i]; - double prevTssk = i >= 1 ? tssKList[i - 1] : 0; - double prevTssd = i >= 1 ? tssDList[i - 1] : 0; + var tssD = tssDList[i]; + var tssK = tssKList[i]; + var prevTssk = i >= 1 ? tssKList[i - 1] : 0; + var prevTssd = i >= 1 ? tssDList[i - 1] : 0; var signal = GetRsiSignal(tssK - tssD, prevTssk - prevTssd, tssK, prevTssk, 70, 30); signalsList.Add(signal); @@ -547,23 +547,23 @@ public static StockData CalculateRecursiveStochastic(this StockData stockData, i var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double stoch = highest - lowest != 0 ? (currentValue - lowest) / (highest - lowest) * 100 : 0; - double prevK1 = i >= 1 ? kList[i - 1] : 0; - double prevK2 = i >= 2 ? kList[i - 2] : 0; - - double ma = (alpha * stoch) + ((1 - alpha) * prevK1); + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var stoch = highest - lowest != 0 ? (currentValue - lowest) / (highest - lowest) * 100 : 0; + var prevK1 = i >= 1 ? kList[i - 1] : 0; + var prevK2 = i >= 2 ? kList[i - 2] : 0; + + var ma = (alpha * stoch) + ((1 - alpha) * prevK1); maList.AddRounded(ma); var lbList = maList.TakeLastExt(length).ToList(); - double highestMa = lbList.Max(); - double lowestMa = lbList.Min(); + var highestMa = lbList.Max(); + var lowestMa = lbList.Min(); - double k = highestMa - lowestMa != 0 ? MinOrMax((ma - lowestMa) / (highestMa - lowestMa) * 100, 100, 0) : 0; + var k = highestMa - lowestMa != 0 ? MinOrMax((ma - lowestMa) / (highestMa - lowestMa) * 100, 100, 0) : 0; kList.AddRounded(k); var signal = GetRsiSignal(k - prevK1, prevK1 - prevK2, k, prevK1, 80, 20); @@ -597,19 +597,19 @@ public static StockData CalculateDiNapoliPreferredStochasticOscillator(this Stoc var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double max = highestList[i]; - double min = lowestList[i]; - double fast = max - min != 0 ? MinOrMax((currentValue - min) / (max - min) * 100, 100, 0) : 0; + var currentValue = inputList[i]; + var max = highestList[i]; + var min = lowestList[i]; + var fast = max - min != 0 ? MinOrMax((currentValue - min) / (max - min) * 100, 100, 0) : 0; - double prevR = rList.LastOrDefault(); - double r = prevR + ((fast - prevR) / length2); + var prevR = rList.LastOrDefault(); + var r = prevR + ((fast - prevR) / length2); rList.AddRounded(r); - double prevS = sList.LastOrDefault(); - double s = prevS + ((r - prevS) / length3); + var prevS = sList.LastOrDefault(); + var s = prevS + ((r - prevS) / length3); sList.AddRounded(s); var signal = GetRsiSignal(r - s, prevR - prevS, r, prevR, 70, 30); @@ -648,16 +648,16 @@ public static StockData CalculateDoubleSmoothedStochastic(this StockData stockDa var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; + var currentValue = inputList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; - double num = currentValue - lowestLow; + var num = currentValue - lowestLow; numList.AddRounded(num); - double denom = highestHigh - lowestLow; + var denom = highestHigh - lowestLow; denomList.AddRounded(denom); } @@ -665,22 +665,22 @@ public static StockData CalculateDoubleSmoothedStochastic(this StockData stockDa var ssDenomList = GetMovingAverageList(stockData, maType, length2, denomList); var dsNumList = GetMovingAverageList(stockData, maType, length3, ssNumList); var dsDenomList = GetMovingAverageList(stockData, maType, length3, ssDenomList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dsNum = dsNumList[i]; - double dsDenom = dsDenomList[i]; + var dsNum = dsNumList[i]; + var dsDenom = dsDenomList[i]; - double dss = dsDenom != 0 ? MinOrMax(100 * dsNum / dsDenom, 100, 0) : 0; + var dss = dsDenom != 0 ? MinOrMax(100 * dsNum / dsDenom, 100, 0) : 0; dssList.AddRounded(dss); } var sdssList = GetMovingAverageList(stockData, maType, length4, dssList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dss = dssList[i]; - double sdss = sdssList[i]; - double prevDss = i >= 1 ? dssList[i - 1] : 0; - double prevSdss = i >= 1 ? sdssList[i - 1] : 0; + var dss = dssList[i]; + var sdss = sdssList[i]; + var prevDss = i >= 1 ? dssList[i - 1] : 0; + var prevSdss = i >= 1 ? sdssList[i - 1] : 0; var signal = GetRsiSignal(dss - sdss, prevDss - prevSdss, dss, prevDss, 70, 30); signalsList.Add(signal); @@ -715,24 +715,24 @@ public static StockData CalculateDoubleStochasticOscillator(this StockData stock var stochasticList = CalculateStochasticOscillator(stockData, maType, length: length).CustomValuesList; var (highestList, lowestList) = GetMaxAndMinValuesList(stochasticList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double slowK = stochasticList[i]; - double highestSlowK = highestList[i]; - double lowestSlowK = lowestList[i]; + var slowK = stochasticList[i]; + var highestSlowK = highestList[i]; + var lowestSlowK = lowestList[i]; - double doubleK = highestSlowK - lowestSlowK != 0 ? MinOrMax((slowK - lowestSlowK) / (highestSlowK - lowestSlowK) * 100, 100, 0) : 0; + var doubleK = highestSlowK - lowestSlowK != 0 ? MinOrMax((slowK - lowestSlowK) / (highestSlowK - lowestSlowK) * 100, 100, 0) : 0; doubleKList.AddRounded(doubleK); } var doubleSlowKList = GetMovingAverageList(stockData, maType, smoothLength, doubleKList); var doubleKSignalList = GetMovingAverageList(stockData, maType, smoothLength, doubleSlowKList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double doubleSlowK = doubleSlowKList[i]; - double doubleKSignal = doubleKSignalList[i]; - double prevDoubleslowk = i >= 1 ? doubleSlowKList[i - 1] : 0; - double prevDoubleKSignal = i >= 1 ? doubleKSignalList[i - 1] : 0; + var doubleSlowK = doubleSlowKList[i]; + var doubleKSignal = doubleKSignalList[i]; + var prevDoubleslowk = i >= 1 ? doubleSlowKList[i - 1] : 0; + var prevDoubleKSignal = i >= 1 ? doubleKSignalList[i - 1] : 0; var signal = GetRsiSignal(doubleSlowK - doubleKSignal, prevDoubleslowk - prevDoubleKSignal, doubleSlowK, prevDoubleslowk, 80, 20); signalsList.Add(signal); @@ -771,33 +771,33 @@ public static StockData CalculateDMIStochastic(this StockData stockData, MovingA var diPlusList = adxList.OutputValues["DiPlus"]; var diMinusList = adxList.OutputValues["DiMinus"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pdi = diPlusList[i]; - double ndi = diMinusList[i]; + var pdi = diPlusList[i]; + var ndi = diMinusList[i]; - double dmiOscillator = ndi - pdi; + var dmiOscillator = ndi - pdi; dmiOscillatorList.AddRounded(dmiOscillator); } var (highestList, lowestList) = GetMaxAndMinValuesList(dmiOscillatorList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double dmiOscillator = dmiOscillatorList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var dmiOscillator = dmiOscillatorList[i]; - double fastK = highest - lowest != 0 ? MinOrMax((dmiOscillator - lowest) / (highest - lowest) * 100, 100, 0) : 0; + var fastK = highest - lowest != 0 ? MinOrMax((dmiOscillator - lowest) / (highest - lowest) * 100, 100, 0) : 0; fastKList.AddRounded(fastK); } var slowKList = GetMovingAverageList(stockData, maType, length3, fastKList); var dmiStochList = GetMovingAverageList(stockData, maType, length4, slowKList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dmiStoch = dmiStochList[i]; - double prevDmiStoch1 = i >= 1 ? dmiStochList[i - 1] : 0; - double prevDmiStoch2 = i >= 2 ? dmiStochList[i - 2] : 0; + var dmiStoch = dmiStochList[i]; + var prevDmiStoch1 = i >= 1 ? dmiStochList[i - 1] : 0; + var prevDmiStoch2 = i >= 2 ? dmiStochList[i - 2] : 0; var signal = GetRsiSignal(dmiStoch - prevDmiStoch1, prevDmiStoch1 - prevDmiStoch2, dmiStoch, prevDmiStoch1, 90, 10); signalsList.Add(signal); @@ -834,17 +834,17 @@ public static StockData CalculateStochasticMomentumIndex(this StockData stockDat var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double median = (highestHigh + lowestLow) / 2; + var currentValue = inputList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var median = (highestHigh + lowestLow) / 2; - double diff = currentValue - median; + var diff = currentValue - median; dList.AddRounded(diff); - double highLow = highestHigh - lowestLow; + var highLow = highestHigh - lowestLow; hlList.AddRounded(highLow); } @@ -852,23 +852,23 @@ public static StockData CalculateStochasticMomentumIndex(this StockData stockDat var hlEmaList = GetMovingAverageList(stockData, maType, length2, hlList); var dSmoothEmaList = GetMovingAverageList(stockData, maType, smoothLength1, dEmaList); var hlSmoothEmaList = GetMovingAverageList(stockData, maType, smoothLength1, hlEmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double hlSmoothEma = hlSmoothEmaList[i]; - double dSmoothEma = dSmoothEmaList[i]; - double hl2 = hlSmoothEma / 2; + var hlSmoothEma = hlSmoothEmaList[i]; + var dSmoothEma = dSmoothEmaList[i]; + var hl2 = hlSmoothEma / 2; - double smi = hl2 != 0 ? MinOrMax(100 * dSmoothEma / hl2, 100, -100) : 0; + var smi = hl2 != 0 ? MinOrMax(100 * dSmoothEma / hl2, 100, -100) : 0; smiList.AddRounded(smi); } var smiSignalList = GetMovingAverageList(stockData, maType, smoothLength2, smiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double smi = smiList[i]; - double smiSignal = smiSignalList[i]; - double prevSmi = i >= 1 ? smiList[i - 1] : 0; - double prevSmiSignal = i >= 1 ? smiSignalList[i - 1] : 0; + var smi = smiList[i]; + var smiSignal = smiSignalList[i]; + var prevSmi = i >= 1 ? smiList[i - 1] : 0; + var prevSmiSignal = i >= 1 ? smiSignalList[i - 1] : 0; var signal = GetCompareSignal(smi - smiSignal, prevSmi - prevSmiSignal); signalsList.Add(signal); @@ -904,12 +904,12 @@ public static StockData CalculateStochasticFastOscillator(this StockData stockDa var pkList = fastKList.OutputValues["FastD"]; var pdList = fastKList.OutputValues["SlowD"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pkEma = pkList[i]; - double pdEma = pdList[i]; - double prevPkema = i >= 1 ? pkList[i - 1] : 0; - double prevPdema = i >= 1 ? pdList[i - 1] : 0; + var pkEma = pkList[i]; + var pdEma = pdList[i]; + var prevPkema = i >= 1 ? pkList[i - 1] : 0; + var prevPdema = i >= 1 ? pdList[i - 1] : 0; var signal = GetRsiSignal(pkEma - pdEma, prevPkema - prevPdema, pkEma, prevPkema, 80, 20); signalsList.Add(signal); @@ -946,37 +946,37 @@ public static StockData CalculateStochasticCustomOscillator(this StockData stock var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; + var currentValue = inputList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; - double num = currentValue - lowestLow; + var num = currentValue - lowestLow; numList.AddRounded(num); - double denom = highestHigh - lowestLow; + var denom = highestHigh - lowestLow; denomList.AddRounded(denom); } var numSmaList = GetMovingAverageList(stockData, maType, length2, numList); var denomSmaList = GetMovingAverageList(stockData, maType, length2, denomList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double numSma = numSmaList[i]; - double denomSma = denomSmaList[i]; + var numSma = numSmaList[i]; + var denomSma = denomSmaList[i]; - double sck = denomSma != 0 ? MinOrMax(numSma / denomSma * 100, 100, 0) : 0; + var sck = denomSma != 0 ? MinOrMax(numSma / denomSma * 100, 100, 0) : 0; sckList.AddRounded(sck); } var scdList = GetMovingAverageList(stockData, maType, length3, sckList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double sck = sckList[i]; - double scd = scdList[i]; - double prevSck = i >= 1 ? sckList[i - 1] : 0; - double prevScd = i >= 1 ? scdList[i - 1] : 0; + var sck = sckList[i]; + var scd = scdList[i]; + var prevSck = i >= 1 ? sckList[i - 1] : 0; + var prevScd = i >= 1 ? scdList[i - 1] : 0; var signal = GetRsiSignal(sck - scd, prevSck - prevScd, sck, prevSck, 70, 30); signalsList.Add(signal); @@ -1011,12 +1011,12 @@ public static StockData CalculateStochasticRegular(this StockData stockData, Mov var fastKList = stoList.CustomValuesList; var skList = stoList.OutputValues["FastD"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fk = fastKList[i]; - double sk = skList[i]; - double prevFk = i >= 1 ? fastKList[i - 1] : 0; - double prevSk = i >= 1 ? skList[i - 1] : 0; + var fk = fastKList[i]; + var sk = skList[i]; + var prevFk = i >= 1 ? fastKList[i - 1] : 0; + var prevSk = i >= 1 ? skList[i - 1] : 0; var signal = GetRsiSignal(fk - sk, prevFk - prevSk, fk, prevFk, 70, 30); signalsList.Add(signal); @@ -1050,23 +1050,23 @@ public static StockData CalculateSwamiStochastics(this StockData stockData, int var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, slowLength - fastLength); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevStoch1 = i >= 1 ? stochList[i - 1] : 0; - double prevStoch2 = i >= 2 ? stochList[i - 2] : 0; - - double pNum = numList.LastOrDefault(); - double num = (currentValue - lowest + pNum) / 2; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevStoch1 = i >= 1 ? stochList[i - 1] : 0; + var prevStoch2 = i >= 2 ? stochList[i - 2] : 0; + + var pNum = numList.LastOrDefault(); + var num = (currentValue - lowest + pNum) / 2; numList.AddRounded(num); - double pDenom = denomList.LastOrDefault(); - double denom = (highest - lowest + pDenom) / 2; + var pDenom = denomList.LastOrDefault(); + var denom = (highest - lowest + pDenom) / 2; denomList.AddRounded(denom); - double stoch = denom != 0 ? MinOrMax((0.2 * num / denom) + (0.8 * prevStoch1), 1, 0) : 0; + var stoch = denom != 0 ? MinOrMax((0.2 * num / denom) + (0.8 * prevStoch1), 1, 0) : 0; stochList.AddRounded(stoch); var signal = GetRsiSignal(stoch - prevStoch1, prevStoch1 - prevStoch2, stoch, prevStoch1, 0.8, 0.2); diff --git a/src/Calculations/TrailingStop.cs b/src/Calculations/TrailingStop.cs index 38f3154..f29ba27 100644 --- a/src/Calculations/TrailingStop.cs +++ b/src/Calculations/TrailingStop.cs @@ -32,34 +32,34 @@ public static StockData CalculateAdaptiveTrailingStop(this StockData stockData, var perList = CalculatePoweredKaufmanAdaptiveMovingAverage(stockData, length, factor).OutputValues["Per"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double per = perList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var per = perList[i]; - double prevA = i >= 1 ? aList.LastOrDefault() : currentValue; - double a = Math.Max(currentValue, prevA) - (Math.Abs(currentValue - prevA) * per); + var prevA = i >= 1 ? aList.LastOrDefault() : currentValue; + var a = Math.Max(currentValue, prevA) - (Math.Abs(currentValue - prevA) * per); aList.AddRounded(a); - double prevB = i >= 1 ? bList.LastOrDefault() : currentValue; - double b = Math.Min(currentValue, prevB) + (Math.Abs(currentValue - prevB) * per); + var prevB = i >= 1 ? bList.LastOrDefault() : currentValue; + var b = Math.Min(currentValue, prevB) + (Math.Abs(currentValue - prevB) * per); bList.AddRounded(b); - double prevUp = upList.LastOrDefault(); - double up = a > prevA ? a : a < prevA && b < prevB ? a : prevUp; + var prevUp = upList.LastOrDefault(); + var up = a > prevA ? a : a < prevA && b < prevB ? a : prevUp; upList.AddRounded(up); - double prevDn = dnList.LastOrDefault(); - double dn = b < prevB ? b : b > prevB && a > prevA ? b : prevDn; + var prevDn = dnList.LastOrDefault(); + var dn = b < prevB ? b : b > prevB && a > prevA ? b : prevDn; dnList.AddRounded(dn); - double prevOs = osList.LastOrDefault(); - double os = up > currentValue ? 1 : dn > currentValue ? 0 : prevOs; + var prevOs = osList.LastOrDefault(); + var os = up > currentValue ? 1 : dn > currentValue ? 0 : prevOs; osList.AddRounded(os); - double prevTs = tsList.LastOrDefault(); - double ts = (os * dn) + ((1 - os) * up); + var prevTs = tsList.LastOrDefault(); + var ts = (os * dn) + ((1 - os) * up); tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); @@ -97,27 +97,27 @@ public static StockData CalculateAdaptiveAutonomousRecursiveTrailingStop(this St var ma2List = aamaList.CustomValuesList; var dList = aamaList.OutputValues["D"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ma2 = ma2List[i]; - double d = dList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ma2 = ma2List[i]; + var d = dList[i]; - double prevUpper = upperList.LastOrDefault(); - double upper = ma2 + d; + var prevUpper = upperList.LastOrDefault(); + var upper = ma2 + d; upperList.AddRounded(upper); - double prevLower = lowerList.LastOrDefault(); - double lower = ma2 - d; + var prevLower = lowerList.LastOrDefault(); + var lower = ma2 - d; lowerList.AddRounded(lower); - double prevOs = osList.LastOrDefault(); - double os = currentValue > prevUpper ? 1 : currentValue < prevLower ? 0 : prevOs; + var prevOs = osList.LastOrDefault(); + var os = currentValue > prevUpper ? 1 : currentValue < prevLower ? 0 : prevOs; osList.AddRounded(os); - double prevTs = tsList.LastOrDefault(); - double ts = (os * lower) + ((1 - os) * upper); + var prevTs = tsList.LastOrDefault(); + var ts = (os * lower) + ((1 - os) * upper); tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); @@ -150,16 +150,16 @@ public static StockData CalculateParabolicSAR(this StockData stockData, double s List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh1 = i >= 1 ? highList[i - 1] : 0; - double prevLow1 = i >= 1 ? lowList[i - 1] : 0; - double prevHigh2 = i >= 2 ? highList[i - 2] : 0; - double prevLow2 = i >= 2 ? lowList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh1 = i >= 1 ? highList[i - 1] : 0; + var prevLow1 = i >= 1 ? lowList[i - 1] : 0; + var prevHigh2 = i >= 2 ? highList[i - 2] : 0; + var prevLow2 = i >= 2 ? lowList[i - 2] : 0; bool uptrend; double ep, prevSAR, prevEP, SAR, af = start; @@ -227,8 +227,8 @@ public static StockData CalculateParabolicSAR(this StockData stockData, double s } sarList.AddRounded(SAR); - double prevNextSar = nextSarList.LastOrDefault(); - double nextSar = SAR + (af * (ep - SAR)); + var prevNextSar = nextSarList.LastOrDefault(); + var nextSar = SAR + (af * (ep - SAR)); nextSarList.AddRounded(nextSar); var signal = GetCompareSignal(currentHigh - nextSar, prevHigh1 - prevNextSar); @@ -265,20 +265,20 @@ public static StockData CalculateChandelierExit(this StockData stockData, Moving var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentAvgTrueRange = atrList[i]; - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - - double prevExitLong = chandelierExitLongList.LastOrDefault(); - double chandelierExitLong = highestHigh - (currentAvgTrueRange * mult); + var currentValue = inputList[i]; + var currentAvgTrueRange = atrList[i]; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + + var prevExitLong = chandelierExitLongList.LastOrDefault(); + var chandelierExitLong = highestHigh - (currentAvgTrueRange * mult); chandelierExitLongList.AddRounded(chandelierExitLong); - double prevExitShort = chandelierExitShortList.LastOrDefault(); - double chandelierExitShort = lowestLow + (currentAvgTrueRange * mult); + var prevExitShort = chandelierExitShortList.LastOrDefault(); + var chandelierExitShort = lowestLow + (currentAvgTrueRange * mult); chandelierExitShortList.AddRounded(chandelierExitShort); var signal = GetBullishBearishSignal(currentValue - chandelierExitLong, prevValue - prevExitLong, currentValue - chandelierExitShort, prevValue - prevExitShort); @@ -316,17 +316,17 @@ public static StockData CalculateAverageTrueRangeTrailingStops(this StockData st var atrList = CalculateAverageTrueRange(stockData, maType, length2).CustomValuesList; var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentEma = emaList[i]; - double currentAtr = atrList[i]; - double prevAtrts = i >= 1 ? atrtsList.LastOrDefault() : currentValue; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma = emaList[i]; + var currentAtr = atrList[i]; + var prevAtrts = i >= 1 ? atrtsList.LastOrDefault() : currentValue; var upTrend = currentValue > currentEma; var dnTrend = currentValue <= currentEma; - double atrts = upTrend ? Math.Max(currentValue - (factor * currentAtr), prevAtrts) : dnTrend ? + var atrts = upTrend ? Math.Max(currentValue - (factor * currentAtr), prevAtrts) : dnTrend ? Math.Min(currentValue + (factor * currentAtr), prevAtrts) : prevAtrts; atrtsList.AddRounded(atrts); @@ -362,36 +362,36 @@ public static StockData CalculateLinearTrailingStop(this StockData stockData, in List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double s = (double)1 / length; + var s = (double)1 / length; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double prevA2 = i >= 2 ? aList[i - 2] : currentValue; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double x = currentValue + ((prevA - prevA2) * mult); + var currentValue = inputList[i]; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var prevA2 = i >= 2 ? aList[i - 2] : currentValue; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var x = currentValue + ((prevA - prevA2) * mult); - double a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; + var a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; aList.AddRounded(a); - double up = a + (Math.Abs(a - prevA) * mult); - double dn = a - (Math.Abs(a - prevA) * mult); + var up = a + (Math.Abs(a - prevA) * mult); + var dn = a - (Math.Abs(a - prevA) * mult); - double prevUpper = upperList.LastOrDefault(); - double upper = up == a ? prevUpper : up; + var prevUpper = upperList.LastOrDefault(); + var upper = up == a ? prevUpper : up; upperList.AddRounded(upper); - double prevLower = lowerList.LastOrDefault(); - double lower = dn == a ? prevLower : dn; + var prevLower = lowerList.LastOrDefault(); + var lower = dn == a ? prevLower : dn; lowerList.AddRounded(lower); - double prevOs = osList.LastOrDefault(); - double os = currentValue > upper ? 1 : currentValue > lower ? 0 : prevOs; + var prevOs = osList.LastOrDefault(); + var os = currentValue > upper ? 1 : currentValue > lower ? 0 : prevOs; osList.AddRounded(os); - double prevTs = tsList.LastOrDefault(); - double ts = (os * lower) + ((1 - os) * upper); + var prevTs = tsList.LastOrDefault(); + var ts = (os * lower) + ((1 - os) * upper); tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); @@ -424,17 +424,17 @@ public static StockData CalculateNickRypockTrailingReverse(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double pct = length * 0.01; + var pct = length * 0.01; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevTrend = trendList.LastOrDefault(); - double prevHp = hpList.LastOrDefault(); - double prevLp = lpList.LastOrDefault(); - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevTrend = trendList.LastOrDefault(); + var prevHp = hpList.LastOrDefault(); + var prevLp = lpList.LastOrDefault(); + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevNrtr = nrtrList.LastOrDefault(); + var prevNrtr = nrtrList.LastOrDefault(); double nrtr, hp = 0, lp = 0, trend = 0; if (prevTrend >= 0) { @@ -504,24 +504,24 @@ public static StockData CalculateHalfTrend(this StockData stockData, MovingAvgTy var highMaList = GetMovingAverageList(stockData, maType, length, highList); var lowMaList = GetMovingAverageList(stockData, maType, length, lowList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentAvgTrueRange = atrList[i]; - double high = highestList[i]; - double low = lowestList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double highMa = highMaList[i]; - double lowMa = lowMaList[i]; - double maxLow = i >= 1 ? prevLow : low; - double minHigh = i >= 1 ? prevHigh : high; - double prevNextTrend = nextTrendList.LastOrDefault(); - double prevTrend = trendList.LastOrDefault(); - double prevUp = upList.LastOrDefault(); - double prevDown = downList.LastOrDefault(); - double atr = currentAvgTrueRange / 2; - double dev = length * atr; + var currentValue = inputList[i]; + var currentAvgTrueRange = atrList[i]; + var high = highestList[i]; + var low = lowestList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var highMa = highMaList[i]; + var lowMa = lowMaList[i]; + var maxLow = i >= 1 ? prevLow : low; + var minHigh = i >= 1 ? prevHigh : high; + var prevNextTrend = nextTrendList.LastOrDefault(); + var prevTrend = trendList.LastOrDefault(); + var prevUp = upList.LastOrDefault(); + var prevDown = downList.LastOrDefault(); + var atr = currentAvgTrueRange / 2; + var dev = length * atr; double trend = 0, nextTrend = 0; if (prevNextTrend == 1) @@ -577,7 +577,7 @@ public static StockData CalculateHalfTrend(this StockData stockData, MovingAvgTy upList.AddRounded(up); downList.AddRounded(down); - double ht = trend == 0 ? up : down; + var ht = trend == 0 ? up : down; htList.AddRounded(ht); var signal = GetConditionSignal(arrowUp != 0 && trend == 0 && prevTrend == 1, arrowDown != 0 && trend == 1 && prevTrend == 0); @@ -621,14 +621,14 @@ public static StockData CalculateKaseDevStopV1(this StockData stockData, InputNa List signalsList = new(); var (inputList, highList, lowList, _, closeList, _) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevClose = i >= 2 ? closeList[i - 2] : 0; - double prevLow = i >= 2 ? lowList[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevClose = i >= 2 ? closeList[i - 2] : 0; + var prevLow = i >= 2 ? lowList[i - 2] : 0; - double dtr = Math.Max(Math.Max(currentHigh - prevLow, Math.Abs(currentHigh - prevClose)), Math.Abs(currentLow - prevClose)); + var dtr = Math.Max(Math.Max(currentHigh - prevLow, Math.Abs(currentHigh - prevClose)), Math.Abs(currentLow - prevClose)); dtrList.AddRounded(dtr); } @@ -637,27 +637,27 @@ public static StockData CalculateKaseDevStopV1(this StockData stockData, InputNa var smaFastList = GetMovingAverageList(stockData, maType, fastLength, inputList); stockData.CustomValuesList = dtrList; var dtrStdList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double maFast = smaFastList[i]; - double maSlow = smaSlowList[i]; - double dtrAvg = dtrAvgList[i]; - double dtrStd = dtrStdList[i]; - double currentTypicalPrice = inputList[i]; - double prevMaFast = i >= 1 ? smaFastList[i - 1] : 0; - double prevMaSlow = i >= 1 ? smaSlowList[i - 1] : 0; - - double warningLine = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev1 * dtrStd) : + var maFast = smaFastList[i]; + var maSlow = smaSlowList[i]; + var dtrAvg = dtrAvgList[i]; + var dtrStd = dtrStdList[i]; + var currentTypicalPrice = inputList[i]; + var prevMaFast = i >= 1 ? smaFastList[i - 1] : 0; + var prevMaSlow = i >= 1 ? smaSlowList[i - 1] : 0; + + var warningLine = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev1 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev1 * dtrStd); warningLineList.AddRounded(warningLine); - double dev1 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev2 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev2 * dtrStd); + var dev1 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev2 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev2 * dtrStd); dev1List.AddRounded(dev1); - double dev2 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev3 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev3 * dtrStd); + var dev2 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev3 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev3 * dtrStd); dev2List.AddRounded(dev2); - double dev3 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev4 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev4 * dtrStd); + var dev3 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev4 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev4 * dtrStd); dev3List.AddRounded(dev3); var signal = GetCompareSignal(maFast - maSlow, prevMaFast - prevMaSlow); @@ -708,51 +708,51 @@ public static StockData CalculateKaseDevStopV2(this StockData stockData, MovingA var smaFastList = GetMovingAverageList(stockData, maType, fastLength, inputList); var smaSlowList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double maFast = smaFastList[i]; - double maSlow = smaSlowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 2 ? inputList[i - 2] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var maFast = smaFastList[i]; + var maSlow = smaSlowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 2 ? inputList[i - 2] : 0; double trend = maFast > maSlow ? 1 : -1; trendList.AddRounded(trend); - double price = trend == 1 ? currentHigh : currentLow; + var price = trend == 1 ? currentHigh : currentLow; price = trend > 0 ? Math.Max(price, currentHigh) : Math.Min(price, currentLow); priceList.AddRounded(price); - double mmax = Math.Max(Math.Max(currentHigh, prevHigh), prevClose); - double mmin = Math.Min(Math.Min(currentLow, prevLow), prevClose); - double rrange = mmax - mmin; + var mmax = Math.Max(Math.Max(currentHigh, prevHigh), prevClose); + var mmin = Math.Min(Math.Min(currentLow, prevLow), prevClose); + var rrange = mmax - mmin; rrangeList.AddRounded(rrange); } var rangeAvgList = GetMovingAverageList(stockData, maType, length, rrangeList); stockData.CustomValuesList = rrangeList; var rangeStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double price = priceList[i]; - double trend = trendList[i]; - double avg = rangeAvgList[i]; - double dev = rangeStdDevList[i]; - double prevPrice = i >= 1 ? priceList[i - 1] : 0; + var price = priceList[i]; + var trend = trendList[i]; + var avg = rangeAvgList[i]; + var dev = rangeStdDevList[i]; + var prevPrice = i >= 1 ? priceList[i - 1] : 0; - double val = (price + ((-1) * trend)) * (avg + (stdDev1 * dev)); + var val = (price + ((-1) * trend)) * (avg + (stdDev1 * dev)); valList.AddRounded(val); - double val1 = (price + ((-1) * trend)) * (avg + (stdDev2 * dev)); + var val1 = (price + ((-1) * trend)) * (avg + (stdDev2 * dev)); val1List.AddRounded(val1); - double val2 = (price + ((-1) * trend)) * (avg + (stdDev3 * dev)); + var val2 = (price + ((-1) * trend)) * (avg + (stdDev3 * dev)); val2List.AddRounded(val2); - double prevVal3 = val3List.LastOrDefault(); - double val3 = (price + ((-1) * trend)) * (avg + (stdDev4 * dev)); + var prevVal3 = val3List.LastOrDefault(); + var val3 = (price + ((-1) * trend)) * (avg + (stdDev4 * dev)); val3List.AddRounded(val3); var signal = GetCompareSignal(price - val3, prevPrice - prevVal3); @@ -788,22 +788,22 @@ public static StockData CalculatePercentageTrailingStops(this StockData stockDat var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevHH = i >= 1 ? highestList[i - 1] : currentClose; - double prevLL = i >= 1 ? lowestList[i - 1] : currentClose; - double pSS = i >= 1 ? stopSList.LastOrDefault() : currentClose; - double pSL = i >= 1 ? stopLList.LastOrDefault() : currentClose; - - double stopL = currentHigh > prevHH ? currentHigh - (pct * currentHigh) : pSL; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevHH = i >= 1 ? highestList[i - 1] : currentClose; + var prevLL = i >= 1 ? lowestList[i - 1] : currentClose; + var pSS = i >= 1 ? stopSList.LastOrDefault() : currentClose; + var pSL = i >= 1 ? stopLList.LastOrDefault() : currentClose; + + var stopL = currentHigh > prevHH ? currentHigh - (pct * currentHigh) : pSL; stopLList.AddRounded(stopL); - double stopS = currentLow < prevLL ? currentLow + (pct * currentLow) : pSS; + var stopS = currentLow < prevLL ? currentLow + (pct * currentLow) : pSS; stopSList.AddRounded(stopS); var signal = GetConditionSignal(prevHigh < stopS && currentHigh > stopS, prevLow > stopL && currentLow < stopL); @@ -839,21 +839,21 @@ public static StockData CalculateMotionToAttractionTrailingStop(this StockData s var aList = mtaList.OutputValues["UpperBand"]; var bList = mtaList.OutputValues["LowerBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double a = aList[i]; - double b = bList[i]; - - double prevOs = osList.LastOrDefault(); - double os = currentValue > prevA ? 1 : currentValue < prevB ? 0 : prevOs; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var a = aList[i]; + var b = bList[i]; + + var prevOs = osList.LastOrDefault(); + var os = currentValue > prevA ? 1 : currentValue < prevB ? 0 : prevOs; osList.AddRounded(os); - double prevTs = tsList.LastOrDefault(); - double ts = (os * b) + ((1 - os) * a); + var prevTs = tsList.LastOrDefault(); + var ts = (os * b) + ((1 - os) * a); tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); @@ -896,47 +896,47 @@ public static StockData CalculateElderSafeZoneStops(this StockData stockData, Mo var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentLow = lowList[i]; - double currentHigh = highList[i]; - double currentEma = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - - double dmMinus = prevLow > currentLow ? prevLow - currentLow : 0; + var currentValue = inputList[i]; + var currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentEma = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + + var dmMinus = prevLow > currentLow ? prevLow - currentLow : 0; dmMinusList.AddRounded(dmMinus); double dmMinusCount = prevLow > currentLow ? 1 : 0; dmMinusCountList.AddRounded(dmMinusCount); - double dmPlus = currentHigh > prevHigh ? currentHigh - prevHigh : 0; + var dmPlus = currentHigh > prevHigh ? currentHigh - prevHigh : 0; dmPlusList.AddRounded(dmPlus); double dmPlusCount = currentHigh > prevHigh ? 1 : 0; dmPlusCountList.AddRounded(dmPlusCount); - double countM = dmMinusCountList.TakeLastExt(length2).Sum(); - double dmMinusSum = dmMinusList.TakeLastExt(length2).Sum(); - double dmAvgMinus = countM != 0 ? dmMinusSum / countM : 0; - double countP = dmPlusCountList.TakeLastExt(length2).Sum(); - double dmPlusSum = dmPlusList.TakeLastExt(length2).Sum(); - double dmAvgPlus = countP != 0 ? dmPlusSum / countP : 0; + var countM = dmMinusCountList.TakeLastExt(length2).Sum(); + var dmMinusSum = dmMinusList.TakeLastExt(length2).Sum(); + var dmAvgMinus = countM != 0 ? dmMinusSum / countM : 0; + var countP = dmPlusCountList.TakeLastExt(length2).Sum(); + var dmPlusSum = dmPlusList.TakeLastExt(length2).Sum(); + var dmAvgPlus = countP != 0 ? dmPlusSum / countP : 0; - double safeZMinus = prevLow - (factor * dmAvgMinus); + var safeZMinus = prevLow - (factor * dmAvgMinus); safeZMinusList.AddRounded(safeZMinus); - double safeZPlus = prevHigh + (factor * dmAvgPlus); + var safeZPlus = prevHigh + (factor * dmAvgPlus); safeZPlusList.AddRounded(safeZPlus); - double highest = safeZMinusList.TakeLastExt(length3).Max(); - double lowest = safeZPlusList.TakeLastExt(length3).Min(); + var highest = safeZMinusList.TakeLastExt(length3).Max(); + var lowest = safeZPlusList.TakeLastExt(length3).Min(); - double prevStop = stopList.LastOrDefault(); - double stop = currentValue >= currentEma ? highest : lowest; + var prevStop = stopList.LastOrDefault(); + var stop = currentValue >= currentEma ? highest : lowest; stopList.AddRounded(stop); var signal = GetBullishBearishSignal(currentValue - Math.Max(currentEma, stop), prevValue - Math.Max(prevEma, prevStop), diff --git a/src/Calculations/Trend.cs b/src/Calculations/Trend.cs index f86b9b8..ba88f56 100644 --- a/src/Calculations/Trend.cs +++ b/src/Calculations/Trend.cs @@ -25,18 +25,18 @@ public static StockData CalculateTrendTriggerFactor(this StockData stockData, in var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highest = highestList[i]; - double lowest = lowestList[i]; - double prevHighest = i >= length ? highestList[i - length] : 0; - double prevLowest = i >= length ? lowestList[i - length] : 0; - double buyPower = highest - prevLowest; - double sellPower = prevHighest - lowest; - double prevTtf1 = i >= 1 ? ttfList[i - 1] : 0; - double prevTtf2 = i >= 2 ? ttfList[i - 2] : 0; - - double ttf = buyPower + sellPower != 0 ? 200 * (buyPower - sellPower) / (buyPower + sellPower) : 0; + var highest = highestList[i]; + var lowest = lowestList[i]; + var prevHighest = i >= length ? highestList[i - length] : 0; + var prevLowest = i >= length ? lowestList[i - length] : 0; + var buyPower = highest - prevLowest; + var sellPower = prevHighest - lowest; + var prevTtf1 = i >= 1 ? ttfList[i - 1] : 0; + var prevTtf2 = i >= 2 ? ttfList[i - 2] : 0; + + var ttf = buyPower + sellPower != 0 ? 200 * (buyPower - sellPower) / (buyPower + sellPower) : 0; ttfList.AddRounded(ttf); var signal = GetRsiSignal(ttf - prevTtf1, prevTtf1 - prevTtf2, ttf, prevTtf1, 100, -100); @@ -75,11 +75,11 @@ public static StockData CalculateTrendPersistenceRate(this StockData stockData, var maList = GetMovingAverageList(stockData, maType, smoothLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevMa1 = i >= 1 ? maList[i - 1] : 0; - double prevMa2 = i >= 2 ? maList[i - 2] : 0; - double diff = (prevMa1 - prevMa2) / mult; + var prevMa1 = i >= 1 ? maList[i - 1] : 0; + var prevMa2 = i >= 2 ? maList[i - 2] : 0; + var diff = (prevMa1 - prevMa2) / mult; double ctrP = diff > threshold ? 1 : 0; ctrPList.AddRounded(ctrP); @@ -87,20 +87,20 @@ public static StockData CalculateTrendPersistenceRate(this StockData stockData, double ctrM = diff < -threshold ? 1 : 0; ctrMList.AddRounded(ctrM); - double ctrPSum = ctrPList.TakeLastExt(length).Sum(); - double ctrMSum = ctrMList.TakeLastExt(length).Sum(); + var ctrPSum = ctrPList.TakeLastExt(length).Sum(); + var ctrMSum = ctrMList.TakeLastExt(length).Sum(); - double tpr = length != 0 ? Math.Abs(100 * (ctrPSum - ctrMSum) / length) : 0; + var tpr = length != 0 ? Math.Abs(100 * (ctrPSum - ctrMSum) / length) : 0; tprList.AddRounded(tpr); } var tprMaList = GetMovingAverageList(stockData, maType, smoothLength, tprList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tpr = tprList[i]; - double tprMa = tprMaList[i]; - double prevTpr = i >= 1 ? tprList[i - 1] : 0; - double prevTprMa = i >= 1 ? tprMaList[i - 1] : 0; + var tpr = tprList[i]; + var tprMa = tprMaList[i]; + var prevTpr = i >= 1 ? tprList[i - 1] : 0; + var prevTprMa = i >= 1 ? tprMaList[i - 1] : 0; var signal = GetCompareSignal(tpr - tprMa, prevTpr - prevTprMa); signalsList.Add(signal); @@ -131,14 +131,14 @@ public static StockData CalculateTrendStep(this StockData stockData, int length var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double dev = stdDevList[i] * 2; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var dev = stdDevList[i] * 2; - double prevA = i >= 1 ? aList[i - 1] : currentValue; - double a = i < length ? currentValue : currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; + var prevA = i >= 1 ? aList[i - 1] : currentValue; + var a = i < length ? currentValue : currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; aList.AddRounded(a); var signal = GetCompareSignal(currentValue - a, prevValue - prevA); @@ -175,14 +175,14 @@ public static StockData CalculateTrendExhaustionIndicator(this StockData stockDa var (inputList, highList, _, _, _) = GetInputValuesList(stockData); var (highestList, _) = GetMaxAndMinValuesList(highList, length); - double sc = (double)2 / (length + 1); + var sc = (double)2 / (length + 1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHighest = i >= 1 ? highestList[i - 1] : 0; - double currentHigh = highList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevHighest = i >= 1 ? highestList[i - 1] : 0; + var currentHigh = highList[i]; double a = currentValue > prevValue ? 1 : 0; aList.AddRounded(a); @@ -190,25 +190,25 @@ public static StockData CalculateTrendExhaustionIndicator(this StockData stockDa double h = currentHigh > prevHighest ? 1 : 0; hList.AddRounded(h); - double aCount = aList.Sum(); + var aCount = aList.Sum(); aCountList.AddRounded(aCount); - double hCount = hList.Sum(); + var hCount = hList.Sum(); hCountList.AddRounded(hCount); - double haRatio = aCount != 0 ? hCount / aCount : 0; - double prevTei = teiList.LastOrDefault(); - double tei = prevTei + (sc * (haRatio - prevTei)); + var haRatio = aCount != 0 ? hCount / aCount : 0; + var prevTei = teiList.LastOrDefault(); + var tei = prevTei + (sc * (haRatio - prevTei)); teiList.AddRounded(tei); } var teiSignalList = GetMovingAverageList(stockData, maType, length, teiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tei = teiList[i]; - double teiSignal = teiSignalList[i]; - double prevTei = i >= 1 ? teiList[i - 1] : 0; - double prevTeiSignal = i >= 1 ? teiSignalList[i - 1] : 0; + var tei = teiList[i]; + var teiSignal = teiSignalList[i]; + var prevTei = i >= 1 ? teiList[i - 1] : 0; + var prevTeiSignal = i >= 1 ? teiSignalList[i - 1] : 0; var signal = GetCompareSignal(tei - teiSignal, prevTei - prevTeiSignal); signalsList.Add(signal); @@ -242,25 +242,25 @@ public static StockData CalculateTrendImpulseFilter(this StockData stockData, Mo var (inputList, _, _, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length1); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevB = i >= 1 ? bList[i - 1] : currentValue; - double highest = i >= 1 ? highestList[i - 1] : 0; - double lowest = i >= 1 ? lowestList[i - 1] : 0; + var currentValue = inputList[i]; + var prevB = i >= 1 ? bList[i - 1] : currentValue; + var highest = i >= 1 ? highestList[i - 1] : 0; + var lowest = i >= 1 ? lowestList[i - 1] : 0; double a = currentValue > highest || currentValue < lowest ? 1 : 0; - double b = (a * currentValue) + ((1 - a) * prevB); + var b = (a * currentValue) + ((1 - a) * prevB); bList.AddRounded(b); } var bEmaList = GetMovingAverageList(stockData, maType, length2, bList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double bEma = bEmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevBEma = i >= 1 ? bEmaList[i - 1] : 0; + var currentValue = inputList[i]; + var bEma = bEmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevBEma = i >= 1 ? bEmaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - bEma, prevValue - prevBEma); signalsList.Add(signal); @@ -295,25 +295,25 @@ public static StockData CalculateTrendAnalysisIndex(this StockData stockData, Mo var smaList = GetMovingAverageList(stockData, maType, length1, inputList); var (highestList, lowestList) = GetMaxAndMinValuesList(smaList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; + var currentValue = inputList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; - double tai = currentValue != 0 ? (highest - lowest) * 100 / currentValue : 0; + var tai = currentValue != 0 ? (highest - lowest) * 100 / currentValue : 0; taiList.AddRounded(tai); } var taiMaList = GetMovingAverageList(stockData, maType, length2, taiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; - double tai = taiList[i]; - double taiSma = taiMaList[i]; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; + var tai = taiList[i]; + var taiSma = taiMaList[i]; var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, tai, taiSma); signalsList.Add(signal); @@ -351,14 +351,14 @@ public static StockData CalculateTrendAnalysisIndicator(this StockData stockData var taiList = CalculateStandardDeviationVolatility(stockData, maType, length2).CustomValuesList; var taiSmaList = GetMovingAverageList(stockData, maType, length1, taiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tai = taiList[i]; - double fastMa = fastMaList[i]; - double slowMa = slowMaList[i]; - double taiMa = taiSmaList[i]; - double prevFastMa = i >= 1 ? fastMaList[i - 1] : 0; - double prevSlowMa = i >= 1 ? slowMaList[i - 1] : 0; + var tai = taiList[i]; + var fastMa = fastMaList[i]; + var slowMa = slowMaList[i]; + var taiMa = taiSmaList[i]; + var prevFastMa = i >= 1 ? fastMaList[i - 1] : 0; + var prevSlowMa = i >= 1 ? slowMaList[i - 1] : 0; var signal = GetVolatilitySignal(fastMa - slowMa, prevFastMa - prevSlowMa, tai, taiMa); signalsList.Add(signal); @@ -399,40 +399,40 @@ public static StockData CalculateTrender(this StockData stockData, MovingAvgType stockData.CustomValuesList = atrList; var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double mpEma = emaList[i]; - double trEma = atrList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var mpEma = emaList[i]; + var trEma = atrList[i]; - double ad = currentValue > prevValue ? mpEma + (trEma / 2) : currentValue < prevValue ? mpEma - (trEma / 2) : mpEma; + var ad = currentValue > prevValue ? mpEma + (trEma / 2) : currentValue < prevValue ? mpEma - (trEma / 2) : mpEma; adList.AddRounded(ad); } var admList = GetMovingAverageList(stockData, maType, length, adList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double adm = admList[i]; - double prevAdm = i >= 1 ? admList[i - 1] : 0; - double mpEma = emaList[i]; - double prevMpEma = i >= 1 ? emaList[i - 1] : 0; - double prevHigh = i >= 2 ? highList[i - 2] : 0; - double prevLow = i >= 2 ? lowList[i - 2] : 0; - double stdDev = stdDevList[i]; - - double prevTrndDn = trndDnList.LastOrDefault(); - double trndDn = adm < mpEma && prevAdm > prevMpEma ? prevHigh : currentValue < prevValue ? currentValue + (stdDev * atrMult) : prevTrndDn; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var adm = admList[i]; + var prevAdm = i >= 1 ? admList[i - 1] : 0; + var mpEma = emaList[i]; + var prevMpEma = i >= 1 ? emaList[i - 1] : 0; + var prevHigh = i >= 2 ? highList[i - 2] : 0; + var prevLow = i >= 2 ? lowList[i - 2] : 0; + var stdDev = stdDevList[i]; + + var prevTrndDn = trndDnList.LastOrDefault(); + var trndDn = adm < mpEma && prevAdm > prevMpEma ? prevHigh : currentValue < prevValue ? currentValue + (stdDev * atrMult) : prevTrndDn; trndDnList.AddRounded(trndDn); - double prevTrndUp = trndUpList.LastOrDefault(); - double trndUp = adm > mpEma && prevAdm < prevMpEma ? prevLow : currentValue > prevValue ? currentValue - (stdDev * atrMult) : prevTrndUp; + var prevTrndUp = trndUpList.LastOrDefault(); + var trndUp = adm > mpEma && prevAdm < prevMpEma ? prevLow : currentValue > prevValue ? currentValue - (stdDev * atrMult) : prevTrndUp; trndUpList.AddRounded(trndUp); - double prevTrndr = trndrList.LastOrDefault(); - double trndr = adm < mpEma ? trndDn : adm > mpEma ? trndUp : prevTrndr; + var prevTrndr = trndrList.LastOrDefault(); + var trndr = adm < mpEma ? trndDn : adm > mpEma ? trndUp : prevTrndr; trndrList.AddRounded(trndr); var signal = GetCompareSignal(currentValue - trndr, prevValue - prevTrndr); @@ -469,25 +469,25 @@ public static StockData CalculateTrendDirectionForceIndex(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int halfLength = MinOrMax((int)Math.Ceiling((double)length1 / 2)); + var halfLength = MinOrMax((int)Math.Ceiling((double)length1 / 2)); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i] * 1000; + var currentValue = inputList[i] * 1000; srcList.AddRounded(currentValue); } var ema1List = GetMovingAverageList(stockData, maType, halfLength, srcList); var ema2List = GetMovingAverageList(stockData, maType, halfLength, ema1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema1 = ema1List[i]; - double ema2 = ema2List[i]; - double prevEma1 = i >= 1 ? ema1List[i - 1] : 0; - double prevEma2 = i >= 1 ? ema2List[i - 1] : 0; - double ema1Diff = ema1 - prevEma1; - double ema2Diff = ema2 - prevEma2; - double emaDiffAvg = (ema1Diff + ema2Diff) / 2; + var ema1 = ema1List[i]; + var ema2 = ema2List[i]; + var prevEma1 = i >= 1 ? ema1List[i - 1] : 0; + var prevEma2 = i >= 1 ? ema2List[i - 1] : 0; + var ema1Diff = ema1 - prevEma1; + var ema2Diff = ema2 - prevEma2; + var emaDiffAvg = (ema1Diff + ema2Diff) / 2; double tdf; try @@ -499,12 +499,12 @@ public static StockData CalculateTrendDirectionForceIndex(this StockData stockDa tdf = double.MaxValue; } - double absTdf = Math.Abs(tdf); + var absTdf = Math.Abs(tdf); absTdfList.AddRounded(absTdf); - double tdfh = absTdfList.TakeLastExt(length2).Max(); - double prevTdfi = tdfiList.LastOrDefault(); - double tdfi = tdfh != 0 ? tdf / tdfh : 0; + var tdfh = absTdfList.TakeLastExt(length2).Max(); + var prevTdfi = tdfiList.LastOrDefault(); + var tdfi = tdfh != 0 ? tdf / tdfh : 0; tdfiList.AddRounded(tdfi); var signal = GetCompareSignal(tdfi, prevTdfi); @@ -541,22 +541,22 @@ public static StockData CalculateTrendIntensityIndex(this StockData stockData, M var smaList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double prevTii1 = i >= 1 ? tiiList[i - 1] : 0; - double prevTii2 = i >= 2 ? tiiList[i - 2] : 0; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var prevTii1 = i >= 1 ? tiiList[i - 1] : 0; + var prevTii2 = i >= 2 ? tiiList[i - 2] : 0; - double deviationUp = currentValue > currentSma ? currentValue - currentSma : 0; + var deviationUp = currentValue > currentSma ? currentValue - currentSma : 0; deviationUpList.AddRounded(deviationUp); - double deviationDown = currentValue < currentSma ? currentSma - currentValue : 0; + var deviationDown = currentValue < currentSma ? currentSma - currentValue : 0; deviationDownList.AddRounded(deviationDown); - double sdPlus = deviationUpList.TakeLastExt(fastLength).Sum(); - double sdMinus = deviationDownList.TakeLastExt(fastLength).Sum(); - double tii = sdPlus + sdMinus != 0 ? sdPlus / (sdPlus + sdMinus) * 100 : 0; + var sdPlus = deviationUpList.TakeLastExt(fastLength).Sum(); + var sdMinus = deviationDownList.TakeLastExt(fastLength).Sum(); + var tii = sdPlus + sdMinus != 0 ? sdPlus / (sdPlus + sdMinus) * 100 : 0; tiiList.AddRounded(tii); var signal = GetRsiSignal(tii - prevTii1, prevTii1 - prevTii2, tii, prevTii1, 80, 20); @@ -594,36 +594,36 @@ public static StockData CalculateTrendForceHistogram(this StockData stockData, i var emaList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length, inputList); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ema = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double highest = i >= 1 ? highestList[i - 1] : 0; - double lowest = i >= 1 ? lowestList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - - double prevA = aList.LastOrDefault(); + var currentValue = inputList[i]; + var ema = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var highest = i >= 1 ? highestList[i - 1] : 0; + var lowest = i >= 1 ? lowestList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + + var prevA = aList.LastOrDefault(); double a = currentValue > highest ? 1 : 0; aList.AddRounded(a); - double prevB = bList.LastOrDefault(); + var prevB = bList.LastOrDefault(); double b = currentValue < lowest ? 1 : 0; bList.AddRounded(b); - double prevC = cList.LastOrDefault(); - double c = a == 1 ? prevC + 1 : b - prevB == 1 ? 0 : prevC; + var prevC = cList.LastOrDefault(); + var c = a == 1 ? prevC + 1 : b - prevB == 1 ? 0 : prevC; cList.AddRounded(c); - double prevD = dList.LastOrDefault(); - double d = b == 1 ? prevD + 1 : a - prevA == 1 ? 0 : prevD; + var prevD = dList.LastOrDefault(); + var d = b == 1 ? prevD + 1 : a - prevA == 1 ? 0 : prevD; dList.AddRounded(d); - double avg = (c + d) / 2; + var avg = (c + d) / 2; avgList.AddRounded(avg); - double rmean = i != 0 ? avgList.Sum() / i : 0; - double osc = avg - rmean; + var rmean = i != 0 ? avgList.Sum() / i : 0; + var osc = avg - rmean; oscList.AddRounded(osc); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, osc, 0); @@ -657,26 +657,26 @@ public static StockData CalculateTrendDetectionIndex(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= length1 ? inputList[i - length1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= length1 ? inputList[i - length1] : 0; - double mom = MinPastValues(i, length1, currentValue - prevValue); + var mom = MinPastValues(i, length1, currentValue - prevValue); momList.AddRounded(mom); - double momAbs = Math.Abs(mom); + var momAbs = Math.Abs(mom); momAbsList.AddRounded(momAbs); - double prevTdiDirection = tdiDirectionList.LastOrDefault(); - double tdiDirection = momList.TakeLastExt(length1).Sum(); + var prevTdiDirection = tdiDirectionList.LastOrDefault(); + var tdiDirection = momList.TakeLastExt(length1).Sum(); tdiDirectionList.AddRounded(tdiDirection); - double momAbsSum1 = momAbsList.TakeLastExt(length1).Sum(); - double momAbsSum2 = momAbsList.TakeLastExt(length2).Sum(); + var momAbsSum1 = momAbsList.TakeLastExt(length1).Sum(); + var momAbsSum2 = momAbsList.TakeLastExt(length2).Sum(); - double prevTdi = tdiList.LastOrDefault(); - double tdi = Math.Abs(tdiDirection) - momAbsSum2 + momAbsSum1; + var prevTdi = tdiList.LastOrDefault(); + var tdi = Math.Abs(tdiDirection) - momAbsSum2 + momAbsSum1; tdiList.AddRounded(tdi); var signal = GetCompareSignal(tdiDirection - tdi, prevTdiDirection - prevTdi); @@ -712,34 +712,34 @@ public static StockData CalculateTrendContinuationFactor(this StockData stockDat List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double priceChg = MinPastValues(i, 1, currentValue - prevValue); - double chgPlus = priceChg > 0 ? priceChg : 0; - double chgMinus = priceChg < 0 ? Math.Abs(priceChg) : 0; - - double prevCfPlus = cfPlusList.LastOrDefault(); - double cfPlus = chgPlus == 0 ? 0 : chgPlus + prevCfPlus; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var priceChg = MinPastValues(i, 1, currentValue - prevValue); + var chgPlus = priceChg > 0 ? priceChg : 0; + var chgMinus = priceChg < 0 ? Math.Abs(priceChg) : 0; + + var prevCfPlus = cfPlusList.LastOrDefault(); + var cfPlus = chgPlus == 0 ? 0 : chgPlus + prevCfPlus; cfPlusList.AddRounded(cfPlus); - double prevCfMinus = cfMinusList.LastOrDefault(); - double cfMinus = chgMinus == 0 ? 0 : chgMinus + prevCfMinus; + var prevCfMinus = cfMinusList.LastOrDefault(); + var cfMinus = chgMinus == 0 ? 0 : chgMinus + prevCfMinus; cfMinusList.AddRounded(cfMinus); - double diffPlus = chgPlus - cfMinus; + var diffPlus = chgPlus - cfMinus; diffPlusList.AddRounded(diffPlus); - double diffMinus = chgMinus - cfPlus; + var diffMinus = chgMinus - cfPlus; diffMinusList.AddRounded(diffMinus); - double prevTcfPlus = tcfPlusList.LastOrDefault(); - double tcfPlus = diffPlusList.TakeLastExt(length).Sum(); + var prevTcfPlus = tcfPlusList.LastOrDefault(); + var tcfPlus = diffPlusList.TakeLastExt(length).Sum(); tcfPlusList.AddRounded(tcfPlus); - double prevTcfMinus = tcfMinusList.LastOrDefault(); - double tcfMinus = diffMinusList.TakeLastExt(length).Sum(); + var prevTcfMinus = tcfMinusList.LastOrDefault(); + var tcfMinus = diffMinusList.TakeLastExt(length).Sum(); tcfMinusList.AddRounded(tcfMinus); var signal = GetCompareSignal(tcfPlus - tcfMinus, prevTcfPlus - prevTcfMinus); @@ -778,29 +778,29 @@ public static StockData CalculateSuperTrend(this StockData stockData, MovingAvgT var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentAtr = atrList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double atrValue = atrMult * currentAtr; - double tempLongStop = currentValue - atrValue; - double tempShortStop = currentValue + atrValue; - - double prevLongStop = i >= 1 ? longStopList.LastOrDefault() : tempLongStop; - double longStop = prevValue > prevLongStop ? Math.Max(tempLongStop, prevLongStop) : tempLongStop; + var currentValue = inputList[i]; + var currentAtr = atrList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var atrValue = atrMult * currentAtr; + var tempLongStop = currentValue - atrValue; + var tempShortStop = currentValue + atrValue; + + var prevLongStop = i >= 1 ? longStopList.LastOrDefault() : tempLongStop; + var longStop = prevValue > prevLongStop ? Math.Max(tempLongStop, prevLongStop) : tempLongStop; longStopList.AddRounded(longStop); - double prevShortStop = i >= 1 ? shortStopList.LastOrDefault() : tempShortStop; - double shortStop = prevValue < prevShortStop ? Math.Min(tempShortStop, prevShortStop) : tempShortStop; + var prevShortStop = i >= 1 ? shortStopList.LastOrDefault() : tempShortStop; + var shortStop = prevValue < prevShortStop ? Math.Min(tempShortStop, prevShortStop) : tempShortStop; shortStopList.AddRounded(shortStop); - double prevDir = i >= 1 ? dirList.LastOrDefault() : 1; - double dir = prevDir == -1 && currentValue > prevShortStop ? 1 : prevDir == 1 && currentValue < prevLongStop ? -1 : prevDir; + var prevDir = i >= 1 ? dirList.LastOrDefault() : 1; + var dir = prevDir == -1 && currentValue > prevShortStop ? 1 : prevDir == 1 && currentValue < prevLongStop ? -1 : prevDir; dirList.AddRounded(dir); - double prevTrend = trendList.LastOrDefault(); - double trend = dir > 0 ? longStop : shortStop; + var prevTrend = trendList.LastOrDefault(); + var trend = dir > 0 ? longStop : shortStop; trendList.AddRounded(trend); var signal = GetCompareSignal(currentValue - trend, prevValue - prevTrend); @@ -837,22 +837,22 @@ public static StockData CalculateSchaffTrendCycle(this StockData stockData, Movi var ema23List = GetMovingAverageList(stockData, maType, fastLength, inputList); var ema50List = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEma23 = ema23List[i]; - double currentEma50 = ema50List[i]; + var currentEma23 = ema23List[i]; + var currentEma50 = ema50List[i]; - double macd = currentEma23 - currentEma50; + var macd = currentEma23 - currentEma50; macdList.AddRounded(macd); } stockData.CustomValuesList = macdList; var stcList = CalculateStochasticOscillator(stockData, maType, length: cycleLength).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stc = stcList[i]; - double prevStc1 = i >= 1 ? stcList[i - 1] : 0; - double prevStc2 = i >= 2 ? stcList[i - 2] : 0; + var stc = stcList[i]; + var prevStc1 = i >= 1 ? stcList[i - 1] : 0; + var prevStc2 = i >= 2 ? stcList[i - 2] : 0; var signal = GetRsiSignal(stc - prevStc1, prevStc1 - prevStc2, stc, prevStc1, 75, 25); signalsList.Add(signal); @@ -885,36 +885,36 @@ public static StockData CalculateUberTrendIndicator(this StockData stockData, in List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; - double prevUti1 = i >= 1 ? utiList[i - 1] : 0; - double prevUti2 = i >= 2 ? utiList[i - 2] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = volumeList[i]; + var prevUti1 = i >= 1 ? utiList[i - 1] : 0; + var prevUti2 = i >= 2 ? utiList[i - 2] : 0; - double adv = i >= 1 && currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; + var adv = i >= 1 && currentValue > prevValue ? MinPastValues(i, 1, currentValue - prevValue) : 0; advList.AddRounded(adv); - double dec = i >= 1 && currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; + var dec = i >= 1 && currentValue < prevValue ? MinPastValues(i, 1, prevValue - currentValue) : 0; decList.AddRounded(dec); - double advSum = advList.TakeLastExt(length).Sum(); - double decSum = decList.TakeLastExt(length).Sum(); + var advSum = advList.TakeLastExt(length).Sum(); + var decSum = decList.TakeLastExt(length).Sum(); - double advVol = i >= 1 && currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; + var advVol = i >= 1 && currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; advVolList.AddRounded(advVol); - double decVol = i >= 1 && currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; + var decVol = i >= 1 && currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; decVolList.AddRounded(decVol); - double advVolSum = advVolList.TakeLastExt(length).Sum(); - double decVolSum = decVolList.TakeLastExt(length).Sum(); - double top = decSum != 0 ? advSum / decSum : 0; - double bot = decVolSum != 0 ? advVolSum / decVolSum : 0; - double ut = bot != 0 ? top / bot : 0; + var advVolSum = advVolList.TakeLastExt(length).Sum(); + var decVolSum = decVolList.TakeLastExt(length).Sum(); + var top = decSum != 0 ? advSum / decSum : 0; + var bot = decVolSum != 0 ? advVolSum / decVolSum : 0; + var ut = bot != 0 ? top / bot : 0; - double uti = ut + 1 != 0 ? (ut - 1) / (ut + 1) : 0; + var uti = ut + 1 != 0 ? (ut - 1) / (ut + 1) : 0; utiList.AddRounded(uti); var signal = GetCompareSignal(uti - prevUti1, prevUti1 - prevUti2); @@ -952,34 +952,34 @@ public static StockData CalculateWaveTrendOscillator(this StockData stockData, I var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ap = inputList[i]; - double esa = emaList[i]; + var ap = inputList[i]; + var esa = emaList[i]; - double absApEsa = Math.Abs(ap - esa); + var absApEsa = Math.Abs(ap - esa); absApEsaList.AddRounded(absApEsa); } var dList = GetMovingAverageList(stockData, maType, length1, absApEsaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ap = inputList[i]; - double esa = emaList[i]; - double d = dList[i]; + var ap = inputList[i]; + var esa = emaList[i]; + var d = dList[i]; - double ci = d != 0 ? (ap - esa) / (0.015 * d) : 0; + var ci = d != 0 ? (ap - esa) / (0.015 * d) : 0; ciList.AddRounded(ci); } var tciList = GetMovingAverageList(stockData, maType, length2, ciList); var wt2List = GetMovingAverageList(stockData, maType, smoothLength, tciList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tci = tciList[i]; - double wt2 = wt2List[i]; - double prevTci = i >= 1 ? tciList[i - 1] : 0; - double prevWt2 = i >= 1 ? wt2List[i - 1] : 0; + var tci = tciList[i]; + var wt2 = wt2List[i]; + var prevTci = i >= 1 ? tciList[i - 1] : 0; + var prevWt2 = i >= 1 ? wt2List[i - 1] : 0; var signal = GetRsiSignal(tci - wt2, prevTci - prevWt2, tci, prevTci, 53, -53); signalsList.Add(signal); @@ -1016,25 +1016,25 @@ public static StockData CalculateOptimizedTrendTracker(this StockData stockData, var maList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double ma = maList[i]; - double fark = ma * percent * 0.01; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var ma = maList[i]; + var fark = ma * percent * 0.01; - double prevLongStop = longStopList.LastOrDefault(); - double longStop = ma - fark; + var prevLongStop = longStopList.LastOrDefault(); + var longStop = ma - fark; longStop = ma > prevLongStop ? Math.Max(longStop, prevLongStop) : longStop; longStopList.AddRounded(longStop); - double prevShortStop = shortStopList.LastOrDefault(); - double shortStop = ma + fark; + var prevShortStop = shortStopList.LastOrDefault(); + var shortStop = ma + fark; shortStopList.AddRounded(shortStop); - double prevOtt = ottList.LastOrDefault(); - double mt = ma > prevShortStop ? longStop : ma < prevLongStop ? shortStop : 0; - double ott = ma > mt ? mt * (200 + percent) / 200 : mt * (200 - percent) / 200; + var prevOtt = ottList.LastOrDefault(); + var mt = ma > prevShortStop ? longStop : ma < prevLongStop ? shortStop : 0; + var ott = ma > mt ? mt * (200 + percent) / 200 : mt * (200 - percent) / 200; ottList.AddRounded(ott); var signal = GetCompareSignal(currentValue - ott, prevValue - prevOtt); @@ -1065,17 +1065,17 @@ public static StockData CalculateGannTrendOscillator(this StockData stockData, i var (_, highList, lowList, _, _) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, length); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double prevHighest1 = i >= 1 ? highestList[i - 1] : 0; - double prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; - double prevHighest2 = i >= 2 ? highestList[i - 2] : 0; - double prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; - - double prevGto = gannTrendOscillatorList.LastOrDefault(); - double gto = prevHighest2 > prevHighest1 && highestHigh > prevHighest1 ? 1 : prevLowest2 < prevLowest1 && lowestLow < prevLowest1 ? -1 : prevGto; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var prevHighest1 = i >= 1 ? highestList[i - 1] : 0; + var prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; + var prevHighest2 = i >= 2 ? highestList[i - 2] : 0; + var prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; + + var prevGto = gannTrendOscillatorList.LastOrDefault(); + var gto = prevHighest2 > prevHighest1 && highestHigh > prevHighest1 ? 1 : prevLowest2 < prevLowest1 && lowestLow < prevLowest1 ? -1 : prevGto; gannTrendOscillatorList.AddRounded(gto); var signal = GetCompareSignal(gto, prevGto); @@ -1115,44 +1115,44 @@ public static StockData CalculateGrandTrendForecasting(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevT = i >= length ? tList[i - length] : currentValue; - double priorT = i >= forecastLength ? tList[i - forecastLength] : 0; - double prevFcast = i >= forecastLength ? fcastList[i - forecastLength] : 0; - double prevChg = i >= length ? chgList[i - length] : currentValue; + var currentValue = inputList[i]; + var prevT = i >= length ? tList[i - length] : currentValue; + var priorT = i >= forecastLength ? tList[i - forecastLength] : 0; + var prevFcast = i >= forecastLength ? fcastList[i - forecastLength] : 0; + var prevChg = i >= length ? chgList[i - length] : currentValue; - double chg = 0.9 * prevT; + var chg = 0.9 * prevT; chgList.AddRounded(chg); - double t = (0.9 * prevT) + (0.1 * currentValue) + (chg - prevChg); + var t = (0.9 * prevT) + (0.1 * currentValue) + (chg - prevChg); tList.AddRounded(t); - double trend = tList.TakeLastExt(length).Average(); + var trend = tList.TakeLastExt(length).Average(); trendList.AddRounded(trend); - double fcast = t + (t - priorT); + var fcast = t + (t - priorT); fcastList.AddRounded(fcast); - double diff = Math.Abs(currentValue - prevFcast); + var diff = Math.Abs(currentValue - prevFcast); diffList.AddRounded(diff); - double diffSma = diffList.TakeLastExt(forecastLength).Average(); - double dev = diffSma * mult; + var diffSma = diffList.TakeLastExt(forecastLength).Average(); + var dev = diffSma * mult; - double upper = fcast + dev; + var upper = fcast + dev; upperList.AddRounded(upper); - double lower = fcast - dev; + var lower = fcast - dev; lowerList.AddRounded(lower); - double prevBullSlope = bullSlopeList.LastOrDefault(); - double bullSlope = currentValue - Math.Max(fcast, Math.Max(t, trend)); + var prevBullSlope = bullSlopeList.LastOrDefault(); + var bullSlope = currentValue - Math.Max(fcast, Math.Max(t, trend)); bullSlopeList.AddRounded(bullSlope); - double prevBearSlope = bearSlopeList.LastOrDefault(); - double bearSlope = currentValue - Math.Min(fcast, Math.Min(t, trend)); + var prevBearSlope = bearSlopeList.LastOrDefault(); + var bearSlope = currentValue - Math.Min(fcast, Math.Min(t, trend)); bearSlopeList.AddRounded(bearSlope); var signal = GetBullishBearishSignal(bullSlope, prevBullSlope, bearSlope, prevBearSlope); @@ -1192,44 +1192,44 @@ public static StockData CalculateCoralTrendIndicator(this StockData stockData, i List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double di = ((double)(length - 1) / 2) + 1; - double c1 = 2 / (di + 1); - double c2 = 1 - c1; - double c3 = 3 * ((cd * cd) + (cd * cd * cd)); - double c4 = -3 * ((2 * cd * cd) + cd + (cd * cd * cd)); - double c5 = (3 * cd) + 1 + (cd * cd * cd) + (3 * cd * cd); + var di = ((double)(length - 1) / 2) + 1; + var c1 = 2 / (di + 1); + var c2 = 1 - c1; + var c3 = 3 * ((cd * cd) + (cd * cd * cd)); + var c4 = -3 * ((2 * cd * cd) + cd + (cd * cd * cd)); + var c5 = (3 * cd) + 1 + (cd * cd * cd) + (3 * cd * cd); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevI1 = i1List.LastOrDefault(); - double i1 = (c1 * currentValue) + (c2 * prevI1); + var prevI1 = i1List.LastOrDefault(); + var i1 = (c1 * currentValue) + (c2 * prevI1); i1List.AddRounded(i1); - double prevI2 = i2List.LastOrDefault(); - double i2 = (c1 * i1) + (c2 * prevI2); + var prevI2 = i2List.LastOrDefault(); + var i2 = (c1 * i1) + (c2 * prevI2); i2List.AddRounded(i2); - double prevI3 = i3List.LastOrDefault(); - double i3 = (c1 * i2) + (c2 * prevI3); + var prevI3 = i3List.LastOrDefault(); + var i3 = (c1 * i2) + (c2 * prevI3); i3List.AddRounded(i3); - double prevI4 = i4List.LastOrDefault(); - double i4 = (c1 * i3) + (c2 * prevI4); + var prevI4 = i4List.LastOrDefault(); + var i4 = (c1 * i3) + (c2 * prevI4); i4List.AddRounded(i4); - double prevI5 = i5List.LastOrDefault(); - double i5 = (c1 * i4) + (c2 * prevI5); + var prevI5 = i5List.LastOrDefault(); + var i5 = (c1 * i4) + (c2 * prevI5); i5List.AddRounded(i5); - double prevI6 = i6List.LastOrDefault(); - double i6 = (c1 * i5) + (c2 * prevI6); + var prevI6 = i6List.LastOrDefault(); + var i6 = (c1 * i5) + (c2 * prevI6); i6List.AddRounded(i6); - double prevBfr = bfrList.LastOrDefault(); - double bfr = (-1 * cd * cd * cd * i6) + (c3 * i5) + (c4 * i4) + (c5 * i3); + var prevBfr = bfrList.LastOrDefault(); + var bfr = (-1 * cd * cd * cd * i6) + (c3 * i5) + (c4 * i4) + (c5 * i3); bfrList.AddRounded(bfr); var signal = GetCompareSignal(currentValue - bfr, prevValue - prevBfr); @@ -1261,24 +1261,24 @@ public static StockData CalculatePriceVolumeTrend(this StockData stockData, Movi List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevPvt = priceVolumeTrendList.LastOrDefault(); - double pvt = prevValue != 0 ? prevPvt + (currentVolume * (MinPastValues(i, 1, currentValue - prevValue) / prevValue)) : prevPvt; + var prevPvt = priceVolumeTrendList.LastOrDefault(); + var pvt = prevValue != 0 ? prevPvt + (currentVolume * (MinPastValues(i, 1, currentValue - prevValue) / prevValue)) : prevPvt; priceVolumeTrendList.AddRounded(pvt); } var pvtEmaList = GetMovingAverageList(stockData, maType, length, priceVolumeTrendList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pvt = priceVolumeTrendList[i]; - double pvtEma = pvtEmaList[i]; - double prevPvt = i >= 1 ? priceVolumeTrendList[i - 1] : 0; - double prevPvtEma = i >= 1 ? pvtEmaList[i - 1] : 0; + var pvt = priceVolumeTrendList[i]; + var pvtEma = pvtEmaList[i]; + var prevPvt = i >= 1 ? priceVolumeTrendList[i - 1] : 0; + var prevPvtEma = i >= 1 ? pvtEmaList[i - 1] : 0; var signal = GetCompareSignal(pvt - pvtEma, prevPvt - prevPvtEma); signalsList.Add(signal); @@ -1309,32 +1309,32 @@ public static StockData CalculatePercentageTrend(this StockData stockData, int l List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; - int period = 0; - double prevTrend = trendList.LastOrDefault(); - double trend = currentValue; - for (int j = 1; j <= length; j++) + var period = 0; + var prevTrend = trendList.LastOrDefault(); + var trend = currentValue; + for (var j = 1; j <= length; j++) { - double prevC = i >= j - 1 ? inputList[i - (j - 1)] : 0; - double currC = i >= j ? inputList[i - j] : 0; + var prevC = i >= j - 1 ? inputList[i - (j - 1)] : 0; + var currC = i >= j ? inputList[i - j] : 0; period = (prevC <= trend && currC > trend) || (prevC >= trend && currC < trend) ? 0 : period; double highest1 = currC, lowest1 = currC; - for (int k = j - period; k <= j; k++) + for (var k = j - period; k <= j; k++) { - double c = i >= j - k ? inputList[i - (j - k)] : 0; + var c = i >= j - k ? inputList[i - (j - k)] : 0; highest1 = Math.Max(highest1, c); lowest1 = Math.Min(lowest1, c); } double highest2 = currC, lowest2 = currC; - for (int k = i - length; k <= j; k++) + for (var k = i - length; k <= j; k++) { - double c = i >= j - k ? inputList[i - (j - k)] : 0; + var c = i >= j - k ? inputList[i - (j - k)] : 0; highest2 = Math.Max(highest2, c); lowest2 = Math.Min(lowest2, c); } @@ -1380,25 +1380,25 @@ public static StockData CalculateModifiedPriceVolumeTrend(this StockData stockDa List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentVolume = volumeList[i]; - double rv = currentVolume / 50000; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = volumeList[i]; + var rv = currentVolume / 50000; - double prevMpvt = mpvtList.LastOrDefault(); - double mpvt = prevValue != 0 ? prevMpvt + (rv * MinPastValues(i, 1, currentValue - prevValue) / prevValue) : 0; + var prevMpvt = mpvtList.LastOrDefault(); + var mpvt = prevValue != 0 ? prevMpvt + (rv * MinPastValues(i, 1, currentValue - prevValue) / prevValue) : 0; mpvtList.AddRounded(mpvt); } var mpvtSignalList = GetMovingAverageList(stockData, maType, length, mpvtList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mpvt = mpvtList[i]; - double mpvtSignal = mpvtSignalList[i]; - double prevMpvt = i >= 1 ? mpvtList[i - 1] : 0; - double prevMpvtSignal = i >= 1 ? mpvtSignalList[i - 1] : 0; + var mpvt = mpvtList[i]; + var mpvtSignal = mpvtSignalList[i]; + var prevMpvt = i >= 1 ? mpvtList[i - 1] : 0; + var prevMpvtSignal = i >= 1 ? mpvtSignalList[i - 1] : 0; var signal = GetCompareSignal(mpvt - mpvtSignal, prevMpvt - prevMpvtSignal); signalsList.Add(signal); diff --git a/src/Calculations/Volatility.cs b/src/Calculations/Volatility.cs index 52a02af..e91a995 100644 --- a/src/Calculations/Volatility.cs +++ b/src/Calculations/Volatility.cs @@ -29,36 +29,36 @@ public static StockData CalculateStandardDeviationVolatility(this StockData stoc var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double currentDeviation = currentValue - currentSma; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var currentDeviation = currentValue - currentSma; - double deviationSquared = Pow(currentDeviation, 2); + var deviationSquared = Pow(currentDeviation, 2); deviationSquaredList.AddRounded(deviationSquared); } var divisionOfSumList = GetMovingAverageList(stockData, maType, length, deviationSquaredList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double divisionOfSum = divisionOfSumList[i]; + var divisionOfSum = divisionOfSumList[i]; - double stdDevVolatility = Sqrt(divisionOfSum); + var stdDevVolatility = Sqrt(divisionOfSum); stdDevVolatilityList.AddRounded(stdDevVolatility); } var stdDevSmaList = GetMovingAverageList(stockData, maType, length, stdDevVolatilityList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; - double stdDev = stdDevVolatilityList[i]; - double stdDevMa = stdDevSmaList[i]; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; + var stdDev = stdDevVolatilityList[i]; + var stdDevMa = stdDevSmaList[i]; - Signal signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, stdDev, stdDevMa); + var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, stdDev, stdDevMa); signalsList.Add(signal); } @@ -89,32 +89,32 @@ public static StockData CalculateHistoricalVolatility(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double annualSqrt = Sqrt(365); + var annualSqrt = Sqrt(365); var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double temp = prevValue != 0 ? currentValue / prevValue : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var temp = prevValue != 0 ? currentValue / prevValue : 0; - double tempLog = temp > 0 ? Math.Log(temp) : 0; + var tempLog = temp > 0 ? Math.Log(temp) : 0; tempLogList.AddRounded(tempLog); } stockData.CustomValuesList = tempLogList; var stdDevLogList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var stdDevLog = stdDevLogList[i]; - double currentEma = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevHv = hvList.LastOrDefault(); - double hv = 100 * stdDevLog * annualSqrt; + var prevHv = hvList.LastOrDefault(); + var hv = 100 * stdDevLog * annualSqrt; hvList.AddRounded(hv); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, hv, prevHv); @@ -153,18 +153,18 @@ public static StockData CalculateMovingAverageBandWidth(this StockData stockData var lbList = mabList.OutputValues["LowerBand"]; var maList = mabList.OutputValues["MiddleBand"]; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mb = maList[i]; - double ub = ubList[i]; - double lb = lbList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMb = i >= 1 ? maList[i - 1] : 0; - double prevUb = i >= 1 ? ubList[i - 1] : 0; - double prevLb = i >= 1 ? lbList[i - 1] : 0; + var mb = maList[i]; + var ub = ubList[i]; + var lb = lbList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMb = i >= 1 ? maList[i - 1] : 0; + var prevUb = i >= 1 ? ubList[i - 1] : 0; + var prevLb = i >= 1 ? lbList[i - 1] : 0; - double mabw = mb != 0 ? (ub - lb) / mb * 100 : 0; + var mabw = mb != 0 ? (ub - lb) / mb * 100 : 0; mabwList.AddRounded(mabw); var signal = GetBollingerBandsSignal(currentValue - mb, prevValue - prevMb, currentValue, prevValue, ub, prevUb, lb, prevLb); @@ -203,32 +203,32 @@ public static StockData CalculateMovingAverageAdaptiveFilter(this StockData stoc var erList = CalculateKaufmanAdaptiveMovingAverage(stockData, length: length).OutputValues["Er"]; var emaList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevAma = i >= 1 ? amaList[i - 1] : currentValue; - double er = erList[i]; - double sm = Pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2); + var currentValue = inputList[i]; + var prevAma = i >= 1 ? amaList[i - 1] : currentValue; + var er = erList[i]; + var sm = Pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2); - double ama = prevAma + (sm * (currentValue - prevAma)); + var ama = prevAma + (sm * (currentValue - prevAma)); amaList.AddRounded(ama); - double amaDiff = ama - prevAma; + var amaDiff = ama - prevAma; amaDiffList.AddRounded(amaDiff); } stockData.CustomValuesList = amaDiffList; var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double stdDev = stdDevList[i]; - double currentValue = inputList[i]; - double ema = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var stdDev = stdDevList[i]; + var currentValue = inputList[i]; + var ema = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double prevMaaf = maafList.LastOrDefault(); - double maaf = stdDev * filter; + var prevMaaf = maafList.LastOrDefault(); + var maaf = stdDev * filter; maafList.AddRounded(maaf); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, maaf, prevMaaf); @@ -270,38 +270,38 @@ public static StockData CalculateRelativeNormalizedVolatility(this StockData sto var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var spStdDevList = CalculateStandardDeviationVolatility(marketData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double spValue = spInputList[i]; - double prevSpValue = i >= 1 ? spInputList[i - 1] : 0; - double stdDev = stdDevList[i]; - double spStdDev = spStdDevList[i]; - double d = MinPastValues(i, 1, currentValue - prevValue); - double sp = spValue - prevSpValue; - double zsrc = stdDev != 0 ? d / stdDev : 0; - double zsp = spStdDev != 0 ? sp / spStdDev : 0; - - double absZsrc = Math.Abs(zsrc); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var spValue = spInputList[i]; + var prevSpValue = i >= 1 ? spInputList[i - 1] : 0; + var stdDev = stdDevList[i]; + var spStdDev = spStdDevList[i]; + var d = MinPastValues(i, 1, currentValue - prevValue); + var sp = spValue - prevSpValue; + var zsrc = stdDev != 0 ? d / stdDev : 0; + var zsp = spStdDev != 0 ? sp / spStdDev : 0; + + var absZsrc = Math.Abs(zsrc); absZsrcList.AddRounded(absZsrc); - double absZsp = Math.Abs(zsp); + var absZsp = Math.Abs(zsp); absZspList.AddRounded(absZsp); } var absZsrcSmaList = GetMovingAverageList(stockData, maType, length, absZsrcList); var absZspSmaList = GetMovingAverageList(marketData, maType, length, absZspList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double absZsrcSma = absZsrcSmaList[i]; - double absZspSma = absZspSmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - - double r = absZspSma != 0 ? absZsrcSma / absZspSma : 0; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var absZsrcSma = absZsrcSmaList[i]; + var absZspSma = absZspSmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + + var r = absZspSma != 0 ? absZsrcSma / absZspSma : 0; rList.AddRounded(r); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, r, 1); @@ -336,37 +336,37 @@ public static StockData CalculateReversalPoints(this StockData stockData, Moving List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - double c = length + (length / Sqrt(length) / 2); - int length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); + var c = length + (length / Sqrt(length) / 2); + var length1 = MinOrMax((int)Math.Ceiling((double)length / 2)); var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double max = Math.Max(currentValue, prevValue); - double min = Math.Min(currentValue, prevValue); + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var max = Math.Max(currentValue, prevValue); + var min = Math.Min(currentValue, prevValue); - double a = max - min; + var a = max - min; aList.AddRounded(a); } var aEma1List = GetMovingAverageList(stockData, maType, length1, aList); var aEma2List = GetMovingAverageList(stockData, maType, length1, aEma1List); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double aEma1 = aEma1List[i]; - double aEma2 = aEma2List[i]; - double currentValue = inputList[i]; - double ema = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var aEma1 = aEma1List[i]; + var aEma2 = aEma2List[i]; + var currentValue = inputList[i]; + var ema = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double b = aEma2 != 0 ? aEma1 / aEma2 : 0; + var b = aEma2 != 0 ? aEma1 / aEma2 : 0; bList.AddRounded(b); - double bSum = bList.TakeLastExt(length).Sum(); + var bSum = bList.TakeLastExt(length).Sum(); bSumList.AddRounded(bSum); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, bSum, c); @@ -401,14 +401,14 @@ public static StockData CalculateMayerMultiple(this StockData stockData, MovingA var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; - double mm = currentSma != 0 ? currentValue / currentSma : 0; + var mm = currentSma != 0 ? currentValue / currentSma : 0; mmList.AddRounded(mm); var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, mm, threshold); @@ -442,27 +442,27 @@ public static StockData CalculateMotionSmoothnessIndex(this StockData stockData, var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; var emaList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double chg = MinPastValues(i, 1, currentValue - prevValue); + var chg = MinPastValues(i, 1, currentValue - prevValue); chgList.AddRounded(chg); } stockData.CustomValuesList = chgList; var aChgStdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double aChgStdDev = aChgStdDevList[i]; - double stdDev = stdDevList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var aChgStdDev = aChgStdDevList[i]; + var stdDev = stdDevList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double b = stdDev != 0 ? aChgStdDev / stdDev : 0; + var b = stdDev != 0 ? aChgStdDev / stdDev : 0; bList.AddRounded(b); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, b, 0.5); @@ -496,14 +496,14 @@ public static StockData CalculateMarketMeannessIndex(this StockData stockData, M var maList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double median = tempList.TakeLastExt(length).Median(); + var median = tempList.TakeLastExt(length).Median(); int nl = 0, nh = 0; - for (int j = 1; j < length; j++) + for (var j = 1; j < length; j++) { var value1 = i >= j - 1 ? tempList[i - (j - 1)] : 0; var value2 = i >= j ? tempList[i - j] : 0; @@ -523,7 +523,7 @@ public static StockData CalculateMarketMeannessIndex(this StockData stockData, M } var mmiFilterList = GetMovingAverageList(stockData, maType, length, mmiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var mmiFilt = mmiFilterList[i]; var prevMmiFilt1 = i >= 1 ? mmiFilterList[i - 1] : 0; @@ -531,7 +531,7 @@ public static StockData CalculateMarketMeannessIndex(this StockData stockData, M var currentValue = inputList[i]; var currentMa = maList[i]; - Signal signal = GetConditionSignal(currentValue < currentMa && ((mmiFilt > prevMmiFilt1 && prevMmiFilt1 < prevMmiFilt2) || (mmiFilt < prevMmiFilt1 && prevMmiFilt1 > prevMmiFilt2)), currentValue < currentMa && ((mmiFilt > prevMmiFilt1 && prevMmiFilt1 < prevMmiFilt2) || (mmiFilt < prevMmiFilt1 && prevMmiFilt1 > prevMmiFilt2))); + var signal = GetConditionSignal(currentValue < currentMa && ((mmiFilt > prevMmiFilt1 && prevMmiFilt1 < prevMmiFilt2) || (mmiFilt < prevMmiFilt1 && prevMmiFilt1 > prevMmiFilt2)), currentValue < currentMa && ((mmiFilt > prevMmiFilt1 && prevMmiFilt1 < prevMmiFilt2) || (mmiFilt < prevMmiFilt1 && prevMmiFilt1 > prevMmiFilt2))); signalsList.Add(signal); } @@ -565,23 +565,23 @@ public static StockData CalculateChoppinessIndex(this StockData stockData, Movin var (highestHighList, lowestLowList) = GetMaxAndMinValuesList(highList, lowList, length); var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double highestHigh = highestHighList[i]; - double lowestLow = lowestLowList[i]; - double range = highestHigh - lowestLow; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var highestHigh = highestHighList[i]; + var lowestLow = lowestLowList[i]; + var range = highestHigh - lowestLow; - double tr = CalculateTrueRange(currentHigh, currentLow, prevValue); + var tr = CalculateTrueRange(currentHigh, currentLow, prevValue); trList.AddRounded(tr); - double trSum = trList.TakeLastExt(length).Sum(); - double ci = range > 0 ? 100 * Math.Log10(trSum / range) / Math.Log10(length) : 0; + var trSum = trList.TakeLastExt(length).Sum(); + var ci = range > 0 ? 100 * Math.Log10(trSum / range) / Math.Log10(length) : 0; ciList.AddRounded(ci); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, ci, 38.2); @@ -616,18 +616,18 @@ public static StockData CalculateUltimateVolatilityIndicator(this StockData stoc var maList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double currentMa = maList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevMa = i >= 1 ? maList[i - 1] : 0; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var currentMa = maList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevMa = i >= 1 ? maList[i - 1] : 0; - double abs = Math.Abs(currentClose - currentOpen); + var abs = Math.Abs(currentClose - currentOpen); absList.AddRounded(abs); - double uvi = (double)1 / length * absList.TakeLastExt(length).Sum(); + var uvi = (double)1 / length * absList.TakeLastExt(length).Sum(); uviList.AddRounded(uvi); var signal = GetVolatilitySignal(currentClose - currentMa, prevClose - prevMa, uvi, 1); @@ -661,17 +661,17 @@ public static StockData CalculateQmaSmaDifference(this StockData stockData, int var smaList = CalculateSimpleMovingAverage(stockData, length).CustomValuesList; var emaList = CalculateExponentialMovingAverage(stockData, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double sma = smaList[i]; - double qma = qmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var sma = smaList[i]; + var qma = qmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double prevC = cList.LastOrDefault(); - double c = qma - sma; + var prevC = cList.LastOrDefault(); + var c = qma - sma; cList.AddRounded(c); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, c, prevC); @@ -707,25 +707,25 @@ public static StockData CalculateGarmanKlassVolatility(this StockData stockData, var wmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double logHl = currentLow != 0 ? Math.Log(currentHigh / currentLow) : 0; - double logCo = currentOpen != 0 ? Math.Log(currentClose / currentOpen) : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var logHl = currentLow != 0 ? Math.Log(currentHigh / currentLow) : 0; + var logCo = currentOpen != 0 ? Math.Log(currentClose / currentOpen) : 0; - double log = (0.5 * Pow(logHl, 2)) - (((2 * Math.Log(2)) - 1) * Pow(logCo, 2)); + var log = (0.5 * Pow(logHl, 2)) - (((2 * Math.Log(2)) - 1) * Pow(logCo, 2)); logList.AddRounded(log); - double logSum = logList.TakeLastExt(length).Sum(); - double gcv = length != 0 && logSum != 0 ? Sqrt((double)i / length * logSum) : 0; + var logSum = logList.TakeLastExt(length).Sum(); + var gcv = length != 0 && logSum != 0 ? Sqrt((double)i / length * logSum) : 0; gcvList.AddRounded(gcv); } var gcvWmaList = GetMovingAverageList(stockData, maType, signalLength, gcvList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var currentClose = inputList[i]; var wma = wmaList[i]; @@ -768,19 +768,19 @@ public static StockData CalculateGopalakrishnanRangeIndex(this StockData stockDa var wmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double highestHigh = highestList[i]; - double lowestLow = lowestList[i]; - double range = highestHigh - lowestLow; - double rangeLog = range > 0 ? Math.Log(range) : 0; + var highestHigh = highestList[i]; + var lowestLow = lowestList[i]; + var range = highestHigh - lowestLow; + var rangeLog = range > 0 ? Math.Log(range) : 0; - double gapo = rangeLog / Math.Log(length); + var gapo = rangeLog / Math.Log(length); gapoList.AddRounded(gapo); } var gapoWmaList = GetMovingAverageList(stockData, maType, length, gapoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var gapoWma = gapoWmaList[i]; var prevGapoWma = i >= 1 ? gapoWmaList[i - 1] : 0; @@ -827,41 +827,41 @@ public static StockData CalculateHistoricalVolatilityPercentile(this StockData s var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEma = emaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double temp = prevValue != 0 ? currentValue / prevValue : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentEma = emaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var temp = prevValue != 0 ? currentValue / prevValue : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double tempLog = temp > 0 ? Math.Log(temp) : 0; + var tempLog = temp > 0 ? Math.Log(temp) : 0; tempLogList.AddRounded(tempLog); - double avgLog = tempLogList.TakeLastExt(length).Average(); - double devLogSq = Pow(tempLog - avgLog, 2); + var avgLog = tempLogList.TakeLastExt(length).Average(); + var devLogSq = Pow(tempLog - avgLog, 2); devLogSqList.AddRounded(devLogSq); - double devLogSqAvg = devLogSqList.TakeLastExt(length).Sum() / (length - 1); - double stdDevLog = devLogSqAvg >= 0 ? Sqrt(devLogSqAvg) : 0; + var devLogSqAvg = devLogSqList.TakeLastExt(length).Sum() / (length - 1); + var stdDevLog = devLogSqAvg >= 0 ? Sqrt(devLogSqAvg) : 0; - double hv = stdDevLog * Sqrt(annualLength); + var hv = stdDevLog * Sqrt(annualLength); hvList.AddRounded(hv); double count = hvList.TakeLastExt(annualLength).Where(i => i < hv).Count(); - double hvp = count / annualLength * 100; + var hvp = count / annualLength * 100; hvpList.AddRounded(hvp); } var hvpEmaList = GetMovingAverageList(stockData, maType, length, hvpList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentEma = emaList[i]; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double hvp = hvpList[i]; - double hvpEma = hvpEmaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentEma = emaList[i]; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var hvp = hvpList[i]; + var hvpEma = hvpEmaList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, hvp, hvpEma); signalsList.Add(signal); @@ -892,7 +892,7 @@ public static StockData CalculateFastZScore(this StockData stockData, MovingAvgT List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - int length2 = MinOrMax((int)Math.Ceiling((double)length / 2)); + var length2 = MinOrMax((int)Math.Ceiling((double)length / 2)); var smaList = GetMovingAverageList(stockData, maType, length, inputList); stockData.CustomValuesList = smaList; @@ -902,17 +902,17 @@ public static StockData CalculateFastZScore(this StockData stockData, MovingAvgT stockData.CustomValuesList = smaList; var smaStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double sma = smaList[i]; - double stdDev = smaStdDevList[i]; - double linreg = smaLinregList[i]; - double linreg2 = linreg2List[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; + var currentValue = inputList[i]; + var sma = smaList[i]; + var stdDev = smaStdDevList[i]; + var linreg = smaLinregList[i]; + var linreg2 = linreg2List[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; - double gs = stdDev != 0 ? (linreg2 - linreg) / stdDev / 2 : 0; + var gs = stdDev != 0 ? (linreg2 - linreg) / stdDev / 2 : 0; gsList.AddRounded(gs); var signal = GetVolatilitySignal(currentValue - sma, prevValue - prevSma, gs, 0); @@ -944,13 +944,13 @@ public static StockData CalculateVolatilitySwitchIndicator(this StockData stockD List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double rocSma = (currentValue + prevValue) / 2; - double dr = rocSma != 0 ? MinPastValues(i, 1, currentValue - prevValue) / rocSma : 0; + var rocSma = (currentValue + prevValue) / 2; + var dr = rocSma != 0 ? MinPastValues(i, 1, currentValue - prevValue) / rocSma : 0; drList.AddRounded(dr); } @@ -958,13 +958,13 @@ public static StockData CalculateVolatilitySwitchIndicator(this StockData stockD var volaList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; var vswitchList = GetMovingAverageList(stockData, maType, length, volaList); var wmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentWma = wmaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevWma = i >= 1 ? wmaList[i - 1] : 0; - double vswitch14 = vswitchList[i]; + var currentValue = inputList[i]; + var currentWma = wmaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevWma = i >= 1 ? wmaList[i - 1] : 0; + var vswitch14 = vswitchList[i]; var signal = GetVolatilitySignal(currentValue - currentWma, prevValue - prevWma, vswitch14, 0.5); signalsList.Add(signal); @@ -1000,31 +1000,31 @@ public static StockData CalculateVerticalHorizontalFilter(this StockData stockDa var wmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentValue = inputList[i]; - double highestPrice = highestList[i]; - double lowestPrice = lowestList[i]; - double numerator = Math.Abs(highestPrice - lowestPrice); + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var highestPrice = highestList[i]; + var lowestPrice = lowestList[i]; + var numerator = Math.Abs(highestPrice - lowestPrice); - double priceChange = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); + var priceChange = Math.Abs(MinPastValues(i, 1, currentValue - prevValue)); changeList.AddRounded(priceChange); - double denominator = changeList.TakeLastExt(length).Sum(); - double vhf = denominator != 0 ? numerator / denominator : 0; + var denominator = changeList.TakeLastExt(length).Sum(); + var vhf = denominator != 0 ? numerator / denominator : 0; vhfList.AddRounded(vhf); } var vhfWmaList = GetMovingAverageList(stockData, maType, signalLength, vhfList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentWma = wmaList[i]; - double prevWma = i >= 1 ? wmaList[i - 1] : 0; - double vhfWma = vhfWmaList[i]; - double vhf = vhfList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentWma = wmaList[i]; + var prevWma = i >= 1 ? wmaList[i - 1] : 0; + var vhfWma = vhfWmaList[i]; + var vhf = vhfList[i]; var signal = GetVolatilitySignal(currentValue - currentWma, prevValue - prevWma, vhf, vhfWma); signalsList.Add(signal); @@ -1060,25 +1060,25 @@ public static StockData CalculateClosedFormDistanceVolatility(this StockData sto var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double ema = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; + var currentValue = inputList[i]; + var ema = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; - double currentHigh = highList[i]; + var currentHigh = highList[i]; tempHighList.AddRounded(currentHigh); - double currentLow = lowList[i]; + var currentLow = lowList[i]; tempLowList.AddRounded(currentLow); - double a = tempHighList.TakeLastExt(length).Sum(); - double b = tempLowList.TakeLastExt(length).Sum(); - double abAvg = (a + b) / 2; + var a = tempHighList.TakeLastExt(length).Sum(); + var b = tempLowList.TakeLastExt(length).Sum(); + var abAvg = (a + b) / 2; - double prevHv = hvList.LastOrDefault(); - double hv = abAvg != 0 && a != b ? Sqrt(1 - (Pow(a, 0.25) * Pow(b, 0.25) / Pow(abAvg, 0.5))) : 0; + var prevHv = hvList.LastOrDefault(); + var hv = abAvg != 0 && a != b ? Sqrt(1 - (Pow(a, 0.25) * Pow(b, 0.25) / Pow(abAvg, 0.5))) : 0; hvList.AddRounded(hv); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, hv, prevHv); @@ -1116,25 +1116,25 @@ public static StockData CalculateProjectionOscillator(this StockData stockData, var plList = projectionBandsList.OutputValues["LowerBand"]; var wmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double pl = plList[i]; - double pu = puList[i]; + var currentValue = inputList[i]; + var pl = plList[i]; + var pu = puList[i]; - double pbo = pu - pl != 0 ? 100 * (currentValue - pl) / (pu - pl) : 0; + var pbo = pu - pl != 0 ? 100 * (currentValue - pl) / (pu - pl) : 0; pboList.AddRounded(pbo); } var pboSignalList = GetMovingAverageList(stockData, maType, smoothLength, pboList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pbo = pboSignalList[i]; - double prevPbo = i >= 1 ? pboSignalList[i - 1] : 0; - double wma = wmaList[i]; - double currentValue = inputList[i]; - double prevWma = i >= 1 ? wmaList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var pbo = pboSignalList[i]; + var prevPbo = i >= 1 ? pboSignalList[i - 1] : 0; + var wma = wmaList[i]; + var currentValue = inputList[i]; + var prevWma = i >= 1 ? wmaList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; var signal = GetVolatilitySignal(currentValue - wma, prevValue - prevWma, pbo, prevPbo); signalsList.Add(signal); @@ -1171,24 +1171,24 @@ public static StockData CalculateProjectionBandwidth(this StockData stockData, M var plList = projectionBandsList.OutputValues["LowerBand"]; var wmaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pu = puList[i]; - double pl = plList[i]; + var pu = puList[i]; + var pl = plList[i]; - double pbw = pu + pl != 0 ? 200 * (pu - pl) / (pu + pl) : 0; + var pbw = pu + pl != 0 ? 200 * (pu - pl) / (pu + pl) : 0; pbwList.AddRounded(pbw); } var pbwSignalList = GetMovingAverageList(stockData, maType, length, pbwList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pbw = pbwList[i]; - double pbwSignal = pbwSignalList[i]; - double wma = wmaList[i]; - double currentValue = inputList[i]; - double prevWma = i >= 1 ? wmaList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var pbw = pbwList[i]; + var pbwSignal = pbwSignalList[i]; + var wma = wmaList[i]; + var currentValue = inputList[i]; + var prevWma = i >= 1 ? wmaList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; var signal = GetVolatilitySignal(currentValue - wma, prevValue - prevWma, pbw, pbwSignal); signalsList.Add(signal); @@ -1224,24 +1224,24 @@ public static StockData CalculateDonchianChannelWidth(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double upper = highestList[i]; - double lower = lowestList[i]; + var upper = highestList[i]; + var lower = lowestList[i]; - double donchianWidth = upper - lower; + var donchianWidth = upper - lower; donchianWidthList.AddRounded(donchianWidth); } var donchianWidthSmaList = GetMovingAverageList(stockData, maType, smoothLength, donchianWidthList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentSma = smaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevSma = i >= 1 ? smaList[i - 1] : 0; - double donchianWidth = donchianWidthList[i]; - double donchianWidthSma = donchianWidthSmaList[i]; + var currentValue = inputList[i]; + var currentSma = smaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevSma = i >= 1 ? smaList[i - 1] : 0; + var donchianWidth = donchianWidthList[i]; + var donchianWidthSma = donchianWidthSmaList[i]; var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, donchianWidth, donchianWidthSma); signalsList.Add(signal); @@ -1276,32 +1276,32 @@ public static StockData CalculateStatisticalVolatility(this StockData stockData, var (highestList1, lowestList1) = GetMaxAndMinValuesList(inputList, length1); var (highestList2, lowestList2) = GetMaxAndMinValuesList(highList, lowList, length1); - double annualSqrt = Sqrt((double)length2 / length1); + var annualSqrt = Sqrt((double)length2 / length1); var emaList = GetMovingAverageList(stockData, maType, length1, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double maxC = highestList1[i]; - double minC = lowestList1[i]; - double maxH = highestList2[i]; - double minL = lowestList2[i]; - double cLog = minC != 0 ? Math.Log(maxC / minC) : 0; - double hlLog = minL != 0 ? Math.Log(maxH / minL) : 0; + var maxC = highestList1[i]; + var minC = lowestList1[i]; + var maxH = highestList2[i]; + var minL = lowestList2[i]; + var cLog = minC != 0 ? Math.Log(maxC / minC) : 0; + var hlLog = minL != 0 ? Math.Log(maxH / minL) : 0; - double vol = MinOrMax(((0.6 * cLog * annualSqrt) + (0.6 * hlLog * annualSqrt)) * 0.5, 2.99, 0); + var vol = MinOrMax(((0.6 * cLog * annualSqrt) + (0.6 * hlLog * annualSqrt)) * 0.5, 2.99, 0); volList.AddRounded(vol); } var volEmaList = GetMovingAverageList(stockData, maType, length1, volList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEma = emaList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double vol = volList[i]; - double volEma = volEmaList[i]; + var currentEma = emaList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var vol = volList[i]; + var volEma = volEmaList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, vol, volEma); signalsList.Add(signal); @@ -1337,39 +1337,39 @@ public static StockData CalculateStandardDevation(this StockData stockData, Movi var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double sum = tempList.TakeLastExt(length).Sum(); - double sumPow = Pow(sum, 2); + var sum = tempList.TakeLastExt(length).Sum(); + var sumPow = Pow(sum, 2); sumList.AddRounded(sumPow); - double pow = Pow(currentValue, 2); + var pow = Pow(currentValue, 2); powList.AddRounded(pow); } var powSmaList = GetMovingAverageList(stockData, maType, length, powList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double a = powSmaList[i]; - double sum = sumList[i]; - double b = sum / Pow(length, 2); + var a = powSmaList[i]; + var sum = sumList[i]; + var b = sum / Pow(length, 2); - double c = a - b >= 0 ? Sqrt(a - b) : 0; + var c = a - b >= 0 ? Sqrt(a - b) : 0; cList.AddRounded(c); } var cSmaList = GetMovingAverageList(stockData, maType, length, cList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentEma = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double c = cList[i]; - double cSma = cSmaList[i]; + var currentValue = inputList[i]; + var currentEma = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var c = cList[i]; + var cSma = cSmaList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, c, cSma); signalsList.Add(signal); @@ -1404,24 +1404,24 @@ public static StockData CalculateVolatilityBasedMomentum(this StockData stockDat var atrList = CalculateAverageTrueRange(stockData, maType, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentAtr = atrList[i]; - double currentValue = inputList[i]; - double prevValue = i >= length1 ? inputList[i - length1] : 0; - double rateOfChange = MinPastValues(i, length1, currentValue - prevValue); + var currentAtr = atrList[i]; + var currentValue = inputList[i]; + var prevValue = i >= length1 ? inputList[i - length1] : 0; + var rateOfChange = MinPastValues(i, length1, currentValue - prevValue); - double vbm = currentAtr != 0 ? rateOfChange / currentAtr : 0; + var vbm = currentAtr != 0 ? rateOfChange / currentAtr : 0; vbmList.AddRounded(vbm); } var vbmEmaList = GetMovingAverageList(stockData, maType, length1, vbmList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vbm = vbmList[i]; - double vbmEma = vbmEmaList[i]; - double prevVbm = i >= 1 ? vbmList[i - 1] : 0; - double prevVbmEma = i >= 1 ? vbmEmaList[i - 1] : 0; + var vbm = vbmList[i]; + var vbmEma = vbmEmaList[i]; + var prevVbm = i >= 1 ? vbmList[i - 1] : 0; + var prevVbmEma = i >= 1 ? vbmEmaList[i - 1] : 0; var signal = GetCompareSignal(vbm - vbmEma, prevVbm - prevVbmEma); signalsList.Add(signal); @@ -1456,35 +1456,35 @@ public static StockData CalculateVolatilityQualityIndex(this StockData stockData List signalsList = new(); var (inputList, highList, lowList, openList, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; - double currentOpen = openList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double trueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; + var currentOpen = openList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var trueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); - double prevVqiT = vqiTList.LastOrDefault(); - double vqiT = trueRange != 0 && currentHigh - currentLow != 0 ? + var prevVqiT = vqiTList.LastOrDefault(); + var vqiT = trueRange != 0 && currentHigh - currentLow != 0 ? (((currentClose - prevClose) / trueRange) + ((currentClose - currentOpen) / (currentHigh - currentLow))) * 0.5 : prevVqiT; vqiTList.AddRounded(vqiT); - double vqi = Math.Abs(vqiT) * ((currentClose - prevClose + (currentClose - currentOpen)) * 0.5); + var vqi = Math.Abs(vqiT) * ((currentClose - prevClose + (currentClose - currentOpen)) * 0.5); vqiList.AddRounded(vqi); - double vqiSum = vqiList.Sum(); + var vqiSum = vqiList.Sum(); vqiSumList.AddRounded(vqiSum); } var vqiSumFastSmaList = GetMovingAverageList(stockData, maType, fastLength, vqiSumList); var vqiSumSlowSmaList = GetMovingAverageList(stockData, maType, slowLength, vqiSumList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vqiSum = vqiSumList[i]; - double vqiSumFastSma = vqiSumFastSmaList[i]; - double prevVqiSum = i >= 1 ? vqiSumList[i - 1] : 0; - double prevVqiSumFastSma = i >= 1 ? vqiSumFastSmaList[i - 1] : 0; + var vqiSum = vqiSumList[i]; + var vqiSumFastSma = vqiSumFastSmaList[i]; + var prevVqiSum = i >= 1 ? vqiSumList[i - 1] : 0; + var prevVqiSumFastSma = i >= 1 ? vqiSumFastSmaList[i - 1] : 0; var signal = GetCompareSignal(vqiSum - vqiSumFastSma, prevVqiSum - prevVqiSumFastSma); signalsList.Add(signal); @@ -1517,31 +1517,31 @@ public static StockData CalculateSigmaSpikes(this StockData stockData, MovingAvg List signalsList = new(); var (inputList, _, _, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; + var ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; retList.AddRounded(ret); } stockData.CustomValuesList = retList; var stdList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double prevStd = i >= 1 ? stdList[i - 1] : 0; - double ret = retList[i]; + var prevStd = i >= 1 ? stdList[i - 1] : 0; + var ret = retList[i]; - double sigma = prevStd != 0 ? ret / prevStd : 0; + var sigma = prevStd != 0 ? ret / prevStd : 0; sigmaList.AddRounded(sigma); } var ssList = GetMovingAverageList(stockData, maType, length, sigmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ss = ssList[i]; - double prevSs = i >= 1 ? ssList[i - 1] : 0; + var ss = ssList[i]; + var prevSs = i >= 1 ? ssList[i - 1] : 0; var signal = GetCompareSignal(ss, prevSs); signalsList.Add(signal); @@ -1578,30 +1578,30 @@ public static StockData CalculateSurfaceRoughnessEstimator(this StockData stockD var emaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; tempList.AddRounded(currentValue); - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; prevList.AddRounded(prevValue); var corr = GoodnessOfFit.R(prevList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - double a = 1 - (((double)corr + 1) / 2); + var a = 1 - (((double)corr + 1) / 2); aList.AddRounded(a); } var aEmaList = GetMovingAverageList(stockData, maType, length, aList); - for (int i = 0; i < stockData.Count; i++) - { - double corr = corrList[i]; - double currentValue = inputList[i]; - double ema = emaList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevEma = i >= 1 ? emaList[i - 1] : 0; - double a = aList[i]; - double aEma = aEmaList[i]; + for (var i = 0; i < stockData.Count; i++) + { + var corr = corrList[i]; + var currentValue = inputList[i]; + var ema = emaList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevEma = i >= 1 ? emaList[i - 1] : 0; + var a = aList[i]; + var aEma = aEmaList[i]; var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, a, aEma); signalsList.Add(signal); diff --git a/src/Calculations/Volume.cs b/src/Calculations/Volume.cs index d189371..d901b58 100644 --- a/src/Calculations/Volume.cs +++ b/src/Calculations/Volume.cs @@ -25,22 +25,22 @@ public static StockData CalculateForceIndex(this StockData stockData, MovingAvgT List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double rawForce = MinPastValues(i, 1, currentValue - prevValue) * currentVolume; + var rawForce = MinPastValues(i, 1, currentValue - prevValue) * currentVolume; rawForceList.AddRounded(rawForce); } var forceList = GetMovingAverageList(stockData, maType, length, rawForceList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double force = forceList[i]; - double prevForce1 = i >= 1 ? forceList[i - 1] : 0; - double prevForce2 = i >= 2 ? forceList[i - 2] : 0; + var force = forceList[i]; + var prevForce1 = i >= 1 ? forceList[i - 1] : 0; + var prevForce2 = i >= 2 ? forceList[i - 2] : 0; var signal = GetCompareSignal(force - prevForce1, prevForce1 - prevForce2); signalsList.Add(signal); @@ -72,26 +72,26 @@ public static StockData CalculateMoneyFlowIndex(this StockData stockData, InputN List signalsList = new(); var (inputList, _, _, _, _, volumeList) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentVolume = volumeList[i]; - double typicalPrice = inputList[i]; - double prevTypicalPrice = i >= 1 ? inputList[i - 1] : 0; - double prevMfi1 = i >= 1 ? mfiList[i - 1] : 0; - double prevMfi2 = i >= 2 ? mfiList[i - 2] : 0; - double rawMoneyFlow = typicalPrice * currentVolume; + var currentVolume = volumeList[i]; + var typicalPrice = inputList[i]; + var prevTypicalPrice = i >= 1 ? inputList[i - 1] : 0; + var prevMfi1 = i >= 1 ? mfiList[i - 1] : 0; + var prevMfi2 = i >= 2 ? mfiList[i - 2] : 0; + var rawMoneyFlow = typicalPrice * currentVolume; - double posMoneyFlow = i >= 1 && typicalPrice > prevTypicalPrice ? rawMoneyFlow : 0; + var posMoneyFlow = i >= 1 && typicalPrice > prevTypicalPrice ? rawMoneyFlow : 0; posMoneyFlowList.AddRounded(posMoneyFlow); - double negMoneyFlow = i >= 1 && typicalPrice < prevTypicalPrice ? rawMoneyFlow : 0; + var negMoneyFlow = i >= 1 && typicalPrice < prevTypicalPrice ? rawMoneyFlow : 0; negMoneyFlowList.AddRounded(negMoneyFlow); - double posMoneyFlowTotal = posMoneyFlowList.TakeLastExt(length).Sum(); - double negMoneyFlowTotal = negMoneyFlowList.TakeLastExt(length).Sum(); - double mfiRatio = negMoneyFlowTotal != 0 ? posMoneyFlowTotal / negMoneyFlowTotal : 0; + var posMoneyFlowTotal = posMoneyFlowList.TakeLastExt(length).Sum(); + var negMoneyFlowTotal = negMoneyFlowList.TakeLastExt(length).Sum(); + var mfiRatio = negMoneyFlowTotal != 0 ? posMoneyFlowTotal / negMoneyFlowTotal : 0; - double mfi = negMoneyFlowTotal == 0 ? 100 : posMoneyFlowTotal == 0 ? 0 : MinOrMax(100 - (100 / (1 + mfiRatio)), 100, 0); + var mfi = negMoneyFlowTotal == 0 ? 100 : posMoneyFlowTotal == 0 ? 0 : MinOrMax(100 - (100 / (1 + mfiRatio)), 100, 0); mfiList.AddRounded(mfi); var signal = GetRsiSignal(mfi - prevMfi1, prevMfi1 - prevMfi2, mfi, prevMfi1, 80, 20); @@ -130,51 +130,51 @@ public static StockData CalculateKlingerVolumeOscillator(this StockData stockDat List signalsList = new(); var (inputList, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double mom = MinPastValues(i, 1, currentValue - prevValue); + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var mom = MinPastValues(i, 1, currentValue - prevValue); - double prevTrend = trendList.LastOrDefault(); - double trend = mom > 0 ? 1 : mom < 0 ? -1 : prevTrend; + var prevTrend = trendList.LastOrDefault(); + var trend = mom > 0 ? 1 : mom < 0 ? -1 : prevTrend; trendList.AddRounded(trend); - double prevDm = dmList.LastOrDefault(); - double dm = currentHigh - currentLow; + var prevDm = dmList.LastOrDefault(); + var dm = currentHigh - currentLow; dmList.AddRounded(dm); - double prevCm = cmList.LastOrDefault(); - double cm = trend == prevTrend ? prevCm + dm : prevDm + dm; + var prevCm = cmList.LastOrDefault(); + var cm = trend == prevTrend ? prevCm + dm : prevDm + dm; cmList.AddRounded(cm); - double temp = cm != 0 ? Math.Abs((2 * (dm / cm)) - 1) : -1; - double vf = currentVolume * temp * trend * 100; + var temp = cm != 0 ? Math.Abs((2 * (dm / cm)) - 1) : -1; + var vf = currentVolume * temp * trend * 100; vfList.AddRounded(vf); } var ema34List = GetMovingAverageList(stockData, maType, fastLength, vfList); var ema55List = GetMovingAverageList(stockData, maType, slowLength, vfList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ema34 = ema34List[i]; - double ema55 = ema55List[i]; + var ema34 = ema34List[i]; + var ema55 = ema55List[i]; - double klingerOscillator = ema34 - ema55; + var klingerOscillator = ema34 - ema55; kvoList.AddRounded(klingerOscillator); } var kvoSignalList = GetMovingAverageList(stockData, maType, signalLength, kvoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double klingerOscillator = kvoList[i]; - double koSignalLine = kvoSignalList[i]; + var klingerOscillator = kvoList[i]; + var koSignalLine = kvoSignalList[i]; - double prevKlingerOscillatorHistogram = kvoHistoList.LastOrDefault(); - double klingerOscillatorHistogram = klingerOscillator - koSignalLine; + var prevKlingerOscillatorHistogram = kvoHistoList.LastOrDefault(); + var klingerOscillatorHistogram = klingerOscillator - koSignalLine; kvoHistoList.AddRounded(klingerOscillatorHistogram); var signal = GetCompareSignal(klingerOscillatorHistogram, prevKlingerOscillatorHistogram); @@ -207,24 +207,24 @@ public static StockData CalculateOnBalanceVolume(this StockData stockData, Movin List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevObv = obvList.LastOrDefault(); - double obv = currentValue > prevValue ? prevObv + currentVolume : currentValue < prevValue ? prevObv - currentVolume : prevObv; + var prevObv = obvList.LastOrDefault(); + var obv = currentValue > prevValue ? prevObv + currentVolume : currentValue < prevValue ? prevObv - currentVolume : prevObv; obvList.AddRounded(obv); } var obvSignalList = GetMovingAverageList(stockData, maType, length, obvList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double obv = obvList[i]; - double prevObv = i >= 1 ? obvList[i - 1] : 0; - double obvSig = obvSignalList[i]; - double prevObvSig = i >= 1 ? obvSignalList[i - 1] : 0; + var obv = obvList[i]; + var prevObv = i >= 1 ? obvList[i - 1] : 0; + var obvSig = obvSignalList[i]; + var prevObvSig = i >= 1 ? obvSignalList[i - 1] : 0; var signal = GetCompareSignal(obv - obvSig, prevObv - prevObvSig); signalsList.Add(signal); @@ -254,27 +254,28 @@ public static StockData CalculateNegativeVolumeIndex(this StockData stockData, M List nviList = new(); List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); + const int initialNvi = 1000; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentVolume = volumeList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevVolume = i >= 1 ? volumeList[i - 1] : 0; - double pctChg = CalculatePercentChange(currentClose, prevClose); + var currentClose = inputList[i]; + var currentVolume = volumeList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevVolume = i >= 1 ? volumeList[i - 1] : 0; + var prevNvi = i >= 1 ? nviList[i - 1] : initialNvi; + var pctChg = CalculatePercentChange(currentClose, prevClose); - double prevNvi = nviList.LastOrDefault(); - double nvi = currentVolume >= prevVolume ? prevNvi : prevNvi + (prevNvi * pctChg); + var nvi = currentVolume >= prevVolume ? prevNvi : prevNvi + (prevNvi * pctChg); nviList.AddRounded(nvi); } var nviSignalList = GetMovingAverageList(stockData, maType, length, nviList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nvi = nviList[i]; - double prevNvi = i >= 1 ? nviList[i - 1] : 0; - double nviSignal = nviSignalList[i]; - double prevNviSignal = i >= 1 ? nviSignalList[i - 1] : 0; + var nvi = nviList[i]; + var prevNvi = i >= 1 ? nviList[i - 1] : 0; + var nviSignal = nviSignalList[i]; + var prevNviSignal = i >= 1 ? nviSignalList[i - 1] : 0; var signal = GetCompareSignal(nvi - nviSignal, prevNvi - prevNviSignal); signalsList.Add(signal); @@ -304,27 +305,28 @@ public static StockData CalculatePositiveVolumeIndex(this StockData stockData, M List pviList = new(); List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); + const int initialPvi = 1000; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentClose = inputList[i]; - double currentVolume = volumeList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevVolume = i >= 1 ? volumeList[i - 1] : 0; - double pctChg = CalculatePercentChange(currentClose, prevClose); + var currentClose = inputList[i]; + var currentVolume = volumeList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevVolume = i >= 1 ? volumeList[i - 1] : 0; + var prevPvi = i >= 1 ? pviList[i - 1] : initialPvi; + var pctChg = CalculatePercentChange(currentClose, prevClose); - double prevPvi = pviList.LastOrDefault(); - double pvi = currentVolume <= prevVolume ? prevPvi : prevPvi + (prevPvi * pctChg); + var pvi = currentVolume <= prevVolume ? prevPvi : prevPvi + (prevPvi * pctChg); pviList.AddRounded(pvi); } var pviSignalList = GetMovingAverageList(stockData, maType, length, pviList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double pvi = pviList[i]; - double prevPvi = i >= 1 ? pviList[i - 1] : 0; - double pviSignal = pviSignalList[i]; - double prevPviSignal = i >= 1 ? pviSignalList[i - 1] : 0; + var pvi = pviList[i]; + var prevPvi = i >= 1 ? pviList[i - 1] : 0; + var pviSignal = pviSignalList[i]; + var prevPviSignal = i >= 1 ? pviSignalList[i - 1] : 0; var signal = GetCompareSignal(pvi - pviSignal, prevPvi - prevPviSignal); signalsList.Add(signal); @@ -356,26 +358,26 @@ public static StockData CalculateChaikinMoneyFlow(this StockData stockData, int List signalsList = new(); var (inputList, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentLow = lowList[i]; - double currentHigh = highList[i]; - double currentClose = inputList[i]; - double moneyFlowMultiplier = currentHigh - currentLow != 0 ? + var currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentClose = inputList[i]; + var moneyFlowMultiplier = currentHigh - currentLow != 0 ? (currentClose - currentLow - (currentHigh - currentClose)) / (currentHigh - currentLow) : 0; - double prevCmf1 = i >= 1 ? chaikinMoneyFlowList[i - 1] : 0; - double prevCmf2 = i >= 2 ? chaikinMoneyFlowList[i - 2] : 0; + var prevCmf1 = i >= 1 ? chaikinMoneyFlowList[i - 1] : 0; + var prevCmf2 = i >= 2 ? chaikinMoneyFlowList[i - 2] : 0; - double currentVolume = volumeList[i]; + var currentVolume = volumeList[i]; tempVolumeList.AddRounded(currentVolume); - double moneyFlowVolume = moneyFlowMultiplier * currentVolume; + var moneyFlowVolume = moneyFlowMultiplier * currentVolume; moneyFlowVolumeList.AddRounded(moneyFlowVolume); - double volumeSum = tempVolumeList.TakeLastExt(length).Sum(); - double mfVolumeSum = moneyFlowVolumeList.TakeLastExt(length).Sum(); + var volumeSum = tempVolumeList.TakeLastExt(length).Sum(); + var mfVolumeSum = moneyFlowVolumeList.TakeLastExt(length).Sum(); - double cmf = volumeSum != 0 ? mfVolumeSum / volumeSum : 0; + var cmf = volumeSum != 0 ? mfVolumeSum / volumeSum : 0; chaikinMoneyFlowList.AddRounded(cmf); var signal = GetCompareSignal(cmf - prevCmf1, prevCmf1 - prevCmf2); @@ -407,23 +409,23 @@ public static StockData CalculateAccumulationDistributionLine(this StockData sto List signalsList = new(); var (inputList, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentLow = lowList[i]; - double currentHigh = highList[i]; - double currentClose = inputList[i]; - double currentVolume = volumeList[i]; - double moneyFlowMultiplier = currentHigh - currentLow != 0 ? + var currentLow = lowList[i]; + var currentHigh = highList[i]; + var currentClose = inputList[i]; + var currentVolume = volumeList[i]; + var moneyFlowMultiplier = currentHigh - currentLow != 0 ? (currentClose - currentLow - (currentHigh - currentClose)) / (currentHigh - currentLow) : 0; - double moneyFlowVolume = moneyFlowMultiplier * currentVolume; + var moneyFlowVolume = moneyFlowMultiplier * currentVolume; - double prevAdl = adlList.LastOrDefault(); - double adl = prevAdl + moneyFlowVolume; + var prevAdl = adlList.LastOrDefault(); + var adl = prevAdl + moneyFlowVolume; adlList.AddRounded(adl); } var adlSignalList = GetMovingAverageList(stockData, maType, length, adlList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { var adl = adlList[i]; var prevAdl = i >= 1 ? adlList[i - 1] : 0; @@ -465,38 +467,38 @@ public static StockData CalculateAverageMoneyFlowOscillator(this StockData stock var avgvList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double chg = MinPastValues(i, 1, currentValue - prevValue); + var chg = MinPastValues(i, 1, currentValue - prevValue); chgList.AddRounded(chg); } var avgcList = GetMovingAverageList(stockData, maType, length, chgList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double avgv = avgvList[i]; - double avgc = avgcList[i]; + var avgv = avgvList[i]; + var avgc = avgcList[i]; - double r = Math.Abs(avgv * avgc) > 0 ? Math.Log(Math.Abs(avgv * avgc)) * Math.Sign(avgc) : 0; + var r = Math.Abs(avgv * avgc) > 0 ? Math.Log(Math.Abs(avgv * avgc)) * Math.Sign(avgc) : 0; rList.AddRounded(r); var list = rList.TakeLastExt(length).ToList(); - double rh = list.Max(); - double rl = list.Min(); - double rs = rh != rl ? (r - rl) / (rh - rl) * 100 : 0; + var rh = list.Max(); + var rl = list.Min(); + var rs = rh != rl ? (r - rl) / (rh - rl) * 100 : 0; - double k = (rs * 2) - 100; + var k = (rs * 2) - 100; kList.AddRounded(k); } var ksList = GetMovingAverageList(stockData, maType, smoothLength, kList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ks = ksList[i]; - double prevKs = i >= 1 ? ksList[i - 1] : 0; + var ks = ksList[i]; + var prevKs = i >= 1 ? ksList[i - 1] : 0; var signal = GetCompareSignal(ks, prevKs); signalsList.Add(signal); @@ -548,115 +550,115 @@ public static StockData CalculateBetterVolumeIndicator(this StockData stockData, var (inputList, highList, lowList, openList, volumeList) = GetInputValuesList(stockData); var (highestList, lowestList) = GetMaxAndMinValuesList(highList, lowList, lbLength); - for (int i = 0; i < stockData.Count; i++) - { - double highest = highestList[i]; - double lowest = lowestList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentVolume = volumeList[i]; - double currentOpen = openList[i]; - double currentClose = inputList[i]; - double highLowRange = highest - lowest; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevOpen = i >= 1 ? openList[i - 1] : 0; - double range = CalculateTrueRange(currentHigh, currentLow, prevClose); - - double prevV1 = v1List.LastOrDefault(); - double v1 = currentClose > currentOpen ? range / ((2 * range) + currentOpen - currentClose) * currentVolume : + for (var i = 0; i < stockData.Count; i++) + { + var highest = highestList[i]; + var lowest = lowestList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentVolume = volumeList[i]; + var currentOpen = openList[i]; + var currentClose = inputList[i]; + var highLowRange = highest - lowest; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevOpen = i >= 1 ? openList[i - 1] : 0; + var range = CalculateTrueRange(currentHigh, currentLow, prevClose); + + var prevV1 = v1List.LastOrDefault(); + var v1 = currentClose > currentOpen ? range / ((2 * range) + currentOpen - currentClose) * currentVolume : currentClose < currentOpen ? (range + currentClose - currentOpen) / ((2 * range) + currentClose - currentOpen) * currentVolume : 0.5 * currentVolume; v1List.AddRounded(v1); - double prevV2 = v2List.LastOrDefault(); - double v2 = currentVolume - v1; + var prevV2 = v2List.LastOrDefault(); + var v2 = currentVolume - v1; v2List.AddRounded(v2); - double prevV3 = v3List.LastOrDefault(); - double v3 = v1 + v2; + var prevV3 = v3List.LastOrDefault(); + var v3 = v1 + v2; v3List.AddRounded(v3); - double v4 = v1 * range; + var v4 = v1 * range; v4List.AddRounded(v4); - double v5 = (v1 - v2) * range; + var v5 = (v1 - v2) * range; v5List.AddRounded(v5); - double v6 = v2 * range; + var v6 = v2 * range; v6List.AddRounded(v6); - double v7 = (v2 - v1) * range; + var v7 = (v2 - v1) * range; v7List.AddRounded(v7); - double v8 = range != 0 ? v1 / range : 0; + var v8 = range != 0 ? v1 / range : 0; v8List.AddRounded(v8); - double v9 = range != 0 ? (v1 - v2) / range : 0; + var v9 = range != 0 ? (v1 - v2) / range : 0; v9List.AddRounded(v9); - double v10 = range != 0 ? v2 / range : 0; + var v10 = range != 0 ? v2 / range : 0; v10List.AddRounded(v10); - double v11 = range != 0 ? (v2 - v1) / range : 0; + var v11 = range != 0 ? (v2 - v1) / range : 0; v11List.AddRounded(v11); - double v12 = range != 0 ? v3 / range : 0; + var v12 = range != 0 ? v3 / range : 0; v12List.AddRounded(v12); - double v13 = v3 + prevV3; + var v13 = v3 + prevV3; v13List.AddRounded(v13); - double v14 = (v1 + prevV1) * highLowRange; + var v14 = (v1 + prevV1) * highLowRange; v14List.AddRounded(v14); - double v15 = (v1 + prevV1 - v2 - prevV2) * highLowRange; + var v15 = (v1 + prevV1 - v2 - prevV2) * highLowRange; v15List.AddRounded(v15); - double v16 = (v2 + prevV2) * highLowRange; + var v16 = (v2 + prevV2) * highLowRange; v16List.AddRounded(v16); - double v17 = (v2 + prevV2 - v1 - prevV1) * highLowRange; + var v17 = (v2 + prevV2 - v1 - prevV1) * highLowRange; v17List.AddRounded(v17); - double v18 = highLowRange != 0 ? (v1 + prevV1) / highLowRange : 0; + var v18 = highLowRange != 0 ? (v1 + prevV1) / highLowRange : 0; v18List.AddRounded(v18); - double v19 = highLowRange != 0 ? (v1 + prevV1 - v2 - prevV2) / highLowRange : 0; + var v19 = highLowRange != 0 ? (v1 + prevV1 - v2 - prevV2) / highLowRange : 0; v19List.AddRounded(v19); - double v20 = highLowRange != 0 ? (v2 + prevV2) / highLowRange : 0; + var v20 = highLowRange != 0 ? (v2 + prevV2) / highLowRange : 0; v20List.AddRounded(v20); - double v21 = highLowRange != 0 ? (v2 + prevV2 - v1 - prevV1) / highLowRange : 0; + var v21 = highLowRange != 0 ? (v2 + prevV2 - v1 - prevV1) / highLowRange : 0; v21List.AddRounded(v21); - double v22 = highLowRange != 0 ? v13 / highLowRange : 0; + var v22 = highLowRange != 0 ? v13 / highLowRange : 0; v22List.AddRounded(v22); - bool c1 = v3 == v3List.TakeLastExt(length).Min(); - bool c2 = v4 == v4List.TakeLastExt(length).Max() && currentClose > currentOpen; - bool c3 = v5 == v5List.TakeLastExt(length).Max() && currentClose > currentOpen; - bool c4 = v6 == v6List.TakeLastExt(length).Max() && currentClose < currentOpen; - bool c5 = v7 == v7List.TakeLastExt(length).Max() && currentClose < currentOpen; - bool c6 = v8 == v8List.TakeLastExt(length).Min() && currentClose < currentOpen; - bool c7 = v9 == v9List.TakeLastExt(length).Min() && currentClose < currentOpen; - bool c8 = v10 == v10List.TakeLastExt(length).Min() && currentClose > currentOpen; - bool c9 = v11 == v11List.TakeLastExt(length).Min() && currentClose > currentOpen; - bool c10 = v12 == v12List.TakeLastExt(length).Max(); - bool c11 = v13 == v13List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose > prevOpen; - bool c12 = v14 == v14List.TakeLastExt(length).Max() && currentClose > currentOpen && prevClose > prevOpen; - bool c13 = v15 == v15List.TakeLastExt(length).Max() && currentClose > currentOpen && prevClose < prevOpen; - bool c14 = v16 == v16List.TakeLastExt(length).Min() && currentClose < currentOpen && prevClose < prevOpen; - bool c15 = v17 == v17List.TakeLastExt(length).Min() && currentClose < currentOpen && prevClose < prevOpen; - bool c16 = v18 == v18List.TakeLastExt(length).Min() && currentClose < currentOpen && prevClose < prevOpen; - bool c17 = v19 == v19List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose < prevOpen; - bool c18 = v20 == v20List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose > prevOpen; - bool c19 = v21 == v21List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose > prevOpen; - bool c20 = v22 == v22List.TakeLastExt(length).Min(); - bool climaxUp = c2 || c3 || c8 || c9 || c12 || c13 || c18 || c19; - bool climaxDown = c4 || c5 || c6 || c7 || c14 || c15 || c16 || c17; - bool churn = c10 || c20; - bool lowVolue = c1 || c11; + var c1 = v3 == v3List.TakeLastExt(length).Min(); + var c2 = v4 == v4List.TakeLastExt(length).Max() && currentClose > currentOpen; + var c3 = v5 == v5List.TakeLastExt(length).Max() && currentClose > currentOpen; + var c4 = v6 == v6List.TakeLastExt(length).Max() && currentClose < currentOpen; + var c5 = v7 == v7List.TakeLastExt(length).Max() && currentClose < currentOpen; + var c6 = v8 == v8List.TakeLastExt(length).Min() && currentClose < currentOpen; + var c7 = v9 == v9List.TakeLastExt(length).Min() && currentClose < currentOpen; + var c8 = v10 == v10List.TakeLastExt(length).Min() && currentClose > currentOpen; + var c9 = v11 == v11List.TakeLastExt(length).Min() && currentClose > currentOpen; + var c10 = v12 == v12List.TakeLastExt(length).Max(); + var c11 = v13 == v13List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose > prevOpen; + var c12 = v14 == v14List.TakeLastExt(length).Max() && currentClose > currentOpen && prevClose > prevOpen; + var c13 = v15 == v15List.TakeLastExt(length).Max() && currentClose > currentOpen && prevClose < prevOpen; + var c14 = v16 == v16List.TakeLastExt(length).Min() && currentClose < currentOpen && prevClose < prevOpen; + var c15 = v17 == v17List.TakeLastExt(length).Min() && currentClose < currentOpen && prevClose < prevOpen; + var c16 = v18 == v18List.TakeLastExt(length).Min() && currentClose < currentOpen && prevClose < prevOpen; + var c17 = v19 == v19List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose < prevOpen; + var c18 = v20 == v20List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose > prevOpen; + var c19 = v21 == v21List.TakeLastExt(length).Min() && currentClose > currentOpen && prevClose > prevOpen; + var c20 = v22 == v22List.TakeLastExt(length).Min(); + var climaxUp = c2 || c3 || c8 || c9 || c12 || c13 || c18 || c19; + var climaxDown = c4 || c5 || c6 || c7 || c14 || c15 || c16 || c17; + var churn = c10 || c20; + var lowVolue = c1 || c11; var signal = GetConditionSignal(climaxUp, climaxDown); signalsList.Add(signal); @@ -689,28 +691,28 @@ public static StockData CalculateBuffAverage(this StockData stockData, int fastL List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; + var currentValue = inputList[i]; - double currentVolume = volumeList[i]; + var currentVolume = volumeList[i]; tempVolumeList.AddRounded(currentVolume); - double priceVol = currentValue * currentVolume; + var priceVol = currentValue * currentVolume; priceVolList.AddRounded(priceVol); - double fastBuffNum = priceVolList.TakeLastExt(fastLength).Sum(); - double fastBuffDenom = tempVolumeList.TakeLastExt(fastLength).Sum(); + var fastBuffNum = priceVolList.TakeLastExt(fastLength).Sum(); + var fastBuffDenom = tempVolumeList.TakeLastExt(fastLength).Sum(); - double prevFastBuff = fastBuffList.LastOrDefault(); - double fastBuff = fastBuffDenom != 0 ? fastBuffNum / fastBuffDenom : 0; + var prevFastBuff = fastBuffList.LastOrDefault(); + var fastBuff = fastBuffDenom != 0 ? fastBuffNum / fastBuffDenom : 0; fastBuffList.AddRounded(fastBuff); - double slowBuffNum = priceVolList.TakeLastExt(slowLength).Sum(); - double slowBuffDenom = tempVolumeList.TakeLastExt(slowLength).Sum(); + var slowBuffNum = priceVolList.TakeLastExt(slowLength).Sum(); + var slowBuffDenom = tempVolumeList.TakeLastExt(slowLength).Sum(); - double prevSlowBuff = slowBuffList.LastOrDefault(); - double slowBuff = slowBuffDenom != 0 ? slowBuffNum / slowBuffDenom : 0; + var prevSlowBuff = slowBuffList.LastOrDefault(); + var slowBuff = slowBuffDenom != 0 ? slowBuffNum / slowBuffDenom : 0; slowBuffList.AddRounded(slowBuff); var signal = GetCompareSignal(fastBuff - slowBuff, prevFastBuff - prevSlowBuff); @@ -743,23 +745,23 @@ public static StockData CalculateUpsideDownsideVolume(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double upVol = currentValue > prevValue ? currentVolume : 0; + var upVol = currentValue > prevValue ? currentVolume : 0; upVolList.AddRounded(upVol); - double downVol = currentValue < prevValue ? currentVolume * -1 : 0; + var downVol = currentValue < prevValue ? currentVolume * -1 : 0; downVolList.AddRounded(downVol); - double upVolSum = upVolList.TakeLastExt(length).Sum(); - double downVolSum = downVolList.TakeLastExt(length).Sum(); + var upVolSum = upVolList.TakeLastExt(length).Sum(); + var downVolSum = downVolList.TakeLastExt(length).Sum(); - double prevUpDownVol = upDownVolumeList.LastOrDefault(); - double upDownVol = downVolSum != 0 ? upVolSum / downVolSum : 0; + var prevUpDownVol = upDownVolumeList.LastOrDefault(); + var upDownVol = downVolSum != 0 ? upVolSum / downVolSum : 0; upDownVolumeList.AddRounded(upDownVol); var signal = GetCompareSignal(upDownVol, prevUpDownVol); @@ -794,31 +796,31 @@ public static StockData CalculateEaseOfMovement(this StockData stockData, Moving List signalsList = new(); var (_, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentVolume = volumeList[i]; - double prevHalfRange = halfRangeList.LastOrDefault(); - double halfRange = (currentHigh - currentLow) * 0.5; - double boxRatio = currentHigh - currentLow != 0 ? currentVolume / (currentHigh - currentLow) : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentVolume = volumeList[i]; + var prevHalfRange = halfRangeList.LastOrDefault(); + var halfRange = (currentHigh - currentLow) * 0.5; + var boxRatio = currentHigh - currentLow != 0 ? currentVolume / (currentHigh - currentLow) : 0; - double prevMidpointMove = midpointMoveList.LastOrDefault(); - double midpointMove = halfRange - prevHalfRange; + var prevMidpointMove = midpointMoveList.LastOrDefault(); + var midpointMove = halfRange - prevHalfRange; midpointMoveList.AddRounded(midpointMove); - double emv = boxRatio != 0 ? divisor * ((midpointMove - prevMidpointMove) / boxRatio) : 0; + var emv = boxRatio != 0 ? divisor * ((midpointMove - prevMidpointMove) / boxRatio) : 0; emvList.AddRounded(emv); } var emvSmaList = GetMovingAverageList(stockData, maType, length, emvList); var emvSignalList = GetMovingAverageList(stockData, maType, length, emvSmaList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double emv = emvList[i]; - double emvSignal = emvSignalList[i]; - double prevEmv = i >= 1 ? emvList[i - 1] : 0; - double prevEmvSignal = i >= 1 ? emvSignalList[i - 1] : 0; + var emv = emvList[i]; + var emvSignal = emvSignalList[i]; + var prevEmv = i >= 1 ? emvList[i - 1] : 0; + var prevEmvSignal = i >= 1 ? emvSignalList[i - 1] : 0; var signal = GetCompareSignal(emv - emvSignal, prevEmv - prevEmvSignal); signalsList.Add(signal); @@ -852,12 +854,12 @@ public static StockData CalculateOnBalanceVolumeModified(this StockData stockDat var obvmList = GetMovingAverageList(stockData, maType, length1, obvList); var sigList = GetMovingAverageList(stockData, maType, length2, obvmList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double obvm = obvmList[i]; - double sig = sigList[i]; - double prevObvm = i >= 1 ? obvmList[i - 1] : 0; - double prevSig = i >= 1 ? sigList[i - 1] : 0; + var obvm = obvmList[i]; + var sig = sigList[i]; + var prevObvm = i >= 1 ? obvmList[i - 1] : 0; + var prevSig = i >= 1 ? sigList[i - 1] : 0; var signal = GetCompareSignal(obvm - sig, prevObvm - prevSig); signalsList.Add(signal); @@ -890,24 +892,24 @@ public static StockData CalculateOnBalanceVolumeReflex(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= length ? inputList[i - length] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= length ? inputList[i - length] : 0; - double prevOvr = ovrList.LastOrDefault(); - double ovr = currentValue > prevValue ? prevOvr + currentVolume : currentValue < prevValue ? prevOvr - currentVolume : prevOvr; + var prevOvr = ovrList.LastOrDefault(); + var ovr = currentValue > prevValue ? prevOvr + currentVolume : currentValue < prevValue ? prevOvr - currentVolume : prevOvr; ovrList.AddRounded(ovr); } var ovrSmaList = GetMovingAverageList(stockData, maType, signalLength, ovrList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double ovr = ovrList[i]; - double ovrEma = ovrSmaList[i]; - double prevOvr = i >= 1 ? ovrList[i - 1] : 0; - double prevOvrEma = i >= 1 ? ovrSmaList[i - 1] : 0; + var ovr = ovrList[i]; + var ovrEma = ovrSmaList[i]; + var prevOvr = i >= 1 ? ovrList[i - 1] : 0; + var prevOvrEma = i >= 1 ? ovrSmaList[i - 1] : 0; var signal = GetCompareSignal(ovr - ovrEma, prevOvr - prevOvrEma); signalsList.Add(signal); @@ -950,34 +952,34 @@ public static StockData CalculateOnBalanceVolumeDisparityIndicator(this StockDat stockData.CustomValuesList = obvList; var obvStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double sma = smaList[i]; - double stdDev = stdDevList[i]; - double obvSma = obvSmaList[i]; - double obvStdDev = obvStdDevList[i]; - double aTop = currentValue - (sma - (2 * stdDev)); - double aBot = currentValue + (2 * stdDev) - (sma - (2 * stdDev)); - double obv = obvList[i]; - double a = aBot != 0 ? aTop / aBot : 0; - double bTop = obv - (obvSma - (2 * obvStdDev)); - double bBot = obvSma + (2 * obvStdDev) - (obvSma - (2 * obvStdDev)); - double b = bBot != 0 ? bTop / bBot : 0; - - double obvdi = 1 + b != 0 ? (1 + a) / (1 + b) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var sma = smaList[i]; + var stdDev = stdDevList[i]; + var obvSma = obvSmaList[i]; + var obvStdDev = obvStdDevList[i]; + var aTop = currentValue - (sma - (2 * stdDev)); + var aBot = currentValue + (2 * stdDev) - (sma - (2 * stdDev)); + var obv = obvList[i]; + var a = aBot != 0 ? aTop / aBot : 0; + var bTop = obv - (obvSma - (2 * obvStdDev)); + var bBot = obvSma + (2 * obvStdDev) - (obvSma - (2 * obvStdDev)); + var b = bBot != 0 ? bTop / bBot : 0; + + var obvdi = 1 + b != 0 ? (1 + a) / (1 + b) : 0; obvdiList.AddRounded(obvdi); } var obvdiEmaList = GetMovingAverageList(stockData, maType, signalLength, obvdiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double obvdi = obvdiList[i]; - double obvdiEma = obvdiEmaList[i]; - double prevObvdi = i >= 1 ? obvdiList[i - 1] : 0; + var obvdi = obvdiList[i]; + var obvdiEma = obvdiEmaList[i]; + var prevObvdi = i >= 1 ? obvdiList[i - 1] : 0; - double prevBsc = bscList.LastOrDefault(); - double bsc = (prevObvdi < bottom && obvdi > bottom) || obvdi > obvdiEma ? 1 : (prevObvdi > top && obvdi < top) || + var prevBsc = bscList.LastOrDefault(); + var bsc = (prevObvdi < bottom && obvdi > bottom) || obvdi > obvdiEma ? 1 : (prevObvdi > top && obvdi < top) || obvdi < bottom ? -1 : prevBsc; bscList.AddRounded(bsc); @@ -1022,34 +1024,34 @@ public static StockData CalculateNegativeVolumeDisparityIndicator(this StockData stockData.CustomValuesList = nviList; var nviStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) - { - double currentValue = inputList[i]; - double sma = smaList[i]; - double stdDev = stdDevList[i]; - double nviSma = nviSmaList[i]; - double nviStdDev = nviStdDevList[i]; - double aTop = currentValue - (sma - (2 * stdDev)); - double aBot = (currentValue + (2 * stdDev)) - (sma - (2 * stdDev)); - double nvi = nviList[i]; - double a = aBot != 0 ? aTop / aBot : 0; - double bTop = nvi - (nviSma - (2 * nviStdDev)); - double bBot = (nviSma + (2 * nviStdDev)) - (nviSma - (2 * nviStdDev)); - double b = bBot != 0 ? bTop / bBot : 0; - - double nvdi = 1 + b != 0 ? (1 + a) / (1 + b) : 0; + for (var i = 0; i < stockData.Count; i++) + { + var currentValue = inputList[i]; + var sma = smaList[i]; + var stdDev = stdDevList[i]; + var nviSma = nviSmaList[i]; + var nviStdDev = nviStdDevList[i]; + var aTop = currentValue - (sma - (2 * stdDev)); + var aBot = (currentValue + (2 * stdDev)) - (sma - (2 * stdDev)); + var nvi = nviList[i]; + var a = aBot != 0 ? aTop / aBot : 0; + var bTop = nvi - (nviSma - (2 * nviStdDev)); + var bBot = (nviSma + (2 * nviStdDev)) - (nviSma - (2 * nviStdDev)); + var b = bBot != 0 ? bTop / bBot : 0; + + var nvdi = 1 + b != 0 ? (1 + a) / (1 + b) : 0; nvdiList.AddRounded(nvdi); } var nvdiEmaList = GetMovingAverageList(stockData, maType, signalLength, nvdiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double nvdi = nvdiList[i]; - double nvdiEma = nvdiEmaList[i]; - double prevNvdi = i >= 1 ? nvdiList[i - 1] : 0; + var nvdi = nvdiList[i]; + var nvdiEma = nvdiEmaList[i]; + var prevNvdi = i >= 1 ? nvdiList[i - 1] : 0; - double prevBsc = bscList.LastOrDefault(); - double bsc = (prevNvdi < bottom && nvdi > bottom) || nvdi > nvdiEma ? 1 : (prevNvdi > top && nvdi < top) || + var prevBsc = bscList.LastOrDefault(); + var bsc = (prevNvdi < bottom && nvdi > bottom) || nvdi > nvdiEma ? 1 : (prevNvdi > top && nvdi < top) || nvdi < bottom ? -1 : prevBsc; bscList.AddRounded(bsc); @@ -1087,45 +1089,45 @@ public static StockData CalculateHawkeyeVolumeIndicator(this StockData stockData List signalsList = new(); var (inputList, highList, lowList, _, closeList, volumeList) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentValue = closeList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentValue = closeList[i]; - double currentVolume = volumeList[i]; + var currentVolume = volumeList[i]; tempVolumeList.AddRounded(currentVolume); - double range = currentHigh - currentLow; + var range = currentHigh - currentLow; tempRangeList.AddRounded(range); - double volumeSma = tempVolumeList.TakeLastExt(length).Average(); - double rangeSma = tempRangeList.TakeLastExt(length).Average(); - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevMidpoint = i >= 1 ? inputList[i - 1] : 0; - double prevVolume = i >= 1 ? volumeList[i - 1] : 0; + var volumeSma = tempVolumeList.TakeLastExt(length).Average(); + var rangeSma = tempRangeList.TakeLastExt(length).Average(); + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevMidpoint = i >= 1 ? inputList[i - 1] : 0; + var prevVolume = i >= 1 ? volumeList[i - 1] : 0; - double u1 = divisor != 0 ? prevMidpoint + ((prevHigh - prevLow) / divisor) : prevMidpoint; + var u1 = divisor != 0 ? prevMidpoint + ((prevHigh - prevLow) / divisor) : prevMidpoint; u1List.AddRounded(u1); - double d1 = divisor != 0 ? prevMidpoint - ((prevHigh - prevLow) / divisor) : prevMidpoint; + var d1 = divisor != 0 ? prevMidpoint - ((prevHigh - prevLow) / divisor) : prevMidpoint; d1List.AddRounded(d1); - bool rEnabled1 = range > rangeSma && currentValue < d1 && currentVolume > volumeSma; - bool rEnabled2 = currentValue < prevMidpoint; - bool rEnabled = rEnabled1 || rEnabled2; + var rEnabled1 = range > rangeSma && currentValue < d1 && currentVolume > volumeSma; + var rEnabled2 = currentValue < prevMidpoint; + var rEnabled = rEnabled1 || rEnabled2; - bool gEnabled1 = currentValue > prevMidpoint; - bool gEnabled2 = range > rangeSma && currentValue > u1 && currentVolume > volumeSma; - bool gEnabled3 = currentHigh > prevHigh && range < rangeSma / 1.5 && currentVolume < volumeSma; - bool gEnabled4 = currentLow < prevLow && range < rangeSma / 1.5 && currentVolume > volumeSma; - bool gEnabled = gEnabled1 || gEnabled2 || gEnabled3 || gEnabled4; + var gEnabled1 = currentValue > prevMidpoint; + var gEnabled2 = range > rangeSma && currentValue > u1 && currentVolume > volumeSma; + var gEnabled3 = currentHigh > prevHigh && range < rangeSma / 1.5 && currentVolume < volumeSma; + var gEnabled4 = currentLow < prevLow && range < rangeSma / 1.5 && currentVolume > volumeSma; + var gEnabled = gEnabled1 || gEnabled2 || gEnabled3 || gEnabled4; - bool grEnabled1 = range > rangeSma && currentValue > d1 && currentValue < u1 && currentVolume > volumeSma && currentVolume < volumeSma * 1.5 && currentVolume > prevVolume; - bool grEnabled2 = range < rangeSma / 1.5 && currentVolume < volumeSma / 1.5; - bool grEnabled3 = currentValue > d1 && currentValue < u1; - bool grEnabled = grEnabled1 || grEnabled2 || grEnabled3; + var grEnabled1 = range > rangeSma && currentValue > d1 && currentValue < u1 && currentVolume > volumeSma && currentVolume < volumeSma * 1.5 && currentVolume > prevVolume; + var grEnabled2 = range < rangeSma / 1.5 && currentVolume < volumeSma / 1.5; + var grEnabled3 = currentValue > d1 && currentValue < u1; + var grEnabled = grEnabled1 || grEnabled2 || grEnabled3; var signal = GetConditionSignal(gEnabled, rEnabled); signalsList.Add(signal); @@ -1157,26 +1159,26 @@ public static StockData CalculateHerrickPayoffIndex(this StockData stockData, In List signalsList = new(); var (inputList, _, _, openList, closeList, volumeList) = GetInputValuesList(inputName, stockData); - for (int i = 0; i < stockData.Count; i++) - { - double currentClose = closeList[i]; - double currentOpen = openList[i]; - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevClose = i >= 1 ? closeList[i - 1] : 0; - double prevOpen = i >= 1 ? openList[i - 1] : 0; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevK = kList.LastOrDefault(); - double absDiff = Math.Abs(currentClose - prevClose); - double g = Math.Min(currentOpen, prevOpen); - double k = MinPastValues(i, 1, currentValue - prevValue) * pointValue * currentVolume; - double temp = g != 0 ? currentValue < prevValue ? 1 - (absDiff / 2 / g) : 1 + (absDiff / 2 / g) : 1; + for (var i = 0; i < stockData.Count; i++) + { + var currentClose = closeList[i]; + var currentOpen = openList[i]; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevClose = i >= 1 ? closeList[i - 1] : 0; + var prevOpen = i >= 1 ? openList[i - 1] : 0; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevK = kList.LastOrDefault(); + var absDiff = Math.Abs(currentClose - prevClose); + var g = Math.Min(currentOpen, prevOpen); + var k = MinPastValues(i, 1, currentValue - prevValue) * pointValue * currentVolume; + var temp = g != 0 ? currentValue < prevValue ? 1 - (absDiff / 2 / g) : 1 + (absDiff / 2 / g) : 1; k *= temp; kList.AddRounded(k); - double prevHpic = hpicList.LastOrDefault(); - double hpic = prevK + (k - prevK); + var prevHpic = hpicList.LastOrDefault(); + var hpic = prevK + (k - prevK); hpicList.AddRounded(hpic); var signal = GetCompareSignal(hpic, prevHpic); @@ -1215,28 +1217,28 @@ public static StockData CalculateFiniteVolumeElements(this StockData stockData, var typicalPriceList = CalculateTypicalPrice(stockData).CustomValuesList; var volumeSmaList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double medianPrice = medianPriceList[i]; - double typicalPrice = typicalPriceList[i]; - double prevTypicalPrice = i >= 1 ? typicalPriceList[i - 1] : 0; - double volumeSma = volumeSmaList[i]; - double volume = volumeList[i]; - double close = inputList[i]; - double nmf = close - medianPrice + typicalPrice - prevTypicalPrice; - double nvlm = nmf > factor * close / 100 ? volume : nmf < -factor * close / 100 ? -volume : 0; + var medianPrice = medianPriceList[i]; + var typicalPrice = typicalPriceList[i]; + var prevTypicalPrice = i >= 1 ? typicalPriceList[i - 1] : 0; + var volumeSma = volumeSmaList[i]; + var volume = volumeList[i]; + var close = inputList[i]; + var nmf = close - medianPrice + typicalPrice - prevTypicalPrice; + var nvlm = nmf > factor * close / 100 ? volume : nmf < -factor * close / 100 ? -volume : 0; - double prevFve = fveList.LastOrDefault(); - double prevFve2 = i >= 2 ? fveList[i - 2] : 0; - double fve = volumeSma != 0 && length != 0 ? prevFve + (nvlm / volumeSma / length * 100) : prevFve; + var prevFve = fveList.LastOrDefault(); + var prevFve2 = i >= 2 ? fveList[i - 2] : 0; + var fve = volumeSma != 0 && length != 0 ? prevFve + (nvlm / volumeSma / length * 100) : prevFve; fveList.AddRounded(fve); - double prevBullSlope = bullList.LastOrDefault(); - double bullSlope = fve - Math.Max(prevFve, prevFve2); + var prevBullSlope = bullList.LastOrDefault(); + var bullSlope = fve - Math.Max(prevFve, prevFve2); bullList.AddRounded(bullSlope); - double prevBearSlope = bearList.LastOrDefault(); - double bearSlope = fve - Math.Min(prevFve, prevFve2); + var prevBearSlope = bearList.LastOrDefault(); + var bearSlope = fve - Math.Min(prevFve, prevFve2); bearList.AddRounded(bearSlope); var signal = GetBullishBearishSignal(bullSlope, prevBullSlope, bearSlope, prevBearSlope); @@ -1273,19 +1275,19 @@ public static StockData CalculateRelativeVolumeIndicator(this StockData stockDat stockData.CustomValuesList = volumeList; var stdDevVolumeList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentVolume = volumeList[i]; - double currentValue = inputList[i]; - double av = smaVolumeList[i]; - double sd = stdDevVolumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentVolume = volumeList[i]; + var currentValue = inputList[i]; + var av = smaVolumeList[i]; + var sd = stdDevVolumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double relVol = sd != 0 ? (currentVolume - av) / sd : 0; + var relVol = sd != 0 ? (currentVolume - av) / sd : 0; relVolList.AddRounded(relVol); - double prevDpl = dplList.LastOrDefault(); - double dpl = relVol >= 2 ? prevValue : i >= 1 ? prevDpl : currentValue; + var prevDpl = dplList.LastOrDefault(); + var dpl = relVol >= 2 ? prevValue : i >= 1 ? prevDpl : currentValue; dplList.AddRounded(dpl); var signal = GetCompareSignal(currentValue - dpl, prevValue - prevDpl); @@ -1325,48 +1327,48 @@ public static StockData CalculateFreedomOfMovement(this StockData stockData, Mov var relVolList = CalculateRelativeVolumeIndicator(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double currentRelVol = relVolList[i]; + var currentRelVol = relVolList[i]; tempList.AddRounded(currentRelVol); - double aMove = prevValue != 0 ? Math.Abs(MinPastValues(i, 1, currentValue - prevValue) / prevValue) : 0; + var aMove = prevValue != 0 ? Math.Abs(MinPastValues(i, 1, currentValue - prevValue) / prevValue) : 0; aMoveList.AddRounded(aMove); var list = aMoveList.TakeLastExt(length).ToList(); - double aMoveMax = list.Max(); - double aMoveMin = list.Min(); - double theMove = aMoveMax - aMoveMin != 0 ? (1 + ((aMove - aMoveMin) * (10 - 1))) / (aMoveMax - aMoveMin) : 0; + var aMoveMax = list.Max(); + var aMoveMin = list.Min(); + var theMove = aMoveMax - aMoveMin != 0 ? (1 + ((aMove - aMoveMin) * (10 - 1))) / (aMoveMax - aMoveMin) : 0; var tList = tempList.TakeLastExt(length).ToList(); - double relVolMax = tList.Max(); - double relVolMin = tList.Min(); - double theVol = relVolMax - relVolMin != 0 ? (1 + ((currentRelVol - relVolMin) * (10 - 1))) / (relVolMax - relVolMin) : 0; + var relVolMax = tList.Max(); + var relVolMin = tList.Min(); + var theVol = relVolMax - relVolMin != 0 ? (1 + ((currentRelVol - relVolMin) * (10 - 1))) / (relVolMax - relVolMin) : 0; - double vBym = theMove != 0 ? theVol / theMove : 0; + var vBym = theMove != 0 ? theVol / theMove : 0; vBymList.AddRounded(vBym); - double avf = vBymList.TakeLastExt(length).Average(); + var avf = vBymList.TakeLastExt(length).Average(); avfList.AddRounded(avf); } stockData.CustomValuesList = vBymList; var sdfList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double vBym = vBymList[i]; - double avf = avfList[i]; - double sdf = sdfList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var vBym = vBymList[i]; + var avf = avfList[i]; + var sdf = sdfList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double theFom = sdf != 0 ? (vBym - avf) / sdf : 0; + var theFom = sdf != 0 ? (vBym - avf) / sdf : 0; theFomList.AddRounded(theFom); - double prevDpl = dplList.LastOrDefault(); - double dpl = theFom >= 2 ? prevValue : i >= 1 ? prevDpl : currentValue; + var prevDpl = dplList.LastOrDefault(); + var dpl = theFom >= 2 ? prevValue : i >= 1 ? prevDpl : currentValue; dplList.AddRounded(dpl); var signal = GetCompareSignal(currentValue - dpl, prevValue - prevDpl); @@ -1408,31 +1410,31 @@ public static StockData CalculateVolumePriceConfirmationIndicator(this StockData var smaShortList = GetMovingAverageList(stockData, maType, fastLength, inputList); var smaLongList = GetMovingAverageList(stockData, maType, slowLength, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vwmaLong = vwmaLongList[i]; - double vwmaShort = vwmaShortList[i]; - double volumeSmaLong = volumeSmaLongList[i]; - double volumeSmaShort = volumeSmaShortList[i]; - double smaLong = smaLongList[i]; - double smaShort = smaShortList[i]; - double vpc = vwmaLong - smaLong; - double vpr = smaShort != 0 ? vwmaShort / smaShort : 0; - double vm = volumeSmaLong != 0 ? volumeSmaShort / volumeSmaLong : 0; + var vwmaLong = vwmaLongList[i]; + var vwmaShort = vwmaShortList[i]; + var volumeSmaLong = volumeSmaLongList[i]; + var volumeSmaShort = volumeSmaShortList[i]; + var smaLong = smaLongList[i]; + var smaShort = smaShortList[i]; + var vpc = vwmaLong - smaLong; + var vpr = smaShort != 0 ? vwmaShort / smaShort : 0; + var vm = volumeSmaLong != 0 ? volumeSmaShort / volumeSmaLong : 0; - double vpci = vpc * vpr * vm; + var vpci = vpc * vpr * vm; vpciList.AddRounded(vpci); } var vpciSmaList = GetMovingAverageList(stockData, maType, length, vpciList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vpci = vpciList[i]; - double vpciSma = vpciSmaList[i]; - double prevVpci = i >= 1 ? vpciList[i - 1] : 0; - double prevVpciSma = i >= 1 ? vpciSmaList[i - 1] : 0; + var vpci = vpciList[i]; + var vpciSma = vpciSmaList[i]; + var prevVpci = i >= 1 ? vpciList[i - 1] : 0; + var prevVpciSma = i >= 1 ? vpciSmaList[i - 1] : 0; - Signal signal = GetCompareSignal(vpci - vpciSma, prevVpci - prevVpciSma); + var signal = GetCompareSignal(vpci - vpciSma, prevVpci - prevVpciSma); signalsList.Add(signal); } @@ -1470,35 +1472,35 @@ public static StockData CalculateVolumePositiveNegativeIndicator(this StockData var mavList = GetMovingAverageList(stockData, maType, length, volumeList); var atrList = CalculateAverageTrueRange(stockData, maType, length).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mav = mavList[i]; + var mav = mavList[i]; mav = mav > 0 ? mav : 1; - double tp = inputList[i]; - double prevTp = i >= 1 ? inputList[i - 1] : 0; - double atr = atrList[i]; - double currentVolume = volumeList[i]; - double mf = tp - prevTp; - double mc = 0.1 * atr; - - double vmp = mf > mc ? currentVolume : 0; + var tp = inputList[i]; + var prevTp = i >= 1 ? inputList[i - 1] : 0; + var atr = atrList[i]; + var currentVolume = volumeList[i]; + var mf = tp - prevTp; + var mc = 0.1 * atr; + + var vmp = mf > mc ? currentVolume : 0; vmpList.AddRounded(vmp); - double vmn = mf < -mc ? currentVolume : 0; + var vmn = mf < -mc ? currentVolume : 0; vmnList.AddRounded(vmn); - double vn = vmnList.TakeLastExt(length).Sum(); - double vp = vmpList.TakeLastExt(length).Sum(); + var vn = vmnList.TakeLastExt(length).Sum(); + var vp = vmpList.TakeLastExt(length).Sum(); - double vpn = mav != 0 && length != 0 ? (vp - vn) / mav / length * 100 : 0; + var vpn = mav != 0 && length != 0 ? (vp - vn) / mav / length * 100 : 0; vpnList.AddRounded(vpn); } var vpnEmaList = GetMovingAverageList(stockData, maType, smoothLength, vpnList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vpnEma = vpnEmaList[i]; - double prevVpnEma = i >= 1 ? vpnEmaList[i - 1] : 0; + var vpnEma = vpnEmaList[i]; + var prevVpnEma = i >= 1 ? vpnEmaList[i - 1] : 0; var signal = GetCompareSignal(vpnEma, prevVpnEma); signalsList.Add(signal); @@ -1529,19 +1531,19 @@ public static StockData CalculateVolumeAccumulationOscillator(this StockData sto List signalsList = new(); var (inputList, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentVolume = volumeList[i]; - double medianValue = (currentHigh + currentLow) / 2; + var currentValue = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentVolume = volumeList[i]; + var medianValue = (currentHigh + currentLow) / 2; - double vao = currentValue != medianValue ? currentVolume * (currentValue - medianValue) : currentVolume; + var vao = currentValue != medianValue ? currentVolume * (currentValue - medianValue) : currentVolume; vaoList.AddRounded(vao); - double prevVaoSum = vaoSumList.LastOrDefault(); - double vaoSum = vaoList.TakeLastExt(length).Average(); + var prevVaoSum = vaoSumList.LastOrDefault(); + var vaoSum = vaoList.TakeLastExt(length).Average(); vaoSumList.AddRounded(vaoSum); var signal = GetCompareSignal(vaoSum, prevVaoSum); @@ -1573,24 +1575,24 @@ public static StockData CalculateVolumeAccumulationPercent(this StockData stockD List signalsList = new(); var (inputList, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentClose = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentClose = inputList[i]; - double currentVolume = volumeList[i]; + var currentVolume = volumeList[i]; tempVolumeList.AddRounded(currentVolume); - double xt = currentHigh - currentLow != 0 ? ((2 * currentClose) - currentHigh - currentLow) / (currentHigh - currentLow) : 0; - double tva = currentVolume * xt; + var xt = currentHigh - currentLow != 0 ? ((2 * currentClose) - currentHigh - currentLow) / (currentHigh - currentLow) : 0; + var tva = currentVolume * xt; tvaList.AddRounded(tva); - double volumeSum = tempVolumeList.TakeLastExt(length).Sum(); - double tvaSum = tvaList.TakeLastExt(length).Sum(); + var volumeSum = tempVolumeList.TakeLastExt(length).Sum(); + var tvaSum = tvaList.TakeLastExt(length).Sum(); - double prevVapc = vapcList.LastOrDefault(); - double vapc = volumeSum != 0 ? MinOrMax(100 * tvaSum / volumeSum, 100, 0) : 0; + var prevVapc = vapcList.LastOrDefault(); + var vapc = volumeSum != 0 ? MinOrMax(100 * tvaSum / volumeSum, 100, 0) : 0; vapcList.AddRounded(vapc); var signal = GetCompareSignal(vapc, prevVapc); @@ -1635,51 +1637,51 @@ public static StockData CalculateVolumeFlowIndicator(this StockData stockData, M var smaVolumeList = GetMovingAverageList(stockData, maType, length1, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double inter = currentValue > 0 && prevValue > 0 ? Math.Log(currentValue) - Math.Log(prevValue) : 0; + var inter = currentValue > 0 && prevValue > 0 ? Math.Log(currentValue) - Math.Log(prevValue) : 0; interList.AddRounded(inter); } stockData.CustomValuesList = interList; var vinterList = CalculateStandardDeviationVolatility(stockData, maType, length2).CustomValuesList; - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vinter = vinterList[i]; - double currentVolume = volumeList[i]; - double currentClose = closeList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; + var vinter = vinterList[i]; + var currentVolume = volumeList[i]; + var currentClose = closeList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevVave = tempList.LastOrDefault(); - double vave = smaVolumeList[i]; + var prevVave = tempList.LastOrDefault(); + var vave = smaVolumeList[i]; tempList.AddRounded(vave); - double cutoff = currentClose * vinter * coef; - double vmax = prevVave * vcoef; - double vc = Math.Min(currentVolume, vmax); - double mf = MinPastValues(i, 1, currentValue - prevValue); + var cutoff = currentClose * vinter * coef; + var vmax = prevVave * vcoef; + var vc = Math.Min(currentVolume, vmax); + var mf = MinPastValues(i, 1, currentValue - prevValue); - double vcp = mf > cutoff ? vc : mf < cutoff * -1 ? vc * -1 : mf > 0 ? vc : mf < 0 ? vc * -1 : 0; + var vcp = mf > cutoff ? vc : mf < cutoff * -1 ? vc * -1 : mf > 0 ? vc : mf < 0 ? vc * -1 : 0; vcpList.AddRounded(vcp); - double vcpSum = vcpList.TakeLastExt(length1).Sum(); - double vcpVaveSum = vave != 0 ? vcpSum / vave : 0; + var vcpSum = vcpList.TakeLastExt(length1).Sum(); + var vcpVaveSum = vave != 0 ? vcpSum / vave : 0; vcpVaveSumList.AddRounded(vcpVaveSum); } var vfiList = GetMovingAverageList(stockData, maType, smoothLength, vcpVaveSumList); var vfiEmaList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, signalLength, vfiList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double vfi = vfiList[i]; - double vfima = vfiEmaList[i]; + var vfi = vfiList[i]; + var vfima = vfiEmaList[i]; - double prevD = dList.LastOrDefault(); - double d = vfi - vfima; + var prevD = dList.LastOrDefault(); + var d = vfi - vfima; dList.AddRounded(d); var signal = GetCompareSignal(d, prevD); @@ -1717,34 +1719,34 @@ public static StockData CalculatePriceVolumeOscillator(this StockData stockData, List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= length1 ? inputList[i - length1] : 0; - double prevVolume = i >= length2 ? volumeList[i - length2] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= length1 ? inputList[i - length1] : 0; + var prevVolume = i >= length2 ? volumeList[i - length2] : 0; - double a = MinPastValues(i, length1, currentValue - prevValue); + var a = MinPastValues(i, length1, currentValue - prevValue); aList.AddRounded(a); - double b = MinPastValues(i, length2, currentVolume - prevVolume); + var b = MinPastValues(i, length2, currentVolume - prevVolume); bList.AddRounded(b); - double absA = Math.Abs(a); + var absA = Math.Abs(a); absAList.AddRounded(absA); - double absB = Math.Abs(b); + var absB = Math.Abs(b); absBList.AddRounded(absB); - double aSum = aList.TakeLastExt(length1).Sum(); - double bSum = bList.TakeLastExt(length2).Sum(); - double absASum = absAList.TakeLastExt(length1).Sum(); - double absBSum = absBList.TakeLastExt(length2).Sum(); + var aSum = aList.TakeLastExt(length1).Sum(); + var bSum = bList.TakeLastExt(length2).Sum(); + var absASum = absAList.TakeLastExt(length1).Sum(); + var absBSum = absBList.TakeLastExt(length2).Sum(); - double oscA = absASum != 0 ? aSum / absASum : 0; + var oscA = absASum != 0 ? aSum / absASum : 0; oscAList.AddRounded(oscA); - double oscB = absBSum != 0 ? bSum / absBSum : 0; + var oscB = absBSum != 0 ? bSum / absBSum : 0; oscBList.AddRounded(oscB); var signal = GetConditionSignal(oscA > 0 && oscB > 0, oscA < 0 && oscB > 0); @@ -1778,12 +1780,12 @@ public static StockData CalculatePriceVolumeRank(this StockData stockData, Movin List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double currentVolume = volumeList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevVolume = i >= 1 ? volumeList[i - 1] : 0; + var currentValue = inputList[i]; + var currentVolume = volumeList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevVolume = i >= 1 ? volumeList[i - 1] : 0; double pvr = currentValue > prevValue && currentVolume > prevVolume ? 1 : currentValue > prevValue && currentVolume <= prevVolume ? 2 : currentValue <= prevValue && currentVolume <= prevVolume ? 3 : 4; @@ -1792,12 +1794,12 @@ public static StockData CalculatePriceVolumeRank(this StockData stockData, Movin var pvrFastSmaList = GetMovingAverageList(stockData, maType, fastLength, pvrList); var pvrSlowSmaList = GetMovingAverageList(stockData, maType, slowLength, pvrList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double fastSma = pvrFastSmaList[i]; - double slowSma = pvrSlowSmaList[i]; - double prevFastSma = i >= 1 ? pvrFastSmaList[i - 1] : 0; - double prevSlowSma = i >= 1 ? pvrSlowSmaList[i - 1] : 0; + var fastSma = pvrFastSmaList[i]; + var slowSma = pvrSlowSmaList[i]; + var prevFastSma = i >= 1 ? pvrFastSmaList[i - 1] : 0; + var prevSlowSma = i >= 1 ? pvrSlowSmaList[i - 1] : 0; var signal = GetCompareSignal(fastSma - slowSma, prevFastSma - prevSlowSma); signalsList.Add(signal); @@ -1833,29 +1835,29 @@ public static StockData CalculateTwiggsMoneyFlow(this StockData stockData, Movin var volumeEmaList = GetMovingAverageList(stockData, maType, length, volumeList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentVolume = volumeList[i]; - double prevPrice = i >= 1 ? inputList[i - 1] : 0; - double trh = Math.Max(currentHigh, prevPrice); - double trl = Math.Min(currentLow, prevPrice); + var currentPrice = inputList[i]; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentVolume = volumeList[i]; + var prevPrice = i >= 1 ? inputList[i - 1] : 0; + var trh = Math.Max(currentHigh, prevPrice); + var trl = Math.Min(currentLow, prevPrice); - double ad = trh - trl != 0 && currentVolume != 0 ? (currentPrice - trl - (trh - currentPrice)) / (trh - trl) * currentVolume : 0; + var ad = trh - trl != 0 && currentVolume != 0 ? (currentPrice - trl - (trh - currentPrice)) / (trh - trl) * currentVolume : 0; adList.AddRounded(ad); } var smoothAdList = GetMovingAverageList(stockData, maType, length, adList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentEmaVolume = volumeEmaList[i]; - double smoothAd = smoothAdList[i]; - double prevTmf1 = i >= 1 ? tmfList[i - 1] : 0; - double prevTmf2 = i >= 2 ? tmfList[i - 2] : 0; + var currentEmaVolume = volumeEmaList[i]; + var smoothAd = smoothAdList[i]; + var prevTmf1 = i >= 1 ? tmfList[i - 1] : 0; + var prevTmf2 = i >= 2 ? tmfList[i - 2] : 0; - double tmf = currentEmaVolume != 0 ? MinOrMax(smoothAd / currentEmaVolume, 1, -1) : 0; + var tmf = currentEmaVolume != 0 ? MinOrMax(smoothAd / currentEmaVolume, 1, -1) : 0; tmfList.AddRounded(tmf); var signal = GetRsiSignal(tmf - prevTmf1, prevTmf1 - prevTmf2, tmf, prevTmf1, 0.2, -0.2); @@ -1888,26 +1890,26 @@ public static StockData CalculateTradeVolumeIndex(this StockData stockData, Movi List signalsList = new(); var (inputList, _, _, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentPrice = inputList[i]; - double currentVolume = volumeList[i]; - double prevPrice = i >= 1 ? inputList[i - 1] : 0; - double priceChange = currentPrice - prevPrice; + var currentPrice = inputList[i]; + var currentVolume = volumeList[i]; + var prevPrice = i >= 1 ? inputList[i - 1] : 0; + var priceChange = currentPrice - prevPrice; - double prevTvi = tviList.LastOrDefault(); - double tvi = priceChange > minTickValue ? prevTvi + currentVolume : priceChange < -minTickValue ? + var prevTvi = tviList.LastOrDefault(); + var tvi = priceChange > minTickValue ? prevTvi + currentVolume : priceChange < -minTickValue ? prevTvi - currentVolume : prevTvi; tviList.AddRounded(tvi); } var tviSignalList = GetMovingAverageList(stockData, maType, length, tviList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double tvi = tviList[i]; - double tviSignal = tviSignalList[i]; - double prevTvi = i >= 1 ? tviList[i - 1] : 0; - double prevTviSignal = i >= 1 ? tviSignalList[i - 1] : 0; + var tvi = tviList[i]; + var tviSignal = tviSignalList[i]; + var prevTvi = i >= 1 ? tviList[i - 1] : 0; + var prevTviSignal = i >= 1 ? tviSignalList[i - 1] : 0; var signal = GetCompareSignal(tvi - tviSignal, prevTvi - prevTviSignal); signalsList.Add(signal); @@ -1938,18 +1940,18 @@ public static StockData CalculateTFSVolumeOscillator(this StockData stockData, i List signalsList = new(); var (inputList, _, _, openList, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double open = openList[i]; - double close = inputList[i]; - double volume = volumeList[i]; + var open = openList[i]; + var close = inputList[i]; + var volume = volumeList[i]; - double totv = close > open ? volume : close < open ? -volume : 0; + var totv = close > open ? volume : close < open ? -volume : 0; totvList.AddRounded(totv); - double totvSum = totvList.TakeLastExt(length).Sum(); - double prevTfsvo = tfsvoList.LastOrDefault(); - double tfsvo = length != 0 ? totvSum / length : 0; + var totvSum = totvList.TakeLastExt(length).Sum(); + var prevTfsvo = tfsvoList.LastOrDefault(); + var tfsvo = length != 0 ? totvSum / length : 0; tfsvoList.AddRounded(tfsvo); var signal = GetCompareSignal(tfsvo, prevTfsvo); @@ -1978,19 +1980,19 @@ public static StockData CalculateMarketFacilitationIndex(this StockData stockDat List signalsList = new(); var (_, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double currentVolume = volumeList[i]; - double prevVolume = i >= 1 ? volumeList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var currentVolume = volumeList[i]; + var prevVolume = i >= 1 ? volumeList[i - 1] : 0; - double prevMfi = mfiList.LastOrDefault(); - double mfi = currentVolume != 0 ? (currentHigh - currentLow) / currentVolume : 0; + var prevMfi = mfiList.LastOrDefault(); + var mfi = currentVolume != 0 ? (currentHigh - currentLow) / currentVolume : 0; mfiList.AddRounded(mfi); - double mfiDiff = mfi - prevMfi; - double volDiff = currentVolume - prevVolume; + var mfiDiff = mfi - prevMfi; + var volDiff = currentVolume - prevVolume; var signal = GetConditionSignal(mfiDiff > 0, volDiff > 0); signalsList.Add(signal); @@ -2021,32 +2023,32 @@ public static StockData CalculateMultiVoteOnBalanceVolume(this StockData stockDa List signalsList = new(); var (inputList, highList, lowList, _, volumeList) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentClose = inputList[i]; - double currentLow = lowList[i]; - double currentVolume = volumeList[i] / 1000000; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; + var currentHigh = highList[i]; + var currentClose = inputList[i]; + var currentLow = lowList[i]; + var currentVolume = volumeList[i] / 1000000; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; double highVote = currentHigh > prevHigh ? 1 : currentHigh < prevHigh ? -1 : 0; double lowVote = currentLow > prevLow ? 1 : currentLow < prevLow ? -1 : 0; double closeVote = currentClose > prevClose ? 1 : currentClose < prevClose ? -1 : 0; - double totalVotes = highVote + lowVote + closeVote; + var totalVotes = highVote + lowVote + closeVote; - double prevMvo = mvoList.LastOrDefault(); - double mvo = prevMvo + (currentVolume * totalVotes); + var prevMvo = mvoList.LastOrDefault(); + var mvo = prevMvo + (currentVolume * totalVotes); mvoList.AddRounded(mvo); } var mvoEmaList = GetMovingAverageList(stockData, maType, length, mvoList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double mvo = mvoList[i]; - double mvoEma = mvoEmaList[i]; - double prevMvo = i >= 1 ? mvoList[i - 1] : 0; - double prevMvoEma = i >= 1 ? mvoEmaList[i - 1] : 0; + var mvo = mvoList[i]; + var mvoEma = mvoEmaList[i]; + var prevMvo = i >= 1 ? mvoList[i - 1] : 0; + var prevMvoEma = i >= 1 ? mvoEmaList[i - 1] : 0; var signal = GetCompareSignal(mvo - mvoEma, prevMvo - prevMvoEma); signalsList.Add(signal); diff --git a/src/Calculations/Wilder.cs b/src/Calculations/Wilder.cs index fdd74a0..feed046 100644 --- a/src/Calculations/Wilder.cs +++ b/src/Calculations/Wilder.cs @@ -28,26 +28,26 @@ public static StockData CalculateAverageTrueRange(this StockData stockData, Movi var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); var maList = GetMovingAverageList(stockData, maType, length, inputList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevClose = i >= 1 ? inputList[i - 1] : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; - double currentTrueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); + var currentTrueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); trList.AddRounded(currentTrueRange); } var atrList = GetMovingAverageList(stockData, maType, length, trList); var atrMaList = GetMovingAverageList(stockData, maType, length, atrList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentValue = inputList[i]; - double atr = atrList[i]; - double currentMa = maList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - double prevMa = i >= 1 ? maList[i - 1] : 0; - double atrMa = atrMaList[i]; + var currentValue = inputList[i]; + var atr = atrList[i]; + var currentMa = maList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + var prevMa = i >= 1 ? maList[i - 1] : 0; + var atrMa = atrMaList[i]; var signal = GetVolatilitySignal(currentValue - currentMa, prevValue - prevMa, atr, atrMa); signalsList.Add(signal); @@ -82,55 +82,55 @@ public static StockData CalculateAverageDirectionalIndex(this StockData stockDat List signalsList = new(); var (inputList, highList, lowList, _, _) = GetInputValuesList(stockData); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentHigh = highList[i]; - double currentLow = lowList[i]; - double prevHigh = i >= 1 ? highList[i - 1] : 0; - double prevLow = i >= 1 ? lowList[i - 1] : 0; - double prevClose = i >= 1 ? inputList[i - 1] : 0; - double highDiff = currentHigh - prevHigh; - double lowDiff = prevLow - currentLow; - - double dmPlus = highDiff > lowDiff ? Math.Max(highDiff, 0) : 0; + var currentHigh = highList[i]; + var currentLow = lowList[i]; + var prevHigh = i >= 1 ? highList[i - 1] : 0; + var prevLow = i >= 1 ? lowList[i - 1] : 0; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var highDiff = currentHigh - prevHigh; + var lowDiff = prevLow - currentLow; + + var dmPlus = highDiff > lowDiff ? Math.Max(highDiff, 0) : 0; dmPlusList.AddRounded(dmPlus); - double dmMinus = highDiff < lowDiff ? Math.Max(lowDiff, 0) : 0; + var dmMinus = highDiff < lowDiff ? Math.Max(lowDiff, 0) : 0; dmMinusList.AddRounded(dmMinus); - double tr = CalculateTrueRange(currentHigh, currentLow, prevClose); + var tr = CalculateTrueRange(currentHigh, currentLow, prevClose); trList.AddRounded(tr); } var dmPlus14List = GetMovingAverageList(stockData, maType, length, dmPlusList); var dmMinus14List = GetMovingAverageList(stockData, maType, length, dmMinusList); var tr14List = GetMovingAverageList(stockData, maType, length, trList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double dmPlus14 = dmPlus14List[i]; - double dmMinus14 = dmMinus14List[i]; - double trueRange14 = tr14List[i]; + var dmPlus14 = dmPlus14List[i]; + var dmMinus14 = dmMinus14List[i]; + var trueRange14 = tr14List[i]; - double diPlus = trueRange14 != 0 ? MinOrMax(100 * dmPlus14 / trueRange14, 100, 0) : 0; + var diPlus = trueRange14 != 0 ? MinOrMax(100 * dmPlus14 / trueRange14, 100, 0) : 0; diPlusList.AddRounded(diPlus); - double diMinus = trueRange14 != 0 ? MinOrMax(100 * dmMinus14 / trueRange14, 100, 0) : 0; + var diMinus = trueRange14 != 0 ? MinOrMax(100 * dmMinus14 / trueRange14, 100, 0) : 0; diMinusList.AddRounded(diMinus); - double diDiff = Math.Abs(diPlus - diMinus); - double diSum = diPlus + diMinus; + var diDiff = Math.Abs(diPlus - diMinus); + var diSum = diPlus + diMinus; - double di = diSum != 0 ? MinOrMax(100 * diDiff / diSum, 100, 0) : 0; + var di = diSum != 0 ? MinOrMax(100 * diDiff / diSum, 100, 0) : 0; diList.AddRounded(di); } var adxList = GetMovingAverageList(stockData, maType, length, diList); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double diPlus = diPlusList[i]; - double diMinus = diMinusList[i]; - double prevDiPlus = i >= 1 ? diPlusList[i - 1] : 0; - double prevDiMinus = i >= 1 ? diMinusList[i - 1] : 0; + var diPlus = diPlusList[i]; + var diMinus = diMinusList[i]; + var prevDiPlus = i >= 1 ? diPlusList[i - 1] : 0; + var prevDiMinus = i >= 1 ? diMinusList[i - 1] : 0; var signal = GetCompareSignal(diPlus - diMinus, prevDiPlus - prevDiMinus); signalsList.Add(signal); @@ -169,18 +169,18 @@ public static StockData CalculateWellesWilderVolatilitySystem(this StockData sto var emaList = GetMovingAverageList(stockData, maType, length1, inputList); var (highestList, lowestList) = GetMaxAndMinValuesList(inputList, length2); - for (int i = 0; i < stockData.Count; i++) + for (var i = 0; i < stockData.Count; i++) { - double currentAtr = atrList[i]; - double currentEma = emaList[i]; - double highest = highestList[i]; - double lowest = lowestList[i]; - double currentValue = inputList[i]; - double prevValue = i >= 1 ? inputList[i - 1] : 0; - - double prevVStop = vstopList.LastOrDefault(); - double sic = currentValue > currentEma ? highest : lowest; - double vstop = currentValue > currentEma ? sic - (factor * currentAtr) : sic + (factor * currentAtr); + var currentAtr = atrList[i]; + var currentEma = emaList[i]; + var highest = highestList[i]; + var lowest = lowestList[i]; + var currentValue = inputList[i]; + var prevValue = i >= 1 ? inputList[i - 1] : 0; + + var prevVStop = vstopList.LastOrDefault(); + var sic = currentValue > currentEma ? highest : lowest; + var vstop = currentValue > currentEma ? sic - (factor * currentAtr) : sic + (factor * currentAtr); vstopList.AddRounded(vstop); var signal = GetCompareSignal(currentValue - vstop, prevValue - prevVStop); diff --git a/src/Helpers/CalculationsHelper.cs b/src/Helpers/CalculationsHelper.cs index 957176c..e22e010 100644 --- a/src/Helpers/CalculationsHelper.cs +++ b/src/Helpers/CalculationsHelper.cs @@ -536,7 +536,7 @@ public static (List inputList, List highList, List lowLi List openList; List closeList; List volumeList; - List inputList = inputName switch + var inputList = inputName switch { InputName.Close => stockData.ClosePrices, InputName.Low => stockData.LowPrices, @@ -556,7 +556,7 @@ public static (List inputList, List highList, List lowLi if (inputList.Count > 0) { - double sum = inputList.Sum(); + var sum = inputList.Sum(); if (inputList.SequenceEqual(stockData.Volumes) || sum < stockData.LowPrices.Sum() || sum > stockData.HighPrices.Sum()) { @@ -615,7 +615,7 @@ public static (List inputList, List highList, List lowLi if (inputList.Count > 0) { - double sum = inputList.Sum(); + var sum = inputList.Sum(); if (inputList.SequenceEqual(stockData.Volumes) || sum < stockData.LowPrices.Sum() || sum > stockData.HighPrices.Sum()) { @@ -658,7 +658,7 @@ public static (List inputList, List highList, List lowLi List volumeList = new(); var groupedDatesParent = stockData.TickerDataList.GroupBy(x => x.Date.Date); - for (int i = 0; i < groupedDatesParent.Count(); i++) + for (var i = 0; i < groupedDatesParent.Count(); i++) { var parent = groupedDatesParent.ElementAt(i); @@ -673,7 +673,7 @@ public static (List inputList, List highList, List lowLi _ => parent.GroupBy(x => x.Date.Day), }; - for (int j = 0; j < groupedDatesChild.Count(); j++) + for (var j = 0; j < groupedDatesChild.Count(); j++) { var groupedDates = groupedDatesChild.ElementAt(j); @@ -709,8 +709,8 @@ public static (List inputList, List highList, List lowLi /// public static double CalculateEMA(double currentValue, double prevEma, int length = 14) { - double k = MinOrMax((double)2 / (length + 1), 0.99, 0.01); - double ema = (currentValue * k) + (prevEma * (1 - k)); + var k = MinOrMax((double)2 / (length + 1), 0.99, 0.01); + var ema = (currentValue * k) + (prevEma * (1 - k)); return ema; } @@ -750,17 +750,17 @@ public static (List, List) GetMaxAndMinValuesList(List i List lowestValuesList = new(); List inputList = new(); - for (int i = 0; i < inputs.Count; i++) + for (var i = 0; i < inputs.Count; i++) { - double input = inputs[i]; + var input = inputs[i]; inputList.AddRounded(input); var list = inputList.TakeLastExt(Math.Max(length, 2)).ToList(); - double highestValue = list.Max(); + var highestValue = list.Max(); highestValuesList.AddRounded(highestValue); - double lowestValue = list.Min(); + var lowestValue = list.Min(); lowestValuesList.AddRounded(lowestValue); } @@ -782,18 +782,18 @@ public static (List, List) GetMaxAndMinValuesList(List h List tempLowList = new(); var count = highList.Count == lowList.Count ? highList.Count : 0; - for (int i = 0; i < count; i++) + for (var i = 0; i < count; i++) { - double high = highList[i]; + var high = highList[i]; tempHighList.AddRounded(high); - double low = lowList[i]; + var low = lowList[i]; tempLowList.AddRounded(low); - double highest = tempHighList.TakeLastExt(length).Max(); + var highest = tempHighList.TakeLastExt(length).Max(); highestList.AddRounded(highest); - double lowest = tempLowList.TakeLastExt(length).Min(); + var lowest = tempLowList.TakeLastExt(length).Min(); lowestList.AddRounded(lowest); } @@ -841,7 +841,7 @@ public static IEnumerable TakeLastExt(this IEnumerable source, int coun if (source is ICollection collection) { - foreach (T item in source.Skip(Math.Max(0, collection.Count - count))) + foreach (var item in source.Skip(Math.Max(0, collection.Count - count))) yield return item; yield break; @@ -849,7 +849,7 @@ public static IEnumerable TakeLastExt(this IEnumerable source, int coun if (source is IReadOnlyCollection collection1) { - foreach (T item in source.Skip(Math.Max(0, collection1.Count - count))) + foreach (var item in source.Skip(Math.Max(0, collection1.Count - count))) yield return item; yield break; @@ -857,7 +857,7 @@ public static IEnumerable TakeLastExt(this IEnumerable source, int coun Queue result = new(); - foreach (T item in source) + foreach (var item in source) { if (result.Count == count) result.Dequeue(); @@ -879,7 +879,7 @@ public static double PercentileNearestRank(this IEnumerable sequence, do { var list = sequence.OrderBy(i => i).ToList(); var n = list.Count; - int rank = n > 0 ? (int)Math.Ceiling(percentile / 100 * n) : 0; + var rank = n > 0 ? (int)Math.Ceiling(percentile / 100 * n) : 0; return list[Math.Max(rank - 1, 0)]; } @@ -896,8 +896,8 @@ public static double PercentileNearestRank(this IEnumerable sequence, do /// public static double RescaleValue(double value, double oldMax, double oldMin, double newMax, double newMin, bool isReversed = false) { - double d = isReversed ? (oldMax - value) : (value - oldMin); - double dRatio = oldMax - oldMin != 0 ? d / (oldMax - oldMin) : 0; + var d = isReversed ? (oldMax - value) : (value - oldMin); + var dRatio = oldMax - oldMin != 0 ? d / (oldMax - oldMin) : 0; return (dRatio * (newMax - newMin)) + newMin; } diff --git a/src/Helpers/MathHelper.cs b/src/Helpers/MathHelper.cs index ca44739..8ff84f1 100644 --- a/src/Helpers/MathHelper.cs +++ b/src/Helpers/MathHelper.cs @@ -130,7 +130,7 @@ public static double MinOrMax(double value, double maxValue, double minValue) /// public static int MinOrMax(int value) { - int result = double.IsNaN(value) ? 0 : double.IsPositiveInfinity(value) ? int.MaxValue : double.IsNegativeInfinity(value) ? int.MinValue : value; + var result = double.IsNaN(value) ? 0 : double.IsPositiveInfinity(value) ? int.MaxValue : double.IsNegativeInfinity(value) ? int.MinValue : value; return Math.Min(Math.Max(result, 2), 530); } } diff --git a/src/Models/StockData.cs b/src/Models/StockData.cs index e726c3b..cdb1640 100644 --- a/src/Models/StockData.cs +++ b/src/Models/StockData.cs @@ -55,7 +55,7 @@ public StockData(IEnumerable openPrices, IEnumerable highPrices, Count = (OpenPrices.Count + HighPrices.Count + LowPrices.Count + ClosePrices.Count + Volumes.Count + Dates.Count) / 6 == ClosePrices.Count ? ClosePrices.Count : 0; TickerDataList = new List(); - for (int i = 0; i < Count; i++) + for (var i = 0; i < Count; i++) { var open = OpenPrices[i]; var high = HighPrices[i]; @@ -94,7 +94,7 @@ public StockData(IEnumerable tickerDataList, InputName inputName = I SignalsList = new List(); InputName = inputName; - for (int i = 0; i < tickerDataList.Count(); i++) + for (var i = 0; i < tickerDataList.Count(); i++) { var ticker = tickerDataList.ElementAt(i);