diff --git a/Calculations/BollingerBands.cs b/Calculations/BollingerBands.cs index 63df20f..d4b46a4 100644 --- a/Calculations/BollingerBands.cs +++ b/Calculations/BollingerBands.cs @@ -22,11 +22,11 @@ public static StockData CalculateBollingerBands(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentStdDeviation = stdDeviationList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = smaList[i]; + decimal currentValue = inputList[i]; + decimal currentStdDeviation = stdDeviationList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (currentStdDeviation * stdDevMult); @@ -78,33 +78,33 @@ public static StockData CalculateAdaptivePriceZoneIndicator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal xHL = currentHigh - currentLow; - xHLList.Add(xHL); + 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++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal xVal1 = ema2List.ElementAtOrDefault(i); - decimal xVal2 = xHLEma2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal xVal1 = ema2List[i]; + decimal xVal2 = xHLEma2List[i]; decimal prevUpBand = outerUpBandList.LastOrDefault(); decimal outerUpBand = (pct * xVal2) + xVal1; - outerUpBandList.Add(outerUpBand); + outerUpBandList.AddRounded(outerUpBand); decimal prevDnBand = outerDnBandList.LastOrDefault(); decimal outerDnBand = xVal1 - (pct * xVal2); - outerDnBandList.Add(outerDnBand); + outerDnBandList.AddRounded(outerDnBand); decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (outerUpBand + outerDnBand) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, outerUpBand, prevUpBand, outerDnBand, prevDnBand); @@ -146,27 +146,27 @@ public static StockData CalculateAutoDispersionBands(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal x = currentValue - prevValue; decimal x2 = x * x; - x2List.Add(x2); + x2List.AddRounded(x2); decimal x2Sma = x2List.TakeLastExt(length).Average(); decimal sq = x2Sma >= 0 ? Sqrt(x2Sma) : 0; decimal a = currentValue + sq; - aList.Add(a); + aList.AddRounded(a); decimal b = currentValue - sq; - bList.Add(b); + bList.AddRounded(b); decimal aMax = aList.TakeLastExt(length).Max(); - aMaxList.Add(aMax); + aMaxList.AddRounded(aMax); decimal bMin = bList.TakeLastExt(length).Min(); - bMinList.Add(bMin); + bMinList.AddRounded(bMin); } var aMaList = GetMovingAverageList(stockData, maType, length, aMaxList); @@ -175,16 +175,16 @@ public static StockData CalculateAutoDispersionBands(this StockData stockData, M var lowerBandList = GetMovingAverageList(stockData, maType, smoothLength, bMaList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal upperBand = upperBandList.ElementAtOrDefault(i); - decimal lowerBand = lowerBandList.ElementAtOrDefault(i); - decimal prevUpperBand = i >= 1 ? upperBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowerBand = i >= 1 ? lowerBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal upperBand = upperBandList[i]; + decimal lowerBand = lowerBandList[i]; + decimal prevUpperBand = i >= 1 ? upperBandList[i - 1] : 0; + decimal prevLowerBand = i >= 1 ? lowerBandList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (upperBand + lowerBand) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -227,18 +227,18 @@ public static StockData CalculateBollingerBandsFibonacciRatios(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal atr = atrList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal atr = atrList[i]; + decimal sma = smaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal r1 = atr * fibRatio1; decimal r2 = atr * fibRatio2; decimal r3 = atr * fibRatio3; decimal prevFibTop3 = fibTop3List.LastOrDefault(); decimal fibTop3 = sma + r3; - fibTop3List.Add(fibTop3); + fibTop3List.AddRounded(fibTop3); decimal fibTop2 = sma + r2; decimal fibTop1 = sma + r1; @@ -247,7 +247,7 @@ public static StockData CalculateBollingerBandsFibonacciRatios(this StockData st decimal prevFibBottom3 = fibBottom3List.LastOrDefault(); decimal fibBottom3 = sma - r3; - fibBottom3List.Add(fibBottom3); + fibBottom3List.AddRounded(fibBottom3); var signal = GetBollingerBandsSignal(currentValue - sma, prevValue - prevSma, currentValue, prevValue, fibTop3, prevFibTop3, fibBottom3, prevFibBottom3); @@ -291,17 +291,17 @@ public static StockData CalculateBollingerBandsAvgTrueRange(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal upperBand = upperBandList.ElementAtOrDefault(i); - decimal lowerBand = lowerBandList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal currentAtr = atrList[i]; + decimal upperBand = upperBandList[i]; + decimal lowerBand = lowerBandList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal bbDiff = upperBand - lowerBand; decimal atrDev = bbDiff != 0 ? currentAtr / bbDiff : 0; - atrDevList.Add(atrDev); + atrDevList.AddRounded(atrDev); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, atrDev, 0.5m); signalsList.Add(signal); @@ -342,31 +342,31 @@ public static StockData CalculateBollingerBandsWithAtrPct(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal basis = smaList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal basis = smaList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal lh = currentHigh - currentLow; decimal hc = Math.Abs(currentHigh - prevValue); decimal lc = Math.Abs(currentLow - prevValue); decimal mm = Math.Max(Math.Max(lh, hc), lc); - decimal prevBasis = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal prevBasis = i >= 1 ? smaList[i - 1] : 0; decimal atrs = mm == hc ? hc / (prevValue + (hc / 2)) : mm == lc ? lc / (currentLow + (lc / 2)) : mm == lh ? lh / (currentLow + (lh / 2)) : 0; decimal prevAptr = aptrList.LastOrDefault(); decimal aptr = (100 * atrs * ratio) + (prevAptr * (1 - ratio)); - aptrList.Add(aptr); + aptrList.AddRounded(aptr); decimal dev = stdDevMult * aptr; decimal prevUpper = upperList.LastOrDefault(); decimal upper = basis + (basis * dev / 100); - upperList.Add(upper); + upperList.AddRounded(upper); decimal prevLower = lowerList.LastOrDefault(); decimal lower = basis - (basis * dev / 100); - lowerList.Add(lower); + lowerList.AddRounded(lower); var signal = GetBollingerBandsSignal(currentValue - basis, prevValue - prevBasis, currentValue, prevValue, upper, prevUpper, lower, prevLower); signalsList.Add(signal); @@ -406,11 +406,11 @@ public static StockData CalculateBollingerBandsPercentB(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal upperBand = upperBandList.ElementAtOrDefault(i); - decimal lowerBand = lowerBandList.ElementAtOrDefault(i); - decimal prevPctB1 = i >= 1 ? pctBList.ElementAtOrDefault(i - 1) : 0; - decimal prevPctB2 = i >= 2 ? pctBList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal upperBand = upperBandList[i]; + decimal lowerBand = lowerBandList[i]; + decimal prevPctB1 = i >= 1 ? pctBList[i - 1] : 0; + decimal prevPctB2 = i >= 2 ? pctBList[i - 2] : 0; decimal pctB = upperBand - lowerBand != 0 ? (currentValue - lowerBand) / (upperBand - lowerBand) * 100 : 0; pctBList.AddRounded(pctB); @@ -452,12 +452,12 @@ public static StockData CalculateBollingerBandsWidth(this StockData stockData, d for (int i = 0; i < stockData.Count; i++) { - decimal upperBand = upperBandList.ElementAtOrDefault(i); - decimal lowerBand = lowerBandList.ElementAtOrDefault(i); - decimal middleBand = middleBandList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? middleBandList.ElementAtOrDefault(i - 1) : 0; + decimal upperBand = upperBandList[i]; + decimal lowerBand = lowerBandList[i]; + decimal middleBand = middleBandList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; decimal prevBbWidth = bbWidthList.LastOrDefault(); decimal bbWidth = middleBand != 0 ? (upperBand - lowerBand) / middleBand : 0; @@ -505,29 +505,29 @@ public static StockData CalculateVervoortModifiedBollingerBandIndicator(this Sto for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevOhlc = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = inputList[i]; + decimal prevOhlc = i >= 1 ? inputList[i - 1] : 0; decimal prevHaOpen = haOpenList.LastOrDefault(); decimal haOpen = (prevOhlc + prevHaOpen) / 2; - haOpenList.Add(haOpen); + haOpenList.AddRounded(haOpen); decimal haC = (currentValue + haOpen + Math.Max(currentHigh, haOpen) + Math.Min(currentLow, haOpen)) / 4; - hacList.Add(haC); + 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++) { - decimal tma1 = tma1List.ElementAtOrDefault(i); - decimal tma2 = tma2List.ElementAtOrDefault(i); + decimal tma1 = tma1List[i]; + decimal tma2 = tma2List[i]; decimal diff = tma1 - tma2; decimal zlha = tma1 + diff; - zlhaList.Add(zlha); + zlhaList.AddRounded(zlha); } var zlhaTemaList = GetMovingAverageList(stockData, maType, smoothLength, zlhaList); @@ -536,33 +536,33 @@ public static StockData CalculateVervoortModifiedBollingerBandIndicator(this Sto var wmaZlhaTemaList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, length1, zlhaTemaList); for (int i = 0; i < stockData.Count; i++) { - decimal zihaTema = zlhaTemaList.ElementAtOrDefault(i); - decimal zihaTemaStdDev = zlhaTemaStdDevList.ElementAtOrDefault(i); - decimal wmaZihaTema = wmaZlhaTemaList.ElementAtOrDefault(i); + decimal zihaTema = zlhaTemaList[i]; + decimal zihaTemaStdDev = zlhaTemaStdDevList[i]; + decimal wmaZihaTema = wmaZlhaTemaList[i]; decimal percb = zihaTemaStdDev != 0 ? (zihaTema + (2 * zihaTemaStdDev) - wmaZihaTema) / (4 * zihaTemaStdDev) * 100 : 0; - percbList.Add(percb); + percbList.AddRounded(percb); } stockData.CustomValuesList = percbList; var percbStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length2).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = percbList.ElementAtOrDefault(i); - decimal percbStdDev = percbStdDevList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? percbList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = percbList[i]; + decimal percbStdDev = percbStdDevList[i]; + decimal prevValue = i >= 1 ? percbList[i - 1] : 0; decimal prevUb = ubList.LastOrDefault(); decimal ub = 50 + (stdDevMult * percbStdDev); - ubList.Add(ub); + ubList.AddRounded(ub); decimal prevLb = lbList.LastOrDefault(); decimal lb = 50 - (stdDevMult * percbStdDev); - lbList.Add(lb); + lbList.AddRounded(lb); decimal prevPercbSignal = percbSignalList.LastOrDefault(); decimal percbSignal = (ub + lb) / 2; - percbSignalList.Add(percbSignal); + percbSignalList.AddRounded(percbSignal); Signal signal = GetBollingerBandsSignal(currentValue - percbSignal, prevValue - prevPercbSignal, currentValue, prevValue, ub, prevUb, lb, prevLb); diff --git a/Calculations/Chande.cs b/Calculations/Chande.cs index a739ff8..9c54ffc 100644 --- a/Calculations/Chande.cs +++ b/Calculations/Chande.cs @@ -17,18 +17,18 @@ public static StockData CalculateChandeQuickStick(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; decimal openClose = currentClose - currentOpen; - openCloseList.Add(openClose); + openCloseList.AddRounded(openClose); } var smaList = GetMovingAverageList(stockData, maType, length, openCloseList); for (int i = 0; i < stockData.Count; i++) { - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal sma = smaList[i]; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; var signal = GetCompareSignal(sma, prevSma); signalsList.Add(signal); @@ -64,8 +64,8 @@ public static StockData CalculateChandeMomentumOscillatorFilter(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal diff = currentValue - prevValue; decimal absDiff = Math.Abs(currentValue - prevValue); @@ -73,23 +73,23 @@ public static StockData CalculateChandeMomentumOscillatorFilter(this StockData s { diff = 0; absDiff = 0; } - diffList.Add(diff); - absDiffList.Add(absDiff); + diffList.AddRounded(diff); + absDiffList.AddRounded(absDiff); decimal diffSum = diffList.TakeLastExt(length).Sum(); decimal absDiffSum = absDiffList.TakeLastExt(length).Sum(); decimal cmo = absDiffSum != 0 ? MinOrMax(100 * diffSum / absDiffSum, 100, -100) : 0; - cmoList.Add(cmo); + cmoList.AddRounded(cmo); } var cmoSignalList = GetMovingAverageList(stockData, maType, length, cmoList); for (int i = 0; i < stockData.Count; i++) { - decimal cmo = cmoList.ElementAtOrDefault(i); - decimal cmoSignal = cmoSignalList.ElementAtOrDefault(i); - decimal prevCmo = i >= 1 ? cmoList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoSignal = i >= 1 ? cmoSignalList.ElementAtOrDefault(i - 1) : 0; + decimal cmo = cmoList[i]; + decimal cmoSignal = cmoSignalList[i]; + decimal prevCmo = i >= 1 ? cmoList[i - 1] : 0; + decimal prevCmoSignal = i >= 1 ? cmoSignalList[i - 1] : 0; var signal = GetRsiSignal(cmo - cmoSignal, prevCmo - prevCmoSignal, cmo, prevCmo, 70, -70); signalsList.Add(signal); @@ -122,20 +122,20 @@ public static StockData CalculateChandeMomentumOscillatorAbsolute(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal prevCmoAbs1 = i >= 1 ? cmoAbsList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoAbs2 = i >= 2 ? cmoAbsList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorValue = i >= length ? inputList[i - length] : 0; + decimal prevCmoAbs1 = i >= 1 ? cmoAbsList[i - 1] : 0; + decimal prevCmoAbs2 = i >= 2 ? cmoAbsList[i - 2] : 0; decimal absDiff = Math.Abs(currentValue - prevValue); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal num = Math.Abs(100 * (currentValue - priorValue)); decimal denom = absDiffList.TakeLastExt(length).Sum(); decimal cmoAbs = denom != 0 ? MinOrMax(num / denom, 100, 0) : 0; - cmoAbsList.Add(cmoAbs); + cmoAbsList.AddRounded(cmoAbs); var signal = GetRsiSignal(cmoAbs - prevCmoAbs1, prevCmoAbs1 - prevCmoAbs2, cmoAbs, prevCmoAbs1, 70, 30); signalsList.Add(signal); @@ -170,16 +170,16 @@ public static StockData CalculateChandeMomentumOscillatorAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal prevPrice = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoAvg1 = i >= 1 ? cmoAvgList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoAvg2 = i >= 2 ? cmoAvgList.ElementAtOrDefault(i - 2) : 0; + decimal currentPrice = inputList[i]; + decimal prevPrice = i >= 1 ? inputList[i - 1] : 0; + decimal prevCmoAvg1 = i >= 1 ? cmoAvgList[i - 1] : 0; + decimal prevCmoAvg2 = i >= 2 ? cmoAvgList[i - 2] : 0; decimal diff = currentPrice - prevPrice; - diffList.Add(diff); + diffList.AddRounded(diff); decimal absDiff = Math.Abs(diff); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal diffSum1 = diffList.TakeLastExt(length1).Sum(); decimal absSum1 = absDiffList.TakeLastExt(length1).Sum(); @@ -192,7 +192,7 @@ public static StockData CalculateChandeMomentumOscillatorAverage(this StockData decimal temp3 = absSum3 != 0 ? MinOrMax(diffSum3 / absSum3, 1, -1) : 0; decimal cmoAvg = 100 * ((temp1 + temp2 + temp3) / 3); - cmoAvgList.Add(cmoAvg); + cmoAvgList.AddRounded(cmoAvg); var signal = GetRsiSignal(cmoAvg - prevCmoAvg1, prevCmoAvg1 - prevCmoAvg2, cmoAvg, prevCmoAvg1, 50, -50); signalsList.Add(signal); @@ -227,16 +227,16 @@ public static StockData CalculateChandeMomentumOscillatorAbsoluteAverage(this St for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal prevPrice = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoAbsAvg1 = i >= 1 ? cmoAbsAvgList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoAbsAvg2 = i >= 2 ? cmoAbsAvgList.ElementAtOrDefault(i - 2) : 0; + decimal currentPrice = inputList[i]; + decimal prevPrice = i >= 1 ? inputList[i - 1] : 0; + decimal prevCmoAbsAvg1 = i >= 1 ? cmoAbsAvgList[i - 1] : 0; + decimal prevCmoAbsAvg2 = i >= 2 ? cmoAbsAvgList[i - 2] : 0; decimal diff = currentPrice - prevPrice; - diffList.Add(diff); + diffList.AddRounded(diff); decimal absDiff = Math.Abs(diff); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal diffSum1 = diffList.TakeLastExt(length1).Sum(); decimal absSum1 = absDiffList.TakeLastExt(length1).Sum(); @@ -249,7 +249,7 @@ public static StockData CalculateChandeMomentumOscillatorAbsoluteAverage(this St decimal temp3 = absSum3 != 0 ? MinOrMax(diffSum3 / absSum3, 1, -1) : 0; decimal cmoAbsAvg = Math.Abs(100 * ((temp1 + temp2 + temp3) / 3)); - cmoAbsAvgList.Add(cmoAbsAvg); + cmoAbsAvgList.AddRounded(cmoAbsAvg); var signal = GetRsiSignal(cmoAbsAvg - prevCmoAbsAvg1, prevCmoAbsAvg1 - prevCmoAbsAvg2, cmoAbsAvg, prevCmoAbsAvg1, 70, 30); signalsList.Add(signal); @@ -296,14 +296,14 @@ public static StockData CalculateChandeCompositeMomentumIndex(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal valueDiff1 = currentValue > prevValue ? currentValue - prevValue : 0; - valueDiff1List.Add(valueDiff1); + valueDiff1List.AddRounded(valueDiff1); decimal valueDiff2 = currentValue < prevValue ? prevValue - currentValue : 0; - valueDiff2List.Add(valueDiff2); + valueDiff2List.AddRounded(valueDiff2); decimal cmo51 = valueDiff1List.TakeLastExt(length1).Sum(); decimal cmo52 = valueDiff2List.TakeLastExt(length1).Sum(); @@ -313,13 +313,13 @@ public static StockData CalculateChandeCompositeMomentumIndex(this StockData sto decimal cmo202 = valueDiff2List.TakeLastExt(length3).Sum(); decimal cmo5Ratio = cmo51 + cmo52 != 0 ? MinOrMax(100 * (cmo51 - cmo52) / (cmo51 + cmo52), 100, -100) : 0; - cmo5RatioList.Add(cmo5Ratio); + cmo5RatioList.AddRounded(cmo5Ratio); decimal cmo10Ratio = cmo101 + cmo102 != 0 ? MinOrMax(100 * (cmo101 - cmo102) / (cmo101 + cmo102), 100, -100) : 0; - cmo10RatioList.Add(cmo10Ratio); + cmo10RatioList.AddRounded(cmo10Ratio); decimal cmo20Ratio = cmo201 + cmo202 != 0 ? MinOrMax(100 * (cmo201 - cmo202) / (cmo201 + cmo202), 100, -100) : 0; - cmo20RatioList.Add(cmo20Ratio); + cmo20RatioList.AddRounded(cmo20Ratio); } var cmo5List = GetMovingAverageList(stockData, maType, smoothLength, cmo5RatioList); @@ -327,24 +327,24 @@ public static StockData CalculateChandeCompositeMomentumIndex(this StockData sto var cmo20List = GetMovingAverageList(stockData, maType, smoothLength, cmo20RatioList); for (int i = 0; i < stockData.Count; i++) { - decimal stdDev5 = stdDevList.ElementAtOrDefault(i); - decimal stdDev10 = stdDev10List.ElementAtOrDefault(i); - decimal stdDev20 = stdDev20List.ElementAtOrDefault(i); - decimal cmo5 = cmo5List.ElementAtOrDefault(i); - decimal cmo10 = cmo10List.ElementAtOrDefault(i); - decimal cmo20 = cmo20List.ElementAtOrDefault(i); + decimal stdDev5 = stdDevList[i]; + decimal stdDev10 = stdDev10List[i]; + decimal stdDev20 = stdDev20List[i]; + decimal cmo5 = cmo5List[i]; + decimal cmo10 = cmo10List[i]; + decimal cmo20 = cmo20List[i]; decimal dmi = stdDev5 + stdDev10 + stdDev20 != 0 ? MinOrMax(((stdDev5 * cmo5) + (stdDev10 * cmo10) + (stdDev20 * cmo20)) / (stdDev5 + stdDev10 + stdDev20), 100, -100) : 0; - dmiList.Add(dmi); + dmiList.AddRounded(dmi); decimal prevS = sList.LastOrDefault(); decimal s = dmiList.TakeLastExt(length1).Average(); - sList.Add(s); + sList.AddRounded(s); decimal prevE = eList.LastOrDefault(); decimal e = CalculateEMA(dmi, prevE, smoothLength); - eList.Add(e); + eList.AddRounded(e); var signal = GetRsiSignal(e - s, prevE - prevS, e, prevE, 70, -70); signalsList.Add(signal); @@ -384,17 +384,17 @@ public static StockData CalculateChandeMomentumOscillatorAverageDisparityIndex(t for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal firstEma = firstEmaList.ElementAtOrDefault(i); - decimal secondEma = secondEmaList.ElementAtOrDefault(i); - decimal thirdEma = thirdEmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal firstEma = firstEmaList[i]; + decimal secondEma = secondEmaList[i]; + decimal thirdEma = thirdEmaList[i]; decimal firstDisparityIndex = currentValue != 0 ? (currentValue - firstEma) / currentValue * 100 : 0; decimal secondDisparityIndex = currentValue != 0 ? (currentValue - secondEma) / currentValue * 100 : 0; decimal thirdDisparityIndex = currentValue != 0 ? (currentValue - thirdEma) / currentValue * 100 : 0; decimal prevAvgDisparityIndex = avgDisparityIndexList.LastOrDefault(); decimal avgDisparityIndex = (firstDisparityIndex + secondDisparityIndex + thirdDisparityIndex) / 3; - avgDisparityIndexList.Add(avgDisparityIndex); + avgDisparityIndexList.AddRounded(avgDisparityIndex); var signal = GetCompareSignal(avgDisparityIndex, prevAvgDisparityIndex); signalsList.Add(signal); @@ -431,23 +431,23 @@ public static StockData CalculateChandeKrollRSquaredIndex(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempValueList.Add(currentValue); + decimal currentValue = inputList[i]; + tempValueList.AddRounded(currentValue); var r2 = GoodnessOfFit.RSquared(indexList.TakeLastExt(length).Select(x => (double)x), tempValueList.TakeLastExt(length).Select(x => (double)x)); r2 = IsValueNullOrInfinity(r2) ? 0 : r2; - r2RawList.Add((decimal)r2); + r2RawList.AddRounded((decimal)r2); } var r2SmoothedList = GetMovingAverageList(stockData, maType, smoothLength, r2RawList); for (int i = 0; i < stockData.Count; i++) { - decimal r2Sma = r2SmoothedList.ElementAtOrDefault(i); - decimal prevR2Sma1 = i >= 1 ? r2SmoothedList.ElementAtOrDefault(i - 1) : 0; - decimal prevR2Sma2 = i >= 2 ? r2SmoothedList.ElementAtOrDefault(i - 2) : 0; + decimal r2Sma = r2SmoothedList[i]; + decimal prevR2Sma1 = i >= 1 ? r2SmoothedList[i - 1] : 0; + decimal prevR2Sma2 = i >= 2 ? r2SmoothedList[i - 2] : 0; var signal = GetCompareSignal(r2Sma - prevR2Sma1, prevR2Sma1 - prevR2Sma2); signalsList.Add(signal); @@ -486,19 +486,19 @@ public static StockData CalculateChandeVolatilityIndexDynamicAverageIndicator(th for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentStdDev = stdDevList.ElementAtOrDefault(i); - decimal currentStdDevEma = stdDevEmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentStdDev = stdDevList[i]; + decimal currentStdDevEma = stdDevEmaList[i]; decimal prevVidya1 = i >= 1 ? vidya1List.LastOrDefault() : currentValue; decimal prevVidya2 = i >= 1 ? vidya2List.LastOrDefault() : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ratio = currentStdDevEma != 0 ? currentStdDev / currentStdDevEma : 0; decimal vidya1 = (alpha1 * ratio * currentValue) + ((1 - (alpha1 * ratio)) * prevVidya1); - vidya1List.Add(vidya1); + vidya1List.AddRounded(vidya1); decimal vidya2 = (alpha2 * ratio * currentValue) + ((1 - (alpha2 * ratio)) * prevVidya2); - vidya2List.Add(vidya2); + vidya2List.AddRounded(vidya2); var signal = GetBullishBearishSignal(currentValue - Math.Max(vidya1, vidya2), prevValue - Math.Max(prevVidya1, prevVidya2), currentValue - Math.Min(vidya1, vidya2), prevValue - Math.Min(prevVidya1, prevVidya2)); @@ -532,16 +532,16 @@ public static StockData CalculateChandeTrendScore(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevTs = tsList.LastOrDefault(); decimal ts = 0; for (int j = startLength; j <= endLength; j++) { - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; ts += currentValue >= prevValue ? 1 : -1; } - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(ts, prevTs); signalsList.Add(signal); @@ -574,12 +574,12 @@ public static StockData CalculateChandeForecastOscillator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentLinReg = linRegList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentLinReg = linRegList[i]; decimal prevPf = pfList.LastOrDefault(); decimal pf = currentValue != 0 ? (currentValue - currentLinReg) * 100 / currentValue : 0; - pfList.Add(pf); + pfList.AddRounded(pf); var signal = GetCompareSignal(pf, prevPf); signalsList.Add(signal); @@ -612,24 +612,24 @@ public static StockData CalculateChandeIntradayMomentumIndex(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevImi1 = i >= 1 ? imiUnfilteredList.ElementAtOrDefault(i - 1) : 0; - decimal prevImi2 = i >= 2 ? imiUnfilteredList.ElementAtOrDefault(i - 2) : 0; + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal prevImi1 = i >= 1 ? imiUnfilteredList[i - 1] : 0; + decimal prevImi2 = i >= 2 ? imiUnfilteredList[i - 2] : 0; decimal prevGains = gainsList.LastOrDefault(); decimal gains = currentClose > currentOpen ? prevGains + (currentClose - currentOpen) : 0; - gainsList.Add(gains); + gainsList.AddRounded(gains); decimal prevLosses = lossesList.LastOrDefault(); decimal losses = currentClose < currentOpen ? prevLosses + (currentOpen - currentClose) : 0; - lossesList.Add(losses); + lossesList.AddRounded(losses); decimal upt = gainsList.TakeLastExt(length).Sum(); decimal dnt = lossesList.TakeLastExt(length).Sum(); decimal imiUnfiltered = upt + dnt != 0 ? MinOrMax(100 * upt / (upt + dnt), 100, 0) : 0; - imiUnfilteredList.Add(imiUnfiltered); + imiUnfilteredList.AddRounded(imiUnfiltered); var signal = GetRsiSignal(imiUnfiltered - prevImi1, prevImi1 - prevImi2, imiUnfiltered, prevImi1, 70, 30); signalsList.Add(signal); @@ -665,30 +665,30 @@ public static StockData CalculateChandeMomentumOscillator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal diff = currentValue - prevValue; decimal negChg = diff < 0 ? Math.Abs(diff) : 0; - cmoNegChgList.Add(negChg); + cmoNegChgList.AddRounded(negChg); decimal posChg = diff > 0 ? diff : 0; - cmoPosChgList.Add(posChg); + cmoPosChgList.AddRounded(posChg); decimal negSum = cmoNegChgList.TakeLastExt(length).Sum(); decimal posSum = cmoPosChgList.TakeLastExt(length).Sum(); decimal cmo = posSum + negSum != 0 ? MinOrMax((posSum - negSum) / (posSum + negSum) * 100, 100, -100) : 0; - cmoList.Add(cmo); + cmoList.AddRounded(cmo); } var cmoSignalList = GetMovingAverageList(stockData, maType, signalLength, cmoList); for (int i = 0; i < stockData.Count; i++) { - decimal cmo = cmoList.ElementAtOrDefault(i); - decimal cmoSignal = cmoSignalList.ElementAtOrDefault(i); - decimal prevCmo = i >= 1 ? cmoList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmoSignal = i >= 1 ? cmoSignalList.ElementAtOrDefault(i - 1) : 0; + decimal cmo = cmoList[i]; + decimal cmoSignal = cmoSignalList[i]; + decimal prevCmo = i >= 1 ? cmoList[i - 1] : 0; + decimal prevCmoSignal = i >= 1 ? cmoSignalList[i - 1] : 0; var signal = GetRsiSignal(cmo - cmoSignal, prevCmo - prevCmoSignal, cmo, prevCmo, 50, -50); signalsList.Add(signal); diff --git a/Calculations/Demark.cs b/Calculations/Demark.cs index e89a286..5efe8e0 100644 --- a/Calculations/Demark.cs +++ b/Calculations/Demark.cs @@ -18,18 +18,18 @@ public static StockData CalculateDemarkRangeExpansionIndex(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal high = highList.ElementAtOrDefault(i); - decimal prevHigh2 = i >= 2 ? highList.ElementAtOrDefault(i - 2) : 0; - decimal prevHigh5 = i >= 5 ? highList.ElementAtOrDefault(i - 5) : 0; - decimal prevHigh6 = i >= 6 ? highList.ElementAtOrDefault(i - 6) : 0; - decimal low = lowList.ElementAtOrDefault(i); - decimal prevLow2 = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; - decimal prevLow5 = i >= 5 ? lowList.ElementAtOrDefault(i - 5) : 0; - decimal prevLow6 = i >= 6 ? lowList.ElementAtOrDefault(i - 6) : 0; - decimal prevClose7 = i >= 7 ? inputList.ElementAtOrDefault(i - 7) : 0; - decimal prevClose8 = i >= 8 ? inputList.ElementAtOrDefault(i - 8) : 0; - decimal prevRei1 = i >= 1 ? reiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRei2 = i >= 2 ? reiList.ElementAtOrDefault(i - 2) : 0; + decimal high = highList[i]; + decimal prevHigh2 = i >= 2 ? highList[i - 2] : 0; + decimal prevHigh5 = i >= 5 ? highList[i - 5] : 0; + decimal prevHigh6 = i >= 6 ? highList[i - 6] : 0; + decimal low = lowList[i]; + decimal prevLow2 = i >= 2 ? lowList[i - 2] : 0; + decimal prevLow5 = i >= 5 ? lowList[i - 5] : 0; + decimal prevLow6 = i >= 6 ? lowList[i - 6] : 0; + decimal prevClose7 = i >= 7 ? inputList[i - 7] : 0; + decimal prevClose8 = i >= 8 ? inputList[i - 8] : 0; + decimal prevRei1 = i >= 1 ? reiList[i - 1] : 0; + decimal prevRei2 = i >= 2 ? reiList[i - 2] : 0; decimal n = (high >= prevLow5 || high >= prevLow6) && (low <= prevHigh5 || low <= prevHigh6) ? 0 : 1; decimal m = prevHigh2 >= prevClose8 && (prevLow2 <= prevClose7 || prevLow2 <= prevClose8) ? 0 : 1; decimal s = high - prevHigh2 + (low - prevLow2); @@ -44,7 +44,7 @@ public static StockData CalculateDemarkRangeExpansionIndex(this StockData stockD decimal s2Sum = s2List.TakeLastExt(length).Sum(); decimal rei = s2Sum != 0 ? s1Sum / s2Sum * 100 : 0; - reiList.Add(rei); + reiList.AddRounded(rei); var signal = GetRsiSignal(rei - prevRei1, prevRei1 - prevRei2, rei, prevRei1, 100, -100); signalsList.Add(signal); @@ -77,30 +77,30 @@ public static StockData CalculateDemarkPressureRatioV1(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevPr1 = i >= 1 ? pressureRatioList.ElementAtOrDefault(i - 1) : 0; - decimal prevPr2 = i >= 2 ? pressureRatioList.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevPr1 = i >= 1 ? pressureRatioList[i - 1] : 0; + decimal prevPr2 = i >= 2 ? pressureRatioList[i - 2] : 0; decimal gapup = prevClose != 0 ? (currentOpen - prevClose) / prevClose : 0; decimal gapdown = currentOpen != 0 ? (prevClose - currentOpen) / currentOpen : 0; decimal bp = gapup > 0.15m ? (currentHigh - prevClose + currentClose - currentLow) * currentVolume : currentClose > currentOpen ? (currentClose - currentOpen) * currentVolume : 0; - bpList.Add(bp); + bpList.AddRounded(bp); decimal sp = gapdown > 0.15m ? (prevClose - currentLow + currentHigh - currentClose) * currentVolume : currentClose < currentOpen ? (currentClose - currentOpen) * currentVolume : 0; - spList.Add(sp); + spList.AddRounded(sp); decimal bpSum = bpList.TakeLastExt(length).Sum(); decimal spSum = spList.TakeLastExt(length).Sum(); decimal pressureRatio = bpSum - spSum != 0 ? MinOrMax(100 * bpSum / (bpSum - spSum), 100, 0) : 0; - pressureRatioList.Add(pressureRatio); + pressureRatioList.AddRounded(pressureRatio); var signal = GetRsiSignal(pressureRatio - prevPr1, prevPr1 - prevPr2, pressureRatio, prevPr1, 75, 25); signalsList.Add(signal); @@ -133,29 +133,29 @@ public static StockData CalculateDemarkPressureRatioV2(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; + decimal currentVolume = volumeList[i]; decimal delta = currentClose - currentOpen; decimal trueRange = currentHigh - currentLow; decimal ratio = trueRange != 0 ? delta / trueRange : 0; - decimal prevPr1 = i >= 1 ? pressureRatioList.ElementAtOrDefault(i - 1) : 0; - decimal prevPr2 = i >= 2 ? pressureRatioList.ElementAtOrDefault(i - 2) : 0; + decimal prevPr1 = i >= 1 ? pressureRatioList[i - 1] : 0; + decimal prevPr2 = i >= 2 ? pressureRatioList[i - 2] : 0; decimal buyingPressure = delta > 0 ? ratio * currentVolume : 0; - bpList.Add(buyingPressure); + bpList.AddRounded(buyingPressure); decimal sellingPressure = delta < 0 ? ratio * currentVolume : 0; - spList.Add(sellingPressure); + spList.AddRounded(sellingPressure); decimal bpSum = bpList.TakeLastExt(length).Sum(); decimal spSum = spList.TakeLastExt(length).Sum(); decimal denom = bpSum + Math.Abs(spSum); decimal pressureRatio = denom != 0 ? MinOrMax(100 * bpSum / denom, 100, 0) : 50; - pressureRatioList.Add(pressureRatio); + pressureRatioList.AddRounded(pressureRatio); var signal = GetRsiSignal(pressureRatio - prevPr1, prevPr1 - prevPr2, pressureRatio, prevPr1, 75, 25); signalsList.Add(signal); @@ -187,13 +187,13 @@ public static StockData CalculateDemarkReversalPoints(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal uCount = 0, dCount = 0; for (int j = 0; j < length1; j++) { - decimal value = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - decimal prevValue = i >= j + length2 ? inputList.ElementAtOrDefault(i - (j + length2)) : 0; + decimal value = i >= j ? inputList[i - j] : 0; + decimal prevValue = i >= j + length2 ? inputList[i - (j + length2)] : 0; uCount += value > prevValue ? 1 : 0; dCount += value < prevValue ? 1 : 0; @@ -201,7 +201,7 @@ public static StockData CalculateDemarkReversalPoints(this StockData stockData, decimal drp = dCount == length1 ? 1 : uCount == length1 ? -1 : 0; decimal drpPrice = drp != 0 ? currentValue : 0; - drpPriceList.Add(drpPrice); + drpPriceList.AddRounded(drpPrice); var signal = GetConditionSignal(drp > 0 || uCount > dCount, drp < 0 || dCount > uCount); signalsList.Add(signal); @@ -232,13 +232,13 @@ public static StockData CalculateDemarkSetupIndicator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal uCount = 0, dCount = 0; for (int j = 0; j < length; j++) { - decimal value = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - decimal prevValue = i >= j + length ? inputList.ElementAtOrDefault(i - (j + length)) : 0; + decimal value = i >= j ? inputList[i - j] : 0; + decimal prevValue = i >= j + length ? inputList[i - (j + length)] : 0; uCount += value > prevValue ? 1 : 0; dCount += value < prevValue ? 1 : 0; @@ -246,7 +246,7 @@ public static StockData CalculateDemarkSetupIndicator(this StockData stockData, decimal drp = dCount == length ? 1 : uCount == length ? -1 : 0; decimal drpPrice = drp != 0 ? currentValue : 0; - drpPriceList.Add(drpPrice); + drpPriceList.AddRounded(drpPrice); var signal = GetConditionSignal(drp > 0 || uCount > dCount, drp < 0 || dCount > uCount); signalsList.Add(signal); @@ -280,29 +280,29 @@ public static StockData CalculateDemarker(this StockData stockData, MovingAvgTyp for (int i = 0; i < stockData.Count; i++) { - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentLow = lowList[i]; + decimal currentHigh = highList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal dMax = currentHigh > prevHigh ? currentHigh - prevHigh : 0; - dMaxList.Add(dMax); + dMaxList.AddRounded(dMax); decimal dMin = currentLow < prevLow ? prevLow - currentLow : 0; - dMinList.Add(dMin); + 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++) { - decimal maxMa = maxMaList.ElementAtOrDefault(i); - decimal minMa = minMaList.ElementAtOrDefault(i); - decimal prevDemarker1 = i >= 1 ? demarkerList.ElementAtOrDefault(i - 1) : 0; - decimal prevDemarker2 = i >= 2 ? demarkerList.ElementAtOrDefault(i - 2) : 0; + decimal maxMa = maxMaList[i]; + decimal minMa = minMaList[i]; + decimal prevDemarker1 = i >= 1 ? demarkerList[i - 1] : 0; + decimal prevDemarker2 = i >= 2 ? demarkerList[i - 2] : 0; decimal demarker = maxMa + minMa != 0 ? MinOrMax(maxMa / (maxMa + minMa) * 100, 100, 0) : 0; - demarkerList.Add(demarker); + demarkerList.AddRounded(demarker); var signal = GetRsiSignal(demarker - prevDemarker1, prevDemarker1 - prevDemarker2, demarker, prevDemarker1, 70, 30); signalsList.Add(signal); diff --git a/Calculations/Ehlers.cs b/Calculations/Ehlers.cs index aaf2416..ddaec57 100644 --- a/Calculations/Ehlers.cs +++ b/Calculations/Ehlers.cs @@ -27,13 +27,13 @@ public static StockData CalculateEhlersRoofingFilterV2(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? highPassList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? highPassList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? highPassList[i - 2] : 0; decimal test1 = Pow((1 - alpha1) / 2, 2); decimal test2 = currentValue - (2 * prevValue1) + prevValue2; decimal v1 = test1 * test2; @@ -41,12 +41,12 @@ public static StockData CalculateEhlersRoofingFilterV2(this StockData stockData, decimal v3 = Pow(1 - alpha1, 2) * prevHp2; decimal highPass = v1 + v2 - v3; - highPassList.Add(highPass); + highPassList.AddRounded(highPass); - decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; + decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; decimal roofingFilter = (c1 * ((highPass + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); - roofingFilterList.Add(roofingFilter); + roofingFilterList.AddRounded(roofingFilter); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); signalsList.Add(signal); @@ -82,7 +82,7 @@ public static StockData CalculateEhlersPhaseCalculation(this StockData stockData decimal realPart = 0, imagPart = 0; for (int j = 0; j < length; j++) { - decimal weight = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal weight = i >= j ? inputList[i - j] : 0; realPart += Cos(2 * Pi * (decimal)j / length) * weight; imagPart += Sin(2 * Pi * (decimal)j / length) * weight; } @@ -98,10 +98,10 @@ public static StockData CalculateEhlersPhaseCalculation(this StockData stockData var phaseEmaList = GetMovingAverageList(stockData, maType, length, phaseList); for (int i = 0; i < stockData.Count; i++) { - decimal phase = phaseList.ElementAtOrDefault(i); - decimal phaseEma = phaseEmaList.ElementAtOrDefault(i); - decimal prevPhase = i >= 1 ? phaseList.ElementAtOrDefault(i - 1) : 0; - decimal prevPhaseEma = i >= 1 ? phaseEmaList.ElementAtOrDefault(i - 1) : 0; + decimal phase = phaseList[i]; + decimal phaseEma = phaseEmaList[i]; + decimal prevPhase = i >= 1 ? phaseList[i - 1] : 0; + decimal prevPhaseEma = i >= 1 ? phaseEmaList[i - 1] : 0; var signal = GetCompareSignal(phase - phaseEma, prevPhase - prevPhaseEma, true); signalsList.Add(signal); @@ -141,53 +141,53 @@ public static StockData CalculateEhlersAdaptiveCyberCycle(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevCycle = i >= 1 ? cycleList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmooth = i >= 1 ? smoothList.ElementAtOrDefault(i - 1) : 0; - decimal prevIp = i >= 1 ? ipList.ElementAtOrDefault(i - 1) : 0; - decimal prevAc1 = i >= 1 ? acList.ElementAtOrDefault(i - 1) : 0; - decimal prevI1 = i >= 1 ? i1List.ElementAtOrDefault(i - 1) : 0; - decimal prevQ1 = i >= 1 ? q1List.ElementAtOrDefault(i - 1) : 0; - decimal prevP = i >= 1 ? pList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevSmooth2 = i >= 2 ? smoothList.ElementAtOrDefault(i - 2) : 0; - decimal prevCycle2 = i >= 2 ? cycleList.ElementAtOrDefault(i - 2) : 0; - decimal prevAc2 = i >= 2 ? acList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal prevCycle3 = i >= 3 ? cycleList.ElementAtOrDefault(i - 3) : 0; - decimal prevCycle4 = i >= 4 ? cycleList.ElementAtOrDefault(i - 4) : 0; - decimal prevCycle6 = i >= 6 ? cycleList.ElementAtOrDefault(i - 6) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevCycle = i >= 1 ? cycleList[i - 1] : 0; + decimal prevSmooth = i >= 1 ? smoothList[i - 1] : 0; + decimal prevIp = i >= 1 ? ipList[i - 1] : 0; + decimal prevAc1 = i >= 1 ? acList[i - 1] : 0; + decimal prevI1 = i >= 1 ? i1List[i - 1] : 0; + decimal prevQ1 = i >= 1 ? q1List[i - 1] : 0; + decimal prevP = i >= 1 ? pList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + decimal prevCycle2 = i >= 2 ? cycleList[i - 2] : 0; + decimal prevAc2 = i >= 2 ? acList[i - 2] : 0; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; + decimal prevCycle3 = i >= 3 ? cycleList[i - 3] : 0; + decimal prevCycle4 = i >= 4 ? cycleList[i - 4] : 0; + decimal prevCycle6 = i >= 6 ? cycleList[i - 6] : 0; decimal smooth = (currentValue + (2 * prevValue) + (2 * prevValue2) + prevValue3) / 6; - smoothList.Add(smooth); + smoothList.AddRounded(smooth); decimal cycle = i < 7 ? (currentValue - (2 * prevValue) + prevValue2) / 4 : (Pow(1 - (0.5m * alpha), 2) * (smooth - (2 * prevSmooth) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle) - (Pow(1 - alpha, 2) * prevCycle2); - cycleList.Add(cycle); + cycleList.AddRounded(cycle); decimal q1 = ((0.0962m * cycle) + (0.5769m * prevCycle2) - (0.5769m * prevCycle4) - (0.0962m * prevCycle6)) * (0.5m + (0.08m * prevIp)); - q1List.Add(q1); + q1List.AddRounded(q1); decimal i1 = prevCycle3; - i1List.Add(i1); + i1List.AddRounded(i1); decimal dp = MinOrMax(q1 != 0 && prevQ1 != 0 ? ((i1 / q1) - (prevI1 / prevQ1)) / (1 + (i1 * prevI1 / (q1 * prevQ1))) : 0, 1.1m, 0.1m); - dpList.Add(dp); + dpList.AddRounded(dp); decimal medianDelta = dpList.TakeLastExt(length).Median(); decimal dc = medianDelta != 0 ? (6.28318m / medianDelta) + 0.5m : 15; decimal ip = (0.33m * dc) + (0.67m * prevIp); - ipList.Add(ip); + ipList.AddRounded(ip); decimal p = (0.15m * ip) + (0.85m * prevP); - pList.Add(p); + pList.AddRounded(p); decimal a1 = 2 / (p + 1); decimal ac = i < 7 ? (currentValue - (2 * prevValue) + prevValue2) / 4 : (Pow(1 - (0.5m * a1), 2) * (smooth - (2 * prevSmooth) + prevSmooth2)) + (2 * (1 - a1) * prevAc1) - (Pow(1 - a1, 2) * prevAc2); - acList.Add(ac); + acList.AddRounded(ac); var signal = GetCompareSignal(ac - prevAc1, prevAc1 - prevAc2); signalsList.Add(signal); @@ -225,19 +225,19 @@ public static StockData CalculateEhlersSimpleDecycler(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal hp = hpList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal hp = hpList[i]; decimal prevDecycler = decyclerList.LastOrDefault(); decimal decycler = currentValue - hp; - decyclerList.Add(decycler); + decyclerList.AddRounded(decycler); decimal upperBand = (1 + (upperPct / 100)) * decycler; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal lowerBand = (1 - (lowerPct / 100)) * decycler; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetCompareSignal(currentValue - decycler, prevValue - prevDecycler); signalsList.Add(signal); @@ -275,16 +275,16 @@ public static StockData CalculateEhlersHighPassFilterV1(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? highPassList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? highPassList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? highPassList[i - 2] : 0; decimal pow1 = Pow(1 - (alpha / 2), 2); decimal pow2 = Pow(1 - alpha, 2); decimal highPass = (pow1 * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - alpha) * prevHp1) - (pow2 * prevHp2); - highPassList.Add(highPass); + highPassList.AddRounded(highPass); var signal = GetCompareSignal(highPass, prevHp1); signalsList.Add(signal); @@ -328,31 +328,31 @@ public static StockData CalculateEhlersRocketRelativeStrengthIndex(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 - 1 ? inputList.ElementAtOrDefault(i - (length1 - 1)) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length1 - 1 ? inputList[i - (length1 - 1)] : 0; decimal prevMom = momList.LastOrDefault(); decimal mom = currentValue - prevValue; - momList.Add(mom); + momList.AddRounded(mom); decimal arg = (mom + prevMom) / 2; - argList.Add(arg); + argList.AddRounded(arg); } var argSsf2PoleList = GetMovingAverageList(stockData, maType, length2, argList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal ssf2Pole = argSsf2PoleList.ElementAtOrDefault(j); - decimal prevSsf2Pole = j >= 1 ? argSsf2PoleList.ElementAtOrDefault(j - 1) : 0; - decimal prevRocketRsi1 = j >= 1 ? ssf2PoleRocketRsiList.ElementAtOrDefault(j - 1) : 0; - decimal prevRocketRsi2 = j >= 2 ? ssf2PoleRocketRsiList.ElementAtOrDefault(j - 2) : 0; + decimal ssf2Pole = argSsf2PoleList[i]; + decimal prevSsf2Pole = i >= 1 ? argSsf2PoleList[i - 1] : 0; + decimal prevRocketRsi1 = i >= 1 ? ssf2PoleRocketRsiList[i - 1] : 0; + decimal prevRocketRsi2 = i >= 2 ? ssf2PoleRocketRsiList[i - 2] : 0; decimal ssf2PoleMom = ssf2Pole - prevSsf2Pole; decimal up2PoleChg = ssf2PoleMom > 0 ? ssf2PoleMom : 0; - ssf2PoleUpChgList.Add(up2PoleChg); + ssf2PoleUpChgList.AddRounded(up2PoleChg); decimal down2PoleChg = ssf2PoleMom < 0 ? Math.Abs(ssf2PoleMom) : 0; - ssf2PoleDownChgList.Add(down2PoleChg); + ssf2PoleDownChgList.AddRounded(down2PoleChg); decimal up2PoleChgSum = ssf2PoleUpChgList.TakeLastExt(length1).Sum(); decimal down2PoleChgSum = ssf2PoleDownChgList.TakeLastExt(length1).Sum(); @@ -360,12 +360,12 @@ public static StockData CalculateEhlersRocketRelativeStrengthIndex(this StockDat decimal prevTmp2Pole = ssf2PoleTmpList.LastOrDefault(); decimal tmp2Pole = up2PoleChgSum + down2PoleChgSum != 0 ? MinOrMax((up2PoleChgSum - down2PoleChgSum) / (up2PoleChgSum + down2PoleChgSum), 0.999m, -0.999m) : prevTmp2Pole; - ssf2PoleTmpList.Add(tmp2Pole); + ssf2PoleTmpList.AddRounded(tmp2Pole); decimal ssf2PoleTempLog = 1 - tmp2Pole != 0 ? (1 + tmp2Pole) / (1 - tmp2Pole) : 0; decimal ssf2PoleLog = Log(ssf2PoleTempLog); decimal ssf2PoleRocketRsi = 0.5m * ssf2PoleLog * mult; - ssf2PoleRocketRsiList.Add(ssf2PoleRocketRsi); + ssf2PoleRocketRsiList.AddRounded(ssf2PoleRocketRsi); var signal = GetRsiSignal(ssf2PoleRocketRsi - prevRocketRsi1, prevRocketRsi1 - prevRocketRsi2, ssf2PoleRocketRsi, prevRocketRsi1, obLevel, osLevel); signalsList.Add(signal); @@ -396,13 +396,13 @@ public static StockData CalculateEhlersCorrelationTrendIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal prevCorr1 = i >= 1 ? corrList.ElementAtOrDefault(i - 1) : 0; - decimal prevCorr2 = i >= 2 ? corrList.ElementAtOrDefault(i - 2) : 0; + decimal prevCorr1 = i >= 1 ? corrList[i - 1] : 0; + decimal prevCorr2 = i >= 2 ? corrList[i - 2] : 0; decimal sx = 0, sy = 0, sxx = 0, sxy = 0, syy = 0; for (int j = 0; j <= length - 1; j++) { - decimal x = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal x = i >= j ? inputList[i - j] : 0; decimal y = -j; sx += x; @@ -414,7 +414,7 @@ public static StockData CalculateEhlersCorrelationTrendIndicator(this StockData decimal 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.Add(corr); + corrList.AddRounded(corr); var signal = GetRsiSignal(corr - prevCorr1, prevCorr1 - prevCorr2, corr, prevCorr1, 0.5m, -0.5m); signalsList.Add(signal); @@ -448,23 +448,23 @@ public static StockData CalculateEhlersRelativeVigorIndex(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal rvi = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; - rviList.Add(rvi); + 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++) { - decimal rviSma = rviSmaList.ElementAtOrDefault(i); - decimal prevRviSma = i >= 1 ? rviSmaList.ElementAtOrDefault(i - 1) : 0; - decimal rviSignal = rviSignalList.ElementAtOrDefault(i); - decimal prevRviSignal = i >= 1 ? rviSignalList.ElementAtOrDefault(i - 1) : 0; + decimal rviSma = rviSmaList[i]; + decimal prevRviSma = i >= 1 ? rviSmaList[i - 1] : 0; + decimal rviSignal = rviSignalList[i]; + decimal prevRviSignal = i >= 1 ? rviSignalList[i - 1] : 0; var signal = GetCompareSignal(rviSma - rviSignal, prevRviSma - prevRviSignal); signalsList.Add(signal); @@ -499,14 +499,14 @@ public static StockData CalculateEhlersCenterofGravityOscillator(this StockData decimal num = 0, denom = 0; for (int j = 0; j <= length - 1; j++) { - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; num += (1 + j) * prevValue; denom += prevValue; } decimal prevCg = cgList.LastOrDefault(); decimal cg = denom != 0 ? (-num / denom) + ((decimal)(length + 1) / 2) : 0; - cgList.Add(cg); + cgList.AddRounded(cg); var signal = GetCompareSignal(cg, prevCg); signalsList.Add(signal); @@ -539,21 +539,21 @@ public static StockData CalculateEhlersAdaptiveCenterOfGravityOscillator(this St for (int i = 0; i < stockData.Count; i++) { - decimal p = pList.ElementAtOrDefault(i); + decimal p = pList[i]; int intPeriod = (int)Math.Ceiling(p / 2); - decimal prevCg1 = i >= 1 ? cgList.ElementAtOrDefault(i - 1) : 0; - decimal prevCg2 = i >= 2 ? cgList.ElementAtOrDefault(i - 2) : 0; + decimal prevCg1 = i >= 1 ? cgList[i - 1] : 0; + decimal prevCg2 = i >= 2 ? cgList[i - 2] : 0; decimal num = 0, denom = 0; for (int j = 0; j <= intPeriod - 1; j++) { - decimal prevPrice = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevPrice = i >= j ? inputList[i - j] : 0; num += (1 + j) * prevPrice; denom += prevPrice; } decimal cg = denom != 0 ? (-num / denom) + ((intPeriod + 1) / 2) : 0; - cgList.Add(cg); + cgList.AddRounded(cg); var signal = GetCompareSignal(cg - prevCg1, prevCg1 - prevCg2); signalsList.Add(signal); @@ -597,27 +597,26 @@ public static StockData CalculateEhlersSmoothedAdaptiveMomentum(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevP = i >= 1 ? pList.ElementAtOrDefault(i - 1) : 0; - decimal p = pList.ElementAtOrDefault(i); - decimal prevF3_1 = i >= 1 ? f3List.ElementAtOrDefault(i - 1) : 0; - decimal prevF3_2 = i >= 2 ? f3List.ElementAtOrDefault(i - 2) : 0; - decimal prevF3_3 = i >= 3 ? f3List.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal p = pList[i]; + decimal prevF3_1 = i >= 1 ? f3List[i - 1] : 0; + decimal prevF3_2 = i >= 2 ? f3List[i - 2] : 0; + decimal prevF3_3 = i >= 3 ? f3List[i - 3] : 0; int pr = (int)Math.Ceiling(Math.Abs(p - 1)); - decimal prevValue = i >= pr ? inputList.ElementAtOrDefault(i - pr) : 0; + decimal prevValue = i >= pr ? inputList[i - pr] : 0; decimal v1 = currentValue - prevValue; decimal f3 = (coef1 * v1) + (coef2 * prevF3_1) + (coef3 * prevF3_2) + (coef4 * prevF3_3); - f3List.Add(f3); + f3List.AddRounded(f3); } var f3EmaList = GetMovingAverageList(stockData, maType, length2, f3List); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal f3 = f3List.ElementAtOrDefault(j); - decimal f3Ema = f3EmaList.ElementAtOrDefault(j); - decimal prevF3 = j >= 1 ? f3List.ElementAtOrDefault(j - 1) : 0; - decimal prevF3Ema = j >= 1 ? f3EmaList.ElementAtOrDefault(j - 1) : 0; + decimal f3 = f3List[i]; + decimal f3Ema = f3EmaList[i]; + decimal prevF3 = i >= 1 ? f3List[i - 1] : 0; + decimal prevF3Ema = i >= 1 ? f3EmaList[i - 1] : 0; var signal = GetCompareSignal(f3 - f3Ema, prevF3 - prevF3Ema); signalsList.Add(signal); @@ -653,25 +652,25 @@ public static StockData CalculateEhlersStochasticCenterOfGravityOscillator(this for (int i = 0; i < stockData.Count; i++) { - decimal cg = ehlersCGOscillatorList.ElementAtOrDefault(i); - decimal maxc = highestList.ElementAtOrDefault(i); - decimal minc = lowestList.ElementAtOrDefault(i); - decimal prevV1_1 = i >= 1 ? v1List.ElementAtOrDefault(i - 1) : 0; - decimal prevV1_2 = i >= 2 ? v1List.ElementAtOrDefault(i - 2) : 0; - decimal prevV1_3 = i >= 3 ? v1List.ElementAtOrDefault(i - 3) : 0; - decimal prevV2_1 = i >= 1 ? v2List.ElementAtOrDefault(i - 1) : 0; - decimal prevT1 = i >= 1 ? tList.ElementAtOrDefault(i - 1) : 0; - decimal prevT2 = i >= 2 ? tList.ElementAtOrDefault(i - 2) : 0; + decimal cg = ehlersCGOscillatorList[i]; + decimal maxc = highestList[i]; + decimal minc = lowestList[i]; + decimal prevV1_1 = i >= 1 ? v1List[i - 1] : 0; + decimal prevV1_2 = i >= 2 ? v1List[i - 2] : 0; + decimal prevV1_3 = i >= 3 ? v1List[i - 3] : 0; + decimal prevV2_1 = i >= 1 ? v2List[i - 1] : 0; + decimal prevT1 = i >= 1 ? tList[i - 1] : 0; + decimal prevT2 = i >= 2 ? tList[i - 2] : 0; decimal v1 = maxc - minc != 0 ? (cg - minc) / (maxc - minc) : 0; - v1List.Add(v1); + v1List.AddRounded(v1); decimal v2_ = ((4 * v1) + (3 * prevV1_1) + (2 * prevV1_2) + prevV1_3) / 10; decimal v2 = 2 * (v2_ - 0.5m); - v2List.Add(v2); + v2List.AddRounded(v2); decimal t = MinOrMax(0.96m * (prevV2_1 + 0.02m), 1, 0); - tList.Add(t); + tList.AddRounded(t); var signal = GetRsiSignal(t - prevT1, prevT1 - prevT2, t, prevT1, 0.8m, 0.2m); signalsList.Add(signal); @@ -704,26 +703,26 @@ public static StockData CalculateEhlersSimpleCycleIndicator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentMedianPrice = inputList.ElementAtOrDefault(i); - decimal prevMedianPrice1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMedianPrice2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevMedianPrice3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; + decimal currentMedianPrice = inputList[i]; + decimal prevMedianPrice1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevMedianPrice2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevMedianPrice3 = i >= 3 ? inputList[i - 3] : 0; decimal prevSmooth1 = smoothList.LastOrDefault(); decimal prevCycle1 = cycle_List.LastOrDefault(); - decimal prevSmooth2 = i >= 2 ? smoothList.ElementAtOrDefault(i - 2) : 0; - decimal prevCycle2 = i >= 2 ? cycle_List.ElementAtOrDefault(i - 2) : 0; - decimal prevCyc1 = i >= 1 ? cycleList.ElementAtOrDefault(i - 1) : 0; - decimal prevCyc2 = i >= 2 ? cycleList.ElementAtOrDefault(i - 2) : 0; + decimal prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + decimal prevCycle2 = i >= 2 ? cycle_List[i - 2] : 0; + decimal prevCyc1 = i >= 1 ? cycleList[i - 1] : 0; + decimal prevCyc2 = i >= 2 ? cycleList[i - 2] : 0; decimal smooth = (currentMedianPrice + (2 * prevMedianPrice1) + (2 * prevMedianPrice2) + prevMedianPrice3) / 6; - smoothList.Add(smooth); + smoothList.AddRounded(smooth); decimal cycle_ = ((1 - (0.5m * alpha)) * (1 - (0.5m * alpha)) * (smooth - (2 * prevSmooth1) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle1) - ((1 - alpha) * (1 - alpha) * prevCycle2); - cycle_List.Add(cycle_); + cycle_List.AddRounded(cycle_); decimal cycle = i < 7 ? (currentMedianPrice - (2 * prevMedianPrice1) + prevMedianPrice2) / 4 : cycle_; - cycleList.Add(cycle); + cycleList.AddRounded(cycle); var signal = GetCompareSignal(cycle - prevCyc1, prevCyc1 - prevCyc2); signalsList.Add(signal); @@ -766,17 +765,17 @@ public static StockData CalculateEhlersDecyclerOscillatorV1(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal decycler1Filtered = decycler1FilteredList.ElementAtOrDefault(i); - decimal decycler2Filtered = decycler2FilteredList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal decycler1Filtered = decycler1FilteredList[i]; + decimal decycler2Filtered = decycler2FilteredList[i]; decimal prevDecyclerOsc1 = decycler1OscillatorList.LastOrDefault(); decimal decyclerOscillator1 = currentValue != 0 ? 100 * fastMult * decycler1Filtered / currentValue : 0; - decycler1OscillatorList.Add(decyclerOscillator1); + decycler1OscillatorList.AddRounded(decyclerOscillator1); decimal prevDecyclerOsc2 = decycler2OscillatorList.LastOrDefault(); decimal decyclerOscillator2 = currentValue != 0 ? 100 * slowMult * decycler2Filtered / currentValue : 0; - decycler2OscillatorList.Add(decyclerOscillator2); + decycler2OscillatorList.AddRounded(decyclerOscillator2); var signal = GetCompareSignal(decyclerOscillator2 - decyclerOscillator1, prevDecyclerOsc2 - prevDecyclerOsc1); signalsList.Add(signal); @@ -815,23 +814,23 @@ public static StockData CalculateEhlersHighPassFilterV2(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; decimal hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); - hpList.Add(hp); + 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++) { - decimal hp = hpMa2List.ElementAtOrDefault(i); - decimal prevHp1 = i >= 1 ? hpMa2List.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpMa2List.ElementAtOrDefault(i - 2) : 0; + decimal hp = hpMa2List[i]; + decimal prevHp1 = i >= 1 ? hpMa2List[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpMa2List[i - 2] : 0; var signal = GetCompareSignal(hp - prevHp1, prevHp1 - prevHp2); signalsList.Add(signal); @@ -867,12 +866,12 @@ public static StockData CalculateEhlersDecyclerOscillatorV2(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal hp1 = hp1List.ElementAtOrDefault(i); - decimal hp2 = hp2List.ElementAtOrDefault(i); + decimal hp1 = hp1List[i]; + decimal hp2 = hp2List[i]; decimal prevDec = decList.LastOrDefault(); decimal dec = hp2 - hp1; - decList.Add(dec); + decList.AddRounded(dec); var signal = GetCompareSignal(dec, prevDec); signalsList.Add(signal); @@ -916,18 +915,18 @@ public static StockData CalculateEhlersModifiedStochasticIndicator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevModStoc1 = i >= 1 ? modStocList.ElementAtOrDefault(i - 1) : 0; - decimal prevModStoc2 = i >= 2 ? modStocList.ElementAtOrDefault(i - 2) : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal roofingFilter = roofingFilterList[i]; + decimal prevModStoc1 = i >= 1 ? modStocList[i - 1] : 0; + decimal prevModStoc2 = i >= 2 ? modStocList[i - 2] : 0; decimal prevStoc = stocList.LastOrDefault(); decimal stoc = highest - lowest != 0 ? (roofingFilter - lowest) / (highest - lowest) * 100 : 0; - stocList.Add(stoc); + stocList.AddRounded(stoc); decimal modStoc = (c1 * ((stoc + prevStoc) / 2)) + (c2 * prevModStoc1) + (c3 * prevModStoc2); - modStocList.Add(modStoc); + modStocList.AddRounded(modStoc); var signal = GetRsiSignal(modStoc - prevModStoc1, prevModStoc1 - prevModStoc2, modStoc, prevModStoc1, 70, 30); signalsList.Add(signal); @@ -971,30 +970,30 @@ public static StockData CalculateEhlersModifiedRelativeStrengthIndex(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevRoofingFilter = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevMrsi1 = i >= 1 ? mrsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevMrsi2 = i >= 2 ? mrsiList.ElementAtOrDefault(i - 2) : 0; - decimal prevMrsiSig1 = i >= 1 ? mrsiSigList.ElementAtOrDefault(i - 1) : 0; - decimal prevMrsiSig2 = i >= 2 ? mrsiSigList.ElementAtOrDefault(i - 2) : 0; + decimal roofingFilter = roofingFilterList[i]; + decimal prevRoofingFilter = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevMrsi1 = i >= 1 ? mrsiList[i - 1] : 0; + decimal prevMrsi2 = i >= 2 ? mrsiList[i - 2] : 0; + decimal prevMrsiSig1 = i >= 1 ? mrsiSigList[i - 1] : 0; + decimal prevMrsiSig2 = i >= 2 ? mrsiSigList[i - 2] : 0; decimal upChg = roofingFilter > prevRoofingFilter ? roofingFilter - prevRoofingFilter : 0; - upChgList.Add(upChg); + upChgList.AddRounded(upChg); decimal dnChg = roofingFilter < prevRoofingFilter ? prevRoofingFilter - roofingFilter : 0; decimal prevUpChgSum = upChgSumList.LastOrDefault(); decimal upChgSum = upChgList.TakeLastExt(length3).Sum(); - upChgSumList.Add(upChgSum); + upChgSumList.AddRounded(upChgSum); decimal prevDenom = denomList.LastOrDefault(); decimal denom = upChg + dnChg; - denomList.Add(denom); + denomList.AddRounded(denom); decimal mrsi = denom != 0 && prevDenom != 0 ? (c1 * (((upChgSum / denom) + (prevUpChgSum / prevDenom)) / 2)) + (c2 * prevMrsi1) + (c3 * prevMrsi2) : 0; - mrsiList.Add(mrsi); + mrsiList.AddRounded(mrsi); decimal mrsiSig = (c1 * ((mrsi + prevMrsi1) / 2)) + (c2 * prevMrsiSig1) + (c3 * prevMrsiSig2); - mrsiSigList.Add(mrsiSig); + mrsiSigList.AddRounded(mrsiSig); var signal = GetRsiSignal(mrsi - mrsiSig, prevMrsi1 - prevMrsiSig1, mrsi, prevMrsi1, 0.7m, 0.3m); signalsList.Add(signal); @@ -1037,17 +1036,17 @@ public static StockData CalculateEhlersHpLpRoofingFilter(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? highPassList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? highPassList[i - 1] : 0; decimal hp = ((1 - (alpha1 / 2)) * (currentValue - prevValue1)) + ((1 - alpha1) * prevHp1); - highPassList.Add(hp); + highPassList.AddRounded(hp); decimal filter = (c1 * ((hp + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); - roofingFilterList.Add(filter); + roofingFilterList.AddRounded(filter); var signal = GetCompareSignal(filter - prevFilter1, prevFilter1 - prevFilter2); signalsList.Add(signal); @@ -1082,12 +1081,12 @@ public static StockData CalculateEhlersDecycler(this StockData stockData, int le for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; decimal prevDec = decList.LastOrDefault(); decimal dec = (alpha1 / 2 * (currentValue + prevValue1)) + ((1 - alpha1) * prevDec); - decList.Add(dec); + decList.AddRounded(dec); var signal = GetCompareSignal(currentValue - dec, prevValue1 - prevDec); signalsList.Add(signal); @@ -1124,13 +1123,13 @@ public static StockData CalculateEhlersZeroMeanRoofingFilter(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentRf = roofingFilterList.ElementAtOrDefault(i); - decimal prevRf = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevZmrFilt1 = i >= 1 ? zmrFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevZmrFilt2 = i >= 2 ? zmrFilterList.ElementAtOrDefault(i - 2) : 0; + decimal currentRf = roofingFilterList[i]; + decimal prevRf = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevZmrFilt1 = i >= 1 ? zmrFilterList[i - 1] : 0; + decimal prevZmrFilt2 = i >= 2 ? zmrFilterList[i - 2] : 0; decimal zmrFilt = ((1 - (alpha1 / 2)) * (currentRf - prevRf)) + ((1 - alpha1) * prevZmrFilt1); - zmrFilterList.Add(zmrFilt); + zmrFilterList.AddRounded(zmrFilt); var signal = GetCompareSignal(zmrFilt - prevZmrFilt1, prevZmrFilt1 - prevZmrFilt2); signalsList.Add(signal); @@ -1172,19 +1171,19 @@ public static StockData CalculateEhlersRoofingFilterIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? highPassList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? highPassList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? highPassList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? highPassList[i - 2] : 0; decimal hp = (Pow(1 - (a1 / 2), 2) * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - a1) * prevHp1) - (Pow(1 - a1, 2) * prevHp2); - highPassList.Add(hp); + highPassList.AddRounded(hp); decimal filter = (c1 * ((hp + prevHp1) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); - roofingFilterList.Add(filter); + roofingFilterList.AddRounded(filter); var signal = GetCompareSignal(filter - prevFilter1, prevFilter1 - prevFilter2); signalsList.Add(signal); @@ -1228,14 +1227,14 @@ public static StockData CalculateEhlersHurstCoefficient(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal hh3 = hh3List.ElementAtOrDefault(i); - decimal ll3 = ll3List.ElementAtOrDefault(i); - decimal hh1 = hh1List.ElementAtOrDefault(i); - decimal ll1 = ll1List.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal priorValue = i >= hLength ? inputList.ElementAtOrDefault(i - hLength) : currentValue; - decimal prevSmoothHurst1 = i >= 1 ? smoothHurstList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmoothHurst2 = i >= 2 ? smoothHurstList.ElementAtOrDefault(i - 2) : 0; + decimal hh3 = hh3List[i]; + decimal ll3 = ll3List[i]; + decimal hh1 = hh1List[i]; + decimal ll1 = ll1List[i]; + decimal currentValue = inputList[i]; + decimal priorValue = i >= hLength ? inputList[i - hLength] : currentValue; + decimal prevSmoothHurst1 = i >= 1 ? smoothHurstList[i - 1] : 0; + decimal prevSmoothHurst2 = i >= 2 ? smoothHurstList[i - 2] : 0; decimal n3 = (hh3 - ll3) / length1; decimal n1 = (hh1 - ll1) / hLength; decimal hh2 = i >= hLength ? priorValue : currentValue; @@ -1243,7 +1242,7 @@ public static StockData CalculateEhlersHurstCoefficient(this StockData stockData for (int j = hLength; j < length1; j++) { - decimal price = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal price = i >= j ? inputList[i - j] : 0; hh2 = price > hh2 ? price : hh2; ll2 = price < ll2 ? price : ll2; } @@ -1251,14 +1250,14 @@ public static StockData CalculateEhlersHurstCoefficient(this StockData stockData decimal prevDimen = dimenList.LastOrDefault(); decimal dimen = 0.5m * (((Log(n1 + n2) - Log(n3)) / Log(2)) + prevDimen); - dimenList.Add(dimen); + dimenList.AddRounded(dimen); decimal prevHurst = hurstList.LastOrDefault(); decimal hurst = 2 - dimen; - hurstList.Add(hurst); + hurstList.AddRounded(hurst); decimal smoothHurst = (c1 * ((hurst + prevHurst) / 2)) + (c2 * prevSmoothHurst1) + (c3 * prevSmoothHurst2); - smoothHurstList.Add(smoothHurst); + smoothHurstList.AddRounded(smoothHurst); var signal = GetCompareSignal(smoothHurst - prevSmoothHurst1, prevSmoothHurst1 - prevSmoothHurst2); signalsList.Add(signal); @@ -1297,32 +1296,32 @@ public static StockData CalculateEhlersReflexIndicator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevFilter1 = filterList.LastOrDefault(); - decimal prevFilter2 = i >= 2 ? filterList.ElementAtOrDefault(i - 2) : 0; - decimal priorFilter = i >= length ? filterList.ElementAtOrDefault(i - length) : 0; - decimal prevReflex1 = i >= 1 ? reflexList.ElementAtOrDefault(i - 1) : 0; - decimal prevReflex2 = i >= 2 ? reflexList.ElementAtOrDefault(i - 2) : 0; + decimal prevFilter2 = i >= 2 ? filterList[i - 2] : 0; + decimal priorFilter = i >= length ? filterList[i - length] : 0; + decimal prevReflex1 = i >= 1 ? reflexList[i - 1] : 0; + decimal prevReflex2 = i >= 2 ? reflexList[i - 2] : 0; decimal filter = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); - filterList.Add(filter); + filterList.AddRounded(filter); decimal slope = length != 0 ? (priorFilter - filter) / length : 0; decimal sum = 0; for (int j = 1; j <= length; j++) { - decimal prevFilterCount = i >= j ? filterList.ElementAtOrDefault(i - j) : 0; + decimal prevFilterCount = i >= j ? filterList[i - j] : 0; sum += filter + (j * slope) - prevFilterCount; } sum /= length; decimal prevMs = msList.LastOrDefault(); decimal ms = (0.04m * sum * sum) + (0.96m * prevMs); - msList.Add(ms); + msList.AddRounded(ms); decimal reflex = ms > 0 ? sum / Sqrt(ms) : 0; - reflexList.Add(reflex); + reflexList.AddRounded(reflex); var signal = GetCompareSignal(reflex - prevReflex1, prevReflex1 - prevReflex2); signalsList.Add(signal); @@ -1366,21 +1365,21 @@ public static StockData CalculateEhlersSpectrumDerivedFilterBank(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal delta = Math.Max((-0.015m * i) + 0.5m, 0.15m); - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp3 = i >= 3 ? hpList.ElementAtOrDefault(i - 3) : 0; - decimal prevHp4 = i >= 4 ? hpList.ElementAtOrDefault(i - 4) : 0; - decimal prevHp5 = i >= 5 ? hpList.ElementAtOrDefault(i - 5) : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevHp3 = i >= 3 ? hpList[i - 3] : 0; + decimal prevHp4 = i >= 4 ? hpList[i - 4] : 0; + decimal prevHp5 = i >= 5 ? hpList[i - 5] : 0; decimal hp = i < 7 ? currentValue : (0.5m * (1 + alpha1) * (currentValue - prevValue)) + (alpha1 * prevHp1); - hpList.Add(hp); + hpList.AddRounded(hp); decimal prevSmoothHp = smoothHpList.LastOrDefault(); decimal smoothHp = i < 7 ? currentValue - prevValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; - smoothHpList.Add(smoothHp); + smoothHpList.AddRounded(smoothHp); decimal num = 0, denom = 0, dc = 0, real = 0, imag = 0, q1 = 0, maxAmpl = 0; for (int j = minLength; j <= maxLength; j++) @@ -1388,12 +1387,12 @@ public static StockData CalculateEhlersSpectrumDerivedFilterBank(this StockData decimal beta = Cos(MinOrMax(2 * Pi / j, 0.99m, 0.01m)); decimal gamma = 1 / Cos(MinOrMax(4 * Pi * delta / j, 0.99m, 0.01m)); decimal alpha = gamma - Sqrt((gamma * gamma) - 1); - decimal priorSmoothHp = i >= j ? smoothHpList.ElementAtOrDefault(i - j) : 0; - decimal prevReal = i >= j ? realList.ElementAtOrDefault(i - j) : 0; - decimal priorReal = i >= j * 2 ? realList.ElementAtOrDefault(i - (j * 2)) : 0; - decimal prevImag = i >= j ? imagList.ElementAtOrDefault(i - j) : 0; - decimal priorImag = i >= j * 2 ? imagList.ElementAtOrDefault(i - (j * 2)) : 0; - decimal prevQ1 = i >= j ? q1List.ElementAtOrDefault(i - j) : 0; + decimal priorSmoothHp = i >= j ? smoothHpList[i - j] : 0; + decimal prevReal = i >= j ? realList[i - j] : 0; + decimal priorReal = i >= j * 2 ? realList[i - (j * 2)] : 0; + decimal prevImag = i >= j ? imagList[i - j] : 0; + decimal priorImag = i >= j * 2 ? imagList[i - (j * 2)] : 0; + decimal prevQ1 = i >= j ? q1List[i - j] : 0; q1 = j / Pi * 2 * (smoothHp - prevSmoothHp); real = (0.5m * (1 - alpha) * (smoothHp - priorSmoothHp)) + (beta * (1 + alpha) * prevReal) - (alpha * priorReal); @@ -1406,13 +1405,13 @@ public static StockData CalculateEhlersSpectrumDerivedFilterBank(this StockData denom += db <= 3 ? maxLength - db : 0; dc = denom != 0 ? num / denom : 0; } - q1List.Add(q1); - realList.Add(real); - imagList.Add(imag); - dcList.Add(dc); + q1List.AddRounded(q1); + realList.AddRounded(real); + imagList.AddRounded(imag); + dcList.AddRounded(dc); decimal domCyc = dcList.TakeLastExt(length2).Median(); - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(smoothHp, prevSmoothHp); signalsList.Add(signal); @@ -1455,33 +1454,33 @@ public static StockData CalculateEhlersDominantCycleTunedBypassFilter(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal domCyc = domCycList.ElementAtOrDefault(i); + decimal domCyc = domCycList[i]; decimal beta = Cos(MinOrMax(2 * Pi / domCyc, 0.99m, 0.01m)); decimal delta = Math.Max((-0.015m * i) + 0.5m, 0.15m); decimal gamma = 1 / Cos(MinOrMax(4 * Pi * (delta / domCyc), 0.99m, 0.01m)); decimal alpha = gamma - Sqrt((gamma * gamma) - 1); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp3 = i >= 3 ? hpList.ElementAtOrDefault(i - 3) : 0; - decimal prevHp4 = i >= 4 ? hpList.ElementAtOrDefault(i - 4) : 0; - decimal prevHp5 = i >= 5 ? hpList.ElementAtOrDefault(i - 5) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevHp3 = i >= 3 ? hpList[i - 3] : 0; + decimal prevHp4 = i >= 4 ? hpList[i - 4] : 0; + decimal prevHp5 = i >= 5 ? hpList[i - 5] : 0; decimal hp = i < 7 ? currentValue : (0.5m * (1 + alpha1) * (currentValue - prevValue)) + (alpha1 * prevHp1); - hpList.Add(hp); + hpList.AddRounded(hp); decimal prevSmoothHp = smoothHpList.LastOrDefault(); decimal smoothHp = i < 7 ? currentValue - prevValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; - smoothHpList.Add(smoothHp); + smoothHpList.AddRounded(smoothHp); - decimal prevV1 = i >= 1 ? v1List.ElementAtOrDefault(i - 1) : 0; - decimal prevV1_2 = i >= 2 ? v1List.ElementAtOrDefault(i - 2) : 0; + decimal prevV1 = i >= 1 ? v1List[i - 1] : 0; + decimal prevV1_2 = i >= 2 ? v1List[i - 2] : 0; decimal v1 = (0.5m * (1 - alpha) * (smoothHp - prevSmoothHp)) + (beta * (1 + alpha) * prevV1) - (alpha * prevV1_2); - v1List.Add(v1); + v1List.AddRounded(v1); decimal v2 = domCyc / Pi * 2 * (v1 - prevV1); - v2List.Add(v2); + v2List.AddRounded(v2); var signal = GetConditionSignal(v2 > v1 && v2 >= 0, v2 < v1 || v2 < 0); signalsList.Add(signal); @@ -1520,20 +1519,20 @@ public static StockData CalculateEhlersRestoringPullIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal domCyc = domCycList.ElementAtOrDefault(i); - decimal volume = volumeList.ElementAtOrDefault(i); + decimal domCyc = domCycList[i]; + decimal volume = volumeList[i]; decimal rpi = volume * Pow(MinOrMax(2 * Pi / domCyc, 0.99m, 0.01m), 2); - rpiList.Add(rpi); + rpiList.AddRounded(rpi); } var rpiEmaList = GetMovingAverageList(stockData, maType, minLength, rpiList); for (int i = 0; i < stockData.Count; i++) { - decimal rpi = rpiList.ElementAtOrDefault(i); - decimal rpiEma = rpiEmaList.ElementAtOrDefault(i); - decimal prevRpi = i >= 1 ? rpiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRpiEma = i >= 1 ? rpiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal rpi = rpiList[i]; + decimal rpiEma = rpiEmaList[i]; + decimal prevRpi = i >= 1 ? rpiList[i - 1] : 0; + decimal prevRpiEma = i >= 1 ? rpiEmaList[i - 1] : 0; var signal = GetCompareSignal(rpi - rpiEma, prevRpi - prevRpiEma, true); signalsList.Add(signal); @@ -1573,29 +1572,29 @@ public static StockData CalculateEhlersTrendflexIndicator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? filterList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filterList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? filterList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filterList[i - 2] : 0; decimal filter = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); - filterList.Add(filter); + filterList.AddRounded(filter); decimal sum = 0; for (int j = 1; j <= length; j++) { - decimal prevFilterCount = i >= j ? filterList.ElementAtOrDefault(i - j) : 0; + decimal prevFilterCount = i >= j ? filterList[i - j] : 0; sum += filter - prevFilterCount; } sum /= length; decimal prevMs = msList.LastOrDefault(); decimal ms = (0.04m * Pow(sum, 2)) + (0.96m * prevMs); - msList.Add(ms); + msList.AddRounded(ms); decimal prevTrendflex = trendflexList.LastOrDefault(); decimal trendflex = ms > 0 ? sum / Sqrt(ms) : 0; - trendflexList.Add(trendflex); + trendflexList.AddRounded(trendflex); var signal = GetCompareSignal(trendflex, prevTrendflex); signalsList.Add(signal); @@ -1630,7 +1629,7 @@ public static StockData CalculateEhlersCorrelationCycleIndicator(this StockData decimal sx = 0, sy = 0, nsy = 0, sxx = 0, syy = 0, nsyy = 0, sxy = 0, nsxy = 0; for (int j = 1; j <= length; j++) { - decimal x = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal x = i >= j - 1 ? inputList[i - (j - 1)] : 0; decimal v = MinOrMax(2 * Pi * ((decimal)(j - 1) / length), 0.99m, 0.01m); decimal y = Cos(v); decimal ny = -Sin(v); @@ -1647,12 +1646,12 @@ public static StockData CalculateEhlersCorrelationCycleIndicator(this StockData decimal prevReal = realList.LastOrDefault(); decimal 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.Add(real); + realList.AddRounded(real); decimal prevImag = imagList.LastOrDefault(); decimal 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.Add(imag); + imagList.AddRounded(imag); var signal = GetCompareSignal(real - imag, prevReal - prevImag); signalsList.Add(signal); @@ -1687,14 +1686,14 @@ public static StockData CalculateEhlersCorrelationAngleIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal real = realList.ElementAtOrDefault(i); - decimal imag = imagList.ElementAtOrDefault(i); + decimal real = realList[i]; + decimal imag = imagList[i]; - decimal prevAngle = i >= 1 ? angleList.ElementAtOrDefault(i - 1) : 0; + decimal prevAngle = i >= 1 ? angleList[i - 1] : 0; decimal angle = imag != 0 ? 90 + Atan(real / imag).ToDegrees() : 90; angle = imag > 0 ? angle - 180 : angle; angle = prevAngle - angle < 270 && angle < prevAngle ? prevAngle : angle; - angleList.Add(angle); + angleList.AddRounded(angle); var signal = GetCompareSignal(angle, prevAngle); signalsList.Add(signal); @@ -1726,12 +1725,12 @@ public static StockData CalculateEhlersMarketStateIndicator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal angle = angleList.ElementAtOrDefault(i); - decimal prevAngle = i >= 1 ? angleList.ElementAtOrDefault(i - 1) : 0; + decimal angle = angleList[i]; + decimal prevAngle = i >= 1 ? angleList[i - 1] : 0; decimal prevState = stateList.LastOrDefault(); decimal state = Math.Abs(angle - prevAngle) < 9 && angle < 0 ? -1 : Math.Abs(angle - prevAngle) < 9 && angle >= 0 ? 1 : 0; - stateList.Add(state); + stateList.AddRounded(state); var signal = GetCompareSignal(state, prevState); signalsList.Add(signal); @@ -1769,20 +1768,20 @@ public static StockData CalculateEhlersTrendExtraction(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal bp = (0.5m * (1 - alpha) * (currentValue - prevValue2)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); - bpList.Add(bp); + bpList.AddRounded(bp); } var trendList = GetMovingAverageList(stockData, maType, length * 2, bpList); for (int i = 0; i < stockData.Count; i++) { - decimal trend = trendList.ElementAtOrDefault(i); - decimal prevTrend = i >= 1 ? trendList.ElementAtOrDefault(i - 1) : 0; + decimal trend = trendList[i]; + decimal prevTrend = i >= 1 ? trendList[i - 1] : 0; var signal = GetCompareSignal(trend, prevTrend); signalsList.Add(signal); @@ -1825,35 +1824,35 @@ public static StockData CalculateEhlersEmpiricalModeDecomposition(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; - decimal bp = bpList.ElementAtOrDefault(i); + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; + decimal bp = bpList[i]; decimal prevPeak = peakList.LastOrDefault(); decimal peak = prevBp1 > bp && prevBp1 > prevBp2 ? prevBp1 : prevPeak; - peakList.Add(peak); + peakList.AddRounded(peak); decimal prevValley = valleyList.LastOrDefault(); decimal valley = prevBp1 < bp && prevBp1 < prevBp2 ? prevBp1 : prevValley; - valleyList.Add(valley); + 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++) { - decimal peakAvg = peakAvgList.ElementAtOrDefault(i); - decimal valleyAvg = valleyAvgList.ElementAtOrDefault(i); - decimal trend = trendList.ElementAtOrDefault(i); - decimal prevTrend = i >= 1 ? trendList.ElementAtOrDefault(i - 1) : 0; + decimal peakAvg = peakAvgList[i]; + decimal valleyAvg = valleyAvgList[i]; + decimal trend = trendList[i]; + decimal prevTrend = i >= 1 ? trendList[i - 1] : 0; decimal prevPeakAvgFrac = peakAvgFracList.LastOrDefault(); decimal peakAvgFrac = fraction * peakAvg; - peakAvgFracList.Add(peakAvgFrac); + peakAvgFracList.AddRounded(peakAvgFrac); decimal prevValleyAvgFrac = valleyAvgFracList.LastOrDefault(); decimal valleyAvgFrac = fraction * valleyAvg; - valleyAvgFracList.Add(valleyAvgFrac); + valleyAvgFracList.AddRounded(valleyAvgFrac); var signal = GetBullishBearishSignal(trend - Math.Max(peakAvgFrac, valleyAvgFrac), prevTrend - Math.Max(prevPeakAvgFrac, prevValleyAvgFrac), trend - Math.Min(peakAvgFrac, valleyAvgFrac), prevTrend - Math.Min(prevPeakAvgFrac, prevValleyAvgFrac)); @@ -1893,16 +1892,16 @@ public static StockData CalculateEhlersEarlyOnsetTrendIndicator(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal filter = superSmoothList.ElementAtOrDefault(i); + decimal filter = superSmoothList[i]; decimal prevPeak = peakList.LastOrDefault(); decimal peak = Math.Abs(filter) > 0.991m * prevPeak ? Math.Abs(filter) : 0.991m * prevPeak; - peakList.Add(peak); + peakList.AddRounded(peak); decimal ratio = peak != 0 ? filter / peak : 0; decimal prevQuotient = quotientList.LastOrDefault(); decimal quotient = (k * ratio) + 1 != 0 ? (ratio + k) / ((k * ratio) + 1) : 0; - quotientList.Add(quotient); + quotientList.AddRounded(quotient); var signal = GetCompareSignal(quotient, prevQuotient); signalsList.Add(signal); @@ -1937,18 +1936,18 @@ public static StockData CalculateEhlersRoofingFilterV1(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal highPass = hpFilterList.ElementAtOrDefault(i); - decimal prevHp1 = i >= 1 ? hpFilterList.ElementAtOrDefault(i - 1) : 0; + decimal highPass = hpFilterList[i]; + decimal prevHp1 = i >= 1 ? hpFilterList[i - 1] : 0; decimal arg = (highPass + prevHp1) / 2; - argList.Add(arg); + argList.AddRounded(arg); } var roofingFilter2PoleList = GetMovingAverageList(stockData, maType, length2, argList); for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilter2PoleList.ElementAtOrDefault(i); - decimal prevRoofingFilter = i >= 1 ? roofingFilter2PoleList.ElementAtOrDefault(i - 1) : 0; + decimal roofingFilter = roofingFilter2PoleList[i]; + decimal prevRoofingFilter = i >= 1 ? roofingFilter2PoleList[i - 1] : 0; var signal = GetCompareSignal(roofingFilter, prevRoofingFilter); signalsList.Add(signal); @@ -1990,31 +1989,31 @@ public static StockData CalculateEhlersSnakeUniversalTradingFilter(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal bp = i < 3 ? 0 : (0.5m * (1 - s1) * (currentValue - prevValue2)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); - bpList.Add(bp); + bpList.AddRounded(bp); } var filtList = GetMovingAverageList(stockData, maType, length1, bpList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal filtPow = Pow(filt, 2); - filtPowList.Add(filtPow); + filtPowList.AddRounded(filtPow); decimal filtPowMa = filtPowList.TakeLastExt(length2).Average(); decimal rms = Sqrt(filtPowMa); - rmsList.Add(rms); + rmsList.AddRounded(rms); decimal negRms = -rms; - negRmsList.Add(negRms); + negRmsList.AddRounded(negRms); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -2055,21 +2054,21 @@ public static StockData CalculateEhlersImpulseResponse(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal bp = i < 3 ? 0 : (0.5m * (1 - s1) * (currentValue - prevValue2)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); - bpList.Add(bp); + bpList.AddRounded(bp); } var filtList = GetMovingAverageList(stockData, maType, hannLength, bpList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -2119,15 +2118,15 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevSsf1 = i >= 1 ? ssfList.ElementAtOrDefault(i - 1) : 0; - decimal prevSsf2 = i >= 2 ? ssfList.ElementAtOrDefault(i - 2) : 0; - decimal prevPredict1 = i >= 1 ? predictList.ElementAtOrDefault(i - 1) : 0; - decimal priorSsf = i >= upperLength - 1 ? ssfList.ElementAtOrDefault(i - (upperLength - 1)) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; + decimal prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; + decimal prevPredict1 = i >= 1 ? predictList[i - 1] : 0; + decimal priorSsf = i >= upperLength - 1 ? ssfList[i - (upperLength - 1)] : 0; var pArray = new decimal[500]; var bb1Array = new decimal[500]; var bb2Array = new decimal[500]; @@ -2137,15 +2136,15 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto var hCoefArray = new decimal[520]; decimal hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); - hpList.Add(hp); + hpList.AddRounded(hp); decimal ssf = i < 3 ? hp : (coef1 * ((hp + prevHp1) / 2)) + (coef2 * prevSsf1) + (coef3 * prevSsf2); - ssfList.Add(ssf); + ssfList.AddRounded(ssf); decimal pwrSum = 0; for (int j = 0; j < upperLength; j++) { - decimal prevSsf = i >= j ? ssfList.ElementAtOrDefault(i - j) : 0; + decimal prevSsf = i >= j ? ssfList[i - j] : 0; pwrSum += Pow(prevSsf, 2); } @@ -2154,7 +2153,7 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto bb2Array[upperLength - 1] = priorSsf; for (int j = 2; j < upperLength; j++) { - decimal prevSsf = i >= j - 1 ? ssfList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevSsf = i >= j - 1 ? ssfList[i - (j - 1)] : 0; bb1Array[j] = prevSsf; bb2Array[j - 1] = prevSsf; } @@ -2222,7 +2221,7 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto for (int j = 1; j <= upperLength; j++) { - xxArray[j] = i >= upperLength - j ? ssfList.ElementAtOrDefault(i - (upperLength - j)) : 0; + xxArray[j] = i >= upperLength - j ? ssfList[i - (upperLength - j)] : 0; } for (int j = 1; j <= length3; j++) @@ -2236,10 +2235,10 @@ public static StockData CalculateEhlersMesaPredictIndicatorV1(this StockData sto decimal prevPrePredict = prePredictList.LastOrDefault(); decimal prePredict = xxArray[upperLength + length1]; - prePredictList.Add(prePredict); + prePredictList.AddRounded(prePredict); decimal predict = (prePredict + prevPrePredict) / 2; - predictList.Add(predict); + predictList.AddRounded(predict); var signal = GetCompareSignal(ssf - predict, prevSsf1 - prevPredict1); signalsList.Add(signal); @@ -2298,32 +2297,32 @@ public static StockData CalculateEhlersMesaPredictIndicatorV2(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevSsf1 = i >= 1 ? ssfList.ElementAtOrDefault(i - 1) : 0; - decimal prevSsf2 = i >= 2 ? ssfList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; + decimal prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; decimal hp = i < 4 ? 0 : (c1 * (currentValue - (2 * prevValue1) + prevValue2)) + (c2 * prevHp1) + (c3 * prevHp2); - hpList.Add(hp); + hpList.AddRounded(hp); decimal ssf = i < 3 ? hp : (coef1 * ((hp + prevHp1) / 2)) + (coef2 * prevSsf1) + (coef3 * prevSsf2); - ssfList.Add(ssf); + ssfList.AddRounded(ssf); } var filtList = GetMovingAverageList(stockData, maType, length3, ssfList); for (int i = 0; i < stockData.Count; i++) { - decimal prevPredict1 = i >= 1 ? predictList.ElementAtOrDefault(i - 1) : 0; - decimal prevPredict2 = i >= 2 ? predictList.ElementAtOrDefault(i - 2) : 0; + decimal prevPredict1 = i >= 1 ? predictList[i - 1] : 0; + decimal prevPredict2 = i >= 2 ? predictList[i - 2] : 0; var xxArray = new decimal[100]; var yyArray = new decimal[100]; for (int j = 1; j <= length1; j++) { - decimal prevFilt = i >= length1 - j ? filtList.ElementAtOrDefault(i - (length1 - j)) : 0; + decimal prevFilt = i >= length1 - j ? filtList[i - (length1 - j)] : 0; xxArray[j] = prevFilt; yyArray[j] = prevFilt; } @@ -2343,10 +2342,10 @@ public static StockData CalculateEhlersMesaPredictIndicatorV2(this StockData sto } decimal predict = xxArray[length1 + length4]; - predictList.Add(predict); + predictList.AddRounded(predict); decimal extrap = yyArray[length1 + length4]; - extrapList.Add(extrap); + extrapList.AddRounded(extrap); var signal = GetCompareSignal(predict - prevPredict1, prevPredict1 - prevPredict2); signalsList.Add(signal); @@ -2389,7 +2388,7 @@ public static StockData CalculateEhlersAnticipateIndicator(this StockData stockD decimal sx = 0, sy = 0, sxx = 0, syy = 0, sxy = 0; for (int k = 0; k < length; k++) { - decimal x = i >= k ? hFiltList.ElementAtOrDefault(i - k) : 0; + decimal x = i >= k ? hFiltList[i - k] : 0; decimal y = -Sin(MinOrMax(2 * Pi * ((decimal)(j + k) / length), 0.99m, 0.01m)); sx += x; sy += y; @@ -2405,7 +2404,7 @@ public static StockData CalculateEhlersAnticipateIndicator(this StockData stockD decimal prevPredict = predictList.LastOrDefault(); decimal predict = Sin(MinOrMax(2 * Pi * start / length, 0.99m, 0.01m)); - predictList.Add(predict); + predictList.AddRounded(predict); var signal = GetCompareSignal(predict, prevPredict); signalsList.Add(signal); @@ -2443,18 +2442,18 @@ public static StockData CalculateEhlersImpulseReaction(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal priorValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; - decimal prevReaction1 = i >= 1 ? reactionList.ElementAtOrDefault(i - 1) : 0; - decimal prevReaction2 = i >= 2 ? reactionList.ElementAtOrDefault(i - 2) : 0; - decimal prevIReact1 = i >= 1 ? ireactList.ElementAtOrDefault(i - 1) : 0; - decimal prevIReact2 = i >= 2 ? ireactList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal priorValue = i >= length1 ? inputList[i - length1] : 0; + decimal prevReaction1 = i >= 1 ? reactionList[i - 1] : 0; + decimal prevReaction2 = i >= 2 ? reactionList[i - 2] : 0; + decimal prevIReact1 = i >= 1 ? ireactList[i - 1] : 0; + decimal prevIReact2 = i >= 2 ? ireactList[i - 2] : 0; decimal reaction = (c1 * (currentValue - priorValue)) + (c2 * prevReaction1) + (c3 * prevReaction2); - reactionList.Add(reaction); + reactionList.AddRounded(reaction); decimal ireact = currentValue != 0 ? 100 * reaction / currentValue : 0; - ireactList.Add(ireact); + ireactList.AddRounded(ireact); var signal = GetCompareSignal(ireact - prevIReact1, prevIReact1 - prevIReact2); signalsList.Add(signal); @@ -2494,29 +2493,29 @@ public static StockData CalculateEhlersUniversalTradingFilter(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal priorValue = i >= hannLength ? inputList.ElementAtOrDefault(i - hannLength) : 0; + decimal currentValue = inputList[i]; + decimal priorValue = i >= hannLength ? inputList[i - hannLength] : 0; decimal mom = currentValue - priorValue; - momList.Add(mom); + momList.AddRounded(mom); } var filtList = GetMovingAverageList(stockData, maType, length1, momList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal filtPow = Pow(filt, 2); - filtPowList.Add(filtPow); + filtPowList.AddRounded(filtPow); decimal filtPowMa = filtPowList.TakeLastExt(length2).Average(); decimal rms = filtPowMa > 0 ? Sqrt(filtPowMa) : 0; - rmsList.Add(rms); + rmsList.AddRounded(rms); decimal negRms = -rms; - negRmsList.Add(negRms); + negRmsList.AddRounded(negRms); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -2560,20 +2559,20 @@ public static StockData CalculateEhlersRecursiveMedianOscillator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal median = tempList.TakeLastExt(length1).Median(); - decimal prevRm1 = i >= 1 ? rmList.ElementAtOrDefault(i - 1) : 0; - decimal prevRm2 = i >= 2 ? rmList.ElementAtOrDefault(i - 2) : 0; - decimal prevRmo1 = i >= 1 ? rmoList.ElementAtOrDefault(i - 1) : 0; - decimal prevRmo2 = i >= 2 ? rmoList.ElementAtOrDefault(i - 2) : 0; + decimal prevRm1 = i >= 1 ? rmList[i - 1] : 0; + decimal prevRm2 = i >= 2 ? rmList[i - 2] : 0; + decimal prevRmo1 = i >= 1 ? rmoList[i - 1] : 0; + decimal prevRmo2 = i >= 2 ? rmoList[i - 2] : 0; decimal rm = (alpha1 * median) + ((1 - alpha1) * prevRm1); - rmList.Add(rm); + rmList.AddRounded(rm); decimal rmo = (Pow(1 - (alpha2 / 2), 2) * (rm - (2 * prevRm1) + prevRm2)) + (2 * (1 - alpha2) * prevRmo1) - (Pow(1 - alpha2, 2) * prevRmo2); - rmoList.Add(rmo); + rmoList.AddRounded(rmo); var signal = GetCompareSignal(rmo, prevRmo1); signalsList.Add(signal); @@ -2613,26 +2612,26 @@ public static StockData CalculateEhlersSuperPassbandFilter(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEspf1 = i >= 1 ? espfList.ElementAtOrDefault(i - 1) : 0; - decimal prevEspf2 = i >= 2 ? espfList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevEspf1 = i >= 1 ? espfList[i - 1] : 0; + decimal prevEspf2 = i >= 2 ? espfList[i - 2] : 0; decimal espf = ((a1 - a2) * currentValue) + (((a2 * (1 - a1)) - (a1 * (1 - a2))) * prevValue1) + ((1 - a1 + (1 - a2)) * prevEspf1) - ((1 - a1) * (1 - a2) * prevEspf2); - espfList.Add(espf); + espfList.AddRounded(espf); decimal espfPow = Pow(espf, 2); - squareList.Add(espfPow); + squareList.AddRounded(espfPow); decimal squareAvg = squareList.TakeLastExt(length2).Average(); decimal prevRms = rmsList.LastOrDefault(); decimal rms = Sqrt(squareAvg); - rmsList.Add(rms); + rmsList.AddRounded(rms); decimal prevNegRms = negRmsList.LastOrDefault(); decimal negRms = -rms; - negRmsList.Add(negRms); + negRmsList.AddRounded(negRms); var signal = GetBullishBearishSignal(espf - rms, prevEspf1 - prevRms, espf - negRms, prevEspf1 - prevNegRms); signalsList.Add(signal); @@ -2669,24 +2668,24 @@ public static StockData CalculateEhlersSimpleDerivIndicator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal prevDeriv1 = i >= 1 ? derivList.ElementAtOrDefault(i - 1) : 0; - decimal prevDeriv2 = i >= 2 ? derivList.ElementAtOrDefault(i - 2) : 0; - decimal prevDeriv3 = i >= 3 ? derivList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; + decimal prevDeriv1 = i >= 1 ? derivList[i - 1] : 0; + decimal prevDeriv2 = i >= 2 ? derivList[i - 2] : 0; + decimal prevDeriv3 = i >= 3 ? derivList[i - 3] : 0; decimal deriv = currentValue - prevValue; - derivList.Add(deriv); + derivList.AddRounded(deriv); decimal z3 = deriv + prevDeriv1 + prevDeriv2 + prevDeriv3; - z3List.Add(z3); + z3List.AddRounded(z3); } var z3EmaList = GetMovingAverageList(stockData, maType, signalLength, z3List); for (int i = 0; i < stockData.Count; i++) { - decimal z3Ema = z3EmaList.ElementAtOrDefault(i); - decimal prevZ3Ema = i >= 1 ? z3EmaList.ElementAtOrDefault(i - 1) : 0; + decimal z3Ema = z3EmaList[i]; + decimal prevZ3Ema = i >= 1 ? z3EmaList[i - 1] : 0; var signal = GetCompareSignal(z3Ema, prevZ3Ema); signalsList.Add(signal); @@ -2725,34 +2724,34 @@ public static StockData CalculateEhlersSimpleClipIndicator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; - decimal prevClip1 = i >= 1 ? clipList.ElementAtOrDefault(i - 1) : 0; - decimal prevClip2 = i >= 2 ? clipList.ElementAtOrDefault(i - 2) : 0; - decimal prevClip3 = i >= 3 ? clipList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length1 ? inputList[i - length1] : 0; + decimal prevClip1 = i >= 1 ? clipList[i - 1] : 0; + decimal prevClip2 = i >= 2 ? clipList[i - 2] : 0; + decimal prevClip3 = i >= 3 ? clipList[i - 3] : 0; decimal deriv = currentValue - prevValue; - derivList.Add(deriv); + derivList.AddRounded(deriv); decimal rms = 0; for (int j = 0; j < length3; j++) { - decimal prevDeriv = i >= j ? derivList.ElementAtOrDefault(i - j) : 0; + decimal prevDeriv = i >= j ? derivList[i - j] : 0; rms += Pow(prevDeriv, 2); } decimal clip = rms != 0 ? MinOrMax(2 * deriv / Sqrt(rms / length3), 1, -1) : 0; - clipList.Add(clip); + clipList.AddRounded(clip); decimal z3 = clip + prevClip1 + prevClip2 + prevClip3; - z3List.Add(z3); + z3List.AddRounded(z3); } var z3EmaList = GetMovingAverageList(stockData, maType, signalLength, z3List); for (int i = 0; i < stockData.Count; i++) { - decimal z3Ema = z3EmaList.ElementAtOrDefault(i); - decimal prevZ3Ema = i >= 1 ? z3EmaList.ElementAtOrDefault(i - 1) : 0; + decimal z3Ema = z3EmaList[i]; + decimal prevZ3Ema = i >= 1 ? z3EmaList[i - 1] : 0; var signal = GetCompareSignal(z3Ema, prevZ3Ema); signalsList.Add(signal); @@ -2786,18 +2785,18 @@ public static StockData CalculateEhlersSpearmanRankIndicator(this StockData stoc { var priceArray = new decimal[50]; var rankArray = new decimal[50]; - for (int j = 0; j < length; j++) + for (int j = 1; j <= length; j++) { - var prevPrice = i >= j - 1 ? inputList.ElementAtOrDefault(i - j - 1) : 0; + var prevPrice = i >= j - 1 ? inputList[i - (j - 1)] : 0; priceArray[j] = prevPrice; rankArray[j] = j; } - for (int j = 0; j < length; j++) + for (int j = 1; j <= length; j++) { var count = length + 1 - j; - for (int k = 0; k < length - count; k++) + for (int k = 1; k <= length - count; k++) { var array1 = priceArray[k + 1]; @@ -2815,14 +2814,14 @@ public static StockData CalculateEhlersSpearmanRankIndicator(this StockData stoc } decimal sum = 0; - for (int j = 0; j < length; j++) + for (int j = 1; j <= length; j++) { sum += Pow(j - rankArray[j], 2); } decimal prevSri = sriList.LastOrDefault(); decimal sri = 2 * (0.5m - (1 - (6 * sum / (length * (Pow(length, 2) - 1))))); - sriList.Add(sri); + sriList.AddRounded(sri); var signal = GetCompareSignal(sri, prevSri); signalsList.Add(signal); @@ -2856,16 +2855,16 @@ public static StockData CalculateEhlersNoiseEliminationTechnology(this StockData for (int i = 0; i < stockData.Count; i++) { var xArray = new decimal[50]; - for (int j = 0; j < length; j++) + for (int j = 1; j <= length; j++) { - var prevPrice = i >= j - 1 ? inputList.ElementAtOrDefault(i - j - 1) : 0; + var prevPrice = i >= j - 1 ? inputList[i - (j - 1)] : 0; xArray[j] = prevPrice; } decimal num = 0; - for (int j = 1; j < length; j++) + for (int j = 2; j <= length; j++) { - for (int k = 0; k < j - 1; k++) + for (int k = 1; k <= j - 1; k++) { num -= Math.Sign(xArray[j] - xArray[k]); } @@ -2873,7 +2872,7 @@ public static StockData CalculateEhlersNoiseEliminationTechnology(this StockData decimal prevNet = netList.LastOrDefault(); decimal net = denom != 0 ? num / denom : 0; - netList.Add(net); + netList.AddRounded(net); var signal = GetCompareSignal(net, prevNet); signalsList.Add(signal); @@ -2913,14 +2912,14 @@ public static StockData CalculateEhlersTruncatedBandPassFilter(this StockData st var trunArray = new decimal[100]; for (int j = length2; j > 0; j--) { - decimal prevValue1 = i >= j - 1 ? inputList.ElementAtOrDefault(i - j - 1) : 0; - decimal prevValue2 = i >= j + 1 ? inputList.ElementAtOrDefault(i - (j + 1)) : 0; + decimal prevValue1 = i >= j - 1 ? inputList[i - (j - 1)] : 0; + decimal prevValue2 = i >= j + 1 ? inputList[i - (j + 1)] : 0; trunArray[j] = (0.5m * (1 - s1) * (prevValue1 - prevValue2)) + (l1 * (1 + s1) * trunArray[j + 1]) - (s1 * trunArray[j + 2]); } decimal prevBpt = bptList.LastOrDefault(); decimal bpt = trunArray[1]; - bptList.Add(bpt); + bptList.AddRounded(bpt); var signal = GetCompareSignal(bpt, prevBpt); signalsList.Add(signal); @@ -2958,23 +2957,23 @@ public static StockData CalculateEhlersAutoCorrelationIndicator(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal prevCorr1 = i >= 1 ? corrList.ElementAtOrDefault(i - 1) : 0; - decimal prevCorr2 = i >= 2 ? corrList.ElementAtOrDefault(i - 2) : 0; + decimal prevCorr1 = i >= 1 ? corrList[i - 1] : 0; + decimal prevCorr2 = i >= 2 ? corrList[i - 2] : 0; - decimal x = roofingFilterList.ElementAtOrDefault(i); - xList.Add(x); + decimal x = roofingFilterList[i]; + xList.AddRounded(x); - decimal y = i >= length1 ? roofingFilterList.ElementAtOrDefault(i - length1) : 0; - yList.Add(y); + decimal y = i >= length1 ? roofingFilterList[i - length1] : 0; + yList.AddRounded(y); decimal xx = Pow(x, 2); - xxList.Add(xx); + xxList.AddRounded(xx); decimal yy = Pow(y, 2); - yyList.Add(yy); + yyList.AddRounded(yy); decimal xy = x * y; - xyList.Add(xy); + xyList.AddRounded(xy); decimal sx = xList.TakeLastExt(length1).Sum(); decimal sy = yList.TakeLastExt(length1).Sum(); @@ -2984,7 +2983,7 @@ public static StockData CalculateEhlersAutoCorrelationIndicator(this StockData s decimal corr = ((i * sxx) - (sx * sx)) * ((i * syy) - (sy * sy)) > 0 ? 0.5m * ((((i * sxy) - (sx * sy)) / Sqrt(((i * sxx) - (sx * sx)) * ((i * syy) - (sy * sy)))) + 1) : 0; - corrList.Add(corr); + corrList.AddRounded(corr); var signal = GetCompareSignal(corr - prevCorr1, prevCorr1 - prevCorr2); signalsList.Add(signal); @@ -3019,9 +3018,9 @@ public static StockData CalculateEhlersAutoCorrelationPeriodogram(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal corr = corrList.ElementAtOrDefault(i); - decimal prevCorr1 = i >= 1 ? corrList.ElementAtOrDefault(i - 1) : 0; - decimal prevCorr2 = i >= 2 ? corrList.ElementAtOrDefault(i - 2) : 0; + decimal corr = corrList[i]; + decimal prevCorr1 = i >= 1 ? corrList[i - 1] : 0; + decimal prevCorr2 = i >= 2 ? corrList[i - 2] : 0; decimal maxPwr = 0, spx = 0, sp = 0; for (int j = length2; j <= length1; j++) @@ -3029,13 +3028,13 @@ public static StockData CalculateEhlersAutoCorrelationPeriodogram(this StockData decimal cosPart = 0, sinPart = 0; for (int k = length3; k <= length1; k++) { - decimal prevCorr = i >= k ? corrList.ElementAtOrDefault(i - k) : 0; + decimal prevCorr = i >= k ? corrList[i - k] : 0; cosPart += prevCorr * Cos(2 * Pi * ((decimal)k / j)); sinPart += prevCorr * Sin(2 * Pi * ((decimal)k / j)); } decimal sqSum = Pow(cosPart, 2) + Pow(sinPart, 2); - decimal prevR = i >= j - 1 ? rList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevR = i >= j - 1 ? rList[i - (j - 1)] : 0; decimal r = (0.2m * Pow(sqSum, 2)) + (0.8m * prevR); maxPwr = Math.Max(r, maxPwr); decimal pwr = maxPwr != 0 ? r / maxPwr : 0; @@ -3048,7 +3047,7 @@ public static StockData CalculateEhlersAutoCorrelationPeriodogram(this StockData } decimal domCyc = sp != 0 ? spx / sp : 0; - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(corr - prevCorr1, prevCorr1 - prevCorr2); signalsList.Add(signal); @@ -3093,36 +3092,36 @@ public static StockData CalculateEhlersAdaptiveRelativeStrengthIndexV2(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal domCyc = MinOrMax(domCycList.ElementAtOrDefault(i), length1, length2); - decimal prevArsi1 = i >= 1 ? arsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevArsi2 = i >= 2 ? arsiList.ElementAtOrDefault(i - 2) : 0; + decimal domCyc = MinOrMax(domCycList[i], length1, length2); + decimal prevArsi1 = i >= 1 ? arsiList[i - 1] : 0; + decimal prevArsi2 = i >= 2 ? arsiList[i - 2] : 0; decimal prevUpChg = upChgList.LastOrDefault(); decimal upChg = 0, dnChg = 0; for (int j = 0; j < (int)Math.Ceiling(domCyc / 2); j++) { - decimal filt = i >= j ? roofingFilterList.ElementAtOrDefault(i - j) : 0; - decimal prevFilt = i >= j + 1 ? roofingFilterList.ElementAtOrDefault(i - (j + 1)) : 0; + decimal filt = i >= j ? roofingFilterList[i - j] : 0; + decimal prevFilt = i >= j + 1 ? roofingFilterList[i - (j + 1)] : 0; upChg += filt > prevFilt ? filt - prevFilt : 0; dnChg += filt < prevFilt ? prevFilt - filt : 0; } - upChgList.Add(upChg); + upChgList.AddRounded(upChg); decimal prevDenom = denomList.LastOrDefault(); decimal denom = upChg + dnChg; - denomList.Add(denom); + denomList.AddRounded(denom); decimal arsi = denom != 0 && prevDenom != 0 ? (c1 * ((upChg / denom) + (prevUpChg / prevDenom)) / 2) + (c2 * prevArsi1) + (c3 * prevArsi2) : 0; - arsiList.Add(arsi); + arsiList.AddRounded(arsi); } var arsiEmaList = GetMovingAverageList(stockData, maType, length2, arsiList); for (int i = 0; i < stockData.Count; i++) { - decimal arsi = arsiList.ElementAtOrDefault(i); - decimal arsiEma = arsiEmaList.ElementAtOrDefault(i); - decimal prevArsi = i >= 1 ? arsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevArsiEma = i >= 1 ? arsiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal arsi = arsiList[i]; + decimal arsiEma = arsiEmaList[i]; + decimal prevArsi = i >= 1 ? arsiList[i - 1] : 0; + decimal prevArsiEma = i >= 1 ? arsiEmaList[i - 1] : 0; var signal = GetRsiSignal(arsi - arsiEma, prevArsi - prevArsiEma, arsi, prevArsi, 0.7m, 0.3m); signalsList.Add(signal); @@ -3159,14 +3158,14 @@ public static StockData CalculateEhlersAdaptiveRsiFisherTransformV2(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal arsi = arsiList.ElementAtOrDefault(i) / 100; - decimal prevFish1 = i >= 1 ? fishList.ElementAtOrDefault(i - 1) : 0; - decimal prevFish2 = i >= 2 ? fishList.ElementAtOrDefault(i - 2) : 0; + decimal arsi = arsiList[i] / 100; + decimal prevFish1 = i >= 1 ? fishList[i - 1] : 0; + decimal prevFish2 = i >= 2 ? fishList[i - 2] : 0; decimal tranRsi = 2 * (arsi - 0.5m); decimal ampRsi = MinOrMax(1.5m * tranRsi, 0.999m, -0.999m); decimal fish = 0.5m * Log((1 + ampRsi) / (1 - ampRsi)); - fishList.Add(fish); + fishList.AddRounded(fish); var signal = GetRsiSignal(fish - prevFish1, prevFish1 - prevFish2, fish, prevFish1, 2, -2); signalsList.Add(signal); @@ -3210,34 +3209,34 @@ public static StockData CalculateEhlersAdaptiveStochasticIndicatorV2(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal domCyc = MinOrMax(domCycList.ElementAtOrDefault(i), length1, length2); - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevAstoc1 = i >= 1 ? astocList.ElementAtOrDefault(i - 1) : 0; - decimal prevAstoc2 = i >= 2 ? astocList.ElementAtOrDefault(i - 2) : 0; + decimal domCyc = MinOrMax(domCycList[i], length1, length2); + decimal roofingFilter = roofingFilterList[i]; + decimal prevAstoc1 = i >= 1 ? astocList[i - 1] : 0; + decimal prevAstoc2 = i >= 2 ? astocList[i - 2] : 0; decimal highest = 0, lowest = 0; for (int j = 0; j < (int)Math.Ceiling(domCyc); j++) { - decimal filt = i >= j ? roofingFilterList.ElementAtOrDefault(i - j) : 0; + decimal filt = i >= j ? roofingFilterList[i - j] : 0; highest = filt > highest ? filt : highest; lowest = filt < lowest ? filt : lowest; } decimal prevStoc = stocList.LastOrDefault(); decimal stoc = highest != lowest ? (roofingFilter - lowest) / (highest - lowest) : 0; - stocList.Add(stoc); + stocList.AddRounded(stoc); decimal astoc = (c1 * ((stoc + prevStoc) / 2)) + (c2 * prevAstoc1) + (c3 * prevAstoc2); - astocList.Add(astoc); + astocList.AddRounded(astoc); } var astocEmaList = GetMovingAverageList(stockData, maType, length2, astocList); for (int i = 0; i < stockData.Count; i++) { - decimal astoc = astocList.ElementAtOrDefault(i); - decimal astocEma = astocEmaList.ElementAtOrDefault(i); - decimal prevAstoc = i >= 1 ? astocList.ElementAtOrDefault(i - 1) : 0; - decimal prevAstocEma = i >= 1 ? astocEmaList.ElementAtOrDefault(i - 1) : 0; + decimal astoc = astocList[i]; + decimal astocEma = astocEmaList[i]; + decimal prevAstoc = i >= 1 ? astocList[i - 1] : 0; + decimal prevAstocEma = i >= 1 ? astocEmaList[i - 1] : 0; var signal = GetRsiSignal(astoc - astocEma, prevAstoc - prevAstocEma, astoc, prevAstoc, 0.7m, 0.3m); signalsList.Add(signal); @@ -3275,16 +3274,16 @@ public static StockData CalculateEhlersAdaptiveStochasticInverseFisherTransform( for (int i = 0; i < stockData.Count; i++) { - decimal astoc = astocList.ElementAtOrDefault(i); + decimal astoc = astocList[i]; decimal v1 = 2 * (astoc - 0.5m); decimal prevFish = fishList.LastOrDefault(); decimal fish = (Exp(6 * v1) - 1) / (Exp(6 * v1) + 1); - fishList.Add(fish); + fishList.AddRounded(fish); decimal prevTrigger = triggerList.LastOrDefault(); decimal trigger = 0.9m * prevFish; - triggerList.Add(trigger); + triggerList.AddRounded(trigger); var signal = GetCompareSignal(fish - trigger, prevFish - prevTrigger); signalsList.Add(signal); @@ -3331,17 +3330,17 @@ public static StockData CalculateEhlersAdaptiveCommodityChannelIndexV2(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal domCyc = MinOrMax(domCycList.ElementAtOrDefault(i), length1, length2); - decimal prevAcci1 = i >= 1 ? acciList.ElementAtOrDefault(i - 1) : 0; - decimal prevAcci2 = i >= 2 ? acciList.ElementAtOrDefault(i - 2) : 0; + decimal domCyc = MinOrMax(domCycList[i], length1, length2); + decimal prevAcci1 = i >= 1 ? acciList[i - 1] : 0; + decimal prevAcci2 = i >= 2 ? acciList[i - 2] : 0; int cycLength = (int)Math.Ceiling(domCyc); - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - tempList.Add(roofingFilter); + decimal roofingFilter = roofingFilterList[i]; + tempList.AddRounded(roofingFilter); decimal avg = tempList.TakeLastExt(cycLength).Average(); decimal md = Pow(roofingFilter - avg, 2); - mdList.Add(md); + mdList.AddRounded(md); decimal mdAvg = mdList.TakeLastExt(cycLength).Average(); decimal rms = cycLength >= 0 ? Sqrt(mdAvg) : 0; @@ -3350,19 +3349,19 @@ public static StockData CalculateEhlersAdaptiveCommodityChannelIndexV2(this Stoc decimal prevRatio = ratioList.LastOrDefault(); decimal ratio = denom != 0 ? num / denom : 0; - ratioList.Add(ratio); + ratioList.AddRounded(ratio); decimal acci = (c1 * ((ratio + prevRatio) / 2)) + (c2 * prevAcci1) + (c3 * prevAcci2); - acciList.Add(acci); + acciList.AddRounded(acci); } var acciEmaList = GetMovingAverageList(stockData, maType, length2, acciList); for (int i = 0; i < stockData.Count; i++) { - decimal acci = acciList.ElementAtOrDefault(i); - decimal acciEma = acciEmaList.ElementAtOrDefault(i); - decimal prevAcci = i >= 1 ? acciList.ElementAtOrDefault(i - 1) : 0; - decimal prevAcciEma = i >= 1 ? acciEmaList.ElementAtOrDefault(i - 1) : 0; + decimal acci = acciList[i]; + decimal acciEma = acciEmaList[i]; + decimal prevAcci = i >= 1 ? acciList[i - 1] : 0; + decimal prevAcciEma = i >= 1 ? acciEmaList[i - 1] : 0; var signal = GetRsiSignal(acci - acciEma, prevAcci - prevAcciEma, acci, prevAcci, 100, -100); signalsList.Add(signal); @@ -3397,9 +3396,9 @@ public static StockData CalculateEhlersDiscreteFourierTransformSpectralEstimate( for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; + decimal roofingFilter = roofingFilterList[i]; + decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; decimal maxPwr = 0, spx = 0, sp = 0; for (int j = length2; j <= length1; j++) @@ -3407,13 +3406,13 @@ public static StockData CalculateEhlersDiscreteFourierTransformSpectralEstimate( decimal cosPart = 0, sinPart = 0; for (int k = 0; k <= length1; k++) { - decimal prevFilt = i >= k ? roofingFilterList.ElementAtOrDefault(i - k) : 0; + decimal prevFilt = i >= k ? roofingFilterList[i - k] : 0; cosPart += prevFilt * Cos(2 * Pi * ((decimal)k / j)); sinPart += prevFilt * Sin(2 * Pi * ((decimal)k / j)); } decimal sqSum = Pow(cosPart, 2) + Pow(sinPart, 2); - decimal prevR = i >= j - 1 ? rList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevR = i >= j - 1 ? rList[i - (j - 1)] : 0; decimal r = (0.2m * Pow(sqSum, 2)) + (0.8m * prevR); maxPwr = Math.Max(r, maxPwr); decimal pwr = maxPwr != 0 ? r / maxPwr : 0; @@ -3426,7 +3425,7 @@ public static StockData CalculateEhlersDiscreteFourierTransformSpectralEstimate( } decimal domCyc = sp != 0 ? spx / sp : 0; - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); signalsList.Add(signal); @@ -3461,11 +3460,11 @@ public static StockData CalculateEhlersCombFilterSpectralEstimate(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal roofingFilter = roofingFilterList[i]; + decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal bp = 0, maxPwr = 0, spx = 0, sp = 0; for (int j = length2; j <= length1; j++) @@ -3478,7 +3477,7 @@ public static StockData CalculateEhlersCombFilterSpectralEstimate(this StockData decimal pwr = 0; for (int k = 1; k <= j; k++) { - decimal prevBp = i >= k ? bpList.ElementAtOrDefault(i - k) : 0; + decimal prevBp = i >= k ? bpList[i - k] : 0; pwr += prevBp / j >= 0 ? Pow(prevBp / j, 2) : 0; } @@ -3491,10 +3490,10 @@ public static StockData CalculateEhlersCombFilterSpectralEstimate(this StockData sp += pwr; } } - bpList.Add(bp); + bpList.AddRounded(bp); decimal domCyc = sp != 0 ? spx / sp : 0; - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); signalsList.Add(signal); @@ -3532,19 +3531,19 @@ public static StockData CalculateEhlersAutoCorrelationReversals(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal ema = emaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal ema = emaList[i]; + decimal currentValue = inputList[i]; decimal delta = 0; for (int j = length3; j <= length1; j++) { - decimal corr = i >= j ? corrList.ElementAtOrDefault(i - j) : 0; - decimal prevCorr = i >= j - 1 ? corrList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal corr = i >= j ? corrList[i - j] : 0; + decimal prevCorr = i >= j - 1 ? corrList[i - (j - 1)] : 0; delta += (corr > 0.5m && prevCorr < 0.5m) || (corr < 0.5m && prevCorr > 0.5m) ? 1 : 0; } decimal reversal = delta > (decimal)length1 / 2 ? 1 : 0; - reversalList.Add(reversal); + reversalList.AddRounded(reversal); var signal = GetConditionSignal(currentValue < ema && reversal == 1, currentValue > ema && reversal == 1); signalsList.Add(signal); @@ -3585,44 +3584,44 @@ public static StockData CalculateEhlersReverseExponentialMovingAverageIndicatorV for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevEma = emaList.LastOrDefault(); decimal ema = (alpha * currentValue) + (cc * prevEma); - emaList.Add(ema); + emaList.AddRounded(ema); decimal prevRe1 = re1List.LastOrDefault(); decimal re1 = (cc * ema) + prevEma; - re1List.Add(re1); + re1List.AddRounded(re1); decimal prevRe2 = re2List.LastOrDefault(); decimal re2 = (Pow(cc, 2) * re1) + prevRe1; - re2List.Add(re2); + re2List.AddRounded(re2); decimal prevRe3 = re3List.LastOrDefault(); decimal re3 = (Pow(cc, 4) * re2) + prevRe2; - re3List.Add(re3); + re3List.AddRounded(re3); decimal prevRe4 = re4List.LastOrDefault(); decimal re4 = (Pow(cc, 8) * re3) + prevRe3; - re4List.Add(re4); + re4List.AddRounded(re4); decimal prevRe5 = re5List.LastOrDefault(); decimal re5 = (Pow(cc, 16) * re4) + prevRe4; - re5List.Add(re5); + re5List.AddRounded(re5); decimal prevRe6 = re6List.LastOrDefault(); decimal re6 = (Pow(cc, 32) * re5) + prevRe5; - re6List.Add(re6); + re6List.AddRounded(re6); decimal prevRe7 = re7List.LastOrDefault(); decimal re7 = (Pow(cc, 64) * re6) + prevRe6; - re7List.Add(re7); + re7List.AddRounded(re7); decimal re8 = (Pow(cc, 128) * re7) + prevRe7; decimal prevWave = waveList.LastOrDefault(); decimal wave = ema - (alpha * re8); - waveList.Add(wave); + waveList.AddRounded(wave); var signal = GetCompareSignal(wave, prevWave); signalsList.Add(signal); @@ -3655,10 +3654,10 @@ public static StockData CalculateEhlersReverseExponentialMovingAverageIndicatorV for (int i = 0; i < stockData.Count; i++) { - decimal waveCycle = cycleList.ElementAtOrDefault(i); - decimal waveTrend = trendList.ElementAtOrDefault(i); - decimal prevWaveCycle = i >= 1 ? cycleList.ElementAtOrDefault(i - 1) : 0; - decimal prevWaveTrend = i >= 1 ? trendList.ElementAtOrDefault(i - 1) : 0; + decimal waveCycle = cycleList[i]; + decimal waveTrend = trendList[i]; + decimal prevWaveCycle = i >= 1 ? cycleList[i - 1] : 0; + decimal prevWaveTrend = i >= 1 ? trendList[i - 1] : 0; var signal = GetCompareSignal(waveCycle - waveTrend, prevWaveCycle - prevWaveTrend); signalsList.Add(signal); @@ -3696,13 +3695,13 @@ public static StockData CalculateEhlersMovingAverageDifferenceIndicator(this Sto for (int i = 0; i < stockData.Count; i++) { - decimal shortMa = shortMaList.ElementAtOrDefault(i); - decimal longMa = longMaList.ElementAtOrDefault(i); - decimal prevMad1 = i >= 1 ? madList.ElementAtOrDefault(i - 1) : 0; - decimal prevMad2 = i >= 2 ? madList.ElementAtOrDefault(i - 2) : 0; + decimal shortMa = shortMaList[i]; + decimal longMa = longMaList[i]; + decimal prevMad1 = i >= 1 ? madList[i - 1] : 0; + decimal prevMad2 = i >= 2 ? madList[i - 2] : 0; decimal mad = longMa != 0 ? 100 * (shortMa - longMa) / longMa : 0; - madList.Add(mad); + madList.AddRounded(mad); var signal = GetCompareSignal(mad - prevMad1, prevMad1 - prevMad2); signalsList.Add(signal); @@ -3738,13 +3737,13 @@ public static StockData CalculateEhlersFisherizedDeviationScaledOscillator(this for (int i = 0; i < stockData.Count; i++) { - decimal currentScaledFilter2Pole = scaledFilter2PoleList.ElementAtOrDefault(i); - decimal prevEfdsoPole1 = i >= 1 ? efdso2PoleList.ElementAtOrDefault(i - 1) : 0; - decimal prevEfdsoPole2 = i >= 2 ? efdso2PoleList.ElementAtOrDefault(i - 2) : 0; + decimal currentScaledFilter2Pole = scaledFilter2PoleList[i]; + decimal prevEfdsoPole1 = i >= 1 ? efdso2PoleList[i - 1] : 0; + decimal prevEfdsoPole2 = i >= 2 ? efdso2PoleList[i - 2] : 0; decimal efdso2Pole = Math.Abs(currentScaledFilter2Pole) < 2 ? 0.5m * Log((1 + (currentScaledFilter2Pole / 2)) / (1 - (currentScaledFilter2Pole / 2))) : prevEfdsoPole1; - efdso2PoleList.Add(efdso2Pole); + efdso2PoleList.AddRounded(efdso2Pole); var signal = GetRsiSignal(efdso2Pole - prevEfdsoPole1, prevEfdsoPole1 - prevEfdsoPole2, efdso2Pole, prevEfdsoPole1, 2, -2); signalsList.Add(signal); @@ -3779,23 +3778,23 @@ public static StockData CalculateEhlersHilbertTransformIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal v2 = i >= 2 ? v1List.ElementAtOrDefault(i - 2) : 0; - decimal v4 = i >= 4 ? v1List.ElementAtOrDefault(i - 4) : 0; - decimal inPhase3 = i >= 3 ? inPhaseList.ElementAtOrDefault(i - 3) : 0; - decimal quad2 = i >= 2 ? quadList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; + decimal v2 = i >= 2 ? v1List[i - 2] : 0; + decimal v4 = i >= 4 ? v1List[i - 4] : 0; + decimal inPhase3 = i >= 3 ? inPhaseList[i - 3] : 0; + decimal quad2 = i >= 2 ? quadList[i - 2] : 0; decimal v1 = currentValue - prevValue; - v1List.Add(v1); + v1List.AddRounded(v1); decimal prevInPhase = inPhaseList.LastOrDefault(); decimal inPhase = (1.25m * (v4 - (iMult * v2))) + (iMult * inPhase3); - inPhaseList.Add(inPhase); + inPhaseList.AddRounded(inPhase); decimal prevQuad = quadList.LastOrDefault(); decimal quad = v2 - (qMult * v1) + (qMult * quad2); - quadList.Add(quad); + quadList.AddRounded(quad); var signal = GetCompareSignal(quad - (-1 * inPhase), prevQuad - (-1 * prevInPhase)); signalsList.Add(signal); @@ -3833,34 +3832,34 @@ public static StockData CalculateEhlersInstantaneousPhaseIndicator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal ip = ipList.ElementAtOrDefault(i); - decimal qu = quList.ElementAtOrDefault(i); - decimal prevIp = i >= 1 ? ipList.ElementAtOrDefault(i - 1) : 0; - decimal prevQu = i >= 1 ? quList.ElementAtOrDefault(i - 1) : 0; + decimal ip = ipList[i]; + decimal qu = quList[i]; + decimal prevIp = i >= 1 ? ipList[i - 1] : 0; + decimal prevQu = i >= 1 ? quList[i - 1] : 0; decimal prevPhase = phaseList.LastOrDefault(); decimal phase = Math.Abs(ip + prevIp) > 0 ? 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.Add(phase); + phaseList.AddRounded(phase); decimal dPhase = prevPhase - phase; dPhase = prevPhase < 90 && phase > 270 ? 360 + prevPhase - phase : dPhase; dPhase = MinOrMax(dPhase, 60, 1); - dPhaseList.Add(dPhase); + dPhaseList.AddRounded(dPhase); decimal instPeriod = 0, v4 = 0; for (int j = 0; j <= length2; j++) { - decimal prevDPhase = i >= j ? dPhaseList.ElementAtOrDefault(i - j) : 0; + decimal prevDPhase = i >= j ? dPhaseList[i - j] : 0; v4 += prevDPhase; instPeriod = v4 > 360 && instPeriod == 0 ? j : instPeriod; } decimal prevDcPeriod = dcPeriodList.LastOrDefault(); decimal dcPeriod = (0.25m * instPeriod) + (0.75m * prevDcPeriod); - dcPeriodList.Add(dcPeriod); + dcPeriodList.AddRounded(dcPeriod); var signal = GetCompareSignal(qu - (-1 * ip), prevQu - (-1 * prevIp)); signalsList.Add(signal); @@ -3899,51 +3898,51 @@ public static StockData CalculateEhlersSquelchIndicator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; - decimal priorV1 = i >= length1 ? v1List.ElementAtOrDefault(i - length1) : 0; - decimal prevV12 = i >= 2 ? v1List.ElementAtOrDefault(i - 2) : 0; - decimal prevV14 = i >= 4 ? v1List.ElementAtOrDefault(i - 4) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length1 ? inputList[i - length1] : 0; + decimal priorV1 = i >= length1 ? v1List[i - length1] : 0; + decimal prevV12 = i >= 2 ? v1List[i - 2] : 0; + decimal prevV14 = i >= 4 ? v1List[i - 4] : 0; decimal v1 = currentValue - prevValue; - v1List.Add(v1); + v1List.AddRounded(v1); - decimal v2 = i >= 3 ? v1List.ElementAtOrDefault(i - 3) : 0; + decimal v2 = i >= 3 ? v1List[i - 3] : 0; decimal v3 = (0.75m * (v1 - priorV1)) + (0.25m * (prevV12 - prevV14)); decimal prevIp = ipList.LastOrDefault(); decimal ip = (0.33m * v2) + (0.67m * prevIp); - ipList.Add(ip); + ipList.AddRounded(ip); decimal prevQu = quList.LastOrDefault(); decimal qu = (0.2m * v3) + (0.8m * prevQu); - quList.Add(qu); + quList.AddRounded(qu); decimal prevPhase = phaseList.LastOrDefault(); decimal phase = Math.Abs(ip + prevIp) > 0 ? 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.Add(phase); + phaseList.AddRounded(phase); decimal dPhase = prevPhase - phase; dPhase = prevPhase < 90 && phase > 270 ? 360 + prevPhase - phase : dPhase; dPhase = MinOrMax(dPhase, 60, 1); - dPhaseList.Add(dPhase); + dPhaseList.AddRounded(dPhase); decimal instPeriod = 0, v4 = 0; for (int j = 0; j <= length3; j++) { - decimal prevDPhase = i >= j ? dPhaseList.ElementAtOrDefault(i - j) : 0; + decimal prevDPhase = i >= j ? dPhaseList[i - j] : 0; v4 += prevDPhase; instPeriod = v4 > 360 && instPeriod == 0 ? j : instPeriod; } decimal prevDcPeriod = dcPeriodList.LastOrDefault(); decimal dcPeriod = (0.25m * instPeriod) + (0.75m * prevDcPeriod); - dcPeriodList.Add(dcPeriod); + dcPeriodList.AddRounded(dcPeriod); decimal si = dcPeriod < length2 ? 0 : 1; - siList.Add(si); + siList.AddRounded(si); var signal = GetCompareSignal(qu - (-1 * ip), prevQu - (-1 * prevIp)); signalsList.Add(signal); @@ -3978,30 +3977,30 @@ public static StockData CalculateEhlersClassicHilbertTransformer(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevReal1 = i >= 1 ? realList.ElementAtOrDefault(i - 1) : 0; - decimal prevReal2 = i >= 2 ? realList.ElementAtOrDefault(i - 2) : 0; - decimal prevReal4 = i >= 4 ? realList.ElementAtOrDefault(i - 4) : 0; - decimal prevReal6 = i >= 6 ? realList.ElementAtOrDefault(i - 6) : 0; - decimal prevReal8 = i >= 8 ? realList.ElementAtOrDefault(i - 8) : 0; - decimal prevReal10 = i >= 10 ? realList.ElementAtOrDefault(i - 10) : 0; - decimal prevReal12 = i >= 12 ? realList.ElementAtOrDefault(i - 12) : 0; - decimal prevReal14 = i >= 14 ? realList.ElementAtOrDefault(i - 14) : 0; - decimal prevReal16 = i >= 16 ? realList.ElementAtOrDefault(i - 16) : 0; - decimal prevReal18 = i >= 18 ? realList.ElementAtOrDefault(i - 18) : 0; - decimal prevReal20 = i >= 20 ? realList.ElementAtOrDefault(i - 20) : 0; - decimal prevReal22 = i >= 22 ? realList.ElementAtOrDefault(i - 22) : 0; + decimal roofingFilter = roofingFilterList[i]; + decimal prevReal1 = i >= 1 ? realList[i - 1] : 0; + decimal prevReal2 = i >= 2 ? realList[i - 2] : 0; + decimal prevReal4 = i >= 4 ? realList[i - 4] : 0; + decimal prevReal6 = i >= 6 ? realList[i - 6] : 0; + decimal prevReal8 = i >= 8 ? realList[i - 8] : 0; + decimal prevReal10 = i >= 10 ? realList[i - 10] : 0; + decimal prevReal12 = i >= 12 ? realList[i - 12] : 0; + decimal prevReal14 = i >= 14 ? realList[i - 14] : 0; + decimal prevReal16 = i >= 16 ? realList[i - 16] : 0; + decimal prevReal18 = i >= 18 ? realList[i - 18] : 0; + decimal prevReal20 = i >= 20 ? realList[i - 20] : 0; + decimal prevReal22 = i >= 22 ? realList[i - 22] : 0; decimal prevPeak = peakList.LastOrDefault(); decimal peak = Math.Max(0.991m * prevPeak, Math.Abs(roofingFilter)); - peakList.Add(peak); + peakList.AddRounded(peak); decimal real = peak != 0 ? roofingFilter / peak : 0; - realList.Add(real); + realList.AddRounded(real); decimal imag = ((0.091m * real) + (0.111m * prevReal2) + (0.143m * prevReal4) + (0.2m * prevReal6) + (0.333m * prevReal8) + prevReal10 - prevReal12 - (0.333m * prevReal14) - (0.2m * prevReal16) - (0.143m * prevReal18) - (0.111m * prevReal20) - (0.091m * prevReal22)) / 1.865m; - imagList.Add(imag); + imagList.AddRounded(imag); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); signalsList.Add(signal); @@ -4038,25 +4037,25 @@ public static StockData CalculateEhlersHilbertTransformer(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevReal1 = i >= 1 ? realList.ElementAtOrDefault(i - 1) : 0; - decimal prevReal2 = i >= 2 ? realList.ElementAtOrDefault(i - 2) : 0; + decimal roofingFilter = roofingFilterList[i]; + decimal prevReal1 = i >= 1 ? realList[i - 1] : 0; + decimal prevReal2 = i >= 2 ? realList[i - 2] : 0; decimal prevPeak = peakList.LastOrDefault(); decimal peak = Math.Max(0.991m * prevPeak, Math.Abs(roofingFilter)); - peakList.Add(peak); + peakList.AddRounded(peak); decimal prevReal = realList.LastOrDefault(); decimal real = peak != 0 ? roofingFilter / peak : 0; - realList.Add(real); + realList.AddRounded(real); decimal qFilt = real - prevReal; decimal prevQPeak = qPeakList.LastOrDefault(); decimal qPeak = Math.Max(0.991m * prevQPeak, Math.Abs(qFilt)); - qPeakList.Add(qPeak); + qPeakList.AddRounded(qPeak); decimal imag = qPeak != 0 ? qFilt / qPeak : 0; - imagList.Add(imag); + imagList.AddRounded(imag); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); signalsList.Add(signal); @@ -4101,29 +4100,29 @@ public static StockData CalculateEhlersHilbertTransformerIndicator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal prevQFilt = i >= 1 ? qFiltList.ElementAtOrDefault(i - 1) : 0; - decimal prevImag1 = i >= 1 ? imagList.ElementAtOrDefault(i - 1) : 0; - decimal prevImag2 = i >= 2 ? imagList.ElementAtOrDefault(i - 2) : 0; + decimal roofingFilter = roofingFilterList[i]; + decimal prevQFilt = i >= 1 ? qFiltList[i - 1] : 0; + decimal prevImag1 = i >= 1 ? imagList[i - 1] : 0; + decimal prevImag2 = i >= 2 ? imagList[i - 2] : 0; decimal prevPeak = peakList.LastOrDefault(); decimal peak = Math.Max(0.991m * prevPeak, Math.Abs(roofingFilter)); - peakList.Add(peak); + peakList.AddRounded(peak); decimal prevReal = realList.LastOrDefault(); decimal real = peak != 0 ? roofingFilter / peak : 0; - realList.Add(real); + realList.AddRounded(real); decimal qFilt = real - prevReal; decimal prevQPeak = qPeakList.LastOrDefault(); decimal qPeak = Math.Max(0.991m * prevQPeak, Math.Abs(qFilt)); - qPeakList.Add(qPeak); + qPeakList.AddRounded(qPeak); qFilt = qPeak != 0 ? qFilt / qPeak : 0; - qFiltList.Add(qFilt); + qFiltList.AddRounded(qFilt); decimal imag = (c1 * ((qFilt + prevQFilt) / 2)) + (c2 * prevImag1) + (c3 * prevImag2); - imagList.Add(imag); + imagList.AddRounded(imag); var signal = GetCompareSignal(imag - qFilt, prevImag1 - prevQFilt); signalsList.Add(signal); @@ -4167,23 +4166,23 @@ public static StockData CalculateEhlersDualDifferentiatorDominantCycle(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal real = realList.ElementAtOrDefault(i); - decimal imag = imagList.ElementAtOrDefault(i); - decimal prevReal1 = i >= 1 ? realList.ElementAtOrDefault(i - 1) : 0; - decimal prevReal2 = i >= 2 ? realList.ElementAtOrDefault(i - 2) : 0; - decimal prevImag1 = i >= 1 ? imagList.ElementAtOrDefault(i - 1) : 0; + decimal real = realList[i]; + decimal imag = imagList[i]; + decimal prevReal1 = i >= 1 ? realList[i - 1] : 0; + decimal prevReal2 = i >= 2 ? realList[i - 2] : 0; + decimal prevImag1 = i >= 1 ? imagList[i - 1] : 0; decimal iDot = real - prevReal1; - decimal prevDomCyc1 = i >= 1 ? domCycList.ElementAtOrDefault(i - 1) : 0; - decimal prevDomCyc2 = i >= 2 ? domCycList.ElementAtOrDefault(i - 2) : 0; + decimal prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; + decimal prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; decimal qDot = imag - prevImag1; decimal prevPeriod = periodList.LastOrDefault(); decimal period = (real * qDot) - (imag * iDot) != 0 ? 2 * Pi * ((real * real) + (imag * imag)) / ((-real * qDot) + (imag * iDot)) : 0; period = MinOrMax(period, length1, length3); - periodList.Add(period); + periodList.AddRounded(period); decimal domCyc = (c1 * ((period + prevPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); signalsList.Add(signal); @@ -4230,30 +4229,30 @@ public static StockData CalculateEhlersPhaseAccumulationDominantCycle(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal real = realList.ElementAtOrDefault(i); - decimal imag = imagList.ElementAtOrDefault(i); - decimal prevReal1 = i >= 1 ? realList.ElementAtOrDefault(i - 1) : 0; - decimal prevReal2 = i >= 2 ? realList.ElementAtOrDefault(i - 2) : 0; - decimal prevDomCyc1 = i >= 1 ? domCycList.ElementAtOrDefault(i - 1) : 0; - decimal prevDomCyc2 = i >= 2 ? domCycList.ElementAtOrDefault(i - 2) : 0; + decimal real = realList[i]; + decimal imag = imagList[i]; + decimal prevReal1 = i >= 1 ? realList[i - 1] : 0; + decimal prevReal2 = i >= 2 ? realList[i - 2] : 0; + decimal prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; + decimal prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; decimal prevPhase = phaseList.LastOrDefault(); decimal phase = Math.Abs(real) > 0 ? 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.Add(phase); + phaseList.AddRounded(phase); decimal dPhase = prevPhase - phase; dPhase = prevPhase < 90 && phase > 270 ? 360 + prevPhase - phase : dPhase; dPhase = MinOrMax(dPhase, length1, length3); - dPhaseList.Add(dPhase); + dPhaseList.AddRounded(dPhase); decimal prevInstPeriod = instPeriodList.LastOrDefault(); decimal instPeriod = 0, phaseSum = 0; for (int j = 0; j < length4; j++) { - decimal prevDPhase = i >= j ? dPhaseList.ElementAtOrDefault(i - j) : 0; + decimal prevDPhase = i >= j ? dPhaseList[i - j] : 0; phaseSum += prevDPhase; if (phaseSum > 360 && instPeriod == 0) @@ -4262,10 +4261,10 @@ public static StockData CalculateEhlersPhaseAccumulationDominantCycle(this Stock } } instPeriod = instPeriod == 0 ? prevInstPeriod : instPeriod; - instPeriodList.Add(instPeriod); + instPeriodList.AddRounded(instPeriod); decimal domCyc = (c1 * ((instPeriod + prevInstPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); signalsList.Add(signal); @@ -4308,23 +4307,23 @@ public static StockData CalculateEhlersHomodyneDominantCycle(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal real = realList.ElementAtOrDefault(i); - decimal imag = imagList.ElementAtOrDefault(i); - decimal prevReal1 = i >= 1 ? realList.ElementAtOrDefault(i - 1) : 0; - decimal prevImag1 = i >= 1 ? imagList.ElementAtOrDefault(i - 1) : 0; - decimal prevReal2 = i >= 2 ? realList.ElementAtOrDefault(i - 2) : 0; - decimal prevDomCyc1 = i >= 1 ? domCycList.ElementAtOrDefault(i - 1) : 0; - decimal prevDomCyc2 = i >= 2 ? domCycList.ElementAtOrDefault(i - 2) : 0; + decimal real = realList[i]; + decimal imag = imagList[i]; + decimal prevReal1 = i >= 1 ? realList[i - 1] : 0; + decimal prevImag1 = i >= 1 ? imagList[i - 1] : 0; + decimal prevReal2 = i >= 2 ? realList[i - 2] : 0; + decimal prevDomCyc1 = i >= 1 ? domCycList[i - 1] : 0; + decimal prevDomCyc2 = i >= 2 ? domCycList[i - 2] : 0; decimal re = (real * prevReal1) + (imag * prevImag1); decimal im = (prevReal1 * imag) - (real * prevImag1); decimal prevPeriod = periodList.LastOrDefault(); decimal period = im != 0 && re != 0 ? 2 * Pi / Math.Abs(im / re) : 0; period = MinOrMax(period, length1, length3); - periodList.Add(period); + periodList.AddRounded(period); decimal domCyc = (c1 * ((period + prevPeriod) / 2)) + (c2 * prevDomCyc1) + (c3 * prevDomCyc2); - domCycList.Add(domCyc); + domCycList.AddRounded(domCyc); var signal = GetCompareSignal(real - prevReal1, prevReal1 - prevReal2); signalsList.Add(signal); @@ -4364,26 +4363,26 @@ public static StockData CalculateEhlersSignalToNoiseRatioV1(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal inPhase = inPhaseList.ElementAtOrDefault(i); - decimal quad = quadList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentEma = emaList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal inPhase = inPhaseList[i]; + decimal quad = quadList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal prevV2 = v2List.LastOrDefault(); decimal v2 = (0.2m * ((inPhase * inPhase) + (quad * quad))) + (0.8m * prevV2); - v2List.Add(v2); + v2List.AddRounded(v2); decimal prevRange = rangeList.LastOrDefault(); decimal range = (0.2m * (currentHigh - currentLow)) + (0.8m * prevRange); - rangeList.Add(range); + rangeList.AddRounded(range); decimal prevAmp = ampList.LastOrDefault(); decimal amp = range != 0 ? (0.25m * ((10 * Log(v2 / (range * range)) / Log(10)) + 1.9m)) + (0.75m * prevAmp) : 0; - ampList.Add(amp); + ampList.AddRounded(amp); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, amp, 1.9m); signalsList.Add(signal); @@ -4416,22 +4415,22 @@ public static StockData CalculateEhlersHannWindowIndicator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; decimal deriv = currentValue - currentOpen; - derivList.Add(deriv); + derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal roc = length / 2 * Pi * (filt - prevFilt1); - rocList.Add(roc); + rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -4467,23 +4466,23 @@ public static StockData CalculateEhlersHammingWindowIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; decimal deriv = currentValue - currentOpen; - derivList.Add(deriv); + derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal roc = length / 2 * Pi * (filt - prevFilt1); - rocList.Add(roc); + rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -4518,22 +4517,22 @@ public static StockData CalculateEhlersTriangleWindowIndicator(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; decimal deriv = currentValue - currentOpen; - derivList.Add(deriv); + derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal roc = length / 2 * Pi * (filt - prevFilt1); - rocList.Add(roc); + rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -4567,11 +4566,11 @@ public static StockData CalculateEhlersSimpleWindowIndicator(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; decimal deriv = currentValue - currentOpen; - derivList.Add(deriv); + derivList.AddRounded(deriv); } var filtList = GetMovingAverageList(stockData, maType, length, derivList); @@ -4579,12 +4578,12 @@ public static StockData CalculateEhlersSimpleWindowIndicator(this StockData stoc var filtMa2List = GetMovingAverageList(stockData, maType, length, filtMa1List); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtMa2List.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtMa2List.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtMa2List.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtMa2List[i]; + decimal prevFilt1 = i >= 1 ? filtMa2List[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtMa2List[i - 2] : 0; decimal roc = length / 2 * Pi * (filt - prevFilt1); - rocList.Add(roc); + rocList.AddRounded(roc); var signal = GetCompareSignal(filt - prevFilt1, prevFilt1 - prevFilt2); signalsList.Add(signal); @@ -4622,23 +4621,23 @@ public static StockData CalculateEhlersSignalToNoiseRatioV2(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevMama = i >= 1 ? mamaList.ElementAtOrDefault(i - 1) : 0; - decimal i1 = i1List.ElementAtOrDefault(i); - decimal q1 = q1List.ElementAtOrDefault(i); - decimal mama = mamaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevMama = i >= 1 ? mamaList[i - 1] : 0; + decimal i1 = i1List[i]; + decimal q1 = q1List[i]; + decimal mama = mamaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevRange = rangeList.LastOrDefault(); decimal range = (0.1m * (currentHigh - currentLow)) + (0.9m * prevRange); - rangeList.Add(range); + rangeList.AddRounded(range); decimal temp = range != 0 ? ((i1 * i1) + (q1 * q1)) / (range * range) : 0; decimal prevSnr = snrList.LastOrDefault(); decimal snr = range > 0 ? (0.25m * ((10 * Log(temp) / Log(10)) + length)) + (0.75m * prevSnr) : 0; - snrList.Add(snr); + snrList.AddRounded(snr); var signal = GetVolatilitySignal(currentValue - mama, prevValue - prevMama, snr, length); signalsList.Add(signal); @@ -4676,37 +4675,37 @@ public static StockData CalculateEhlersEnhancedSignalToNoiseRatio(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal smooth = smoothList.ElementAtOrDefault(i); - decimal prevSmooth2 = i >= 2 ? smoothList.ElementAtOrDefault(i - 2) : 0; - decimal smoothPeriod = smoothPeriodList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmooth = i >= 1 ? smoothList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal smooth = smoothList[i]; + decimal prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + decimal smoothPeriod = smoothPeriodList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSmooth = i >= 1 ? smoothList[i - 1] : 0; decimal q3 = 0.5m * (smooth - prevSmooth2) * ((0.1759m * smoothPeriod) + 0.4607m); - q3List.Add(q3); + q3List.AddRounded(q3); int sp = (int)Math.Ceiling(smoothPeriod / 2); decimal i3 = 0; for (int j = 0; j <= sp - 1; j++) { - decimal prevQ3 = i >= j ? q3List.ElementAtOrDefault(i - j) : 0; + decimal prevQ3 = i >= j ? q3List[i - j] : 0; i3 += prevQ3; } i3 = sp != 0 ? 1.57m * i3 / sp : i3; - i3List.Add(i3); + i3List.AddRounded(i3); decimal signalValue = (i3 * i3) + (q3 * q3); decimal prevNoise = noiseList.LastOrDefault(); decimal noise = (0.1m * (currentHigh - currentLow) * (currentHigh - currentLow) * 0.25m) + (0.9m * prevNoise); - noiseList.Add(noise); + noiseList.AddRounded(noise); decimal temp = noise != 0 ? signalValue / noise : 0; decimal prevSnr = snrList.LastOrDefault(); decimal snr = (0.33m * (10 * Log(temp) / Log(10))) + (0.67m * prevSnr); - snrList.Add(snr); + snrList.AddRounded(snr); var signal = GetVolatilitySignal(currentValue - smooth, prevValue - prevSmooth, snr, length); signalsList.Add(signal); @@ -4744,20 +4743,20 @@ public static StockData CalculateEhlersHilbertOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal smoothPeriod = smoothPeriodList.ElementAtOrDefault(i); - decimal i3 = i3List.ElementAtOrDefault(i); - decimal prevI3 = i >= 1 ? i3List.ElementAtOrDefault(i - 1) : 0; - decimal prevIq = i >= 1 ? iqList.ElementAtOrDefault(i - 1) : 0; + decimal smoothPeriod = smoothPeriodList[i]; + decimal i3 = i3List[i]; + decimal prevI3 = i >= 1 ? i3List[i - 1] : 0; + decimal prevIq = i >= 1 ? iqList[i - 1] : 0; int maxCount = (int)Math.Ceiling(smoothPeriod / 4); decimal iq = 0; for (int j = 0; j <= maxCount - 1; j++) { - decimal prevQ3 = i >= j ? q3List.ElementAtOrDefault(i - j) : 0; + decimal prevQ3 = i >= j ? q3List[i - j] : 0; iq += prevQ3; } iq = maxCount != 0 ? 1.25m * iq / maxCount : iq; - iqList.Add(iq); + iqList.AddRounded(iq); var signal = GetCompareSignal(iq - i3, prevIq - prevI3); signalsList.Add(signal); @@ -4795,23 +4794,23 @@ public static StockData CalculateEhlersAlternateSignalToNoiseRatio(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal mama = mamaList.ElementAtOrDefault(i); - decimal re = reList.ElementAtOrDefault(i); - decimal im = imList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMama = i >= 1 ? mamaList.ElementAtOrDefault(i - 1) : 0; + decimal mama = mamaList[i]; + decimal re = reList[i]; + decimal im = imList[i]; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMama = i >= 1 ? mamaList[i - 1] : 0; decimal prevRange = rangeList.LastOrDefault(); decimal range = (0.1m * (currentHigh - currentLow)) + (0.9m * prevRange); - rangeList.Add(range); + rangeList.AddRounded(range); decimal temp = range != 0 ? (re + im) / (range * range) : 0; decimal prevSnr = snrList.LastOrDefault(); decimal snr = (0.25m * ((10 * Log(temp) / Log(10)) + length)) + (0.75m * prevSnr); - snrList.Add(snr); + snrList.AddRounded(snr); var signal = GetVolatilitySignal(currentValue - mama, prevValue - prevMama, snr, length); signalsList.Add(signal); @@ -4850,39 +4849,39 @@ public static StockData CalculateEhlersDiscreteFourierTransform(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp3 = i >= 3 ? hpList.ElementAtOrDefault(i - 3) : 0; - decimal prevHp4 = i >= 4 ? hpList.ElementAtOrDefault(i - 4) : 0; - decimal prevHp5 = i >= 5 ? hpList.ElementAtOrDefault(i - 5) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevHp3 = i >= 3 ? hpList[i - 3] : 0; + decimal prevHp4 = i >= 4 ? hpList[i - 4] : 0; + decimal prevHp5 = i >= 5 ? hpList[i - 5] : 0; decimal hp = i <= 5 ? currentValue : (0.5m * (1 + alpha) * (currentValue - prevValue1)) + (alpha * prevHp1); - hpList.Add(hp); + hpList.AddRounded(hp); decimal cleanedData = i <= 5 ? currentValue : (hp + (2 * prevHp1) + (3 * prevHp2) + (3 * prevHp3) + (2 * prevHp4) + prevHp5) / 12; - cleanedDataList.Add(cleanedData); + cleanedDataList.AddRounded(cleanedData); decimal pwr = 0, cosPart = 0, sinPart = 0; for (int j = minLength; j <= maxLength; j++) { for (int n = 0; n <= maxLength - 1; n++) { - decimal prevCleanedData = i >= n ? cleanedDataList.ElementAtOrDefault(i - n) : 0; + decimal prevCleanedData = i >= n ? cleanedDataList[i - n] : 0; cosPart += prevCleanedData * Cos(MinOrMax(2 * Pi * ((decimal)n / j), 0.99m, 0.01m)); sinPart += prevCleanedData * Sin(MinOrMax(2 * Pi * ((decimal)n / j), 0.99m, 0.01m)); } pwr = (cosPart * cosPart) + (sinPart * sinPart); } - powerList.Add(pwr); + powerList.AddRounded(pwr); - decimal maxPwr = i >= minLength ? powerList.ElementAtOrDefault(i - minLength) : 0; + decimal maxPwr = i >= minLength ? powerList[i - minLength] : 0; decimal num = 0, denom = 0; for (int period = minLength; period <= maxLength; period++) { - decimal prevPwr = i >= period ? powerList.ElementAtOrDefault(i - period) : 0; + decimal prevPwr = i >= period ? powerList[i - period] : 0; maxPwr = prevPwr > maxPwr ? prevPwr : maxPwr; decimal db = maxPwr > 0 && prevPwr > 0 ? -10 * Log(0.01m / (1 - (0.99m * prevPwr / maxPwr))) / Log(10) : 0; db = db > 20 ? 20 : db; @@ -4892,7 +4891,7 @@ public static StockData CalculateEhlersDiscreteFourierTransform(this StockData s } decimal dominantCycle = denom != 0 ? num / denom : 0; - dominantCycleList.Add(dominantCycle); + dominantCycleList.AddRounded(dominantCycle); var signal = GetCompareSignal(hp, prevHp1); signalsList.Add(signal); @@ -4941,43 +4940,43 @@ public static StockData CalculateEhlersFourierSeriesAnalysis(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevBp1_1 = bp1List.LastOrDefault(); decimal prevBp2_1 = bp2List.LastOrDefault(); decimal prevBp3_1 = bp3List.LastOrDefault(); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1_2 = i >= 2 ? bp1List.ElementAtOrDefault(i - 2) : 0; - decimal prevBp2_2 = i >= 2 ? bp2List.ElementAtOrDefault(i - 2) : 0; - decimal prevBp3_2 = i >= 2 ? bp3List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave2 = i >= 2 ? waveList.ElementAtOrDefault(i - 2) : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevBp1_2 = i >= 2 ? bp1List[i - 2] : 0; + decimal prevBp2_2 = i >= 2 ? bp2List[i - 2] : 0; + decimal prevBp3_2 = i >= 2 ? bp3List[i - 2] : 0; + decimal prevWave2 = i >= 2 ? waveList[i - 2] : 0; decimal bp1 = i <= 3 ? 0 : (0.5m * (1 - s1) * (currentValue - prevValue2)) + (l1 * (1 + s1) * prevBp1_1) - (s1 * prevBp1_2); - bp1List.Add(bp1); + bp1List.AddRounded(bp1); decimal q1 = i <= 4 ? 0 : length / 2 * Pi * (bp1 - prevBp1_1); - q1List.Add(q1); + q1List.AddRounded(q1); decimal bp2 = i <= 3 ? 0 : (0.5m * (1 - s2) * (currentValue - prevValue2)) + (l2 * (1 + s2) * prevBp2_1) - (s2 * prevBp2_2); - bp2List.Add(bp2); + bp2List.AddRounded(bp2); decimal q2 = i <= 4 ? 0 : length / 2 * Pi * (bp2 - prevBp2_1); - q2List.Add(q2); + q2List.AddRounded(q2); decimal bp3 = i <= 3 ? 0 : (0.5m * (1 - s3) * (currentValue - prevValue2)) + (l3 * (1 + s3) * prevBp3_1) - (s3 * prevBp3_2); - bp3List.Add(bp3); + bp3List.AddRounded(bp3); decimal q3 = i <= 4 ? 0 : length / 2 * Pi * (bp3 - prevBp3_1); - q3List.Add(q3); + q3List.AddRounded(q3); decimal p1 = 0, p2 = 0, p3 = 0; for (int j = 0; j <= length - 1; j++) { - decimal prevBp1 = i >= j ? bp1List.ElementAtOrDefault(i - j) : 0; - decimal prevBp2 = i >= j ? bp2List.ElementAtOrDefault(i - j) : 0; - decimal prevBp3 = i >= j ? bp3List.ElementAtOrDefault(i - j) : 0; - decimal prevQ1 = i >= j ? q1List.ElementAtOrDefault(i - j) : 0; - decimal prevQ2 = i >= j ? q2List.ElementAtOrDefault(i - j) : 0; - decimal prevQ3 = i >= j ? q3List.ElementAtOrDefault(i - j) : 0; + decimal prevBp1 = i >= j ? bp1List[i - j] : 0; + decimal prevBp2 = i >= j ? bp2List[i - j] : 0; + decimal prevBp3 = i >= j ? bp3List[i - j] : 0; + decimal prevQ1 = i >= j ? q1List[i - j] : 0; + decimal prevQ2 = i >= j ? q2List[i - j] : 0; + decimal prevQ3 = i >= j ? q3List[i - j] : 0; p1 += (prevBp1 * prevBp1) + (prevQ1 * prevQ1); p2 += (prevBp2 * prevBp2) + (prevQ2 * prevQ2); @@ -4986,10 +4985,10 @@ public static StockData CalculateEhlersFourierSeriesAnalysis(this StockData stoc decimal prevWave = waveList.LastOrDefault(); decimal wave = p1 != 0 ? bp1 + (Sqrt(p2 / p1) * bp2) + (Sqrt(p3 / p1) * bp3) : 0; - waveList.Add(wave); + waveList.AddRounded(wave); decimal roc = length / Pi * 4 * (wave - prevWave2); - rocList.Add(roc); + rocList.AddRounded(roc); var signal = GetCompareSignal(wave, prevWave); signalsList.Add(signal); @@ -5029,24 +5028,24 @@ public static StockData CalculateEhlersVossPredictiveFilter(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; decimal filt = i <= 5 ? 0 : (0.5m * (1 - s1) * (currentValue - prevValue2)) + (f1 * (1 + s1) * prevFilt1) - (s1 * prevFilt2); - filtList.Add(filt); + filtList.AddRounded(filt); decimal sumC = 0; for (int j = 0; j <= order - 1; j++) { - decimal prevVoss = i >= order - j ? vossList.ElementAtOrDefault(i - (order - j)) : 0; + decimal prevVoss = i >= order - j ? vossList[i - (order - j)] : 0; sumC += (decimal)(j + 1) / order * prevVoss; } decimal prevvoss = vossList.LastOrDefault(); decimal voss = ((decimal)(3 + order) / 2 * filt) - sumC; - vossList.Add(voss); + vossList.AddRounded(voss); var signal = GetCompareSignal(voss - filt, prevvoss - prevFilt1); signalsList.Add(signal); @@ -5091,10 +5090,10 @@ public static StockData CalculateEhlersSwissArmyKnifeIndicator(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevPrice1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevPrice2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevPrice = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevPrice1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevPrice2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevPrice = i >= length ? inputList[i - length] : 0; decimal prevEmaFilter1 = emaFilterList.LastOrDefault(); decimal prevSmaFilter1 = smaFilterList.LastOrDefault(); decimal prevGaussFilter1 = gaussFilterList.LastOrDefault(); @@ -5104,65 +5103,65 @@ public static StockData CalculateEhlersSwissArmyKnifeIndicator(this StockData st decimal prevPhp2Filter1 = php2FilterList.LastOrDefault(); decimal prevBpFilter1 = bpFilterList.LastOrDefault(); decimal prevBsFilter1 = bsFilterList.LastOrDefault(); - decimal prevEmaFilter2 = i >= 2 ? emaFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevSmaFilter2 = i >= 2 ? smaFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevGaussFilter2 = i >= 2 ? gaussFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevButterFilter2 = i >= 2 ? butterFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevSmoothFilter2 = i >= 2 ? smoothFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevHpFilter2 = i >= 2 ? hpFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevPhp2Filter2 = i >= 2 ? php2FilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevBpFilter2 = i >= 2 ? bpFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevBsFilter2 = i >= 2 ? bsFilterList.ElementAtOrDefault(i - 2) : 0; + decimal prevEmaFilter2 = i >= 2 ? emaFilterList[i - 2] : 0; + decimal prevSmaFilter2 = i >= 2 ? smaFilterList[i - 2] : 0; + decimal prevGaussFilter2 = i >= 2 ? gaussFilterList[i - 2] : 0; + decimal prevButterFilter2 = i >= 2 ? butterFilterList[i - 2] : 0; + decimal prevSmoothFilter2 = i >= 2 ? smoothFilterList[i - 2] : 0; + decimal prevHpFilter2 = i >= 2 ? hpFilterList[i - 2] : 0; + decimal prevPhp2Filter2 = i >= 2 ? php2FilterList[i - 2] : 0; + decimal prevBpFilter2 = i >= 2 ? bpFilterList[i - 2] : 0; + decimal prevBsFilter2 = i >= 2 ? bsFilterList[i - 2] : 0; decimal alpha = (Cos(twoPiPrd) + Sin(twoPiPrd) - 1) / Cos(twoPiPrd), c0 = 1, c1 = 0, b0 = alpha, b1 = 0, b2 = 0, a1 = 1 - alpha, a2 = 0; decimal emaFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevEmaFilter1) + (a2 * prevEmaFilter2) - (c1 * prevPrice); - emaFilterList.Add(emaFilter); + emaFilterList.AddRounded(emaFilter); int n = length; c0 = 1; c1 = (decimal)1 / n; b0 = (decimal)1 / n; b1 = 0; b2 = 0; a1 = 1; a2 = 0; decimal smaFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevSmaFilter1) + (a2 * prevSmaFilter2) - (c1 * prevPrice); - smaFilterList.Add(smaFilter); + smaFilterList.AddRounded(smaFilter); decimal beta = 2.415m * (1 - 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); decimal gaussFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevGaussFilter1) + (a2 * prevGaussFilter2) - (c1 * prevPrice); - gaussFilterList.Add(gaussFilter); + gaussFilterList.AddRounded(gaussFilter); beta = 2.415m * (1 - 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); decimal butterFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevButterFilter1) + (a2 * prevButterFilter2) - (c1 * prevPrice); - butterFilterList.Add(butterFilter); + butterFilterList.AddRounded(butterFilter); c0 = (decimal)1 / 4; c1 = 0; b0 = 1; b1 = 2; b2 = 1; a1 = 0; a2 = 0; decimal smoothFilter = (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevSmoothFilter1) + (a2 * prevSmoothFilter2) - (c1 * prevPrice); - smoothFilterList.Add(smoothFilter); + smoothFilterList.AddRounded(smoothFilter); alpha = (Cos(twoPiPrd) + Sin(twoPiPrd) - 1) / Cos(twoPiPrd); c0 = 1 - (alpha / 2); c1 = 0; b0 = 1; b1 = -1; b2 = 0; a1 = 1 - alpha; a2 = 0; decimal hpFilter = i <= length ? 0 : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevHpFilter1) + (a2 * prevHpFilter2) - (c1 * prevPrice); - hpFilterList.Add(hpFilter); + hpFilterList.AddRounded(hpFilter); beta = 2.415m * (1 - 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); decimal php2Filter = i <= length ? 0 : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevPhp2Filter1) + (a2 * prevPhp2Filter2) - (c1 * prevPrice); - php2FilterList.Add(php2Filter); + php2FilterList.AddRounded(php2Filter); beta = Cos(twoPiPrd); decimal gamma = 1 / 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; decimal bpFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevBpFilter1) + (a2 * prevBpFilter2) - (c1 * prevPrice); - bpFilterList.Add(bpFilter); + bpFilterList.AddRounded(bpFilter); beta = Cos(twoPiPrd); gamma = 1 / 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; decimal bsFilter = i <= length ? currentValue : (c0 * ((b0 * currentValue) + (b1 * prevPrice1) + (b2 * prevPrice2))) + (a1 * prevBsFilter1) + (a2 * prevBsFilter2) - (c1 * prevPrice); - bsFilterList.Add(bsFilter); + bsFilterList.AddRounded(bsFilter); var signal = GetCompareSignal(smaFilter - prevSmaFilter1, prevSmaFilter1 - prevSmaFilter2); signalsList.Add(signal); @@ -5213,35 +5212,35 @@ public static StockData CalculateEhlersUniversalOscillator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal prevWhitenoise = whitenoiseList.LastOrDefault(); decimal whitenoise = (currentValue - prevValue2) / 2; - whitenoiseList.Add(whitenoise); + whitenoiseList.AddRounded(whitenoise); decimal prevFilt1 = filtList.LastOrDefault(); decimal filt = (c1 * ((whitenoise + prevWhitenoise) / 2)) + (c2 * prevFilt1) + (c3 * prevFilt2); - filtList.Add(filt); + filtList.AddRounded(filt); decimal prevPk = pkList.LastOrDefault(); decimal pk = Math.Abs(filt) > prevPk ? Math.Abs(filt) : 0.991m * prevPk; - pkList.Add(pk); + pkList.AddRounded(pk); decimal denom = pk == 0 ? -1 : pk; decimal prevEuo = euoList.LastOrDefault(); decimal euo = denom == -1 ? prevEuo : pk != 0 ? filt / pk : 0; - euoList.Add(euo); + euoList.AddRounded(euo); } var euoMaList = GetMovingAverageList(stockData, maType, signalLength, euoList); for (int i = 0; i < stockData.Count; i++) { - decimal euo = euoList.ElementAtOrDefault(i); - decimal euoMa = euoMaList.ElementAtOrDefault(i); - decimal prevEuo = i >= 1 ? euoList.ElementAtOrDefault(i - 1) : 0; - decimal prevEuoMa = i >= 1 ? euoMaList.ElementAtOrDefault(i - 1) : 0; + decimal euo = euoList[i]; + decimal euoMa = euoMaList[i]; + decimal prevEuo = i >= 1 ? euoList[i - 1] : 0; + decimal prevEuoMa = i >= 1 ? euoMaList[i - 1] : 0; var signal = GetCompareSignal(euo - euoMa, prevEuo - prevEuoMa); signalsList.Add(signal); @@ -5280,30 +5279,30 @@ public static StockData CalculateEhlersDetrendedLeadingIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = Math.Max(prevHigh, highList.ElementAtOrDefault(i)); - decimal currentLow = Math.Min(prevLow, lowList.ElementAtOrDefault(i)); + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal currentHigh = Math.Max(prevHigh, highList[i]); + decimal currentLow = Math.Min(prevLow, lowList[i]); decimal currentPrice = (currentHigh + currentLow) / 2; decimal prevEma1 = i >= 1 ? ema1List.LastOrDefault() : currentPrice; decimal prevEma2 = i >= 1 ? ema2List.LastOrDefault() : currentPrice; decimal ema1 = (alpha * currentPrice) + ((1 - alpha) * prevEma1); - ema1List.Add(ema1); + ema1List.AddRounded(ema1); decimal ema2 = (alpha2 * currentPrice) + ((1 - alpha2) * prevEma2); - ema2List.Add(ema2); + ema2List.AddRounded(ema2); decimal dsp = ema1 - ema2; - dspList.Add(dsp); + dspList.AddRounded(dsp); decimal prevTemp = tempList.LastOrDefault(); decimal temp = (alpha * dsp) + ((1 - alpha) * prevTemp); - tempList.Add(temp); + tempList.AddRounded(temp); decimal prevDeli = deliList.LastOrDefault(); decimal deli = dsp - temp; - deliList.Add(deli); + deliList.AddRounded(deli); var signal = GetCompareSignal(deli, prevDeli); signalsList.Add(signal); @@ -5348,30 +5347,30 @@ public static StockData CalculateEhlersBandPassFilterV1(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal hp = ((1 + (alpha2 / 2)) * (currentValue - prevValue)) + ((1 - alpha2) * prevHp1); - hpList.Add(hp); + hpList.AddRounded(hp); decimal bp = i > 2 ? (0.5m * (1 - alpha1) * (hp - prevHp2)) + (beta * (1 + alpha1) * prevBp1) - (alpha1 * prevBp2) : 0; - bpList.Add(bp); + bpList.AddRounded(bp); decimal prevPeak = peakList.LastOrDefault(); decimal peak = Math.Max(0.991m * prevPeak, Math.Abs(bp)); - peakList.Add(peak); + peakList.AddRounded(peak); decimal prevSig = signalList.LastOrDefault(); decimal sig = peak != 0 ? bp / peak : 0; - signalList.Add(sig); + signalList.AddRounded(sig); decimal prevTrigger = triggerList.LastOrDefault(); decimal trigger = ((1 + (alpha3 / 2)) * (sig - prevSig)) + ((1 - alpha3) * prevTrigger); - triggerList.Add(trigger); + triggerList.AddRounded(trigger); var signal = GetCompareSignal(sig - trigger, prevSig - prevTrigger); signalsList.Add(signal); @@ -5408,13 +5407,13 @@ public static StockData CalculateEhlersBandPassFilterV2(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 2 ? inputList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal bp = i < 3 ? 0 : (0.5m * (1 - s1) * (currentValue - prevValue)) + (l1 * (1 + s1) * prevBp1) - (s1 * prevBp2); - bpList.Add(bp); + bpList.AddRounded(bp); var signal = GetCompareSignal(bp - prevBp1, prevBp1 - prevBp2); signalsList.Add(signal); @@ -5450,13 +5449,13 @@ public static StockData CalculateEhlersCycleBandPassFilter(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 2 ? inputList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; decimal bp = (0.5m * (1 - alpha) * (currentValue - prevValue)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2); - bpList.Add(bp); + bpList.AddRounded(bp); var signal = GetCompareSignal(bp - prevBp1, prevBp1 - prevBp2); signalsList.Add(signal); @@ -5491,19 +5490,19 @@ public static StockData CalculateEhlersCycleAmplitude(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal prevPtop1 = i >= 1 ? ptopList.ElementAtOrDefault(i - 1) : 0; - decimal prevPtop2 = i >= 2 ? ptopList.ElementAtOrDefault(i - 2) : 0; + decimal prevPtop1 = i >= 1 ? ptopList[i - 1] : 0; + decimal prevPtop2 = i >= 2 ? ptopList[i - 2] : 0; decimal power = 0; for (int j = length; j < length; j++) { - decimal prevBp1 = i >= j ? bpList.ElementAtOrDefault(i - j) : 0; - decimal prevBp2 = i >= j + lbLength ? bpList.ElementAtOrDefault(i - (j + lbLength)) : 0; + decimal prevBp1 = i >= j ? bpList[i - j] : 0; + decimal prevBp2 = i >= j + lbLength ? bpList[i - (j + lbLength)] : 0; power += Pow(prevBp1, 2) + Pow(prevBp2, 2); } decimal ptop = 2 * 1.414m * Sqrt(power / length); - ptopList.Add(ptop); + ptopList.AddRounded(ptop); var signal = GetCompareSignal(ptop - prevPtop1, prevPtop1 - prevPtop2); signalsList.Add(signal); @@ -5540,10 +5539,10 @@ public static StockData CalculateEhlersZeroCrossingsDominantCycle(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal real = realList.ElementAtOrDefault(i); - decimal trigger = triggerList.ElementAtOrDefault(i); - decimal prevReal = i >= 1 ? realList.ElementAtOrDefault(i - 1) : 0; - decimal prevTrigger = i >= 1 ? triggerList.ElementAtOrDefault(i - 1) : 0; + decimal real = realList[i]; + decimal trigger = triggerList[i]; + decimal prevReal = i >= 1 ? realList[i - 1] : 0; + decimal prevTrigger = i >= 1 ? triggerList[i - 1] : 0; decimal prevDc = dcList.LastOrDefault(); decimal dc = Math.Max(prevDc, 6); @@ -5553,7 +5552,7 @@ public static StockData CalculateEhlersZeroCrossingsDominantCycle(this StockData dc = MinOrMax(2 * counter, 1.25m * prevDc, 0.8m * prevDc); counter = 0; } - dcList.Add(dc); + dcList.AddRounded(dc); var signal = GetCompareSignal(real - trigger, prevReal - prevTrigger); signalsList.Add(signal); @@ -5593,36 +5592,36 @@ public static StockData CalculateEhlersAdaptiveBandPassFilter(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal roofingFilter = roofingFilterList.ElementAtOrDefault(i); - decimal domCyc = MinOrMax(domCycList.ElementAtOrDefault(i), length1, length3); + decimal roofingFilter = roofingFilterList[i]; + decimal domCyc = MinOrMax(domCycList[i], length1, length3); decimal beta = Cos(2 * Pi / 0.9m * domCyc); decimal gamma = 1 / Cos(2 * Pi * bw / 0.9m * domCyc); decimal alpha = MinOrMax(gamma - Sqrt((gamma * gamma) - 1), 0.99m, 0.01m); - decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; - decimal prevBp1 = i >= 1 ? bpList.ElementAtOrDefault(i - 1) : 0; - decimal prevBp2 = i >= 2 ? bpList.ElementAtOrDefault(i - 2) : 0; - decimal prevSignal1 = i >= 1 ? signalList.ElementAtOrDefault(i - 1) : 0; - decimal prevSignal2 = i >= 2 ? signalList.ElementAtOrDefault(i - 2) : 0; - decimal prevSignal3 = i >= 3 ? signalList.ElementAtOrDefault(i - 3) : 0; + decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; + decimal prevBp1 = i >= 1 ? bpList[i - 1] : 0; + decimal prevBp2 = i >= 2 ? bpList[i - 2] : 0; + decimal prevSignal1 = i >= 1 ? signalList[i - 1] : 0; + decimal prevSignal2 = i >= 2 ? signalList[i - 2] : 0; + decimal prevSignal3 = i >= 3 ? signalList[i - 3] : 0; decimal bp = i > 2 ? (0.5m * (1 - alpha) * (roofingFilter - prevRoofingFilter2)) + (beta * (1 + alpha) * prevBp1) - (alpha * prevBp2) : 0; - bpList.Add(bp); + bpList.AddRounded(bp); decimal prevPeak = peakList.LastOrDefault(); decimal peak = Math.Max(0.991m * prevPeak, Math.Abs(bp)); - peakList.Add(peak); + peakList.AddRounded(peak); decimal sig = peak != 0 ? bp / peak : 0; - signalList.Add(sig); + signalList.AddRounded(sig); decimal lead = 1.3m * (sig + prevSignal1 - prevSignal2 - prevSignal3) / 4; decimal prevLeadPeak = leadPeakList.LastOrDefault(); decimal leadPeak = Math.Max(0.93m * prevLeadPeak, Math.Abs(lead)); - leadPeakList.Add(leadPeak); + leadPeakList.AddRounded(leadPeak); decimal prevTrigger = triggerList.LastOrDefault(); decimal trigger = 0.9m * prevSignal1; - triggerList.Add(trigger); + triggerList.AddRounded(trigger); var signal = GetRsiSignal(sig - trigger, prevSignal1 - prevTrigger, sig, prevSignal1, 0.707m, -0.707m); signalsList.Add(signal); @@ -5655,21 +5654,21 @@ public static StockData CalculateEhlersCyberCycle(this StockData stockData, deci for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal prevSmooth1 = i >= 1 ? smoothList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmooth2 = i >= 2 ? smoothList.ElementAtOrDefault(i - 2) : 0; - decimal prevCycle1 = i >= 1 ? cycleList.ElementAtOrDefault(i - 1) : 0; - decimal prevCycle2 = i >= 2 ? cycleList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; + decimal prevSmooth1 = i >= 1 ? smoothList[i - 1] : 0; + decimal prevSmooth2 = i >= 2 ? smoothList[i - 2] : 0; + decimal prevCycle1 = i >= 1 ? cycleList[i - 1] : 0; + decimal prevCycle2 = i >= 2 ? cycleList[i - 2] : 0; decimal smooth = (currentValue + (2 * prevValue1) + (2 * prevValue2) + prevValue3) / 6; - smoothList.Add(smooth); + smoothList.AddRounded(smooth); decimal cycle = i < 7 ? (currentValue - (2 * prevValue1) + prevValue2) / 4 : (Pow(1 - (0.5m * alpha), 2) * (smooth - (2 * prevSmooth1) + prevSmooth2)) + (2 * (1 - alpha) * prevCycle1) - (Pow(1 - alpha, 2) * prevCycle2); - cycleList.Add(cycle); + cycleList.AddRounded(cycle); var signal = GetCompareSignal(cycle - prevCycle1, prevCycle1 - prevCycle2); signalsList.Add(signal); @@ -5705,23 +5704,23 @@ public static StockData CalculateEhlersStochasticCyberCycle(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal prevStoch1 = i >= 1 ? stochList.ElementAtOrDefault(i - 1) : 0; - decimal prevStoch2 = i >= 2 ? stochList.ElementAtOrDefault(i - 2) : 0; - decimal prevStoch3 = i >= 3 ? stochList.ElementAtOrDefault(i - 3) : 0; - decimal cycle = cyberCycleList.ElementAtOrDefault(i); - decimal maxCycle = maxCycleList.ElementAtOrDefault(i); - decimal minCycle = minCycleList.ElementAtOrDefault(i); + decimal prevStoch1 = i >= 1 ? stochList[i - 1] : 0; + decimal prevStoch2 = i >= 2 ? stochList[i - 2] : 0; + decimal prevStoch3 = i >= 3 ? stochList[i - 3] : 0; + decimal cycle = cyberCycleList[i]; + decimal maxCycle = maxCycleList[i]; + decimal minCycle = minCycleList[i]; decimal stoch = maxCycle - minCycle != 0 ? MinOrMax((cycle - minCycle) / (maxCycle - minCycle), 1, 0) : 0; - stochList.Add(stoch); + stochList.AddRounded(stoch); decimal prevStochCC = stochCCList.LastOrDefault(); decimal stochCC = MinOrMax(2 * ((((4 * stoch) + (3 * prevStoch1) + (2 * prevStoch2) + prevStoch3) / 10) - 0.5m), 1, -1); - stochCCList.Add(stochCC); + stochCCList.AddRounded(stochCC); decimal prevTrigger = triggerList.LastOrDefault(); decimal trigger = MinOrMax(0.96m * (prevStochCC + 0.02m), 1, -1); - triggerList.Add(trigger); + triggerList.AddRounded(trigger); var signal = GetRsiSignal(stochCC - trigger, prevStochCC - prevTrigger, stochCC, prevStochCC, 0.5m, -0.5m); signalsList.Add(signal); @@ -5756,20 +5755,20 @@ public static StockData CalculateEhlersFMDemodulatorIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; decimal der = currentClose - currentOpen; decimal hlRaw = fastLength * der; decimal hl = MinOrMax(hlRaw, 1, -1); - hlList.Add(hl); + hlList.AddRounded(hl); } var ssList = GetMovingAverageList(stockData, maType, slowLength, hlList); for (int i = 0; i < stockData.Count; i++) { - decimal ss = ssList.ElementAtOrDefault(i); - decimal prevSs = i >= 1 ? ssList.ElementAtOrDefault(i - 1) : 0; + decimal ss = ssList[i]; + decimal prevSs = i >= 1 ? ssList[i - 1] : 0; var signal = GetCompareSignal(ss, prevSs); signalsList.Add(signal); @@ -5807,24 +5806,24 @@ public static StockData CalculateEhlersStochastic(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal rf2Pole = roofingFilter2PoleList.ElementAtOrDefault(i); - decimal min2Pole = min2PoleList.ElementAtOrDefault(i); - decimal max2Pole = max2PoleList.ElementAtOrDefault(i); + decimal rf2Pole = roofingFilter2PoleList[i]; + decimal min2Pole = min2PoleList[i]; + decimal max2Pole = max2PoleList[i]; decimal prevStoch2Pole = stoch2PoleList.LastOrDefault(); decimal stoch2Pole = max2Pole - min2Pole != 0 ? MinOrMax((rf2Pole - min2Pole) / (max2Pole - min2Pole), 1, 0) : 0; - stoch2PoleList.Add(stoch2Pole); + stoch2PoleList.AddRounded(stoch2Pole); decimal arg2Pole = (stoch2Pole + prevStoch2Pole) / 2; - arg2PoleList.Add(arg2Pole); + arg2PoleList.AddRounded(arg2Pole); } var estoch2PoleList = GetMovingAverageList(stockData, maType, length2, arg2PoleList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal estoch2Pole = estoch2PoleList.ElementAtOrDefault(j); - decimal prevEstoch2Pole1 = j >= 1 ? estoch2PoleList.ElementAtOrDefault(j - 1) : 0; - decimal prevEstoch2Pole2 = j >= 2 ? estoch2PoleList.ElementAtOrDefault(j - 2) : 0; + decimal estoch2Pole = estoch2PoleList[i]; + decimal prevEstoch2Pole1 = i >= 1 ? estoch2PoleList[i - 1] : 0; + decimal prevEstoch2Pole2 = i >= 2 ? estoch2PoleList[i - 2] : 0; var signal = GetRsiSignal(estoch2Pole - prevEstoch2Pole1, prevEstoch2Pole1 - prevEstoch2Pole2, estoch2Pole, prevEstoch2Pole1, 0.8m, 0.2m); signalsList.Add(signal); @@ -5860,31 +5859,31 @@ public static StockData CalculateEhlersTripleDelayLineDetrender(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevTmp1_6 = i >= 6 ? tmp1List.ElementAtOrDefault(i - 6) : 0; - decimal prevTmp2_6 = i >= 6 ? tmp2List.ElementAtOrDefault(i - 6) : 0; - decimal prevTmp2_12 = i >= 12 ? tmp2List.ElementAtOrDefault(i - 12) : 0; + decimal currentValue = inputList[i]; + decimal prevTmp1_6 = i >= 6 ? tmp1List[i - 6] : 0; + decimal prevTmp2_6 = i >= 6 ? tmp2List[i - 6] : 0; + decimal prevTmp2_12 = i >= 12 ? tmp2List[i - 12] : 0; decimal tmp1 = currentValue + (0.088m * prevTmp1_6); - tmp1List.Add(tmp1); + tmp1List.AddRounded(tmp1); decimal tmp2 = tmp1 - prevTmp1_6 + (1.2m * prevTmp2_6) - (0.7m * prevTmp2_12); - tmp2List.Add(tmp2); + tmp2List.AddRounded(tmp2); decimal detrender = prevTmp2_12 - (2 * prevTmp2_6) + tmp2; - detrenderList.Add(detrender); + 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++) { - decimal tdld = tdldList.ElementAtOrDefault(i); - decimal tdldSignal = tdldSignalList.ElementAtOrDefault(i); + decimal tdld = tdldList[i]; + decimal tdldSignal = tdldSignalList[i]; decimal prevHist = histList.LastOrDefault(); decimal hist = tdld - tdldSignal; - histList.Add(hist); + histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); signalsList.Add(signal); @@ -5922,27 +5921,27 @@ public static StockData CalculateEhlersAMDetector(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; decimal der = currentClose - currentOpen; decimal absDer = Math.Abs(der); - absDerList.Add(absDer); + absDerList.AddRounded(absDer); decimal env = absDerList.TakeLastExt(length1).Max(); - envList.Add(env); + 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++) { - decimal vol = volList.ElementAtOrDefault(i); - decimal volEma = volEmaList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal vol = volList[i]; + decimal volEma = volEmaList[i]; + decimal ema = emaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, vol, volEma); signalsList.Add(signal); @@ -5978,13 +5977,13 @@ public static StockData CalculateEhlersSineWaveIndicatorV1(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal sp = spList.ElementAtOrDefault(i); + decimal sp = spList[i]; int dcPeriod = (int)Math.Ceiling(sp + 0.5m); decimal realPart = 0, imagPart = 0; for (int j = 0; j <= dcPeriod - 1; j++) { - decimal prevSmooth = i >= j ? smoothList.ElementAtOrDefault(i - j) : 0; + decimal prevSmooth = i >= j ? smoothList[i - j] : 0; realPart += Sin(MinOrMax(2 * Pi * ((decimal)j / dcPeriod), 0.99m, 0.01m)) * prevSmooth; imagPart += Cos(MinOrMax(2 * Pi * ((decimal)j / dcPeriod), 0.99m, 0.01m)) * prevSmooth; } @@ -5994,15 +5993,15 @@ public static StockData CalculateEhlersSineWaveIndicatorV1(this StockData stockD dcPhase += sp != 0 ? 360 / sp : 0; dcPhase += imagPart < 0 ? 180 : 0; dcPhase -= dcPhase > 315 ? 360 : 0; - dcPhaseList.Add(dcPhase); + dcPhaseList.AddRounded(dcPhase); decimal prevSine = sineList.LastOrDefault(); decimal sine = Sin(dcPhase.ToRadians()); - sineList.Add(sine); + sineList.AddRounded(sine); decimal prevLeadSine = leadSineList.LastOrDefault(); decimal leadSine = Sin((dcPhase + 45).ToRadians()); - leadSineList.Add(leadSine); + leadSineList.AddRounded(leadSine); var signal = GetCompareSignal(sine - leadSine, prevSine - prevLeadSine); signalsList.Add(signal); @@ -6039,13 +6038,13 @@ public static StockData CalculateEhlersSineWaveIndicatorV2(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal period = periodList.ElementAtOrDefault(i); + decimal period = periodList[i]; int dcPeriod = (int)Math.Ceiling(period); decimal realPart = 0, imagPart = 0; for (int j = 0; j <= dcPeriod - 1; j++) { - decimal prevCycle = i >= j ? cycleList.ElementAtOrDefault(i - j) : 0; + decimal prevCycle = i >= j ? cycleList[i - j] : 0; realPart += Sin(MinOrMax(2 * Pi * ((decimal)j / dcPeriod), 0.99m, 0.01m)) * prevCycle; imagPart += Cos(MinOrMax(2 * Pi * ((decimal)j / dcPeriod), 0.99m, 0.01m)) * prevCycle; } @@ -6054,15 +6053,15 @@ public static StockData CalculateEhlersSineWaveIndicatorV2(this StockData stockD dcPhase += 90; dcPhase += imagPart < 0 ? 180 : 0; dcPhase -= dcPhase > 315 ? 360 : 0; - dcPhaseList.Add(dcPhase); + dcPhaseList.AddRounded(dcPhase); decimal prevSine = sineList.LastOrDefault(); decimal sine = Sin(dcPhase.ToRadians()); - sineList.Add(sine); + sineList.AddRounded(sine); decimal prevLeadSine = leadSineList.LastOrDefault(); decimal leadSine = Sin((dcPhase + 45).ToRadians()); - leadSineList.Add(leadSine); + leadSineList.AddRounded(leadSine); var signal = GetCompareSignal(sine - leadSine, prevSine - prevLeadSine); signalsList.Add(signal); @@ -6105,23 +6104,23 @@ public static StockData CalculateEhlersEvenBetterSineWaveIndicator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilt2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilt1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilt2 = i >= 2 ? filtList[i - 2] : 0; decimal prevHp = hpList.LastOrDefault(); decimal hp = ((0.5m * (1 + a1)) * (currentValue - prevValue)) + (a1 * prevHp); - hpList.Add(hp); + hpList.AddRounded(hp); decimal filt = (c1 * ((hp + prevHp) / 2)) + (c2 * prevFilt1) + (c3 * prevFilt2); - filtList.Add(filt); + filtList.AddRounded(filt); decimal wave = (filt + prevFilt1 + prevFilt2) / 3; decimal pwr = (Pow(filt, 2) + Pow(prevFilt1, 2) + Pow(prevFilt2, 2)) / 3; decimal prevEbsi = ebsiList.LastOrDefault(); decimal ebsi = pwr > 0 ? wave / Sqrt(pwr) : 0; - ebsiList.Add(ebsi); + ebsiList.AddRounded(ebsi); var signal = GetCompareSignal(ebsi, prevEbsi); signalsList.Add(signal); @@ -6165,27 +6164,27 @@ public static StockData CalculateEhlersConvolutionIndicator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevHp1 = i >= 1 ? hpList.ElementAtOrDefault(i - 1) : 0; - decimal prevHp2 = i >= 2 ? hpList.ElementAtOrDefault(i - 2) : 0; - decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList.ElementAtOrDefault(i - 1) : 0; - decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevHp1 = i >= 1 ? hpList[i - 1] : 0; + decimal prevHp2 = i >= 2 ? hpList[i - 2] : 0; + decimal prevRoofingFilter1 = i >= 1 ? roofingFilterList[i - 1] : 0; + decimal prevRoofingFilter2 = i >= 2 ? roofingFilterList[i - 2] : 0; decimal highPass = (Pow(1 - (alpha / 2), 2) * (currentValue - (2 * prevValue1) + prevValue2)) + (2 * (1 - alpha) * prevHp1) - (Pow(1 - alpha, 2) * prevHp2); - hpList.Add(highPass); + hpList.AddRounded(highPass); decimal roofingFilter = (c1 * ((highPass + prevHp1) / 2)) + (c2 * prevRoofingFilter1) + (c3 * prevRoofingFilter2); - roofingFilterList.Add(roofingFilter); + roofingFilterList.AddRounded(roofingFilter); int n = i + 1; decimal sx = 0, sy = 0, sxx = 0, syy = 0, sxy = 0, corr = 0, conv = 0, slope = 0; for (int j = 1; j <= length3; j++) { - decimal x = i >= j - 1 ? roofingFilterList.ElementAtOrDefault(i - (j - 1)) : 0; - decimal y = i >= j ? roofingFilterList.ElementAtOrDefault(i - j) : 0; + decimal x = i >= j - 1 ? roofingFilterList[i - (j - 1)] : 0; + decimal y = i >= j ? roofingFilterList[i - j] : 0; sx += x; sy += y; sxx += Pow(x, 2); @@ -6196,11 +6195,11 @@ public static StockData CalculateEhlersConvolutionIndicator(this StockData stock conv = (1 + (Exp(3 * corr) - 1)) / (Exp(3 * corr) + 1) / 2; int filtLength = (int)Math.Ceiling(0.5 * n); - decimal prevFilt = i >= filtLength ? roofingFilterList.ElementAtOrDefault(i - filtLength) : 0; + decimal prevFilt = i >= filtLength ? roofingFilterList[i - filtLength] : 0; slope = prevFilt < roofingFilter ? -1 : 1; } - convList.Add(conv); - slopeList.Add(slope); + convList.AddRounded(conv); + slopeList.AddRounded(slope); var signal = GetCompareSignal(roofingFilter - prevRoofingFilter1, prevRoofingFilter1 - prevRoofingFilter2); signalsList.Add(signal); @@ -6234,19 +6233,19 @@ public static StockData CalculateEhlersFisherTransform(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal maxH = maxList.ElementAtOrDefault(i); - decimal minL = minList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal maxH = maxList[i]; + decimal minL = minList[i]; decimal ratio = maxH - minL != 0 ? (currentValue - minL) / (maxH - minL) : 0; - decimal prevFisherTransform1 = i >= 1 ? fisherTransformList.ElementAtOrDefault(i - 1) : 0; - decimal prevFisherTransform2 = i >= 2 ? fisherTransformList.ElementAtOrDefault(i - 2) : 0; + decimal prevFisherTransform1 = i >= 1 ? fisherTransformList[i - 1] : 0; + decimal prevFisherTransform2 = i >= 2 ? fisherTransformList[i - 2] : 0; decimal prevNValue = nValueList.LastOrDefault(); decimal nValue = MinOrMax((0.33m * 2 * (ratio - 0.5m)) + (0.67m * prevNValue), 0.999m, -0.999m); - nValueList.Add(nValue); + nValueList.AddRounded(nValue); decimal fisherTransform = (0.5m * Log((1 + nValue) / (1 - nValue))) + (0.5m * prevFisherTransform1); - fisherTransformList.Add(fisherTransform); + fisherTransformList.AddRounded(fisherTransform); var signal = GetCompareSignal(fisherTransform - prevFisherTransform1, prevFisherTransform1 - prevFisherTransform2); signalsList.Add(signal); @@ -6282,22 +6281,22 @@ public static StockData CalculateEhlersInverseFisherTransform(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentRsi = rsiList.ElementAtOrDefault(i); + decimal currentRsi = rsiList[i]; decimal v1 = 0.1m * (currentRsi - 50); - v1List.Add(v1); + v1List.AddRounded(v1); } var v2List = GetMovingAverageList(stockData, maType, length2, v1List); for (int i = 0; i < stockData.Count; i++) { - decimal v2 = v2List.ElementAtOrDefault(i); - decimal prevIft1 = i >= 1 ? inverseFisherTransformList.ElementAtOrDefault(i - 1) : 0; - decimal prevIft2 = i >= 2 ? inverseFisherTransformList.ElementAtOrDefault(i - 2) : 0; + decimal v2 = v2List[i]; + decimal prevIft1 = i >= 1 ? inverseFisherTransformList[i - 1] : 0; + decimal prevIft2 = i >= 2 ? inverseFisherTransformList[i - 2] : 0; decimal bottom = Exp(2 * v2) + 1; decimal inverseFisherTransform = bottom != 0 ? MinOrMax((Exp(2 * v2) - 1) / bottom, 1, -1) : 0; - inverseFisherTransformList.Add(inverseFisherTransform); + inverseFisherTransformList.AddRounded(inverseFisherTransform); var signal = GetRsiSignal(inverseFisherTransform - prevIft1, prevIft1 - prevIft2, inverseFisherTransform, prevIft1, 0.5m, -0.5m); signalsList.Add(signal); @@ -6329,19 +6328,19 @@ public static StockData CalculateEhlersInstantaneousTrendlineV2(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevIt1 = i >= 1 ? itList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevIt2 = i >= 2 ? itList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevIt1 = i >= 1 ? itList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevIt2 = i >= 2 ? itList[i - 2] : 0; decimal it = i < 7 ? (currentValue + (2 * prevValue1) + prevValue2) / 4 : ((alpha - (Pow(alpha, 2) / 4)) * currentValue) + (0.5m * Pow(alpha, 2) * prevValue1) - ((alpha - (0.75m * Pow(alpha, 2))) * prevValue2) + (2 * (1 - alpha) * prevIt1) - (Pow(1 - alpha, 2) * prevIt2); - itList.Add(it); + itList.AddRounded(it); decimal prevLag = lagList.LastOrDefault(); decimal lag = (2 * it) - prevIt2; - lagList.Add(lag); + lagList.AddRounded(lag); var signal = GetCompareSignal(lag - it, prevLag - prevIt1); signalsList.Add(signal); @@ -6375,27 +6374,27 @@ public static StockData CalculateEhlersInstantaneousTrendlineV1(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal sp = spList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevIt1 = i >= 1 ? itList.ElementAtOrDefault(i - 1) : 0; - decimal prevIt2 = i >= 2 ? itList.ElementAtOrDefault(i - 2) : 0; - decimal prevIt3 = i >= 3 ? itList.ElementAtOrDefault(i - 3) : 0; - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal sp = spList[i]; + decimal currentValue = inputList[i]; + decimal prevIt1 = i >= 1 ? itList[i - 1] : 0; + decimal prevIt2 = i >= 2 ? itList[i - 2] : 0; + decimal prevIt3 = i >= 3 ? itList[i - 3] : 0; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; int dcPeriod = (int)Math.Ceiling(sp + 0.5m); decimal iTrend = 0; for (int j = 0; j <= dcPeriod - 1; j++) { - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; iTrend += prevValue; } iTrend = dcPeriod != 0 ? iTrend / dcPeriod : iTrend; - itList.Add(iTrend); + itList.AddRounded(iTrend); decimal prevTrendLine = trendLineList.LastOrDefault(); decimal trendLine = ((4 * iTrend) + (3 * prevIt1) + (2 * prevIt2) + prevIt3) / 10; - trendLineList.Add(trendLine); + trendLineList.AddRounded(trendLine); var signal = GetCompareSignal(currentValue - trendLine, prevVal - prevTrendLine); signalsList.Add(signal); @@ -6433,34 +6432,34 @@ public static StockData CalculateEhlersLaguerreRelativeStrengthIndex(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; decimal prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; decimal prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; decimal prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; - decimal prevRsi1 = i >= 1 ? laguerreRsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsi2 = i >= 2 ? laguerreRsiList.ElementAtOrDefault(i - 2) : 0; + decimal prevRsi1 = i >= 1 ? laguerreRsiList[i - 1] : 0; + decimal prevRsi2 = i >= 2 ? laguerreRsiList[i - 2] : 0; decimal l0 = ((1 - gamma) * currentValue) + (gamma * prevL0); - l0List.Add(l0); + l0List.AddRounded(l0); decimal l1 = (-1 * gamma * l0) + prevL0 + (gamma * prevL1); - l1List.Add(l1); + l1List.AddRounded(l1); decimal l2 = (-1 * gamma * l1) + prevL1 + (gamma * prevL2); - l2List.Add(l2); + l2List.AddRounded(l2); decimal l3 = (-1 * gamma * l2) + prevL2 + (gamma * prevL3); - l3List.Add(l3); + l3List.AddRounded(l3); decimal cu = (l0 >= l1 ? l0 - l1 : 0) + (l1 >= l2 ? l1 - l2 : 0) + (l2 >= l3 ? l2 - l3 : 0); - cuList.Add(cu); + cuList.AddRounded(cu); decimal cd = (l0 >= l1 ? 0 : l1 - l0) + (l1 >= l2 ? 0 : l2 - l1) + (l2 >= l3 ? 0 : l3 - l2); - cdList.Add(cd); + cdList.AddRounded(cd); decimal laguerreRsi = cu + cd != 0 ? MinOrMax(cu / (cu + cd), 1, 0) : 0; - laguerreRsiList.Add(laguerreRsi); + laguerreRsiList.AddRounded(laguerreRsi); var signal = GetRsiSignal(laguerreRsi - prevRsi1, prevRsi1 - prevRsi2, laguerreRsi, prevRsi1, 0.8m, 0.2m); signalsList.Add(signal); @@ -6497,45 +6496,45 @@ public static StockData CalculateEhlersLaguerreRelativeStrengthIndexWithSelfAdju for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevRsi1 = i >= 1 ? laguerreRsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsi2 = i >= 2 ? laguerreRsiList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevRsi1 = i >= 1 ? laguerreRsiList[i - 1] : 0; + decimal prevRsi2 = i >= 2 ? laguerreRsiList[i - 2] : 0; decimal oc = (currentOpen + prevValue) / 2; decimal hc = Math.Max(currentHigh, prevValue); decimal lc = Math.Min(currentLow, prevValue); decimal feValue = (oc + hc + lc + currentValue) / 4; decimal ratio = highestHigh - lowestLow != 0 ? (hc - lc) / (highestHigh - lowestLow) : 0; - ratioList.Add(ratio); + ratioList.AddRounded(ratio); decimal ratioSum = ratioList.TakeLastExt(length).Sum(); decimal alpha = ratioSum > 0 ? MinOrMax(Log(ratioSum) / Log(length), 0.99m, 0.01m) : 0.01m; decimal prevL0 = l0List.LastOrDefault(); decimal l0 = (alpha * feValue) + ((1 - alpha) * prevL0); - l0List.Add(l0); + l0List.AddRounded(l0); decimal prevL1 = l1List.LastOrDefault(); decimal l1 = (-(1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); - l1List.Add(l1); + l1List.AddRounded(l1); decimal prevL2 = l2List.LastOrDefault(); decimal l2 = (-(1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); - l2List.Add(l2); + l2List.AddRounded(l2); decimal prevL3 = l3List.LastOrDefault(); decimal l3 = (-(1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); - l3List.Add(l3); + l3List.AddRounded(l3); decimal cu = (l0 >= l1 ? l0 - l1 : 0) + (l1 >= l2 ? l1 - l2 : 0) + (l2 >= l3 ? l2 - l3 : 0); decimal cd = (l0 >= l1 ? 0 : l1 - l0) + (l1 >= l2 ? 0 : l2 - l1) + (l2 >= l3 ? 0 : l3 - l2); decimal laguerreRsi = cu + cd != 0 ? MinOrMax(cu / (cu + cd), 1, 0) : 0; - laguerreRsiList.Add(laguerreRsi); + laguerreRsiList.AddRounded(laguerreRsi); var signal = GetRsiSignal(laguerreRsi - prevRsi1, prevRsi1 - prevRsi2, laguerreRsi, prevRsi1, 0.8m, 0.2m); signalsList.Add(signal); @@ -6569,25 +6568,25 @@ public static StockData CalculateEhlersAdaptiveRelativeStrengthIndexV1(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal sp = spList.ElementAtOrDefault(i); - decimal prevArsi1 = i >= 1 ? arsiEmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevArsi2 = i >= 2 ? arsiEmaList.ElementAtOrDefault(i - 2) : 0; + decimal sp = spList[i]; + decimal prevArsi1 = i >= 1 ? arsiEmaList[i - 1] : 0; + decimal prevArsi2 = i >= 2 ? arsiEmaList[i - 2] : 0; decimal cu = 0, cd = 0; for (int j = 0; j < (int)Math.Ceiling(cycPart * sp); j++) { - var price = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - var pPrice = i >= j + 1 ? inputList.ElementAtOrDefault(i - (j + 1)) : 0; + var price = i >= j ? inputList[i - j] : 0; + var pPrice = i >= j + 1 ? inputList[i - (j + 1)] : 0; cu += price - pPrice > 0 ? price - pPrice : 0; cd += price - pPrice < 0 ? pPrice - price : 0; } decimal arsi = cu + cd != 0 ? 100 * cu / (cu + cd) : 0; - arsiList.Add(arsi); + arsiList.AddRounded(arsi); decimal arsiEma = CalculateEMA(arsi, prevArsi1, (int)Math.Ceiling(sp)); - arsiEmaList.Add(arsiEma); + arsiEmaList.AddRounded(arsiEma); var signal = GetRsiSignal(arsiEma - prevArsi1, prevArsi1 - prevArsi2, arsiEma, prevArsi1, 70, 30); signalsList.Add(signal); @@ -6619,14 +6618,14 @@ public static StockData CalculateEhlersAdaptiveRsiFisherTransformV1(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal arsi = arsiList.ElementAtOrDefault(i) / 100; - decimal prevFish1 = i >= 1 ? fishList.ElementAtOrDefault(i - 1) : 0; - decimal prevFish2 = i >= 2 ? fishList.ElementAtOrDefault(i - 2) : 0; + decimal arsi = arsiList[i] / 100; + decimal prevFish1 = i >= 1 ? fishList[i - 1] : 0; + decimal prevFish2 = i >= 2 ? fishList[i - 2] : 0; decimal tranRsi = 2 * (arsi - 0.5m); decimal ampRsi = MinOrMax(1.5m * tranRsi, 0.999m, -0.999m); decimal fish = 0.5m * Log((1 + ampRsi) / (1 - ampRsi)); - fishList.Add(fish); + fishList.AddRounded(fish); var signal = GetCompareSignal(fish - prevFish1, prevFish1 - prevFish2); signalsList.Add(signal); @@ -6660,29 +6659,29 @@ public static StockData CalculateEhlersAdaptiveStochasticIndicatorV1(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal sp = spList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); - decimal close = inputList.ElementAtOrDefault(i); - decimal prevAstoc1 = i >= 1 ? astocEmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevAstoc2 = i >= 2 ? astocEmaList.ElementAtOrDefault(i - 2) : 0; + decimal sp = spList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; + decimal close = inputList[i]; + decimal prevAstoc1 = i >= 1 ? astocEmaList[i - 1] : 0; + decimal prevAstoc2 = i >= 2 ? astocEmaList[i - 2] : 0; int length = (int)Math.Ceiling(cycPart * sp); decimal hh = high, ll = low; for (int j = 0; j < length; j++) { - var h = i >= j ? highList.ElementAtOrDefault(i - j) : 0; - var l = i >= j ? lowList.ElementAtOrDefault(i - j) : 0; + var h = i >= j ? highList[i - j] : 0; + var l = i >= j ? lowList[i - j] : 0; hh = h > hh ? h : hh; ll = l < ll ? l : ll; } decimal astoc = hh - ll != 0 ? 100 * (close - ll) / (hh - ll) : 0; - astocList.Add(astoc); + astocList.AddRounded(astoc); decimal astocEma = CalculateEMA(astoc, prevAstoc1, length); - astocEmaList.Add(astocEma); + astocEmaList.AddRounded(astocEma); var signal = GetRsiSignal(astocEma - prevAstoc1, prevAstoc1 - prevAstoc2, astocEma, prevAstoc1, 70, 30); signalsList.Add(signal); @@ -6720,16 +6719,16 @@ public static StockData CalculateEhlersAdaptiveCommodityChannelIndexV1(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal sp = spList.ElementAtOrDefault(i); - decimal prevAcci1 = i >= 1 ? acciEmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevAcci2 = i >= 2 ? acciEmaList.ElementAtOrDefault(i - 2) : 0; - decimal tp = inputList.ElementAtOrDefault(i); + decimal sp = spList[i]; + decimal prevAcci1 = i >= 1 ? acciEmaList[i - 1] : 0; + decimal prevAcci2 = i >= 2 ? acciEmaList[i - 2] : 0; + decimal tp = inputList[i]; int length = (int)Math.Ceiling(cycPart * sp); decimal avg = 0; for (int j = 0; j < length; j++) { - decimal prevMp = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevMp = i >= j ? inputList[i - j] : 0; avg += prevMp; } avg /= length; @@ -6737,16 +6736,16 @@ public static StockData CalculateEhlersAdaptiveCommodityChannelIndexV1(this Stoc decimal md = 0; for (int j = 0; j < length; j++) { - decimal prevMp = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevMp = i >= j ? inputList[i - j] : 0; md += Math.Abs(prevMp - avg); } md /= length; decimal acci = md != 0 ? (tp - avg) / (constant * md) : 0; - acciList.Add(acci); + acciList.AddRounded(acci); decimal acciEma = CalculateEMA(acci, prevAcci1, (int)Math.Ceiling(sp)); - acciEmaList.Add(acciEma); + acciEmaList.AddRounded(acciEma); var signal = GetRsiSignal(acciEma - prevAcci1, prevAcci1 - prevAcci2, acciEma, prevAcci1, 100, -100); signalsList.Add(signal); @@ -6785,22 +6784,22 @@ public static StockData CalculateEhlersCommodityChannelIndexInverseFisherTransfo for (int i = 0; i < stockData.Count; i++) { - decimal cci = cciList.ElementAtOrDefault(i); + decimal cci = cciList[i]; decimal v1 = 0.1m * (cci - 50); - v1List.Add(v1); + v1List.AddRounded(v1); } var v2List = GetMovingAverageList(stockData, maType, signalLength, v1List); for (int i = 0; i < stockData.Count; i++) { - decimal v2 = v2List.ElementAtOrDefault(i); + decimal v2 = v2List[i]; decimal expValue = Exp(2 * v2); - decimal prevIFish1 = i >= 1 ? iFishList.ElementAtOrDefault(i - 1) : 0; - decimal prevIFish2 = i >= 2 ? iFishList.ElementAtOrDefault(i - 2) : 0; + decimal prevIFish1 = i >= 1 ? iFishList[i - 1] : 0; + decimal prevIFish2 = i >= 2 ? iFishList[i - 2] : 0; decimal iFish = expValue + 1 != 0 ? (expValue - 1) / (expValue + 1) : 0; - iFishList.Add(iFish); + iFishList.AddRounded(iFish); var signal = GetRsiSignal(iFish - prevIFish1, prevIFish1 - prevIFish2, iFish, prevIFish1, 0.5m, -0.5m); signalsList.Add(signal); @@ -6836,22 +6835,22 @@ public static StockData CalculateEhlersRelativeStrengthIndexInverseFisherTransfo for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; decimal v1 = 0.1m * (rsi - 50); - v1List.Add(v1); + v1List.AddRounded(v1); } var v2List = GetMovingAverageList(stockData, maType, signalLength, v1List); for (int i = 0; i < stockData.Count; i++) { - decimal v2 = v2List.ElementAtOrDefault(i); + decimal v2 = v2List[i]; decimal expValue = Exp(2 * v2); - decimal prevIfish1 = i >= 1 ? iFishList.ElementAtOrDefault(i - 1) : 0; - decimal prevIfish2 = i >= 2 ? iFishList.ElementAtOrDefault(i - 2) : 0; + decimal prevIfish1 = i >= 1 ? iFishList[i - 1] : 0; + decimal prevIfish2 = i >= 2 ? iFishList[i - 2] : 0; decimal iFish = expValue + 1 != 0 ? MinOrMax((expValue - 1) / (expValue + 1), 1, -1) : 0; - iFishList.Add(iFish); + iFishList.AddRounded(iFish); var signal = GetRsiSignal(iFish - prevIfish1, prevIfish1 - prevIfish2, iFish, prevIfish1, 0.5m, -0.5m); signalsList.Add(signal); diff --git a/Calculations/Inputs.cs b/Calculations/Inputs.cs index 4a32342..69dcd33 100644 --- a/Calculations/Inputs.cs +++ b/Calculations/Inputs.cs @@ -15,11 +15,11 @@ public static StockData CalculateTypicalPrice(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevTypicalPrice1 = i >= 1 ? tpList.ElementAtOrDefault(i - 1) : 0; - decimal prevTypicalPrice2 = i >= 2 ? tpList.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal prevTypicalPrice1 = i >= 1 ? tpList[i - 1] : 0; + decimal prevTypicalPrice2 = i >= 2 ? tpList[i - 2] : 0; decimal typicalPrice = (currentHigh + currentLow + currentClose) / 3; tpList.AddRounded(typicalPrice); @@ -52,10 +52,10 @@ public static StockData CalculateMedianPrice(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal prevMedianPrice1 = i >= 1 ? medianPriceList.ElementAtOrDefault(i - 1) : 0; - decimal prevMedianPrice2 = i >= 2 ? medianPriceList.ElementAtOrDefault(i - 2) : 0; + decimal currentLow = lowList[i]; + decimal currentHigh = highList[i]; + decimal prevMedianPrice1 = i >= 1 ? medianPriceList[i - 1] : 0; + decimal prevMedianPrice2 = i >= 2 ? medianPriceList[i - 2] : 0; decimal medianPrice = (currentHigh + currentLow) / 2; medianPriceList.AddRounded(medianPrice); @@ -88,12 +88,12 @@ public static StockData CalculateFullTypicalPrice(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevTypicalPrice1 = i >= 1 ? fullTpList.ElementAtOrDefault(i - 1) : 0; - decimal prevTypicalPrice2 = i >= 2 ? fullTpList.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal prevTypicalPrice1 = i >= 1 ? fullTpList[i - 1] : 0; + decimal prevTypicalPrice2 = i >= 2 ? fullTpList[i - 2] : 0; decimal typicalPrice = (currentHigh + currentLow + currentClose + currentOpen) / 4; fullTpList.AddRounded(typicalPrice); @@ -126,10 +126,10 @@ public static StockData CalculateWeightedClose(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal prevWeightedClose = weightedCloseList.LastOrDefault(); decimal weightedClose = (currentHigh + currentLow + (currentClose * 2)) / 4; @@ -165,14 +165,14 @@ public static StockData CalculateMidpoint(this StockData stockData, int length = for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal prevMidPoint = midpointList.LastOrDefault(); decimal midpoint = (highest + lowest) / 2; - midpointList.Add(midpoint); + midpointList.AddRounded(midpoint); var signal = GetCompareSignal(currentValue - midpoint, prevValue - prevMidPoint); signalsList.Add(signal); @@ -204,14 +204,14 @@ public static StockData CalculateMidprice(this StockData stockData, int length = for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal prevMidPrice = midpriceList.LastOrDefault(); decimal midPrice = (highest + lowest) / 2; - midpriceList.Add(midPrice); + midpriceList.AddRounded(midPrice); var signal = GetCompareSignal(currentValue - midPrice, prevValue - prevMidPrice); signalsList.Add(signal); diff --git a/Calculations/Macd.cs b/Calculations/Macd.cs index 4ba7e8d..83cbd0d 100644 --- a/Calculations/Macd.cs +++ b/Calculations/Macd.cs @@ -24,8 +24,8 @@ public static StockData CalculateMovingAverageConvergenceDivergence(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal fastEma = fastEmaList.ElementAtOrDefault(i); - decimal slowEma = slowEmaList.ElementAtOrDefault(i); + decimal fastEma = fastEmaList[i]; + decimal slowEma = slowEmaList[i]; decimal macd = fastEma - slowEma; macdList.AddRounded(macd); @@ -34,8 +34,8 @@ public static StockData CalculateMovingAverageConvergenceDivergence(this StockDa var macdSignalLineList = GetMovingAverageList(stockData, movingAvgType, signalLength, macdList); for (int i = 0; i < stockData.Count; i++) { - decimal macd = macdList.ElementAtOrDefault(i); - decimal macdSignalLine = macdSignalLineList.ElementAtOrDefault(i); + decimal macd = macdList[i]; + decimal macdSignalLine = macdSignalLineList[i]; decimal prevMacdHistogram = macdHistogramList.LastOrDefault(); decimal macdHistogram = macd - macdSignalLine; @@ -94,24 +94,24 @@ public static StockData Calculate4MovingAverageConvergenceDivergence(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal ema5 = ema5List.ElementAtOrDefault(i); - decimal ema8 = ema8List.ElementAtOrDefault(i); - decimal ema10 = ema10List.ElementAtOrDefault(i); - decimal ema14 = ema14List.ElementAtOrDefault(i); - decimal ema16 = ema16List.ElementAtOrDefault(i); - decimal ema17 = ema17List.ElementAtOrDefault(i); + decimal ema5 = ema5List[i]; + decimal ema8 = ema8List[i]; + decimal ema10 = ema10List[i]; + decimal ema14 = ema14List[i]; + decimal ema16 = ema16List[i]; + decimal ema17 = ema17List[i]; decimal macd1 = ema17 - ema14; - macd1List.Add(macd1); + macd1List.AddRounded(macd1); decimal macd2 = ema17 - ema8; - macd2List.Add(macd2); + macd2List.AddRounded(macd2); decimal macd3 = ema10 - ema16; - macd3List.Add(macd3); + macd3List.AddRounded(macd3); decimal macd4 = ema5 - ema10; - macd4List.Add(macd4); + macd4List.AddRounded(macd4); } var macd1SignalLineList = GetMovingAverageList(stockData, maType, length1, macd1List); @@ -120,27 +120,27 @@ public static StockData Calculate4MovingAverageConvergenceDivergence(this StockD var macd4SignalLineList = GetMovingAverageList(stockData, maType, length1, macd4List); for (int i = 0; i < stockData.Count; i++) { - decimal macd1 = macd1List.ElementAtOrDefault(i); - decimal macd1SignalLine = macd1SignalLineList.ElementAtOrDefault(i); - decimal macd2 = macd2List.ElementAtOrDefault(i); - decimal macd2SignalLine = macd2SignalLineList.ElementAtOrDefault(i); - decimal macd3 = macd3List.ElementAtOrDefault(i); - decimal macd3SignalLine = macd3SignalLineList.ElementAtOrDefault(i); - decimal macd4 = macd4List.ElementAtOrDefault(i); - decimal macd4SignalLine = macd4SignalLineList.ElementAtOrDefault(i); + decimal macd1 = macd1List[i]; + decimal macd1SignalLine = macd1SignalLineList[i]; + decimal macd2 = macd2List[i]; + decimal macd2SignalLine = macd2SignalLineList[i]; + decimal macd3 = macd3List[i]; + decimal macd3SignalLine = macd3SignalLineList[i]; + decimal macd4 = macd4List[i]; + decimal macd4SignalLine = macd4SignalLineList[i]; decimal macd1Histogram = macd1 - macd1SignalLine; decimal macdBlue = blueMult * macd1Histogram; decimal prevMacd2Histogram = macd2HistogramList.LastOrDefault(); decimal macd2Histogram = macd2 - macd2SignalLine; - macd2HistogramList.Add(macd2Histogram); + macd2HistogramList.AddRounded(macd2Histogram); decimal macd3Histogram = macd3 - macd3SignalLine; decimal macdYellow = yellowMult * macd3Histogram; decimal prevMacd4Histogram = macd4HistogramList.LastOrDefault(); decimal macd4Histogram = macd4 - macd4SignalLine; - macd4HistogramList.Add(macd4Histogram); + macd4HistogramList.AddRounded(macd4Histogram); var signal = GetCompareSignal(macd4Histogram - macd2Histogram, prevMacd4Histogram - prevMacd2Histogram); signalsList.Add(signal); @@ -186,19 +186,19 @@ public static StockData CalculateImpulseMovingAverageConvergenceDivergence(this for (int i = 0; i < stockData.Count; i++) { - decimal hi = wellesWilderHighMovingAvgList.ElementAtOrDefault(i); - decimal lo = wellesWilderLowMovingAvgList.ElementAtOrDefault(i); - decimal mi = typicalPriceZeroLagEmaList.ElementAtOrDefault(i); + decimal hi = wellesWilderHighMovingAvgList[i]; + decimal lo = wellesWilderLowMovingAvgList[i]; + decimal mi = typicalPriceZeroLagEmaList[i]; decimal macd = mi > hi ? mi - hi : mi < lo ? mi - lo : 0; - macdList.Add(macd); + macdList.AddRounded(macd); decimal macdSignalLine = macdList.TakeLastExt(signalLength).Average(); - macdSignalLineList.Add(macdSignalLine); + macdSignalLineList.AddRounded(macdSignalLine); decimal prevMacdHistogram = macdHistogramList.LastOrDefault(); decimal macdHistogram = macd - macdSignalLine; - macdHistogramList.Add(macdHistogram); + macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); signalsList.Add(signal); @@ -237,12 +237,12 @@ public static StockData CalculateKaseConvergenceDivergence(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal pk = pkList.ElementAtOrDefault(i); - decimal pkSma = pkSignalList.ElementAtOrDefault(i); + decimal pk = pkList[i]; + decimal pkSma = pkSignalList[i]; decimal prevKcd = kcdList.LastOrDefault(); decimal kcd = pk - pkSma; - kcdList.Add(kcd); + kcdList.AddRounded(kcd); var signal = GetCompareSignal(kcd, prevKcd); signalsList.Add(signal); @@ -285,45 +285,45 @@ public static StockData CalculateMovingAverageConvergenceDivergenceLeader(this S for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema12 = emaList.ElementAtOrDefault(i); - decimal ema26 = ema26List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal ema12 = emaList[i]; + decimal ema26 = ema26List[i]; decimal diff12 = currentValue - ema12; - diff12List.Add(diff12); + diff12List.AddRounded(diff12); decimal diff26 = currentValue - ema26; - diff26List.Add(diff26); + 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++) { - decimal ema12 = emaList.ElementAtOrDefault(i); - decimal ema26 = ema26List.ElementAtOrDefault(i); - decimal diff12Ema = diff12EmaList.ElementAtOrDefault(i); - decimal diff26Ema = diff26EmaList.ElementAtOrDefault(i); + decimal ema12 = emaList[i]; + decimal ema26 = ema26List[i]; + decimal diff12Ema = diff12EmaList[i]; + decimal diff26Ema = diff26EmaList[i]; decimal i1 = ema12 + diff12Ema; - i1List.Add(i1); + i1List.AddRounded(i1); decimal i2 = ema26 + diff26Ema; - i2List.Add(i2); + i2List.AddRounded(i2); decimal macd = i1 - i2; - macdList.Add(macd); + macdList.AddRounded(macd); } var macdSignalLineList = GetMovingAverageList(stockData, maType, signalLength, macdList); for (int i = 0; i < stockData.Count; i++) { - decimal macd = macdList.ElementAtOrDefault(i); - decimal macdSignalLine = macdSignalLineList.ElementAtOrDefault(i); + decimal macd = macdList[i]; + decimal macdSignalLine = macdSignalLineList[i]; decimal prevMacdHistogram = macdHistogramList.LastOrDefault(); decimal macdHistogram = macd - macdSignalLine; - macdHistogramList.Add(macdHistogram); + macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); signalsList.Add(signal); @@ -364,22 +364,22 @@ public static StockData CalculateTFSMboIndicator(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal mob1 = mob1List.ElementAtOrDefault(i); - decimal mob2 = mob2List.ElementAtOrDefault(i); + decimal mob1 = mob1List[i]; + decimal mob2 = mob2List[i]; decimal tfsMob = mob1 - mob2; - tfsMobList.Add(tfsMob); + tfsMobList.AddRounded(tfsMob); } var tfsMobSignalLineList = GetMovingAverageList(stockData, maType, signalLength, tfsMobList); for (int i = 0; i < stockData.Count; i++) { - decimal tfsMob = tfsMobList.ElementAtOrDefault(i); - decimal tfsMobSignalLine = tfsMobSignalLineList.ElementAtOrDefault(i); + decimal tfsMob = tfsMobList[i]; + decimal tfsMobSignalLine = tfsMobSignalLineList[i]; decimal prevTfsMobHistogram = tfsMobHistogramList.LastOrDefault(); decimal tfsMobHistogram = tfsMob - tfsMobSignalLine; - tfsMobHistogramList.Add(tfsMobHistogram); + tfsMobHistogramList.AddRounded(tfsMobHistogram); var signal = GetCompareSignal(tfsMobHistogram, prevTfsMobHistogram); signalsList.Add(signal); @@ -430,44 +430,44 @@ public static StockData CalculateMacZVwapIndicator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal stdev = stdDevList.ElementAtOrDefault(i); - decimal fastMa = fastSmaList.ElementAtOrDefault(i); - decimal slowMa = slowSmaList.ElementAtOrDefault(i); - decimal zscore = zScoreList.ElementAtOrDefault(i); + decimal stdev = stdDevList[i]; + decimal fastMa = fastSmaList[i]; + decimal slowMa = slowSmaList[i]; + decimal zscore = zScoreList[i]; decimal macd = fastMa - slowMa; decimal maczt = stdev != 0 ? zscore + (macd / stdev) : zscore; - macztList.Add(maczt); + macztList.AddRounded(maczt); decimal prevL0 = i >= 1 ? l0List.LastOrDefault() : maczt; decimal l0 = ((1 - gamma) * maczt) + (gamma * prevL0); - l0List.Add(l0); + l0List.AddRounded(l0); decimal prevL1 = i >= 1 ? l1List.LastOrDefault() : maczt; decimal l1 = (-1 * gamma * l0) + prevL0 + (gamma * prevL1); - l1List.Add(l1); + l1List.AddRounded(l1); decimal prevL2 = i >= 1 ? l2List.LastOrDefault() : maczt; decimal l2 = (-1 * gamma * l1) + prevL1 + (gamma * prevL2); - l2List.Add(l2); + l2List.AddRounded(l2); decimal prevL3 = i >= 1 ? l3List.LastOrDefault() : maczt; decimal l3 = (-1 * gamma * l2) + prevL2 + (gamma * prevL3); - l3List.Add(l3); + l3List.AddRounded(l3); decimal macz = (l0 + (2 * l1) + (2 * l2) + l3) / 6; - maczList.Add(macz); + maczList.AddRounded(macz); } var maczSignalList = GetMovingAverageList(stockData, maType, signalLength, maczList); for (int i = 0; i < stockData.Count; i++) { - decimal macz = maczList.ElementAtOrDefault(i); - decimal maczSignal = maczSignalList.ElementAtOrDefault(i); + decimal macz = maczList[i]; + decimal maczSignal = maczSignalList[i]; decimal prevHist = histList.LastOrDefault(); decimal hist = macz - maczSignal; - histList.Add(hist); + histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); signalsList.Add(signal); @@ -513,27 +513,27 @@ public static StockData CalculateMacZIndicator(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal stdev = stdDevList.ElementAtOrDefault(i); - decimal wima = wilderMovingAvgList.ElementAtOrDefault(i); - decimal fastMa = fastSmaList.ElementAtOrDefault(i); - decimal slowMa = slowSmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal stdev = stdDevList[i]; + decimal wima = wilderMovingAvgList[i]; + decimal fastMa = fastSmaList[i]; + decimal slowMa = slowSmaList[i]; decimal zscore = stdev != 0 ? (currentValue - wima) / stdev : 0; decimal macd = fastMa - slowMa; decimal macz = stdev != 0 ? (zscore * mult) + (mult * macd / stdev) : zscore; - maczList.Add(macz); + maczList.AddRounded(macz); } var maczSignalList = GetMovingAverageList(stockData, maType, signalLength, maczList); for (int i = 0; i < stockData.Count; i++) { - decimal macz = maczList.ElementAtOrDefault(i); - decimal maczSignal = maczSignalList.ElementAtOrDefault(i); + decimal macz = maczList[i]; + decimal maczSignal = maczSignalList[i]; decimal prevHist = histList.LastOrDefault(); decimal hist = macz - maczSignal; - histList.Add(hist); + histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); signalsList.Add(signal); @@ -575,31 +575,31 @@ public static StockData CalculateMirroredMovingAverageConvergenceDivergence(this for (int i = 0; i < stockData.Count; i++) { - decimal mao = emaOpenList.ElementAtOrDefault(i); - decimal mac = emaCloseList.ElementAtOrDefault(i); + decimal mao = emaOpenList[i]; + decimal mac = emaCloseList[i]; decimal macd = mac - mao; - macdList.Add(macd); + macdList.AddRounded(macd); decimal macdMirror = mao - mac; - macdMirrorList.Add(macdMirror); + 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++) { - decimal macd = macdList.ElementAtOrDefault(i); - decimal macdMirror = macdMirrorList.ElementAtOrDefault(i); - decimal macdSignalLine = macdSignalLineList.ElementAtOrDefault(i); - decimal macdMirrorSignalLine = macdMirrorSignalLineList.ElementAtOrDefault(i); + decimal macd = macdList[i]; + decimal macdMirror = macdMirrorList[i]; + decimal macdSignalLine = macdSignalLineList[i]; + decimal macdMirrorSignalLine = macdMirrorSignalLineList[i]; decimal prevMacdHistogram = macdHistogramList.LastOrDefault(); decimal macdHistogram = macd - macdSignalLine; - macdHistogramList.Add(macdHistogram); + macdHistogramList.AddRounded(macdHistogram); decimal macdMirrorHistogram = macdMirror - macdMirrorSignalLine; - macdMirrorHistogramList.Add(macdMirrorHistogram); + macdMirrorHistogramList.AddRounded(macdMirrorHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); signalsList.Add(signal); @@ -646,26 +646,26 @@ public static StockData CalculateDiNapoliMovingAverageConvergenceDivergence(this for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevFs = fsList.LastOrDefault(); decimal fs = prevFs + (scAlpha * (currentValue - prevFs)); - fsList.Add(fs); + fsList.AddRounded(fs); decimal prevSs = ssList.LastOrDefault(); decimal ss = prevSs + (lcAlpha * (currentValue - prevSs)); - ssList.Add(ss); + ssList.AddRounded(ss); decimal r = fs - ss; - rList.Add(r); + rList.AddRounded(r); decimal prevS = sList.LastOrDefault(); decimal s = prevS + (spAlpha * (r - prevS)); - sList.Add(s); + sList.AddRounded(s); decimal prevH = hList.LastOrDefault(); decimal h = r - s; - hList.Add(h); + hList.AddRounded(h); var signal = GetCompareSignal(h, prevH); signalsList.Add(signal); @@ -712,31 +712,31 @@ public static StockData CalculateStochasticMovingAverageConvergenceDivergenceOsc for (int i = 0; i < stockData.Count; i++) { - decimal fastEma = fastEmaList.ElementAtOrDefault(i); - decimal slowEma = slowEmaList.ElementAtOrDefault(i); - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); + decimal fastEma = fastEmaList[i]; + decimal slowEma = slowEmaList[i]; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; decimal range = hh - ll; decimal fastStochastic = range != 0 ? (fastEma - ll) / range : 0; - fastStochasticList.Add(fastStochastic); + fastStochasticList.AddRounded(fastStochastic); decimal slowStochastic = range != 0 ? (slowEma - ll) / range : 0; - slowStochasticList.Add(slowStochastic); + slowStochasticList.AddRounded(slowStochastic); decimal macdStochastic = 10 * (fastStochastic - slowStochastic); - macdStochasticList.Add(macdStochastic); + macdStochasticList.AddRounded(macdStochastic); } var macdStochasticSignalLineList = GetMovingAverageList(stockData, maType, signalLength, macdStochasticList); for (int i = 0; i < stockData.Count; i++) { - decimal macdStochastic = macdStochasticList.ElementAtOrDefault(i); - decimal macdStochasticSignalLine = macdStochasticSignalLineList.ElementAtOrDefault(i); + decimal macdStochastic = macdStochasticList[i]; + decimal macdStochasticSignalLine = macdStochasticSignalLineList[i]; decimal prevMacdHistogram = macdStochasticHistogramList.LastOrDefault(); decimal macdHistogram = macdStochastic - macdStochasticSignalLine; - macdStochasticHistogramList.Add(macdHistogram); + macdStochasticHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); signalsList.Add(signal); @@ -777,22 +777,22 @@ public static StockData CalculateErgodicMovingAverageConvergenceDivergence(this for (int i = 0; i < stockData.Count; i++) { - decimal ema1 = period1EmaList.ElementAtOrDefault(i); - decimal ema2 = period2EmaList.ElementAtOrDefault(i); + decimal ema1 = period1EmaList[i]; + decimal ema2 = period2EmaList[i]; decimal macd = ema1 - ema2; - macdList.Add(macd); + macdList.AddRounded(macd); } var macdSignalLineList = GetMovingAverageList(stockData, maType, length3, macdList); for (int i = 0; i < stockData.Count; i++) { - decimal macd = macdList.ElementAtOrDefault(i); - decimal macdSignalLine = macdSignalLineList.ElementAtOrDefault(i); + decimal macd = macdList[i]; + decimal macdSignalLine = macdSignalLineList[i]; decimal prevMacdHistogram = macdHistogramList.LastOrDefault(); decimal macdHistogram = macd - macdSignalLine; - macdHistogramList.Add(macdHistogram); + macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); signalsList.Add(signal); diff --git a/Calculations/Momentum.cs b/Calculations/Momentum.cs index 77ae21b..1ca4a51 100644 --- a/Calculations/Momentum.cs +++ b/Calculations/Momentum.cs @@ -24,22 +24,22 @@ public static StockData CalculateDynamicMomentumOscillator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal smaVal = smaValList.ElementAtOrDefault(i); - decimal stochSma = stochSmaList.ElementAtOrDefault(i); - decimal prevDmo1 = i >= 1 ? dmoList.ElementAtOrDefault(i - 1) : 0; - decimal prevDmo2 = i >= 2 ? dmoList.ElementAtOrDefault(i - 2) : 0; + decimal smaVal = smaValList[i]; + decimal stochSma = stochSmaList[i]; + decimal prevDmo1 = i >= 1 ? dmoList[i - 1] : 0; + decimal prevDmo2 = i >= 2 ? dmoList[i - 2] : 0; decimal prevHighest = highestList.LastOrDefault(); decimal highest = stochSma > prevHighest ? stochSma : prevHighest; - highestList.Add(highest); + highestList.AddRounded(highest); decimal prevLowest = i >= 1 ? lowestList.LastOrDefault() : decimal.MaxValue; decimal lowest = stochSma < prevLowest ? stochSma : prevLowest; - lowestList.Add(lowest); + lowestList.AddRounded(lowest); decimal midpoint = MinOrMax((lowest + highest) / 2, 100, 0); decimal dmo = MinOrMax(midpoint - (smaVal - stochSma), 100, 0); - dmoList.Add(dmo); + dmoList.AddRounded(dmo); var signal = GetRsiSignal(dmo - prevDmo1, prevDmo1 - prevDmo2, dmo, prevDmo1, 77, 23); signalsList.Add(signal); @@ -78,8 +78,8 @@ public static StockData CalculatePriceMomentumOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal roc = prevValue != 0 ? (currentValue - prevValue) / prevValue * 100 : 0; decimal prevRocMa1 = rocMaList.LastOrDefault(); @@ -88,16 +88,16 @@ public static StockData CalculatePriceMomentumOscillator(this StockData stockDat decimal prevPmo = pmoList.LastOrDefault(); decimal pmo = prevPmo + (((rocMa * 10) - prevPmo) * sc2); - pmoList.Add(pmo); + pmoList.AddRounded(pmo); } var pmoSignalList = GetMovingAverageList(stockData, maType, signalLength, pmoList); for (int i = 0; i < stockData.Count; i++) { - decimal pmo = pmoList.ElementAtOrDefault(i); - decimal prevPmo = i >= 1 ? pmoList.ElementAtOrDefault(i - 1) : 0; - decimal pmoSignal = pmoSignalList.ElementAtOrDefault(i); - decimal prevPmoSignal = i >= 1 ? pmoSignalList.ElementAtOrDefault(i - 1) : 0; + decimal pmo = pmoList[i]; + decimal prevPmo = i >= 1 ? pmoList[i - 1] : 0; + decimal pmoSignal = pmoSignalList[i]; + decimal prevPmoSignal = i >= 1 ? pmoSignalList[i - 1] : 0; var signal = GetCompareSignal(pmo - pmoSignal, prevPmo - prevPmoSignal); signalsList.Add(signal); @@ -139,19 +139,19 @@ public static StockData CalculateAnchoredMomentum(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentEma = emaList.ElementAtOrDefault(i); + decimal currentEma = emaList[i]; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal sma = tempList.TakeLastExt(p).Average(); decimal prevAmom = amomList.LastOrDefault(); decimal amom = sma != 0 ? 100 * ((currentEma / sma) - 1) : 0; - amomList.Add(amom); + amomList.AddRounded(amom); decimal prevAmoms = amomsList.LastOrDefault(); decimal amoms = amomList.TakeLastExt(signalLength).Average(); - amomsList.Add(amoms); + amomsList.AddRounded(amoms); var signal = GetCompareSignal(amom - amoms, prevAmom - prevAmoms); signalsList.Add(signal); @@ -201,17 +201,17 @@ public static StockData CalculateUltimateMomentumIndicator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal mo = moList.ElementAtOrDefault(i); - decimal bbPct = bbPctList.ElementAtOrDefault(i); - decimal mfi1 = mfi1List.ElementAtOrDefault(i); - decimal mfi2 = mfi2List.ElementAtOrDefault(i); - decimal mfi3 = mfi3List.ElementAtOrDefault(i); - decimal advSum = advSumList.ElementAtOrDefault(i); - decimal decSum = decSumList.ElementAtOrDefault(i); + decimal mo = moList[i]; + decimal bbPct = bbPctList[i]; + decimal mfi1 = mfi1List[i]; + decimal mfi2 = mfi2List[i]; + decimal mfi3 = mfi3List[i]; + decimal advSum = advSumList[i]; + decimal decSum = decSumList[i]; decimal ratio = decSum != 0 ? advSum / decSum : 0; decimal utm = (200 * bbPct) + (100 * ratio) + (2 * mo) + (1.5m * mfi3) + (3 * mfi2) + (3 * mfi1); - utmList.Add(utm); + utmList.AddRounded(utm); } stockData.CustomValuesList = utmList; @@ -219,9 +219,9 @@ public static StockData CalculateUltimateMomentumIndicator(this StockData stockD var utmiList = GetMovingAverageList(stockData, maType, length1, utmRsiList); for (int i = 0; i < stockData.Count; i++) { - decimal utmi = utmiList.ElementAtOrDefault(i); - decimal prevUtmi1 = i >= 1 ? utmiList.ElementAtOrDefault(i - 1) : 0; - decimal prevUtmi2 = i >= 2 ? utmiList.ElementAtOrDefault(i - 2) : 0; + decimal utmi = utmiList[i]; + decimal prevUtmi1 = i >= 1 ? utmiList[i - 1] : 0; + decimal prevUtmi2 = i >= 2 ? utmiList[i - 2] : 0; var signal = GetCompareSignal(utmi - prevUtmi1, prevUtmi1 - prevUtmi2); signalsList.Add(signal); @@ -261,12 +261,12 @@ public static StockData CalculateComparePriceMomentumOscillator(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal pmo = pmoList.ElementAtOrDefault(i); - decimal spPmo = spPmoList.ElementAtOrDefault(i); + decimal pmo = pmoList[i]; + decimal spPmo = spPmoList[i]; decimal prevCpmo = cpmoList.LastOrDefault(); decimal cpmo = pmo - spPmo; - cpmoList.Add(cpmo); + cpmoList.AddRounded(cpmo); var signal = GetCompareSignal(cpmo, prevCpmo); signalsList.Add(signal); @@ -304,14 +304,14 @@ public static StockData CalculateTickLineMomentumOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevMa = i >= 1 ? maList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevMa = i >= 1 ? maList[i - 1] : 0; decimal cumo = currentValue > prevMa ? 1 : currentValue < prevMa ? -1 : 0; - cumoList.Add(cumo); + cumoList.AddRounded(cumo); decimal cumoSum = cumoList.Sum(); - cumoSumList.Add(cumoSum); + cumoSumList.AddRounded(cumoSum); } stockData.CustomValuesList = cumoSumList; @@ -319,9 +319,9 @@ public static StockData CalculateTickLineMomentumOscillator(this StockData stock var tlmoList = GetMovingAverageList(stockData, maType, smoothLength, rocList); for (int i = 0; i < stockData.Count; i++) { - decimal tlmo = tlmoList.ElementAtOrDefault(i); - decimal prevTlmo1 = i >= 1 ? tlmoList.ElementAtOrDefault(i - 1) : 0; - decimal prevTlmo2 = i >= 2 ? tlmoList.ElementAtOrDefault(i - 2) : 0; + decimal tlmo = tlmoList[i]; + decimal prevTlmo1 = i >= 1 ? tlmoList[i - 1] : 0; + decimal prevTlmo2 = i >= 2 ? tlmoList[i - 2] : 0; var signal = GetRsiSignal(tlmo - prevTlmo1, prevTlmo1 - prevTlmo2, tlmo, prevTlmo1, 5, -5); signalsList.Add(signal); @@ -354,18 +354,18 @@ public static StockData CalculateMomentumOscillator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal prevPrice = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentPrice = inputList[i]; + decimal prevPrice = i >= length ? inputList[i - length] : 0; decimal momentumOscillator = prevPrice != 0 ? currentPrice / prevPrice * 100 : 0; - momentumOscillatorList.Add(momentumOscillator); + momentumOscillatorList.AddRounded(momentumOscillator); } var emaList = GetMovingAverageList(stockData, maType, length, momentumOscillatorList); for (int i = 0; i < stockData.Count; i++) { - decimal momentum = emaList.ElementAtOrDefault(i); - decimal prevMomentum = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal momentum = emaList[i]; + decimal prevMomentum = i >= 1 ? emaList[i - 1] : 0; var signal = GetCompareSignal(momentum, prevMomentum); signalsList.Add(signal); @@ -403,39 +403,39 @@ public static StockData CalculateRelativeMomentumIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length2 ? inputList.ElementAtOrDefault(i - length2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length2 ? inputList[i - length2] : 0; decimal priceChg = currentValue - prevValue; decimal loss = priceChg < 0 ? Math.Abs(priceChg) : 0; - lossList.Add(loss); + lossList.AddRounded(loss); decimal gain = priceChg > 0 ? priceChg : 0; - gainList.Add(gain); + 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++) { - decimal avgGain = avgGainList.ElementAtOrDefault(i); - decimal avgLoss = avgLossList.ElementAtOrDefault(i); + decimal avgGain = avgGainList[i]; + decimal avgLoss = avgLossList[i]; decimal rs = avgLoss != 0 ? avgGain / avgLoss : 0; decimal rsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); - rsiList.Add(rsi); + rsiList.AddRounded(rsi); } var rsiSignalList = GetMovingAverageList(stockData, maType, length1, rsiList); for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal rsiSignal = rsiSignalList.ElementAtOrDefault(i); - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; + decimal rsi = rsiList[i]; + decimal rsiSignal = rsiSignalList[i]; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; decimal prevRsiHistogram = rsiHistogramList.LastOrDefault(); decimal rsiHistogram = rsi - rsiSignal; - rsiHistogramList.Add(rsiHistogram); + rsiHistogramList.AddRounded(rsiHistogram); var signal = GetRsiSignal(rsiHistogram, prevRsiHistogram, rsi, prevRsi, 70, 30); signalsList.Add(signal); @@ -477,28 +477,28 @@ public static StockData CalculateDecisionPointPriceMomentumOscillator(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ival = prevValue != 0 ? currentValue / prevValue * 100 : 100; decimal prevPmol = pmolList.LastOrDefault(); decimal prevPmol2 = pmol2List.LastOrDefault(); decimal pmol2 = ((ival - 100 - prevPmol2) * smPmol2) + prevPmol2; - pmol2List.Add(pmol2); + pmol2List.AddRounded(pmol2); decimal pmol = (((10 * pmol2) - prevPmol) * smPmol) + prevPmol; - pmolList.Add(pmol); + pmolList.AddRounded(pmol); } var pmolsList = GetMovingAverageList(stockData, maType, signalLength, pmolList); for (int i = 0; i < stockData.Count; i++) { - decimal pmol = pmolList.ElementAtOrDefault(i); - decimal pmols = pmolsList.ElementAtOrDefault(i); + decimal pmol = pmolList[i]; + decimal pmols = pmolsList[i]; decimal prevD = dList.LastOrDefault(); decimal d = pmol - pmols; - dList.Add(d); + dList.AddRounded(d); var signal = GetCompareSignal(d, prevD); signalsList.Add(signal); @@ -544,9 +544,9 @@ public static StockData CalculateDynamicMomentumIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal asd = stdDeviationSmaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal asd = stdDeviationSmaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; int dTime; try @@ -562,10 +562,10 @@ public static StockData CalculateDynamicMomentumIndex(this StockData stockData, decimal priceChg = currentValue - prevValue; decimal loss = priceChg < 0 ? Math.Abs(priceChg) : 0; - lossList.Add(loss); + lossList.AddRounded(loss); decimal gain = priceChg > 0 ? priceChg : 0; - gainList.Add(gain); + gainList.AddRounded(gain); decimal avgGainSma = gainList.TakeLastExt(dmiLength).Average(); decimal avgLossSma = lossList.TakeLastExt(dmiLength).Average(); @@ -573,14 +573,14 @@ public static StockData CalculateDynamicMomentumIndex(this StockData stockData, decimal prevDmiSma = dmiSmaList.LastOrDefault(); decimal dmiSma = avgLossSma == 0 ? 100 : avgGainSma == 0 ? 0 : 100 - (100 / (1 + rsSma)); - dmiSmaList.Add(dmiSma); + dmiSmaList.AddRounded(dmiSma); decimal dmiSignalSma = dmiSmaList.TakeLastExt(dmiLength).Average(); - dmiSignalSmaList.Add(dmiSignalSma); + dmiSignalSmaList.AddRounded(dmiSignalSma); decimal prevDmiHistogram = dmiHistogramSmaList.LastOrDefault(); decimal dmiHistogramSma = dmiSma - dmiSignalSma; - dmiHistogramSmaList.Add(dmiHistogramSma); + dmiHistogramSmaList.AddRounded(dmiHistogramSma); var signal = GetRsiSignal(dmiHistogramSma, prevDmiHistogram, dmiSma, prevDmiSma, 70, 30); signalsList.Add(signal); @@ -617,23 +617,23 @@ public static StockData CalculateSqueezeMomentumIndicator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal midprice = (highest + lowest) / 2; - decimal sma = smaList.ElementAtOrDefault(i); + decimal sma = smaList[i]; decimal midpriceSmaAvg = (midprice + sma) / 2; decimal diff = currentValue - midpriceSmaAvg; - diffList.Add(diff); + diffList.AddRounded(diff); } stockData.CustomValuesList = diffList; var linregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal predictedToday = linregList.ElementAtOrDefault(i); - decimal prevPredictedToday = i >= 1 ? linregList.ElementAtOrDefault(i - 1) : 0; + decimal predictedToday = linregList[i]; + decimal prevPredictedToday = i >= 1 ? linregList[i - 1] : 0; var signal = GetCompareSignal(predictedToday, prevPredictedToday); signalsList.Add(signal); diff --git a/Calculations/MovingAvg.cs b/Calculations/MovingAvg.cs index 34da3ab..8907b46 100644 --- a/Calculations/MovingAvg.cs +++ b/Calculations/MovingAvg.cs @@ -17,8 +17,8 @@ public static StockData CalculateSimpleMovingAverage(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentValue = inputList[i]; tempList.AddRounded(currentValue); decimal prevSma = smaList.LastOrDefault(); @@ -54,14 +54,14 @@ public static StockData CalculateWeightedMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j < length; j++) { decimal weight = length - j; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -100,8 +100,8 @@ public static StockData CalculateExponentialMovingAverage(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevEma = emaList.LastOrDefault(); decimal ema = CalculateEMA(currentValue, prevEma, length); @@ -139,10 +139,10 @@ public static StockData CalculateTriangularMovingAverage(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal tma = tmaList.ElementAtOrDefault(i); - decimal prevTma = i >= 1 ? tmaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal tma = tmaList[i]; + decimal prevTma = i >= 1 ? tmaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - tma, prevValue - prevTma); signalsList.Add(signal); @@ -181,20 +181,20 @@ public static StockData CalculateHullMovingAverage(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentWMA1 = wma1List.ElementAtOrDefault(i); - decimal currentWMA2 = wma2List.ElementAtOrDefault(i); + decimal currentWMA1 = wma1List[i]; + decimal currentWMA2 = wma2List[i]; decimal totalWeightedMA = (2 * currentWMA2) - currentWMA1; - totalWeightedMAList.Add(totalWeightedMA); + totalWeightedMAList.AddRounded(totalWeightedMA); } var hullMAList = GetMovingAverageList(stockData, maType, sqrtLength, totalWeightedMAList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(j); - decimal prevValue = j >= 1 ? inputList.ElementAtOrDefault(j - 1) : 0; - decimal hullMa = hullMAList.ElementAtOrDefault(j); - decimal prevHullMa = j >= 1 ? inputList.ElementAtOrDefault(j - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal hullMa = hullMAList[i]; + decimal prevHullMa = i >= 1 ? inputList[i - 1] : 0; var signal = GetCompareSignal(currentValue - hullMa, prevValue - prevHullMa); signalsList.Add(signal); @@ -232,12 +232,12 @@ public static StockData CalculateKaufmanAdaptiveMovingAverage(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorValue = i >= length ? inputList[i - length] : 0; decimal volatility = Math.Abs(currentValue - prevValue); - volatilityList.Add(volatility); + volatilityList.AddRounded(volatility); decimal volatilitySum = volatilityList.TakeLastExt(length).Sum(); decimal momentum = Math.Abs(currentValue - priorValue); @@ -248,7 +248,7 @@ public static StockData CalculateKaufmanAdaptiveMovingAverage(this StockData sto decimal sc = Pow((efficiencyRatio * (fastAlpha - slowAlpha)) + slowAlpha, 2); decimal prevKama = kamaList.LastOrDefault(); decimal currentKAMA = (sc * currentValue) + ((1 - sc) * prevKama); - kamaList.Add(currentKAMA); + kamaList.AddRounded(currentKAMA); var signal = GetCompareSignal(currentValue - currentKAMA, prevValue - prevKama); signalsList.Add(signal); @@ -285,14 +285,14 @@ public static StockData CalculateArnaudLegouxMovingAverage(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = s != 0 ? Exp(-1 * Pow(j - m, 2) / (2 * Pow(s, 2))) : 0; - decimal prevValue = i >= length - 1 - j ? inputList.ElementAtOrDefault(i - (length - 1 - j)) : 0; + decimal prevValue = i >= length - 1 - j ? inputList[i - (length - 1 - j)] : 0; sum += prevValue * weight; weightedSum += weight; @@ -300,7 +300,7 @@ public static StockData CalculateArnaudLegouxMovingAverage(this StockData stockD decimal prevAlma = almaList.LastOrDefault(); decimal alma = weightedSum != 0 ? sum / weightedSum : 0; - almaList.Add(alma); + almaList.AddRounded(alma); var signal = GetCompareSignal(currentValue - alma, prevVal - prevAlma); signalsList.Add(signal); @@ -332,14 +332,14 @@ public static StockData CalculateEndPointMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = length - j - length; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -347,7 +347,7 @@ public static StockData CalculateEndPointMovingAverage(this StockData stockData, decimal prevEpma = epmaList.LastOrDefault(); decimal epma = weightedSum != 0 ? 1 / weightedSum * sum : 0; - epmaList.Add(epma); + epmaList.AddRounded(epma); var signal = GetCompareSignal(currentValue - epma, prevVal - prevEpma); signalsList.Add(signal); @@ -381,14 +381,14 @@ public static StockData CalculateLeastSquaresMovingAverage(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentWma = wmaList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentWma = wmaList[i]; + decimal currentSma = smaList[i]; decimal prevLsma = lsmaList.LastOrDefault(); decimal lsma = (3 * currentWma) - (2 * currentSma); - lsmaList.Add(lsma); + lsmaList.AddRounded(lsma); var signal = GetCompareSignal(currentValue - lsma, prevValue - prevLsma); signalsList.Add(signal); @@ -432,86 +432,86 @@ public static StockData CalculateEhlersMotherOfAdaptiveMovingAverages(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevPrice1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal previ2 = i >= 1 ? i2List.ElementAtOrDefault(i - 1) : 0; - decimal prevq2 = i >= 1 ? q2List.ElementAtOrDefault(i - 1) : 0; - decimal prevRe = i >= 1 ? reList.ElementAtOrDefault(i - 1) : 0; - decimal prevIm = i >= 1 ? imList.ElementAtOrDefault(i - 1) : 0; - decimal prevSprd = i >= 1 ? sPrdList.ElementAtOrDefault(i - 1) : 0; - decimal prevPhase = i >= 1 ? phaseList.ElementAtOrDefault(i - 1) : 0; - decimal prevPeriod = i >= 1 ? periodList.ElementAtOrDefault(i - 1) : 0; - decimal prevPrice2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevPrice3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal prevs2 = i >= 2 ? smoothList.ElementAtOrDefault(i - 2) : 0; - decimal prevd2 = i >= 2 ? detList.ElementAtOrDefault(i - 2) : 0; - decimal prevq1x2 = i >= 2 ? q1List.ElementAtOrDefault(i - 2) : 0; - decimal previ1x2 = i >= 2 ? i1List.ElementAtOrDefault(i - 2) : 0; - decimal prevd3 = i >= 3 ? detList.ElementAtOrDefault(i - 3) : 0; - decimal prevs4 = i >= 4 ? smoothList.ElementAtOrDefault(i - 4) : 0; - decimal prevd4 = i >= 4 ? detList.ElementAtOrDefault(i - 4) : 0; - decimal prevq1x4 = i >= 4 ? q1List.ElementAtOrDefault(i - 4) : 0; - decimal previ1x4 = i >= 4 ? i1List.ElementAtOrDefault(i - 4) : 0; - decimal prevs6 = i >= 6 ? smoothList.ElementAtOrDefault(i - 6) : 0; - decimal prevd6 = i >= 6 ? detList.ElementAtOrDefault(i - 6) : 0; - decimal prevq1x6 = i >= 6 ? q1List.ElementAtOrDefault(i - 6) : 0; - decimal previ1x6 = i >= 6 ? i1List.ElementAtOrDefault(i - 6) : 0; - decimal prevMama = i >= 1 ? mamaList.ElementAtOrDefault(i - 1) : 0; - decimal prevFama = i >= 1 ? famaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevPrice1 = i >= 1 ? inputList[i - 1] : 0; + decimal previ2 = i >= 1 ? i2List[i - 1] : 0; + decimal prevq2 = i >= 1 ? q2List[i - 1] : 0; + decimal prevRe = i >= 1 ? reList[i - 1] : 0; + decimal prevIm = i >= 1 ? imList[i - 1] : 0; + decimal prevSprd = i >= 1 ? sPrdList[i - 1] : 0; + decimal prevPhase = i >= 1 ? phaseList[i - 1] : 0; + decimal prevPeriod = i >= 1 ? periodList[i - 1] : 0; + decimal prevPrice2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevPrice3 = i >= 3 ? inputList[i - 3] : 0; + decimal prevs2 = i >= 2 ? smoothList[i - 2] : 0; + decimal prevd2 = i >= 2 ? detList[i - 2] : 0; + decimal prevq1x2 = i >= 2 ? q1List[i - 2] : 0; + decimal previ1x2 = i >= 2 ? i1List[i - 2] : 0; + decimal prevd3 = i >= 3 ? detList[i - 3] : 0; + decimal prevs4 = i >= 4 ? smoothList[i - 4] : 0; + decimal prevd4 = i >= 4 ? detList[i - 4] : 0; + decimal prevq1x4 = i >= 4 ? q1List[i - 4] : 0; + decimal previ1x4 = i >= 4 ? i1List[i - 4] : 0; + decimal prevs6 = i >= 6 ? smoothList[i - 6] : 0; + decimal prevd6 = i >= 6 ? detList[i - 6] : 0; + decimal prevq1x6 = i >= 6 ? q1List[i - 6] : 0; + decimal previ1x6 = i >= 6 ? i1List[i - 6] : 0; + decimal prevMama = i >= 1 ? mamaList[i - 1] : 0; + decimal prevFama = i >= 1 ? famaList[i - 1] : 0; decimal smooth = ((4 * currentValue) + (3 * prevPrice1) + (2 * prevPrice2) + prevPrice3) / 10; - smoothList.Add(smooth); + smoothList.AddRounded(smooth); decimal det = ((0.0962m * smooth) + (0.5769m * prevs2) - (0.5769m * prevs4) - (0.0962m * prevs6)) * ((0.075m * prevPeriod) + 0.54m); - detList.Add(det); + detList.AddRounded(det); decimal q1 = ((0.0962m * det) + (0.5769m * prevd2) - (0.5769m * prevd4) - (0.0962m * prevd6)) * ((0.075m * prevPeriod) + 0.54m); - q1List.Add(q1); + q1List.AddRounded(q1); decimal i1 = prevd3; - i1List.Add(i1); + i1List.AddRounded(i1); decimal j1 = ((0.0962m * i1) + (0.5769m * previ1x2) - (0.5769m * previ1x4) - (0.0962m * previ1x6)) * ((0.075m * prevPeriod) + 0.54m); decimal jq = ((0.0962m * q1) + (0.5769m * prevq1x2) - (0.5769m * prevq1x4) - (0.0962m * prevq1x6)) * ((0.075m * prevPeriod) + 0.54m); decimal i2 = i1 - jq; i2 = (0.2m * i2) + (0.8m * previ2); - i2List.Add(i2); + i2List.AddRounded(i2); decimal q2 = q1 + j1; q2 = (0.2m * q2) + (0.8m * prevq2); - q2List.Add(q2); + q2List.AddRounded(q2); decimal re = (i2 * previ2) + (q2 * prevq2); re = (0.2m * re) + (0.8m * prevRe); - reList.Add(re); + reList.AddRounded(re); decimal im = (i2 * prevq2) - (q2 * previ2); im = (0.2m * im) + (0.8m * prevIm); - imList.Add(im); + imList.AddRounded(im); var atan = re != 0 ? Atan(im / re) : 0; decimal period = atan != 0 ? 2 * Pi / atan : 0; period = MinOrMax(period, 1.5m * prevPeriod, 0.67m * prevPeriod); period = MinOrMax(period, 50, 6); period = (0.2m * period) + (0.8m * prevPeriod); - periodList.Add(period); + periodList.AddRounded(period); decimal sPrd = (0.33m * period) + (0.67m * prevSprd); - sPrdList.Add(sPrd); + sPrdList.AddRounded(sPrd); decimal phase = i1 != 0 ? Atan(q1 / i1).ToDegrees() : 0; - phaseList.Add(phase); + phaseList.AddRounded(phase); decimal deltaPhase = prevPhase - phase < 1 ? 1 : prevPhase - phase; decimal alpha = deltaPhase != 0 ? fastAlpha / deltaPhase : 0; alpha = alpha < slowAlpha ? slowAlpha : alpha; decimal mama = (alpha * currentValue) + ((1 - alpha) * prevMama); - mamaList.Add(mama); + mamaList.AddRounded(mama); decimal fama = (0.5m * alpha * mama) + ((1 - (0.5m * alpha)) * prevFama); - famaList.Add(fama); + famaList.AddRounded(fama); var signal = GetCompareSignal(mama - fama, prevMama - prevFama); signalsList.Add(signal); @@ -551,12 +551,12 @@ public static StockData CalculateWellesWilderMovingAverage(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevWwma = wwmaList.LastOrDefault(); decimal wwma = (currentValue * k) + (prevWwma * (1 - k)); - wwmaList.Add(wwma); + wwmaList.AddRounded(wwma); var signal = GetCompareSignal(currentValue - wwma, prevValue - prevWwma); signalsList.Add(signal); @@ -602,12 +602,12 @@ public static StockData CalculateTillsonT3MovingAverage(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ema6 = ema6List.ElementAtOrDefault(i); - decimal ema5 = ema5List.ElementAtOrDefault(i); - decimal ema4 = ema4List.ElementAtOrDefault(i); - decimal ema3 = ema3List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ema6 = ema6List[i]; + decimal ema5 = ema5List[i]; + decimal ema4 = ema4List[i]; + decimal ema3 = ema3List[i]; decimal prevT3 = t3List.LastOrDefault(); decimal t3 = (c1 * ema6) + (c2 * ema5) + (c3 * ema4) + (c4 * ema3); @@ -648,15 +648,15 @@ public static StockData CalculateTripleExponentialMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentEma1 = ema1List.ElementAtOrDefault(i); - decimal currentEma2 = ema2List.ElementAtOrDefault(i); - decimal currentEma3 = ema3List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentEma1 = ema1List[i]; + decimal currentEma2 = ema2List[i]; + decimal currentEma3 = ema3List[i]; decimal prevTema = temaList.LastOrDefault(); decimal tema = (3 * currentEma1) - (3 * currentEma2) + currentEma3; - temaList.Add(tema); + temaList.AddRounded(tema); var signal = GetCompareSignal(currentValue - tema, prevValue - prevTema); signalsList.Add(signal); @@ -689,21 +689,21 @@ public static StockData CalculateVolumeWeightedAveragePrice(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - tempVolList.Add(currentVolume); + decimal currentVolume = volumeList[i]; + tempVolList.AddRounded(currentVolume); decimal volumePrice = currentValue * currentVolume; - tempVolPriceList.Add(volumePrice); + tempVolPriceList.AddRounded(volumePrice); decimal volPriceSum = tempVolPriceList.Sum(); decimal volSum = tempVolList.Sum(); decimal prevVwap = vwapList.LastOrDefault(); decimal vwap = volSum != 0 ? volPriceSum / volSum : 0; - vwapList.Add(vwap); + vwapList.AddRounded(vwap); var signal = GetCompareSignal(currentValue - vwap, prevValue - prevVwap); signalsList.Add(signal); @@ -739,19 +739,19 @@ public static StockData CalculateVolumeWeightedMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal currentVolumeSma = volumeSmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal currentVolumeSma = volumeSmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal volumePrice = currentValue * currentVolume; - volumePriceList.Add(volumePrice); + volumePriceList.AddRounded(volumePrice); decimal volumePriceSma = volumePriceList.TakeLastExt(length).Average(); decimal prevVwma = vwmaList.LastOrDefault(); decimal vwma = currentVolumeSma != 0 ? volumePriceSma / currentVolumeSma : 0; - vwmaList.Add(vwma); + vwmaList.AddRounded(vwma); var signal = GetCompareSignal(currentValue - vwma, prevValue - prevVwma); signalsList.Add(signal); @@ -791,19 +791,19 @@ public static StockData CalculateUltimateMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentVolume = stockData.Volumes.ElementAtOrDefault(i); - decimal typicalPrice = tpList.ElementAtOrDefault(i); - decimal prevTypicalPrice = i >= 1 ? tpList.ElementAtOrDefault(i - 1) : 0; - decimal length = MinOrMax(lenList.ElementAtOrDefault(i), maxLength, minLength); + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; + decimal currentVolume = stockData.Volumes[i]; + decimal typicalPrice = tpList[i]; + decimal prevTypicalPrice = i >= 1 ? tpList[i - 1] : 0; + decimal length = MinOrMax(lenList[i], maxLength, minLength); decimal rawMoneyFlow = typicalPrice * currentVolume; decimal posMoneyFlow = typicalPrice > prevTypicalPrice ? rawMoneyFlow : 0; - posMoneyFlowList.Add(posMoneyFlow); + posMoneyFlowList.AddRounded(posMoneyFlow); decimal negMoneyFlow = typicalPrice < prevTypicalPrice ? rawMoneyFlow : 0; - negMoneyFlowList.Add(negMoneyFlow); + negMoneyFlowList.AddRounded(negMoneyFlow); int len = (int)length; decimal posMoneyFlowTotal = posMoneyFlowList.TakeLastExt(len).Sum(); @@ -816,7 +816,7 @@ public static StockData CalculateUltimateMovingAverage(this StockData stockData, for (int j = 0; j <= len - 1; j++) { decimal weight = Pow(len - j, p); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -824,7 +824,7 @@ public static StockData CalculateUltimateMovingAverage(this StockData stockData, decimal prevUma = umaList.LastOrDefault(); decimal uma = weightedSum != 0 ? sum / weightedSum : 0; - umaList.Add(uma); + umaList.AddRounded(uma); var signal = GetCompareSignal(currentValue - uma, prevVal - prevUma); signalsList.Add(signal); @@ -862,24 +862,24 @@ public static StockData CalculateVariableLengthMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = smaList[i]; + decimal stdDev = stdDevList[i]; decimal a = sma - (1.75m * stdDev); decimal b = sma - (0.25m * stdDev); decimal c = sma + (0.25m * stdDev); decimal d = sma + (1.75m * stdDev); - decimal prevLength = i >= 1 ? lengthList.ElementAtOrDefault(i - 1) : maxLength; + decimal prevLength = i >= 1 ? lengthList[i - 1] : maxLength; decimal length = MinOrMax(currentValue >= b && currentValue <= c ? prevLength + 1 : currentValue < a || currentValue > d ? prevLength - 1 : prevLength, maxLength, minLength); - lengthList.Add(length); + lengthList.AddRounded(length); decimal sc = 2 / (length + 1); - decimal prevVlma = i >= 1 ? vlmaList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevVlma = i >= 1 ? vlmaList[i - 1] : currentValue; decimal vlma = (currentValue * sc) + ((1 - sc) * prevVlma); - vlmaList.Add(vlma); + vlmaList.AddRounded(vlma); var signal = GetCompareSignal(currentValue - vlma, prevValue - prevVlma); signalsList.Add(signal); @@ -911,13 +911,13 @@ public static StockData CalculateAhrensMovingAverage(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorAhma = i >= length ? ahmaList.ElementAtOrDefault(i - length) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorAhma = i >= length ? ahmaList[i - length] : currentValue; decimal prevAhma = ahmaList.LastOrDefault(); decimal ahma = prevAhma + ((currentValue - ((prevAhma + priorAhma) / 2)) / length); - ahmaList.Add(ahma); + ahmaList.AddRounded(ahma); var signal = GetCompareSignal(currentValue - ahma, prevValue - prevAhma); signalsList.Add(signal); @@ -954,16 +954,16 @@ public static StockData CalculateAdaptiveMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; decimal mltp = hh - ll != 0 ? MinOrMax(Math.Abs((2 * currentValue) - ll - hh) / (hh - ll), 1, 0) : 0; decimal ssc = (mltp * (fastAlpha - slowAlpha)) + slowAlpha; decimal prevAma = amaList.LastOrDefault(); decimal ama = prevAma + (Pow(ssc, 2) * (currentValue - prevAma)); - amaList.Add(ama); + amaList.AddRounded(ama); var signal = GetCompareSignal(currentValue - ama, prevValue - prevAma); signalsList.Add(signal); @@ -1001,17 +1001,17 @@ public static StockData CalculateAdaptiveExponentialMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; + decimal sma = smaList[i]; decimal mltp2 = hh - ll != 0 ? MinOrMax(Math.Abs((2 * currentValue) - ll - hh) / (hh - ll), 1, 0) : 0; decimal rate = mltp1 * (1 + mltp2); decimal prevAema = i >= 1 ? aemaList.LastOrDefault() : currentValue; decimal aema = i <= length ? sma : prevAema + (rate * (currentValue - prevAema)); - aemaList.Add(aema); + aemaList.AddRounded(aema); var signal = GetCompareSignal(currentValue - aema, prevValue - prevAema); signalsList.Add(signal); @@ -1048,24 +1048,24 @@ public static StockData CalculateAdaptiveAutonomousRecursiveMovingAverage(this S for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal er = erList.ElementAtOrDefault(i); - decimal prevMa2 = i >= 1 ? ma2List.ElementAtOrDefault(i - 1) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal er = erList[i]; + decimal prevMa2 = i >= 1 ? ma2List[i - 1] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal absDiff = Math.Abs(currentValue - prevMa2); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal d = i != 0 ? absDiffList.Sum() / i * gamma : 0; dList.AddRounded(d); decimal c = currentValue > prevMa2 + d ? currentValue + d : currentValue < prevMa2 - d ? currentValue - d : prevMa2; - decimal prevMa1 = i >= 1 ? ma1List.ElementAtOrDefault(i - 1) : currentValue; + decimal prevMa1 = i >= 1 ? ma1List[i - 1] : currentValue; decimal ma1 = (er * c) + ((1 - er) * prevMa1); - ma1List.Add(ma1); + ma1List.AddRounded(ma1); decimal ma2 = (er * ma1) + ((1 - er) * prevMa2); - ma2List.Add(ma2); + ma2List.AddRounded(ma2); var signal = GetCompareSignal(currentValue - ma2, prevValue - prevMa2); signalsList.Add(signal); @@ -1102,23 +1102,23 @@ public static StockData CalculateAutonomousRecursiveMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - momLength) : 0; - decimal prevMad = i >= 1 ? madList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorValue = i >= length ? inputList[i - momLength] : 0; + decimal prevMad = i >= 1 ? madList[i - 1] : currentValue; decimal absDiff = Math.Abs(priorValue - prevMad); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal d = i != 0 ? absDiffList.Sum() / i * gamma : 0; decimal c = currentValue > prevMad + d ? currentValue + d : currentValue < prevMad - d ? currentValue - d : prevMad; - cList.Add(c); + cList.AddRounded(c); decimal ma1 = cList.TakeLastExt(length).Average(); - ma1List.Add(ma1); + ma1List.AddRounded(ma1); decimal mad = ma1List.TakeLastExt(length).Average(); - madList.Add(mad); + madList.AddRounded(mad); var signal = GetCompareSignal(currentValue - mad, prevValue - prevMad); signalsList.Add(signal); @@ -1161,40 +1161,40 @@ public static StockData CalculateAtrFilteredExponentialMovingAverage(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); decimal trVal = currentValue != 0 ? tr / currentValue : tr; - trValList.Add(trVal); + trValList.AddRounded(trVal); } var atrValList = GetMovingAverageList(stockData, maType, atrLength, trValList); for (int i = 0; i < stockData.Count; i++) { - decimal atrVal = atrValList.ElementAtOrDefault(i); + decimal atrVal = atrValList[i]; decimal atrValPow = Pow(atrVal, 2); - atrValPowList.Add(atrValPow); + atrValPowList.AddRounded(atrValPow); } var stdDevAList = GetMovingAverageList(stockData, maType, stdDevLength, atrValPowList); for (int i = 0; i < stockData.Count; i++) { - decimal stdDevA = stdDevAList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal stdDevA = stdDevAList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal atrVal = atrValList.ElementAtOrDefault(i); - tempList.Add(atrVal); + decimal atrVal = atrValList[i]; + tempList.AddRounded(atrVal); decimal atrValSum = tempList.TakeLastExt(stdDevLength).Sum(); decimal stdDevB = Pow(atrValSum, 2) / Pow(stdDevLength, 2); decimal stdDev = stdDevA - stdDevB >= 0 ? Sqrt(stdDevA - stdDevB) : 0; - stdDevList.Add(stdDev); + stdDevList.AddRounded(stdDev); decimal stdDevLow = stdDevList.TakeLastExt(lbLength).Min(); decimal stdDevFactorAFP = stdDev != 0 ? stdDevLow / stdDev : 0; @@ -1206,11 +1206,11 @@ public static StockData CalculateAtrFilteredExponentialMovingAverage(this StockD decimal prevEmaAfp = emaAFPList.LastOrDefault(); decimal emaAfp = (alphaAfp * currentValue) + ((1 - alphaAfp) * prevEmaAfp); - emaAFPList.Add(emaAfp); + emaAFPList.AddRounded(emaAfp); decimal prevEmaCtp = emaCTPList.LastOrDefault(); decimal emaCtp = (alphaCtp * currentValue) + ((1 - alphaCtp) * prevEmaCtp); - emaCTPList.Add(emaCtp); + emaCTPList.AddRounded(emaCtp); var signal = GetCompareSignal(currentValue - emaAfp, prevValue - prevEmaAfp); signalsList.Add(signal); @@ -1250,14 +1250,14 @@ public static StockData CalculateAdaptiveLeastSquares(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal index = i; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - tempList.Add(tr); + tempList.AddRounded(tr); decimal highest = tempList.TakeLastExt(length).Max(); decimal alpha = highest != 0 ? MinOrMax(Pow(tr / highest, smooth), 0.99m, 0.01m) : 0.01m; @@ -1265,36 +1265,36 @@ public static StockData CalculateAdaptiveLeastSquares(this StockData stockData, decimal yy = currentValue * currentValue; decimal xy = index * currentValue; - decimal prevX = i >= 1 ? xList.ElementAtOrDefault(i - 1) : index; + decimal prevX = i >= 1 ? xList[i - 1] : index; decimal x = (alpha * index) + ((1 - alpha) * prevX); - xList.Add(x); + xList.AddRounded(x); - decimal prevY = i >= 1 ? yList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevY = i >= 1 ? yList[i - 1] : currentValue; decimal y = (alpha * currentValue) + ((1 - alpha) * prevY); - yList.Add(y); + yList.AddRounded(y); decimal dx = Math.Abs(index - x); decimal dy = Math.Abs(currentValue - y); - decimal prevMx = i >= 1 ? mxList.ElementAtOrDefault(i - 1) : dx; + decimal prevMx = i >= 1 ? mxList[i - 1] : dx; decimal mx = (alpha * dx) + ((1 - alpha) * prevMx); - mxList.Add(mx); + mxList.AddRounded(mx); - decimal prevMy = i >= 1 ? myList.ElementAtOrDefault(i - 1) : dy; + decimal prevMy = i >= 1 ? myList[i - 1] : dy; decimal my = (alpha * dy) + ((1 - alpha) * prevMy); - myList.Add(my); + myList.AddRounded(my); - decimal prevMxx = i >= 1 ? mxxList.ElementAtOrDefault(i - 1) : xx; + decimal prevMxx = i >= 1 ? mxxList[i - 1] : xx; decimal mxx = (alpha * xx) + ((1 - alpha) * prevMxx); - mxxList.Add(mxx); + mxxList.AddRounded(mxx); - decimal prevMyy = i >= 1 ? myyList.ElementAtOrDefault(i - 1) : yy; + decimal prevMyy = i >= 1 ? myyList[i - 1] : yy; decimal myy = (alpha * yy) + ((1 - alpha) * prevMyy); - myyList.Add(myy); + myyList.AddRounded(myy); - decimal prevMxy = i >= 1 ? mxyList.ElementAtOrDefault(i - 1) : xy; + decimal prevMxy = i >= 1 ? mxyList[i - 1] : xy; decimal mxy = (alpha * xy) + ((1 - alpha) * prevMxy); - mxyList.Add(mxy); + mxyList.AddRounded(mxy); decimal alphaVal = (2 / alpha) + 1; decimal a1 = alpha != 0 ? (Pow(alphaVal, 2) * mxy) - (alphaVal * mx * alphaVal * my) : 0; @@ -1306,7 +1306,7 @@ public static StockData CalculateAdaptiveLeastSquares(this StockData stockData, decimal prevReg = regList.LastOrDefault(); decimal reg = (x * a) + b; - regList.Add(reg); + regList.AddRounded(reg); var signal = GetCompareSignal(currentValue - reg, prevValue - prevReg); signalsList.Add(signal); @@ -1336,13 +1336,13 @@ public static StockData CalculateAlphaDecreasingExponentialMovingAverage(this St for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal alpha = (decimal)2 / (i + 1); decimal prevEma = emaList.LastOrDefault(); decimal ema = (alpha * currentValue) + ((1 - alpha) * prevEma); - emaList.Add(ema); + emaList.AddRounded(ema); var signal = GetCompareSignal(currentValue - ema, prevValue - prevEma); signalsList.Add(signal); @@ -1378,9 +1378,9 @@ public static StockData CalculatePoweredKaufmanAdaptiveMovingAverage(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal er = erList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal er = erList[i]; decimal powSp = er != 0 ? 1 / er : factor; decimal perSp = Pow(er, powSp); @@ -1434,18 +1434,18 @@ public static StockData CalculateAutoFilter(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal dev = devList.ElementAtOrDefault(i); + decimal dev = devList[i]; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal prevX = i >= 1 ? xList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevX = i >= 1 ? xList[i - 1] : currentValue; decimal x = currentValue > prevX + dev ? currentValue : currentValue < prevX - dev ? currentValue : prevX; - xList.Add(x); + xList.AddRounded(x); var corr = GoodnessOfFit.R(tempList.TakeLastExt(length).Select(x => (double)x), xList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } var xMaList = GetMovingAverageList(stockData, maType, length, xList); @@ -1453,20 +1453,20 @@ public static StockData CalculateAutoFilter(this StockData stockData, MovingAvgT var mxList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal my = devList.ElementAtOrDefault(i); - decimal mx = mxList.ElementAtOrDefault(i); - decimal corr = corrList.ElementAtOrDefault(i); - decimal yMa = yMaList.ElementAtOrDefault(i); - decimal xMa = xMaList.ElementAtOrDefault(i); - decimal x = xList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal my = devList[i]; + decimal mx = mxList[i]; + decimal corr = corrList[i]; + decimal yMa = yMaList[i]; + decimal xMa = xMaList[i]; + decimal x = xList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal slope = mx != 0 ? corr * (my / mx) : 0; decimal inter = yMa - (slope * xMa); decimal prevReg = regList.LastOrDefault(); decimal reg = (x * slope) + inter; - regList.Add(reg); + regList.AddRounded(reg); var signal = GetCompareSignal(currentValue - reg, prevValue - prevReg); signalsList.Add(signal); @@ -1499,13 +1499,13 @@ public static StockData CalculateAutoLine(this StockData stockData, int length = for (int i = 0; i < stockData.Count; i++) { - decimal dev = devList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal dev = devList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal prevX = i >= 1 ? xList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevX = i >= 1 ? xList[i - 1] : currentValue; decimal x = currentValue > prevX + dev ? currentValue : currentValue < prevX - dev ? currentValue : prevX; - xList.Add(x); + xList.AddRounded(x); var signal = GetCompareSignal(currentValue - x, prevValue - prevX); signalsList.Add(signal); @@ -1538,16 +1538,16 @@ public static StockData CalculateAutoLineWithDrift(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal dev = stdDevList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal dev = stdDevList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal r = Math.Round(currentValue); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : r; - decimal priorA = i >= length + 1 ? aList.ElementAtOrDefault(i - (length + 1)) : r; + decimal prevA = i >= 1 ? aList[i - 1] : r; + decimal priorA = i >= length + 1 ? aList[i - (length + 1)] : r; decimal a = currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA + ((decimal)1 / (length * 2) * (prevA - priorA)); - aList.Add(a); + aList.AddRounded(a); var signal = GetCompareSignal(currentValue - a, prevValue - prevA); signalsList.Add(signal); @@ -1586,28 +1586,28 @@ public static StockData Calculate1LCLeastSquaresMovingAverage(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); var corr = GoodnessOfFit.R(indexList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } for (int i = 0; i < stockData.Count; i++) { - decimal sma = smaList.ElementAtOrDefault(i); - decimal corr = corrList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal sma = smaList[i]; + decimal corr = corrList[i]; + decimal stdDev = stdDevList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevY = yList.LastOrDefault(); decimal y = sma + (corr * stdDev * 1.7m); - yList.Add(y); + yList.AddRounded(y); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); signalsList.Add(signal); @@ -1647,21 +1647,21 @@ public static StockData Calculate3HMA(this StockData stockData, MovingAvgType ma for (int i = 0; i < stockData.Count; i++) { - decimal wma1 = wma1List.ElementAtOrDefault(i); - decimal wma2 = wma2List.ElementAtOrDefault(i); - decimal wma3 = wma3List.ElementAtOrDefault(i); + decimal wma1 = wma1List[i]; + decimal wma2 = wma2List[i]; + decimal wma3 = wma3List[i]; decimal mid = (wma1 * 3) - wma2 - wma3; - midList.Add(mid); + midList.AddRounded(mid); } var aList = GetMovingAverageList(stockData, maType, p, midList); for (int i = 0; i < stockData.Count; i++) { - decimal a = aList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal a = aList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; var signal = GetCompareSignal(currentValue - a, prevValue - prevA); signalsList.Add(signal); @@ -1692,13 +1692,13 @@ public static StockData CalculateJsaMovingAverage(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal priorValue = i >= length ? inputList[i - length] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevJma = jmaList.LastOrDefault(); decimal jma = (currentValue + priorValue) / 2; - jmaList.Add(jma); + jmaList.AddRounded(jma); var signal = GetCompareSignal(currentValue - jma, prevValue - prevJma); signalsList.Add(signal); @@ -1739,8 +1739,8 @@ public static StockData CalculateJurikMovingAverage(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevJma = jmaList.LastOrDefault(); decimal prevE0 = e0List.LastOrDefault(); @@ -1791,19 +1791,19 @@ public static StockData CalculateZeroLowLagMovingAverage(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorB = i >= lbLength ? bList.ElementAtOrDefault(i - lbLength) : currentValue; - decimal priorA = i >= length ? aList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorB = i >= lbLength ? bList[i - lbLength] : currentValue; + decimal priorA = i >= length ? aList[i - length] : 0; decimal prevA = aList.LastOrDefault(); decimal a = (lag * currentValue) + ((1 - lag) * priorB) + prevA; - aList.Add(a); + aList.AddRounded(a); decimal aDiff = a - priorA; decimal prevB = bList.LastOrDefault(); decimal b = aDiff / length; - bList.Add(b); + bList.AddRounded(b); var signal = GetCompareSignal(currentValue - b, prevValue - prevB); signalsList.Add(signal); @@ -1839,15 +1839,15 @@ public static StockData CalculateZeroLagExponentialMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ema1 = ema1List.ElementAtOrDefault(i); - decimal ema2 = ema2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ema1 = ema1List[i]; + decimal ema2 = ema2List[i]; decimal d = ema1 - ema2; decimal prevZema = zemaList.LastOrDefault(); decimal zema = ema1 + d; - zemaList.Add(zema); + zemaList.AddRounded(zema); var signal = GetCompareSignal(currentValue - zema, prevValue - prevZema); signalsList.Add(signal); @@ -1883,15 +1883,15 @@ public static StockData CalculateZeroLagTripleExponentialMovingAverage(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal tma1 = tma1List.ElementAtOrDefault(i); - decimal tma2 = tma2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal tma1 = tma1List[i]; + decimal tma2 = tma2List[i]; decimal diff = tma1 - tma2; decimal prevZltema = zlTemaList.LastOrDefault(); decimal zltema = tma1 + diff; - zlTemaList.Add(zltema); + zlTemaList.AddRounded(zltema); var signal = GetCompareSignal(currentValue - zltema, prevValue - prevZltema); signalsList.Add(signal); @@ -1926,9 +1926,9 @@ public static StockData CalculateBryantAdaptiveMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal er = erList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal er = erList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ver = Pow(er - (((2 * er) - 1) / 2 * (1 - trend)) + 0.5m, 2); decimal vLength = ver != 0 ? (length - ver + 1) / ver : 0; vLength = Math.Min(vLength, maxLength); @@ -1936,7 +1936,7 @@ public static StockData CalculateBryantAdaptiveMovingAverage(this StockData stoc decimal prevBama = bamaList.LastOrDefault(); decimal bama = (vAlpha * currentValue) + ((1 - vAlpha) * prevBama); - bamaList.Add(bama); + bamaList.AddRounded(bama); var signal = GetCompareSignal(currentValue - bama, prevValue - prevBama); signalsList.Add(signal); @@ -1975,47 +1975,47 @@ public static StockData CalculateWindowedVolumeWeightedMovingAverage(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal iRatio = (decimal)i / length; decimal bartlett = 1 - (2 * Math.Abs(i - ((decimal)length / 2)) / length); decimal bartlettW = bartlett * currentVolume; - bartlettWList.Add(bartlettW); + bartlettWList.AddRounded(bartlettW); decimal bartlettWSum = bartlettWList.TakeLastExt(length).Sum(); decimal bartlettVW = currentValue * bartlettW; - bartlettVWList.Add(bartlettVW); + bartlettVWList.AddRounded(bartlettVW); decimal bartlettVWSum = bartlettVWList.TakeLastExt(length).Sum(); decimal prevBartlettWvwma = bartlettWvwmaList.LastOrDefault(); decimal bartlettWvwma = bartlettWSum != 0 ? bartlettVWSum / bartlettWSum : 0; - bartlettWvwmaList.Add(bartlettWvwma); + bartlettWvwmaList.AddRounded(bartlettWvwma); decimal blackman = 0.42m - (0.5m * Cos(2 * (decimal)Math.PI * iRatio)) + (0.08m * Cos(4 * (decimal)Math.PI * iRatio)); decimal blackmanW = blackman * currentVolume; - blackmanWList.Add(blackmanW); + blackmanWList.AddRounded(blackmanW); decimal blackmanWSum = blackmanWList.TakeLastExt(length).Sum(); decimal blackmanVW = currentValue * blackmanW; - blackmanVWList.Add(blackmanVW); + blackmanVWList.AddRounded(blackmanVW); decimal blackmanVWSum = blackmanVWList.TakeLastExt(length).Sum(); decimal blackmanWvwma = blackmanWSum != 0 ? blackmanVWSum / blackmanWSum : 0; - blackmanWvwmaList.Add(blackmanWvwma); + blackmanWvwmaList.AddRounded(blackmanWvwma); decimal hanning = 0.5m - (0.5m * Cos(2 * (decimal)Math.PI * iRatio)); decimal hanningW = hanning * currentVolume; - hanningWList.Add(hanningW); + hanningWList.AddRounded(hanningW); decimal hanningWSum = hanningWList.TakeLastExt(length).Sum(); decimal hanningVW = currentValue * hanningW; - hanningVWList.Add(hanningVW); + hanningVWList.AddRounded(hanningVW); decimal hanningVWSum = hanningVWList.TakeLastExt(length).Sum(); decimal hanningWvwma = hanningWSum != 0 ? hanningVWSum / hanningWSum : 0; - hanningWvwmaList.Add(hanningWvwma); + hanningWvwmaList.AddRounded(hanningWvwma); var signal = GetCompareSignal(currentValue - bartlettWvwma, prevValue - prevBartlettWvwma); signalsList.Add(signal); @@ -2053,33 +2053,33 @@ public static StockData CalculateWellRoundedMovingAverage(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSrcY = i >= 1 ? srcYList.ElementAtOrDefault(i - 1) : 0; - decimal prevSrcEma = i >= 1 ? srcEmaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSrcY = i >= 1 ? srcYList[i - 1] : 0; + decimal prevSrcEma = i >= 1 ? srcEmaList[i - 1] : 0; decimal prevA = aList.LastOrDefault(); decimal a = prevA + (alpha * prevSrcY); - aList.Add(a); + aList.AddRounded(a); decimal prevB = bList.LastOrDefault(); decimal b = prevB + (alpha * prevSrcEma); - bList.Add(b); + bList.AddRounded(b); decimal ab = a + b; decimal prevY = yList.LastOrDefault(); decimal y = CalculateEMA(ab, prevY, 1); - yList.Add(y); + yList.AddRounded(y); decimal srcY = currentValue - y; - srcYList.Add(srcY); + srcYList.AddRounded(srcY); decimal prevYEma = yEmaList.LastOrDefault(); decimal yEma = CalculateEMA(y, prevYEma, length); - yEmaList.Add(yEma); + yEmaList.AddRounded(yEma); decimal srcEma = currentValue - yEma; - srcEmaList.Add(srcEma); + srcEmaList.AddRounded(srcEma); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); signalsList.Add(signal); @@ -2110,12 +2110,12 @@ public static StockData CalculateWellesWilderSummation(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevSum = sumList.LastOrDefault(); decimal sum = prevSum - (prevSum / length) + currentValue; - sumList.Add(sum); + sumList.AddRounded(sum); var signal = GetCompareSignal(currentValue - sum, prevValue - prevSum); signalsList.Add(signal); @@ -2148,14 +2148,14 @@ public static StockData CalculateQuickMovingAverage(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal num = 0, denom = 0; for (int j = 1; j <= length + 1; j++) { decimal mult = j <= peak ? (decimal)j / peak : (decimal)(length + 1 - j) / (length + 1 - peak); - decimal prevValue = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; num += prevValue * mult; denom += mult; @@ -2163,7 +2163,7 @@ public static StockData CalculateQuickMovingAverage(this StockData stockData, in decimal prevQma = qmaList.LastOrDefault(); decimal qma = denom != 0 ? num / denom : 0; - qmaList.Add(qma); + qmaList.AddRounded(qma); var signal = GetCompareSignal(currentValue - qma, prevVal - prevQma); signalsList.Add(signal); @@ -2195,16 +2195,16 @@ public static StockData CalculateQuadraticMovingAverage(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal pow = Pow(currentValue, 2); - powList.Add(pow); + powList.AddRounded(pow); decimal prevQma = qmaList.LastOrDefault(); decimal powSma = powList.TakeLastExt(length).Average(); decimal qma = powSma >= 0 ? Sqrt(powSma) : 0; - qmaList.Add(qma); + qmaList.AddRounded(qma); var signal = GetCompareSignal(currentValue - qma, prevValue - prevQma); signalsList.Add(signal); @@ -2243,17 +2243,17 @@ public static StockData CalculateQuadrupleExponentialMovingAverage(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ema1 = ema1List.ElementAtOrDefault(i); - decimal ema2 = ema2List.ElementAtOrDefault(i); - decimal ema3 = ema3List.ElementAtOrDefault(i); - decimal ema4 = ema4List.ElementAtOrDefault(i); - decimal ema5 = ema5List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ema1 = ema1List[i]; + decimal ema2 = ema2List[i]; + decimal ema3 = ema3List[i]; + decimal ema4 = ema4List[i]; + decimal ema5 = ema5List[i]; decimal prevQema = qemaList.LastOrDefault(); decimal qema = (5 * ema1) - (10 * ema2) + (10 * ema3) - (5 * ema4) + ema5; - qemaList.Add(qema); + qemaList.AddRounded(qema); var signal = GetCompareSignal(currentValue - qema, prevValue - prevQema); signalsList.Add(signal); @@ -2298,22 +2298,22 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal n = i; - nList.Add(n); + nList.AddRounded(n); decimal n2 = Pow(n, 2); - n2List.Add(n2); + n2List.AddRounded(n2); decimal nn2 = n * n2; - nn2List.Add(nn2); + nn2List.AddRounded(nn2); decimal n2v = n2 * currentValue; - n2vList.Add(n2v); + n2vList.AddRounded(n2v); decimal nv = n * currentValue; - nvList.Add(nv); + nvList.AddRounded(nv); } var nSmaList = GetMovingAverageList(stockData, maType, length, nList); @@ -2323,21 +2323,21 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa var nn2SmaList = GetMovingAverageList(stockData, maType, length, nn2List); for (int i = 0; i < stockData.Count; i++) { - decimal nSma = nSmaList.ElementAtOrDefault(i); - decimal n2Sma = n2SmaList.ElementAtOrDefault(i); - decimal n2vSma = n2vSmaList.ElementAtOrDefault(i); - decimal nvSma = nvSmaList.ElementAtOrDefault(i); - decimal nn2Sma = nn2SmaList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); + decimal nSma = nSmaList[i]; + decimal n2Sma = n2SmaList[i]; + decimal n2vSma = n2vSmaList[i]; + decimal nvSma = nvSmaList[i]; + decimal nn2Sma = nn2SmaList[i]; + decimal sma = smaList[i]; decimal nn2Cov = nn2Sma - (nSma * n2Sma); - nn2CovList.Add(nn2Cov); + nn2CovList.AddRounded(nn2Cov); decimal n2vCov = n2vSma - (n2Sma * sma); - n2vCovList.Add(n2vCov); + n2vCovList.AddRounded(n2vCov); decimal nvCov = nvSma - (nSma * sma); - nvCovList.Add(nvCov); + nvCovList.AddRounded(nvCov); } stockData.CustomValuesList = nList; @@ -2346,17 +2346,17 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa var n2VarianceList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal n2Variance = n2VarianceList.ElementAtOrDefault(i); - decimal nVariance = nVarianceList.ElementAtOrDefault(i); - decimal nn2Cov = nn2CovList.ElementAtOrDefault(i); - decimal n2vCov = n2vCovList.ElementAtOrDefault(i); - decimal nvCov = nvCovList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal n2Sma = n2SmaList.ElementAtOrDefault(i); - decimal nSma = nSmaList.ElementAtOrDefault(i); - decimal n2 = n2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal n2Variance = n2VarianceList[i]; + decimal nVariance = nVarianceList[i]; + decimal nn2Cov = nn2CovList[i]; + decimal n2vCov = n2vCovList[i]; + decimal nvCov = nvCovList[i]; + decimal sma = smaList[i]; + decimal n2Sma = n2SmaList[i]; + decimal nSma = nSmaList[i]; + decimal n2 = n2List[i]; decimal norm = (n2Variance * nVariance) - Pow(nn2Cov, 2); decimal a = norm != 0 ? ((n2vCov * nVariance) - (nvCov * nn2Cov)) / norm : 0; decimal b = norm != 0 ? ((nvCov * n2Variance) - (n2vCov * nn2Cov)) / norm : 0; @@ -2364,10 +2364,10 @@ public static StockData CalculateQuadraticLeastSquaresMovingAverage(this StockDa decimal prevQlsma = qlsmaList.LastOrDefault(); decimal qlsma = (a * n2) + (b * i) + c; - qlsmaList.Add(qlsma); + qlsmaList.AddRounded(qlsma); decimal fcast = (a * Pow(i + forecastLength, 2)) + (b * (i + forecastLength)) + c; - fcastList.Add(fcast); + fcastList.AddRounded(fcast); var signal = GetCompareSignal(currentValue - qlsma, prevValue - prevQlsma); signalsList.Add(signal); @@ -2415,47 +2415,47 @@ public static StockData CalculateQuadraticRegression(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal y = inputList.ElementAtOrDefault(i); - tempList.Add(y); + decimal y = inputList[i]; + tempList.AddRounded(y); decimal x1 = i; - x1List.Add(x1); + x1List.AddRounded(x1); decimal x2 = Pow(x1, 2); - x2List.Add(x2); + x2List.AddRounded(x2); decimal x1x2 = x1 * x2; - x1x2List.Add(x1x2); + x1x2List.AddRounded(x1x2); decimal yx1 = y * x1; - yx1List.Add(yx1); + yx1List.AddRounded(yx1); decimal yx2 = y * x2; - yx2List.Add(yx2); + yx2List.AddRounded(yx2); decimal x2Pow = Pow(x2, 2); - x2PowList.Add(x2Pow); + x2PowList.AddRounded(x2Pow); decimal ySum = tempList.TakeLastExt(length).Sum(); - ySumList.Add(ySum); + ySumList.AddRounded(ySum); decimal x1Sum = x1List.TakeLastExt(length).Sum(); - x1SumList.Add(x1Sum); + x1SumList.AddRounded(x1Sum); decimal x2Sum = x2List.TakeLastExt(length).Sum(); - x2SumList.Add(x2Sum); + x2SumList.AddRounded(x2Sum); decimal x1x2Sum = x1x2List.TakeLastExt(length).Sum(); - x1x2SumList.Add(x1x2Sum); + x1x2SumList.AddRounded(x1x2Sum); decimal yx1Sum = yx1List.TakeLastExt(length).Sum(); - yx1SumList.Add(yx1Sum); + yx1SumList.AddRounded(yx1Sum); decimal yx2Sum = yx2List.TakeLastExt(length).Sum(); - yx2SumList.Add(yx2Sum); + yx2SumList.AddRounded(yx2Sum); decimal x2PowSum = x2PowList.TakeLastExt(length).Sum(); - x2PowSumList.Add(x2PowSum); + x2PowSumList.AddRounded(x2PowSum); } var max1List = GetMovingAverageList(stockData, maType, length, x1List); @@ -2463,20 +2463,20 @@ public static StockData CalculateQuadraticRegression(this StockData stockData, M var mayList = GetMovingAverageList(stockData, maType, length, inputList); for (int i = 0; i < stockData.Count; i++) { - decimal x1Sum = x1SumList.ElementAtOrDefault(i); - decimal x2Sum = x2SumList.ElementAtOrDefault(i); - decimal x1x2Sum = x1x2SumList.ElementAtOrDefault(i); - decimal x2PowSum = x2PowSumList.ElementAtOrDefault(i); - decimal yx1Sum = yx1SumList.ElementAtOrDefault(i); - decimal yx2Sum = yx2SumList.ElementAtOrDefault(i); - decimal ySum = ySumList.ElementAtOrDefault(i); - decimal may = mayList.ElementAtOrDefault(i); - decimal max1 = max1List.ElementAtOrDefault(i); - decimal max2 = max2List.ElementAtOrDefault(i); - decimal x1 = x1List.ElementAtOrDefault(i); - decimal x2 = x2List.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal x1Sum = x1SumList[i]; + decimal x2Sum = x2SumList[i]; + decimal x1x2Sum = x1x2SumList[i]; + decimal x2PowSum = x2PowSumList[i]; + decimal yx1Sum = yx1SumList[i]; + decimal yx2Sum = yx2SumList[i]; + decimal ySum = ySumList[i]; + decimal may = mayList[i]; + decimal max1 = max1List[i]; + decimal max2 = max2List[i]; + decimal x1 = x1List[i]; + decimal x2 = x2List[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal s11 = x2Sum - (Pow(x1Sum, 2) / length); decimal s12 = x1x2Sum - ((x1Sum * x2Sum) / length); decimal s22 = x2PowSum - (Pow(x2Sum, 2) / length); @@ -2489,7 +2489,7 @@ public static StockData CalculateQuadraticRegression(this StockData stockData, M decimal prevY = yList.LastOrDefault(); decimal y = b1 + (b2 * x1) + (b3 * x2); - yList.Add(y); + yList.AddRounded(y); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); signalsList.Add(signal); @@ -2520,14 +2520,14 @@ public static StockData CalculateLinearWeightedMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = length - j; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -2535,7 +2535,7 @@ public static StockData CalculateLinearWeightedMovingAverage(this StockData stoc decimal prevLwma = lwmaList.LastOrDefault(); decimal lwma = weightedSum != 0 ? sum / weightedSum : 0; - lwmaList.Add(lwma); + lwmaList.AddRounded(lwma); var signal = GetCompareSignal(currentValue - lwma, prevVal - prevLwma); signalsList.Add(signal); @@ -2569,14 +2569,14 @@ public static StockData CalculateLeoMovingAverage(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentWma = wmaList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentWma = wmaList[i]; + decimal currentSma = smaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevLma = lmaList.LastOrDefault(); decimal lma = (2 * currentWma) - currentSma; - lmaList.Add(lma); + lmaList.AddRounded(lma); var signal = GetCompareSignal(currentValue - lma, prevValue - prevLma); signalsList.Add(signal); @@ -2613,7 +2613,7 @@ public static StockData CalculateLightLeastSquaresMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); } var sma1List = GetMovingAverageList(stockData, maType, length, inputList); @@ -2624,19 +2624,19 @@ public static StockData CalculateLightLeastSquaresMovingAverage(this StockData s var indexSmaList = GetMovingAverageList(stockData, maType, length, indexList); for (int i = 0; i < stockData.Count; i++) { - decimal sma1 = sma1List.ElementAtOrDefault(i); - decimal sma2 = sma2List.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal indexStdDev = indexStdDevList.ElementAtOrDefault(i); - decimal indexSma = indexSmaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal sma1 = sma1List[i]; + decimal sma2 = sma2List[i]; + decimal stdDev = stdDevList[i]; + decimal indexStdDev = indexStdDevList[i]; + decimal indexSma = indexSmaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal c = stdDev != 0 ? (sma2 - sma1) / stdDev : 0; decimal z = indexStdDev != 0 && c != 0 ? (i - indexSma) / indexStdDev * c : 0; decimal prevY = yList.LastOrDefault(); decimal y = sma1 + (z * stdDev); - yList.Add(y); + yList.AddRounded(y); var signal = GetCompareSignal(currentValue - y, prevValue - prevY); signalsList.Add(signal); @@ -2668,19 +2668,19 @@ public static StockData CalculateLinearExtrapolation(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevY = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorY = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal priorY2 = i >= length * 2 ? inputList.ElementAtOrDefault(i - (length * 2)) : 0; - decimal priorX = i >= length ? xList.ElementAtOrDefault(i - length) : 0; - decimal priorX2 = i >= length * 2 ? xList.ElementAtOrDefault(i - (length * 2)) : 0; + decimal currentValue = inputList[i]; + decimal prevY = i >= 1 ? inputList[i - 1] : 0; + decimal priorY = i >= length ? inputList[i - length] : 0; + decimal priorY2 = i >= length * 2 ? inputList[i - (length * 2)] : 0; + decimal priorX = i >= length ? xList[i - length] : 0; + decimal priorX2 = i >= length * 2 ? xList[i - (length * 2)] : 0; decimal x = i; - xList.Add(i); + xList.AddRounded(i); decimal prevExt = extList.LastOrDefault(); decimal ext = priorX2 - priorX != 0 && priorY2 - priorY != 0 ? priorY + ((x - priorX) / (priorX2 - priorX) * (priorY2 - priorY)) : priorY; - extList.Add(ext); + extList.AddRounded(ext); var signal = GetCompareSignal(currentValue - ext, prevY - prevExt); signalsList.Add(signal); @@ -2719,15 +2719,15 @@ public static StockData CalculateLinearRegressionLine(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - yList.Add(currentValue); + decimal currentValue = inputList[i]; + yList.AddRounded(currentValue); decimal x = i; - xList.Add(x); + xList.AddRounded(x); var corr = GoodnessOfFit.R(yList.TakeLastExt(length).Select(x => (double)x), xList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } var xMaList = GetMovingAverageList(stockData, maType, length, xList); @@ -2735,20 +2735,20 @@ public static StockData CalculateLinearRegressionLine(this StockData stockData, var mxList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; ; for (int i = 0; i < stockData.Count; i++) { - decimal my = myList.ElementAtOrDefault(i); - decimal mx = mxList.ElementAtOrDefault(i); - decimal corr = corrList.ElementAtOrDefault(i); - decimal yMa = yMaList.ElementAtOrDefault(i); - decimal xMa = xMaList.ElementAtOrDefault(i); - decimal x = xList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal my = myList[i]; + decimal mx = mxList[i]; + decimal corr = corrList[i]; + decimal yMa = yMaList[i]; + decimal xMa = xMaList[i]; + decimal x = xList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal slope = mx != 0 ? corr * (my / mx) : 0; decimal inter = yMa - (slope * xMa); decimal prevReg = regList.LastOrDefault(); decimal reg = (x * slope) + inter; - regList.Add(reg); + regList.AddRounded(reg); var signal = GetCompareSignal(currentValue - reg, prevValue - prevReg); signalsList.Add(signal); @@ -2783,16 +2783,16 @@ public static StockData CalculateIIRLeastSquaresEstimate(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal prevS = i >= 1 ? sList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevS = i >= 1 ? sList[i - 1] : currentValue; decimal prevSEma = sEmaList.LastOrDefault(); decimal sEma = CalculateEMA(prevS, prevSEma, halfLength); - sEmaList.Add(prevSEma); + sEmaList.AddRounded(prevSEma); decimal s = (a * currentValue) + prevS - (a * sEma); - sList.Add(s); + sList.AddRounded(s); var signal = GetCompareSignal(currentValue - s, prevValue - prevS); signalsList.Add(signal); @@ -2823,18 +2823,18 @@ public static StockData CalculateInverseDistanceWeightedMovingAverage(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; decimal weight = 0; for (int k = 0; k <= length - 1; k++) { - decimal prevValue2 = i >= k ? inputList.ElementAtOrDefault(i - k) : 0; + decimal prevValue2 = i >= k ? inputList[i - k] : 0; weight += Math.Abs(prevValue - prevValue2); } @@ -2844,7 +2844,7 @@ public static StockData CalculateInverseDistanceWeightedMovingAverage(this Stock decimal prevIdwma = idwmaList.LastOrDefault(); decimal idwma = weightedSum != 0 ? sum / weightedSum : 0; - idwmaList.Add(idwma); + idwmaList.AddRounded(idwma); var signal = GetCompareSignal(currentValue - idwma, prevVal - prevIdwma); signalsList.Add(signal); @@ -2880,23 +2880,23 @@ public static StockData CalculateTrimean(this StockData stockData, int length = for (int i = 0; i < stockData.Count; i++) { decimal prevValue = tempList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); var lookBackList = tempList.TakeLastExt(length); decimal q1 = lookBackList.PercentileNearestRank(25); - q1List.Add(q1); + q1List.AddRounded(q1); decimal median = lookBackList.PercentileNearestRank(50); - medianList.Add(median); + medianList.AddRounded(median); decimal q3 = lookBackList.PercentileNearestRank(75); - q3List.Add(q3); + q3List.AddRounded(q3); decimal prevTrimean = trimeanList.LastOrDefault(); decimal trimean = (q1 + (2 * median) + q3) / 4; - trimeanList.Add(trimean); + trimeanList.AddRounded(trimean); var signal = GetCompareSignal(currentValue - trimean, prevValue - prevTrimean); signalsList.Add(signal); @@ -2933,11 +2933,11 @@ public static StockData CalculateOptimalWeightedMovingAverage(this StockData sto for (int i = 0; i < stockData.Count; i++) { decimal prevVal = tempList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal prevOwma = i >= 1 ? owmaList.ElementAtOrDefault(i - 1) : 0; - prevOwmaList.Add(prevOwma); + decimal 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; @@ -2946,14 +2946,14 @@ public static StockData CalculateOptimalWeightedMovingAverage(this StockData sto for (int j = 0; j <= length - 1; j++) { decimal weight = Pow(length - j, (decimal)corr); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } decimal owma = weightedSum != 0 ? sum / weightedSum : 0; - owmaList.Add(owma); + owmaList.AddRounded(owma); var signal = GetCompareSignal(currentValue - owma, prevVal - prevOwma); signalsList.Add(signal); @@ -2994,14 +2994,14 @@ public static StockData CalculateOvershootReductionMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); var corr = GoodnessOfFit.R(indexList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } var indexSmaList = GetMovingAverageList(stockData, maType, length, indexList); @@ -3011,28 +3011,28 @@ public static StockData CalculateOvershootReductionMovingAverage(this StockData var indexStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal index = indexList.ElementAtOrDefault(i); - decimal indexSma = indexSmaList.ElementAtOrDefault(i); - decimal indexStdDev = indexStdDevList.ElementAtOrDefault(i); - decimal corr = corrList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevD = i >= 1 ? dList.ElementAtOrDefault(i - 1) != 0 ? dList.ElementAtOrDefault(i - 1) : prevValue : prevValue; - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal index = indexList[i]; + decimal indexSma = indexSmaList[i]; + decimal indexStdDev = indexStdDevList[i]; + decimal corr = corrList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevD = i >= 1 ? dList[i - 1] != 0 ? dList[i - 1] : prevValue : prevValue; + decimal sma = smaList[i]; + decimal stdDev = stdDevList[i]; decimal a = indexStdDev != 0 && corr != 0 ? (index - indexSma) / indexStdDev * corr : 0; decimal b = Math.Abs(prevD - currentValue); - bList.Add(b); + bList.AddRounded(b); decimal bSma = bList.TakeLastExt(length1).Average(); - bSmaList.Add(bSma); + bSmaList.AddRounded(bSma); decimal highest = bSmaList.TakeLastExt(length).Max(); decimal c = highest != 0 ? b / highest : 0; decimal d = sma + (a * (stdDev * c)); - dList.Add(d); + dList.AddRounded(d); var signal = GetCompareSignal(currentValue - d, prevValue - prevD); signalsList.Add(signal); @@ -3069,13 +3069,13 @@ public static StockData CalculateVariableIndexDynamicAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentCmo = Math.Abs(cmoList.ElementAtOrDefault(i) / 100); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentCmo = Math.Abs(cmoList[i] / 100); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevVidya = vidyaList.LastOrDefault(); decimal currentVidya = (currentValue * alpha * currentCmo) + (prevVidya * (1 - (alpha * currentCmo))); - vidyaList.Add(currentVidya); + vidyaList.AddRounded(currentVidya); var signal = GetCompareSignal(currentValue - currentVidya, prevValue - prevVidya); signalsList.Add(signal); @@ -3107,17 +3107,17 @@ public static StockData CalculateNaturalMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ln = currentValue > 0 ? Log(currentValue) * 1000 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); decimal num = 0, denom = 0; for (int j = 0; j < length; j++) { - decimal currentLn = i >= j ? lnList.ElementAtOrDefault(i - j) : 0; - decimal prevLn = i >= j + 1 ? lnList.ElementAtOrDefault(i - (j + 1)) : 0; + decimal currentLn = i >= j ? lnList[i - j] : 0; + decimal prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; decimal oi = Math.Abs(currentLn - prevLn); num += oi * (Sqrt(j + 1) - Sqrt(j)); denom += oi; @@ -3126,7 +3126,7 @@ public static StockData CalculateNaturalMovingAverage(this StockData stockData, decimal ratio = denom != 0 ? num / denom : 0; decimal prevNma = nmaList.LastOrDefault(); decimal nma = (currentValue * ratio) + (prevValue * (1 - ratio)); - nmaList.Add(nma); + nmaList.AddRounded(nma); var signal = GetCompareSignal(currentValue - nma, prevValue - prevNma); signalsList.Add(signal); @@ -3160,8 +3160,8 @@ public static StockData CalculateSymmetricallyWeightedMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal nr = 0, nl = 0, sr = 0, sl = 0; if (floorLength == roundLength) @@ -3169,7 +3169,7 @@ public static StockData CalculateSymmetricallyWeightedMovingAverage(this StockDa for (int j = 0; j <= floorLength - 1; j++) { decimal wr = (length - (length - 1 - j)) * length; - decimal prevVal = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevVal = i >= j ? inputList[i - j] : 0; nr += wr; sr += prevVal * wr; } @@ -3177,7 +3177,7 @@ public static StockData CalculateSymmetricallyWeightedMovingAverage(this StockDa for (int j = floorLength; j <= length - 1; j++) { decimal wl = (length - j) * length; - decimal prevVal = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevVal = i >= j ? inputList[i - j] : 0; nl += wl; sl += prevVal * wl; } @@ -3187,7 +3187,7 @@ public static StockData CalculateSymmetricallyWeightedMovingAverage(this StockDa for (int j = 0; j <= floorLength; j++) { decimal wr = (length - (length - 1 - j)) * length; - decimal prevVal = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevVal = i >= j ? inputList[i - j] : 0; nr += wr; sr += prevVal * wr; } @@ -3195,7 +3195,7 @@ public static StockData CalculateSymmetricallyWeightedMovingAverage(this StockDa for (int j = roundLength; j <= length - 1; j++) { decimal wl = (length - j) * length; - decimal prevVal = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevVal = i >= j ? inputList[i - j] : 0; nl += wl; sl += prevVal * wl; } @@ -3240,14 +3240,14 @@ public static StockData CalculateGeneralizedDoubleExponentialMovingAverage(this for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentEma1 = ema1List.ElementAtOrDefault(i); - decimal currentEma2 = ema2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentEma1 = ema1List[i]; + decimal currentEma2 = ema2List[i]; decimal prevGd = gdList.LastOrDefault(); decimal gd = (currentEma1 * (1 + factor)) - (currentEma2 * factor); - gdList.Add(gd); + gdList.AddRounded(gd); var signal = GetCompareSignal(currentValue - gd, prevValue - prevGd); signalsList.Add(signal); @@ -3285,21 +3285,21 @@ public static StockData CalculateGeneralFilterEstimator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorB = i >= p ? bList.ElementAtOrDefault(i - p) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorB = i >= p ? bList[i - p] : currentValue; decimal a = currentValue - priorB; - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; decimal b = prevB + (a / p * gamma); - bList.Add(b); + bList.AddRounded(b); - decimal priorD = i >= p ? dList.ElementAtOrDefault(i - p) : b; + decimal priorD = i >= p ? dList[i - p] : b; decimal c = b - priorD; - decimal prevD = i >= 1 ? dList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevD = i >= 1 ? dList[i - 1] : currentValue; decimal d = prevD + (((zeta * a) + ((1 - zeta) * c)) / p * gamma); - dList.Add(d); + dList.AddRounded(d); var signal = GetCompareSignal(currentValue - d, prevValue - prevD); signalsList.Add(signal); @@ -3332,8 +3332,8 @@ public static StockData CalculateHendersonWeightedMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) @@ -3345,7 +3345,7 @@ public static StockData CalculateHendersonWeightedMovingAverage(this StockData s decimal 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); decimal weight = denominator != 0 ? numerator / denominator : 0; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -3353,7 +3353,7 @@ public static StockData CalculateHendersonWeightedMovingAverage(this StockData s decimal prevHwma = hwmaList.LastOrDefault(); decimal hwma = weightedSum != 0 ? sum / weightedSum : 0; - hwmaList.Add(hwma); + hwmaList.AddRounded(hwma); var signal = GetCompareSignal(currentValue - hwma, prevVal - prevHwma); signalsList.Add(signal); @@ -3389,16 +3389,16 @@ public static StockData CalculateHoltExponentialMovingAverage(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevHema = hemaList.LastOrDefault(); decimal hema = ((1 - alpha) * (prevHema + prevB)) + (alpha * currentValue); - hemaList.Add(hema); + hemaList.AddRounded(hema); decimal b = ((1 - gamma) * prevB) + (gamma * (hema - prevHema)); - bList.Add(b); + bList.AddRounded(b); var signal = GetCompareSignal(currentValue - hema, prevValue - prevHema); signalsList.Add(signal); @@ -3434,14 +3434,14 @@ public static StockData CalculateHullEstimate(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentWma = wmaList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentWma = wmaList[i]; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevHema = hemaList.LastOrDefault(); decimal hema = (3 * currentWma) - (2 * currentEma); - hemaList.Add(hema); + hemaList.AddRounded(hema); var signal = GetCompareSignal(currentValue - hema, prevValue - prevHema); signalsList.Add(signal); @@ -3479,20 +3479,20 @@ public static StockData CalculateHampelFilter(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { decimal prevValue = tempList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal sampleMedian = tempList.TakeLastExt(length).Median(); decimal absDiff = Math.Abs(currentValue - sampleMedian); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal mad = absDiffList.TakeLastExt(length).Median(); decimal hf = absDiff <= scalingFactor * mad ? currentValue : sampleMedian; - hfList.Add(hf); + hfList.AddRounded(hf); decimal prevHfEma = hfEmaList.LastOrDefault(); decimal hfEma = (alpha * hf) + ((1 - alpha) * prevHfEma); - hfEmaList.Add(hfEma); + hfEmaList.AddRounded(hfEma); var signal = GetCompareSignal(currentValue - hfEma, prevValue - prevHfEma); signalsList.Add(signal); @@ -3523,19 +3523,19 @@ public static StockData CalculateHybridConvolutionFilter(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; - decimal prevOutput = i >= 1 ? outputList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevOutput = i >= 1 ? outputList[i - 1] : currentValue; decimal output = 0; for (int j = 1; j <= length; j++) { decimal sign = (0.5m * (1 - Cos(MinOrMax((decimal)j / length * Pi, 0.99m, 0.01m)))); decimal d = sign - (0.5m * (1 - Cos(MinOrMax((decimal)(j - 1) / length, 0.99m, 0.01m)))); - decimal prevValue = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; output += ((sign * prevOutput) + ((1 - sign) * prevValue)) * d; } - outputList.Add(output); + outputList.AddRounded(output); var signal = GetCompareSignal(currentValue - output, prevVal - prevOutput); signalsList.Add(signal); @@ -3568,15 +3568,15 @@ public static StockData CalculateFibonacciWeightedMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal pow = Pow(phi, length - j); decimal weight = (pow - (Pow(-1, j) / pow)) / Sqrt(5); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -3584,7 +3584,7 @@ public static StockData CalculateFibonacciWeightedMovingAverage(this StockData s decimal prevFwma = fibonacciWmaList.LastOrDefault(); decimal fwma = weightedSum != 0 ? sum / weightedSum : 0; - fibonacciWmaList.Add(fwma); + fibonacciWmaList.AddRounded(fwma); var signal = GetCompareSignal(currentValue - fwma, prevVal - prevFwma); signalsList.Add(signal); @@ -3635,14 +3635,14 @@ public static StockData CalculateFareySequenceWeightedMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; - for (int k = 0; k < resList.Count; k++) + for (int j = 0; j < resList.Count; j++) { - decimal prevValue = i >= k ? inputList.ElementAtOrDefault(i - k) : 0; - decimal weight = resList.ElementAtOrDefault(k); + decimal prevValue = i >= j ? inputList[i - j] : 0; + decimal weight = resList[j]; sum += prevValue * weight; weightedSum += weight; @@ -3650,7 +3650,7 @@ public static StockData CalculateFareySequenceWeightedMovingAverage(this StockDa decimal prevFswma = fswmaList.LastOrDefault(); decimal fswma = weightedSum != 0 ? sum / weightedSum : 0; - fswmaList.Add(fswma); + fswmaList.AddRounded(fswma); var signal = GetCompareSignal(currentValue - fswma, prevVal - prevFswma); signalsList.Add(signal); @@ -3686,15 +3686,15 @@ public static StockData CalculateEhlersFractalAdaptiveMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevFilter = i >= 1 ? filterList.LastOrDefault() : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal highestHigh1 = highestList1.ElementAtOrDefault(i); - decimal lowestLow1 = lowestList1.ElementAtOrDefault(i); - decimal highestHigh2 = highestList2.ElementAtOrDefault(i); - decimal lowestLow2 = lowestList2.ElementAtOrDefault(i); - decimal highestHigh3 = highestList2.ElementAtOrDefault(Math.Max(i - halfP, i)); - decimal lowestLow3 = lowestList2.ElementAtOrDefault(Math.Max(i - halfP, i)); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal highestHigh1 = highestList1[i]; + decimal lowestLow1 = lowestList1[i]; + decimal highestHigh2 = highestList2[i]; + decimal lowestLow2 = lowestList2[i]; + decimal highestHigh3 = highestList2[Math.Max(i - halfP, i)]; + decimal lowestLow3 = lowestList2[Math.Max(i - halfP, i)]; decimal n3 = (highestHigh1 - lowestLow1) / length; decimal n1 = (highestHigh2 - lowestLow2) / halfP; decimal n2 = (highestHigh3 - lowestLow3) / halfP; @@ -3702,7 +3702,7 @@ public static StockData CalculateEhlersFractalAdaptiveMovingAverage(this StockDa decimal alpha = MinOrMax(Exp(-4.6m * (dm - 1)), 1, 0.01m); decimal filter = (alpha * currentValue) + ((1 - alpha) * prevFilter); - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter); signalsList.Add(signal); @@ -3737,20 +3737,20 @@ public static StockData CalculateFallingRisingFilter(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : 0; - decimal prevError = i >= 1 ? errorList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : 0; + decimal prevError = i >= 1 ? errorList[i - 1] : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - tempList.Add(prevValue); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + tempList.AddRounded(prevValue); var lbList = tempList.TakeLastExt(length).ToList(); decimal beta = currentValue > lbList.Max() || currentValue < lbList.Min() ? 1 : alpha; decimal a = prevA + (alpha * prevError) + (beta * prevError); - aList.Add(a); + aList.AddRounded(a); decimal error = currentValue - a; - errorList.Add(error); + errorList.AddRounded(error); var signal = GetCompareSignal(error, prevError); signalsList.Add(signal); @@ -3790,7 +3790,7 @@ public static StockData CalculateFisherLeastSquaresMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); } stockData.CustomValuesList = indexList; @@ -3798,19 +3798,19 @@ public static StockData CalculateFisherLeastSquaresMovingAverage(this StockData var indexSmaList = GetMovingAverageList(stockData, maType, length, indexList); for (int i = 0; i < stockData.Count; i++) { - decimal stdDevSrc = stdDevSrcList.ElementAtOrDefault(i); - decimal indexStdDev = indexStdDevList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal indexSma = indexSmaList.ElementAtOrDefault(i); - decimal sma = smaSrcList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal stdDevSrc = stdDevSrcList[i]; + decimal indexStdDev = indexStdDevList[i]; + decimal currentValue = inputList[i]; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; + decimal indexSma = indexSmaList[i]; + decimal sma = smaSrcList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal diff = currentValue - prevB; - diffList.Add(diff); + diffList.AddRounded(diff); decimal absDiff = Math.Abs(diff); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal e = absDiffList.TakeLastExt(length).Average(); decimal z = e != 0 ? diffList.TakeLastExt(length).Average() / e : 0; @@ -3818,7 +3818,7 @@ public static StockData CalculateFisherLeastSquaresMovingAverage(this StockData decimal a = indexStdDev != 0 && r != 0 ? (i - indexSma) / indexStdDev * r : 0; decimal b = sma + (a * stdDevSrc); - bList.Add(b); + bList.AddRounded(b); var signal = GetCompareSignal(currentValue - b, prevValue - prevB); signalsList.Add(signal); @@ -3859,25 +3859,25 @@ public static StockData CalculateKaufmanAdaptiveLeastSquaresMovingAverage(this S for (int i = 0; i < stockData.Count; i++) { decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); } var indexMaList = GetMovingAverageList(stockData, maType, length, indexList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - var indexSt = indexStList.ElementAtOrDefault(i); - var srcSt = srcStList.ElementAtOrDefault(i); - var srcMa = srcMaList.ElementAtOrDefault(i); - var indexMa = indexMaList.ElementAtOrDefault(i); - var r = rList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + var indexSt = indexStList[i]; + var srcSt = srcStList[i]; + var srcMa = srcMaList[i]; + var indexMa = indexMaList[i]; + var r = rList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal alpha = indexSt != 0 ? srcSt / indexSt * r : 0; decimal beta = srcMa - (alpha * indexMa); decimal prevKalsma = kalsmaList.LastOrDefault(); decimal kalsma = (alpha * i) + beta; - kalsmaList.Add(kalsma); + kalsmaList.AddRounded(kalsma); var signal = GetCompareSignal(currentValue - kalsma, prevValue - prevKalsma); signalsList.Add(signal); @@ -3909,18 +3909,18 @@ public static StockData CalculateKalmanSmoother(this StockData stockData, int le for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevKf = i >= 1 ? kfList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevKf = i >= 1 ? kfList[i - 1] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal dk = currentValue - prevKf; decimal smooth = prevKf + (dk * Sqrt((decimal)length / 10000 * 2)); - decimal prevVelo = i >= 1 ? veloList.ElementAtOrDefault(i - 1) : 0; + decimal prevVelo = i >= 1 ? veloList[i - 1] : 0; decimal velo = prevVelo + ((decimal)length / 10000 * dk); - veloList.Add(velo); + veloList.AddRounded(velo); decimal kf = smooth + velo; - kfList.Add(kf); + kfList.AddRounded(kf); var signal = GetCompareSignal(currentValue - kf, prevValue - prevKf); signalsList.Add(signal); @@ -3960,27 +3960,27 @@ public static StockData CalculateVolumeAdjustedMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal volumeSma = volumeSmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentVolume = volumeList[i]; + decimal currentValue = inputList[i]; + decimal volumeSma = volumeSmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal volumeIncrement = volumeSma * factor; decimal volumeRatio = volumeIncrement != 0 ? currentVolume / volumeIncrement : 0; - volumeRatioList.Add(volumeRatio); + volumeRatioList.AddRounded(volumeRatio); decimal priceVolumeRatio = currentValue * volumeRatio; - priceVolumeRatioList.Add(priceVolumeRatio); + priceVolumeRatioList.AddRounded(priceVolumeRatio); decimal volumeRatioSum = volumeRatioList.TakeLastExt(length).Sum(); - volumeRatioSumList.Add(volumeRatioSum); + volumeRatioSumList.AddRounded(volumeRatioSum); decimal priceVolumeRatioSum = priceVolumeRatioList.TakeLastExt(length).Sum(); - priceVolumeRatioSumList.Add(priceVolumeRatioSum); + priceVolumeRatioSumList.AddRounded(priceVolumeRatioSum); decimal prevVama = vamaList.LastOrDefault(); decimal vama = volumeRatioSum != 0 ? priceVolumeRatioSum / volumeRatioSum : 0; - vamaList.Add(vama); + vamaList.AddRounded(vama); var signal = GetCompareSignal(currentValue - vama, prevValue - prevVama); signalsList.Add(signal); @@ -4020,44 +4020,44 @@ public static StockData CalculateVolatilityWaveMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal stdDev = stdDevList[i]; + decimal currentValue = inputList[i]; decimal sdPct = currentValue != 0 ? stdDev / currentValue * 100 : 0; decimal p = sdPct >= 0 ? MinOrMax(Sqrt(sdPct) * kf, 4, 1) : 1; - pList.Add(p); + pList.AddRounded(p); } for (int i = 0; i < stockData.Count; i++) { - decimal p = pList.ElementAtOrDefault(i); + decimal p = pList[i]; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = Pow(length - j, p); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } decimal pma = weightedSum != 0 ? sum / weightedSum : 0; - pmaList.Add(pma); + 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++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal wmap1 = wmap1List.ElementAtOrDefault(i); - decimal wmap2 = wmap2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal wmap1 = wmap1List[i]; + decimal wmap2 = wmap2List[i]; decimal prevZlmap = zlmapList.LastOrDefault(); decimal zlmap = (2 * wmap1) - wmap2; - zlmapList.Add(zlmap); + zlmapList.AddRounded(zlmap); var signal = GetCompareSignal(currentValue - zlmap, prevValue - prevZlmap); signalsList.Add(signal); @@ -4095,17 +4095,17 @@ public static StockData CalculateVariableAdaptiveMovingAverage(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal c = cList.ElementAtOrDefault(i); - decimal o = oList.ElementAtOrDefault(i); - decimal h = hList.ElementAtOrDefault(i); - decimal l = lList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal c = cList[i]; + decimal o = oList[i]; + decimal h = hList[i]; + decimal l = lList[i]; decimal lv = h - l != 0 ? MinOrMax(Math.Abs(c - o) / (h - l), 0.99m, 0.01m) : 0; - decimal prevVma = i >= 1 ? vmaList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevVma = i >= 1 ? vmaList[i - 1] : currentValue; decimal vma = (lv * currentValue) + ((1 - lv) * prevVma); - vmaList.Add(vma); + vmaList.AddRounded(vma); var signal = GetCompareSignal(currentValue - vma, prevValue - prevVma); signalsList.Add(signal); @@ -4143,18 +4143,18 @@ public static StockData CalculateVariableMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal pdm = Math.Max(currentValue - prevValue, 0); decimal mdm = Math.Max(prevValue - currentValue, 0); decimal prevPdms = pdmsList.LastOrDefault(); decimal pdmS = ((1 - k) * prevPdms) + (k * pdm); - pdmsList.Add(pdmS); + pdmsList.AddRounded(pdmS); decimal prevMdms = mdmsList.LastOrDefault(); decimal mdmS = ((1 - k) * prevMdms) + (k * mdm); - mdmsList.Add(mdmS); + mdmsList.AddRounded(mdmS); decimal s = pdmS + mdmS; decimal pdi = s != 0 ? pdmS / s : 0; @@ -4162,11 +4162,11 @@ public static StockData CalculateVariableMovingAverage(this StockData stockData, decimal prevPdis = pdisList.LastOrDefault(); decimal pdiS = ((1 - k) * prevPdis) + (k * pdi); - pdisList.Add(pdiS); + pdisList.AddRounded(pdiS); decimal prevMdis = mdisList.LastOrDefault(); decimal mdiS = ((1 - k) * prevMdis) + (k * mdi); - mdisList.Add(mdiS); + mdisList.AddRounded(mdiS); decimal d = Math.Abs(pdiS - mdiS); decimal s1 = pdiS + mdiS; @@ -4174,7 +4174,7 @@ public static StockData CalculateVariableMovingAverage(this StockData stockData, decimal prevIs = isList.LastOrDefault(); decimal iS = ((1 - k) * prevIs) + (k * dS1); - isList.Add(iS); + isList.AddRounded(iS); var lbList = isList.TakeLastExt(length).ToList(); decimal hhv = lbList.Max(); @@ -4184,7 +4184,7 @@ public static StockData CalculateVariableMovingAverage(this StockData stockData, decimal prevVma = vmaList.LastOrDefault(); decimal vma = ((1 - k) * vI * prevVma) + (k * vI * currentValue); - vmaList.Add(vma); + vmaList.AddRounded(vma); var signal = GetCompareSignal(currentValue - vma, prevValue - prevVma); signalsList.Add(signal); @@ -4224,20 +4224,20 @@ public static StockData CalculateVolatilityMovingAverage(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal sma = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal dev = stdDevList.ElementAtOrDefault(i); + decimal sma = smaList[i]; + decimal currentValue = inputList[i]; + decimal dev = stdDevList[i]; decimal upper = sma + dev; decimal lower = sma - dev; decimal k = upper - lower != 0 ? (currentValue - sma) / (upper - lower) * 100 * 2 : 0; - kList.Add(k); + kList.AddRounded(k); } var kMaList = GetMovingAverageList(stockData, maType, smoothLength, kList); for (int i = 0; i < stockData.Count; i++) { - decimal kMa = kMaList.ElementAtOrDefault(i); + decimal kMa = kMaList[i]; decimal kNorm = Math.Min(Math.Max(kMa, -100), 100); decimal kAbs = Math.Round(Math.Abs(kNorm) / lbLength); decimal kRescaled = RescaleValue(kAbs, 10, 0, length, 0, true); @@ -4247,23 +4247,23 @@ public static StockData CalculateVolatilityMovingAverage(this StockData stockDat for (int j = 0; j <= vLength - 1; j++) { decimal weight = vLength - j; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } decimal vma1 = weightedSum != 0 ? sum / weightedSum : 0; - vma1List.Add(vma1); + vma1List.AddRounded(vma1); } var vma2List = GetMovingAverageList(stockData, maType, smoothLength, vma1List); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal vma = vma2List.ElementAtOrDefault(i); - decimal prevVma = i >= 1 ? vma2List.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal vma = vma2List[i]; + decimal prevVma = i >= 1 ? vma2List[i - 1] : 0; var signal = GetCompareSignal(currentValue - vma, prevValue - prevVma); signalsList.Add(signal); @@ -4296,14 +4296,14 @@ public static StockData CalculateVerticalHorizontalMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal priorValue = i >= length ? inputList[i - length] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal priceChange = Math.Abs(currentValue - priorValue); - changeList.Add(priceChange); + changeList.AddRounded(priceChange); decimal numerator = highest - lowest; decimal denominator = changeList.TakeLastExt(length).Sum(); @@ -4311,7 +4311,7 @@ public static StockData CalculateVerticalHorizontalMovingAverage(this StockData decimal prevVhma = vhmaList.LastOrDefault(); decimal vhma = prevVhma + (Pow(vhf, 2) * (currentValue - prevVhma)); - vhmaList.Add(vhma); + vhmaList.AddRounded(vhma); var signal = GetCompareSignal(currentValue - vhma, prevValue - prevVhma); signalsList.Add(signal); @@ -4349,14 +4349,14 @@ public static StockData CalculateMcNichollMovingAverage(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ema1 = ema1List.ElementAtOrDefault(i); - decimal ema2 = ema2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ema1 = ema1List[i]; + decimal ema2 = ema2List[i]; decimal prevMnma = mnmaList.LastOrDefault(); decimal mnma = 1 - alpha != 0 ? (((2 - alpha) * ema1) - ema2) / (1 - alpha) : 0; - mnmaList.Add(mnma); + mnmaList.AddRounded(mnma); var signal = GetCompareSignal(currentValue - mnma, prevValue - prevMnma); signalsList.Add(signal); @@ -4396,23 +4396,23 @@ public static StockData CalculateCompoundRatioMovingAverage(this StockData stock for (int j = 0; j <= length - 1; j++) { decimal weight = Pow(bas, length - i); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; } decimal coraRaw = weightedSum != 0 ? sum / weightedSum : 0; - coraRawList.Add(coraRaw); + coraRawList.AddRounded(coraRaw); } var coraWaveList = GetMovingAverageList(stockData, maType, smoothLength, coraRawList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal coraWave = coraWaveList.ElementAtOrDefault(i); - decimal prevCoraWave = i >= 1 ? coraWaveList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal coraWave = coraWaveList[i]; + decimal prevCoraWave = i >= 1 ? coraWaveList[i - 1] : 0; var signal = GetCompareSignal(currentValue - coraWave, prevValue - prevCoraWave); signalsList.Add(signal); @@ -4443,14 +4443,14 @@ public static StockData CalculateCubedWeightedMovingAverage(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = Pow(length - j, 3); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -4458,7 +4458,7 @@ public static StockData CalculateCubedWeightedMovingAverage(this StockData stock decimal prevCwma = cwmaList.LastOrDefault(); decimal cwma = weightedSum != 0 ? sum / weightedSum : 0; - cwmaList.Add(cwma); + cwmaList.AddRounded(cwma); var signal = GetCompareSignal(currentValue - cwma, prevVal - prevCwma); signalsList.Add(signal); @@ -4494,11 +4494,11 @@ public static StockData CalculateCorrectedMovingAverage(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevCma = i >= 1 ? cmaList.ElementAtOrDefault(i - 1) : sma; - decimal v1 = v1List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = smaList[i]; + decimal prevCma = i >= 1 ? cmaList[i - 1] : sma; + decimal v1 = v1List[i]; decimal v2 = Pow(prevCma - sma, 2); decimal v3 = v1 == 0 || v2 == 0 ? 1 : v2 / (v1 + v2); @@ -4514,7 +4514,7 @@ public static StockData CalculateCorrectedMovingAverage(this StockData stockData } decimal cma = prevCma + (k * (sma - prevCma)); - cmaList.Add(cma); + cmaList.AddRounded(cma); var signal = GetCompareSignal(currentValue - cma, prevValue - prevCma); signalsList.Add(signal); @@ -4550,14 +4550,14 @@ public static StockData CalculateDoubleExponentialMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentEma = ema1List.ElementAtOrDefault(i); - decimal currentEma2 = ema2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentEma = ema1List[i]; + decimal currentEma2 = ema2List[i]; decimal prevDema = demaList.LastOrDefault(); decimal dema = (2 * currentEma) - currentEma2; - demaList.Add(dema); + demaList.AddRounded(dema); var signal = GetCompareSignal(currentValue - dema, prevValue - prevDema); signalsList.Add(signal); @@ -4599,20 +4599,20 @@ public static StockData CalculatePentupleExponentialMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ema1 = ema1List.ElementAtOrDefault(i); - decimal ema2 = ema2List.ElementAtOrDefault(i); - decimal ema3 = ema3List.ElementAtOrDefault(i); - decimal ema4 = ema4List.ElementAtOrDefault(i); - decimal ema5 = ema5List.ElementAtOrDefault(i); - decimal ema6 = ema6List.ElementAtOrDefault(i); - decimal ema7 = ema7List.ElementAtOrDefault(i); - decimal ema8 = ema8List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ema1 = ema1List[i]; + decimal ema2 = ema2List[i]; + decimal ema3 = ema3List[i]; + decimal ema4 = ema4List[i]; + decimal ema5 = ema5List[i]; + decimal ema6 = ema6List[i]; + decimal ema7 = ema7List[i]; + decimal ema8 = ema8List[i]; decimal prevPema = pemaList.LastOrDefault(); decimal pema = (8 * ema1) - (28 * ema2) + (56 * ema3) - (70 * ema4) + (56 * ema5) - (28 * ema6) + (8 * ema7) - ema8; - pemaList.Add(pema); + pemaList.AddRounded(pema); var signal = GetCompareSignal(currentValue - pema, prevValue - prevPema); signalsList.Add(signal); @@ -4643,14 +4643,14 @@ public static StockData CalculatePolynomialLeastSquaresMovingAverage(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal prevSumPow3 = sumPow3List.LastOrDefault(); decimal x1Pow1Sum, x2Pow1Sum, x1Pow2Sum, x2Pow2Sum, x1Pow3Sum, x2Pow3Sum, wPow1, wPow2, wPow3, sumPow1 = 0, sumPow2 = 0, sumPow3 = 0; for (int j = 1; j <= length; j++) { - decimal prevValue = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; decimal x1 = (decimal)j / length; decimal x2 = (decimal)(j - 1) / length; decimal ax1 = x1 * x1; @@ -4683,7 +4683,7 @@ public static StockData CalculatePolynomialLeastSquaresMovingAverage(this StockD wPow3 = x1Pow3Sum - x2Pow3Sum; sumPow3 += prevValue * wPow3; } - sumPow3List.Add(sumPow3); + sumPow3List.AddRounded(sumPow3); var signal = GetCompareSignal(currentValue - sumPow3, prevVal - prevSumPow3); signalsList.Add(signal); @@ -4722,21 +4722,21 @@ public static StockData CalculateParametricCorrectiveLinearMovingAverage(this St for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal p1 = i + 1 - (per / 100 * length); decimal p2 = i + 1 - ((100 - per) / 100 * length); decimal w1 = p1 >= 0 ? p1 : alpha * p1; - w1List.Add(w1); + w1List.AddRounded(w1); decimal w2 = p2 >= 0 ? p2 : alpha * p2; - w2List.Add(w2); + w2List.AddRounded(w2); decimal vw1 = prevValue * w1; - vw1List.Add(vw1); + vw1List.AddRounded(vw1); decimal vw2 = prevValue * w2; - vw2List.Add(vw2); + vw2List.AddRounded(vw2); decimal wSum1 = w1List.TakeLastExt(length).Sum(); decimal wSum2 = w2List.TakeLastExt(length).Sum(); @@ -4745,11 +4745,11 @@ public static StockData CalculateParametricCorrectiveLinearMovingAverage(this St decimal prevRrma1 = rrma1List.LastOrDefault(); decimal rrma1 = wSum1 != 0 ? sum1 / wSum1 : 0; - rrma1List.Add(rrma1); + rrma1List.AddRounded(rrma1); decimal prevRrma2 = rrma2List.LastOrDefault(); decimal rrma2 = wSum2 != 0 ? sum2 / wSum2 : 0; - rrma2List.Add(rrma2); + rrma2List.AddRounded(rrma2); var signal = GetCompareSignal(rrma1 - rrma2, prevRrma1 - prevRrma2); signalsList.Add(signal); @@ -4780,14 +4780,14 @@ public static StockData CalculateParabolicWeightedMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = Pow(length - j, 2); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -4795,7 +4795,7 @@ public static StockData CalculateParabolicWeightedMovingAverage(this StockData s decimal prevPwma = pwmaList.LastOrDefault(); decimal pwma = weightedSum != 0 ? sum / weightedSum : 0; - pwmaList.Add(pwma); + pwmaList.AddRounded(pwma); var signal = GetCompareSignal(currentValue - pwma, prevVal - prevPwma); signalsList.Add(signal); @@ -4827,14 +4827,14 @@ public static StockData CalculateParametricKalmanFilter(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorEst = i >= length ? estList.ElementAtOrDefault(i - length) : prevValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorEst = i >= length ? estList[i - length] : prevValue; decimal errMea = Math.Abs(priorEst - currentValue); decimal errPrv = Math.Abs((currentValue - prevValue) * -1); - decimal prevErr = i >= 1 ? errList.ElementAtOrDefault(i - 1) : errPrv; + decimal prevErr = i >= 1 ? errList[i - 1] : errPrv; decimal kg = prevErr != 0 ? prevErr / (prevErr + errMea) : 0; - decimal prevEst = i >= 1 ? estList.ElementAtOrDefault(i - 1) : prevValue; + decimal prevEst = i >= 1 ? estList[i - 1] : prevValue; decimal est = prevEst + (kg * (currentValue - prevEst)); estList.AddRounded(est); @@ -4882,23 +4882,23 @@ public static StockData CalculateTStepLeastSquaresMovingAverage(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal efRatio = efRatioList.ElementAtOrDefault(i); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; + decimal efRatio = efRatioList[i]; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; decimal er = 1 - efRatio; decimal chg = Math.Abs(currentValue - prevB); - chgList.Add(chg); + chgList.AddRounded(chg); decimal a = chgList.Average() * (1 + er); decimal b = currentValue > prevB + a ? currentValue : currentValue < prevB - a ? currentValue : prevB; - bList.Add(b); + bList.AddRounded(b); var corr = GoodnessOfFit.R(bList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } stockData.CustomValuesList = bList; @@ -4906,22 +4906,22 @@ public static StockData CalculateTStepLeastSquaresMovingAverage(this StockData s var bSmaList = GetMovingAverageList(stockData, maType, length, bList); for (int i = 0; i < stockData.Count; i++) { - decimal corr = corrList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal bStdDev = bStdDevList.ElementAtOrDefault(i); - decimal bSma = bSmaList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevLs = i >= 1 ? lsList.ElementAtOrDefault(i - 1) : currentValue; - decimal b = bList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal corr = corrList[i]; + decimal stdDev = stdDevList[i]; + decimal bStdDev = bStdDevList[i]; + decimal bSma = bSmaList[i]; + decimal sma = smaList[i]; + decimal currentValue = inputList[i]; + decimal prevLs = i >= 1 ? lsList[i - 1] : currentValue; + decimal b = bList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal tslsma = (sc * currentValue) + ((1 - sc) * prevLs); decimal alpha = bStdDev != 0 ? corr * stdDev / bStdDev : 0; decimal beta = sma - (alpha * bSma); decimal ls = (alpha * b) + beta; - lsList.Add(ls); + lsList.AddRounded(ls); var signal = GetCompareSignal(currentValue - ls, prevValue - prevLs); signalsList.Add(signal); @@ -4956,16 +4956,16 @@ public static StockData CalculateTillsonIE2(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal sma = smaList.ElementAtOrDefault(i); - decimal a0 = linRegList.ElementAtOrDefault(i); - decimal a1 = i >= 1 ? linRegList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal sma = smaList[i]; + decimal a0 = linRegList[i]; + decimal a1 = i >= 1 ? linRegList[i - 1] : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal m = a0 - a1 + sma; decimal prevIe2 = ie2List.LastOrDefault(); decimal ie2 = (m + a0) / 2; - ie2List.Add(ie2); + ie2List.AddRounded(ie2); var signal = GetCompareSignal(currentValue - ie2, prevValue - prevIe2); signalsList.Add(signal); @@ -5007,19 +5007,19 @@ public static StockData CalculateR2AdaptiveRegression(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal stdDev = stdDevList[i]; + decimal sma = smaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); var lbList = tempList.TakeLastExt(length).Select(x => (double)x); - decimal y1 = linregList.ElementAtOrDefault(i); - y1List.Add(y1); + decimal y1 = linregList[i]; + y1List.AddRounded(y1); - decimal x2 = i >= 1 ? outList.ElementAtOrDefault(i - 1) : currentValue; - x2List.Add(x2); + decimal 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); @@ -5028,7 +5028,7 @@ public static StockData CalculateR2AdaptiveRegression(this StockData stockData, decimal x2Dev = x2 - x2Avg; decimal x2Pow = Pow(x2Dev, 2); - x2PowList.Add(x2Pow); + x2PowList.AddRounded(x2Pow); decimal x2PowAvg = x2PowList.TakeLastExt(length).Average(); decimal x2StdDev = x2PowAvg >= 0 ? Sqrt(x2PowAvg) : 0; @@ -5036,7 +5036,7 @@ public static StockData CalculateR2AdaptiveRegression(this StockData stockData, decimal b = sma - (a * x2Avg); decimal y2 = (a * x2) + b; - y2List.Add(y2); + y2List.AddRounded(y2); var ry1 = Math.Pow(GoodnessOfFit.R(y1List.TakeLastExt(length).Select(x => (double)x), lbList), 2); ry1 = IsValueNullOrInfinity(ry1) ? 0 : ry1; @@ -5045,7 +5045,7 @@ public static StockData CalculateR2AdaptiveRegression(this StockData stockData, decimal prevOutVal = outList.LastOrDefault(); decimal outval = ((decimal)ry1 * y1) + ((decimal)ry2 * y2) + ((1 - (decimal)(ry1 + ry2)) * x2); - outList.Add(outval); + outList.AddRounded(outval); var signal = GetCompareSignal(currentValue - outval, prevValue - prevOutVal); signalsList.Add(signal); @@ -5075,17 +5075,17 @@ public static StockData CalculateRatioOCHLAverager(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal b = currentHigh - currentLow != 0 ? Math.Abs(currentValue - currentOpen) / (currentHigh - currentLow) : 0; decimal c = b > 1 ? 1 : b; - decimal prevD = i >= 1 ? dList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevD = i >= 1 ? dList[i - 1] : currentValue; decimal d = (c * currentValue) + ((1 - c) * prevD); - dList.Add(d); + dList.AddRounded(d); var signal = GetCompareSignal(currentValue - d, prevValue - prevD); signalsList.Add(signal); @@ -5119,13 +5119,13 @@ public static StockData CalculateRegularizedExponentialMovingAverage(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevRema1 = i >= 1 ? remaList.ElementAtOrDefault(i - 1) : 0; - decimal prevRema2 = i >= 2 ? remaList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevRema1 = i >= 1 ? remaList[i - 1] : 0; + decimal prevRema2 = i >= 2 ? remaList[i - 2] : 0; decimal rema = (prevRema1 + (alpha * (currentValue - prevRema1)) + (lambda * ((2 * prevRema1) - prevRema2))) / (lambda + 1); - remaList.Add(rema); + remaList.AddRounded(rema); var signal = GetCompareSignal(currentValue - rema, prevValue - prevRema1); signalsList.Add(signal); @@ -5162,15 +5162,15 @@ public static StockData CalculateRepulsionMovingAverage(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma1 = sma1List.ElementAtOrDefault(i); - decimal sma2 = sma2List.ElementAtOrDefault(i); - decimal sma3 = sma3List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma1 = sma1List[i]; + decimal sma2 = sma2List[i]; + decimal sma3 = sma3List[i]; decimal prevMa = maList.LastOrDefault(); decimal ma = sma3 + sma2 - sma1; - maList.Add(ma); + maList.AddRounded(ma); var signal = GetCompareSignal(currentValue - ma, prevValue - prevMa); signalsList.Add(signal); @@ -5203,12 +5203,12 @@ public static StockData CalculateRetentionAccelerationFilter(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal highest1 = highestList1.ElementAtOrDefault(i); - decimal lowest1 = lowestList1.ElementAtOrDefault(i); - decimal highest2 = highestList2.ElementAtOrDefault(i); - decimal lowest2 = lowestList2.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal highest1 = highestList1[i]; + decimal lowest1 = lowestList1[i]; + decimal highest2 = highestList2[i]; + decimal lowest2 = lowestList2[i]; decimal ar = 2 * (highest1 - lowest1); decimal br = 2 * (highest2 - lowest2); decimal k1 = ar != 0 ? (1 - ar) / ar : 0; @@ -5219,9 +5219,9 @@ public static StockData CalculateRetentionAccelerationFilter(this StockData stoc decimal factor = r1 != 0 ? r2 / r1 : 0; decimal altk = Pow(factor >= 1 ? 1 : factor, Sqrt(length)) * ((decimal)1 / length); - decimal prevAltma = i >= 1 ? altmaList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevAltma = i >= 1 ? altmaList[i - 1] : currentValue; decimal altma = (altk * currentValue) + ((1 - altk) * prevAltma); - altmaList.Add(altma); + altmaList.AddRounded(altma); var signal = GetCompareSignal(currentValue - altma, prevValue - prevAltma); signalsList.Add(signal); @@ -5258,21 +5258,21 @@ public static StockData CalculateReverseEngineeringRelativeStrengthIndex(this St for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevAuc = i >= 1 ? aucList.ElementAtOrDefault(i - 1) : 1; - decimal prevAdc = i >= 1 ? adcList.ElementAtOrDefault(i - 1) : 1; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevAuc = i >= 1 ? aucList[i - 1] : 1; + decimal prevAdc = i >= 1 ? adcList[i - 1] : 1; decimal auc = currentValue > prevValue ? (k * (currentValue - prevValue)) + ((1 - k) * prevAuc) : (1 - k) * prevAuc; - aucList.Add(auc); + aucList.AddRounded(auc); decimal adc = currentValue > prevValue ? ((1 - k) * prevAdc) : (k * (prevValue - currentValue)) + ((1 - k) * prevAdc); - adcList.Add(adc); + adcList.AddRounded(adc); decimal rsiValue = (length - 1) * ((adc * rsiLevel / (100 - rsiLevel)) - auc); decimal prevRevRsi = revRsiList.LastOrDefault(); decimal revRsi = rsiValue >= 0 ? currentValue + rsiValue : currentValue + (rsiValue * (100 - rsiLevel) / rsiLevel); - revRsiList.Add(revRsi); + revRsiList.AddRounded(revRsi); var signal = GetCompareSignal(currentValue - revRsi, prevValue - prevRevRsi); signalsList.Add(signal); @@ -5306,20 +5306,20 @@ public static StockData CalculateRightSidedRickerMovingAverage(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal w = 0, vw = 0; for (int j = 0; j < length; j++) { - decimal prevV = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevV = i >= j ? inputList[i - j] : 0; w += (1 - Pow(j / width, 2)) * Exp(-(Pow(j, 2) / (2 * Pow(width, 2)))); vw += prevV * w; } decimal prevRrma = rrmaList.LastOrDefault(); decimal rrma = w != 0 ? vw / w : 0; - rrmaList.Add(rrma); + rrmaList.AddRounded(rrma); var signal = GetCompareSignal(currentValue - rrma, prevValue - prevRrma); signalsList.Add(signal); @@ -5353,16 +5353,16 @@ public static StockData CalculateRecursiveMovingTrendAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevBot = i >= 1 ? botList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevNRes = i >= 1 ? nResList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevBot = i >= 1 ? botList[i - 1] : currentValue; + decimal prevNRes = i >= 1 ? nResList[i - 1] : currentValue; decimal bot = ((1 - alpha) * prevBot) + currentValue; - botList.Add(bot); + botList.AddRounded(bot); decimal nRes = ((1 - alpha) * prevNRes) + (alpha * (currentValue + bot - prevBot)); - nResList.Add(nRes); + nResList.AddRounded(nRes); var signal = GetCompareSignal(currentValue - nRes, prevValue - prevNRes); signalsList.Add(signal); @@ -5407,8 +5407,8 @@ public static StockData CalculateReverseMovingAverageConvergenceDivergence(this for (int i = 0; i < stockData.Count; i++) { - decimal prevFastEma = i >= 1 ? fastEmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevSlowEma = i >= 1 ? slowEmaList.ElementAtOrDefault(i - 1) : 0; + decimal prevFastEma = i >= 1 ? fastEmaList[i - 1] : 0; + decimal prevSlowEma = i >= 1 ? slowEmaList[i - 1] : 0; decimal pMacdEq = fastAlpha - slowAlpha != 0 ? ((prevFastEma * fastAlpha) - (prevSlowEma * slowAlpha)) / (fastAlpha - slowAlpha) : 0; pMacdEqList.AddRounded(pMacdEq); @@ -5421,11 +5421,11 @@ public static StockData CalculateReverseMovingAverageConvergenceDivergence(this var pMacdEqSignalList = GetMovingAverageList(stockData, maType, signalLength, pMacdEqList); for (int i = 0; i < stockData.Count; i++) { - decimal pMacdEq = pMacdEqList.ElementAtOrDefault(i); - decimal pMacdEqSignal = pMacdEqSignalList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevPMacdEq = i >= 1 ? pMacdEqList.ElementAtOrDefault(i - 1) : 0; + decimal pMacdEq = pMacdEqList[i]; + decimal pMacdEqSignal = pMacdEqSignalList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevPMacdEq = i >= 1 ? pMacdEqList[i - 1] : 0; decimal macdHistogram = pMacdEq - pMacdEqSignal; histogramList.AddRounded(macdHistogram); @@ -5469,14 +5469,14 @@ public static StockData CalculateLinearRegression(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { decimal prevValue = yList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - yList.Add(currentValue); + decimal currentValue = inputList[i]; + yList.AddRounded(currentValue); decimal x = i; - xList.Add(x); + xList.AddRounded(x); decimal xy = x * currentValue; - xyList.Add(xy); + xyList.AddRounded(xy); decimal sumX = xList.TakeLastExt(length).Sum(); decimal sumY = yList.TakeLastExt(length).Sum(); @@ -5486,17 +5486,17 @@ public static StockData CalculateLinearRegression(this StockData stockData, int decimal bottom = (length * sumX2) - Pow(sumX, 2); decimal b = bottom != 0 ? top / bottom : 0; - slopeList.Add(b); + slopeList.AddRounded(b); decimal a = length != 0 ? (sumY - (b * sumX)) / length : 0; - interceptList.Add(a); + interceptList.AddRounded(a); decimal predictedToday = a + (b * x); - predictedTodayList.Add(predictedToday); + predictedTodayList.AddRounded(predictedToday); decimal prevPredictedNextDay = predictedTomorrowList.LastOrDefault(); decimal predictedNextDay = a + (b * (x + 1)); - predictedTomorrowList.Add(predictedNextDay); + predictedTomorrowList.AddRounded(predictedNextDay); var signal = GetCompareSignal(currentValue - predictedNextDay, prevValue - prevPredictedNextDay, true); signalsList.Add(signal); @@ -5535,14 +5535,14 @@ public static StockData CalculateMovingAverageAdaptiveQ(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMaaq = i >= 1 ? maaqList.ElementAtOrDefault(i - 1) : currentValue; - decimal er = erList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMaaq = i >= 1 ? maaqList[i - 1] : currentValue; + decimal er = erList[i]; decimal temp = (er * fastAlpha) + slowAlpha; decimal maaq = prevMaaq + (Pow(temp, 2) * (currentValue - prevMaaq)); - maaqList.Add(maaq); + maaqList.AddRounded(maaq); var signal = GetCompareSignal(currentValue - maaq, prevValue - prevMaaq); signalsList.Add(signal); @@ -5574,14 +5574,14 @@ public static StockData CalculateMcGinleyDynamicIndicator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevMdi = i >= 1 ? mdiList.LastOrDefault() : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ratio = prevMdi != 0 ? currentValue / prevMdi : 0; decimal bottom = k * length * Pow(ratio, 4); decimal mdi = bottom != 0 ? prevMdi + ((currentValue - prevMdi) / Math.Max(bottom, 1)) : currentValue; - mdiList.Add(mdi); + mdiList.AddRounded(mdi); var signal = GetCompareSignal(currentValue - mdi, prevValue - prevMdi); signalsList.Add(signal); @@ -5615,13 +5615,13 @@ public static StockData CalculateEhlersMedianAverageAdaptiveFilter(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal prevP1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevP2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevP3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; + decimal currentPrice = inputList[i]; + decimal prevP1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevP2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevP3 = i >= 3 ? inputList[i - 3] : 0; decimal smth = (currentPrice + (2 * prevP1) + (2 * prevP2) + prevP3) / 6; - smthList.Add(smth); + smthList.AddRounded(smth); int len = length; decimal value3 = 0.2m, value2 = 0, prevV2 = value2List.LastOrDefault(), alpha; @@ -5633,14 +5633,14 @@ public static StockData CalculateEhlersMedianAverageAdaptiveFilter(this StockDat value3 = value1 != 0 ? Math.Abs(value1 - value2) / value1 : value3; len -= 2; } - value2List.Add(value2); + value2List.AddRounded(value2); len = len < 3 ? 3 : len; alpha = (decimal)2 / (len + 1); decimal prevFilter = filterList.LastOrDefault(); decimal filter = (alpha * smth) + ((1 - alpha) * prevFilter); - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(currentPrice - filter, prevP1 - prevFilter); signalsList.Add(signal); @@ -5676,10 +5676,10 @@ public static StockData CalculateMiddleHighLowMovingAverage(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentMhlMa = mhlMaList.ElementAtOrDefault(i); - decimal prevMhlma = i >= 1 ? mhlMaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentMhlMa = mhlMaList[i]; + decimal prevMhlma = i >= 1 ? mhlMaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - currentMhlMa, prevValue - prevMhlma); signalsList.Add(signal); @@ -5719,14 +5719,14 @@ public static StockData CalculateMovingAverageV3(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal ma1 = ma1List.ElementAtOrDefault(i); - decimal ma2 = ma2List.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal ma1 = ma1List[i]; + decimal ma2 = ma2List[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevNma = nmaList.LastOrDefault(); decimal nma = ((1 + alpha) * ma1) - (alpha * ma2); - nmaList.Add(nma); + nmaList.AddRounded(nma); var signal = GetCompareSignal(currentValue - nma, prevValue - prevNma); signalsList.Add(signal); @@ -5772,51 +5772,51 @@ public static StockData CalculateMultiDepthZeroLagExponentialMovingAverage(this for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal prevAlpha1 = i >= 1 ? alpha1List.ElementAtOrDefault(i - 1) : currentValue; + decimal prevAlpha1 = i >= 1 ? alpha1List[i - 1] : currentValue; decimal alpha1 = (a1 * currentValue) + ((1 - a1) * prevAlpha1); - alpha1List.Add(alpha1); + alpha1List.AddRounded(alpha1); - decimal prevAlpha2 = i >= 1 ? alpha2List.ElementAtOrDefault(i - 1) : currentValue; - decimal priorAlpha2 = i >= 2 ? alpha2List.ElementAtOrDefault(i - 2) : currentValue; + decimal prevAlpha2 = i >= 1 ? alpha2List[i - 1] : currentValue; + decimal priorAlpha2 = i >= 2 ? alpha2List[i - 2] : currentValue; decimal alpha2 = (b2 * prevAlpha2) - (a2 * a2 * priorAlpha2) + ((1 - b2 + (a2 * a2)) * currentValue); - alpha2List.Add(alpha2); + alpha2List.AddRounded(alpha2); - decimal prevAlpha3 = i >= 1 ? alpha3List.ElementAtOrDefault(i - 1) : currentValue; - decimal prevAlpha3_2 = i >= 2 ? alpha3List.ElementAtOrDefault(i - 2) : currentValue; - decimal prevAlpha3_3 = i >= 3 ? alpha3List.ElementAtOrDefault(i - 3) : currentValue; + decimal prevAlpha3 = i >= 1 ? alpha3List[i - 1] : currentValue; + decimal prevAlpha3_2 = i >= 2 ? alpha3List[i - 2] : currentValue; + decimal prevAlpha3_3 = i >= 3 ? alpha3List[i - 3] : currentValue; decimal alpha3 = ((b3 + c) * prevAlpha3) - ((c + (b3 * c)) * prevAlpha3_2) + (c * c * prevAlpha3_3) + ((1 - b3 + c) * (1 - c) * currentValue); - alpha3List.Add(alpha3); + alpha3List.AddRounded(alpha3); decimal detrend1 = currentValue - alpha1; decimal detrend2 = currentValue - alpha2; decimal detrend3 = currentValue - alpha3; - decimal prevBeta1 = i >= 1 ? beta1List.ElementAtOrDefault(i - 1) : 0; + decimal prevBeta1 = i >= 1 ? beta1List[i - 1] : 0; decimal beta1 = (a1 * detrend1) + ((1 - a1) * prevBeta1); - beta1List.Add(beta1); + beta1List.AddRounded(beta1); - decimal prevBeta2 = i >= 1 ? beta2List.ElementAtOrDefault(i - 1) : 0; - decimal prevBeta2_2 = i >= 2 ? beta2List.ElementAtOrDefault(i - 2) : 0; + decimal prevBeta2 = i >= 1 ? beta2List[i - 1] : 0; + decimal prevBeta2_2 = i >= 2 ? beta2List[i - 2] : 0; decimal beta2 = (b2 * prevBeta2) - (a2 * a2 * prevBeta2_2) + ((1 - b2 + (a2 * a2)) * detrend2); - beta2List.Add(beta2); + beta2List.AddRounded(beta2); - decimal prevBeta3_2 = i >= 2 ? beta3List.ElementAtOrDefault(i - 2) : 0; - decimal prevBeta3_3 = i >= 3 ? beta3List.ElementAtOrDefault(i - 3) : 0; + decimal prevBeta3_2 = i >= 2 ? beta3List[i - 2] : 0; + decimal prevBeta3_3 = i >= 3 ? beta3List[i - 3] : 0; decimal beta3 = ((b3 + c) * prevBeta3_2) - ((c + (b3 * c)) * prevBeta3_2) + (c * c * prevBeta3_3) + ((1 - b3 + c) * (1 - c) * detrend3); - beta3List.Add(beta3); + beta3List.AddRounded(beta3); decimal mda1 = alpha1 + ((decimal)1 / 1 * beta1); - mda1List.Add(mda1); + mda1List.AddRounded(mda1); decimal prevMda2 = mda2List.LastOrDefault(); decimal mda2 = alpha2 + ((decimal)1 / 2 * beta2); - mda2List.Add(mda2); + mda2List.AddRounded(mda2); decimal mda3 = alpha3 + ((decimal)1 / 3 * beta3); - mda3List.Add(mda3); + mda3List.AddRounded(mda3); var signal = GetCompareSignal(currentValue - mda2, prevValue - prevMda2); signalsList.Add(signal); @@ -5856,27 +5856,27 @@ public static StockData CalculateModularFilter(this StockData stockData, int len for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal prevB2 = i >= 1 ? b2List.ElementAtOrDefault(i - 1) : currentValue; + decimal prevB2 = i >= 1 ? b2List[i - 1] : currentValue; decimal b2 = currentValue > (alpha * currentValue) + ((1 - alpha) * prevB2) ? currentValue : (alpha * currentValue) + ((1 - alpha) * prevB2); - b2List.Add(b2); + b2List.AddRounded(b2); - decimal prevC2 = i >= 1 ? c2List.ElementAtOrDefault(i - 1) : currentValue; + decimal prevC2 = i >= 1 ? c2List[i - 1] : currentValue; decimal c2 = currentValue < (alpha * currentValue) + ((1 - alpha) * prevC2) ? currentValue : (alpha * currentValue) + ((1 - alpha) * prevC2); - c2List.Add(c2); + c2List.AddRounded(c2); decimal prevOs2 = os2List.LastOrDefault(); decimal os2 = currentValue == b2 ? 1 : currentValue == c2 ? 0 : prevOs2; - os2List.Add(os2); + os2List.AddRounded(os2); decimal upper2 = (beta * b2) + ((1 - beta) * c2); decimal lower2 = (beta * c2) + ((1 - beta) * b2); decimal prevTs2 = ts2List.LastOrDefault(); decimal ts2 = (os2 * upper2) + ((1 - os2) * lower2); - ts2List.Add(ts2); + ts2List.AddRounded(ts2); var signal = GetCompareSignal(currentValue - ts2, prevValue - prevTs2); signalsList.Add(signal); @@ -5907,13 +5907,13 @@ public static StockData CalculateDampedSineWaveWeightedFilter(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal w, wSum = 0, wvSum = 0; for (int j = 1; j <= length; j++) { - decimal prevValue = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; w = Sin(MinOrMax(2 * Pi * (decimal)j / length, 0.99m, 0.01m)) / j; wvSum += w * prevValue; @@ -5922,7 +5922,7 @@ public static StockData CalculateDampedSineWaveWeightedFilter(this StockData sto decimal prevDswwf = dswwfList.LastOrDefault(); decimal dswwf = wSum != 0 ? wvSum / wSum : 0; - dswwfList.Add(dswwf); + dswwfList.AddRounded(dswwf); var signal = GetCompareSignal(currentValue - dswwf, prevVal - prevDswwf); signalsList.Add(signal); @@ -5954,14 +5954,14 @@ public static StockData CalculateDoubleExponentialSmoothing(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal x = inputList.ElementAtOrDefault(i); - decimal prevX = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevS = i >= 1 ? sList.ElementAtOrDefault(i - 1) : 0; - decimal prevS2 = i >= 2 ? sList.ElementAtOrDefault(i - 2) : 0; + decimal x = inputList[i]; + decimal prevX = i >= 1 ? inputList[i - 1] : 0; + decimal prevS = i >= 1 ? sList[i - 1] : 0; + decimal prevS2 = i >= 2 ? sList[i - 2] : 0; decimal sChg = prevS - prevS2; decimal s = (alpha * x) + ((1 - alpha) * (prevS + (gamma * (sChg + ((1 - gamma) * sChg))))); - sList.Add(s); + sList.AddRounded(s); var signal = GetCompareSignal(x - s, prevX - prevS); signalsList.Add(signal); @@ -5992,18 +5992,18 @@ public static StockData CalculateDistanceWeightedMovingAverage(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j < length; j++) { - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; decimal distanceSum = 0; for (int k = 0; k < length; k++) { - decimal prevValue2 = i >= k ? inputList.ElementAtOrDefault(i - k) : 0; + decimal prevValue2 = i >= k ? inputList[i - k] : 0; distanceSum += Math.Abs(prevValue - prevValue2); } @@ -6016,7 +6016,7 @@ public static StockData CalculateDistanceWeightedMovingAverage(this StockData st decimal prevDwma = dwmaList.LastOrDefault(); decimal dwma = weightedSum != 0 ? sum / weightedSum : 0; - dwmaList.Add(dwma); + dwmaList.AddRounded(dwma); var signal = GetCompareSignal(currentValue - dwma, prevVal - prevDwma); signalsList.Add(signal); @@ -6050,24 +6050,24 @@ public static StockData CalculateDynamicallyAdjustableFilter(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevOut = i >= 1 ? outList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevK = i >= 1 ? kList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevOut = i >= 1 ? outList[i - 1] : currentValue; + decimal prevK = i >= 1 ? kList[i - 1] : 0; decimal src = currentValue + (currentValue - prevOut); - srcList.Add(src); + srcList.AddRounded(src); decimal outVal = prevOut + (prevK * (src - prevOut)); - outList.Add(outVal); + outList.AddRounded(outVal); decimal srcSma = srcList.TakeLastExt(length).Average(); decimal srcDev = Pow(src - srcSma, 2); - srcDevList.Add(srcDev); + srcDevList.AddRounded(srcDev); decimal srcStdDev = Sqrt(srcDevList.TakeLastExt(length).Average()); decimal k = src - outVal != 0 ? Math.Abs(src - outVal) / (Math.Abs(src - outVal) + (srcStdDev * length)) : 0; - kList.Add(k); + kList.AddRounded(k); var signal = GetCompareSignal(currentValue - outVal, prevValue - prevOut); signalsList.Add(signal); @@ -6104,13 +6104,13 @@ public static StockData CalculateDynamicallyAdjustableMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal a = shortStdDevList.ElementAtOrDefault(i); - decimal b = longStdDevList.ElementAtOrDefault(i); + decimal a = shortStdDevList[i]; + decimal b = longStdDevList[i]; decimal v = a != 0 ? (b / a) + fastLength : fastLength; decimal prevValue = tempList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); int p; try @@ -6122,13 +6122,13 @@ public static StockData CalculateDynamicallyAdjustableMovingAverage(this StockDa p = slowLength; } - decimal prevK = i >= p ? kList.ElementAtOrDefault(i - p) : 0; + decimal prevK = i >= p ? kList[i - p] : 0; decimal k = tempList.Sum(); - kList.Add(k); + kList.AddRounded(k); decimal prevAma = amaList.LastOrDefault(); decimal ama = p != 0 ? (k - prevK) / p : 0; - amaList.Add(ama); + amaList.AddRounded(ama); var signal = GetCompareSignal(currentValue - ama, prevValue - prevAma); signalsList.Add(signal); @@ -6158,8 +6158,8 @@ public static StockData CalculateSpencer21PointMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= 20; j++) @@ -6189,7 +6189,7 @@ public static StockData CalculateSpencer21PointMovingAverage(this StockData stoc 20 => -1, _ => 0, }; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -6197,7 +6197,7 @@ public static StockData CalculateSpencer21PointMovingAverage(this StockData stoc decimal prevSpma = spmaList.LastOrDefault(); decimal spma = weightedSum != 0 ? sum / weightedSum : 0; - spmaList.Add(spma); + spmaList.AddRounded(spma); var signal = GetCompareSignal(currentValue - spma, prevVal - prevSpma); signalsList.Add(signal); @@ -6227,8 +6227,8 @@ public static StockData CalculateSpencer15PointMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= 14; j++) @@ -6252,7 +6252,7 @@ public static StockData CalculateSpencer15PointMovingAverage(this StockData stoc 14 => -3, _ => 0, }; - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -6260,7 +6260,7 @@ public static StockData CalculateSpencer15PointMovingAverage(this StockData stoc decimal prevSpma = spmaList.LastOrDefault(); decimal spma = weightedSum != 0 ? sum / weightedSum : 0; - spmaList.Add(spma); + spmaList.AddRounded(spma); var signal = GetCompareSignal(currentValue - spma, prevVal - prevSpma); signalsList.Add(signal); @@ -6291,14 +6291,14 @@ public static StockData CalculateSquareRootWeightedMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = Pow(length - j, 0.5m); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -6306,7 +6306,7 @@ public static StockData CalculateSquareRootWeightedMovingAverage(this StockData decimal prevSrwma = srwmaList.LastOrDefault(); decimal srwma = weightedSum != 0 ? sum / weightedSum : 0; - srwmaList.Add(srwma); + srwmaList.AddRounded(srwma); var signal = GetCompareSignal(currentValue - srwma, prevVal - prevSrwma); signalsList.Add(signal); @@ -6338,8 +6338,8 @@ public static StockData CalculateShapeshiftingMovingAverage(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sumX = 0, weightedSumX = 0, sumN = 0, weightedSumN = 0; for (int j = 0; j <= length - 1; j++) @@ -6348,7 +6348,7 @@ public static StockData CalculateShapeshiftingMovingAverage(this StockData stock decimal n = -1 + (x * 2); decimal wx = 1 - (2 * x / (Pow(x, 4) + 1)); decimal wn = 1 - (2 * Pow(n, 2) / (Pow(n, 4 - (4 % 2)) + 1)); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sumX += prevValue * wx; weightedSumX += wx; @@ -6358,10 +6358,10 @@ public static StockData CalculateShapeshiftingMovingAverage(this StockData stock decimal prevFiltX = filtXList.LastOrDefault(); decimal filtX = weightedSumX != 0 ? sumX / weightedSumX : 0; - filtXList.Add(filtX); + filtXList.AddRounded(filtX); decimal filtN = weightedSumN != 0 ? sumN / weightedSumN : 0; - filtNList.Add(filtN); + filtNList.AddRounded(filtN); var signal = GetCompareSignal(currentValue - filtX, prevVal - prevFiltX); signalsList.Add(signal); @@ -6392,21 +6392,21 @@ public static StockData CalculateSelfWeightedMovingAverage(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightSum = 0; for (int j = 0; j < length; j++) { - decimal pValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - decimal weight = i >= length + j ? inputList.ElementAtOrDefault(i - (length + j)) : 0; + decimal pValue = i >= j ? inputList[i - j] : 0; + decimal weight = i >= length + j ? inputList[i - (length + j)] : 0; weightSum += weight; sum += weight * pValue; } decimal prevWma = wmaList.LastOrDefault(); decimal wma = weightSum != 0 ? sum / weightSum : 0; - wmaList.Add(wma); + wmaList.AddRounded(wma); var signal = GetCompareSignal(currentValue - wma, prevValue - prevWma); signalsList.Add(signal); @@ -6437,14 +6437,14 @@ public static StockData CalculateSineWeightedMovingAverage(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal sum = 0, weightedSum = 0; for (int j = 0; j <= length - 1; j++) { decimal weight = Sin((j + 1) * Pi / (length + 1)); - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; sum += prevValue * weight; weightedSum += weight; @@ -6452,7 +6452,7 @@ public static StockData CalculateSineWeightedMovingAverage(this StockData stockD decimal prevSwma = swmaList.LastOrDefault(); decimal swma = weightedSum != 0 ? sum / weightedSum : 0; - swmaList.Add(swma); + swmaList.AddRounded(swma); var signal = GetCompareSignal(currentValue - swma, prevVal - prevSwma); signalsList.Add(signal); @@ -6487,24 +6487,24 @@ public static StockData CalculateSimplifiedWeightedMovingAverage(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal cml = tempList.Sum(); - cmlList.Add(cml); + cmlList.AddRounded(cml); - decimal prevCmlSum = i >= length ? cmlSumList.ElementAtOrDefault(i - length) : 0; + decimal prevCmlSum = i >= length ? cmlSumList[i - length] : 0; decimal cmlSum = cmlList.Sum(); - cmlSumList.Add(cmlSum); + cmlSumList.AddRounded(cmlSum); decimal prevSum = sumList.LastOrDefault(); decimal sum = cmlSum - prevCmlSum; - sumList.Add(sum); + sumList.AddRounded(sum); decimal prevWma = wmaList.LastOrDefault(); decimal wma = ((length * cml) - prevSum) / (length * (decimal)(length + 1) / 2); - wmaList.Add(wma); + wmaList.AddRounded(wma); var signal = GetCompareSignal(currentValue - wma, prevValue - prevWma); signalsList.Add(signal); @@ -6539,26 +6539,26 @@ public static StockData CalculateSimplifiedLeastSquaresMovingAverage(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal prevCml = i >= length ? cmlList.ElementAtOrDefault(i - length) : 0; + decimal prevCml = i >= length ? cmlList[i - length] : 0; decimal cml = tempList.Sum(); - cmlList.Add(cml); + cmlList.AddRounded(cml); - decimal prevCmlSum = i >= length ? cmlSumList.ElementAtOrDefault(i - length) : 0; + decimal prevCmlSum = i >= length ? cmlSumList[i - length] : 0; decimal cmlSum = cmlList.Sum(); - cmlSumList.Add(cmlSum); + cmlSumList.AddRounded(cmlSum); decimal prevSum = sumList.LastOrDefault(); decimal sum = cmlSum - prevCmlSum; - sumList.Add(sum); + sumList.AddRounded(sum); decimal wma = ((length * cml) - prevSum) / (length * (decimal)(length + 1) / 2); decimal prevLsma = lsmaList.LastOrDefault(); decimal lsma = length != 0 ? (3 * wma) - (2 * (cml - prevCml) / length) : 0; - lsmaList.Add(lsma); + lsmaList.AddRounded(lsma); var signal = GetCompareSignal(currentValue - lsma, prevValue - prevLsma); signalsList.Add(signal); @@ -6592,21 +6592,21 @@ public static StockData CalculateSharpModifiedMovingAverage(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; decimal slope = 0; for (int j = 1; j <= length; j++) { - decimal prevValue = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevValue = i >= j - 1 ? inputList[i - (j - 1)] : 0; decimal factor = 1 + (2 * (j - 1)); slope += prevValue * (length - factor) / 2; } decimal prevShmma = shmmaList.LastOrDefault(); decimal shmma = currentSma + (6 * slope / ((length + 1) * length)); - shmmaList.Add(shmma); + shmmaList.AddRounded(shmma); var signal = GetCompareSignal(currentValue - shmma, prevVal - prevShmma); signalsList.Add(signal); @@ -6645,10 +6645,10 @@ public static StockData CalculateSlowSmoothedMovingAverage(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal l3 = l3List.ElementAtOrDefault(i); - decimal prevL3 = i >= 1 ? l3List.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal l3 = l3List[i]; + decimal prevL3 = i >= 1 ? l3List[i - 1] : 0; var signal = GetCompareSignal(currentValue - l3, prevValue - prevL3); signalsList.Add(signal); @@ -6684,19 +6684,19 @@ public static StockData CalculateSequentiallyFilteredMovingAverage(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = smaList[i]; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal a = Math.Sign(sma - prevSma); - signList.Add(a); + signList.AddRounded(a); decimal sum = signList.TakeLastExt(length).Sum(); decimal alpha = Math.Abs(sum) == length ? 1 : 0; - decimal prevSfma = i >= 1 ? sfmaList.ElementAtOrDefault(i - 1) : sma; + decimal prevSfma = i >= 1 ? sfmaList[i - 1] : sma; decimal sfma = (alpha * sma) + ((1 - alpha) * prevSfma); - sfmaList.Add(sfma); + sfmaList.AddRounded(sfma); var signal = GetCompareSignal(currentValue - sfma, prevValue - prevSfma); signalsList.Add(signal); @@ -6730,28 +6730,28 @@ public static StockData CalculateSvama(this StockData stockData, int length = 14 for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal a = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal a = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal prevH = i >= 1 ? hList.ElementAtOrDefault(i - 1) : a; + decimal prevH = i >= 1 ? hList[i - 1] : a; decimal h = a > prevH ? a : prevH; - hList.Add(h); + hList.AddRounded(h); - decimal prevL = i >= 1 ? lList.ElementAtOrDefault(i - 1) : a; + decimal prevL = i >= 1 ? lList[i - 1] : a; decimal l = a < prevL ? a : prevL; - lList.Add(l); + lList.AddRounded(l); decimal bMax = h != 0 ? a / h : 0; decimal bMin = a != 0 ? l / a : 0; - decimal prevCMax = i >= 1 ? cMaxList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevCMax = i >= 1 ? cMaxList[i - 1] : currentValue; decimal cMax = (bMax * currentValue) + ((1 - bMax) * prevCMax); - cMaxList.Add(cMax); + cMaxList.AddRounded(cMax); - decimal prevCMin = i >= 1 ? cMinList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevCMin = i >= 1 ? cMinList[i - 1] : currentValue; decimal cMin = (bMin * currentValue) + ((1 - bMin) * prevCMin); - cMinList.Add(cMin); + cMinList.AddRounded(cMin); var signal = GetCompareSignal(currentValue - cMax, prevValue - prevCMax); signalsList.Add(signal); @@ -6783,21 +6783,21 @@ public static StockData CalculateSettingLessTrendStepFiltering(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; decimal prevA = aList.LastOrDefault(); decimal sc = Math.Abs(currentValue - prevB) + prevA != 0 ? Math.Abs(currentValue - prevB) / (Math.Abs(currentValue - prevB) + prevA) : 0; decimal sltsf = (sc * currentValue) + ((1 - sc) * prevB); decimal chg = Math.Abs(sltsf - prevB); - chgList.Add(chg); + chgList.AddRounded(chg); decimal a = chgList.Average() * (1 + sc); - aList.Add(a); + aList.AddRounded(a); decimal b = sltsf > prevB + a ? sltsf : sltsf < prevB - a ? sltsf : prevB; - bList.Add(b); + bList.AddRounded(b); var signal = GetCompareSignal(currentValue - b, prevValue - prevB); signalsList.Add(signal); @@ -6833,15 +6833,15 @@ public static StockData CalculateElasticVolumeWeightedMovingAverageV1(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentAvgVolume = volumeSmaList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentAvgVolume = volumeSmaList[i]; + decimal currentVolume = volumeList[i]; decimal n = currentAvgVolume * mult; decimal prevEVWMA = i >= 1 ? evwmaList.LastOrDefault() : currentValue; decimal evwma = n > 0 ? (((n - currentVolume) * prevEVWMA) + (currentVolume * currentValue)) / n : 0; ; - evwmaList.Add(evwma); + evwmaList.AddRounded(evwma); var signal = GetCompareSignal(currentValue - evwma, prevValue - prevEVWMA); signalsList.Add(signal); @@ -6873,16 +6873,16 @@ public static StockData CalculateElasticVolumeWeightedMovingAverageV2(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - tempList.Add(currentVolume); + decimal currentVolume = volumeList[i]; + tempList.AddRounded(currentVolume); decimal volumeSum = tempList.TakeLastExt(length).Sum(); decimal prevEvwma = evwmaList.LastOrDefault(); decimal evwma = volumeSum != 0 ? (((volumeSum - currentVolume) * prevEvwma) + (currentVolume * currentValue)) / volumeSum : 0; - evwmaList.Add(evwma); + evwmaList.AddRounded(evwma); var signal = GetCompareSignal(currentValue - evwma, prevValue - prevEvwma); signalsList.Add(signal); @@ -6919,27 +6919,27 @@ public static StockData CalculateEquityMovingAverage(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevEqma = i >= 1 ? eqmaList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = smaList[i]; + decimal prevEqma = i >= 1 ? eqmaList[i - 1] : currentValue; decimal prevX = xList.LastOrDefault(); decimal x = Math.Sign(currentValue - sma); - xList.Add(x); + xList.AddRounded(x); decimal chgX = (currentValue - prevValue) * prevX; - chgXList.Add(chgX); + chgXList.AddRounded(chgX); decimal chgXCum = (currentValue - prevValue) * x; - chgXCumList.Add(chgXCum); + chgXCumList.AddRounded(chgXCum); decimal opteq = chgXCumList.Sum(); decimal req = chgXList.TakeLastExt(length).Sum(); decimal alpha = opteq != 0 ? MinOrMax(req / opteq, 0.99m, 0.01m) : 0.99m; decimal eqma = (alpha * currentValue) + ((1 - alpha) * prevEqma); - eqmaList.Add(eqma); + eqmaList.AddRounded(eqma); var signal = GetCompareSignal(currentValue - eqma, prevValue - prevEqma); signalsList.Add(signal); @@ -6980,14 +6980,14 @@ public static StockData CalculateEdgePreservingFilter(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; decimal os = currentValue - sma; - osList.Add(os); + osList.AddRounded(os); decimal absOs = Math.Abs(os); - absOsList.Add(absOs); + absOsList.AddRounded(absOs); } stockData.CustomValuesList = absOsList; @@ -6995,31 +6995,31 @@ public static StockData CalculateEdgePreservingFilter(this StockData stockData, var (highestList, _) = GetMaxAndMinValuesList(pList, length); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal p = pList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal os = osList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal p = pList[i]; + decimal highest = highestList[i]; + decimal os = osList[i]; decimal prevH = hList.LastOrDefault(); decimal h = highest != 0 ? p / highest : 0; - hList.Add(h); + hList.AddRounded(h); decimal cnd = h == 1 && prevH != 1 ? 1 : 0; decimal sign = cnd == 1 && os < 0 ? 1 : cnd == 1 && os > 0 ? -1 : 0; bool condition = sign != 0; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : 1; + decimal prevA = i >= 1 ? aList[i - 1] : 1; decimal a = condition ? 1 : prevA + 1; - aList.Add(a); + aList.AddRounded(a); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; decimal b = a == 1 ? currentValue : prevB + currentValue; - bList.Add(b); + bList.AddRounded(b); decimal prevC = cList.LastOrDefault(); decimal c = a != 0 ? b / a : 0; - cList.Add(c); + cList.AddRounded(c); var signal = GetCompareSignal(currentValue - c, prevValue - prevC); signalsList.Add(signal); @@ -7056,13 +7056,13 @@ public static StockData CalculateEhlers2PoleSuperSmootherFilterV2(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; decimal filt = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevFilter1) + (c3 * prevFilter2); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); signalsList.Add(signal); @@ -7102,14 +7102,14 @@ public static StockData CalculateEhlers3PoleSuperSmootherFilter(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; - decimal prevFilter3 = i >= 3 ? filtList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + decimal prevFilter3 = i >= 3 ? filtList[i - 3] : 0; decimal filt = i < 4 ? currentValue : (coef1 * currentValue) + (coef2 * prevFilter1) + (coef3 * prevFilter2) + (coef4 * prevFilter3); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); signalsList.Add(signal); @@ -7146,13 +7146,13 @@ public static StockData CalculateEhlers2PoleButterworthFilterV1(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; decimal filt = (c1 * currentValue) + (c2 * prevFilter1) + (c3 * prevFilter2); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); signalsList.Add(signal); @@ -7189,14 +7189,14 @@ public static StockData CalculateEhlers2PoleButterworthFilterV2(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; decimal filt = i < 3 ? currentValue : (c1 * (currentValue + (2 * prevValue1) + prevValue3)) + (c2 * prevFilter1) + (c3 * prevFilter2); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue1 - prevFilter1); signalsList.Add(signal); @@ -7235,14 +7235,14 @@ public static StockData CalculateEhlers3PoleButterworthFilterV1(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; - decimal prevFilter3 = i >= 3 ? filtList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + decimal prevFilter3 = i >= 3 ? filtList[i - 3] : 0; decimal filt = (d1 * currentValue) + (d2 * prevFilter1) + (d3 * prevFilter2) + (d4 * prevFilter3); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); signalsList.Add(signal); @@ -7281,17 +7281,17 @@ public static StockData CalculateEhlers3PoleButterworthFilterV2(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; - decimal prevFilter3 = i >= 3 ? filtList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + decimal prevFilter3 = i >= 3 ? filtList[i - 3] : 0; decimal filt = i < 4 ? currentValue : (coef1 * (currentValue + (3 * prevValue1) + (3 * prevValue2) + prevValue3)) + (coef2 * prevFilter1) + (coef3 * prevFilter2) + (coef4 * prevFilter3); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue1 - prevFilter1); signalsList.Add(signal); @@ -7335,32 +7335,32 @@ public static StockData CalculateEhlersGaussianFilter(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevGf1 = i >= 1 ? gf1List.ElementAtOrDefault(i - 1) : 0; - decimal prevGf2_1 = i >= 1 ? gf2List.ElementAtOrDefault(i - 1) : 0; - decimal prevGf2_2 = i >= 2 ? gf2List.ElementAtOrDefault(i - 2) : 0; - decimal prevGf3_1 = i >= 1 ? gf3List.ElementAtOrDefault(i - 1) : 0; - decimal prevGf4_1 = i >= 1 ? gf4List.ElementAtOrDefault(i - 1) : 0; - decimal prevGf3_2 = i >= 2 ? gf3List.ElementAtOrDefault(i - 2) : 0; - decimal prevGf4_2 = i >= 2 ? gf4List.ElementAtOrDefault(i - 2) : 0; - decimal prevGf3_3 = i >= 3 ? gf3List.ElementAtOrDefault(i - 3) : 0; - decimal prevGf4_3 = i >= 3 ? gf4List.ElementAtOrDefault(i - 3) : 0; - decimal prevGf4_4 = i >= 4 ? gf4List.ElementAtOrDefault(i - 4) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevGf1 = i >= 1 ? gf1List[i - 1] : 0; + decimal prevGf2_1 = i >= 1 ? gf2List[i - 1] : 0; + decimal prevGf2_2 = i >= 2 ? gf2List[i - 2] : 0; + decimal prevGf3_1 = i >= 1 ? gf3List[i - 1] : 0; + decimal prevGf4_1 = i >= 1 ? gf4List[i - 1] : 0; + decimal prevGf3_2 = i >= 2 ? gf3List[i - 2] : 0; + decimal prevGf4_2 = i >= 2 ? gf4List[i - 2] : 0; + decimal prevGf3_3 = i >= 3 ? gf3List[i - 3] : 0; + decimal prevGf4_3 = i >= 3 ? gf4List[i - 3] : 0; + decimal prevGf4_4 = i >= 4 ? gf4List[i - 4] : 0; decimal gf1 = (alpha1 * currentValue) + ((1 - alpha1) * prevGf1); - gf1List.Add(gf1); + gf1List.AddRounded(gf1); decimal gf2 = (Pow(alpha2, 2) * currentValue) + (2 * (1 - alpha2) * prevGf2_1) - (Pow(1 - alpha2, 2) * prevGf2_2); - gf2List.Add(gf2); + gf2List.AddRounded(gf2); decimal gf3 = (Pow(alpha3, 3) * currentValue) + (3 * (1 - alpha3) * prevGf3_1) - (3 * Pow(1 - alpha3, 2) * prevGf3_2) + (Pow(1 - alpha3, 3) * prevGf3_3); - gf3List.Add(gf3); + gf3List.AddRounded(gf3); decimal 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.Add(gf4); + gf4List.AddRounded(gf4); var signal = GetCompareSignal(currentValue - gf4, prevValue - prevGf4_1); signalsList.Add(signal); @@ -7401,13 +7401,13 @@ public static StockData CalculateEhlersRecursiveMedianFilter(this StockData stoc for (int i = 0; i < stockData.Count; i++) { decimal prevValue = tempList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal median = tempList.TakeLastExt(length1).Median(); decimal prevRmf = rmfList.LastOrDefault(); decimal rmf = (alpha * median) + ((1 - alpha) * prevRmf); - rmfList.Add(rmf); + rmfList.AddRounded(rmf); var signal = GetCompareSignal(currentValue - rmf, prevValue - prevRmf); signalsList.Add(signal); @@ -7444,14 +7444,14 @@ public static StockData CalculateEhlersSuperSmootherFilter(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; decimal prevFilt = filtList.LastOrDefault(); decimal filt = (coeff1 * ((currentValue + prevValue) / 2)) + (coeff2 * prevFilter1) + (coeff3 * prevFilter2); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); signalsList.Add(signal); @@ -7488,13 +7488,13 @@ public static StockData CalculateEhlers2PoleSuperSmootherFilterV1(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevFilter1 = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevFilter2 = i >= 2 ? filtList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevFilter1 = i >= 1 ? filtList[i - 1] : 0; + decimal prevFilter2 = i >= 2 ? filtList[i - 2] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal filt = i < 3 ? currentValue : (coef1 * currentValue) + (coef2 * prevFilter1) + (coef3 * prevFilter2); - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilter1); signalsList.Add(signal); @@ -7533,22 +7533,22 @@ public static StockData CalculateEhlersAverageErrorFilter(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevE11 = i >= 1 ? e1List.ElementAtOrDefault(i - 1) : 0; - decimal prevE12 = i >= 2 ? e1List.ElementAtOrDefault(i - 2) : 0; - decimal prevSsf1 = i >= 1 ? ssfList.ElementAtOrDefault(i - 1) : 0; - decimal prevSsf2 = i >= 2 ? ssfList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevE11 = i >= 1 ? e1List[i - 1] : 0; + decimal prevE12 = i >= 2 ? e1List[i - 2] : 0; + decimal prevSsf1 = i >= 1 ? ssfList[i - 1] : 0; + decimal prevSsf2 = i >= 2 ? ssfList[i - 2] : 0; decimal ssf = i < 3 ? currentValue : (0.5m * c1 * (currentValue + prevValue)) + (c2 * prevSsf1) + (c3 * prevSsf2); - ssfList.Add(ssf); + ssfList.AddRounded(ssf); decimal e1 = i < 3 ? 0 : (c1 * (currentValue - ssf)) + (c2 * prevE11) + (c3 * prevE12); - e1List.Add(e1); + e1List.AddRounded(e1); decimal prevFilt = filtList.LastOrDefault(); decimal filt = ssf + e1; - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); signalsList.Add(signal); @@ -7584,34 +7584,34 @@ public static StockData CalculateEhlersLaguerreFilter(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevP1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevP2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevP3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; + decimal currentValue = inputList[i]; + decimal prevP1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevP2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevP3 = i >= 3 ? inputList[i - 3] : 0; decimal prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; decimal prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; decimal prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; decimal prevL3 = i >= 1 ? l3List.LastOrDefault() : currentValue; decimal l0 = (alpha * currentValue) + ((1 - alpha) * prevL0); - l0List.Add(l0); + l0List.AddRounded(l0); decimal l1 = (-1 * (1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); - l1List.Add(l1); + l1List.AddRounded(l1); decimal l2 = (-1 * (1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); - l2List.Add(l2); + l2List.AddRounded(l2); decimal l3 = (-1 * (1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); - l3List.Add(l3); + l3List.AddRounded(l3); decimal prevFilter = filterList.LastOrDefault(); decimal filter = (l0 + (2 * l1) + (2 * l2) + l3) / 6; - filterList.Add(filter); + filterList.AddRounded(filter); decimal prevFir = firList.LastOrDefault(); decimal fir = (currentValue + (2 * prevP1) + (2 * prevP2) + prevP3) / 6; - firList.Add(fir); + firList.AddRounded(fir); var signal = GetCompareSignal(filter - fir, prevFilter - prevFir); signalsList.Add(signal); @@ -7650,8 +7650,8 @@ public static StockData CalculateEhlersAdaptiveLaguerreFilter(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevL0 = i >= 1 ? l0List.LastOrDefault() : currentValue; decimal prevL1 = i >= 1 ? l1List.LastOrDefault() : currentValue; decimal prevL2 = i >= 1 ? l2List.LastOrDefault() : currentValue; @@ -7659,33 +7659,33 @@ public static StockData CalculateEhlersAdaptiveLaguerreFilter(this StockData sto decimal prevFilter = i >= 1 ? filterList.LastOrDefault() : currentValue; decimal diff = Math.Abs(currentValue - prevFilter); - diffList.Add(diff); + diffList.AddRounded(diff); var list = diffList.TakeLastExt(length1).ToList(); decimal highestHigh = list.Max(); decimal lowestLow = list.Min(); decimal mid = highestHigh - lowestLow != 0 ? (diff - lowestLow) / (highestHigh - lowestLow) : 0; - midList.Add(mid); + midList.AddRounded(mid); decimal prevAlpha = i >= 1 ? alphaList.LastOrDefault() : (decimal)2 / (length1 + 1); decimal alpha = mid != 0 ? midList.TakeLastExt(length2).Median() : prevAlpha; - alphaList.Add(alpha); + alphaList.AddRounded(alpha); decimal l0 = (alpha * currentValue) + ((1 - alpha) * prevL0); - l0List.Add(l0); + l0List.AddRounded(l0); decimal l1 = (-1 * (1 - alpha) * l0) + prevL0 + ((1 - alpha) * prevL1); - l1List.Add(l1); + l1List.AddRounded(l1); decimal l2 = (-1 * (1 - alpha) * l1) + prevL1 + ((1 - alpha) * prevL2); - l2List.Add(l2); + l2List.AddRounded(l2); decimal l3 = (-1 * (1 - alpha) * l2) + prevL2 + ((1 - alpha) * prevL3); - l3List.Add(l3); + l3List.AddRounded(l3); decimal filter = (l0 + (2 * l1) + (2 * l2) + l3) / 6; - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter); signalsList.Add(signal); @@ -7718,16 +7718,16 @@ public static StockData CalculateEhlersLeadingIndicator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevLead = leadList.LastOrDefault(); decimal lead = (2 * currentValue) + ((alpha1 - 2) * prevValue) + ((1 - alpha1) * prevLead); - leadList.Add(lead); + leadList.AddRounded(lead); decimal prevLeadIndicator = leadIndicatorList.LastOrDefault(); decimal leadIndicator = (alpha2 * lead) + ((1 - alpha2) * prevLeadIndicator); - leadIndicatorList.Add(leadIndicator); + leadIndicatorList.AddRounded(leadIndicator); var signal = GetCompareSignal(currentValue - leadIndicator, prevValue - prevLeadIndicator); signalsList.Add(signal); @@ -7757,14 +7757,14 @@ public static StockData CalculateEhlersOptimumEllipticFilter(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevOef1 = i >= 1 ? oefList.ElementAtOrDefault(i - 1) : 0; - decimal prevOef2 = i >= 2 ? oefList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevOef1 = i >= 1 ? oefList[i - 1] : 0; + decimal prevOef2 = i >= 2 ? oefList[i - 2] : 0; decimal oef = (0.13785m * currentValue) + (0.0007m * prevValue1) + (0.13785m * prevValue2) + (1.2103m * prevOef1) - (0.4867m * prevOef2); - oefList.Add(oef); + oefList.AddRounded(oef); var signal = GetCompareSignal(currentValue - oef, prevValue1 - prevOef1); signalsList.Add(signal); @@ -7794,16 +7794,16 @@ public static StockData CalculateEhlersModifiedOptimumEllipticFilter(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : prevValue1; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : prevValue2; - decimal prevMoef1 = i >= 1 ? moefList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevMoef2 = i >= 2 ? moefList.ElementAtOrDefault(i - 2) : prevMoef1; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : currentValue; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : prevValue1; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : prevValue2; + decimal prevMoef1 = i >= 1 ? moefList[i - 1] : currentValue; + decimal prevMoef2 = i >= 2 ? moefList[i - 2] : prevMoef1; decimal moef = (0.13785m * ((2 * currentValue) - prevValue1)) + (0.0007m * ((2 * prevValue1) - prevValue2)) + (0.13785m * ((2 * prevValue2) - prevValue3)) + (1.2103m * prevMoef1) - (0.4867m * prevMoef2); - moefList.Add(moef); + moefList.AddRounded(moef); var signal = GetCompareSignal(currentValue - moef, prevValue1 - prevMoef1); signalsList.Add(signal); @@ -7835,14 +7835,14 @@ public static StockData CalculateEhlersFilter(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal num = 0, sumC = 0; for (int j = 0; j <= length1 - 1; j++) { - decimal currentPrice = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - decimal prevPrice = i >= j + length2 ? inputList.ElementAtOrDefault(i - (j + length2)) : 0; + decimal currentPrice = i >= j ? inputList[i - j] : 0; + decimal prevPrice = i >= j + length2 ? inputList[i - (j + length2)] : 0; decimal priceDiff = Math.Abs(currentPrice - prevPrice); num += priceDiff * currentPrice; @@ -7851,7 +7851,7 @@ public static StockData CalculateEhlersFilter(this StockData stockData, int leng decimal prevEhlersFilter = filterList.LastOrDefault(); decimal ehlersFilter = sumC != 0 ? num / sumC : 0; - filterList.Add(ehlersFilter); + filterList.AddRounded(ehlersFilter); var signal = GetCompareSignal(currentValue - ehlersFilter, prevValue - prevEhlersFilter); signalsList.Add(signal); @@ -7882,18 +7882,18 @@ public static StockData CalculateEhlersDistanceCoefficientFilter(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal srcSum = 0, coefSum = 0; for (int count = 0; count <= length - 1; count++) { - decimal prevCount = i >= count ? inputList.ElementAtOrDefault(i - count) : 0; + decimal prevCount = i >= count ? inputList[i - count] : 0; decimal distance = 0; for (int lookBack = 1; lookBack <= length - 1; lookBack++) { - decimal prevCountLookBack = i >= count + lookBack ? inputList.ElementAtOrDefault(i - (count + lookBack)) : 0; + decimal prevCountLookBack = i >= count + lookBack ? inputList[i - (count + lookBack)] : 0; distance += Pow(prevCount - prevCountLookBack, 2); } @@ -7903,7 +7903,7 @@ public static StockData CalculateEhlersDistanceCoefficientFilter(this StockData decimal prevFilter = filterList.LastOrDefault(); decimal filter = coefSum != 0 ? srcSum / coefSum : 0; - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter); signalsList.Add(signal); @@ -7943,18 +7943,18 @@ public static StockData CalculateEhlersFiniteImpulseResponseFilter(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal prevValue4 = i >= 4 ? inputList.ElementAtOrDefault(i - 4) : 0; - decimal prevValue5 = i >= 5 ? inputList.ElementAtOrDefault(i - 5) : 0; - decimal prevValue6 = i >= 6 ? inputList.ElementAtOrDefault(i - 6) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; + decimal prevValue4 = i >= 4 ? inputList[i - 4] : 0; + decimal prevValue5 = i >= 5 ? inputList[i - 5] : 0; + decimal prevValue6 = i >= 6 ? inputList[i - 6] : 0; decimal prevFilter = filterList.LastOrDefault(); decimal filter = ((coef1 * currentValue) + (coef2 * prevValue1) + (coef3 * prevValue2) + (coef4 * prevValue3) + (coef5 * prevValue4) + (coef6 * prevValue5) + (coef7 * prevValue6)) / coefSum; - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue1 - prevFilter); signalsList.Add(signal); @@ -7988,12 +7988,12 @@ public static StockData CalculateEhlersInfiniteImpulseResponseFilter(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= lag ? inputList.ElementAtOrDefault(i - lag) : 0; - decimal prevFilter1 = i >= 1 ? filterList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= lag ? inputList[i - lag] : 0; + decimal prevFilter1 = i >= 1 ? filterList[i - 1] : 0; decimal filter = (alpha * (currentValue + (currentValue - prevValue))) + ((1 - alpha) * prevFilter1); - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(currentValue - filter, prevValue - prevFilter1); signalsList.Add(signal); @@ -8030,15 +8030,15 @@ public static StockData CalculateEhlersDeviationScaledMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; decimal prevZeros = zerosList.LastOrDefault(); decimal zeros = currentValue - prevValue2; - zerosList.Add(zeros); + zerosList.AddRounded(zeros); decimal avgZeros = (zeros + prevZeros) / 2; - avgZerosList.Add(avgZeros); + avgZerosList.AddRounded(avgZeros); } var ssf2PoleList = GetMovingAverageList(stockData, maType, fastLength, avgZerosList); @@ -8046,19 +8046,19 @@ public static StockData CalculateEhlersDeviationScaledMovingAverage(this StockDa var ssf2PoleStdDevList = CalculateStandardDeviationVolatility(stockData, length: slowLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSsf2Pole = ssf2PoleList.ElementAtOrDefault(i); - decimal currentSsf2PoleStdDev = ssf2PoleStdDevList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentSsf2Pole = ssf2PoleList[i]; + decimal currentSsf2PoleStdDev = ssf2PoleStdDevList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevScaledFilter2Pole = scaledFilter2PoleList.LastOrDefault(); decimal scaledFilter2Pole = currentSsf2PoleStdDev != 0 ? currentSsf2Pole / currentSsf2PoleStdDev : prevScaledFilter2Pole; - scaledFilter2PoleList.Add(scaledFilter2Pole); + scaledFilter2PoleList.AddRounded(scaledFilter2Pole); decimal alpha2Pole = MinOrMax(5 * Math.Abs(scaledFilter2Pole) / slowLength, 0.99m, 0.01m); decimal prevEdsma2pole = edsma2PoleList.LastOrDefault(); decimal edsma2Pole = (alpha2Pole * currentValue) + ((1 - alpha2Pole) * prevEdsma2pole); - edsma2PoleList.Add(edsma2Pole); + edsma2PoleList.AddRounded(edsma2Pole); var signal = GetCompareSignal(currentValue - edsma2Pole, prevValue - prevEdsma2pole); signalsList.Add(signal); @@ -8089,21 +8089,21 @@ public static StockData CalculateEhlersHannMovingAverage(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevFilt = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevFilt = i >= 1 ? filtList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal filtSum = 0, coefSum = 0; for (int j = 1; j <= length; j++) { - decimal prevV = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevV = i >= j - 1 ? inputList[i - (j - 1)] : 0; decimal cos = 1 - Cos(2 * Pi * ((decimal)j / (length + 1))); filtSum += cos * prevV; coefSum += cos; } decimal filt = coefSum != 0 ? filtSum / coefSum : 0; - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); signalsList.Add(signal); @@ -8141,24 +8141,24 @@ public static StockData CalculateEhlersDeviationScaledSuperSmoother(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal priorValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; + decimal currentValue = inputList[i]; + decimal priorValue = i >= length1 ? inputList[i - length1] : 0; decimal mom = currentValue - priorValue; - momList.Add(mom); + momList.AddRounded(mom); } var filtList = GetMovingAverageList(stockData, maType, hannLength, momList); for (int i = 0; i < stockData.Count; i++) { - decimal filt = filtList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevDsss1 = i >= 1 ? dsssList.ElementAtOrDefault(i - 1) : 0; - decimal prevDsss2 = i >= 2 ? dsssList.ElementAtOrDefault(i - 2) : 0; + decimal filt = filtList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevDsss1 = i >= 1 ? dsssList[i - 1] : 0; + decimal prevDsss2 = i >= 2 ? dsssList[i - 2] : 0; decimal filtPow = Pow(filt, 2); - filtPowList.Add(filtPow); + filtPowList.AddRounded(filtPow); decimal filtPowMa = filtPowList.TakeLastExt(length2).Average(); decimal rms = filtPowMa > 0 ? Sqrt(filtPowMa) : 0; @@ -8170,7 +8170,7 @@ public static StockData CalculateEhlersDeviationScaledSuperSmoother(this StockDa decimal c1 = 1 - c2 - c3; decimal dsss = (c1 * ((currentValue + prevValue) / 2)) + (c2 * prevDsss1) + (c3 * prevDsss2); - dsssList.Add(dsss); + dsssList.AddRounded(dsss); var signal = GetCompareSignal(currentValue - dsss, prevValue - prevDsss1); signalsList.Add(signal); @@ -8205,20 +8205,20 @@ public static StockData CalculateEhlersZeroLagExponentialMovingAverage(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= lag ? inputList.ElementAtOrDefault(i - lag) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= lag ? inputList[i - lag] : 0; decimal d = currentValue + (currentValue - prevValue); - dList.Add(d); + dList.AddRounded(d); } var zemaList = GetMovingAverageList(stockData, maType, length, dList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal zema = zemaList.ElementAtOrDefault(i); - decimal prevZema = i >= 1 ? zemaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal zema = zemaList[i]; + decimal prevZema = i >= 1 ? zemaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - zema, prevValue - prevZema); signalsList.Add(signal); @@ -8257,19 +8257,19 @@ public static StockData CalculateEhlersVariableIndexDynamicAverage(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal shortAvg = shortAvgList.ElementAtOrDefault(i); - decimal longAvg = longAvgList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal shortAvg = shortAvgList[i]; + decimal longAvg = longAvgList[i]; decimal shortPow = Pow(currentValue - shortAvg, 2); - shortPowList.Add(shortPow); + shortPowList.AddRounded(shortPow); decimal shortMa = shortPowList.TakeLastExt(fastLength).Average(); decimal shortRms = shortMa > 0 ? Sqrt(shortMa) : 0; decimal longPow = Pow(currentValue - longAvg, 2); - longPowList.Add(longPow); + longPowList.AddRounded(longPow); decimal longMa = longPowList.TakeLastExt(slowLength).Average(); decimal longRms = longMa > 0 ? Sqrt(longMa) : 0; @@ -8277,7 +8277,7 @@ public static StockData CalculateEhlersVariableIndexDynamicAverage(this StockDat decimal prevVidya = vidyaList.LastOrDefault(); decimal vidya = (kk * currentValue) + ((1 - kk) * prevVidya); - vidyaList.Add(vidya); + vidyaList.AddRounded(vidya); var signal = GetCompareSignal(currentValue - vidya, prevValue - prevVidya); signalsList.Add(signal); @@ -8308,15 +8308,15 @@ public static StockData CalculateEhlersKaufmanAdaptiveMovingAverage(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length - 1 ? inputList.ElementAtOrDefault(i - (length - 1)) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorValue = i >= length - 1 ? inputList[i - (length - 1)] : 0; decimal deltaSum = 0; for (int j = 0; j < length; j++) { - decimal cValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - decimal pValue = i >= j + 1 ? inputList.ElementAtOrDefault(i - (j + 1)) : 0; + decimal cValue = i >= j ? inputList[i - j] : 0; + decimal pValue = i >= j + 1 ? inputList[i - (j + 1)] : 0; deltaSum += Math.Abs(cValue - pValue); } @@ -8325,7 +8325,7 @@ public static StockData CalculateEhlersKaufmanAdaptiveMovingAverage(this StockDa decimal prevKama = kamaList.LastOrDefault(); decimal kama = (s * currentValue) + ((1 - s) * prevKama); - kamaList.Add(kama); + kamaList.AddRounded(kama); var signal = GetCompareSignal(currentValue - kama, prevValue - prevKama); signalsList.Add(signal); @@ -8362,14 +8362,14 @@ public static StockData CalculateEhlersAllPassPhaseShifter(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevPhaser1 = i >= 1 ? phaserList.ElementAtOrDefault(i - 1) : 0; - decimal prevPhaser2 = i >= 2 ? phaserList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevPhaser1 = i >= 1 ? phaserList[i - 1] : 0; + decimal prevPhaser2 = i >= 2 ? phaserList[i - 2] : 0; decimal phaser = (b3 * (currentValue + (a2 * prevValue1) + (a3 * prevValue2))) - (b2 * prevPhaser1) - (b3 * prevPhaser2); - phaserList.Add(phaser); + phaserList.AddRounded(phaser); var signal = GetCompareSignal(currentValue - phaser, prevValue1 - prevPhaser1); signalsList.Add(signal); @@ -8416,99 +8416,99 @@ public static StockData CalculateEhlersChebyshevLowPassFilter(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevV1Neg2_1 = i >= 1 ? v1Neg2List.ElementAtOrDefault(i - 1) : 0; - decimal prevV1Neg2_2 = i >= 2 ? v1Neg2List.ElementAtOrDefault(i - 2) : 0; - decimal prevWaveNeg2_1 = i >= 1 ? waveNeg2List.ElementAtOrDefault(i - 1) : 0; - decimal prevWaveNeg2_2 = i >= 2 ? waveNeg2List.ElementAtOrDefault(i - 2) : 0; - decimal prevV1Neg1_1 = i >= 1 ? v1Neg1List.ElementAtOrDefault(i - 1) : 0; - decimal prevV1Neg1_2 = i >= 2 ? v1Neg1List.ElementAtOrDefault(i - 2) : 0; - decimal prevWaveNeg1_1 = i >= 1 ? waveNeg1List.ElementAtOrDefault(i - 1) : 0; - decimal prevWaveNeg1_2 = i >= 2 ? waveNeg1List.ElementAtOrDefault(i - 2) : 0; - decimal prevV10_1 = i >= 1 ? v10List.ElementAtOrDefault(i - 1) : 0; - decimal prevV10_2 = i >= 2 ? v10List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave0_1 = i >= 1 ? wave0List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave0_2 = i >= 2 ? wave0List.ElementAtOrDefault(i - 2) : 0; - decimal prevV11_1 = i >= 1 ? v11List.ElementAtOrDefault(i - 1) : 0; - decimal prevV11_2 = i >= 2 ? v11List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave1_1 = i >= 1 ? wave1List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave1_2 = i >= 2 ? wave1List.ElementAtOrDefault(i - 2) : 0; - decimal prevV12_1 = i >= 1 ? v12List.ElementAtOrDefault(i - 1) : 0; - decimal prevV12_2 = i >= 2 ? v12List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave2_1 = i >= 1 ? wave2List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave2_2 = i >= 2 ? wave2List.ElementAtOrDefault(i - 2) : 0; - decimal prevV13_1 = i >= 1 ? v13List.ElementAtOrDefault(i - 1) : 0; - decimal prevV13_2 = i >= 2 ? v13List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave3_1 = i >= 1 ? wave3List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave3_2 = i >= 2 ? wave3List.ElementAtOrDefault(i - 2) : 0; - decimal prevV14_1 = i >= 1 ? v14List.ElementAtOrDefault(i - 1) : 0; - decimal prevV14_2 = i >= 2 ? v14List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave4_1 = i >= 1 ? wave4List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave4_2 = i >= 2 ? wave4List.ElementAtOrDefault(i - 2) : 0; - decimal prevV15_1 = i >= 1 ? v15List.ElementAtOrDefault(i - 1) : 0; - decimal prevV15_2 = i >= 2 ? v15List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave5_1 = i >= 1 ? wave5List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave5_2 = i >= 2 ? wave5List.ElementAtOrDefault(i - 2) : 0; - decimal prevV16_1 = i >= 1 ? v16List.ElementAtOrDefault(i - 1) : 0; - decimal prevV16_2 = i >= 2 ? v16List.ElementAtOrDefault(i - 2) : 0; - decimal prevWave6_1 = i >= 1 ? wave6List.ElementAtOrDefault(i - 1) : 0; - decimal prevWave6_2 = i >= 2 ? wave6List.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevV1Neg2_1 = i >= 1 ? v1Neg2List[i - 1] : 0; + decimal prevV1Neg2_2 = i >= 2 ? v1Neg2List[i - 2] : 0; + decimal prevWaveNeg2_1 = i >= 1 ? waveNeg2List[i - 1] : 0; + decimal prevWaveNeg2_2 = i >= 2 ? waveNeg2List[i - 2] : 0; + decimal prevV1Neg1_1 = i >= 1 ? v1Neg1List[i - 1] : 0; + decimal prevV1Neg1_2 = i >= 2 ? v1Neg1List[i - 2] : 0; + decimal prevWaveNeg1_1 = i >= 1 ? waveNeg1List[i - 1] : 0; + decimal prevWaveNeg1_2 = i >= 2 ? waveNeg1List[i - 2] : 0; + decimal prevV10_1 = i >= 1 ? v10List[i - 1] : 0; + decimal prevV10_2 = i >= 2 ? v10List[i - 2] : 0; + decimal prevWave0_1 = i >= 1 ? wave0List[i - 1] : 0; + decimal prevWave0_2 = i >= 2 ? wave0List[i - 2] : 0; + decimal prevV11_1 = i >= 1 ? v11List[i - 1] : 0; + decimal prevV11_2 = i >= 2 ? v11List[i - 2] : 0; + decimal prevWave1_1 = i >= 1 ? wave1List[i - 1] : 0; + decimal prevWave1_2 = i >= 2 ? wave1List[i - 2] : 0; + decimal prevV12_1 = i >= 1 ? v12List[i - 1] : 0; + decimal prevV12_2 = i >= 2 ? v12List[i - 2] : 0; + decimal prevWave2_1 = i >= 1 ? wave2List[i - 1] : 0; + decimal prevWave2_2 = i >= 2 ? wave2List[i - 2] : 0; + decimal prevV13_1 = i >= 1 ? v13List[i - 1] : 0; + decimal prevV13_2 = i >= 2 ? v13List[i - 2] : 0; + decimal prevWave3_1 = i >= 1 ? wave3List[i - 1] : 0; + decimal prevWave3_2 = i >= 2 ? wave3List[i - 2] : 0; + decimal prevV14_1 = i >= 1 ? v14List[i - 1] : 0; + decimal prevV14_2 = i >= 2 ? v14List[i - 2] : 0; + decimal prevWave4_1 = i >= 1 ? wave4List[i - 1] : 0; + decimal prevWave4_2 = i >= 2 ? wave4List[i - 2] : 0; + decimal prevV15_1 = i >= 1 ? v15List[i - 1] : 0; + decimal prevV15_2 = i >= 2 ? v15List[i - 2] : 0; + decimal prevWave5_1 = i >= 1 ? wave5List[i - 1] : 0; + decimal prevWave5_2 = i >= 2 ? wave5List[i - 2] : 0; + decimal prevV16_1 = i >= 1 ? v16List[i - 1] : 0; + decimal prevV16_2 = i >= 2 ? v16List[i - 2] : 0; + decimal prevWave6_1 = i >= 1 ? wave6List[i - 1] : 0; + decimal prevWave6_2 = i >= 2 ? wave6List[i - 2] : 0; decimal v1Neg2 = (0.080778m * (currentValue + (1.907m * prevValue1) + prevValue2)) + (0.293m * prevV1Neg2_1) - (0.063m * prevV1Neg2_2); - v1Neg2List.Add(v1Neg2); + v1Neg2List.AddRounded(v1Neg2); decimal waveNeg2 = v1Neg2 + (0.513m * prevV1Neg2_1) + prevV1Neg2_2 + (0.451m * prevWaveNeg2_1) - (0.481m * prevWaveNeg2_2); - waveNeg2List.Add(waveNeg2); + waveNeg2List.AddRounded(waveNeg2); decimal v1Neg1 = (0.021394m * (currentValue + (1.777m * prevValue1) + prevValue2)) + (0.731m * prevV1Neg1_1) - (0.166m * prevV1Neg1_2); - v1Neg1List.Add(v1Neg1); + v1Neg1List.AddRounded(v1Neg1); decimal waveNeg1 = v1Neg1 + (0.977m * prevV1Neg1_1) + prevV1Neg1_2 + (1.008m * prevWaveNeg1_1) - (0.561m * prevWaveNeg1_2); - waveNeg1List.Add(waveNeg1); + waveNeg1List.AddRounded(waveNeg1); decimal v10 = (0.0095822m * (currentValue + (1.572m * prevValue1) + prevValue2)) + (1.026m * prevV10_1) - (0.282m * prevV10_2); - v10List.Add(v10); + v10List.AddRounded(v10); decimal wave0 = v10 + (0.356m * prevV10_1) + prevV10_2 + (1.329m * prevWave0_1) - (0.644m * prevWave0_2); - wave0List.Add(wave0); + wave0List.AddRounded(wave0); decimal v11 = (0.00461m * (currentValue + (1.192m * prevValue1) + prevValue2)) + (1.281m * prevV11_1) - (0.426m * prevV11_2); - v11List.Add(v11); + v11List.AddRounded(v11); decimal wave1 = v11 - (0.384m * prevV11_1) + prevV11_2 + (1.565m * prevWave1_1) - (0.729m * prevWave1_2); - wave1List.Add(wave1); + wave1List.AddRounded(wave1); decimal v12 = (0.0026947m * (currentValue + (0.681m * prevValue1) + prevValue2)) + (1.46m * prevV12_1) - (0.543m * prevV12_2); - v12List.Add(v12); + v12List.AddRounded(v12); decimal wave2 = v12 - (0.966m * prevV12_1) + prevV12_2 + (1.703m * prevWave2_1) - (0.793m * prevWave2_2); - wave2List.Add(wave2); + wave2List.AddRounded(wave2); decimal v13 = (0.0017362m * (currentValue + (0.012m * prevValue1) + prevValue2)) + (1.606m * prevV13_1) - (0.65m * prevV13_2); - v13List.Add(v13); + v13List.AddRounded(v13); decimal wave3 = v13 - (1.408m * prevV13_1) + prevV13_2 + (1.801m * prevWave3_1) - (0.848m * prevWave3_2); - wave3List.Add(wave3); + wave3List.AddRounded(wave3); decimal v14 = (0.0013738m * (currentValue - (0.669m * prevValue1) + prevValue2)) + (1.716m * prevV14_1) - (0.74m * prevV14_2); - v14List.Add(v14); + v14List.AddRounded(v14); decimal wave4 = v14 - (1.685m * prevV14_1) + prevV14_2 + (1.866m * prevWave4_1) - (0.89m * prevWave4_2); - wave4List.Add(wave4); + wave4List.AddRounded(wave4); decimal v15 = (0.0010794m * (currentValue - (1.226m * prevValue1) + prevValue2)) + (1.8m * prevV15_1) - (0.811m * prevV15_2); - v15List.Add(v15); + v15List.AddRounded(v15); decimal wave5 = v15 - (1.842m * prevV15_1) + prevV15_2 + (1.91m * prevWave5_1) - (0.922m * prevWave5_2); - wave5List.Add(wave5); + wave5List.AddRounded(wave5); decimal v16 = (0.001705m * (currentValue - (1.659m * prevValue1) + prevValue2)) + (1.873m * prevV16_1) - (0.878m * prevV16_2); - v16List.Add(v16); + v16List.AddRounded(v16); decimal wave6 = v16 - (1.957m * prevV16_1) + prevV16_2 + (1.946m * prevWave6_1) - (0.951m * prevWave6_2); - wave6List.Add(wave6); + wave6List.AddRounded(wave6); var signal = GetCompareSignal(currentValue - waveNeg2, prevValue1 - prevWaveNeg2_1); signalsList.Add(signal); @@ -8551,16 +8551,16 @@ public static StockData CalculateEhlersBetterExponentialMovingAverage(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevEma1 = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevEma1 = i >= 1 ? emaList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ema = (alpha * currentValue) + ((1 - alpha) * prevEma1); - emaList.Add(ema); + emaList.AddRounded(ema); decimal prevBEma = bEmaList.LastOrDefault(); decimal bEma = (alpha * ((currentValue + prevValue) / 2)) + ((1 - alpha) * prevEma1); - bEmaList.Add(bEma); + bEmaList.AddRounded(bEma); var signal = GetCompareSignal(currentValue - bEma, prevValue - prevBEma); signalsList.Add(signal); @@ -8592,21 +8592,21 @@ public static StockData CalculateEhlersHammingMovingAverage(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevFilt = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevFilt = i >= 1 ? filtList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal filtSum = 0, coefSum = 0; for (int j = 0; j < length; j++) { - decimal prevV = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevV = i >= j ? inputList[i - j] : 0; decimal sine = Sin(pedestal + ((Pi - (2 * pedestal)) * ((decimal)j / (length - 1)))); filtSum += sine * prevV; coefSum += sine; } decimal filt = coefSum != 0 ? filtSum / coefSum : 0; - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); signalsList.Add(signal); @@ -8639,21 +8639,21 @@ public static StockData CalculateEhlersTriangleMovingAverage(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevFilt = i >= 1 ? filtList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevFilt = i >= 1 ? filtList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal filtSum = 0, coefSum = 0; for (int j = 1; j <= length; j++) { - decimal prevV = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; + decimal prevV = i >= j - 1 ? inputList[i - (j - 1)] : 0; decimal c = j < l2 ? j : j > l2 ? length + 1 - j : l2; filtSum += c * prevV; coefSum += c; } decimal filt = coefSum != 0 ? filtSum / coefSum : 0; - filtList.Add(filt); + filtList.AddRounded(filt); var signal = GetCompareSignal(currentValue - filt, prevValue - prevFilt); signalsList.Add(signal); diff --git a/Calculations/Oscillator.cs b/Calculations/Oscillator.cs index 935d23b..7f4ec9e 100644 --- a/Calculations/Oscillator.cs +++ b/Calculations/Oscillator.cs @@ -23,24 +23,24 @@ public static StockData CalculateCommodityChannelIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal tpSma = tpSmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal tpSma = tpSmaList[i]; decimal tpDevDiff = Math.Abs(currentValue - tpSma); - tpDevDiffList.Add(tpDevDiff); + tpDevDiffList.AddRounded(tpDevDiff); } var tpMeanDevList = GetMovingAverageList(stockData, maType, length, tpDevDiffList); for (int i = 0; i < stockData.Count; i++) { - decimal prevCci1 = i >= 1 ? cciList.ElementAtOrDefault(i - 1) : 0; - decimal prevCci2 = i >= 2 ? cciList.ElementAtOrDefault(i - 2) : 0; - decimal tpMeanDev = tpMeanDevList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal tpSma = tpSmaList.ElementAtOrDefault(i); + decimal prevCci1 = i >= 1 ? cciList[i - 1] : 0; + decimal prevCci2 = i >= 2 ? cciList[i - 2] : 0; + decimal tpMeanDev = tpMeanDevList[i]; + decimal currentValue = inputList[i]; + decimal tpSma = tpSmaList[i]; decimal cci = tpMeanDev != 0 ? (currentValue - tpSma) / (constant * tpMeanDev) : 0; - cciList.Add(cci); + cciList.AddRounded(cci); var signal = GetRsiSignal(cci - prevCci1, prevCci1 - prevCci2, cci, prevCci1, 100, -100); signalsList.Add(signal); @@ -78,12 +78,12 @@ public static StockData CalculateAwesomeOscillator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal fastSma = fastSmaList.ElementAtOrDefault(i); - decimal slowSma = slowSmaList.ElementAtOrDefault(i); + decimal fastSma = fastSmaList[i]; + decimal slowSma = slowSmaList[i]; decimal prevAo = aoList.LastOrDefault(); decimal ao = fastSma - slowSma; - aoList.Add(ao); + aoList.AddRounded(ao); var signal = GetCompareSignal(ao, prevAo); signalsList.Add(signal); @@ -121,12 +121,12 @@ public static StockData CalculateAcceleratorOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal ao = awesomeOscList.ElementAtOrDefault(i); - decimal aoSma = awesomeOscMaList.ElementAtOrDefault(i); + decimal ao = awesomeOscList[i]; + decimal aoSma = awesomeOscMaList[i]; decimal prevAc = acList.LastOrDefault(); decimal ac = ao - aoSma; - acList.Add(ac); + acList.AddRounded(ac); var signal = GetCompareSignal(ac, prevAc); signalsList.Add(signal); @@ -159,18 +159,18 @@ public static StockData CalculateUlcerIndex(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal maxValue = highestList.ElementAtOrDefault(i); - decimal prevUlcerIndex1 = i >= 1 ? ulcerIndexList.ElementAtOrDefault(i - 1) : 0; - decimal prevUlcerIndex2 = i >= 2 ? ulcerIndexList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal maxValue = highestList[i]; + decimal prevUlcerIndex1 = i >= 1 ? ulcerIndexList[i - 1] : 0; + decimal prevUlcerIndex2 = i >= 2 ? ulcerIndexList[i - 2] : 0; decimal pctDrawdownSquared = maxValue != 0 ? Pow((currentValue - maxValue) / maxValue * 100, 2) : 0; - pctDrawdownSquaredList.Add(pctDrawdownSquared); + pctDrawdownSquaredList.AddRounded(pctDrawdownSquared); decimal squaredAvg = pctDrawdownSquaredList.TakeLastExt(length).Average(); decimal ulcerIndex = squaredAvg >= 0 ? Sqrt(squaredAvg) : 0; - ulcerIndexList.Add(ulcerIndex); + ulcerIndexList.AddRounded(ulcerIndex); var signal = GetCompareSignal(ulcerIndex - prevUlcerIndex1, prevUlcerIndex1 - prevUlcerIndex2, true); signalsList.Add(signal); @@ -202,22 +202,22 @@ public static StockData CalculateBalanceOfPower(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal balanceOfPower = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; - balanceOfPowerList.Add(balanceOfPower); + balanceOfPowerList.AddRounded(balanceOfPower); } var bopSignalList = GetMovingAverageList(stockData, maType, length, balanceOfPowerList); for (int i = 0; i < stockData.ClosePrices.Count; i++) { - decimal bop = balanceOfPowerList.ElementAtOrDefault(i); - decimal bopMa = bopSignalList.ElementAtOrDefault(i); - decimal prevBop = i >= 1 ? balanceOfPowerList.ElementAtOrDefault(i - 1) : 0; - decimal prevBopMa = i >= 1 ? bopSignalList.ElementAtOrDefault(i - 1) : 0; + decimal bop = balanceOfPowerList[i]; + decimal bopMa = bopSignalList[i]; + decimal prevBop = i >= 1 ? balanceOfPowerList[i - 1] : 0; + decimal prevBopMa = i >= 1 ? bopSignalList[i - 1] : 0; var signal = GetCompareSignal(bop - bopMa, prevBop - prevBopMa); signalsList.Add(signal); @@ -249,13 +249,13 @@ public static StockData CalculateRateOfChange(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal prevRoc1 = i >= 1 ? rocList.ElementAtOrDefault(i - 1) : 0; - decimal prevRoc2 = i >= 2 ? rocList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; + decimal prevRoc1 = i >= 1 ? rocList[i - 1] : 0; + decimal prevRoc2 = i >= 2 ? rocList[i - 2] : 0; decimal roc = prevValue != 0 ? (currentValue - prevValue) / prevValue * 100 : 0; - rocList.Add(roc); + rocList.AddRounded(roc); var signal = GetCompareSignal(roc - prevRoc1, prevRoc1 - prevRoc2); signalsList.Add(signal); @@ -292,12 +292,12 @@ public static StockData CalculateChaikinOscillator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal adl3Ema = adl3EmaList.ElementAtOrDefault(i); - decimal adl10Ema = adl10EmaList.ElementAtOrDefault(i); + decimal adl3Ema = adl3EmaList[i]; + decimal adl10Ema = adl10EmaList[i]; decimal prevChaikinOscillator = chaikinOscillatorList.LastOrDefault(); decimal chaikinOscillator = adl3Ema - adl10Ema; - chaikinOscillatorList.Add(chaikinOscillator); + chaikinOscillatorList.AddRounded(chaikinOscillator); var signal = GetCompareSignal(chaikinOscillator, prevChaikinOscillator); signalsList.Add(signal); @@ -337,26 +337,26 @@ public static StockData CalculateIchimokuCloud(this StockData stockData, int ten for (int i = 0; i < stockData.Count; i++) { - decimal highest1 = tenkanHighList.ElementAtOrDefault(i); - decimal lowest1 = tenkanLowList.ElementAtOrDefault(i); - decimal highest2 = kijunHighList.ElementAtOrDefault(i); - decimal lowest2 = kijunLowList.ElementAtOrDefault(i); - decimal highest3 = senkouHighList.ElementAtOrDefault(i); - decimal lowest3 = senkouLowList.ElementAtOrDefault(i); + decimal highest1 = tenkanHighList[i]; + decimal lowest1 = tenkanLowList[i]; + decimal highest2 = kijunHighList[i]; + decimal lowest2 = kijunLowList[i]; + decimal highest3 = senkouHighList[i]; + decimal lowest3 = senkouLowList[i]; decimal prevTenkanSen = tenkanSenList.LastOrDefault(); decimal tenkanSen = (highest1 + lowest1) / 2; - tenkanSenList.Add(tenkanSen); + tenkanSenList.AddRounded(tenkanSen); decimal prevKijunSen = kijunSenList.LastOrDefault(); decimal kijunSen = (highest2 + lowest2) / 2; - kijunSenList.Add(kijunSen); + kijunSenList.AddRounded(kijunSen); decimal senkouSpanA = (tenkanSen + kijunSen) / 2; - senkouSpanAList.Add(senkouSpanA); + senkouSpanAList.AddRounded(senkouSpanA); decimal senkouSpanB = (highest3 + lowest3) / 2; - senkouSpanBList.Add(senkouSpanB); + senkouSpanBList.AddRounded(senkouSpanB); var signal = GetCompareSignal(tenkanSen - kijunSen, prevTenkanSen - prevKijunSen); signalsList.Add(signal); @@ -406,16 +406,16 @@ public static StockData CalculateAlligatorIndex(this StockData stockData, InputN for (int i = 0; i < stockData.Count; i++) { decimal prevJaw = displacedJawList.LastOrDefault(); - decimal displacedJaw = i >= jawOffset ? jawList.ElementAtOrDefault(i - jawOffset) : 0; - displacedJawList.Add(displacedJaw); + decimal displacedJaw = i >= jawOffset ? jawList[i - jawOffset] : 0; + displacedJawList.AddRounded(displacedJaw); decimal prevTeeth = displacedTeethList.LastOrDefault(); - decimal displacedTeeth = i >= teethOffset ? teethList.ElementAtOrDefault(i - teethOffset) : 0; - displacedTeethList.Add(displacedTeeth); + decimal displacedTeeth = i >= teethOffset ? teethList[i - teethOffset] : 0; + displacedTeethList.AddRounded(displacedTeeth); decimal prevLips = displacedLipsList.LastOrDefault(); - decimal displacedLips = i >= lipsOffset ? lipsList.ElementAtOrDefault(i - lipsOffset) : 0; - displacedLipsList.Add(displacedLips); + decimal displacedLips = i >= lipsOffset ? lipsList[i - lipsOffset] : 0; + displacedLipsList.AddRounded(displacedLips); var signal = GetBullishBearishSignal(displacedLips - Math.Max(displacedJaw, displacedTeeth), prevLips - Math.Max(prevJaw, prevTeeth), displacedLips - Math.Min(displacedJaw, displacedTeeth), prevLips - Math.Min(prevJaw, prevTeeth)); @@ -463,9 +463,9 @@ public static StockData CalculateGatorOscillator(this StockData stockData, Input for (int i = 0; i < stockData.Count; i++) { - decimal jaw = jawList.ElementAtOrDefault(i); - decimal teeth = teethList.ElementAtOrDefault(i); - decimal lips = lipsList.ElementAtOrDefault(i); + decimal jaw = jawList[i]; + decimal teeth = teethList[i]; + decimal lips = lipsList[i]; decimal prevTop = topList.LastOrDefault(); decimal top = Math.Abs(jaw - teeth); @@ -509,20 +509,20 @@ public static StockData CalculateUltimateOscillator(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal minValue = Math.Min(currentLow, prevClose); decimal maxValue = Math.Max(currentHigh, prevClose); - decimal prevUo1 = i >= 1 ? uoList.ElementAtOrDefault(i - 1) : 0; - decimal prevUo2 = i >= 2 ? uoList.ElementAtOrDefault(i - 2) : 0; + decimal prevUo1 = i >= 1 ? uoList[i - 1] : 0; + decimal prevUo2 = i >= 2 ? uoList[i - 2] : 0; decimal buyingPressure = currentClose - minValue; - bpList.Add(buyingPressure); + bpList.AddRounded(buyingPressure); decimal trueRange = maxValue - minValue; - trList.Add(trueRange); + trList.AddRounded(trueRange); decimal bp7Sum = bpList.TakeLastExt(length1).Sum(); decimal bp14Sum = bpList.TakeLastExt(length2).Sum(); @@ -535,7 +535,7 @@ public static StockData CalculateUltimateOscillator(this StockData stockData, in decimal avg28 = tr28Sum != 0 ? bp28Sum / tr28Sum : 0; decimal ultimateOscillator = MinOrMax(100 * (((4 * avg7) + (2 * avg14) + avg28) / (4 + 2 + 1)), 100, 0); - uoList.Add(ultimateOscillator); + uoList.AddRounded(ultimateOscillator); var signal = GetRsiSignal(ultimateOscillator - prevUo1, prevUo1 - prevUo2, ultimateOscillator, prevUo1, 70, 30); signalsList.Add(signal); @@ -570,20 +570,20 @@ public static StockData CalculateVortexIndicator(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; decimal vmPlus = Math.Abs(currentHigh - prevLow); - vmPlusList.Add(vmPlus); + vmPlusList.AddRounded(vmPlus); decimal vmMinus = Math.Abs(currentLow - prevHigh); - vmMinusList.Add(vmMinus); + vmMinusList.AddRounded(vmMinus); decimal trueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); - trueRangeList.Add(trueRange); + trueRangeList.AddRounded(trueRange); decimal vmPlus14 = vmPlusList.TakeLastExt(length).Sum(); decimal vmMinus14 = vmMinusList.TakeLastExt(length).Sum(); @@ -591,11 +591,11 @@ public static StockData CalculateVortexIndicator(this StockData stockData, int l decimal prevViPlus14 = viPlus14List.LastOrDefault(); decimal viPlus14 = trueRange14 != 0 ? vmPlus14 / trueRange14 : 0; - viPlus14List.Add(viPlus14); + viPlus14List.AddRounded(viPlus14); decimal prevViMinus14 = viMinus14List.LastOrDefault(); decimal viMinus14 = trueRange14 != 0 ? vmMinus14 / trueRange14 : 0; - viMinus14List.Add(viMinus14); + viMinus14List.AddRounded(viMinus14); var signal = GetCompareSignal(viPlus14 - viMinus14, prevViPlus14 - prevViMinus14); signalsList.Add(signal); @@ -634,20 +634,20 @@ public static StockData CalculateTrix(this StockData stockData, MovingAvgType ma for (int i = 0; i < stockData.Count; i++) { - decimal ema3 = ema3List.ElementAtOrDefault(i); - decimal prevEma3 = i >= 1 ? ema3List.ElementAtOrDefault(i - 1) : 0; + decimal ema3 = ema3List[i]; + decimal prevEma3 = i >= 1 ? ema3List[i - 1] : 0; decimal trix = CalculatePercentChange(ema3, prevEma3); - trixList.Add(trix); + trixList.AddRounded(trix); } var trixSignalList = GetMovingAverageList(stockData, maType, signalLength, trixList); for (int i = 0; i < stockData.Count; i++) { - decimal trix = trixList.ElementAtOrDefault(i); - decimal trixSignal = trixSignalList.ElementAtOrDefault(i); - decimal prevTrix = i >= 1 ? trixList.ElementAtOrDefault(i - 1) : 0; - decimal prevTrixSignal = i >= 1 ? trixSignalList.ElementAtOrDefault(i - 1) : 0; + decimal trix = trixList[i]; + decimal trixSignal = trixSignalList[i]; + decimal prevTrix = i >= 1 ? trixList[i - 1] : 0; + decimal prevTrixSignal = i >= 1 ? trixSignalList[i - 1] : 0; var signal = GetCompareSignal(trix - trixSignal, prevTrix - prevTrixSignal); signalsList.Add(signal); @@ -679,14 +679,14 @@ public static StockData CalculateWilliamsR(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevWilliamsR1 = i >= 1 ? williamsRList.ElementAtOrDefault(i - 1) : 0; - decimal prevWilliamsR2 = i >= 2 ? williamsRList.ElementAtOrDefault(i - 2) : 0; + decimal currentClose = inputList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevWilliamsR1 = i >= 1 ? williamsRList[i - 1] : 0; + decimal prevWilliamsR2 = i >= 2 ? williamsRList[i - 2] : 0; decimal williamsR = highestHigh - lowestLow != 0 ? -100 * (highestHigh - currentClose) / (highestHigh - lowestLow) : -100; - williamsRList.Add(williamsR); + williamsRList.AddRounded(williamsR); var signal = GetRsiSignal(williamsR - prevWilliamsR1, prevWilliamsR1 - prevWilliamsR2, williamsR, prevWilliamsR1, -20, -80); signalsList.Add(signal); @@ -723,14 +723,14 @@ public static StockData CalculateTrueStrengthIndex(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal pc = currentValue - prevValue; - pcList.Add(pc); + pcList.AddRounded(pc); decimal absPC = Math.Abs(pc); - absPCList.Add(absPC); + absPCList.AddRounded(absPC); } var pcSmooth1List = GetMovingAverageList(stockData, maType, length1, pcList); @@ -739,20 +739,20 @@ public static StockData CalculateTrueStrengthIndex(this StockData stockData, Mov var absPCSmooth2List = GetMovingAverageList(stockData, maType, length2, absPCSmooth1List); for (int i = 0; i < stockData.Count; i++) { - decimal absSmooth2PC = absPCSmooth2List.ElementAtOrDefault(i); - decimal smooth2PC = pcSmooth2List.ElementAtOrDefault(i); + decimal absSmooth2PC = absPCSmooth2List[i]; + decimal smooth2PC = pcSmooth2List[i]; decimal tsi = absSmooth2PC != 0 ? MinOrMax(100 * smooth2PC / absSmooth2PC, 100, -100) : 0; - tsiList.Add(tsi); + tsiList.AddRounded(tsi); } var tsiSignalList = GetMovingAverageList(stockData, maType, signalLength, tsiList); for (int i = 0; i < stockData.Count; i++) { - decimal tsi = tsiList.ElementAtOrDefault(i); - decimal tsiSignal = tsiSignalList.ElementAtOrDefault(i); - decimal prevTsi = i >= 1 ? tsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevTsiSignal = i >= 1 ? tsiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal tsi = tsiList[i]; + decimal tsiSignal = tsiSignalList[i]; + decimal prevTsi = i >= 1 ? tsiList[i - 1] : 0; + decimal prevTsiSignal = i >= 1 ? tsiSignalList[i - 1] : 0; var signal = GetRsiSignal(tsi - tsiSignal, prevTsi - prevTsiSignal, tsi, prevTsi, 25, -25); signalsList.Add(signal); @@ -789,17 +789,17 @@ public static StockData CalculateElderRayIndex(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentEma = emaList[i]; decimal prevBullPower = bullPowerList.LastOrDefault(); decimal bullPower = currentHigh - currentEma; - bullPowerList.Add(bullPower); + bullPowerList.AddRounded(bullPower); decimal prevBearPower = bearPowerList.LastOrDefault(); decimal bearPower = currentLow - currentEma; - bearPowerList.Add(bearPower); + bearPowerList.AddRounded(bearPower); var signal = GetCompareSignal(bullPower - bearPower, prevBullPower - prevBearPower); signalsList.Add(signal); @@ -837,12 +837,12 @@ public static StockData CalculateAbsolutePriceOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal fastEma = fastEmaList.ElementAtOrDefault(i); - decimal slowEma = slowEmaList.ElementAtOrDefault(i); + decimal fastEma = fastEmaList[i]; + decimal slowEma = slowEmaList[i]; decimal prevApo = apoList.LastOrDefault(); decimal apo = fastEma - slowEma; - apoList.Add(apo); + apoList.AddRounded(apo); var signal = GetCompareSignal(apo, prevApo); signalsList.Add(signal); @@ -875,12 +875,12 @@ public static StockData CalculateAroonOscillator(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - tempList.Add(currentPrice); + decimal currentPrice = inputList[i]; + tempList.AddRounded(currentPrice); - decimal maxPrice = highestList.ElementAtOrDefault(i); + decimal maxPrice = highestList[i]; int maxIndex = tempList.LastIndexOf(maxPrice); - decimal minPrice = lowestList.ElementAtOrDefault(i); + decimal minPrice = lowestList[i]; int minIndex = tempList.LastIndexOf(minPrice); int daysSinceMax = i - maxIndex; int daysSinceMin = i - minIndex; @@ -889,7 +889,7 @@ public static StockData CalculateAroonOscillator(this StockData stockData, int l decimal prevAroonOscillator = aroonOscillatorList.LastOrDefault(); decimal aroonOscillator = aroonUp - aroonDown; - aroonOscillatorList.Add(aroonOscillator); + aroonOscillatorList.AddRounded(aroonOscillator); var signal = GetCompareSignal(aroonOscillator, prevAroonOscillator); signalsList.Add(signal); @@ -930,38 +930,38 @@ public static StockData CalculateAbsoluteStrengthIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevA = AList.LastOrDefault(); decimal A = currentValue > prevValue && prevValue != 0 ? prevA + ((currentValue / prevValue) - 1) : prevA; - AList.Add(A); + AList.AddRounded(A); decimal prevM = MList.LastOrDefault(); decimal M = currentValue == prevValue ? prevM + ((decimal)1 / length) : prevM; - MList.Add(M); + MList.AddRounded(M); decimal prevD = DList.LastOrDefault(); decimal D = currentValue < prevValue && currentValue != 0 ? prevD + ((prevValue / currentValue) - 1) : prevD; - DList.Add(D); + DList.AddRounded(D); decimal abssi = (D + M) / 2 != 0 ? 1 - (1 / (1 + ((A + M) / 2 / ((D + M) / 2)))) : 1; decimal abssiEma = CalculateEMA(abssi, abssiEmaList.LastOrDefault(), maLength); - abssiEmaList.Add(abssiEma); + abssiEmaList.AddRounded(abssiEma); decimal abssio = abssi - abssiEma; decimal prevMt = mtList.LastOrDefault(); decimal mt = (alp * abssio) + ((1 - alp) * prevMt); - mtList.Add(mt); + mtList.AddRounded(mt); decimal prevUt = utList.LastOrDefault(); decimal ut = (alp * mt) + ((1 - alp) * prevUt); - utList.Add(ut); + utList.AddRounded(ut); decimal s = (2 - alp) * (mt - ut) / (1 - alp); decimal prevd = dList.LastOrDefault(); decimal d = abssio - s; - dList.Add(d); + dList.AddRounded(d); var signal = GetCompareSignal(d, prevd); signalsList.Add(signal); @@ -993,14 +993,14 @@ public static StockData CalculateAccumulativeSwingIndex(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevOpen = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevOpen = i >= 1 ? openList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal prevHighCurrentClose = prevHigh - currentClose; decimal prevLowCurrentClose = prevLow - currentClose; decimal prevClosePrevOpen = prevClose - prevOpen; @@ -1016,14 +1016,14 @@ public static StockData CalculateAccumulativeSwingIndex(this StockData stockData decimal prevSwingIndex = accumulativeSwingIndexList.LastOrDefault(); decimal accumulativeSwingIndex = prevSwingIndex + swingIndex; - accumulativeSwingIndexList.Add(accumulativeSwingIndex); + accumulativeSwingIndexList.AddRounded(accumulativeSwingIndex); } var asiOscillatorList = GetMovingAverageList(stockData, maType, length, accumulativeSwingIndexList); for (int i = 0; i < stockData.Count; i++) { - var asi = accumulativeSwingIndexList.ElementAtOrDefault(i); - var prevAsi = i >= 1 ? accumulativeSwingIndexList.ElementAtOrDefault(i - 1) : 0; + var asi = accumulativeSwingIndexList[i]; + var prevAsi = i >= 1 ? accumulativeSwingIndexList[i - 1] : 0; var signal = GetCompareSignal(asi, prevAsi); signalsList.Add(signal); @@ -1068,40 +1068,40 @@ public static StockData CalculateAdaptiveErgodicCandlestickOscillator(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal stoch = stochList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal stoch = stochList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; decimal vrb = Math.Abs(stoch - 50) / 50; decimal prevCame1 = came1List.LastOrDefault(); decimal came1 = i < ce ? currentClose - currentOpen : prevCame1 + (mep * vrb * (currentClose - currentOpen - prevCame1)); - came1List.Add(came1); + came1List.AddRounded(came1); decimal prevCame2 = came2List.LastOrDefault(); decimal came2 = i < ce ? currentHigh - currentLow : prevCame2 + (mep * vrb * (currentHigh - currentLow - prevCame2)); - came2List.Add(came2); + came2List.AddRounded(came2); decimal prevCame11 = came11List.LastOrDefault(); decimal came11 = i < ce ? came1 : prevCame11 + (mep * vrb * (came1 - prevCame11)); - came11List.Add(came11); + came11List.AddRounded(came11); decimal prevCame22 = came22List.LastOrDefault(); decimal came22 = i < ce ? came2 : prevCame22 + (mep * vrb * (came2 - prevCame22)); - came22List.Add(came22); + came22List.AddRounded(came22); decimal eco = came22 != 0 ? came11 / came22 * 100 : 0; - ecoList.Add(eco); + ecoList.AddRounded(eco); } var seList = GetMovingAverageList(stockData, maType, signalLength, ecoList); for (int i = 0; i < stockData.Count; i++) { - var eco = ecoList.ElementAtOrDefault(i); - var se = seList.ElementAtOrDefault(i); - var prevEco = i >= 1 ? ecoList.ElementAtOrDefault(i - 1) : 0; - var prevSe = i >= 1 ? seList.ElementAtOrDefault(i - 1) : 0; + var eco = ecoList[i]; + var se = seList[i]; + var prevEco = i >= 1 ? ecoList[i - 1] : 0; + var prevSe = i >= 1 ? seList[i - 1] : 0; var signal = GetCompareSignal(eco - se, prevEco - prevSe); signalsList.Add(signal); @@ -1143,8 +1143,8 @@ public static StockData CalculateAbsoluteStrengthMTFIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - prevValuesList.Add(prevValue); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + prevValuesList.AddRounded(prevValue); } var price1List = GetMovingAverageList(stockData, maType, length, inputList); @@ -1152,42 +1152,42 @@ public static StockData CalculateAbsoluteStrengthMTFIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal price1 = price1List.ElementAtOrDefault(i); - decimal price2 = price2List.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal price1 = price1List[i]; + decimal price2 = price2List[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal bulls0 = 0.5m * (Math.Abs(price1 - price2) + (price1 - price2)); - bulls0List.Add(bulls0); + bulls0List.AddRounded(bulls0); decimal bears0 = 0.5m * (Math.Abs(price1 - price2) - (price1 - price2)); - bears0List.Add(bears0); + bears0List.AddRounded(bears0); decimal bulls1 = price1 - lowest; - bulls1List.Add(bulls1); + bulls1List.AddRounded(bulls1); decimal bears1 = highest - price1; - bears1List.Add(bears1); + bears1List.AddRounded(bears1); decimal bulls2 = 0.5m * (Math.Abs(high - prevHigh) + (high - prevHigh)); - bulls2List.Add(bulls2); + bulls2List.AddRounded(bulls2); decimal bears2 = 0.5m * (Math.Abs(prevLow - low) + (prevLow - low)); - bears2List.Add(bears2); + 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++) { - decimal bulls = smthBulls0List.ElementAtOrDefault(i); - decimal bears = smthBears0List.ElementAtOrDefault(i); - decimal prevBulls = i >= 1 ? smthBulls0List.ElementAtOrDefault(i - 1) : 0; - decimal prevBears = i >= 1 ? smthBears0List.ElementAtOrDefault(i - 1) : 0; + decimal bulls = smthBulls0List[i]; + decimal bears = smthBears0List[i]; + decimal prevBulls = i >= 1 ? smthBulls0List[i - 1] : 0; + decimal prevBears = i >= 1 ? smthBears0List[i - 1] : 0; var signal = GetCompareSignal(bulls - bears, prevBulls - prevBears); signalsList.Add(signal); @@ -1229,16 +1229,16 @@ public static StockData CalculateJapaneseCorrelationCoefficient(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal c = cList.ElementAtOrDefault(i); - decimal prevC = i >= length ? cList.ElementAtOrDefault(i - length) : 0; - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevJo1 = i >= 1 ? joList.ElementAtOrDefault(i - 1) : 0; - decimal prevJo2 = i >= 2 ? joList.ElementAtOrDefault(i - 2) : 0; + decimal c = cList[i]; + decimal prevC = i >= length ? cList[i - length] : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevJo1 = i >= 1 ? joList[i - 1] : 0; + decimal prevJo2 = i >= 2 ? joList[i - 2] : 0; decimal cChg = c - prevC; decimal jo = highest - lowest != 0 ? cChg / (highest - lowest) : 0; - joList.Add(jo); + joList.AddRounded(jo); var signal = GetCompareSignal(jo - prevJo1, prevJo1 - prevJo2); signalsList.Add(signal); @@ -1287,82 +1287,82 @@ public static StockData CalculateJmaRsxClone(this StockData stockData, int lengt for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevRsx1 = i >= 1 ? rsxList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsx2 = i >= 2 ? rsxList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevRsx1 = i >= 1 ? rsxList[i - 1] : 0; + decimal prevRsx2 = i >= 2 ? rsxList[i - 2] : 0; decimal prevF8 = f8List.LastOrDefault(); decimal f8 = 100 * currentValue; - f8List.Add(f8); + f8List.AddRounded(f8); decimal f10 = prevF8; decimal v8 = f8 - f10; decimal prevF28 = f28List.LastOrDefault(); decimal f28 = (f20 * prevF28) + (f18 * v8); - f28List.Add(f28); + f28List.AddRounded(f28); decimal prevF30 = f30List.LastOrDefault(); decimal f30 = (f18 * f28) + (f20 * prevF30); - f30List.Add(f30); + f30List.AddRounded(f30); decimal vC = (f28 * 1.5m) - (f30 * 0.5m); decimal prevF38 = f38List.LastOrDefault(); decimal f38 = (f20 * prevF38) + (f18 * vC); - f38List.Add(f38); + f38List.AddRounded(f38); decimal prevF40 = f40List.LastOrDefault(); decimal f40 = (f18 * f38) + (f20 * prevF40); - f40List.Add(f40); + f40List.AddRounded(f40); decimal v10 = (f38 * 1.5m) - (f40 * 0.5m); decimal prevF48 = f48List.LastOrDefault(); decimal f48 = (f20 * prevF48) + (f18 * v10); - f48List.Add(f48); + f48List.AddRounded(f48); decimal prevF50 = f50List.LastOrDefault(); decimal f50 = (f18 * f48) + (f20 * prevF50); - f50List.Add(f50); + f50List.AddRounded(f50); decimal v14 = (f48 * 1.5m) - (f50 * 0.5m); decimal prevF58 = f58List.LastOrDefault(); decimal f58 = (f20 * prevF58) + (f18 * Math.Abs(v8)); - f58List.Add(f58); + f58List.AddRounded(f58); decimal prevF60 = f60List.LastOrDefault(); decimal f60 = (f18 * f58) + (f20 * prevF60); - f60List.Add(f60); + f60List.AddRounded(f60); decimal v18 = (f58 * 1.5m) - (f60 * 0.5m); decimal prevF68 = f68List.LastOrDefault(); decimal f68 = (f20 * prevF68) + (f18 * v18); - f68List.Add(f68); + f68List.AddRounded(f68); decimal prevF70 = f70List.LastOrDefault(); decimal f70 = (f18 * f68) + (f20 * prevF70); - f70List.Add(f70); + f70List.AddRounded(f70); decimal v1C = (f68 * 1.5m) - (f70 * 0.5m); decimal prevF78 = f78List.LastOrDefault(); decimal f78 = (f20 * prevF78) + (f18 * v1C); - f78List.Add(f78); + f78List.AddRounded(f78); decimal prevF80 = f80List.LastOrDefault(); decimal f80 = (f18 * f78) + (f20 * prevF80); - f80List.Add(f80); + f80List.AddRounded(f80); decimal v20 = (f78 * 1.5m) - (f80 * 0.5m); decimal prevF88 = f88List.LastOrDefault(); decimal prevF90_ = f90_List.LastOrDefault(); decimal f90_ = prevF90_ == 0 ? 1 : prevF88 <= prevF90_ ? prevF88 + 1 : prevF90_ + 1; - f90_List.Add(f90_); + f90_List.AddRounded(f90_); decimal f88 = prevF90_ == 0 && length - 1 >= 5 ? length - 1 : 5; decimal f0 = f88 >= f90_ && f8 != f10 ? 1 : 0; decimal f90 = f88 == f90_ && f0 == 0 ? 0 : f90_; decimal v4_ = f88 < f90 && v20 > 0 ? MinOrMax(((v14 / v20) + 1) * 50, 100, 0) : 50; decimal rsx = v4_ > 100 ? 100 : v4_ < 0 ? 0 : v4_; - rsxList.Add(rsx); + rsxList.AddRounded(rsx); var signal = GetRsiSignal(rsx - prevRsx1, prevRsx1 - prevRsx2, rsx, prevRsx1, 70, 30); signalsList.Add(signal); @@ -1406,15 +1406,15 @@ public static StockData CalculateJrcFractalDimension(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal highest1 = highest1List.ElementAtOrDefault(i); - decimal lowest1 = lowest1List.ElementAtOrDefault(i); - decimal prevValue1 = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; - decimal highest2 = highest2List.ElementAtOrDefault(i); - decimal lowest2 = lowest2List.ElementAtOrDefault(i); - decimal prevValue2 = i >= wind2 ? inputList.ElementAtOrDefault(i - wind2) : 0; + decimal highest1 = highest1List[i]; + decimal lowest1 = lowest1List[i]; + decimal prevValue1 = i >= length1 ? inputList[i - length1] : 0; + decimal highest2 = highest2List[i]; + decimal lowest2 = lowest2List[i]; + decimal prevValue2 = i >= wind2 ? inputList[i - wind2] : 0; decimal bigRange = Math.Max(prevValue2, highest2) - Math.Min(prevValue2, lowest2); - decimal prevSmallRange = i >= wind1 ? smallRangeList.ElementAtOrDefault(i - wind1) : 0; + decimal prevSmallRange = i >= wind1 ? smallRangeList[i - wind1] : 0; decimal smallRange = Math.Max(prevValue1, highest1) - Math.Min(prevValue1, lowest1); smallRangeList.AddRounded(smallRange); @@ -1434,10 +1434,10 @@ public static StockData CalculateJrcFractalDimension(this StockData stockData, M var jrcfdSignalList = GetMovingAverageList(stockData, maType, smoothLength, jrcfdList); for (int i = 0; i < stockData.Count; i++) { - var jrcfd = jrcfdList.ElementAtOrDefault(i); - var jrcfdSignal = jrcfdSignalList.ElementAtOrDefault(i); - var prevJrcfd = i >= 1 ? jrcfdList.ElementAtOrDefault(i - 1) : 0; - var prevJrcfdSignal = i >= 1 ? jrcfdSignalList.ElementAtOrDefault(i - 1) : 0; + var jrcfd = jrcfdList[i]; + var jrcfdSignal = jrcfdSignalList[i]; + var prevJrcfd = i >= 1 ? jrcfdList[i - 1] : 0; + var prevJrcfdSignal = i >= 1 ? jrcfdSignalList[i - 1] : 0; var signal = GetCompareSignal(jrcfd - jrcfdSignal, prevJrcfd - prevJrcfdSignal, true); signalsList.Add(signal); @@ -1473,28 +1473,28 @@ public static StockData CalculateZweigMarketBreadthIndicator(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal advance = currentValue > prevValue ? 1 : 0; - advancesList.Add(advance); + advancesList.AddRounded(advance); decimal decline = currentValue < prevValue ? 1 : 0; - declinesList.Add(decline); + declinesList.AddRounded(decline); decimal advSum = advancesList.TakeLastExt(length).Sum(); decimal decSum = declinesList.TakeLastExt(length).Sum(); decimal advDiff = advSum + decSum != 0 ? advSum / (advSum + decSum) : 0; - advDiffList.Add(advDiff); + advDiffList.AddRounded(advDiff); } var zmbtiList = GetMovingAverageList(stockData, maType, length, advDiffList); for (int i = 0; i < stockData.Count; i++) { - decimal prevZmbti1 = i >= 1 ? zmbtiList.ElementAtOrDefault(i - 1) : 0; - decimal prevZmbti2 = i >= 2 ? zmbtiList.ElementAtOrDefault(i - 2) : 0; - decimal zmbti = zmbtiList.ElementAtOrDefault(i); + decimal prevZmbti1 = i >= 1 ? zmbtiList[i - 1] : 0; + decimal prevZmbti2 = i >= 2 ? zmbtiList[i - 2] : 0; + decimal zmbti = zmbtiList[i]; var signal = GetRsiSignal(zmbti - prevZmbti1, prevZmbti1 - prevZmbti2, zmbti, prevZmbti1, 0.615m, 0.4m); signalsList.Add(signal); @@ -1531,14 +1531,14 @@ public static StockData CalculateZDistanceFromVwapIndicator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevZScore1 = i >= 1 ? zscoreList.ElementAtOrDefault(i - 1) : 0; - decimal prevZScore2 = i >= 2 ? zscoreList.ElementAtOrDefault(i - 2) : 0; - decimal mean = vwapList.ElementAtOrDefault(i); - decimal vwapsd = vwapSdList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevZScore1 = i >= 1 ? zscoreList[i - 1] : 0; + decimal prevZScore2 = i >= 2 ? zscoreList[i - 2] : 0; + decimal mean = vwapList[i]; + decimal vwapsd = vwapSdList[i]; decimal zscore = vwapsd != 0 ? (currentValue - mean) / vwapsd : 0; - zscoreList.Add(zscore); + zscoreList.AddRounded(zscore); var signal = GetRsiSignal(zscore - prevZScore1, prevZScore1 - prevZScore2, zscore, prevZScore1, 2, -2); signalsList.Add(signal); @@ -1573,14 +1573,14 @@ public static StockData CalculateZScore(this StockData stockData, MovingAvgType for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; decimal dev = currentValue - sma; - decimal stdDevPopulation = stdDevList.ElementAtOrDefault(i); + decimal stdDevPopulation = stdDevList[i]; decimal prevZScorePopulation = zScorePopulationList.LastOrDefault(); decimal zScorePopulation = stdDevPopulation != 0 ? dev / stdDevPopulation : 0; - zScorePopulationList.Add(zScorePopulation); + zScorePopulationList.AddRounded(zScorePopulation); var signal = GetCompareSignal(zScorePopulation, prevZScorePopulation); signalsList.Add(signal); @@ -1621,75 +1621,75 @@ public static StockData CalculateZeroLagSmoothedCycle(this StockData stockData, var linregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal linreg = linregList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal linreg = linregList[i]; decimal ax1 = currentValue - linreg; - ax1List.Add(ax1); + ax1List.AddRounded(ax1); } stockData.CustomValuesList = ax1List; var ax1LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal ax1 = ax1List.ElementAtOrDefault(i); - decimal ax1Linreg = ax1LinregList.ElementAtOrDefault(i); + decimal ax1 = ax1List[i]; + decimal ax1Linreg = ax1LinregList[i]; decimal lx1 = ax1 + (ax1 - ax1Linreg); - lx1List.Add(lx1); + lx1List.AddRounded(lx1); } stockData.CustomValuesList = lx1List; var lx1LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal lx1 = lx1List.ElementAtOrDefault(i); - decimal lx1Linreg = lx1LinregList.ElementAtOrDefault(i); + decimal lx1 = lx1List[i]; + decimal lx1Linreg = lx1LinregList[i]; decimal ax2 = lx1 - lx1Linreg; - ax2List.Add(ax2); + ax2List.AddRounded(ax2); } stockData.CustomValuesList = ax2List; var ax2LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal ax2 = ax2List.ElementAtOrDefault(i); - decimal ax2Linreg = ax2LinregList.ElementAtOrDefault(i); + decimal ax2 = ax2List[i]; + decimal ax2Linreg = ax2LinregList[i]; decimal lx2 = ax2 + (ax2 - ax2Linreg); - lx2List.Add(lx2); + lx2List.AddRounded(lx2); } stockData.CustomValuesList = lx2List; var lx2LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal lx2 = lx2List.ElementAtOrDefault(i); - decimal lx2Linreg = lx2LinregList.ElementAtOrDefault(i); + decimal lx2 = lx2List[i]; + decimal lx2Linreg = lx2LinregList[i]; decimal ax3 = lx2 - lx2Linreg; - ax3List.Add(ax3); + ax3List.AddRounded(ax3); } stockData.CustomValuesList = ax3List; var ax3LinregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal ax3 = ax3List.ElementAtOrDefault(i); - decimal ax3Linreg = ax3LinregList.ElementAtOrDefault(i); + decimal ax3 = ax3List[i]; + decimal ax3Linreg = ax3LinregList[i]; decimal prevLco = lcoList.LastOrDefault(); decimal lco = ax3 + (ax3 - ax3Linreg); - lcoList.Add(lco); + lcoList.AddRounded(lco); decimal lcoSma1 = lcoList.TakeLastExt(length1).Average(); - lcoSma1List.Add(lcoSma1); + lcoSma1List.AddRounded(lcoSma1); decimal lcoSma2 = lcoSma1List.TakeLastExt(length1).Average(); decimal prevFilter = filterList.LastOrDefault(); decimal filter = -lcoSma2 * 2; - filterList.Add(filter); + filterList.AddRounded(filter); var signal = GetCompareSignal(lco - filter, prevLco - prevFilter); signalsList.Add(signal); @@ -1737,33 +1737,33 @@ public static StockData CalculateBayesianOscillator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal upperBb = upperBbList.ElementAtOrDefault(i); - decimal basis = basisList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal upperBb = upperBbList[i]; + decimal basis = basisList[i]; decimal probBbUpperUpSeq = currentValue > upperBb ? 1 : 0; - probBbUpperUpSeqList.Add(probBbUpperUpSeq); + probBbUpperUpSeqList.AddRounded(probBbUpperUpSeq); decimal probBbUpperUp = probBbUpperUpSeqList.TakeLastExt(length).Average(); decimal probBbUpperDownSeq = currentValue < upperBb ? 1 : 0; - probBbUpperDownSeqList.Add(probBbUpperDownSeq); + probBbUpperDownSeqList.AddRounded(probBbUpperDownSeq); decimal probBbUpperDown = probBbUpperDownSeqList.TakeLastExt(length).Average(); decimal probUpBbUpper = probBbUpperUp + probBbUpperDown != 0 ? probBbUpperUp / (probBbUpperUp + probBbUpperDown) : 0; decimal probDownBbUpper = probBbUpperUp + probBbUpperDown != 0 ? probBbUpperDown / (probBbUpperUp + probBbUpperDown) : 0; decimal probBbBasisUpSeq = currentValue > basis ? 1 : 0; - probBbBasisUpSeqList.Add(probBbBasisUpSeq); + probBbBasisUpSeqList.AddRounded(probBbBasisUpSeq); decimal probBbBasisUp = probBbBasisUpSeqList.TakeLastExt(length).Average(); - probBbBasisUpList.Add(probBbBasisUp); + probBbBasisUpList.AddRounded(probBbBasisUp); decimal probBbBasisDownSeq = currentValue < basis ? 1 : 0; - probBbBasisDownSeqList.Add(probBbBasisDownSeq); + probBbBasisDownSeqList.AddRounded(probBbBasisDownSeq); decimal probBbBasisDown = probBbBasisDownSeqList.TakeLastExt(length).Average(); - probBbBasisDownList.Add(probBbBasisDown); + probBbBasisDownList.AddRounded(probBbBasisDown); decimal probUpBbBasis = probBbBasisUp + probBbBasisDown != 0 ? probBbBasisUp / (probBbBasisUp + probBbBasisDown) : 0; decimal probDownBbBasis = probBbBasisUp + probBbBasisDown != 0 ? probBbBasisDown / (probBbBasisUp + probBbBasisDown) : 0; @@ -1771,17 +1771,17 @@ public static StockData CalculateBayesianOscillator(this StockData stockData, Mo decimal prevSigmaProbsDown = sigmaProbsDownList.LastOrDefault(); decimal sigmaProbsDown = probUpBbUpper != 0 && probUpBbBasis != 0 ? ((probUpBbUpper * probUpBbBasis) / (probUpBbUpper * probUpBbBasis)) + ((1 - probUpBbUpper) * (1 - probUpBbBasis)) : 0; - sigmaProbsDownList.Add(sigmaProbsDown); + sigmaProbsDownList.AddRounded(sigmaProbsDown); decimal prevSigmaProbsUp = sigmaProbsUpList.LastOrDefault(); decimal sigmaProbsUp = probDownBbUpper != 0 && probDownBbBasis != 0 ? ((probDownBbUpper * probDownBbBasis) / (probDownBbUpper * probDownBbBasis)) + ((1 - probDownBbUpper) * (1 - probDownBbBasis)) : 0; - sigmaProbsUpList.Add(sigmaProbsUp); + sigmaProbsUpList.AddRounded(sigmaProbsUp); decimal prevProbPrime = probPrimeList.LastOrDefault(); decimal probPrime = sigmaProbsDown != 0 && sigmaProbsUp != 0 ? ((sigmaProbsDown * sigmaProbsUp) / (sigmaProbsDown * sigmaProbsUp)) + ((1 - sigmaProbsDown) * (1 - sigmaProbsUp)) : 0; - probPrimeList.Add(probPrime); + probPrimeList.AddRounded(probPrime); bool longUsingProbPrime = probPrime > lowerThreshold / 100 && prevProbPrime == 0; bool longUsingSigmaProbsUp = sigmaProbsUp < 1 && prevSigmaProbsUp == 1; @@ -1820,27 +1820,27 @@ public static StockData CalculateBearPowerIndicator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal open = openList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal close = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal open = openList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; decimal 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) : close > open ? Math.Max(prevClose - open, high - close) : prevClose < open ? Math.Max(open - low, high - close) : high - low; - bpiList.Add(bpi); + bpiList.AddRounded(bpi); } var bpiEmaList = GetMovingAverageList(stockData, maType, length, bpiList); for (int i = 0; i < stockData.Count; i++) { - var bpi = bpiList.ElementAtOrDefault(i); - var bpiEma = bpiEmaList.ElementAtOrDefault(i); - var prevBpi = i >= 1 ? bpiList.ElementAtOrDefault(i - 1) : 0; - var prevBpiEma = i >= 1 ? bpiEmaList.ElementAtOrDefault(i - 1) : 0; + var bpi = bpiList[i]; + var bpiEma = bpiEmaList[i]; + var prevBpi = i >= 1 ? bpiList[i - 1] : 0; + var prevBpiEma = i >= 1 ? bpiEmaList[i - 1] : 0; var signal = GetCompareSignal(bpi - bpiEma, prevBpi - prevBpiEma, true); signalsList.Add(signal); @@ -1873,27 +1873,27 @@ public static StockData CalculateBullPowerIndicator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal open = openList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal close = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal open = openList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; decimal 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 : prevClose > open ? Math.Max(high - open, close - low) : prevClose < open ? Math.Max(open - close, high - low) : high - low; - bpiList.Add(bpi); + bpiList.AddRounded(bpi); } var bpiEmaList = GetMovingAverageList(stockData, maType, length, bpiList); for (int i = 0; i < stockData.Count; i++) { - var bpi = bpiList.ElementAtOrDefault(i); - var bpiEma = bpiEmaList.ElementAtOrDefault(i); - var prevBpi = i >= 1 ? bpiList.ElementAtOrDefault(i - 1) : 0; - var prevBpiEma = i >= 1 ? bpiEmaList.ElementAtOrDefault(i - 1) : 0; + var bpi = bpiList[i]; + var bpiEma = bpiEmaList[i]; + var prevBpi = i >= 1 ? bpiList[i - 1] : 0; + var prevBpiEma = i >= 1 ? bpiEmaList[i - 1] : 0; var signal = GetCompareSignal(bpi - bpiEma, prevBpi - prevBpiEma, true); signalsList.Add(signal); @@ -1924,26 +1924,26 @@ public static StockData CalculateBelkhayateTiming(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh1 = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow1 = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh2 = i >= 2 ? highList.ElementAtOrDefault(i - 2) : 0; - decimal prevLow2 = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; - decimal prevHigh3 = i >= 3 ? highList.ElementAtOrDefault(i - 3) : 0; - decimal prevLow3 = i >= 3 ? lowList.ElementAtOrDefault(i - 3) : 0; - decimal prevHigh4 = i >= 4 ? highList.ElementAtOrDefault(i - 4) : 0; - decimal prevLow4 = i >= 4 ? lowList.ElementAtOrDefault(i - 4) : 0; - decimal prevB1 = i >= 1 ? bList.ElementAtOrDefault(i - 1) : 0; - decimal prevB2 = i >= 2 ? bList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh1 = i >= 1 ? highList[i - 1] : 0; + decimal prevLow1 = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh2 = i >= 2 ? highList[i - 2] : 0; + decimal prevLow2 = i >= 2 ? lowList[i - 2] : 0; + decimal prevHigh3 = i >= 3 ? highList[i - 3] : 0; + decimal prevLow3 = i >= 3 ? lowList[i - 3] : 0; + decimal prevHigh4 = i >= 4 ? highList[i - 4] : 0; + decimal prevLow4 = i >= 4 ? lowList[i - 4] : 0; + decimal prevB1 = i >= 1 ? bList[i - 1] : 0; + decimal prevB2 = i >= 2 ? bList[i - 2] : 0; decimal middle = (((currentHigh + currentLow) / 2) + ((prevHigh1 + prevLow1) / 2) + ((prevHigh2 + prevLow2) / 2) + ((prevHigh3 + prevLow3) / 2) + ((prevHigh4 + prevLow4) / 2)) / 5; decimal scale = ((currentHigh - currentLow + (prevHigh1 - prevLow1) + (prevHigh2 - prevLow2) + (prevHigh3 - prevLow3) + (prevHigh4 - prevLow4)) / 5) * 0.2m; decimal b = scale != 0 ? (currentValue - middle) / scale : 0; - bList.Add(b); + bList.AddRounded(b); var signal = GetRsiSignal(b - prevB1, prevB1 - prevB2, b, prevB1, 4, -4); signalsList.Add(signal); @@ -1982,9 +1982,9 @@ public static StockData CalculateUltimateTraderOscillator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevClose); trList.AddRounded(tr); @@ -1996,18 +1996,18 @@ public static StockData CalculateUltimateTraderOscillator(this StockData stockDa var vStoList = CalculateStochasticOscillator(stockData, maType, length: lbLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal body = close - openList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal close = inputList[i]; + decimal body = close - openList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; decimal range = high - low; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal c = close - prevClose; decimal sign = Math.Sign(c); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal vSto = vStoList.ElementAtOrDefault(i); - decimal trSto = trStoList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal vSto = vStoList[i]; + decimal trSto = trStoList[i]; decimal k1 = range != 0 ? body / range * 100 : 0; decimal k2 = range == 0 ? 0 : ((close - low) / range * 100 * 2) - 100; decimal k3 = c == 0 || highest - lowest == 0 ? 0 : ((close - lowest) / (highest - lowest) * 100 * 2) - 100; @@ -2018,10 +2018,10 @@ public static StockData CalculateUltimateTraderOscillator(this StockData stockDa decimal 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)); decimal dx = bearScore != 0 ? bullScore / bearScore : 0; - dxList.Add(dx); + dxList.AddRounded(dx); decimal dxi = (2 * (100 - (100 / (1 + dx)))) - 100; - dxiList.Add(dxi); + dxiList.AddRounded(dxi); } var dxiavgList = GetMovingAverageList(stockData, maType, lbLength, dxiList); @@ -2029,10 +2029,10 @@ public static StockData CalculateUltimateTraderOscillator(this StockData stockDa var dxissList = GetMovingAverageList(stockData, maType, smoothLength, dxisList); for (int i = 0; i < stockData.Count; i++) { - decimal dxis = dxisList.ElementAtOrDefault(i); - decimal dxiss = dxissList.ElementAtOrDefault(i); - decimal prevDxis = i >= 1 ? dxisList.ElementAtOrDefault(i - 1) : 0; - decimal prevDxiss = i >= 1 ? dxissList.ElementAtOrDefault(i - 1) : 0; + decimal dxis = dxisList[i]; + decimal dxiss = dxissList[i]; + decimal prevDxis = i >= 1 ? dxisList[i - 1] : 0; + decimal prevDxiss = i >= 1 ? dxissList[i - 1] : 0; var signal = GetCompareSignal(dxis - dxiss, prevDxis - prevDxiss); signalsList.Add(signal); @@ -2070,9 +2070,9 @@ public static StockData CalculateUhlMaCrossoverSystem(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevVar = i >= length ? varList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal prevVar = i >= length ? varList[i - length] : 0; decimal prevCma = i >= 1 ? cmaList.LastOrDefault() : currentValue; decimal prevCts = i >= 1 ? ctsList.LastOrDefault() : currentValue; decimal secma = Pow(sma - prevCma, 2); @@ -2081,10 +2081,10 @@ public static StockData CalculateUhlMaCrossoverSystem(this StockData stockData, decimal kb = prevVar < sects && sects != 0 ? 1 - (prevVar / sects) : 0; decimal cma = (ka * sma) + ((1 - ka) * prevCma); - cmaList.Add(cma); + cmaList.AddRounded(cma); decimal cts = (kb * currentValue) + ((1 - kb) * prevCts); - ctsList.Add(cts); + ctsList.AddRounded(cts); var signal = GetCompareSignal(cts - cma, prevCts - prevCma); signalsList.Add(signal); @@ -2125,23 +2125,23 @@ public static StockData CalculateMcClellanOscillator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal advance = currentValue > prevValue ? 1 : 0; - advancesList.Add(advance); + advancesList.AddRounded(advance); decimal decline = currentValue < prevValue ? 1 : 0; - declinesList.Add(decline); + declinesList.AddRounded(decline); decimal advanceSum = advancesList.TakeLastExt(fastLength).Sum(); - advancesSumList.Add(advanceSum); + advancesSumList.AddRounded(advanceSum); decimal declineSum = declinesList.TakeLastExt(fastLength).Sum(); - declinesSumList.Add(declineSum); + declinesSumList.AddRounded(declineSum); decimal rana = advanceSum + declineSum != 0 ? mult * (advanceSum - declineSum) / (advanceSum + declineSum) : 0; - ranaList.Add(rana); + ranaList.AddRounded(rana); } stockData.CustomValuesList = ranaList; @@ -2151,8 +2151,8 @@ public static StockData CalculateMcClellanOscillator(this StockData stockData, M var mcclellanHistogramList = moList.OutputValues["Histogram"]; for (int i = 0; i < stockData.Count; i++) { - decimal mcclellanHistogram = mcclellanHistogramList.ElementAtOrDefault(i); - decimal prevMcclellanHistogram = i >= 1 ? mcclellanHistogramList.ElementAtOrDefault(i - 1) : 0; + decimal mcclellanHistogram = mcclellanHistogramList[i]; + decimal prevMcclellanHistogram = i >= 1 ? mcclellanHistogramList[i - 1] : 0; var signal = GetCompareSignal(mcclellanHistogram, prevMcclellanHistogram); signalsList.Add(signal); @@ -2192,8 +2192,8 @@ public static StockData CalculateWoodieCommodityChannelIndex(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal cci = cciList.ElementAtOrDefault(i); - decimal cciTurbo = turboCciList.ElementAtOrDefault(i); + decimal cci = cciList[i]; + decimal cciTurbo = turboCciList[i]; decimal prevCciHistogram = histogramList.LastOrDefault(); decimal cciHistogram = cciTurbo - cci; @@ -2231,24 +2231,24 @@ public static StockData CalculateWilliamsFractals(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal prevHigh = i >= length - 2 ? highList.ElementAtOrDefault(i - (length - 2)) : 0; - decimal prevHigh1 = i >= length - 1 ? highList.ElementAtOrDefault(i - (length - 1)) : 0; - decimal prevHigh2 = i >= length ? highList.ElementAtOrDefault(i - length) : 0; - decimal prevHigh3 = i >= length + 1 ? highList.ElementAtOrDefault(i - (length + 1)) : 0; - decimal prevHigh4 = i >= length + 2 ? highList.ElementAtOrDefault(i - (length + 2)) : 0; - decimal prevHigh5 = i >= length + 3 ? highList.ElementAtOrDefault(i - (length + 3)) : 0; - decimal prevHigh6 = i >= length + 4 ? highList.ElementAtOrDefault(i - (length + 4)) : 0; - decimal prevHigh7 = i >= length + 5 ? highList.ElementAtOrDefault(i - (length + 5)) : 0; - decimal prevHigh8 = i >= length + 8 ? highList.ElementAtOrDefault(i - (length + 6)) : 0; - decimal prevLow = i >= length - 2 ? lowList.ElementAtOrDefault(i - (length - 2)) : 0; - decimal prevLow1 = i >= length - 1 ? lowList.ElementAtOrDefault(i - (length - 1)) : 0; - decimal prevLow2 = i >= length ? lowList.ElementAtOrDefault(i - length) : 0; - decimal prevLow3 = i >= length + 1 ? lowList.ElementAtOrDefault(i - (length + 1)) : 0; - decimal prevLow4 = i >= length + 2 ? lowList.ElementAtOrDefault(i - (length + 2)) : 0; - decimal prevLow5 = i >= length + 3 ? lowList.ElementAtOrDefault(i - (length + 3)) : 0; - decimal prevLow6 = i >= length + 4 ? lowList.ElementAtOrDefault(i - (length + 4)) : 0; - decimal prevLow7 = i >= length + 5 ? lowList.ElementAtOrDefault(i - (length + 5)) : 0; - decimal prevLow8 = i >= length + 8 ? lowList.ElementAtOrDefault(i - (length + 6)) : 0; + decimal prevHigh = i >= length - 2 ? highList[i - (length - 2)] : 0; + decimal prevHigh1 = i >= length - 1 ? highList[i - (length - 1)] : 0; + decimal prevHigh2 = i >= length ? highList[i - length] : 0; + decimal prevHigh3 = i >= length + 1 ? highList[i - (length + 1)] : 0; + decimal prevHigh4 = i >= length + 2 ? highList[i - (length + 2)] : 0; + decimal prevHigh5 = i >= length + 3 ? highList[i - (length + 3)] : 0; + decimal prevHigh6 = i >= length + 4 ? highList[i - (length + 4)] : 0; + decimal prevHigh7 = i >= length + 5 ? highList[i - (length + 5)] : 0; + decimal prevHigh8 = i >= length + 8 ? highList[i - (length + 6)] : 0; + decimal prevLow = i >= length - 2 ? lowList[i - (length - 2)] : 0; + decimal prevLow1 = i >= length - 1 ? lowList[i - (length - 1)] : 0; + decimal prevLow2 = i >= length ? lowList[i - length] : 0; + decimal prevLow3 = i >= length + 1 ? lowList[i - (length + 1)] : 0; + decimal prevLow4 = i >= length + 2 ? lowList[i - (length + 2)] : 0; + decimal prevLow5 = i >= length + 3 ? lowList[i - (length + 3)] : 0; + decimal prevLow6 = i >= length + 4 ? lowList[i - (length + 4)] : 0; + decimal prevLow7 = i >= length + 5 ? lowList[i - (length + 5)] : 0; + decimal prevLow8 = i >= length + 8 ? lowList[i - (length + 6)] : 0; decimal prevUpFractal = upFractalList.LastOrDefault(); decimal upFractal = (prevHigh4 < prevHigh2 && prevHigh3 < prevHigh2 && prevHigh1 < prevHigh2 && prevHigh < prevHigh2) || @@ -2258,7 +2258,7 @@ public static StockData CalculateWilliamsFractals(this StockData stockData, int prevHigh3 <= prevHigh2 && prevHigh1 < prevHigh2 && prevHigh < prevHigh2) || (prevHigh8 < prevHigh2 && prevHigh7 < prevHigh2 && prevHigh6 == prevHigh2 && prevHigh5 <= prevHigh2 && prevHigh4 == prevHigh2 && prevHigh3 <= prevHigh2 && prevHigh1 < prevHigh2 && prevHigh < prevHigh2) ? 1 : 0; - upFractalList.Add(upFractal); + upFractalList.AddRounded(upFractal); decimal prevDnFractal = dnFractalList.LastOrDefault(); decimal dnFractal = (prevLow4 > prevLow2 && prevLow3 > prevLow2 && prevLow1 > prevLow2 && prevLow > prevLow2) || (prevLow5 > prevLow2 && @@ -2267,7 +2267,7 @@ public static StockData CalculateWilliamsFractals(this StockData stockData, int (prevLow7 > prevLow2 && prevLow6 > prevLow2 && prevLow5 == prevLow2 && prevLow4 == prevLow2 && prevLow3 >= prevLow2 && prevLow1 > prevLow2 && prevLow > prevLow2) || (prevLow8 > prevLow2 && prevLow7 > prevLow2 && prevLow6 == prevLow2 && prevLow5 >= prevLow2 && prevLow4 == prevLow2 && prevLow3 >= prevLow2 && prevLow1 > prevLow2 && prevLow > prevLow2) ? 1 : 0; - dnFractalList.Add(dnFractal); + dnFractalList.AddRounded(dnFractal); var signal = GetCompareSignal(upFractal - dnFractal, prevUpFractal - prevDnFractal); signalsList.Add(signal); @@ -2298,14 +2298,14 @@ public static StockData CalculateWilliamsAccumulationDistribution(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; + decimal close = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; decimal prevWad = wadList.LastOrDefault(); decimal wad = close > prevClose ? prevWad + close - prevLow : close < prevClose ? prevWad + close - prevHigh : 0; - wadList.Add(wad); + wadList.AddRounded(wad); var signal = GetCompareSignal(wad, prevWad); signalsList.Add(signal); @@ -2339,11 +2339,11 @@ public static StockData CalculateWamiOscillator(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal diff = currentValue - prevValue; - diffList.Add(diff); + diffList.AddRounded(diff); } var wma1List = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, length2, diffList); @@ -2351,8 +2351,8 @@ public static StockData CalculateWamiOscillator(this StockData stockData, Moving var wamiList = GetMovingAverageList(stockData, maType, length1, ema2List); for (int i = 0; i < stockData.Count; i++) { - decimal wami = wamiList.ElementAtOrDefault(i); - decimal prevWami = i >= 1 ? wamiList.ElementAtOrDefault(i - 1) : 0; + decimal wami = wamiList[i]; + decimal prevWami = i >= 1 ? wamiList[i - 1] : 0; var signal = GetCompareSignal(wami, prevWami); signalsList.Add(signal); @@ -2397,14 +2397,14 @@ public static StockData CalculateWaddahAttarExplosion(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - temp1List.Add(prevValue1); + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + temp1List.AddRounded(prevValue1); - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - temp2List.Add(prevValue2); + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + temp2List.AddRounded(prevValue2); - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - temp3List.Add(prevValue3); + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; + temp3List.AddRounded(prevValue3); } stockData.CustomValuesList = temp1List; @@ -2415,12 +2415,12 @@ public static StockData CalculateWaddahAttarExplosion(this StockData stockData, var macd4List = CalculateMovingAverageConvergenceDivergence(stockData, fastLength: fastLength, slowLength: slowLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentMacd1 = macd1List.ElementAtOrDefault(i); - decimal currentMacd2 = macd2List.ElementAtOrDefault(i); - decimal currentMacd3 = macd3List.ElementAtOrDefault(i); - decimal currentMacd4 = macd4List.ElementAtOrDefault(i); - decimal currentUpperBB = upperBollingerBandList.ElementAtOrDefault(i); - decimal currentLowerBB = lowerBollingerBandList.ElementAtOrDefault(i); + decimal currentMacd1 = macd1List[i]; + decimal currentMacd2 = macd2List[i]; + decimal currentMacd3 = macd3List[i]; + decimal currentMacd4 = macd4List[i]; + decimal currentUpperBB = upperBollingerBandList[i]; + decimal currentLowerBB = lowerBollingerBandList[i]; decimal t1 = (currentMacd1 - currentMacd2) * sensitivity; t1List.AddRounded(t1); @@ -2430,14 +2430,14 @@ public static StockData CalculateWaddahAttarExplosion(this StockData stockData, decimal prevE1 = e1List.LastOrDefault(); decimal e1 = currentUpperBB - currentLowerBB; - e1List.Add(e1); + e1List.AddRounded(e1); decimal prevTrendUp = trendUpList.LastOrDefault(); decimal trendUp = (t1 >= 0) ? t1 : 0; - trendUpList.Add(trendUp); + trendUpList.AddRounded(trendUp); decimal trendDown = (t1 < 0) ? (-1 * t1) : 0; - trendDnList.Add(trendDown); + trendDnList.AddRounded(trendDown); var signal = GetConditionSignal(trendUp > prevTrendUp && trendUp > e1 && e1 > prevE1 && trendUp > fastLength && e1 > fastLength, trendUp < e1); @@ -2485,27 +2485,27 @@ public static StockData CalculateQuantitativeQualitativeEstimation(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentRsiEma = rsiEmaList.ElementAtOrDefault(i); - decimal prevRsiEma = i >= 1 ? rsiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal currentRsiEma = rsiEmaList[i]; + decimal prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; decimal atrRsi = Math.Abs(currentRsiEma - prevRsiEma); - atrRsiList.Add(atrRsi); + 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++) { - decimal atrRsiEmaSmooth = atrRsiEmaSmoothList.ElementAtOrDefault(i); - decimal prevAtrRsiEmaSmooth = i >= 1 ? atrRsiEmaSmoothList.ElementAtOrDefault(i - 1) : 0; + decimal atrRsiEmaSmooth = atrRsiEmaSmoothList[i]; + decimal prevAtrRsiEmaSmooth = i >= 1 ? atrRsiEmaSmoothList[i - 1] : 0; decimal prevFastTl = fastAtrRsiList.LastOrDefault(); decimal fastTl = atrRsiEmaSmooth * fastFactor; - fastAtrRsiList.Add(fastTl); + fastAtrRsiList.AddRounded(fastTl); decimal prevSlowTl = slowAtrRsiList.LastOrDefault(); decimal slowTl = atrRsiEmaSmooth * slowFactor; - slowAtrRsiList.Add(slowTl); + slowAtrRsiList.AddRounded(slowTl); var signal = GetBullishBearishSignal(atrRsiEmaSmooth - Math.Max(fastTl, slowTl), prevAtrRsiEmaSmooth - Math.Max(prevFastTl, prevSlowTl), atrRsiEmaSmooth - Math.Min(fastTl, slowTl), prevAtrRsiEmaSmooth - Math.Min(prevFastTl, prevSlowTl)); @@ -2543,12 +2543,12 @@ public static StockData CalculateQuasiWhiteNoise(this StockData stockData, Movin var connorsRsiList = CalculateConnorsRelativeStrengthIndex(stockData, maType, noiseLength, noiseLength, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal connorsRsi = connorsRsiList.ElementAtOrDefault(i); - decimal prevConnorsRsi1 = i >= 1 ? connorsRsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevConnorsRsi2 = i >= 2 ? connorsRsiList.ElementAtOrDefault(i - 2) : 0; + decimal connorsRsi = connorsRsiList[i]; + decimal prevConnorsRsi1 = i >= 1 ? connorsRsiList[i - 1] : 0; + decimal prevConnorsRsi2 = i >= 2 ? connorsRsiList[i - 2] : 0; decimal whiteNoise = (connorsRsi - 50) * (1 / divisor); - whiteNoiseList.Add(whiteNoise); + whiteNoiseList.AddRounded(whiteNoise); var signal = GetRsiSignal(connorsRsi - prevConnorsRsi1, prevConnorsRsi1 - prevConnorsRsi2, connorsRsi, prevConnorsRsi1, 70, 30); signalsList.Add(signal); @@ -2559,10 +2559,10 @@ public static StockData CalculateQuasiWhiteNoise(this StockData stockData, Movin var whiteNoiseStdDevList = CalculateStandardDeviationVolatility(stockData, maType, noiseLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal whiteNoiseStdDev = whiteNoiseStdDevList.ElementAtOrDefault(i); + decimal whiteNoiseStdDev = whiteNoiseStdDevList[i]; decimal whiteNoiseVariance = Pow(whiteNoiseStdDev, 2); - whiteNoiseVarianceList.Add(whiteNoiseVariance); + whiteNoiseVarianceList.AddRounded(whiteNoiseVariance); } stockData.OutputValues = new() @@ -2602,22 +2602,22 @@ public static StockData CalculateLBRPaintBars(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal currentAtr = atrList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal aatr = atrMult * currentAtr; - aatrList.Add(aatr); + aatrList.AddRounded(aatr); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = lowest + aatr; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = highest - aatr; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); var signal = GetBullishBearishSignal(currentValue - Math.Max(lowerBand, upperBand), prevValue - Math.Max(prevLowerBand, prevUpperBand), currentValue - Math.Min(lowerBand, upperBand), prevValue - Math.Min(prevLowerBand, prevUpperBand)); @@ -2657,23 +2657,23 @@ public static StockData CalculateLinearQuadraticConvergenceDivergenceOscillator( for (int i = 0; i < stockData.Count; i++) { - decimal linreg = linregList.ElementAtOrDefault(i); - decimal y = yList.ElementAtOrDefault(i); + decimal linreg = linregList[i]; + decimal y = yList[i]; decimal lqcd = y - linreg; - lqcdList.Add(lqcd); + lqcdList.AddRounded(lqcd); } var signList = GetMovingAverageList(stockData, maType, signalLength, lqcdList); for (int i = 0; i < stockData.Count; i++) { - decimal sign = signList.ElementAtOrDefault(i); - decimal lqcd = lqcdList.ElementAtOrDefault(i); + decimal sign = signList[i]; + decimal lqcd = lqcdList[i]; decimal osc = lqcd - sign; decimal prevHist = histList.LastOrDefault(); decimal hist = osc - sign; - histList.Add(hist); + histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); signalsList.Add(signal); @@ -2708,25 +2708,25 @@ public static StockData CalculateLogisticCorrelation(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); var corr = GoodnessOfFit.R(indexList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } for (int i = 0; i < stockData.Count; i++) { - decimal corr = corrList.ElementAtOrDefault(i); - decimal prevLog1 = i >= 1 ? logList.ElementAtOrDefault(i - 1) : 0; - decimal prevLog2 = i >= 2 ? logList.ElementAtOrDefault(i - 2) : 0; + decimal corr = corrList[i]; + decimal prevLog1 = i >= 1 ? logList[i - 1] : 0; + decimal prevLog2 = i >= 2 ? logList[i - 2] : 0; decimal log = 1 / (1 + Exp(k * -corr)); - logList.Add(log); + logList.AddRounded(log); var signal = GetCompareSignal(log - prevLog1, prevLog1 - prevLog2); signalsList.Add(signal); @@ -2767,31 +2767,31 @@ public static StockData CalculateLindaRaschke3_10Oscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal sma3 = fastSmaList.ElementAtOrDefault(i); - decimal sma10 = slowSmaList.ElementAtOrDefault(i); + decimal sma3 = fastSmaList[i]; + decimal sma10 = slowSmaList[i]; decimal ppo = sma10 != 0 ? (sma3 - sma10) / sma10 * 100 : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); decimal macd = sma3 - sma10; - macdList.Add(macd); + 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++) { - decimal ppo = ppoList.ElementAtOrDefault(i); - decimal ppoSignalLine = ppoSignalLineList.ElementAtOrDefault(i); - decimal macd = macdList.ElementAtOrDefault(i); - decimal macdSignalLine = macdSignalLineList.ElementAtOrDefault(i); + decimal ppo = ppoList[i]; + decimal ppoSignalLine = ppoSignalLineList[i]; + decimal macd = macdList[i]; + decimal macdSignalLine = macdSignalLineList[i]; decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); decimal prevMacdHistogram = macdHistogramList.LastOrDefault(); decimal macdHistogram = macd - macdSignalLine; - macdHistogramList.Add(macdHistogram); + macdHistogramList.AddRounded(macdHistogram); var signal = GetCompareSignal(macdHistogram, prevMacdHistogram); signalsList.Add(signal); @@ -2834,29 +2834,29 @@ public static StockData CalculateRelativeVolatilityIndexV1(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentStdDeviation = stdDeviationList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentStdDeviation = stdDeviationList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal up = currentValue > prevValue ? currentStdDeviation : 0; - upList.Add(up); + upList.AddRounded(up); decimal down = currentValue < prevValue ? currentStdDeviation : 0; - downList.Add(down); + 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++) { - decimal avgUp = upAvgList.ElementAtOrDefault(i); - decimal avgDown = downAvgList.ElementAtOrDefault(i); - decimal prevRvi1 = i >= 1 ? rviOriginalList.ElementAtOrDefault(i - 1) : 0; - decimal prevRvi2 = i >= 1 ? rviOriginalList.ElementAtOrDefault(i - 2) : 0; + decimal avgUp = upAvgList[i]; + decimal avgDown = downAvgList[i]; + decimal prevRvi1 = i >= 1 ? rviOriginalList[i - 1] : 0; + decimal prevRvi2 = i >= 2 ? rviOriginalList[i - 2] : 0; decimal rs = avgDown != 0 ? avgUp / avgDown : 0; decimal rvi = avgDown == 0 ? 100 : avgUp == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); - rviOriginalList.Add(rvi); + rviOriginalList.AddRounded(rvi); var signal = GetRsiSignal(rvi - prevRvi1, prevRvi1 - prevRvi2, rvi, prevRvi1, 70, 30); signalsList.Add(signal); @@ -2895,13 +2895,13 @@ public static StockData CalculateRelativeVolatilityIndexV2(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal rviOriginalHigh = rviHighList.ElementAtOrDefault(i); - decimal rviOriginalLow = rviLowList.ElementAtOrDefault(i); - decimal prevRvi1 = i >= 1 ? rviList.ElementAtOrDefault(i - 1) : 0; - decimal prevRvi2 = i >= 2 ? rviList.ElementAtOrDefault(i - 2) : 0; + decimal rviOriginalHigh = rviHighList[i]; + decimal rviOriginalLow = rviLowList[i]; + decimal prevRvi1 = i >= 1 ? rviList[i - 1] : 0; + decimal prevRvi2 = i >= 2 ? rviList[i - 2] : 0; decimal rvi = (rviOriginalHigh + rviOriginalLow) / 2; - rviList.Add(rvi); + rviList.AddRounded(rvi); var signal = GetRsiSignal(rvi - prevRvi1, prevRvi1 - prevRvi2, rvi, prevRvi1, 70, 30); signalsList.Add(signal); @@ -2935,9 +2935,9 @@ public static StockData CalculateInertiaIndicator(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal inertiaIndicator = inertiaList.ElementAtOrDefault(i); - decimal prevInertiaIndicator1 = i >= 1 ? inertiaList.ElementAtOrDefault(i - 1) : 0; - decimal prevInertiaIndicator2 = i >= 2 ? inertiaList.ElementAtOrDefault(i - 2) : 0; + decimal inertiaIndicator = inertiaList[i]; + decimal prevInertiaIndicator1 = i >= 1 ? inertiaList[i - 1] : 0; + decimal prevInertiaIndicator2 = i >= 2 ? inertiaList[i - 2] : 0; var signal = GetCompareSignal(inertiaIndicator - prevInertiaIndicator1, prevInertiaIndicator1 - prevInertiaIndicator2); signalsList.Add(signal); @@ -2971,20 +2971,20 @@ public static StockData CalculateInternalBarStrengthIndicator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal close = inputList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; decimal ibs = high - low != 0 ? (close - low) / (high - low) * 100 : 0; - ibsList.Add(ibs); + ibsList.AddRounded(ibs); decimal prevIbsi = ibsiList.LastOrDefault(); decimal ibsi = ibsList.TakeLastExt(length).Average(); - ibsiList.Add(ibsi); + ibsiList.AddRounded(ibsi); decimal prevIbsiEma = ibsEmaList.LastOrDefault(); decimal ibsiEma = CalculateEMA(ibsi, prevIbsiEma, smoothLength); - ibsEmaList.Add(ibsiEma); + ibsEmaList.AddRounded(ibsiEma); var signal = GetRsiSignal(ibsi - ibsiEma, prevIbsi - prevIbsiEma, ibsi, prevIbsi, 70, 30); signalsList.Add(signal); @@ -3028,15 +3028,15 @@ public static StockData CalculateInverseFisherFastZScore(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal linreg1 = linreg1List.ElementAtOrDefault(i); - decimal linreg2 = linreg2List.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); + decimal linreg1 = linreg1List[i]; + decimal linreg2 = linreg2List[i]; + decimal stdDev = stdDevList[i]; decimal fz = stdDev != 0 ? (linreg2 - linreg1) / stdDev / 2 : 0; - decimal prevIfz1 = i >= 1 ? ifzList.ElementAtOrDefault(i - 1) : 0; - decimal prevIfz2 = i >= 2 ? ifzList.ElementAtOrDefault(i - 2) : 0; + decimal prevIfz1 = i >= 1 ? ifzList[i - 1] : 0; + decimal prevIfz2 = i >= 2 ? ifzList[i - 2] : 0; decimal ifz = Exp(10 * fz) + 1 != 0 ? (Exp(10 * fz) - 1) / (Exp(10 * fz) + 1) : 0; - ifzList.Add(ifz); + ifzList.AddRounded(ifz); var signal = GetCompareSignal(ifz - prevIfz1, prevIfz1 - prevIfz2); signalsList.Add(signal); @@ -3072,16 +3072,16 @@ public static StockData CalculateInverseFisherZScore(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal prevF1 = i >= 1 ? fList.ElementAtOrDefault(i - 1) : 0; - decimal prevF2 = i >= 2 ? fList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal stdDev = stdDevList[i]; + decimal prevF1 = i >= 1 ? fList[i - 1] : 0; + decimal prevF2 = i >= 2 ? fList[i - 2] : 0; decimal z = stdDev != 0 ? (currentValue - sma) / stdDev : 0; decimal expZ = Exp(2 * z); decimal f = expZ + 1 != 0 ? MinOrMax((((expZ - 1) / (expZ + 1)) + 1) * 50, 100, 0) : 0; - fList.Add(f); + fList.AddRounded(f); var signal = GetRsiSignal(f - prevF1, prevF1 - prevF2, f, prevF1, 80, 20); signalsList.Add(signal); @@ -3150,49 +3150,49 @@ public static StockData CalculateInsyncIndex(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal bolins2 = bbIndicatorList.ElementAtOrDefault(i); - decimal prevPdoinss10 = i >= smaLength ? pdoinssList.ElementAtOrDefault(i - smaLength) : 0; - decimal prevPdoinsb10 = i >= smaLength ? pdoinsbList.ElementAtOrDefault(i - smaLength) : 0; - decimal cci = cciList.ElementAtOrDefault(i); - decimal mfi = mfiList.ElementAtOrDefault(i); - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal stochD = stochDList.ElementAtOrDefault(i); - decimal stochK = stochKList.ElementAtOrDefault(i); - decimal prevIidx1 = i >= 1 ? iidxList.ElementAtOrDefault(i - 1) : 0; - decimal prevIidx2 = i >= 2 ? iidxList.ElementAtOrDefault(i - 2) : 0; + decimal bolins2 = bbIndicatorList[i]; + decimal prevPdoinss10 = i >= smaLength ? pdoinssList[i - smaLength] : 0; + decimal prevPdoinsb10 = i >= smaLength ? pdoinsbList[i - smaLength] : 0; + decimal cci = cciList[i]; + decimal mfi = mfiList[i]; + decimal rsi = rsiList[i]; + decimal stochD = stochDList[i]; + decimal stochK = stochKList[i]; + decimal prevIidx1 = i >= 1 ? iidxList[i - 1] : 0; + decimal prevIidx2 = i >= 2 ? iidxList[i - 2] : 0; decimal bolinsll = bolins2 < 0.05m ? -5 : bolins2 > 0.95m ? 5 : 0; decimal cciins = cci > 100 ? 5 : cci < -100 ? -5 : 0; - decimal emo = emvList.ElementAtOrDefault(i); - emoList.Add(emo); + decimal emo = emvList[i]; + emoList.AddRounded(emo); decimal emoSma = emoList.TakeLastExt(smaLength).Average(); - emoSmaList.Add(emoSma); + emoSmaList.AddRounded(emoSma); decimal emvins2 = emo - emoSma; decimal emvinsb = emvins2 < 0 ? emoSma < 0 ? -5 : 0 : emoSma > 0 ? 5 : 0; - decimal macd = macdList.ElementAtOrDefault(i); - tempMacdList.Add(macd); + decimal macd = macdList[i]; + tempMacdList.AddRounded(macd); decimal macdSma = tempMacdList.TakeLastExt(smaLength).Average(); decimal macdins2 = macd - macdSma; decimal macdinsb = macdins2 < 0 ? macdSma < 0 ? -5 : 0 : macdSma > 0 ? 5 : 0; decimal mfiins = mfi > 80 ? 5 : mfi < 20 ? -5 : 0; - decimal dpo = dpoList.ElementAtOrDefault(i); - tempDpoList.Add(dpo); + decimal dpo = dpoList[i]; + tempDpoList.AddRounded(dpo); decimal dpoSma = tempDpoList.TakeLastExt(smaLength).Average(); decimal pdoins2 = dpo - dpoSma; decimal pdoinsb = pdoins2 < 0 ? dpoSma < 0 ? -5 : 0 : dpoSma > 0 ? 5 : 0; - pdoinsbList.Add(pdoinsb); + pdoinsbList.AddRounded(pdoinsb); decimal pdoinss = pdoins2 > 0 ? dpoSma > 0 ? 5 : 0 : dpoSma < 0 ? -5 : 0; - pdoinssList.Add(pdoinss); + pdoinssList.AddRounded(pdoinss); - decimal roc = rocList.ElementAtOrDefault(i); - tempRocList.Add(roc); + decimal roc = rocList[i]; + tempRocList.AddRounded(roc); decimal rocSma = tempRocList.TakeLastExt(smaLength).Average(); decimal rocins2 = roc - rocSma; @@ -3202,7 +3202,7 @@ public static StockData CalculateInsyncIndex(this StockData stockData, MovingAvg decimal stopkins = stochK > 80 ? 5 : stochK < 20 ? -5 : 0; decimal iidx = 50 + cciins + bolinsll + rsiins + stopkins + stopdins + mfiins + emvinsb + rocinsb + prevPdoinss10 + prevPdoinsb10 + macdinsb; - iidxList.Add(iidx); + iidxList.AddRounded(iidx); var signal = GetRsiSignal(iidx - prevIidx1, prevIidx1 - prevIidx2, iidx, prevIidx1, 95, 5); signalsList.Add(signal); @@ -3239,12 +3239,12 @@ public static StockData CalculateDetrendedPriceOscillator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= prevPeriods ? inputList.ElementAtOrDefault(i - prevPeriods) : 0; + decimal currentSma = smaList[i]; + decimal prevValue = i >= prevPeriods ? inputList[i - prevPeriods] : 0; decimal prevDpo = dpoList.LastOrDefault(); decimal dpo = prevValue - currentSma; - dpoList.Add(dpo); + dpoList.AddRounded(dpo); var signal = GetCompareSignal(dpo, prevDpo); signalsList.Add(signal); @@ -3278,22 +3278,22 @@ public static StockData CalculateOceanIndicator(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevLn = i >= length ? lnList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevLn = i >= length ? lnList[i - length] : 0; decimal ln = currentValue > 0 ? Log(currentValue) * 1000 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); decimal oi = (ln - prevLn) / Sqrt(length) * 100; - oiList.Add(oi); + oiList.AddRounded(oi); } var oiEmaList = GetMovingAverageList(stockData, maType, length, oiList); for (int i = 0; i < stockData.Count; i++) { - decimal oiEma = oiEmaList.ElementAtOrDefault(i); - decimal prevOiEma1 = i >= 1 ? oiEmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevOiEma2 = i >= 2 ? oiEmaList.ElementAtOrDefault(i - 2) : 0; + decimal oiEma = oiEmaList[i]; + decimal prevOiEma1 = i >= 1 ? oiEmaList[i - 1] : 0; + decimal prevOiEma2 = i >= 2 ? oiEmaList[i - 2] : 0; var signal = GetCompareSignal(oiEma - prevOiEma1, prevOiEma1 - prevOiEma2); signalsList.Add(signal); @@ -3326,15 +3326,15 @@ public static StockData CalculateOscarIndicator(this StockData stockData, int le for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal rough = highest - lowest != 0 ? MinOrMax((currentValue - lowest) / (highest - lowest) * 100, 100, 0) : 0; - decimal prevOscar1 = i >= 1 ? oscarList.ElementAtOrDefault(i - 1) : 0; - decimal prevOscar2 = i >= 2 ? oscarList.ElementAtOrDefault(i - 2) : 0; + decimal prevOscar1 = i >= 1 ? oscarList[i - 1] : 0; + decimal prevOscar2 = i >= 2 ? oscarList[i - 2] : 0; decimal oscar = (prevOscar1 / 6) + (rough / 3); - oscarList.Add(oscar); + oscarList.AddRounded(oscar); var signal = GetRsiSignal(oscar - prevOscar1, prevOscar1 - prevOscar2, oscar, prevOscar1, 80, 20); signalsList.Add(signal); @@ -3370,12 +3370,12 @@ public static StockData CalculateOCHistogram(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal currentCloseEma = closeEmaList.ElementAtOrDefault(i); - decimal currentOpenEma = openEmaList.ElementAtOrDefault(i); + decimal currentCloseEma = closeEmaList[i]; + decimal currentOpenEma = openEmaList[i]; decimal prevOcHistogram = ocHistogramList.LastOrDefault(); decimal ocHistogram = currentCloseEma - currentOpenEma; - ocHistogramList.Add(ocHistogram); + ocHistogramList.AddRounded(ocHistogram); var signal = GetCompareSignal(ocHistogram, prevOcHistogram); signalsList.Add(signal); @@ -3412,13 +3412,13 @@ public static StockData CalculateOscOscillator(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal fastSma = fastSmaList.ElementAtOrDefault(i); - decimal slowSma = slowSmaList.ElementAtOrDefault(i); - decimal prevOsc1 = i >= 1 ? oscList.ElementAtOrDefault(i - 1) : 0; - decimal prevOsc2 = i >= 2 ? oscList.ElementAtOrDefault(i - 2) : 0; + decimal fastSma = fastSmaList[i]; + decimal slowSma = slowSmaList[i]; + decimal prevOsc1 = i >= 1 ? oscList[i - 1] : 0; + decimal prevOsc2 = i >= 2 ? oscList[i - 2] : 0; decimal osc = slowSma - fastSma; - oscList.Add(osc); + oscList.AddRounded(osc); var signal = GetCompareSignal(osc - prevOsc1, prevOsc1 - prevOsc2); signalsList.Add(signal); @@ -3454,14 +3454,14 @@ public static StockData CalculateNaturalDirectionalCombo(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal ndx = ndxList.ElementAtOrDefault(i); - decimal nst = nstList.ElementAtOrDefault(i); - decimal prevNxc1 = i >= 1 ? nxcList.ElementAtOrDefault(i - 1) : 0; - decimal prevNxc2 = i >= 2 ? nxcList.ElementAtOrDefault(i - 2) : 0; + decimal ndx = ndxList[i]; + decimal nst = nstList[i]; + decimal prevNxc1 = i >= 1 ? nxcList[i - 1] : 0; + decimal prevNxc2 = i >= 2 ? nxcList[i - 2] : 0; decimal v3 = Math.Sign(ndx) != Math.Sign(nst) ? ndx * nst : ((Math.Abs(ndx) * nst) + (Math.Abs(nst) * ndx)) / 2; decimal nxc = Math.Sign(v3) * Sqrt(Math.Abs(v3)); - nxcList.Add(nxc); + nxcList.AddRounded(nxc); var signal = GetCompareSignal(nxc - prevNxc1, prevNxc1 - prevNxc2); signalsList.Add(signal); @@ -3496,16 +3496,16 @@ public static StockData CalculateNaturalDirectionalIndex(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal ln = currentValue > 0 ? Log(currentValue) * 1000 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); decimal weightSum = 0, denomSum = 0, absSum = 0; for (int j = 0; j < length; j++) { - decimal prevLn = i >= j + 1 ? lnList.ElementAtOrDefault(i - (j + 1)) : 0; - decimal currLn = i >= j ? lnList.ElementAtOrDefault(i - j) : 0; + decimal prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; + decimal currLn = i >= j ? lnList[i - j] : 0; decimal diff = prevLn - currLn; absSum += Math.Abs(diff); decimal frac = absSum != 0 ? (ln - currLn) / absSum : 0; @@ -3515,15 +3515,15 @@ public static StockData CalculateNaturalDirectionalIndex(this StockData stockDat } decimal rawNdx = denomSum != 0 ? weightSum / denomSum * 100 : 0; - rawNdxList.Add(rawNdx); + rawNdxList.AddRounded(rawNdx); } var ndxList = GetMovingAverageList(stockData, maType, smoothLength, rawNdxList); for (int i = 0; i < stockData.Count; i++) { - decimal ndx = ndxList.ElementAtOrDefault(i); - decimal prevNdx1 = i >= 1 ? ndxList.ElementAtOrDefault(i - 1) : 0; - decimal prevNdx2 = i >= 2 ? ndxList.ElementAtOrDefault(i - 2) : 0; + decimal ndx = ndxList[i]; + decimal prevNdx1 = i >= 1 ? ndxList[i - 1] : 0; + decimal prevNdx2 = i >= 2 ? ndxList[i - 2] : 0; var signal = GetCompareSignal(ndx - prevNdx1, prevNdx1 - prevNdx2); signalsList.Add(signal); @@ -3557,28 +3557,28 @@ public static StockData CalculateNaturalMarketMirror(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal ln = currentValue > 0 ? Log(currentValue) * 1000 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); decimal oiSum = 0; for (int j = 1; j <= length; j++) { - decimal prevLn = i >= j ? lnList.ElementAtOrDefault(i - j) : 0; + decimal prevLn = i >= j ? lnList[i - j] : 0; oiSum += (ln - prevLn) / Sqrt(j) * 100; } decimal oiAvg = oiSum / length; - oiAvgList.Add(oiAvg); + oiAvgList.AddRounded(oiAvg); } var nmmList = GetMovingAverageList(stockData, maType, length, oiAvgList); for (int i = 0; i < stockData.Count; i++) { - decimal nmm = nmmList.ElementAtOrDefault(i); - decimal prevNmm1 = i >= 1 ? nmmList.ElementAtOrDefault(i - 1) : 0; - decimal prevNmm2 = i >= 2 ? nmmList.ElementAtOrDefault(i - 2) : 0; + decimal nmm = nmmList[i]; + decimal prevNmm1 = i >= 1 ? nmmList[i - 1] : 0; + decimal prevNmm2 = i >= 2 ? nmmList[i - 2] : 0; var signal = GetCompareSignal(nmm - prevNmm1, prevNmm1 - prevNmm2); signalsList.Add(signal); @@ -3612,28 +3612,28 @@ public static StockData CalculateNaturalMarketRiver(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal ln = currentValue > 0 ? Log(currentValue) * 1000 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); decimal oiSum = 0; for (int j = 0; j < length; j++) { - decimal currentLn = i >= j ? lnList.ElementAtOrDefault(i - j) : 0; - decimal prevLn = i >= j + 1 ? lnList.ElementAtOrDefault(i - (j + 1)) : 0; + decimal currentLn = i >= j ? lnList[i - j] : 0; + decimal prevLn = i >= j + 1 ? lnList[i - (j + 1)] : 0; oiSum += (prevLn - currentLn) * (Sqrt(j) - Sqrt(j + 1)); } - oiSumList.Add(oiSum); + oiSumList.AddRounded(oiSum); } var nmrList = GetMovingAverageList(stockData, maType, length, oiSumList); for (int i = 0; i < stockData.Count; i++) { - decimal nmr = nmrList.ElementAtOrDefault(i); - decimal prevNmr1 = i >= 1 ? nmrList.ElementAtOrDefault(i - 1) : 0; - decimal prevNmr2 = i >= 2 ? nmrList.ElementAtOrDefault(i - 2) : 0; + decimal nmr = nmrList[i]; + decimal prevNmr1 = i >= 1 ? nmrList[i - 1] : 0; + decimal prevNmr2 = i >= 2 ? nmrList[i - 2] : 0; var signal = GetCompareSignal(nmr - prevNmr1, prevNmr1 - prevNmr2); signalsList.Add(signal); @@ -3669,20 +3669,20 @@ public static StockData CalculateNaturalMarketCombo(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal nmr = nmrList.ElementAtOrDefault(i); - decimal nmm = nmmList.ElementAtOrDefault(i); + decimal nmr = nmrList[i]; + decimal nmm = nmmList[i]; decimal v3 = Math.Sign(nmm) != Math.Sign(nmr) ? nmm * nmr : ((Math.Abs(nmm) * nmr) + (Math.Abs(nmr) * nmm)) / 2; decimal nmc = Math.Sign(v3) * Sqrt(Math.Abs(v3)); - nmcList.Add(nmc); + nmcList.AddRounded(nmc); } var nmcMaList = GetMovingAverageList(stockData, maType, smoothLength, nmcList); for (int i = 0; i < stockData.Count; i++) { - decimal nmc = nmcMaList.ElementAtOrDefault(i); - decimal prevNmc1 = i >= 1 ? nmcMaList.ElementAtOrDefault(i - 1) : 0; - decimal prevNmc2 = i >= 2 ? nmcMaList.ElementAtOrDefault(i - 2) : 0; + decimal nmc = nmcMaList[i]; + decimal prevNmc1 = i >= 1 ? nmcMaList[i - 1] : 0; + decimal prevNmc2 = i >= 2 ? nmcMaList[i - 2] : 0; var signal = GetCompareSignal(nmc - prevNmc1, prevNmc1 - prevNmc2); signalsList.Add(signal); @@ -3714,23 +3714,23 @@ public static StockData CalculateNaturalMarketSlope(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal ln = currentValue > 0 ? Log(currentValue) * 1000 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); } stockData.CustomValuesList = lnList; var linRegList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal linReg = linRegList.ElementAtOrDefault(i); - decimal prevLinReg = i >= 1 ? linRegList.ElementAtOrDefault(i - 1) : 0; - decimal prevNms1 = i >= 1 ? nmsList.ElementAtOrDefault(i - 1) : 0; - decimal prevNms2 = i >= 2 ? nmsList.ElementAtOrDefault(i - 2) : 0; + decimal linReg = linRegList[i]; + decimal prevLinReg = i >= 1 ? linRegList[i - 1] : 0; + decimal prevNms1 = i >= 1 ? nmsList[i - 1] : 0; + decimal prevNms2 = i >= 2 ? nmsList[i - 2] : 0; decimal nms = (linReg - prevLinReg) * Log(length); - nmsList.Add(nms); + nmsList.AddRounded(nms); var signal = GetCompareSignal(nms - prevNms1, prevNms1 - prevNms2); signalsList.Add(signal); @@ -3761,19 +3761,19 @@ public static StockData CalculateNarrowBandpassFilter(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal prevSum1 = i >= 1 ? sumList.ElementAtOrDefault(i - 1) : 0; - decimal prevSum2 = i >= 2 ? sumList.ElementAtOrDefault(i - 2) : 0; + decimal prevSum1 = i >= 1 ? sumList[i - 1] : 0; + decimal prevSum2 = i >= 2 ? sumList[i - 2] : 0; decimal sum = 0; for (int j = 0; j <= length - 1; j++) { - decimal prevValue = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevValue = i >= j ? inputList[i - j] : 0; decimal x = j / (decimal)(length - 1); decimal win = 0.42m - (0.5m * Cos(2 * Pi * x)) + (0.08m * Cos(4 * Pi * x)); decimal w = Sin(2 * Pi * j / length) * win; sum += prevValue * w; } - sumList.Add(sum); + sumList.AddRounded(sum); var signal = GetCompareSignal(sum - prevSum1, prevSum1 - prevSum2); signalsList.Add(signal); @@ -3805,12 +3805,12 @@ public static StockData CalculateNthOrderDifferencingOscillator(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal sum = 0, w = 1; for (int j = 0; j <= lbLength; j++) { - decimal prevValue = i >= length * (j + 1) ? inputList.ElementAtOrDefault(i - (length * (j + 1))) : 0; + decimal prevValue = i >= length * (j + 1) ? inputList[i - (length * (j + 1))] : 0; decimal x = Math.Sign(((j + 1) % 2) - 0.5); w *= (lbLength - j) / (decimal)(j + 1); sum += prevValue * w * x; @@ -3818,7 +3818,7 @@ public static StockData CalculateNthOrderDifferencingOscillator(this StockData s decimal prevNodo = nodoList.LastOrDefault(); decimal nodo = currentValue - sum; - nodoList.Add(nodo); + nodoList.AddRounded(nodo); var signal = GetCompareSignal(nodo, prevNodo); signalsList.Add(signal); @@ -3857,45 +3857,45 @@ public static StockData CalculateNormalizedRelativeVigorIndex(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal closeOpen = currentClose - currentOpen; - closeOpenList.Add(closeOpen); + closeOpenList.AddRounded(closeOpen); decimal highLow = currentHigh - currentLow; - highLowList.Add(highLow); + 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++) { - decimal swmaCloseOpen = swmaCloseOpenList.ElementAtOrDefault(i); - tempCloseOpenList.Add(swmaCloseOpen); + decimal swmaCloseOpen = swmaCloseOpenList[i]; + tempCloseOpenList.AddRounded(swmaCloseOpen); decimal closeOpenSum = tempCloseOpenList.TakeLastExt(length).Sum(); - swmaCloseOpenSumList.Add(closeOpenSum); + swmaCloseOpenSumList.AddRounded(closeOpenSum); - decimal swmaHighLow = swmaHighLowList.ElementAtOrDefault(i); - tempHighLowList.Add(swmaHighLow); + decimal swmaHighLow = swmaHighLowList[i]; + tempHighLowList.AddRounded(swmaHighLow); decimal highLowSum = tempHighLowList.TakeLastExt(length).Sum(); - swmaHighLowSumList.Add(highLowSum); + swmaHighLowSumList.AddRounded(highLowSum); decimal rvgi = highLowSum != 0 ? closeOpenSum / highLowSum * 100 : 0; - rvgiList.Add(rvgi); + rvgiList.AddRounded(rvgi); } var rvgiSignalList = GetMovingAverageList(stockData, maType, length, rvgiList); for (int i = 0; i < stockData.Count; i++) { - decimal rvgi = rvgiList.ElementAtOrDefault(i); - decimal rvgiSig = rvgiSignalList.ElementAtOrDefault(i); - decimal prevRvgi = i >= 1 ? rvgiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRvgiSig = i >= 1 ? rvgiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal rvgi = rvgiList[i]; + decimal rvgiSig = rvgiSignalList[i]; + decimal prevRvgi = i >= 1 ? rvgiList[i - 1] : 0; + decimal prevRvgiSig = i >= 1 ? rvgiSignalList[i - 1] : 0; var signal = GetCompareSignal(rvgi - rvgiSig, prevRvgi - prevRvgiSig); signalsList.Add(signal); @@ -3928,17 +3928,17 @@ public static StockData CalculateGannSwingOscillator(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevHighest1 = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowest1 = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal prevHighest2 = i >= 2 ? highestList.ElementAtOrDefault(i - 2) : 0; - decimal prevLowest2 = i >= 2 ? lowestList.ElementAtOrDefault(i - 2) : 0; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevHighest1 = i >= 1 ? highestList[i - 1] : 0; + decimal prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; + decimal prevHighest2 = i >= 2 ? highestList[i - 2] : 0; + decimal prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; decimal prevGso = gannSwingOscillatorList.LastOrDefault(); decimal gso = prevHighest2 > prevHighest1 && highestHigh > prevHighest1 ? 1 : prevLowest2 < prevLowest1 && lowestLow < prevLowest1 ? -1 : prevGso; - gannSwingOscillatorList.Add(gso); + gannSwingOscillatorList.AddRounded(gso); var signal = GetCompareSignal(gso, prevGso); signalsList.Add(signal); @@ -3974,16 +3974,16 @@ public static StockData CalculateGannHiLoActivator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal highMa = highMaList.ElementAtOrDefault(i); - decimal lowMa = lowMaList.ElementAtOrDefault(i); - decimal prevHighMa = i >= 1 ? highMaList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowMa = i >= 1 ? lowMaList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal highMa = highMaList[i]; + decimal lowMa = lowMaList[i]; + decimal prevHighMa = i >= 1 ? highMaList[i - 1] : 0; + decimal prevLowMa = i >= 1 ? lowMaList[i - 1] : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevGhla = ghlaList.LastOrDefault(); decimal ghla = currentValue > prevHighMa ? lowMa : currentValue < prevLowMa ? highMa : prevGhla; - ghlaList.Add(ghla); + ghlaList.AddRounded(ghla); var signal = GetCompareSignal(currentValue - ghla, prevValue - prevGhla); signalsList.Add(signal); @@ -4021,16 +4021,16 @@ public static StockData CalculateGroverLlorensCycleOscillator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal atr = atrList.ElementAtOrDefault(i); - decimal prevTs = i >= 1 ? tsList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal atr = atrList[i]; + decimal prevTs = i >= 1 ? tsList[i - 1] : currentValue; decimal diff = currentValue - prevTs; decimal ts = diff > 0 ? prevTs - (atr * mult) : diff < 0 ? prevTs + (atr * mult) : prevTs; tsList.AddRounded(ts); decimal osc = currentValue - ts; - oscList.Add(osc); + oscList.AddRounded(osc); } var smoList = GetMovingAverageList(stockData, maType, smoothLength, oscList); @@ -4038,9 +4038,9 @@ public static StockData CalculateGroverLlorensCycleOscillator(this StockData sto var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length: smoothLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal prevRsi1 = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsi2 = i >= 2 ? rsiList.ElementAtOrDefault(i - 2) : 0; + decimal rsi = rsiList[i]; + decimal prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; + decimal prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; var signal = GetRsiSignal(rsi - prevRsi1, prevRsi1 - prevRsi2, rsi, prevRsi1, 80, 20); signalsList.Add(signal); @@ -4077,18 +4077,18 @@ public static StockData CalculateGroverLlorensActivator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal atr = atrList.ElementAtOrDefault(i); - decimal prevTs = i >= 1 ? tsList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal atr = atrList[i]; + decimal prevTs = i >= 1 ? tsList[i - 1] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; prevTs = prevTs == 0 ? prevValue : prevTs; decimal prevDiff = diffList.LastOrDefault(); decimal diff = currentValue - prevTs; - diffList.Add(diff); + diffList.AddRounded(diff); decimal ts = diff > 0 ? prevTs - (atr * mult) : diff < 0 ? prevTs + (atr * mult) : prevTs; - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(diff, prevDiff); signalsList.Add(signal); @@ -4120,24 +4120,24 @@ public static StockData CalculateGuppyCountBackLine(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; decimal prevCbl = cblList.LastOrDefault(); int hCount = 0, lCount = 0; decimal cbl = currentValue; for (int j = 0; j <= length; j++) { - decimal currentLow = i >= j ? lowList.ElementAtOrDefault(i - j) : 0; - decimal currentHigh = i >= j ? highList.ElementAtOrDefault(i - j) : 0; + decimal currentLow = i >= j ? lowList[i - j] : 0; + decimal currentHigh = i >= j ? highList[i - j] : 0; if (currentLow == ll) { for (int k = j + 1; k <= j + length; k++) { - decimal prevHigh = i >= k ? highList.ElementAtOrDefault(i - k) : 0; + decimal prevHigh = i >= k ? highList[i - k] : 0; lCount += prevHigh > currentHigh ? 1 : 0; if (lCount == 2) { @@ -4151,7 +4151,7 @@ public static StockData CalculateGuppyCountBackLine(this StockData stockData, in { for (int k = j + 1; k <= j + length; k++) { - decimal prevLow = i >= k ? lowList.ElementAtOrDefault(i - k) : 0; + decimal prevLow = i >= k ? lowList[i - k] : 0; hCount += prevLow > currentLow ? 1 : 0; if (hCount == 2) { @@ -4161,7 +4161,7 @@ public static StockData CalculateGuppyCountBackLine(this StockData stockData, in } } } - cblList.Add(cbl); + cblList.AddRounded(cbl); var signal = GetCompareSignal(currentValue - cbl, prevValue - prevCbl); signalsList.Add(signal); @@ -4266,55 +4266,55 @@ public static StockData CalculateGuppyMultipleMovingAverage(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal emaF1 = ema3List.ElementAtOrDefault(i); - decimal emaF2 = ema5List.ElementAtOrDefault(i); - decimal emaF3 = ema7List.ElementAtOrDefault(i); - decimal emaF4 = ema9List.ElementAtOrDefault(i); - decimal emaF5 = ema11List.ElementAtOrDefault(i); - decimal emaF6 = ema13List.ElementAtOrDefault(i); - decimal emaF7 = ema15List.ElementAtOrDefault(i); - decimal emaF8 = ema17List.ElementAtOrDefault(i); - decimal emaF9 = ema19List.ElementAtOrDefault(i); - decimal emaF10 = ema21List.ElementAtOrDefault(i); - decimal emaF11 = ema23List.ElementAtOrDefault(i); - decimal emaS1 = ema25List.ElementAtOrDefault(i); - decimal emaS2 = ema28List.ElementAtOrDefault(i); - decimal emaS3 = ema31List.ElementAtOrDefault(i); - decimal emaS4 = ema34List.ElementAtOrDefault(i); - decimal emaS5 = ema37List.ElementAtOrDefault(i); - decimal emaS6 = ema40List.ElementAtOrDefault(i); - decimal emaS7 = ema43List.ElementAtOrDefault(i); - decimal emaS8 = ema46List.ElementAtOrDefault(i); - decimal emaS9 = ema49List.ElementAtOrDefault(i); - decimal emaS10 = ema52List.ElementAtOrDefault(i); - decimal emaS11 = ema55List.ElementAtOrDefault(i); - decimal emaS12 = ema58List.ElementAtOrDefault(i); - decimal emaS13 = ema61List.ElementAtOrDefault(i); - decimal emaS14 = ema64List.ElementAtOrDefault(i); - decimal emaS15 = ema67List.ElementAtOrDefault(i); - decimal emaS16 = ema70List.ElementAtOrDefault(i); + decimal emaF1 = ema3List[i]; + decimal emaF2 = ema5List[i]; + decimal emaF3 = ema7List[i]; + decimal emaF4 = ema9List[i]; + decimal emaF5 = ema11List[i]; + decimal emaF6 = ema13List[i]; + decimal emaF7 = ema15List[i]; + decimal emaF8 = ema17List[i]; + decimal emaF9 = ema19List[i]; + decimal emaF10 = ema21List[i]; + decimal emaF11 = ema23List[i]; + decimal emaS1 = ema25List[i]; + decimal emaS2 = ema28List[i]; + decimal emaS3 = ema31List[i]; + decimal emaS4 = ema34List[i]; + decimal emaS5 = ema37List[i]; + decimal emaS6 = ema40List[i]; + decimal emaS7 = ema43List[i]; + decimal emaS8 = ema46List[i]; + decimal emaS9 = ema49List[i]; + decimal emaS10 = ema52List[i]; + decimal emaS11 = ema55List[i]; + decimal emaS12 = ema58List[i]; + decimal emaS13 = ema61List[i]; + decimal emaS14 = ema64List[i]; + decimal emaS15 = ema67List[i]; + decimal emaS16 = ema70List[i]; decimal superGmmaFast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11) / 11; - superGmmaFastList.Add(superGmmaFast); + superGmmaFastList.AddRounded(superGmmaFast); decimal superGmmaSlow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + emaS14 + emaS15 + emaS16) / 16; - superGmmaSlowList.Add(superGmmaSlow); + superGmmaSlowList.AddRounded(superGmmaSlow); decimal superGmmaOscRaw = superGmmaSlow != 0 ? (superGmmaFast - superGmmaSlow) / superGmmaSlow * 100 : 0; - superGmmaOscRawList.Add(superGmmaOscRaw); + superGmmaOscRawList.AddRounded(superGmmaOscRaw); decimal superGmmaOsc = superGmmaOscRawList.TakeLastExt(smoothLength).Average(); - superGmmaOscList.Add(superGmmaOsc); + superGmmaOscList.AddRounded(superGmmaOsc); } var superGmmaSignalList = GetMovingAverageList(stockData, maType, signalLength, superGmmaOscRawList); for (int i = 0; i < stockData.Count; i++) { - decimal superGmmaOsc = superGmmaOscList.ElementAtOrDefault(i); - decimal superGmmaSignal = superGmmaSignalList.ElementAtOrDefault(i); - decimal prevSuperGmmaOsc = i >= 1 ? superGmmaOscList.ElementAtOrDefault(i - 1) : 0; - decimal prevSuperGmmaSignal = i >= 1 ? superGmmaSignalList.ElementAtOrDefault(i - 1) : 0; + decimal superGmmaOsc = superGmmaOscList[i]; + decimal superGmmaSignal = superGmmaSignalList[i]; + decimal prevSuperGmmaOsc = i >= 1 ? superGmmaOscList[i - 1] : 0; + decimal prevSuperGmmaSignal = i >= 1 ? superGmmaSignalList[i - 1] : 0; var signal = GetCompareSignal(superGmmaOsc - superGmmaSignal, prevSuperGmmaOsc - prevSuperGmmaSignal); signalsList.Add(signal); @@ -4374,18 +4374,18 @@ public static StockData CalculateGuppyDistanceIndicator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal ema1 = ema3List.ElementAtOrDefault(i); - decimal ema2 = ema5List.ElementAtOrDefault(i); - decimal ema3 = ema8List.ElementAtOrDefault(i); - decimal ema4 = ema10List.ElementAtOrDefault(i); - decimal ema5 = ema12List.ElementAtOrDefault(i); - decimal ema6 = ema15List.ElementAtOrDefault(i); - decimal ema7 = ema30List.ElementAtOrDefault(i); - decimal ema8 = ema35List.ElementAtOrDefault(i); - decimal ema9 = ema40List.ElementAtOrDefault(i); - decimal ema10 = ema45List.ElementAtOrDefault(i); - decimal ema11 = ema50List.ElementAtOrDefault(i); - decimal ema12 = ema60List.ElementAtOrDefault(i); + decimal ema1 = ema3List[i]; + decimal ema2 = ema5List[i]; + decimal ema3 = ema8List[i]; + decimal ema4 = ema10List[i]; + decimal ema5 = ema12List[i]; + decimal ema6 = ema15List[i]; + decimal ema7 = ema30List[i]; + decimal ema8 = ema35List[i]; + decimal ema9 = ema40List[i]; + decimal ema10 = ema45List[i]; + decimal ema11 = ema50List[i]; + decimal ema12 = ema60List[i]; decimal diff12 = Math.Abs(ema1 - ema2); decimal diff23 = Math.Abs(ema2 - ema3); decimal diff34 = Math.Abs(ema3 - ema4); @@ -4398,10 +4398,10 @@ public static StockData CalculateGuppyDistanceIndicator(this StockData stockData decimal diff1112 = Math.Abs(ema11 - ema12); decimal fastDistance = diff12 + diff23 + diff34 + diff45 + diff56; - fastDistanceList.Add(fastDistance); + fastDistanceList.AddRounded(fastDistance); decimal slowDistance = diff78 + diff89 + diff910 + diff1011 + diff1112; - slowDistanceList.Add(slowDistance); + 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; @@ -4439,16 +4439,16 @@ public static StockData CalculateGOscillator(this StockData stockData, int lengt for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevBSum1 = i >= 1 ? bSumList.ElementAtOrDefault(i - 1) : 0; - decimal prevBSum2 = i >= 2 ? bSumList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevBSum1 = i >= 1 ? bSumList[i - 1] : 0; + decimal prevBSum2 = i >= 2 ? bSumList[i - 2] : 0; decimal b = currentValue > prevValue ? (decimal)100 / length : 0; - bList.Add(b); + bList.AddRounded(b); decimal bSum = bList.TakeLastExt(length).Sum(); - bSumList.Add(bSum); + bSumList.AddRounded(bSum); var signal = GetRsiSignal(bSum - prevBSum1, prevBSum1 - prevBSum2, bSum, prevBSum1, 80, 20); signalsList.Add(signal); @@ -4482,20 +4482,20 @@ public static StockData CalculateGainLossMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal gainLoss = currentValue + prevValue != 0 ? (currentValue - prevValue) / ((currentValue + prevValue) / 2) * 100 : 0; - gainLossList.Add(gainLoss); + 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++) { - var gainLossSignal = gainLossAvgSignalList.ElementAtOrDefault(i); - var prevGainLossSignal1 = i >= 1 ? gainLossAvgSignalList.ElementAtOrDefault(i - 1) : 0; - var prevGainLossSignal2 = i >= 2 ? gainLossAvgSignalList.ElementAtOrDefault(i - 2) : 0; + var gainLossSignal = gainLossAvgSignalList[i]; + var prevGainLossSignal1 = i >= 1 ? gainLossAvgSignalList[i - 1] : 0; + var prevGainLossSignal2 = i >= 2 ? gainLossAvgSignalList[i - 2] : 0; var signal = GetCompareSignal(gainLossSignal - prevGainLossSignal1, prevGainLossSignal1 - prevGainLossSignal2); signalsList.Add(signal); @@ -4533,30 +4533,30 @@ public static StockData CalculateHighLowIndex(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal prevHighest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowest = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal prevHighest = i >= 1 ? highestList[i - 1] : 0; + decimal prevLowest = i >= 1 ? lowestList[i - 1] : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal adv = highest > prevHighest ? 1 : 0; - advList.Add(adv); + advList.AddRounded(adv); decimal lo = lowest < prevLowest ? 1 : 0; - loList.Add(lo); + loList.AddRounded(lo); decimal advSum = advList.TakeLastExt(length).Sum(); decimal loSum = loList.TakeLastExt(length).Sum(); decimal advDiff = advSum + loSum != 0 ? MinOrMax(advSum / (advSum + loSum) * 100, 100, 0) : 0; - advDiffList.Add(advDiff); + advDiffList.AddRounded(advDiff); } var zmbtiList = GetMovingAverageList(stockData, maType, length, advDiffList); for (int i = 0; i < stockData.Count; i++) { - decimal zmbti = zmbtiList.ElementAtOrDefault(i); - decimal prevZmbti1 = i >= 1 ? hliList.ElementAtOrDefault(i - 1) : 0; - decimal prevZmbti2 = i >= 2 ? hliList.ElementAtOrDefault(i - 2) : 0; + decimal zmbti = zmbtiList[i]; + decimal prevZmbti1 = i >= 1 ? hliList[i - 1] : 0; + decimal prevZmbti2 = i >= 2 ? hliList[i - 2] : 0; var signal = GetRsiSignal(zmbti - prevZmbti1, prevZmbti1 - prevZmbti2, zmbti, prevZmbti1, 70, 30); signalsList.Add(signal); @@ -4589,18 +4589,18 @@ public static StockData CalculateForecastOscillator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal pf = currentValue != 0 ? 100 * (currentValue - prevValue) / currentValue : 0; - pfList.Add(pf); + pfList.AddRounded(pf); } var pfSmaList = GetMovingAverageList(stockData, maType, length, pfList); for (int i = 0; i < stockData.Count; i++) { - var pfSma = pfSmaList.ElementAtOrDefault(i); - var prevPfSma = i >= 1 ? pfSmaList.ElementAtOrDefault(i - 1) : 0; + var pfSma = pfSmaList[i]; + var prevPfSma = i >= 1 ? pfSmaList[i - 1] : 0; var signal = GetCompareSignal(pfSma, prevPfSma); signalsList.Add(signal); @@ -4636,25 +4636,25 @@ public static StockData CalculateFastandSlowKurtosisOscillator(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal prevMomentum = momentumList.LastOrDefault(); decimal momentum = currentValue - prevValue; - momentumList.Add(momentum); + momentumList.AddRounded(momentum); decimal prevFsk = fskList.LastOrDefault(); decimal fsk = (ratio * (momentum - prevMomentum)) + ((1 - ratio) * prevFsk); - fskList.Add(fsk); + fskList.AddRounded(fsk); } var fskSignalList = GetMovingAverageList(stockData, maType, length, fskList); for (int i = 0; i < fskSignalList.Count; i++) { - decimal fsk = fskList.ElementAtOrDefault(i); - decimal fskSignal = fskSignalList.ElementAtOrDefault(i); - decimal prevFsk = i >= 1 ? fskList.ElementAtOrDefault(i - 1) : 0; - decimal prevFskSignal = i >= 1 ? fskSignalList.ElementAtOrDefault(i - 1) : 0; + decimal fsk = fskList[i]; + decimal fskSignal = fskSignalList[i]; + decimal prevFsk = i >= 1 ? fskList[i - 1] : 0; + decimal prevFskSignal = i >= 1 ? fskSignalList[i - 1] : 0; var signal = GetCompareSignal(fsk - fskSignal, prevFsk - prevFskSignal); signalsList.Add(signal); @@ -4694,20 +4694,20 @@ public static StockData CalculateFastandSlowRelativeStrengthIndexOscillator(this for (int i = 0; i < v4List.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal v4 = v4List.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; + decimal v4 = v4List[i]; decimal fsrsi = (10000 * v4) + rsi; - fsrsiList.Add(fsrsi); + fsrsiList.AddRounded(fsrsi); } var fsrsiSignalList = GetMovingAverageList(stockData, maType, length4, fsrsiList); - for (int j = 0; j < fsrsiSignalList.Count; j++) + for (int i = 0; i < fsrsiSignalList.Count; i++) { - decimal fsrsi = fsrsiList.ElementAtOrDefault(j); - decimal fsrsiSignal = fsrsiSignalList.ElementAtOrDefault(j); - decimal prevFsrsi = j >= 1 ? fsrsiList.ElementAtOrDefault(j - 1) : 0; - decimal prevFsrsiSignal = j >= 1 ? fsrsiSignalList.ElementAtOrDefault(j - 1) : 0; + decimal fsrsi = fsrsiList[i]; + decimal fsrsiSignal = fsrsiSignalList[i]; + decimal prevFsrsi = i >= 1 ? fsrsiList[i - 1] : 0; + decimal prevFsrsiSignal = i >= 1 ? fsrsiSignalList[i - 1] : 0; var signal = GetCompareSignal(fsrsi - fsrsiSignal, prevFsrsi - prevFsrsiSignal); signalsList.Add(signal); @@ -4752,57 +4752,57 @@ public static StockData CalculateFastSlowDegreeOscillator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal fastF1x = (decimal)(i + 1) / length; decimal fastF1b = (decimal)1 / (i + 1) * Sin(fastF1x * (i + 1) * Pi); - fastF1bList.Add(fastF1b); + fastF1bList.AddRounded(fastF1b); decimal fastF1bSum = fastF1bList.TakeLastExt(fastLength).Sum(); decimal fastF1pol = (fastF1x * fastF1x) + fastF1bSum; decimal fastF2x = length != 0 ? (decimal)i / length : 0; decimal fastF2b = (decimal)1 / (i + 1) * Sin(fastF2x * (i + 1) * Pi); - fastF2bList.Add(fastF2b); + fastF2bList.AddRounded(fastF2b); decimal fastF2bSum = fastF2bList.TakeLastExt(fastLength).Sum(); decimal fastF2pol = (fastF2x * fastF2x) + fastF2bSum; decimal fastW = fastF1pol - fastF2pol; decimal fastVW = prevValue * fastW; - fastVWList.Add(fastVW); + fastVWList.AddRounded(fastVW); decimal fastVWSum = fastVWList.TakeLastExt(length).Sum(); decimal slowF1x = length != 0 ? (decimal)(i + 1) / length : 0; decimal slowF1b = (decimal)1 / (i + 1) * Sin(slowF1x * (i + 1) * Pi); - slowF1bList.Add(slowF1b); + slowF1bList.AddRounded(slowF1b); decimal slowF1bSum = slowF1bList.TakeLastExt(slowLength).Sum(); decimal slowF1pol = (slowF1x * slowF1x) + slowF1bSum; decimal slowF2x = length != 0 ? (decimal)i / length : 0; decimal slowF2b = (decimal)1 / (i + 1) * Sin(slowF2x * (i + 1) * Pi); - slowF2bList.Add(slowF2b); + slowF2bList.AddRounded(slowF2b); decimal slowF2bSum = slowF2bList.TakeLastExt(slowLength).Sum(); decimal slowF2pol = (slowF2x * slowF2x) + slowF2bSum; decimal slowW = slowF1pol - slowF2pol; decimal slowVW = prevValue * slowW; - slowVWList.Add(slowVW); + slowVWList.AddRounded(slowVW); decimal slowVWSum = slowVWList.TakeLastExt(length).Sum(); - slowVWSumList.Add(slowVWSum); + slowVWSumList.AddRounded(slowVWSum); decimal os = fastVWSum - slowVWSum; - osList.Add(os); + osList.AddRounded(os); } var osSignalList = GetMovingAverageList(stockData, maType, signalLength, osList); for (int i = 0; i < stockData.Count; i++) { - decimal os = osList.ElementAtOrDefault(i); - decimal osSignal = osSignalList.ElementAtOrDefault(i); + decimal os = osList[i]; + decimal osSignal = osSignalList[i]; decimal prevHist = histList.LastOrDefault(); decimal hist = os - osSignal; - histList.Add(hist); + histList.AddRounded(hist); var signal = GetCompareSignal(hist, prevHist); signalsList.Add(signal); @@ -4837,14 +4837,14 @@ public static StockData CalculateFractalChaosOscillator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal upperBand = upperBandList.ElementAtOrDefault(i); - decimal prevUpperBand = i >= 1 ? upperBandList.ElementAtOrDefault(i - 1) : 0; - decimal lowerBand = lowerBandList.ElementAtOrDefault(i); - decimal prevLowerBand = i >= 1 ? lowerBandList.ElementAtOrDefault(i - 1) : 0; + decimal upperBand = upperBandList[i]; + decimal prevUpperBand = i >= 1 ? upperBandList[i - 1] : 0; + decimal lowerBand = lowerBandList[i]; + decimal prevLowerBand = i >= 1 ? lowerBandList[i - 1] : 0; decimal prevFco = fcoList.LastOrDefault(); decimal fco = upperBand != prevUpperBand ? 1 : lowerBand != prevLowerBand ? -1 : 0; - fcoList.Add(fco); + fcoList.AddRounded(fco); var signal = GetCompareSignal(fco, prevFco); signalsList.Add(signal); @@ -4881,12 +4881,12 @@ public static StockData CalculateFireflyOscillator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; decimal v2 = (currentHigh + currentLow + (currentClose * 2)) / 4; - v2List.Add(v2); + v2List.AddRounded(v2); } var v3List = GetMovingAverageList(stockData, maType, length, v2List); @@ -4894,12 +4894,12 @@ public static StockData CalculateFireflyOscillator(this StockData stockData, Mov var v4List = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal v2 = v2List.ElementAtOrDefault(i); - decimal v3 = v3List.ElementAtOrDefault(i); - decimal v4 = v4List.ElementAtOrDefault(i); + decimal v2 = v2List[i]; + decimal v3 = v3List[i]; + decimal v4 = v4List[i]; decimal v5 = v4 == 0 ? (v2 - v3) * 100 : (v2 - v3) * 100 / v4; - v5List.Add(v5); + v5List.AddRounded(v5); } var v6List = GetMovingAverageList(stockData, maType, smoothLength, v5List); @@ -4907,15 +4907,15 @@ public static StockData CalculateFireflyOscillator(this StockData stockData, Mov var wwZLagEmaList = GetMovingAverageList(stockData, maType, length, v7List); for (int i = 0; i < stockData.Count; i++) { - decimal wwZlagEma = wwZLagEmaList.ElementAtOrDefault(i); - decimal prevWw1 = i >= 1 ? wwList.ElementAtOrDefault(i - 1) : 0; - decimal prevWw2 = i >= 2 ? wwList.ElementAtOrDefault(i - 2) : 0; + decimal wwZlagEma = wwZLagEmaList[i]; + decimal prevWw1 = i >= 1 ? wwList[i - 1] : 0; + decimal prevWw2 = i >= 2 ? wwList[i - 2] : 0; decimal ww = ((wwZlagEma + 100) / 2) - 4; - wwList.Add(ww); + wwList.AddRounded(ww); decimal mm = wwList.TakeLastExt(smoothLength).Max(); - mmList.Add(mm); + mmList.AddRounded(mm); var signal = GetRsiSignal(ww - prevWw1, prevWw1 - prevWw2, ww, prevWw1, 80, 20); signalsList.Add(signal); @@ -4955,19 +4955,19 @@ public static StockData CalculateFibonacciRetrace(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal wma = wmaList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; + decimal wma = wmaList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevWma = i >= 1 ? wmaList[i - 1] : 0; decimal retrace = (highest - lowest) * factor; decimal prevHret = hretList.LastOrDefault(); decimal hret = highest - retrace; - hretList.Add(hret); + hretList.AddRounded(hret); decimal prevLret = lretList.LastOrDefault(); decimal lret = lowest + retrace; - lretList.Add(lret); + lretList.AddRounded(lret); var signal = GetBullishBearishSignal(wma - hret, prevWma - prevHret, wma - lret, prevWma - prevLret); signalsList.Add(signal); @@ -5020,35 +5020,35 @@ public static StockData CalculateFXSniperIndicator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal cci = cciList.ElementAtOrDefault(i); + decimal cci = cciList[i]; decimal prevE1 = e1List.LastOrDefault(); decimal e1 = (w1 * cci) + (w2 * prevE1); - e1List.Add(e1); + e1List.AddRounded(e1); decimal prevE2 = e2List.LastOrDefault(); decimal e2 = (w1 * e1) + (w2 * prevE2); - e2List.Add(e2); + e2List.AddRounded(e2); decimal prevE3 = e3List.LastOrDefault(); decimal e3 = (w1 * e2) + (w2 * prevE3); - e3List.Add(e3); + e3List.AddRounded(e3); decimal prevE4 = e4List.LastOrDefault(); decimal e4 = (w1 * e3) + (w2 * prevE4); - e4List.Add(e4); + e4List.AddRounded(e4); decimal prevE5 = e5List.LastOrDefault(); decimal e5 = (w1 * e4) + (w2 * prevE5); - e5List.Add(e5); + e5List.AddRounded(e5); decimal prevE6 = e6List.LastOrDefault(); decimal e6 = (w1 * e5) + (w2 * prevE6); - e6List.Add(e6); + e6List.AddRounded(e6); decimal prevFxSniper = fxSniperList.LastOrDefault(); decimal fxsniper = (c1 * e6) + (c2 * e5) + (c3 * e4) + (c4 * e3); - fxSniperList.Add(fxsniper); + fxSniperList.AddRounded(fxsniper); var signal = GetCompareSignal(fxsniper, prevFxSniper); signalsList.Add(signal); @@ -5085,17 +5085,17 @@ public static StockData CalculateFearAndGreedIndicator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); decimal trUp = currentValue > prevValue ? tr : 0; - trUpList.Add(trUp); + trUpList.AddRounded(trUp); decimal trDn = currentValue < prevValue ? tr : 0; - trDnList.Add(trDn); + trDnList.AddRounded(trDn); } var fastTrUpList = GetMovingAverageList(stockData, maType, fastLength, trUpList); @@ -5104,22 +5104,22 @@ public static StockData CalculateFearAndGreedIndicator(this StockData stockData, var slowTrDnList = GetMovingAverageList(stockData, maType, slowLength, trDnList); for (int i = 0; i < stockData.Count; i++) { - decimal fastTrUp = fastTrUpList.ElementAtOrDefault(i); - decimal fastTrDn = fastTrDnList.ElementAtOrDefault(i); - decimal slowTrUp = slowTrUpList.ElementAtOrDefault(i); - decimal slowTrDn = slowTrDnList.ElementAtOrDefault(i); + decimal fastTrUp = fastTrUpList[i]; + decimal fastTrDn = fastTrDnList[i]; + decimal slowTrUp = slowTrUpList[i]; + decimal slowTrDn = slowTrDnList[i]; decimal fastDiff = fastTrUp - fastTrDn; decimal slowDiff = slowTrUp - slowTrDn; decimal fgi = fastDiff - slowDiff; - fgiList.Add(fgi); + fgiList.AddRounded(fgi); } var fgiEmaList = GetMovingAverageList(stockData, maType, smoothLength, fgiList); for (int i = 0; i < stockData.Count; i++) { - decimal fgiEma = fgiEmaList.ElementAtOrDefault(i); - decimal prevFgiEma = i >= 1 ? fgiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal fgiEma = fgiEmaList[i]; + decimal prevFgiEma = i >= 1 ? fgiEmaList[i - 1] : 0; var signal = GetCompareSignal(fgiEma, prevFgiEma); signalsList.Add(signal); @@ -5162,15 +5162,15 @@ public static StockData CalculateFunctionToCandles(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal rsiC = rsiCList.ElementAtOrDefault(i); - decimal rsiO = rsiOList.ElementAtOrDefault(i); - decimal rsiH = rsiHList.ElementAtOrDefault(i); - decimal rsiL = rsiLList.ElementAtOrDefault(i); - decimal prevTp1 = i >= 1 ? tpList.ElementAtOrDefault(i - 1) : 0; - decimal prevTp2 = i >= 2 ? tpList.ElementAtOrDefault(i - 2) : 0; + decimal rsiC = rsiCList[i]; + decimal rsiO = rsiOList[i]; + decimal rsiH = rsiHList[i]; + decimal rsiL = rsiLList[i]; + decimal prevTp1 = i >= 1 ? tpList[i - 1] : 0; + decimal prevTp2 = i >= 2 ? tpList[i - 2] : 0; decimal tp = (rsiC + rsiO + rsiH + rsiL) / 4; - tpList.Add(tp); + tpList.AddRounded(tp); var signal = GetCompareSignal(tp - prevTp1, prevTp1 - prevTp2); signalsList.Add(signal); @@ -5210,30 +5210,30 @@ public static StockData CalculateKarobeinOscillator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal ema = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal a = ema < prevEma && prevEma != 0 ? ema / prevEma : 0; - aList.Add(a); + aList.AddRounded(a); decimal b = ema > prevEma && prevEma != 0 ? ema / prevEma : 0; - bList.Add(b); + 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++) { - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal a = aEmaList.ElementAtOrDefault(i); - decimal b = bEmaList.ElementAtOrDefault(i); - decimal prevD1 = i >= 1 ? dList.ElementAtOrDefault(i - 1) : 0; - decimal prevD2 = i >= 2 ? dList.ElementAtOrDefault(i - 2) : 0; + decimal ema = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal a = aEmaList[i]; + decimal b = bEmaList[i]; + decimal prevD1 = i >= 1 ? dList[i - 1] : 0; + decimal prevD2 = i >= 2 ? dList[i - 2] : 0; decimal c = prevEma != 0 && ema != 0 ? MinOrMax(ema / prevEma / ((ema / prevEma) + b), 1, 0) : 0; decimal d = prevEma != 0 && ema != 0 ? MinOrMax((2 * (ema / prevEma / ((ema / prevEma) + (c * a)))) - 1, 1, 0) : 0; - dList.Add(d); + dList.AddRounded(d); var signal = GetRsiSignal(d - prevD1, prevD1 - prevD2, d, prevD1, 0.8m, 0.2m); signalsList.Add(signal); @@ -5270,16 +5270,16 @@ public static StockData CalculateKasePeakOscillatorV1(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevLow = i >= length ? lowList.ElementAtOrDefault(i - length) : 0; - decimal prevHigh = i >= length ? highList.ElementAtOrDefault(i - length) : 0; + decimal currentAtr = atrList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevLow = i >= length ? lowList[i - length] : 0; + decimal prevHigh = i >= length ? highList[i - length] : 0; decimal rwh = currentAtr != 0 ? (currentHigh - prevLow) / currentAtr * sqrt : 0; decimal rwl = currentAtr != 0 ? (prevHigh - currentLow) / currentAtr * sqrt : 0; decimal diff = rwh - rwl; - diffList.Add(diff); + diffList.AddRounded(diff); } var pkList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, smoothLength, diffList); @@ -5288,16 +5288,16 @@ public static StockData CalculateKasePeakOscillatorV1(this StockData stockData, var sdList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal pk = pkList.ElementAtOrDefault(i); - decimal mn = mnList.ElementAtOrDefault(i); - decimal sd = sdList.ElementAtOrDefault(i); - decimal prevPk = i >= 1 ? pkList.ElementAtOrDefault(i - 1) : 0; + decimal pk = pkList[i]; + decimal mn = mnList[i]; + decimal sd = sdList[i]; + decimal prevPk = i >= 1 ? pkList[i - 1] : 0; decimal v1 = mn + (1.33m * sd) > 2.08m ? mn + (1.33m * sd) : 2.08m; decimal v2 = mn - (1.33m * sd) < -1.92m ? mn - (1.33m * sd) : -1.92m; decimal prevLn = lnList.LastOrDefault(); decimal ln = prevPk >= 0 && pk > 0 ? v1 : prevPk <= 0 && pk < 0 ? v2 : 0; - lnList.Add(ln); + lnList.AddRounded(ln); var signal = GetCompareSignal(ln, prevLn); signalsList.Add(signal); @@ -5346,12 +5346,12 @@ public static StockData CalculateKasePeakOscillatorV2(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal temp = prevValue != 0 ? currentValue / prevValue : 0; decimal ccLog = temp > 0 ? Log(temp) : 0; - ccLogList.Add(ccLog); + ccLogList.AddRounded(ccLog); } stockData.CustomValuesList = ccLogList; @@ -5359,16 +5359,16 @@ public static StockData CalculateKasePeakOscillatorV2(this StockData stockData, var ccDevAvgList = GetMovingAverageList(stockData, maType, length2, ccDevList); for (int i = 0; i < stockData.Count; i++) { - decimal avg = ccDevAvgList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); + decimal avg = ccDevAvgList[i]; + decimal currentLow = lowList[i]; + decimal currentHigh = highList[i]; decimal max1 = 0, max2 = 0; for (int j = fastLength; j < slowLength; j++) { decimal sqrtK = Sqrt(j); - decimal prevLow = i >= j ? lowList.ElementAtOrDefault(i - j) : 0; - decimal prevHigh = i >= j ? highList.ElementAtOrDefault(i - j) : 0; + decimal prevLow = i >= j ? lowList[i - j] : 0; + decimal prevHigh = i >= j ? highList[i - j] : 0; decimal temp1 = prevLow != 0 ? currentHigh / prevLow : 0; decimal log1 = temp1 > 0 ? Log(temp1) : 0; max1 = Math.Max(log1 / sqrtK, max1); @@ -5378,43 +5378,43 @@ public static StockData CalculateKasePeakOscillatorV2(this StockData stockData, } decimal x1 = avg != 0 ? max1 / avg : 0; - x1List.Add(x1); + x1List.AddRounded(x1); decimal x2 = avg != 0 ? max2 / avg : 0; - x2List.Add(x2); + x2List.AddRounded(x2); decimal xp = sensitivity * (x1List.TakeLastExt(smoothLength).Average() - x2List.TakeLastExt(smoothLength).Average()); - xpList.Add(xp); + xpList.AddRounded(xp); decimal xpAbs = Math.Abs(xp); - xpAbsList.Add(xpAbs); + xpAbsList.AddRounded(xpAbs); decimal xpAbsAvg = xpAbsList.TakeLastExt(length3).Average(); - xpAbsAvgList.Add(xpAbsAvg); + xpAbsAvgList.AddRounded(xpAbsAvg); } stockData.CustomValuesList = xpAbsList; var xpAbsStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length3).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal xpAbsAvg = xpAbsAvgList.ElementAtOrDefault(i); - decimal xpAbsStdDev = xpAbsStdDevList.ElementAtOrDefault(i); - decimal prevKpoBuffer1 = i >= 1 ? kpoBufferList.ElementAtOrDefault(i - 1) : 0; - decimal prevKpoBuffer2 = i >= 2 ? kpoBufferList.ElementAtOrDefault(i - 2) : 0; + decimal xpAbsAvg = xpAbsAvgList[i]; + decimal xpAbsStdDev = xpAbsStdDevList[i]; + decimal prevKpoBuffer1 = i >= 1 ? kpoBufferList[i - 1] : 0; + decimal prevKpoBuffer2 = i >= 2 ? kpoBufferList[i - 2] : 0; decimal tmpVal = xpAbsAvg + (devFactor * xpAbsStdDev); decimal maxVal = Math.Max(90, tmpVal); decimal prevKpoBuffer = kpoBufferList.LastOrDefault(); - decimal kpoBuffer = xpList.ElementAtOrDefault(i); - kpoBufferList.Add(kpoBuffer); + decimal kpoBuffer = xpList[i]; + kpoBufferList.AddRounded(kpoBuffer); decimal 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.Add(kppBuffer); + kppBufferList.AddRounded(kppBuffer); var signal = GetCompareSignal(kpoBuffer, prevKpoBuffer); signalsList.Add(signal); @@ -5447,23 +5447,23 @@ public static StockData CalculateKaseSerialDependencyIndex(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal temp = prevValue != 0 ? currentValue / prevValue : 0; decimal tempLog = temp > 0 ? Log(temp) : 0; - tempList.Add(tempLog); + tempList.AddRounded(tempLog); } stockData.CustomValuesList = tempList; var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal volatility = stdDevList.ElementAtOrDefault(i); - decimal prevHigh = i >= length ? highList.ElementAtOrDefault(i - length) : 0; - decimal prevLow = i >= length ? lowList.ElementAtOrDefault(i - length) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal volatility = stdDevList[i]; + decimal prevHigh = i >= length ? highList[i - length] : 0; + decimal prevLow = i >= length ? lowList[i - length] : 0; decimal ksdiUpTemp = prevLow != 0 ? currentHigh / prevLow : 0; decimal ksdiDownTemp = prevHigh != 0 ? currentLow / prevHigh : 0; decimal ksdiUpLog = ksdiUpTemp > 0 ? Log(ksdiUpTemp) : 0; @@ -5471,11 +5471,11 @@ public static StockData CalculateKaseSerialDependencyIndex(this StockData stockD decimal prevKsdiUp = ksdiUpList.LastOrDefault(); decimal ksdiUp = volatility != 0 ? ksdiUpLog / volatility : 0; - ksdiUpList.Add(ksdiUp); + ksdiUpList.AddRounded(ksdiUp); decimal prevKsdiDown = ksdiDownList.LastOrDefault(); decimal ksdiDown = volatility != 0 ? ksdiDownLog / volatility : 0; - ksdiDownList.Add(ksdiDown); + ksdiDownList.AddRounded(ksdiDown); var signal = GetCompareSignal(ksdiUp - ksdiDown, prevKsdiUp - prevKsdiDown); signalsList.Add(signal); @@ -5517,39 +5517,39 @@ public static StockData CalculateKaufmanBinaryWave(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal efRatio = efRatioList.ElementAtOrDefault(i); - decimal prevAma = i >= 1 ? amaList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal efRatio = efRatioList[i]; + decimal prevAma = i >= 1 ? amaList[i - 1] : currentValue; decimal smooth = Pow((efRatio * fastSc) + slowSc, 2); decimal ama = prevAma + (smooth * (currentValue - prevAma)); - amaList.Add(ama); + amaList.AddRounded(ama); decimal diff = ama - prevAma; - diffList.Add(diff); + diffList.AddRounded(diff); } stockData.CustomValuesList = diffList; var diffStdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ama = amaList.ElementAtOrDefault(i); - decimal diffStdDev = diffStdDevList.ElementAtOrDefault(i); - decimal prevAma = i >= 1 ? amaList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal ama = amaList[i]; + decimal diffStdDev = diffStdDevList[i]; + decimal prevAma = i >= 1 ? amaList[i - 1] : currentValue; decimal filter = filterPct / 100 * diffStdDev; decimal prevAmaLow = amaLowList.LastOrDefault(); decimal amaLow = ama < prevAma ? ama : prevAmaLow; - amaLowList.Add(amaLow); + amaLowList.AddRounded(amaLow); decimal prevAmaHigh = amaHighList.LastOrDefault(); decimal amaHigh = ama > prevAma ? ama : prevAmaHigh; - amaHighList.Add(amaHigh); + amaHighList.AddRounded(amaHigh); decimal prevBw = bwList.LastOrDefault(); decimal bw = ama - amaLow > filter ? 1 : amaHigh - ama > filter ? -1 : 0; - bwList.Add(bw); + bwList.AddRounded(bw); var signal = GetCompareSignal(bw, prevBw); signalsList.Add(signal); @@ -5585,23 +5585,23 @@ public static StockData CalculateKurtosisIndicator(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; - decimal prevDiff = i >= length2 ? diffList.ElementAtOrDefault(i - length2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length1 ? inputList[i - length1] : 0; + decimal prevDiff = i >= length2 ? diffList[i - length2] : 0; decimal diff = currentValue - prevValue; - diffList.Add(diff); + diffList.AddRounded(diff); decimal k = diff - prevDiff; - kList.Add(k); + kList.AddRounded(k); } var fkList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, slowLength, kList); var fskList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, fastLength, fkList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal fsk = fskList.ElementAtOrDefault(j); - decimal prevFsk = j >= 1 ? fskList.ElementAtOrDefault(j - 1) : 0; + decimal fsk = fskList[i]; + decimal prevFsk = i >= 1 ? fskList[i - 1] : 0; var signal = GetCompareSignal(fsk, prevFsk); signalsList.Add(signal); @@ -5643,19 +5643,19 @@ public static StockData CalculateKaufmanAdaptiveCorrelationOscillator(this Stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); decimal indexSrc = i * currentValue; - indexSrcList.Add(indexSrc); + indexSrcList.AddRounded(indexSrc); decimal srcSrc = currentValue * currentValue; - src2List.Add(srcSrc); + src2List.AddRounded(srcSrc); decimal indexIndex = index * index; - index2List.Add(indexIndex); + index2List.AddRounded(indexIndex); } var indexMaList = GetMovingAverageList(stockData, maType, length, indexList); @@ -5664,27 +5664,27 @@ public static StockData CalculateKaufmanAdaptiveCorrelationOscillator(this Stock var src2MaList = GetMovingAverageList(stockData, maType, length, src2List); for (int i = 0; i < stockData.Count; i++) { - decimal srcMa = kamaList.ElementAtOrDefault(i); - decimal indexMa = indexMaList.ElementAtOrDefault(i); - decimal indexSrcMa = indexSrcMaList.ElementAtOrDefault(i); - decimal index2Ma = index2MaList.ElementAtOrDefault(i); - decimal src2Ma = src2MaList.ElementAtOrDefault(i); - decimal prevR1 = i >= 1 ? rList.ElementAtOrDefault(i - 1) : 0; - decimal prevR2 = i >= 2 ? rList.ElementAtOrDefault(i - 2) : 0; + decimal srcMa = kamaList[i]; + decimal indexMa = indexMaList[i]; + decimal indexSrcMa = indexSrcMaList[i]; + decimal index2Ma = index2MaList[i]; + decimal src2Ma = src2MaList[i]; + decimal prevR1 = i >= 1 ? rList[i - 1] : 0; + decimal prevR2 = i >= 2 ? rList[i - 2] : 0; decimal indexSqrt = index2Ma - Pow(indexMa, 2); decimal indexSt = indexSqrt >= 0 ? Sqrt(indexSqrt) : 0; - indexStList.Add(indexSt); + indexStList.AddRounded(indexSt); decimal srcSqrt = src2Ma - Pow(srcMa, 2); decimal srcSt = srcSqrt >= 0 ? Sqrt(srcSqrt) : 0; - srcStList.Add(srcSt); + srcStList.AddRounded(srcSt); decimal a = indexSrcMa - (indexMa * srcMa); decimal b = indexSt * srcSt; decimal r = b != 0 ? a / b : 0; - rList.Add(r); + rList.AddRounded(r); var signal = GetRsiSignal(r - prevR1, prevR1 - prevR2, r, prevR1, 0.5m, -0.5m); signalsList.Add(signal); @@ -5740,22 +5740,22 @@ public static StockData CalculateKnowSureThing(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal roc1 = roc1SmaList.ElementAtOrDefault(i); - decimal roc2 = roc2SmaList.ElementAtOrDefault(i); - decimal roc3 = roc3SmaList.ElementAtOrDefault(i); - decimal roc4 = roc4SmaList.ElementAtOrDefault(i); + decimal roc1 = roc1SmaList[i]; + decimal roc2 = roc2SmaList[i]; + decimal roc3 = roc3SmaList[i]; + decimal roc4 = roc4SmaList[i]; decimal kst = (roc1 * weight1) + (roc2 * weight2) + (roc3 * weight3) + (roc4 * weight4); - kstList.Add(kst); + kstList.AddRounded(kst); } var kstSignalList = GetMovingAverageList(stockData, maType, signalLength, kstList); for (int i = 0; i < stockData.Count; i++) { - decimal kst = kstList.ElementAtOrDefault(i); - decimal kstSignal = kstSignalList.ElementAtOrDefault(i); - decimal prevKst = i >= 1 ? kstList.ElementAtOrDefault(i - 1) : 0; - decimal prevKstSignal = i >= 1 ? kstSignalList.ElementAtOrDefault(i - 1) : 0; + decimal kst = kstList[i]; + decimal kstSignal = kstSignalList[i]; + decimal prevKst = i >= 1 ? kstList[i - 1] : 0; + decimal prevKstSignal = i >= 1 ? kstSignalList[i - 1] : 0; var signal = GetCompareSignal(kst - kstSignal, prevKst - prevKstSignal); signalsList.Add(signal); @@ -5794,21 +5794,21 @@ public static StockData CalculateKaseIndicator(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal avgTrueRange = atrList.ElementAtOrDefault(i); - decimal avgVolSma = volumeSmaList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal avgTrueRange = atrList[i]; + decimal avgVolSma = volumeSmaList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal ratio = avgVolSma * sqrtPeriod; decimal prevKUp = kUpList.LastOrDefault(); decimal kUp = avgTrueRange > 0 && ratio != 0 && currentLow != 0 ? prevHigh / currentLow / ratio : prevKUp; - kUpList.Add(kUp); + kUpList.AddRounded(kUp); decimal prevKDown = kDownList.LastOrDefault(); decimal kDown = avgTrueRange > 0 && ratio != 0 && prevLow != 0 ? currentHigh / prevLow / ratio : prevKDown; - kDownList.Add(kDown); + kDownList.AddRounded(kDown); var signal = GetCompareSignal(kUp - kDown, prevKUp - prevKDown); signalsList.Add(signal); @@ -5846,19 +5846,19 @@ public static StockData CalculateKendallRankCorrelationCoefficient(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal prevKendall1 = i >= 1 ? kendallCorrelationList.ElementAtOrDefault(i - 1) : 0; - decimal prevKendall2 = i >= 2 ? kendallCorrelationList.ElementAtOrDefault(i - 2) : 0; + decimal prevKendall1 = i >= 1 ? kendallCorrelationList[i - 1] : 0; + decimal prevKendall2 = i >= 2 ? kendallCorrelationList[i - 2] : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal linReg = linRegList.ElementAtOrDefault(i); - tempLinRegList.Add(linReg); + decimal linReg = linRegList[i]; + tempLinRegList.AddRounded(linReg); var pearsonCorrelation = Correlation.Pearson(tempLinRegList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); pearsonCorrelation = IsValueNullOrInfinity(pearsonCorrelation) ? 0 : pearsonCorrelation; - pearsonCorrelationList.Add((decimal)pearsonCorrelation); + pearsonCorrelationList.AddRounded((decimal)pearsonCorrelation); decimal totalPairs = length * (decimal)(length - 1) / 2; decimal numerator = 0; @@ -5866,16 +5866,16 @@ public static StockData CalculateKendallRankCorrelationCoefficient(this StockDat { for (int k = 0; k <= j; k++) { - decimal prevValueJ = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; - decimal prevValueK = i >= k ? inputList.ElementAtOrDefault(i - k) : 0; - decimal prevLinRegJ = i >= j ? linRegList.ElementAtOrDefault(i - j) : 0; - decimal prevLinRegK = i >= k ? linRegList.ElementAtOrDefault(i - k) : 0; + decimal prevValueJ = i >= j ? inputList[i - j] : 0; + decimal prevValueK = i >= k ? inputList[i - k] : 0; + decimal prevLinRegJ = i >= j ? linRegList[i - j] : 0; + decimal prevLinRegK = i >= k ? linRegList[i - k] : 0; numerator += Math.Sign(prevLinRegJ - prevLinRegK) * Math.Sign(prevValueJ - prevValueK); } } decimal kendallCorrelation = numerator / totalPairs; - kendallCorrelationList.Add(kendallCorrelation); + kendallCorrelationList.AddRounded(kendallCorrelation); var signal = GetCompareSignal(kendallCorrelation - prevKendall1, prevKendall1 - prevKendall2); signalsList.Add(signal); @@ -5914,26 +5914,26 @@ public static StockData CalculateKwanIndicator(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal priorClose = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentClose = inputList[i]; + decimal priorClose = i >= length ? inputList[i - length] : 0; decimal mom = priorClose != 0 ? currentClose / priorClose * 100 : 0; - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; decimal sto = hh - ll != 0 ? (currentClose - ll) / (hh - ll) * 100 : 0; - decimal prevVr = i >= smoothLength ? vrList.ElementAtOrDefault(i - smoothLength) : 0; - decimal prevKnrp1 = i >= 1 ? knrpList.ElementAtOrDefault(i - 1) : 0; - decimal prevKnrp2 = i >= 2 ? knrpList.ElementAtOrDefault(i - 2) : 0; + decimal prevVr = i >= smoothLength ? vrList[i - smoothLength] : 0; + decimal prevKnrp1 = i >= 1 ? knrpList[i - 1] : 0; + decimal prevKnrp2 = i >= 2 ? knrpList[i - 2] : 0; decimal vr = mom != 0 ? sto * rsi / mom : 0; - vrList.Add(vr); + vrList.AddRounded(vr); decimal prev = prevVr; - prevList.Add(prev); + prevList.AddRounded(prev); decimal vrSum = prevList.Sum(); decimal knrp = vrSum / smoothLength; - knrpList.Add(knrp); + knrpList.AddRounded(knrp); var signal = GetCompareSignal(knrp - prevKnrp1, prevKnrp1 - prevKnrp2); signalsList.Add(signal); @@ -5971,21 +5971,21 @@ public static StockData CalculateKaufmanStressIndicator(this StockData stockData { for (int i = 0; i < stockData.Count; i++) { - decimal highestHigh1 = highestList1.ElementAtOrDefault(i); - decimal lowestLow1 = lowestList1.ElementAtOrDefault(i); - decimal highestHigh2 = highestList2.ElementAtOrDefault(i); - decimal lowestLow2 = lowestList2.ElementAtOrDefault(i); - decimal currentValue1 = inputList1.ElementAtOrDefault(i); - decimal currentValue2 = inputList2.ElementAtOrDefault(i); - decimal prevSv1 = i >= 1 ? svList.ElementAtOrDefault(i - 1) : 0; - decimal prevSv2 = i >= 2 ? svList.ElementAtOrDefault(i - 2) : 0; + decimal highestHigh1 = highestList1[i]; + decimal lowestLow1 = lowestList1[i]; + decimal highestHigh2 = highestList2[i]; + decimal lowestLow2 = lowestList2[i]; + decimal currentValue1 = inputList1[i]; + decimal currentValue2 = inputList2[i]; + decimal prevSv1 = i >= 1 ? svList[i - 1] : 0; + decimal prevSv2 = i >= 2 ? svList[i - 2] : 0; decimal r1 = highestHigh1 - lowestLow1; decimal r2 = highestHigh2 - lowestLow2; decimal s1 = r1 != 0 ? (currentValue1 - lowestLow1) / r1 : 50; decimal s2 = r2 != 0 ? (currentValue2 - lowestLow2) / r2 : 50; decimal d = s1 - s2; - dList.Add(d); + dList.AddRounded(d); var list = dList.TakeLastExt(length).ToList(); decimal highestD = list.Max(); @@ -5993,7 +5993,7 @@ public static StockData CalculateKaufmanStressIndicator(this StockData stockData decimal r11 = highestD - lowestD; decimal sv = r11 != 0 ? MinOrMax(100 * (d - lowestD) / r11, 100, 0) : 50; - svList.Add(sv); + svList.AddRounded(sv); var signal = GetRsiSignal(sv - prevSv1, prevSv1 - prevSv2, sv, prevSv1, 90, 10); signalsList.Add(signal); @@ -6035,17 +6035,17 @@ public static StockData CalculateVostroIndicator(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal wma = wmaList.ElementAtOrDefault(i); - decimal prevBuff109_1 = i >= 1 ? iBuff109List.ElementAtOrDefault(i - 1) : 0; - decimal prevBuff109_2 = i >= 2 ? iBuff109List.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal wma = wmaList[i]; + decimal prevBuff109_1 = i >= 1 ? iBuff109List[i - 1] : 0; + decimal prevBuff109_2 = i >= 2 ? iBuff109List[i - 2] : 0; - decimal medianPrice = inputList.ElementAtOrDefault(i); - tempList.Add(medianPrice); + decimal medianPrice = inputList[i]; + tempList.AddRounded(medianPrice); decimal range = currentHigh - currentLow; - rangeList.Add(range); + rangeList.AddRounded(range); decimal gd120 = tempList.TakeLastExt(length1).Sum(); decimal gd128 = gd120 * 0.2m; @@ -6054,15 +6054,15 @@ public static StockData CalculateVostroIndicator(this StockData stockData, Movin decimal prevIBuff116 = iBuff116List.LastOrDefault(); decimal iBuff116 = gd136 != 0 ? (currentLow - gd128) / gd136 : 0; - iBuff116List.Add(iBuff116); + iBuff116List.AddRounded(iBuff116); decimal prevIBuff112 = iBuff112List.LastOrDefault(); decimal iBuff112 = gd136 != 0 ? (currentHigh - gd128) / gd136 : 0; - iBuff112List.Add(iBuff112); + iBuff112List.AddRounded(iBuff112); decimal iBuff108 = iBuff112 > level && currentHigh > wma ? 90 : iBuff116 < -level && currentLow < wma ? -90 : 0; decimal iBuff109 = (iBuff112 > level && prevIBuff112 > level) || (iBuff116 < -level && prevIBuff116 < -level) ? 0 : iBuff108; - iBuff109List.Add(iBuff109); + iBuff109List.AddRounded(iBuff109); var signal = GetRsiSignal(iBuff109 - prevBuff109_1, prevBuff109_1 - prevBuff109_2, iBuff109, prevBuff109_1, 80, -80); signalsList.Add(signal); @@ -6104,26 +6104,26 @@ public static StockData CalculateValueChartIndicator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal prevClose1 = i >= 1 ? closeList.ElementAtOrDefault(i - 1) : 0; - decimal prevHighest1 = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowest1 = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose2 = i >= 2 ? closeList.ElementAtOrDefault(i - 2) : 0; - decimal prevHighest2 = i >= 2 ? highestList.ElementAtOrDefault(i - 2) : 0; - decimal prevLowest2 = i >= 2 ? lowestList.ElementAtOrDefault(i - 2) : 0; - decimal prevClose3 = i >= 3 ? closeList.ElementAtOrDefault(i - 3) : 0; - decimal prevHighest3 = i >= 3 ? highestList.ElementAtOrDefault(i - 3) : 0; - decimal prevLowest3 = i >= 3 ? lowestList.ElementAtOrDefault(i - 3) : 0; - decimal prevClose4 = i >= 4 ? closeList.ElementAtOrDefault(i - 4) : 0; - decimal prevHighest4 = i >= 4 ? highestList.ElementAtOrDefault(i - 4) : 0; - decimal prevLowest4 = i >= 4 ? lowestList.ElementAtOrDefault(i - 4) : 0; - decimal prevClose5 = i >= 5 ? closeList.ElementAtOrDefault(i - 5) : 0; - decimal mba = smaList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); + decimal currentClose = closeList[i]; + decimal prevClose1 = i >= 1 ? closeList[i - 1] : 0; + decimal prevHighest1 = i >= 1 ? highestList[i - 1] : 0; + decimal prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; + decimal prevClose2 = i >= 2 ? closeList[i - 2] : 0; + decimal prevHighest2 = i >= 2 ? highestList[i - 2] : 0; + decimal prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; + decimal prevClose3 = i >= 3 ? closeList[i - 3] : 0; + decimal prevHighest3 = i >= 3 ? highestList[i - 3] : 0; + decimal prevLowest3 = i >= 3 ? lowestList[i - 3] : 0; + decimal prevClose4 = i >= 4 ? closeList[i - 4] : 0; + decimal prevHighest4 = i >= 4 ? highestList[i - 4] : 0; + decimal prevLowest4 = i >= 4 ? lowestList[i - 4] : 0; + decimal prevClose5 = i >= 5 ? closeList[i - 5] : 0; + decimal mba = smaList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; decimal vara = highest - lowest; decimal varr1 = vara == 0 && varp == 1 ? Math.Abs(currentClose - prevClose1) : vara; decimal varb = prevHighest1 - prevLowest1; @@ -6139,25 +6139,25 @@ public static StockData CalculateValueChartIndicator(this StockData stockData, M decimal lRange = (varr1 + varr2 + varr3 + varr4 + varr5) / 5 * 0.2m; decimal vClose = lRange != 0 ? (currentClose - mba) / lRange : 0; - vCloseList.Add(vClose); + vCloseList.AddRounded(vClose); decimal vOpen = lRange != 0 ? (currentOpen - mba) / lRange : 0; - vOpenList.Add(vOpen); + vOpenList.AddRounded(vOpen); decimal vHigh = lRange != 0 ? (currentHigh - mba) / lRange : 0; - vHighList.Add(vHigh); + vHighList.AddRounded(vHigh); decimal vLow = lRange != 0 ? (currentLow - mba) / lRange : 0; - vLowList.Add(vLow); + vLowList.AddRounded(vLow); } var vValueEmaList = GetMovingAverageList(stockData, maType, length, vCloseList); for (int i = 0; i < stockData.Count; i++) { - decimal vValue = vCloseList.ElementAtOrDefault(i); - decimal vValueEma = vValueEmaList.ElementAtOrDefault(i); - decimal prevVvalue = i >= 1 ? vCloseList.ElementAtOrDefault(i - 1) : 0; - decimal prevVValueEma = i >= 1 ? vValueEmaList.ElementAtOrDefault(i - 1) : 0; + decimal vValue = vCloseList[i]; + decimal vValueEma = vValueEmaList[i]; + decimal prevVvalue = i >= 1 ? vCloseList[i - 1] : 0; + decimal prevVValueEma = i >= 1 ? vValueEmaList[i - 1] : 0; var signal = GetRsiSignal(vValue - vValueEma, prevVvalue - prevVValueEma, vValue, prevVvalue, 4, -4); signalsList.Add(signal); @@ -6214,30 +6214,30 @@ public static StockData CalculateVervoortSmoothedOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal r1 = r1List.ElementAtOrDefault(i); - decimal r2 = r2List.ElementAtOrDefault(i); - decimal r3 = r3List.ElementAtOrDefault(i); - decimal r4 = r4List.ElementAtOrDefault(i); - decimal r5 = r5List.ElementAtOrDefault(i); - decimal r6 = r6List.ElementAtOrDefault(i); - decimal r7 = r7List.ElementAtOrDefault(i); - decimal r8 = r8List.ElementAtOrDefault(i); - decimal r9 = r9List.ElementAtOrDefault(i); - decimal r10 = r10List.ElementAtOrDefault(i); + decimal r1 = r1List[i]; + decimal r2 = r2List[i]; + decimal r3 = r3List[i]; + decimal r4 = r4List[i]; + decimal r5 = r5List[i]; + decimal r6 = r6List[i]; + decimal r7 = r7List[i]; + decimal r8 = r8List[i]; + decimal r9 = r9List[i]; + decimal r10 = r10List[i]; decimal rainbow = ((5 * r1) + (4 * r2) + (3 * r3) + (2 * r4) + r5 + r6 + r7 + r8 + r9 + r10) / 20; - rainbowList.Add(rainbow); + 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++) { - decimal ema1 = ema1List.ElementAtOrDefault(i); - decimal ema2 = ema2List.ElementAtOrDefault(i); + decimal ema1 = ema1List[i]; + decimal ema2 = ema2List[i]; decimal zlrb = (2 * ema1) - ema2; - zlrbList.Add(zlrb); + zlrbList.AddRounded(zlrb); } var tzList = GetMovingAverageList(stockData, MovingAvgType.TripleExponentialMovingAverage, smoothLength, zlrbList); @@ -6246,31 +6246,31 @@ public static StockData CalculateVervoortSmoothedOscillator(this StockData stock var wmatzList = GetMovingAverageList(stockData, MovingAvgType.WeightedMovingAverage, length1, tzList); for (int i = 0; i < stockData.Count; i++) { - decimal currentTypicalPrice = inputList.ElementAtOrDefault(i); - decimal rainbow = rainbowList.ElementAtOrDefault(i); - decimal tz = tzList.ElementAtOrDefault(i); - decimal hwidth = hwidthList.ElementAtOrDefault(i); - decimal wmatz = wmatzList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentTypicalPrice = inputList[i]; + decimal rainbow = rainbowList[i]; + decimal tz = tzList[i]; + decimal hwidth = hwidthList[i]; + decimal wmatz = wmatzList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal prevZlrbpercb = zlrbpercbList.LastOrDefault(); decimal zlrbpercb = hwidth != 0 ? (tz + (stdDevMult * hwidth) - wmatz) / (2 * stdDevMult * hwidth * 100) : 0; - zlrbpercbList.Add(zlrbpercb); + zlrbpercbList.AddRounded(zlrbpercb); decimal rbc = (rainbow + currentTypicalPrice) / 2; - rbcList.Add(rbc); + rbcList.AddRounded(rbc); decimal lowestRbc = rbcList.TakeLastExt(length2).Min(); decimal nom = rbc - lowest; decimal den = highest - lowestRbc; decimal fastK = den != 0 ? MinOrMax(100 * nom / den, 100, 0) : 0; - fastKList.Add(fastK); + fastKList.AddRounded(fastK); decimal prevSk = skList.LastOrDefault(); decimal sk = fastKList.TakeLastExt(smoothLength).Average(); - skList.Add(sk); + skList.AddRounded(sk); var signal = GetConditionSignal(sk > prevSk && zlrbpercb > prevZlrbpercb, sk < prevSk && zlrbpercb < prevZlrbpercb); signalsList.Add(signal); @@ -6316,20 +6316,20 @@ public static StockData CalculateVervoortHeikenAshiLongTermCandlestickOscillator for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevHao = haoList.LastOrDefault(); decimal hao = (prevValue + prevHao) / 2; - haoList.Add(hao); + haoList.AddRounded(hao); decimal hac = (currentValue + hao + Math.Max(currentHigh, hao) + Math.Min(currentLow, hao)) / 4; - hacList.Add(hac); + hacList.AddRounded(hac); decimal medianPrice = (currentHigh + currentLow) / 2; - medianPriceList.Add(medianPrice); + medianPriceList.AddRounded(medianPrice); } var tacList = GetMovingAverageList(stockData, maType, length, hacList); @@ -6338,21 +6338,21 @@ public static StockData CalculateVervoortHeikenAshiLongTermCandlestickOscillator var thl2TemaList = GetMovingAverageList(stockData, maType, length, thl2List); for (int i = 0; i < stockData.Count; i++) { - decimal tac = tacList.ElementAtOrDefault(i); - decimal tacTema = tacTemaList.ElementAtOrDefault(i); - decimal thl2 = thl2List.ElementAtOrDefault(i); - decimal thl2Tema = thl2TemaList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal hac = hacList.ElementAtOrDefault(i); - decimal hao = haoList.ElementAtOrDefault(i); - decimal prevHac = i >= 1 ? hacList.ElementAtOrDefault(i - 1) : 0; - decimal prevHao = i >= 1 ? haoList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? closeList.ElementAtOrDefault(i - 1) : 0; + decimal tac = tacList[i]; + decimal tacTema = tacTemaList[i]; + decimal thl2 = thl2List[i]; + decimal thl2Tema = thl2TemaList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = closeList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal hac = hacList[i]; + decimal hao = haoList[i]; + decimal prevHac = i >= 1 ? hacList[i - 1] : 0; + decimal prevHao = i >= 1 ? haoList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 1 ? closeList[i - 1] : 0; decimal hacSmooth = (2 * tac) - tacTema; decimal hl2Smooth = (2 * thl2) - thl2Tema; @@ -6387,7 +6387,7 @@ public static StockData CalculateVervoortHeikenAshiLongTermCandlestickOscillator bool dnw = utr == false && prevUtr && dtr; decimal prevHaco = hacoList.LastOrDefault(); decimal haco = upw ? 1 : dnw ? -1 : prevHaco; - hacoList.Add(haco); + hacoList.AddRounded(haco); var signal = GetCompareSignal(haco, prevHaco); signalsList.Add(signal); @@ -6424,13 +6424,13 @@ public static StockData CalculateVixTradingSystem(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal vixts = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal vixts = smaList[i]; decimal prevCount = countList.LastOrDefault(); decimal count = currentValue > vixts && prevCount >= 0 ? prevCount + 1 : currentValue <= vixts && prevCount <= 0 ? prevCount - 1 : prevCount; - countList.Add(count); + countList.AddRounded(count); var signal = GetBullishBearishSignal(count - maxCount - 1, prevCount - maxCount - 1, count - minCount + 1, prevCount - minCount + 1, true); @@ -6466,27 +6466,27 @@ public static StockData CalculateVaradiOscillator(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal median = (currentHigh + currentLow) / 2; decimal ratio = median != 0 ? currentValue / median : 0; - ratioList.Add(ratio); + ratioList.AddRounded(ratio); } var aList = GetMovingAverageList(stockData, maType, length, ratioList); for (int i = 0; i < stockData.Count; i++) { - decimal a = aList.ElementAtOrDefault(i); - decimal prevDvo1 = i >= 1 ? dvoList.ElementAtOrDefault(i - 1) : 0; - decimal prevDvo2 = i >= 2 ? dvoList.ElementAtOrDefault(i - 2) : 0; + decimal a = aList[i]; + decimal prevDvo1 = i >= 1 ? dvoList[i - 1] : 0; + decimal prevDvo2 = i >= 2 ? dvoList[i - 2] : 0; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : 0; - tempList.Add(prevA); + decimal prevA = i >= 1 ? aList[i - 1] : 0; + tempList.AddRounded(prevA); decimal dvo = MinOrMax((decimal)tempList.TakeLastExt(length).Where(i => i <= a).Count() / length * 100, 100, 0); - dvoList.Add(dvo); + dvoList.AddRounded(dvo); var signal = GetRsiSignal(dvo - prevDvo1, prevDvo1 - prevDvo2, dvo, prevDvo1, 80, 20); signalsList.Add(signal); @@ -6518,25 +6518,25 @@ public static StockData CalculateVanillaABCDPattern(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevValue3 = i >= 3 ? inputList[i - 3] : 0; decimal up = prevValue3 > prevValue2 && prevValue1 > prevValue2 && currentValue < prevValue2 ? 1 : 0; decimal dn = prevValue3 < prevValue2 && prevValue1 < prevValue2 && currentValue > prevValue2 ? 1 : 0; decimal prevOs = osList.LastOrDefault(); decimal os = up == 1 ? 1 : dn == 1 ? 0 : prevOs; - osList.Add(os); + osList.AddRounded(os); decimal prevF = fList.LastOrDefault(); decimal f = os == 1 && currentValue > currentOpen ? 1 : os == 0 && currentValue < currentOpen ? 0 : prevF; - fList.Add(f); + fList.AddRounded(f); decimal prevDos = dosList.LastOrDefault(); decimal dos = os - prevOs; - dosList.Add(dos); + dosList.AddRounded(dos); var signal = GetCompareSignal(dos, prevDos); signalsList.Add(signal); @@ -6579,20 +6579,20 @@ public static StockData CalculateVervoortHeikenAshiCandlestickOscillator(this St for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevHao = haoList.LastOrDefault(); decimal hao = (prevValue + prevHao) / 2; - haoList.Add(hao); + haoList.AddRounded(hao); decimal hac = (currentValue + hao + Math.Max(currentHigh, hao) + Math.Min(currentLow, hao)) / 4; - hacList.Add(hac); + hacList.AddRounded(hac); decimal medianPrice = (currentHigh + currentLow) / 2; - medianPriceList.Add(medianPrice); + medianPriceList.AddRounded(medianPrice); } var tma1List = GetMovingAverageList(stockData, maType, length, hacList); @@ -6601,21 +6601,21 @@ public static StockData CalculateVervoortHeikenAshiCandlestickOscillator(this St var tma22List = GetMovingAverageList(stockData, maType, length, tma12List); for (int i = 0; i < stockData.Count; i++) { - decimal tma1 = tma1List.ElementAtOrDefault(i); - decimal tma2 = tma2List.ElementAtOrDefault(i); - decimal tma12 = tma12List.ElementAtOrDefault(i); - decimal tma22 = tma22List.ElementAtOrDefault(i); - decimal hao = haoList.ElementAtOrDefault(i); - decimal hac = hacList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal prevHao = i >= 1 ? haoList.ElementAtOrDefault(i - 1) : 0; - decimal prevHac = i >= 1 ? hacList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? closeList.ElementAtOrDefault(i - 1) : 0; + decimal tma1 = tma1List[i]; + decimal tma2 = tma2List[i]; + decimal tma12 = tma12List[i]; + decimal tma22 = tma22List[i]; + decimal hao = haoList[i]; + decimal hac = hacList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = closeList[i]; + decimal prevHao = i >= 1 ? haoList[i - 1] : 0; + decimal prevHac = i >= 1 ? hacList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 1 ? closeList[i - 1] : 0; decimal diff = tma1 - tma2; decimal zlHa = tma1 + diff; decimal diff2 = tma12 - tma22; @@ -6658,7 +6658,7 @@ public static StockData CalculateVervoortHeikenAshiCandlestickOscillator(this St decimal prevHaco = hacoList.LastOrDefault(); decimal haco = upw ? 1 : dnw ? -1 : prevHaco; - hacoList.Add(haco); + hacoList.AddRounded(haco); var signal = GetCompareSignal(haco, prevHaco); signalsList.Add(signal); @@ -6698,26 +6698,26 @@ public static StockData CalculateChartmillValueIndicator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal v = atrList.ElementAtOrDefault(i); - decimal f = fList.ElementAtOrDefault(i); - decimal prevCmvc1 = i >= 1 ? cmvCList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmvc2 = i >= 2 ? cmvCList.ElementAtOrDefault(i - 2) : 0; - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal v = atrList[i]; + decimal f = fList[i]; + decimal prevCmvc1 = i >= 1 ? cmvCList[i - 1] : 0; + decimal prevCmvc2 = i >= 2 ? cmvCList[i - 2] : 0; + decimal currentClose = closeList[i]; + decimal currentOpen = openList[i]; decimal cmvC = v != 0 ? MinOrMax((currentClose - f) / (v * Pow(length, 0.5m)), 1, -1) : 0; - cmvCList.Add(cmvC); + cmvCList.AddRounded(cmvC); decimal cmvO = v != 0 ? MinOrMax((currentOpen - f) / (v * Pow(length, 0.5m)), 1, -1) : 0; - cmvOList.Add(cmvO); + cmvOList.AddRounded(cmvO); decimal cmvH = v != 0 ? MinOrMax((currentHigh - f) / (v * Pow(length, 0.5m)), 1, -1) : 0; - cmvHList.Add(cmvH); + cmvHList.AddRounded(cmvH); decimal cmvL = v != 0 ? MinOrMax((currentLow - f) / (v * Pow(length, 0.5m)), 1, -1) : 0; - cmvLList.Add(cmvL); + cmvLList.AddRounded(cmvL); var signal = GetRsiSignal(cmvC - prevCmvc1, prevCmvc1 - prevCmvc2, cmvC, prevCmvc1, 0.5m, -0.5m); signalsList.Add(signal); @@ -6754,23 +6754,23 @@ public static StockData CalculateConditionalAccumulator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal prevValue = valueList.LastOrDefault(); decimal value = currentLow >= prevHigh ? prevValue + increment : currentHigh <= prevLow ? prevValue - increment : prevValue; - valueList.Add(value); + valueList.AddRounded(value); } var valueEmaList = GetMovingAverageList(stockData, maType, length, valueList); for (int i = 0; i < stockData.Count; i++) { - decimal value = valueList.ElementAtOrDefault(i); - decimal valueEma = valueEmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? valueList.ElementAtOrDefault(i - 1) : 0; - decimal prevValueEma = i >= 1 ? valueEmaList.ElementAtOrDefault(i - 1) : 0; + decimal value = valueList[i]; + decimal valueEma = valueEmaList[i]; + decimal prevValue = i >= 1 ? valueList[i - 1] : 0; + decimal prevValueEma = i >= 1 ? valueEmaList[i - 1] : 0; var signal = GetCompareSignal(value - valueEma, prevValue - prevValueEma); signalsList.Add(signal); @@ -6802,16 +6802,16 @@ public static StockData CalculateContractHighLow(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal prevConHi = conHiList.LastOrDefault(); decimal conHi = i >= 1 ? Math.Max(prevConHi, currentHigh) : currentHigh; - conHiList.Add(conHi); + conHiList.AddRounded(conHi); decimal prevConLow = conLowList.LastOrDefault(); decimal conLow = i >= 1 ? Math.Min(prevConLow, currentLow) : currentLow; - conLowList.Add(conLow); + conLowList.AddRounded(conLow); var signal = GetConditionSignal(conHi > prevConHi, conLow < prevConLow); signalsList.Add(signal); @@ -6850,19 +6850,19 @@ public static StockData CalculateChopZone(this StockData stockData, MovingAvgTyp for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal ema = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal range = highest - lowest != 0 ? 25 / (highest - lowest) * lowest : 0; - decimal avg = inputList.ElementAtOrDefault(i); + decimal avg = inputList[i]; decimal y = avg != 0 && range != 0 ? (prevEma - ema) / avg * range : 0; decimal c = Sqrt(1 + (y * y)); decimal emaAngle1 = c != 0 ? Math.Round(Acos(1 / c).ToDegrees()) : 0; decimal prevEmaAngle = emaAngleList.LastOrDefault(); decimal emaAngle = y > 0 ? -emaAngle1 : emaAngle1; - emaAngleList.Add(emaAngle); + emaAngleList.AddRounded(emaAngle); var signal = GetCompareSignal(emaAngle, prevEmaAngle); signalsList.Add(signal); @@ -6894,15 +6894,15 @@ public static StockData CalculateCenterOfLinearity(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorValue = i >= length ? inputList[i - length] : 0; decimal a = (i + 1) * (priorValue - prevValue); - aList.Add(a); + aList.AddRounded(a); decimal prevCol = colList.LastOrDefault(); decimal col = aList.TakeLastExt(length).Sum(); - colList.Add(col); + colList.AddRounded(col); var signal = GetCompareSignal(col, prevCol); signalsList.Add(signal); @@ -6937,22 +6937,22 @@ public static StockData CalculateChaikinVolatility(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal highLow = currentHigh - currentLow; - highLowList.Add(highLow); + highLowList.AddRounded(highLow); } var highLowEmaList = GetMovingAverageList(stockData, maType, length1, highLowList); for (int i = 0; i < stockData.Count; i++) { - decimal highLowEma = highLowEmaList.ElementAtOrDefault(i); - decimal prevHighLowEma = i >= length2 ? highLowEmaList.ElementAtOrDefault(i - length2) : 0; + decimal highLowEma = highLowEmaList[i]; + decimal prevHighLowEma = i >= length2 ? highLowEmaList[i - length2] : 0; decimal prevChaikinVolatility = chaikinVolatilityList.LastOrDefault(); decimal chaikinVolatility = prevHighLowEma != 0 ? (highLowEma - prevHighLowEma) / prevHighLowEma * 100 : 0; - chaikinVolatilityList.Add(chaikinVolatility); + chaikinVolatilityList.AddRounded(chaikinVolatility); var signal = GetCompareSignal(chaikinVolatility, prevChaikinVolatility, true); signalsList.Add(signal); @@ -7014,32 +7014,32 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal sAvg = sAvgList.ElementAtOrDefault(i); - decimal priorSAvg = i >= soff ? sAvgList.ElementAtOrDefault(i - soff) : 0; - decimal priorHAvg = i >= hoff ? hAvgList.ElementAtOrDefault(i - hoff) : 0; - decimal iAvg = iAvgList.ElementAtOrDefault(i); - decimal priorIAvg = i >= ioff ? iAvgList.ElementAtOrDefault(i - ioff) : 0; - decimal lAvg = lAvgList.ElementAtOrDefault(i); - decimal hAvg = hAvgList.ElementAtOrDefault(i); - decimal prevSAvg = i >= 1 ? sAvgList.ElementAtOrDefault(i - 1) : 0; - decimal prevHAvg = i >= 1 ? hAvgList.ElementAtOrDefault(i - 1) : 0; - decimal prevIAvg = i >= 1 ? iAvgList.ElementAtOrDefault(i - 1) : 0; - decimal prevLAvg = i >= 1 ? lAvgList.ElementAtOrDefault(i - 1) : 0; - decimal h2 = h2AvgList.ElementAtOrDefault(i); - decimal s2 = s2AvgList.ElementAtOrDefault(i); - decimal i2 = i2AvgList.ElementAtOrDefault(i); - decimal l2 = l2AvgList.ElementAtOrDefault(i); - decimal ftpAvg = ftpAvgList.ElementAtOrDefault(i); - decimal priorValue5 = i >= hoff ? value5List.ElementAtOrDefault(i - hoff) : 0; - decimal priorValue6 = i >= soff ? value6List.ElementAtOrDefault(i - soff) : 0; - decimal priorValue7 = i >= ioff ? value7List.ElementAtOrDefault(i - ioff) : 0; - decimal priorSum = i >= soff ? sumList.ElementAtOrDefault(i - soff) : 0; - decimal priorHAvg2 = i >= soff ? hAvgList.ElementAtOrDefault(i - soff) : 0; - decimal prevErrSum = i >= 1 ? errSumList.ElementAtOrDefault(i - 1) : 0; - decimal prevMom = i >= 1 ? momList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue70 = i >= 1 ? value70List.ElementAtOrDefault(i - 1) : 0; - decimal prevConfluence1 = i >= 1 ? confluenceList.ElementAtOrDefault(i - 1) : 0; - decimal prevConfluence2 = i >= 2 ? confluenceList.ElementAtOrDefault(i - 2) : 0; + decimal sAvg = sAvgList[i]; + decimal priorSAvg = i >= soff ? sAvgList[i - soff] : 0; + decimal priorHAvg = i >= hoff ? hAvgList[i - hoff] : 0; + decimal iAvg = iAvgList[i]; + decimal priorIAvg = i >= ioff ? iAvgList[i - ioff] : 0; + decimal lAvg = lAvgList[i]; + decimal hAvg = hAvgList[i]; + decimal prevSAvg = i >= 1 ? sAvgList[i - 1] : 0; + decimal prevHAvg = i >= 1 ? hAvgList[i - 1] : 0; + decimal prevIAvg = i >= 1 ? iAvgList[i - 1] : 0; + decimal prevLAvg = i >= 1 ? lAvgList[i - 1] : 0; + decimal h2 = h2AvgList[i]; + decimal s2 = s2AvgList[i]; + decimal i2 = i2AvgList[i]; + decimal l2 = l2AvgList[i]; + decimal ftpAvg = ftpAvgList[i]; + decimal priorValue5 = i >= hoff ? value5List[i - hoff] : 0; + decimal priorValue6 = i >= soff ? value6List[i - soff] : 0; + decimal priorValue7 = i >= ioff ? value7List[i - ioff] : 0; + decimal priorSum = i >= soff ? sumList[i - soff] : 0; + decimal priorHAvg2 = i >= soff ? hAvgList[i - soff] : 0; + decimal prevErrSum = i >= 1 ? errSumList[i - 1] : 0; + decimal prevMom = i >= 1 ? momList[i - 1] : 0; + decimal prevValue70 = i >= 1 ? value70List[i - 1] : 0; + decimal prevConfluence1 = i >= 1 ? confluenceList[i - 1] : 0; + decimal prevConfluence2 = i >= 2 ? confluenceList[i - 2] : 0; decimal value2 = sAvg - priorHAvg; decimal value3 = iAvg - priorSAvg; decimal value12 = lAvg - priorIAvg; @@ -7066,13 +7066,13 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M decimal lSum = ftpAvg * (ltl - 1); decimal value5 = (hSum + drh) / length; - value5List.Add(value5); + value5List.AddRounded(value5); decimal value6 = (sSum + drs) / stl; - value6List.Add(value6); + value6List.AddRounded(value6); decimal value7 = (iSum + dri) / itl; - value7List.Add(value7); + value7List.AddRounded(value7); decimal value13 = (lSum + drl) / ltl; decimal value9 = value6 - priorValue5; @@ -7080,7 +7080,7 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M decimal value14 = value13 - priorValue7; decimal mom = value9 + value10 + value14; - momList.Add(mom); + momList.AddRounded(mom); decimal ht = Sin(value5 * 2 * Pi / 360) + Cos(value5 * 2 * Pi / 360); decimal hta = Sin(hAvg * 2 * Pi / 360) + Cos(hAvg * 2 * Pi / 360); @@ -7090,17 +7090,17 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M decimal ita = Sin(iAvg * 2 * Pi / 360) + Cos(iAvg * 2 * Pi / 360); decimal sum = ht + st + it; - sumList.Add(sum); + sumList.AddRounded(sum); decimal err = hta + sta + ita; decimal cond2 = (sum > priorSum && hAvg < priorHAvg2) || (sum < priorSum && hAvg > priorHAvg2) ? 1 : 0; decimal phase = cond2 == 1 ? -1 : 1; decimal errSum = (sum - err) * phase; - errSumList.Add(errSum); + errSumList.AddRounded(errSum); decimal value70 = value5 - value13; - value70List.Add(value70); + value70List.AddRounded(value70); decimal errSig = errSumList.TakeLastExt(soff).Average(); decimal value71 = value70List.TakeLastExt(length).Average(); @@ -7120,7 +7120,7 @@ public static StockData CalculateConfluenceIndicator(this StockData stockData, M decimal confluence = value42 > 0 && value70 > 0 ? value42 : value42 < 0 && value70 < 0 ? value42 : (value42 > 0 && value70 < 0) || (value42 < 0 && value70 > 0) ? value42 / 10 : 0; - confluenceList.Add(confluence); + confluenceList.AddRounded(confluence); decimal res1 = confluence >= 1 ? confluence : 0; decimal res2 = confluence <= -1 ? confluence : 0; @@ -7161,18 +7161,18 @@ public static StockData CalculateCoppockCurve(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal currentRoc11 = roc11List.ElementAtOrDefault(i); - decimal currentRoc14 = roc14List.ElementAtOrDefault(i); + decimal currentRoc11 = roc11List[i]; + decimal currentRoc14 = roc14List[i]; decimal rocTotal = currentRoc11 + currentRoc14; - rocTotalList.Add(rocTotal); + rocTotalList.AddRounded(rocTotal); } var coppockCurveList = GetMovingAverageList(stockData, maType, length, rocTotalList); for (int i = 0; i < stockData.Count; i++) { - decimal coppockCurve = coppockCurveList.ElementAtOrDefault(i); - decimal prevCoppockCurve = i >= 1 ? coppockCurveList.ElementAtOrDefault(i - 1) : 0; + decimal coppockCurve = coppockCurveList[i]; + decimal prevCoppockCurve = i >= 1 ? coppockCurveList[i - 1] : 0; var signal = GetCompareSignal(coppockCurve, prevCoppockCurve); signalsList.Add(signal); @@ -7214,28 +7214,28 @@ public static StockData CalculateConstanceBrownCompositeIndex(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal rsiSma = rsiSmaList.ElementAtOrDefault(i); - decimal rsiDelta = i >= length2 ? rsi1List.ElementAtOrDefault(i - length2) : 0; + decimal rsiSma = rsiSmaList[i]; + decimal rsiDelta = i >= length2 ? rsi1List[i - length2] : 0; decimal s = rsiDelta + rsiSma; - sList.Add(s); + 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++) { - decimal s = sList.ElementAtOrDefault(i); - decimal sFastSma = sFastSmaList.ElementAtOrDefault(i); - decimal sSlowSma = sSlowSmaList.ElementAtOrDefault(i); + decimal s = sList[i]; + decimal sFastSma = sFastSmaList[i]; + decimal sSlowSma = sSlowSmaList[i]; decimal prevBullSlope = bullSlopeList.LastOrDefault(); decimal bullSlope = s - Math.Max(sFastSma, sSlowSma); - bullSlopeList.Add(bullSlope); + bullSlopeList.AddRounded(bullSlope); decimal prevBearSlope = bearSlopeList.LastOrDefault(); decimal bearSlope = s - Math.Min(sFastSma, sSlowSma); - bearSlopeList.Add(bearSlope); + bearSlopeList.AddRounded(bearSlope); var signal = GetBullishBearishSignal(bullSlope, prevBullSlope, bearSlope, prevBearSlope); signalsList.Add(signal); @@ -7278,16 +7278,16 @@ public static StockData CalculateCommoditySelectionIndex(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal atr = atrList.ElementAtOrDefault(i); - decimal adxRating = adxList.ElementAtOrDefault(i); + decimal atr = atrList[i]; + decimal adxRating = adxList[i]; decimal prevCsi = csiList.LastOrDefault(); decimal csi = k * atr * adxRating; - csiList.Add(csi); + csiList.AddRounded(csi); decimal prevCsiSma = csiSmaList.LastOrDefault(); decimal csiSma = csiList.TakeLastExt(length).Average(); - csiSmaList.Add(csiSma); + csiSmaList.AddRounded(csiSma); var signal = GetCompareSignal(csi - csiSma, prevCsi - prevCsiSma, true); signalsList.Add(signal); @@ -7325,14 +7325,14 @@ public static StockData CalculatePivotDetectorOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal prevPdo1 = i >= 1 ? pdoList.ElementAtOrDefault(i - 1) : 0; - decimal prevPdo2 = i >= 2 ? pdoList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal rsi = rsiList[i]; + decimal prevPdo1 = i >= 1 ? pdoList[i - 1] : 0; + decimal prevPdo2 = i >= 2 ? pdoList[i - 2] : 0; decimal pdo = currentValue > sma ? (rsi - 35) / (85 - 35) * 100 : currentValue <= sma ? (rsi - 20) / (70 - 20) * 100 : 0; - pdoList.Add(pdo); + pdoList.AddRounded(pdo); var signal = GetCompareSignal(pdo - prevPdo1, prevPdo1 - prevPdo2); signalsList.Add(signal); @@ -7365,21 +7365,21 @@ public static StockData CalculatePercentChangeOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevPcc = percentChangeList.LastOrDefault(); decimal pcc = prevValue - 1 != 0 ? prevPcc + (currentValue / (prevValue - 1)) : 0; - percentChangeList.Add(pcc); + percentChangeList.AddRounded(pcc); } var pctChgWmaList = GetMovingAverageList(stockData, maType, length, percentChangeList); for (int i = 0; i < stockData.Count; i++) { - decimal pcc = percentChangeList.ElementAtOrDefault(i); - decimal pccWma = pctChgWmaList.ElementAtOrDefault(i); - decimal prevPcc = i >= 1 ? percentChangeList.ElementAtOrDefault(i - 1) : 0; - decimal prevPccWma = i >= 1 ? pctChgWmaList.ElementAtOrDefault(i - 1) : 0; + decimal pcc = percentChangeList[i]; + decimal pccWma = pctChgWmaList[i]; + decimal prevPcc = i >= 1 ? percentChangeList[i - 1] : 0; + decimal prevPccWma = i >= 1 ? pctChgWmaList[i - 1] : 0; var signal = GetCompareSignal(pcc - pccWma, prevPcc - prevPccWma); signalsList.Add(signal); @@ -7413,15 +7413,15 @@ public static StockData CalculatePrimeNumberOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal ratio = currentValue * length / 100; - Int64 convertedValue = (Int64)Math.Round(currentValue); - Int64 sqrtValue = currentValue >= 0 ? (Int64)Math.Round(Sqrt(currentValue)) : 0; - Int64 maxValue = (Int64)Math.Round(currentValue + ratio); - Int64 minValue = (Int64)Math.Round(currentValue - ratio); + 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); - decimal pno = 0, pno1 = 0, pno2 = 0; - for (Int64 j = convertedValue; j <= maxValue; j++) + decimal pno1 = 0, pno2 = 0; + for (long j = convertedValue; j <= maxValue; j++) { pno1 = j; for (int k = 2; k <= sqrtValue; k++) @@ -7439,9 +7439,9 @@ public static StockData CalculatePrimeNumberOscillator(this StockData stockData, } } pno1 = pno1 == 0 ? pno1List.LastOrDefault() : pno1; - pno1List.Add(pno1); + pno1List.AddRounded(pno1); - for (Int64 l = convertedValue; l >= minValue; l--) + for (long l = convertedValue; l >= minValue; l--) { pno2 = l; for (int m = 2; m <= sqrtValue; m++) @@ -7459,12 +7459,12 @@ public static StockData CalculatePrimeNumberOscillator(this StockData stockData, } } pno2 = pno2 == 0 ? pno2List.LastOrDefault() : pno2; - pno2List.Add(pno2); + pno2List.AddRounded(pno2); decimal prevPno = pnoList.LastOrDefault(); - pno = pno1 - currentValue < currentValue - pno2 ? pno1 - currentValue : pno2 - currentValue; + decimal pno = pno1 - currentValue < currentValue - pno2 ? pno1 - currentValue : pno2 - currentValue; pno = pno == 0 ? prevPno : pno; - pnoList.Add(pno); + pnoList.AddRounded(pno); var signal = GetCompareSignal(pno, prevPno); signalsList.Add(signal); @@ -7536,31 +7536,31 @@ public static StockData CalculatePringSpecialK(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal roc10Sma = roc10SmaList.ElementAtOrDefault(i); - decimal roc15Sma = roc15SmaList.ElementAtOrDefault(i); - decimal roc20Sma = roc20SmaList.ElementAtOrDefault(i); - decimal roc30Sma = roc30SmaList.ElementAtOrDefault(i); - decimal roc40Sma = roc40SmaList.ElementAtOrDefault(i); - decimal roc65Sma = roc65SmaList.ElementAtOrDefault(i); - decimal roc75Sma = roc75SmaList.ElementAtOrDefault(i); - decimal roc100Sma = roc100SmaList.ElementAtOrDefault(i); - decimal roc195Sma = roc195SmaList.ElementAtOrDefault(i); - decimal roc265Sma = roc265SmaList.ElementAtOrDefault(i); - decimal roc390Sma = roc390SmaList.ElementAtOrDefault(i); - decimal roc530Sma = roc530SmaList.ElementAtOrDefault(i); + decimal roc10Sma = roc10SmaList[i]; + decimal roc15Sma = roc15SmaList[i]; + decimal roc20Sma = roc20SmaList[i]; + decimal roc30Sma = roc30SmaList[i]; + decimal roc40Sma = roc40SmaList[i]; + decimal roc65Sma = roc65SmaList[i]; + decimal roc75Sma = roc75SmaList[i]; + decimal roc100Sma = roc100SmaList[i]; + decimal roc195Sma = roc195SmaList[i]; + decimal roc265Sma = roc265SmaList[i]; + decimal roc390Sma = roc390SmaList[i]; + decimal roc530Sma = roc530SmaList[i]; decimal 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.Add(specialK); + specialKList.AddRounded(specialK); } var specialKSignalList = GetMovingAverageList(stockData, maType, smoothLength, specialKList); for (int i = 0; i < stockData.Count; i++) { - decimal specialK = specialKList.ElementAtOrDefault(i); - decimal specialKSignal = specialKSignalList.ElementAtOrDefault(i); - decimal prevSpecialK = i >= 1 ? specialKList.ElementAtOrDefault(i - 1) : 0; - decimal prevSpecialKSignal = i >= 1 ? specialKSignalList.ElementAtOrDefault(i - 1) : 0; + decimal specialK = specialKList[i]; + decimal specialKSignal = specialKSignalList[i]; + decimal prevSpecialK = i >= 1 ? specialKList[i - 1] : 0; + decimal prevSpecialKSignal = i >= 1 ? specialKSignalList[i - 1] : 0; var signal = GetCompareSignal(specialK - specialKSignal, prevSpecialK - prevSpecialKSignal); signalsList.Add(signal); @@ -7597,23 +7597,23 @@ public static StockData CalculatePriceZoneOscillator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal dvol = Math.Sign(currentValue - prevValue) * currentValue; - dvolList.Add(dvol); + dvolList.AddRounded(dvol); } var dvmaList = GetMovingAverageList(stockData, maType, length, dvolList); for (int i = 0; i < stockData.Count; i++) { - decimal vma = emaList.ElementAtOrDefault(i); - decimal dvma = dvmaList.ElementAtOrDefault(i); - decimal prevPzo1 = i >= 1 ? pzoList.ElementAtOrDefault(i - 1) : 0; - decimal prevPzo2 = i >= 2 ? pzoList.ElementAtOrDefault(i - 2) : 0; + decimal vma = emaList[i]; + decimal dvma = dvmaList[i]; + decimal prevPzo1 = i >= 1 ? pzoList[i - 1] : 0; + decimal prevPzo2 = i >= 2 ? pzoList[i - 2] : 0; decimal pzo = vma != 0 ? MinOrMax(100 * dvma / vma, 100, -100) : 0; - pzoList.Add(pzo); + pzoList.AddRounded(pzo); var signal = GetRsiSignal(pzo - prevPzo1, prevPzo1 - prevPzo2, pzo, prevPzo1, 40, -40); signalsList.Add(signal); @@ -7644,12 +7644,12 @@ public static StockData CalculatePerformanceIndex(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal prevKpi = kpiList.LastOrDefault(); decimal kpi = prevValue != 0 ? (currentValue - prevValue) * 100 / prevValue : 0; - kpiList.Add(kpi); + kpiList.AddRounded(kpi); var signal = GetCompareSignal(kpi, prevKpi); signalsList.Add(signal); @@ -7684,26 +7684,26 @@ public static StockData CalculatePolarizedFractalEfficiency(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal priorValue = i >= length ? inputList[i - length] : 0; decimal pfe = Sqrt(Pow(currentValue - priorValue, 2) + 100); decimal c2c = Sqrt(Pow(currentValue - prevValue, 2) + 1); - c2cList.Add(c2c); + c2cList.AddRounded(c2c); decimal c2cSum = c2cList.TakeLastExt(length).Sum(); decimal efRatio = c2cSum != 0 ? pfe / c2cSum * 100 : 0; decimal fracEff = currentValue - priorValue > 0 ? efRatio : -efRatio; - fracEffList.Add(fracEff); + fracEffList.AddRounded(fracEff); } var emaList = GetMovingAverageList(stockData, maType, smoothLength, fracEffList); for (int i = 0; i < stockData.Count; i++) { - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal ema = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; var signal = GetCompareSignal(ema, prevEma); signalsList.Add(signal); @@ -7739,13 +7739,13 @@ public static StockData CalculatePrettyGoodOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal atr = atrList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal atr = atrList[i]; decimal prevPgo = pgoList.LastOrDefault(); decimal pgo = atr != 0 ? (currentValue - sma) / atr : 0; - pgoList.Add(pgo); + pgoList.AddRounded(pgo); var signal = GetCompareSignal(pgo, prevPgo); signalsList.Add(signal); @@ -7781,23 +7781,23 @@ public static StockData CalculatePriceCycleOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal currentLow = lowList[i]; decimal diff = currentClose - currentLow; - diffList.Add(diff); + diffList.AddRounded(diff); } var diffSmaList = GetMovingAverageList(stockData, maType, length, diffList); for (int i = 0; i < stockData.Count; i++) { - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal prevPco1 = i >= 1 ? pcoList.ElementAtOrDefault(i - 1) : 0; - decimal prevPco2 = i >= 2 ? pcoList.ElementAtOrDefault(i - 2) : 0; - decimal diffSma = diffSmaList.ElementAtOrDefault(i); + decimal currentAtr = atrList[i]; + decimal prevPco1 = i >= 1 ? pcoList[i - 1] : 0; + decimal prevPco2 = i >= 2 ? pcoList[i - 2] : 0; + decimal diffSma = diffSmaList[i]; decimal pco = currentAtr != 0 ? diffSma / currentAtr * 100 : 0; - pcoList.Add(pco); + pcoList.AddRounded(pco); var signal = GetCompareSignal(pco - prevPco1, prevPco1 - prevPco2); signalsList.Add(signal); @@ -7831,14 +7831,14 @@ public static StockData CalculatePhaseChangeIndex(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal mom = currentValue - prevValue; decimal positiveSum = 0, negativeSum = 0; for (int j = 0; j <= length - 1; j++) { - decimal prevValue2 = i >= length - j ? inputList.ElementAtOrDefault(i - (length - j)) : 0; + decimal prevValue2 = i >= length - j ? inputList[i - (length - j)] : 0; decimal gradient = prevValue + (mom * (length - j) / (length - 1)); decimal deviation = prevValue2 - gradient; positiveSum = deviation > 0 ? positiveSum + deviation : positiveSum + 0; @@ -7847,15 +7847,15 @@ public static StockData CalculatePhaseChangeIndex(this StockData stockData, Movi decimal sum = positiveSum + negativeSum; decimal pci = sum != 0 ? MinOrMax(100 * positiveSum / sum, 100, 0) : 0; - pciList.Add(pci); + pciList.AddRounded(pci); } var pciSmoothedList = GetMovingAverageList(stockData, maType, smoothLength, pciList); for (int i = 0; i < stockData.Count; i++) { - decimal pciSmoothed = pciSmoothedList.ElementAtOrDefault(i); - decimal prevPciSmoothed1 = i >= 1 ? pciSmoothedList.ElementAtOrDefault(i - 1) : 0; - decimal prevPciSmoothed2 = i >= 2 ? pciSmoothedList.ElementAtOrDefault(i - 2) : 0; + decimal pciSmoothed = pciSmoothedList[i]; + decimal prevPciSmoothed1 = i >= 1 ? pciSmoothedList[i - 1] : 0; + decimal prevPciSmoothed2 = i >= 2 ? pciSmoothedList[i - 2] : 0; var signal = GetRsiSignal(pciSmoothed - prevPciSmoothed1, prevPciSmoothed1 - prevPciSmoothed2, pciSmoothed, prevPciSmoothed1, 80, 20); signalsList.Add(signal); @@ -7895,16 +7895,16 @@ public static StockData CalculatePeakValleyEstimation(this StockData stockData, var smaList = GetMovingAverageList(stockData, maType, length, inputList); - for (int h = 0; h < stockData.Count; h++) + for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(h); - decimal sma = smaList.ElementAtOrDefault(h); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; decimal os = currentValue - sma; - osList.Add(os); + osList.AddRounded(os); decimal absOs = Math.Abs(os); - absOsList.Add(absOs); + absOsList.AddRounded(absOs); } stockData.CustomValuesList = absOsList; @@ -7912,26 +7912,26 @@ public static StockData CalculatePeakValleyEstimation(this StockData stockData, var (highestList, _) = GetMaxAndMinValuesList(pList, length); for (int i = 0; i < stockData.Count; i++) { - decimal os = osList.ElementAtOrDefault(i); - decimal p = pList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); + decimal os = osList[i]; + decimal p = pList[i]; + decimal highest = highestList[i]; - decimal prevH = i >= 1 ? hList.ElementAtOrDefault(i - 1) : 0; + decimal prevH = i >= 1 ? hList[i - 1] : 0; decimal h = highest != 0 ? p / highest : 0; - hList.Add(h); + hList.AddRounded(h); decimal mod1 = h == 1 && prevH != 1 ? 1 : 0; decimal mod2 = h < 0.8m ? 1 : 0; decimal mod3 = prevH == 1 && h < prevH ? 1 : 0; decimal sign1 = mod1 == 1 && os < 0 ? 1 : mod1 == 1 && os > 0 ? -1 : 0; - sign1List.Add(sign1); + sign1List.AddRounded(sign1); decimal sign2 = mod2 == 1 && os < 0 ? 1 : mod2 == 1 && os > 0 ? -1 : 0; - sign2List.Add(sign2); + sign2List.AddRounded(sign2); decimal sign3 = mod3 == 1 && os < 0 ? 1 : mod3 == 1 && os > 0 ? -1 : 0; - sign3List.Add(sign3); + sign3List.AddRounded(sign3); var signal = GetConditionSignal(sign1 > 0, sign1 < 0); signalsList.Add(signal); @@ -7965,17 +7965,17 @@ public static StockData CalculatePsychologicalLine(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevPsy1 = i >= 1 ? psyList.ElementAtOrDefault(i - 1) : 0; - decimal prevPsy2 = i >= 2 ? psyList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevPsy1 = i >= 1 ? psyList[i - 1] : 0; + decimal prevPsy2 = i >= 2 ? psyList[i - 2] : 0; decimal cond = currentValue > prevValue ? 1 : 0; - condList.Add(cond); + condList.AddRounded(cond); decimal condSum = condList.TakeLastExt(length).Sum(); decimal psy = length != 0 ? condSum / length * 100 : 0; - psyList.Add(psy); + psyList.AddRounded(psy); var signal = GetCompareSignal(psy - prevPsy1, prevPsy1 - prevPsy2); signalsList.Add(signal); @@ -8017,45 +8017,45 @@ public static StockData CalculateTurboTrigger(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal c = cList.ElementAtOrDefault(i); - decimal o = oList.ElementAtOrDefault(i); + decimal c = cList[i]; + decimal o = oList[i]; decimal avg = (c + o) / 2; - avgList.Add(avg); + avgList.AddRounded(avg); } var yList = GetMovingAverageList(stockData, maType, length, avgList); for (int i = 0; i < stockData.Count; i++) { - decimal y = yList.ElementAtOrDefault(i); - decimal h = hList.ElementAtOrDefault(i); - decimal l = lList.ElementAtOrDefault(i); + decimal y = yList[i]; + decimal h = hList[i]; + decimal l = lList[i]; decimal hy = h - y; - hyList.Add(hy); + hyList.AddRounded(hy); decimal yl = y - l; - ylList.Add(yl); + 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++) { - decimal a = aList.ElementAtOrDefault(i); - decimal b = bList.ElementAtOrDefault(i); + decimal a = aList[i]; + decimal b = bList[i]; decimal ab = a - b; - abList.Add(ab); + abList.AddRounded(ab); } var oscList = GetMovingAverageList(stockData, maType, length, abList); for (int i = 0; i < stockData.Count; i++) { - decimal osc = oscList.ElementAtOrDefault(i); - decimal prevOsc = i >= 1 ? oscList.ElementAtOrDefault(i - 1) : 0; - decimal a = aList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : 0; + decimal osc = oscList[i]; + decimal prevOsc = i >= 1 ? oscList[i - 1] : 0; + decimal a = aList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : 0; var signal = GetCompareSignal(osc - a, prevOsc - prevA); signalsList.Add(signal); @@ -8097,28 +8097,28 @@ public static StockData CalculateTotalPowerIndicator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal bullPower = bullPowerList.ElementAtOrDefault(i); - decimal bearPower = bearPowerList.ElementAtOrDefault(i); + decimal bullPower = bullPowerList[i]; + decimal bearPower = bearPowerList[i]; decimal bullCount = bullPower > 0 ? 1 : 0; - bullCountList.Add(bullCount); + bullCountList.AddRounded(bullCount); decimal bearCount = bearPower < 0 ? 1 : 0; - bearCountList.Add(bearCount); + bearCountList.AddRounded(bearCount); decimal bullCountSum = bullCountList.TakeLastExt(length1).Sum(); decimal bearCountSum = bearCountList.TakeLastExt(length1).Sum(); decimal totalPower = length1 != 0 ? 100 * Math.Abs(bullCountSum - bearCountSum) / length1 : 0; - totalPowerList.Add(totalPower); + totalPowerList.AddRounded(totalPower); decimal prevAdjBullCount = adjBullCountList.LastOrDefault(); decimal adjBullCount = length1 != 0 ? 100 * bullCountSum / length1 : 0; - adjBullCountList.Add(adjBullCount); + adjBullCountList.AddRounded(adjBullCount); decimal prevAdjBearCount = adjBearCountList.LastOrDefault(); decimal adjBearCount = length1 != 0 ? 100 * bearCountSum / length1 : 0; - adjBearCountList.Add(adjBearCount); + adjBearCountList.AddRounded(adjBearCount); var signal = GetCompareSignal(adjBullCount - adjBearCount, prevAdjBullCount - prevAdjBearCount); signalsList.Add(signal); @@ -8160,15 +8160,15 @@ public static StockData CalculateTurboScaler(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal sma2 = sma2List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal sma2 = sma2List[i]; decimal smoSma = (alpha * sma) + ((1 - alpha) * sma2); - smoSmaList.Add(smoSma); + smoSmaList.AddRounded(smoSma); decimal smo = (alpha * currentValue) + ((1 - alpha) * sma); - smoList.Add(smo); + smoList.AddRounded(smo); decimal smoSmaHighest = smoSmaList.TakeLastExt(length).Max(); decimal smoSmaLowest = smoSmaList.TakeLastExt(length).Min(); @@ -8176,20 +8176,20 @@ public static StockData CalculateTurboScaler(this StockData stockData, MovingAvg decimal smoLowest = smoList.TakeLastExt(length).Min(); decimal a = smoHighest - smoLowest != 0 ? (currentValue - smoLowest) / (smoHighest - smoLowest) : 0; - aList.Add(a); + aList.AddRounded(a); decimal b = smoSmaHighest - smoSmaLowest != 0 ? (sma - smoSmaLowest) / (smoSmaHighest - smoSmaLowest) : 0; - bList.Add(b); + 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++) { - decimal a = aSmaList.ElementAtOrDefault(i); - decimal b = bSmaList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aSmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevB = i >= 1 ? bSmaList.ElementAtOrDefault(i - 1) : 0; + decimal a = aSmaList[i]; + decimal b = bSmaList[i]; + decimal prevA = i >= 1 ? aSmaList[i - 1] : 0; + decimal prevB = i >= 1 ? bSmaList[i - 1] : 0; var signal = GetCompareSignal(a - b, prevA - prevB); signalsList.Add(signal); @@ -8238,27 +8238,27 @@ public static StockData CalculateTechnicalRank(this StockData stockData, int len for (int i = 0; i < stockData.Count; i++) { - decimal currentEma200 = ma1List.ElementAtOrDefault(i); - decimal currentEma50 = ma2List.ElementAtOrDefault(i); - decimal currentRoc125 = ltRocList.ElementAtOrDefault(i); - decimal currentRoc20 = mtRocList.ElementAtOrDefault(i); - decimal currentPpoHistogram = ppoHistList.ElementAtOrDefault(i); - decimal currentRsi = rsiList.ElementAtOrDefault(i); - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal prevTr1 = i >= 1 ? trList.ElementAtOrDefault(i - 1) : 0; - decimal prevTr2 = i >= 2 ? trList.ElementAtOrDefault(i - 2) : 0; + decimal currentEma200 = ma1List[i]; + decimal currentEma50 = ma2List[i]; + decimal currentRoc125 = ltRocList[i]; + decimal currentRoc20 = mtRocList[i]; + decimal currentPpoHistogram = ppoHistList[i]; + decimal currentRsi = rsiList[i]; + decimal currentPrice = inputList[i]; + decimal prevTr1 = i >= 1 ? trList[i - 1] : 0; + decimal prevTr2 = i >= 2 ? trList[i - 2] : 0; decimal ltMa = currentEma200 != 0 ? 0.3m * 100 * (currentPrice - currentEma200) / currentEma200 : 0; decimal ltRoc = 0.3m * 100 * currentRoc125; decimal mtMa = currentEma50 != 0 ? 0.15m * 100 * (currentPrice - currentEma50) / currentEma50 : 0; decimal mtRoc = 0.15m * 100 * currentRoc20; decimal currentValue = currentPpoHistogram; - decimal prevValue = i >= length8 ? ppoHistList.ElementAtOrDefault(i - length8) : 0; + decimal prevValue = i >= length8 ? ppoHistList[i - length8] : 0; decimal slope = length8 != 0 ? (currentValue - prevValue) / length8 : 0; decimal stPpo = 0.05m * 100 * slope; decimal stRsi = 0.05m * currentRsi; decimal tr = Math.Min(100, Math.Max(0, ltMa + ltRoc + mtMa + mtRoc + stPpo + stRsi)); - trList.Add(tr); + trList.AddRounded(tr); var signal = GetCompareSignal(tr - prevTr1, prevTr1 - prevTr2); signalsList.Add(signal); @@ -8291,25 +8291,25 @@ public static StockData CalculateTrigonometricOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal s = sList.ElementAtOrDefault(i); - decimal prevS = i >= 1 ? sList.ElementAtOrDefault(i - 1) : 0; + decimal s = sList[i]; + decimal prevS = i >= 1 ? sList[i - 1] : 0; decimal wa = Asin(Math.Sign(s - prevS)) * 2; decimal wb = Asin(Math.Sign(1)) * 2; decimal u = wa + (2 * Pi * Math.Round((wa - wb) / (2 * Pi))); - uList.Add(u); + uList.AddRounded(u); } stockData.CustomValuesList = uList; var uLinregList = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal u = uLinregList.ElementAtOrDefault(i); - decimal prevO1 = i >= 1 ? oList.ElementAtOrDefault(i - 1) : 0; - decimal prevO2 = i >= 2 ? oList.ElementAtOrDefault(i - 2) : 0; + decimal u = uLinregList[i]; + decimal prevO1 = i >= 1 ? oList[i - 1] : 0; + decimal prevO2 = i >= 2 ? oList[i - 2] : 0; decimal o = Atan(u); - oList.Add(o); + oList.AddRounded(o); var signal = GetRsiSignal(o - prevO1, prevO1 - prevO2, o, prevO1, 1, -1); signalsList.Add(signal); @@ -8351,9 +8351,9 @@ public static StockData CalculateTradingMadeMoreSimplerOscillator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal stoch1 = stochastic1List.ElementAtOrDefault(i); - decimal stoch2 = stochastic2List.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; + decimal stoch1 = stochastic1List[i]; + decimal stoch2 = stochastic2List[i]; decimal bufRsi = rsi - threshold; decimal bufStoch1 = stoch1 - threshold; decimal bufStoch2 = stoch2 - threshold; @@ -8362,7 +8362,7 @@ public static StockData CalculateTradingMadeMoreSimplerOscillator(this StockData decimal prevBufHistNo = bufHistNoList.LastOrDefault(); decimal bufHistNo = bufHistUp - bufHistDn; - bufHistNoList.Add(bufHistNo); + bufHistNoList.AddRounded(bufHistNo); var signal = GetCompareSignal(bufHistNo, prevBufHistNo); signalsList.Add(signal); @@ -8407,24 +8407,24 @@ public static StockData CalculateTradersDynamicIndex(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal rsiSma = maList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal mab = mabList.ElementAtOrDefault(i); - decimal mbb = mbbList.ElementAtOrDefault(i); - decimal prevMab = i >= 1 ? mabList.ElementAtOrDefault(i - 1) : 0; - decimal prevMbb = i >= 1 ? mbbList.ElementAtOrDefault(i - 1) : 0; + decimal rsiSma = maList[i]; + decimal stdDev = stdDevList[i]; + decimal mab = mabList[i]; + decimal mbb = mbbList[i]; + decimal prevMab = i >= 1 ? mabList[i - 1] : 0; + decimal prevMbb = i >= 1 ? mbbList[i - 1] : 0; decimal offs = 1.6185m * stdDev; decimal prevUp = upList.LastOrDefault(); decimal up = rsiSma + offs; - upList.Add(up); + upList.AddRounded(up); decimal prevDn = dnList.LastOrDefault(); decimal dn = rsiSma - offs; - dnList.Add(dn); + dnList.AddRounded(dn); decimal mid = (up + dn) / 2; - midList.Add(mid); + midList.AddRounded(mid); var signal = GetBollingerBandsSignal(mab - mbb, prevMab - prevMbb, mab, prevMab, up, prevUp, dn, prevDn); signalsList.Add(signal); @@ -8467,14 +8467,14 @@ public static StockData CalculateTopsAndBottomsFinder(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal a = emaList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal a = emaList[i]; + decimal prevA = i >= 1 ? emaList[i - 1] : 0; decimal b = a > prevA ? a : 0; - bList.Add(b); + bList.AddRounded(b); decimal c = a < prevA ? a : 0; - cList.Add(c); + cList.AddRounded(c); } stockData.CustomValuesList = bList; @@ -8483,20 +8483,20 @@ public static StockData CalculateTopsAndBottomsFinder(this StockData stockData, var cStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal a = emaList.ElementAtOrDefault(i); - decimal b = bStdDevList.ElementAtOrDefault(i); - decimal c = cStdDevList.ElementAtOrDefault(i); + decimal a = emaList[i]; + decimal b = bStdDevList[i]; + decimal c = cStdDevList[i]; decimal prevUp = upList.LastOrDefault(); decimal up = a + b != 0 ? a / (a + b) : 0; - upList.Add(up); + upList.AddRounded(up); decimal prevDn = dnList.LastOrDefault(); decimal dn = a + c != 0 ? a / (a + c) : 0; - dnList.Add(dn); + dnList.AddRounded(dn); decimal os = prevUp == 1 && up != 1 ? 1 : prevDn == 1 && dn != 1 ? -1 : 0; - osList.Add(os); + osList.AddRounded(os); var signal = GetConditionSignal(os > 0, os < 0); signalsList.Add(signal); @@ -8534,41 +8534,41 @@ public static StockData CalculateTraderPressureIndex(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal high = highList[i]; + decimal low = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal hiup = Math.Max(high - prevHigh, 0); decimal loup = Math.Max(low - prevLow, 0); decimal hidn = Math.Min(high - prevHigh, 0); decimal lodn = Math.Min(low - prevLow, 0); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal range = highest - lowest; decimal bulls = range != 0 ? Math.Min((hiup + loup) / range, 1) * 100 : 0; - bullsList.Add(bulls); + bullsList.AddRounded(bulls); decimal bears = range != 0 ? Math.Max((hidn + lodn) / range, -1) * -100 : 0; - bearsList.Add(bears); + 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++) { - decimal avgBulls = avgBullsList.ElementAtOrDefault(i); - decimal avgBears = avgBearsList.ElementAtOrDefault(i); + decimal avgBulls = avgBullsList[i]; + decimal avgBears = avgBearsList[i]; decimal net = avgBulls - avgBears; - netList.Add(net); + netList.AddRounded(net); } var tpxList = GetMovingAverageList(stockData, maType, smoothLength, netList); for (int i = 0; i < stockData.Count; i++) { - decimal tpx = tpxList.ElementAtOrDefault(i); - decimal prevTpx = i >= 1 ? tpxList.ElementAtOrDefault(i - 1) : 0; + decimal tpx = tpxList[i]; + decimal prevTpx = i >= 1 ? tpxList[i - 1] : 0; var signal = GetCompareSignal(tpx, prevTpx); signalsList.Add(signal); @@ -8674,53 +8674,53 @@ public static StockData CalculateTechnicalRatings(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal ma10 = ma10List.ElementAtOrDefault(i); - decimal ma20 = ma20List.ElementAtOrDefault(i); - decimal ma30 = ma30List.ElementAtOrDefault(i); - decimal ma50 = ma50List.ElementAtOrDefault(i); - decimal ma100 = ma100List.ElementAtOrDefault(i); - decimal ma200 = ma200List.ElementAtOrDefault(i); - decimal hullMa = hullMaList.ElementAtOrDefault(i); - decimal vwma = vwmaList.ElementAtOrDefault(i); - decimal conLine = tenkanList.ElementAtOrDefault(i); - decimal baseLine = kijunList.ElementAtOrDefault(i); - decimal leadLine1 = senkouAList.ElementAtOrDefault(i); - decimal leadLine2 = senkouBList.ElementAtOrDefault(i); - decimal kSto = stoKList.ElementAtOrDefault(i); - decimal prevKSto = i >= 1 ? stoKList.ElementAtOrDefault(i - 1) : 0; - decimal dSto = stoDList.ElementAtOrDefault(i); - decimal prevDSto = i >= 1 ? stoDList.ElementAtOrDefault(i - 1) : 0; - decimal cci = cciList.ElementAtOrDefault(i); - decimal prevCci = i >= 1 ? cciList.ElementAtOrDefault(i - 1) : 0; - decimal adx = adxList.ElementAtOrDefault(i); - decimal adxPlus = adxPlusList.ElementAtOrDefault(i); - decimal prevAdxPlus = i >= 1 ? adxPlusList.ElementAtOrDefault(i - 1) : 0; - decimal adxMinus = adxMinusList.ElementAtOrDefault(i); - decimal prevAdxMinus = i >= 1 ? adxMinusList.ElementAtOrDefault(i - 1) : 0; - decimal ao = aoList.ElementAtOrDefault(i); - decimal prevAo1 = i >= 1 ? aoList.ElementAtOrDefault(i - 1) : 0; - decimal prevAo2 = i >= 2 ? aoList.ElementAtOrDefault(i - 2) : 0; - decimal mom = momentumList.ElementAtOrDefault(i); - decimal prevMom = i >= 1 ? momentumList.ElementAtOrDefault(i - 1) : 0; - decimal macd = macdList.ElementAtOrDefault(i); - decimal macdSig = macdSignalList.ElementAtOrDefault(i); - decimal kStoRsi = stoRsiKList.ElementAtOrDefault(i); - decimal prevKStoRsi = i >= 1 ? stoRsiKList.ElementAtOrDefault(i - 1) : 0; - decimal dStoRsi = stoRsiDList.ElementAtOrDefault(i); - decimal prevDStoRsi = i >= 1 ? stoRsiDList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal rsi = rsiList[i]; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; + decimal ma10 = ma10List[i]; + decimal ma20 = ma20List[i]; + decimal ma30 = ma30List[i]; + decimal ma50 = ma50List[i]; + decimal ma100 = ma100List[i]; + decimal ma200 = ma200List[i]; + decimal hullMa = hullMaList[i]; + decimal vwma = vwmaList[i]; + decimal conLine = tenkanList[i]; + decimal baseLine = kijunList[i]; + decimal leadLine1 = senkouAList[i]; + decimal leadLine2 = senkouBList[i]; + decimal kSto = stoKList[i]; + decimal prevKSto = i >= 1 ? stoKList[i - 1] : 0; + decimal dSto = stoDList[i]; + decimal prevDSto = i >= 1 ? stoDList[i - 1] : 0; + decimal cci = cciList[i]; + decimal prevCci = i >= 1 ? cciList[i - 1] : 0; + decimal adx = adxList[i]; + decimal adxPlus = adxPlusList[i]; + decimal prevAdxPlus = i >= 1 ? adxPlusList[i - 1] : 0; + decimal adxMinus = adxMinusList[i]; + decimal prevAdxMinus = i >= 1 ? adxMinusList[i - 1] : 0; + decimal ao = aoList[i]; + decimal prevAo1 = i >= 1 ? aoList[i - 1] : 0; + decimal prevAo2 = i >= 2 ? aoList[i - 2] : 0; + decimal mom = momentumList[i]; + decimal prevMom = i >= 1 ? momentumList[i - 1] : 0; + decimal macd = macdList[i]; + decimal macdSig = macdSignalList[i]; + decimal kStoRsi = stoRsiKList[i]; + decimal prevKStoRsi = i >= 1 ? stoRsiKList[i - 1] : 0; + decimal dStoRsi = stoRsiDList[i]; + decimal prevDStoRsi = i >= 1 ? stoRsiDList[i - 1] : 0; bool upTrend = currentValue > ma50; bool dnTrend = currentValue < ma50; - decimal wr = williamsPctList.ElementAtOrDefault(i); - decimal prevWr = i >= 1 ? williamsPctList.ElementAtOrDefault(i - 1) : 0; - decimal bullPower = bullPowerList.ElementAtOrDefault(i); - decimal prevBullPower = i >= 1 ? bullPowerList.ElementAtOrDefault(i - 1) : 0; - decimal bearPower = bearPowerList.ElementAtOrDefault(i); - decimal prevBearPower = i >= 1 ? bearPowerList.ElementAtOrDefault(i - 1) : 0; - decimal uo = uoList.ElementAtOrDefault(i); + decimal wr = williamsPctList[i]; + decimal prevWr = i >= 1 ? williamsPctList[i - 1] : 0; + decimal bullPower = bullPowerList[i]; + decimal prevBullPower = i >= 1 ? bullPowerList[i - 1] : 0; + decimal bearPower = bearPowerList[i]; + decimal prevBearPower = i >= 1 ? bearPowerList[i - 1] : 0; + decimal uo = uoList[i]; decimal maRating = 0; maRating += currentValue > ma10 ? 1 : currentValue < ma10 ? -1 : 0; @@ -8735,7 +8735,7 @@ public static StockData CalculateTechnicalRatings(this StockData stockData, Movi currentValue > conLine ? 1 : leadLine2 > leadLine1 && currentValue < leadLine2 && currentValue > baseLine && prevValue > conLine && currentValue < conLine ? -1 : 0; maRating /= 9; - maRatingList.Add(maRating); + maRatingList.AddRounded(maRating); decimal oscRating = 0; oscRating += rsi < 30 && prevRsi < rsi ? 1 : rsi > 70 && prevRsi > rsi ? -1 : 0; @@ -8754,10 +8754,10 @@ public static StockData CalculateTechnicalRatings(this StockData stockData, Movi oscRating += upTrend && bearPower < 0 && bearPower > prevBearPower ? 1 : dnTrend && bullPower > 0 && bullPower < prevBullPower ? -1 : 0; oscRating += uo > 70 ? 1 : uo < 30 ? -1 : 0; oscRating /= 11; - oscRatingList.Add(oscRating); + oscRatingList.AddRounded(oscRating); decimal totalRating = (maRating + oscRating) / 2; - totalRatingList.Add(totalRating); + totalRatingList.AddRounded(totalRating); var signal = GetConditionSignal(totalRating > 0.1m, totalRating < -0.1m); signalsList.Add(signal); @@ -8791,26 +8791,26 @@ public static StockData CalculateTTMScalperIndicator(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal prevClose1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevClose3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal close = inputList[i]; + decimal prevClose1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevClose2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevClose3 = i >= 3 ? inputList[i - 3] : 0; + decimal high = highList[i]; + decimal low = lowList[i]; decimal triggerSell = prevClose1 < close && (prevClose2 < prevClose1 || prevClose3 < prevClose1) ? 1 : 0; decimal triggerBuy = prevClose1 > close && (prevClose2 > prevClose1 || prevClose3 > prevClose1) ? 1 : 0; decimal prevBuySellSwitch = buySellSwitchList.LastOrDefault(); decimal buySellSwitch = triggerSell == 1 ? 1 : triggerBuy == 1 ? 0 : prevBuySellSwitch; - buySellSwitchList.Add(buySellSwitch); + buySellSwitchList.AddRounded(buySellSwitch); decimal prevSbs = sbsList.LastOrDefault(); decimal sbs = triggerSell == 1 && prevBuySellSwitch == 0 ? high : triggerBuy == 1 && prevBuySellSwitch == 1 ? low : prevSbs; - sbsList.Add(sbs); + sbsList.AddRounded(sbs); decimal prevClrs = clrsList.LastOrDefault(); decimal clrs = triggerSell == 1 && prevBuySellSwitch == 0 ? 1 : triggerBuy == 1 && prevBuySellSwitch == 1 ? -1 : prevClrs; - clrsList.Add(clrs); + clrsList.AddRounded(clrs); var signal = GetCompareSignal(clrs, prevClrs); signalsList.Add(signal); @@ -8842,14 +8842,14 @@ public static StockData CalculateTFSTetherLineIndicator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevTetherLine = tetherLineList.LastOrDefault(); decimal tetherLine = (highest + lowest) / 2; - tetherLineList.Add(tetherLine); + tetherLineList.AddRounded(tetherLine); var signal = GetCompareSignal(currentValue - tetherLine, prevValue - prevTetherLine); signalsList.Add(signal); @@ -8884,29 +8884,29 @@ public static StockData CalculateTheRangeIndicator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); decimal v1 = currentValue > prevValue ? tr / (currentValue - prevValue) : tr; - v1List.Add(v1); + v1List.AddRounded(v1); var lbList = v1List.TakeLastExt(length).ToList(); decimal v2 = lbList.Min(); decimal v3 = lbList.Max(); decimal stoch = v3 - v2 != 0 ? MinOrMax(100 * (v1 - v2) / (v3 - v2), 100, 0) : MinOrMax(100 * (v1 - v2), 100, 0); - stochList.Add(stoch); + stochList.AddRounded(stoch); } var triList = GetMovingAverageList(stockData, maType, length, stochList); for (int i = 0; i < stockData.Count; i++) { - decimal tri = triList.ElementAtOrDefault(i); - decimal prevTri1 = i >= 1 ? triList.ElementAtOrDefault(i - 1) : 0; - decimal prevTri2 = i >= 2 ? triList.ElementAtOrDefault(i - 2) : 0; + decimal tri = triList[i]; + decimal prevTri1 = i >= 1 ? triList[i - 1] : 0; + decimal prevTri2 = i >= 2 ? triList[i - 2] : 0; var signal = GetRsiSignal(tri - prevTri1, prevTri1 - prevTri2, tri, prevTri1, 80, 20); signalsList.Add(signal); @@ -8941,27 +8941,27 @@ public static StockData CalculateTimePriceIndicator(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal highest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal lowest = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal highest = i >= 1 ? highestList[i - 1] : 0; + decimal lowest = i >= 1 ? lowestList[i - 1] : 0; decimal rising = currentHigh > highest ? 1 : 0; - risingList.Add(rising); + risingList.AddRounded(rising); decimal falling = currentLow < lowest ? 1 : 0; - fallingList.Add(falling); + fallingList.AddRounded(falling); decimal a = i - risingList.LastIndexOf(1); decimal b = i - fallingList.LastIndexOf(1); decimal prevUpper = upperList.LastOrDefault(); decimal upper = length != 0 ? ((a > length ? length : a) / length) - 0.5m : 0; - upperList.Add(upper); + upperList.AddRounded(upper); decimal prevLower = lowerList.LastOrDefault(); decimal lower = length != 0 ? ((b > length ? length : b) / length) - 0.5m : 0; - lowerList.Add(lower); + lowerList.AddRounded(lower); var signal = GetCompareSignal((lower * -1) - (upper * -1), (prevLower * -1) - (prevUpper * -1)); signalsList.Add(signal); @@ -9009,23 +9009,23 @@ public static StockData CalculateRahulMohindarOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal r1 = r1List.ElementAtOrDefault(i); - decimal r2 = r2List.ElementAtOrDefault(i); - decimal r3 = r3List.ElementAtOrDefault(i); - decimal r4 = r4List.ElementAtOrDefault(i); - decimal r5 = r5List.ElementAtOrDefault(i); - decimal r6 = r6List.ElementAtOrDefault(i); - decimal r7 = r7List.ElementAtOrDefault(i); - decimal r8 = r8List.ElementAtOrDefault(i); - decimal r9 = r9List.ElementAtOrDefault(i); - decimal r10 = r10List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal r1 = r1List[i]; + decimal r2 = r2List[i]; + decimal r3 = r3List[i]; + decimal r4 = r4List[i]; + decimal r5 = r5List[i]; + decimal r6 = r6List[i]; + decimal r7 = r7List[i]; + decimal r8 = r8List[i]; + decimal r9 = r9List[i]; + decimal r10 = r10List[i]; decimal swingTrd1 = highest - lowest != 0 ? 100 * (currentValue - ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10)) / (highest - lowest) : 0; - swingTrd1List.Add(swingTrd1); + swingTrd1List.AddRounded(swingTrd1); } var swingTrd2List = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length3, swingTrd1List); @@ -9033,8 +9033,8 @@ public static StockData CalculateRahulMohindarOscillator(this StockData stockDat var rmoList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, length4, swingTrd3List); for (int i = 0; i < stockData.Count; i++) { - decimal rmo = rmoList.ElementAtOrDefault(i); - decimal prevRmo = i >= 1 ? rmoList.ElementAtOrDefault(i - 1) : 0; + decimal rmo = rmoList[i]; + decimal prevRmo = i >= 1 ? rmoList[i - 1] : 0; var signal = GetCompareSignal(rmo, prevRmo); signalsList.Add(signal); @@ -9082,19 +9082,19 @@ public static StockData CalculateRainbowOscillator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal r1 = r1List.ElementAtOrDefault(i); - decimal r2 = r2List.ElementAtOrDefault(i); - decimal r3 = r3List.ElementAtOrDefault(i); - decimal r4 = r4List.ElementAtOrDefault(i); - decimal r5 = r5List.ElementAtOrDefault(i); - decimal r6 = r6List.ElementAtOrDefault(i); - decimal r7 = r7List.ElementAtOrDefault(i); - decimal r8 = r8List.ElementAtOrDefault(i); - decimal r9 = r9List.ElementAtOrDefault(i); - decimal r10 = r10List.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal currentValue = inputList[i]; + decimal r1 = r1List[i]; + decimal r2 = r2List[i]; + decimal r3 = r3List[i]; + decimal r4 = r4List[i]; + decimal r5 = r5List[i]; + decimal r6 = r6List[i]; + decimal r7 = r7List[i]; + decimal r8 = r8List[i]; + decimal r9 = r9List[i]; + decimal r10 = r10List[i]; decimal 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))))))))); decimal 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, @@ -9103,13 +9103,13 @@ public static StockData CalculateRainbowOscillator(this StockData stockData, Mov decimal prevRainbowOscillator = rainbowOscillatorList.LastOrDefault(); decimal rainbowOscillator = highest - lowest != 0 ? 100 * ((currentValue - ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10)) / (highest - lowest)) : 0; - rainbowOscillatorList.Add(rainbowOscillator); + rainbowOscillatorList.AddRounded(rainbowOscillator); decimal upperBand = highest - lowest != 0 ? 100 * ((highestRainbow - lowestRainbow) / (highest - lowest)) : 0; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal lowerBand = -upperBand; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetCompareSignal(rainbowOscillator, prevRainbowOscillator); signalsList.Add(signal); @@ -9148,20 +9148,20 @@ public static StockData CalculateRandomWalkIndex(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= length ? highList.ElementAtOrDefault(i - length) : 0; - decimal prevLow = i >= length ? lowList.ElementAtOrDefault(i - length) : 0; + decimal currentAtr = atrList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh = i >= length ? highList[i - length] : 0; + decimal prevLow = i >= length ? lowList[i - length] : 0; decimal bottom = currentAtr * sqrt; decimal prevRwiLow = rwiLowList.LastOrDefault(); decimal rwiLow = bottom != 0 ? (prevHigh - currentLow) / bottom : 0; - rwiLowList.Add(rwiLow); + rwiLowList.AddRounded(rwiLow); decimal prevRwiHigh = rwiHighList.LastOrDefault(); decimal rwiHigh = bottom != 0 ? (currentHigh - prevLow) / bottom : 0; - rwiHighList.Add(rwiHigh); + rwiHighList.AddRounded(rwiHigh); var signal = GetCompareSignal(rwiHigh - rwiLow, prevRwiHigh - prevRwiLow); signalsList.Add(signal); @@ -9199,13 +9199,13 @@ public static StockData CalculateRangeActionVerificationIndex(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal fastMA = smaFastList.ElementAtOrDefault(i); - decimal slowMA = smaSlowList.ElementAtOrDefault(i); - decimal prevRavi1 = i >= 1 ? raviList.ElementAtOrDefault(i - 1) : 0; - decimal prevRavi2 = i >= 2 ? raviList.ElementAtOrDefault(i - 2) : 0; + decimal fastMA = smaFastList[i]; + decimal slowMA = smaSlowList[i]; + decimal prevRavi1 = i >= 1 ? raviList[i - 1] : 0; + decimal prevRavi2 = i >= 2 ? raviList[i - 2] : 0; decimal ravi = slowMA != 0 ? (fastMA - slowMA) / slowMA * 100 : 0; - raviList.Add(ravi); + raviList.AddRounded(ravi); var signal = GetCompareSignal(ravi - prevRavi1, prevRavi1 - prevRavi2); signalsList.Add(signal); @@ -9241,21 +9241,21 @@ public static StockData CalculateReallySimpleIndicator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentMa = maList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentLow = lowList[i]; + decimal currentMa = maList[i]; decimal rsi = currentValue != 0 ? (currentLow - currentMa) / currentValue * 100 : 0; - rsiList.Add(rsi); + rsiList.AddRounded(rsi); } var rsiMaList = GetMovingAverageList(stockData, maType, smoothLength, rsiList); for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiMaList.ElementAtOrDefault(i); - decimal prevRsiMa = i >= 1 ? rsiMaList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal rsiMa = rsiMaList.ElementAtOrDefault(i); + decimal rsi = rsiMaList[i]; + decimal prevRsiMa = i >= 1 ? rsiMaList[i - 1] : 0; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; + decimal rsiMa = rsiMaList[i]; var signal = GetCompareSignal(rsi - rsiMa, prevRsi - prevRsiMa); signalsList.Add(signal); @@ -9295,17 +9295,17 @@ public static StockData CalculateRecursiveDifferenciator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal priorB = i >= length ? bList.ElementAtOrDefault(i - length) : 0; + decimal rsi = rsiList[i]; + decimal priorB = i >= length ? bList[i - length] : 0; decimal a = rsi / 100; - decimal prevBChg1 = i >= 1 ? bChgList.ElementAtOrDefault(i - 1) : a; - decimal prevBChg2 = i >= 2 ? bChgList.ElementAtOrDefault(i - 2) : 0; + decimal prevBChg1 = i >= 1 ? bChgList[i - 1] : a; + decimal prevBChg2 = i >= 2 ? bChgList[i - 2] : 0; decimal b = (alpha * a) + ((1 - alpha) * prevBChg1); - bList.Add(b); + bList.AddRounded(b); decimal bChg = b - priorB; - bChgList.Add(bChg); + bChgList.AddRounded(bChg); var signal = GetCompareSignal(bChg - prevBChg1, prevBChg1 - prevBChg2); signalsList.Add(signal); @@ -9338,12 +9338,12 @@ public static StockData CalculateRegressionOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentLinReg = linRegList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentLinReg = linRegList[i]; decimal prevRosc = roscList.LastOrDefault(); decimal rosc = currentLinReg != 0 ? 100 * ((currentValue / currentLinReg) - 1) : 0; - roscList.Add(rosc); + roscList.AddRounded(rosc); var signal = GetCompareSignal(rosc, prevRosc); signalsList.Add(signal); @@ -9377,24 +9377,24 @@ public static StockData CalculateRelativeDifferenceOfSquaresOscillator(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal a = currentValue > prevValue ? 1 : 0; - aList.Add(a); + aList.AddRounded(a); decimal d = currentValue < prevValue ? 1 : 0; - dList.Add(d); + dList.AddRounded(d); decimal n = currentValue == prevValue ? 1 : 0; - nList.Add(n); + nList.AddRounded(n); decimal prevRdos = rdosList.LastOrDefault(); decimal aSum = aList.TakeLastExt(length).Sum(); decimal dSum = dList.TakeLastExt(length).Sum(); decimal nSum = nList.TakeLastExt(length).Sum(); decimal rdos = aSum > 0 || dSum > 0 || nSum > 0 ? (Pow(aSum, 2) - Pow(dSum, 2)) / Pow(aSum + nSum + dSum, 2) : 0; - rdosList.Add(rdos); + rdosList.AddRounded(rdos); var signal = GetCompareSignal(rdos, prevRdos); signalsList.Add(signal); @@ -9433,11 +9433,11 @@ public static StockData CalculateRelativeSpreadStrength(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal fastEma = fastEmaList.ElementAtOrDefault(i); - decimal slowEma = slowEmaList.ElementAtOrDefault(i); + decimal fastEma = fastEmaList[i]; + decimal slowEma = slowEmaList[i]; decimal spread = fastEma - slowEma; - spreadList.Add(spread); + spreadList.AddRounded(spread); } stockData.CustomValuesList = spreadList; @@ -9445,9 +9445,9 @@ public static StockData CalculateRelativeSpreadStrength(this StockData stockData var rssList = GetMovingAverageList(stockData, maType, smoothLength, rsList); for (int i = 0; i < stockData.Count; i++) { - decimal rss = rssList.ElementAtOrDefault(i); - decimal prevRss1 = i >= 1 ? rssList.ElementAtOrDefault(i - 1) : 0; - decimal prevRss2 = i >= 2 ? rssList.ElementAtOrDefault(i - 2) : 0; + decimal rss = rssList[i]; + decimal prevRss1 = i >= 1 ? rssList[i - 1] : 0; + decimal prevRss2 = i >= 2 ? rssList[i - 2] : 0; var signal = GetRsiSignal(rss - prevRss1, prevRss1 - prevRss2, rss, prevRss1, 80, 20); signalsList.Add(signal); @@ -9492,12 +9492,12 @@ public static StockData CalculateRelativeStrength3DIndicator(this StockData stoc { for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSp = spInputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentSp = spInputList[i]; decimal prevR1 = r1List.LastOrDefault(); decimal r1 = currentSp != 0 ? currentValue / currentSp * 100 : prevR1; - r1List.Add(r1); + r1List.AddRounded(r1); } var fastMaList = GetMovingAverageList(stockData, maType, length3, r1List); @@ -9506,32 +9506,32 @@ public static StockData CalculateRelativeStrength3DIndicator(this StockData stoc var vSlowMaList = GetMovingAverageList(stockData, maType, length5, slowMaList); for (int i = 0; i < stockData.Count; i++) { - decimal fastMa = fastMaList.ElementAtOrDefault(i); - decimal medMa = medMaList.ElementAtOrDefault(i); - decimal slowMa = slowMaList.ElementAtOrDefault(i); - decimal vSlowMa = vSlowMaList.ElementAtOrDefault(i); + decimal fastMa = fastMaList[i]; + decimal medMa = medMaList[i]; + decimal slowMa = slowMaList[i]; + decimal vSlowMa = vSlowMaList[i]; decimal t1 = fastMa >= medMa && medMa >= slowMa && slowMa >= vSlowMa ? 10 : 0; decimal t2 = fastMa >= medMa && medMa >= slowMa && slowMa < vSlowMa ? 9 : 0; decimal t3 = fastMa < medMa && medMa >= slowMa && slowMa >= vSlowMa ? 9 : 0; decimal t4 = fastMa < medMa && medMa >= slowMa && slowMa < vSlowMa ? 5 : 0; decimal rs2 = t1 + t2 + t3 + t4; - rs2List.Add(rs2); + rs2List.AddRounded(rs2); } var rs2MaList = GetMovingAverageList(stockData, maType, length1, rs2List); for (int i = 0; i < stockData.Count; i++) { - decimal rs2 = rs2List.ElementAtOrDefault(i); - decimal rs2Ma = rs2MaList.ElementAtOrDefault(i); - decimal prevRs3_1 = i >= 1 ? rs3List.ElementAtOrDefault(i - 1) : 0; - decimal prevRs3_2 = i >= 2 ? rs3List.ElementAtOrDefault(i - 1) : 0; + decimal rs2 = rs2List[i]; + decimal rs2Ma = rs2MaList[i]; + decimal prevRs3_1 = i >= 1 ? rs3List[i - 1] : 0; + decimal prevRs3_2 = i >= 2 ? rs3List[i - 1] : 0; decimal x = rs2 >= 5 ? 1 : 0; - xList.Add(x); + xList.AddRounded(x); decimal rs3 = rs2 >= 5 || rs2 > rs2Ma ? xList.TakeLastExt(length4).Sum() / length4 * 100 : 0; - rs3List.Add(rs3); + rs3List.AddRounded(rs3); var signal = GetCompareSignal(rs3 - prevRs3_1, prevRs3_1 - prevRs3_2); signalsList.Add(signal); @@ -9568,19 +9568,19 @@ public static StockData CalculateRelativeVigorIndex(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevOpen1 = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh1 = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevOpen2 = i >= 2 ? openList.ElementAtOrDefault(i - 2) : 0; - decimal prevClose2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevHigh2 = i >= 2 ? highList.ElementAtOrDefault(i - 2) : 0; - decimal prevOpen3 = i >= 3 ? openList.ElementAtOrDefault(i - 3) : 0; - decimal prevClose3 = i >= 3 ? inputList.ElementAtOrDefault(i - 3) : 0; - decimal prevHigh3 = i >= 3 ? highList.ElementAtOrDefault(i - 3) : 0; + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevOpen1 = i >= 1 ? openList[i - 1] : 0; + decimal prevClose1 = i >= 1 ? inputList[i - 1] : 0; + decimal prevHigh1 = i >= 1 ? highList[i - 1] : 0; + decimal prevOpen2 = i >= 2 ? openList[i - 2] : 0; + decimal prevClose2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevHigh2 = i >= 2 ? highList[i - 2] : 0; + decimal prevOpen3 = i >= 3 ? openList[i - 3] : 0; + decimal prevClose3 = i >= 3 ? inputList[i - 3] : 0; + decimal prevHigh3 = i >= 3 ? highList[i - 3] : 0; decimal a = currentClose - currentOpen; decimal b = prevClose1 - prevOpen1; decimal c = prevClose2 - prevOpen2; @@ -9591,28 +9591,28 @@ public static StockData CalculateRelativeVigorIndex(this StockData stockData, Mo decimal h = prevHigh3 - prevOpen3; decimal numerator = (a + (2 * b) + (2 * c) + d) / 6; - numeratorList.Add(numerator); + numeratorList.AddRounded(numerator); decimal denominator = (e + (2 * f) + (2 * g) + h) / 6; - denominatorList.Add(denominator); + 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++) { - decimal numeratorAvg = numeratorAvgList.ElementAtOrDefault(i); - decimal denominatorAvg = denominatorAvgList.ElementAtOrDefault(i); - decimal k = i >= 1 ? rviList.ElementAtOrDefault(i - 1) : 0; - decimal l = i >= 2 ? rviList.ElementAtOrDefault(i - 2) : 0; - decimal m = i >= 3 ? rviList.ElementAtOrDefault(i - 3) : 0; + decimal numeratorAvg = numeratorAvgList[i]; + decimal denominatorAvg = denominatorAvgList[i]; + decimal k = i >= 1 ? rviList[i - 1] : 0; + decimal l = i >= 2 ? rviList[i - 2] : 0; + decimal m = i >= 3 ? rviList[i - 3] : 0; decimal rvi = denominatorAvg != 0 ? numeratorAvg / denominatorAvg : 0; - rviList.Add(rvi); + rviList.AddRounded(rvi); decimal prevSignalLine = signalLineList.LastOrDefault(); decimal signalLine = (rvi + (2 * k) + (2 * l) + m) / 6; - signalLineList.Add(signalLine); + signalLineList.AddRounded(signalLine); var signal = GetCompareSignal(rvi - signalLine, k - prevSignalLine); signalsList.Add(signal); @@ -9648,36 +9648,36 @@ public static StockData CalculateRepulse(this StockData stockData, MovingAvgType for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal prevOpen = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal lowestLow = lowestList[i]; + decimal highestHigh = highestList[i]; + decimal prevOpen = i >= 1 ? openList[i - 1] : 0; decimal bullPower = currentClose != 0 ? 100 * ((3 * currentClose) - (2 * lowestLow) - prevOpen) / currentClose : 0; - bullPowerList.Add(bullPower); + bullPowerList.AddRounded(bullPower); decimal bearPower = currentClose != 0 ? 100 * (prevOpen + (2 * highestHigh) - (3 * currentClose)) / currentClose : 0; - bearPowerList.Add(bearPower); + 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++) { - decimal bullPowerEma = bullPowerEmaList.ElementAtOrDefault(i); - decimal bearPowerEma = bearPowerEmaList.ElementAtOrDefault(i); + decimal bullPowerEma = bullPowerEmaList[i]; + decimal bearPowerEma = bearPowerEmaList[i]; decimal repulse = bullPowerEma - bearPowerEma; - repulseList.Add(repulse); + repulseList.AddRounded(repulse); } var repulseEmaList = GetMovingAverageList(stockData, maType, length, repulseList); for (int i = 0; i < stockData.Count; i++) { - decimal repulse = repulseList.ElementAtOrDefault(i); - decimal prevRepulse = i >= 1 ? repulseList.ElementAtOrDefault(i - 1) : 0; - decimal repulseEma = repulseEmaList.ElementAtOrDefault(i); - decimal prevRepulseEma = i >= 1 ? repulseEmaList.ElementAtOrDefault(i - 1) : 0; + decimal repulse = repulseList[i]; + decimal prevRepulse = i >= 1 ? repulseList[i - 1] : 0; + decimal repulseEma = repulseEmaList[i]; + decimal prevRepulseEma = i >= 1 ? repulseEmaList[i - 1] : 0; var signal = GetCompareSignal(repulse - repulseEma, prevRepulse - prevRepulseEma); signalsList.Add(signal); @@ -9711,16 +9711,16 @@ public static StockData CalculateRetrospectiveCandlestickChart(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevK1 = i >= 1 ? kList.ElementAtOrDefault(i - 1) : 0; - decimal prevK2 = i >= 2 ? kList.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal currentOpen = openList[i]; + decimal prevK1 = i >= 1 ? kList[i - 1] : 0; + decimal prevK2 = i >= 2 ? kList[i - 2] : 0; decimal absChg = Math.Abs(currentClose - prevClose); - absChgList.Add(absChg); + absChgList.AddRounded(absChg); var lbList = absChgList.TakeLastExt(length).ToList(); decimal highest = lbList.Max(); @@ -9728,9 +9728,9 @@ public static StockData CalculateRetrospectiveCandlestickChart(this StockData st decimal s = highest - lowest != 0 ? (absChg - lowest) / (highest - lowest) * 100 : 0; decimal weight = s / 100; - decimal prevC = i >= 1 ? cList.ElementAtOrDefault(i - 1) : currentClose; + decimal prevC = i >= 1 ? cList[i - 1] : currentClose; decimal c = (weight * currentClose) + ((1 - weight) * prevC); - cList.Add(c); + cList.AddRounded(c); decimal prevH = i >= 1 ? prevC : currentHigh; decimal h = (weight * currentHigh) + ((1 - weight) * prevH); @@ -9740,7 +9740,7 @@ public static StockData CalculateRetrospectiveCandlestickChart(this StockData st decimal o = (weight * currentOpen) + ((1 - weight) * prevO); decimal k = (c + h + l + o) / 4; - kList.Add(k); + kList.AddRounded(k); var signal = GetCompareSignal(k - prevK1, prevK1 - prevK2); signalsList.Add(signal); @@ -9773,23 +9773,23 @@ public static StockData CalculateRexOscillator(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal open = openList.ElementAtOrDefault(i); - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal close = inputList[i]; + decimal open = openList[i]; + decimal high = highList[i]; + decimal low = lowList[i]; decimal tvb = (3 * close) - (low + open + high); - tvbList.Add(tvb); + tvbList.AddRounded(tvb); } var roList = GetMovingAverageList(stockData, maType, length, tvbList); var roEmaList = GetMovingAverageList(stockData, maType, length, roList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal ro = roList.ElementAtOrDefault(j); - decimal roEma = roEmaList.ElementAtOrDefault(j); - decimal prevRo = j >= 1 ? roList.ElementAtOrDefault(j - 1) : 0; - decimal prevRoEma = j >= 1 ? roEmaList.ElementAtOrDefault(j - 1) : 0; + decimal ro = roList[i]; + decimal roEma = roEmaList[i]; + decimal prevRo = i >= 1 ? roList[i - 1] : 0; + decimal prevRoEma = i >= 1 ? roEmaList[i - 1] : 0; var signal = GetCompareSignal(ro - roEma, prevRo - prevRoEma); signalsList.Add(signal); @@ -9827,14 +9827,14 @@ public static StockData CalculateRobustWeightingOscillator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); var corr = GoodnessOfFit.R(indexList.TakeLastExt(length).Select(x => (double)x), tempList.TakeLastExt(length).Select(x => (double)x)); corr = IsValueNullOrInfinity(corr) ? 0 : corr; - corrList.Add((decimal)corr); + corrList.AddRounded((decimal)corr); } var smaList = GetMovingAverageList(stockData, maType, length, inputList); @@ -9844,25 +9844,25 @@ public static StockData CalculateRobustWeightingOscillator(this StockData stockD var indexStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal corr = corrList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal indexStdDev = indexStdDevList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal indexSma = indexSmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal corr = corrList[i]; + decimal stdDev = stdDevList[i]; + decimal indexStdDev = indexStdDevList[i]; + decimal sma = smaList[i]; + decimal indexSma = indexSmaList[i]; decimal a = indexStdDev != 0 ? corr * (stdDev / indexStdDev) : 0; decimal b = sma - (a * indexSma); decimal l = currentValue - a - (b * currentValue); - lList.Add(l); + lList.AddRounded(l); } var lSmaList = GetMovingAverageList(stockData, maType, length, lList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal l = lSmaList.ElementAtOrDefault(j); - decimal prevL1 = j >= 1 ? lSmaList.ElementAtOrDefault(j - 1) : 0; - decimal prevL2 = j >= 2 ? lSmaList.ElementAtOrDefault(j - 2) : 0; + decimal l = lSmaList[i]; + decimal prevL1 = i >= 1 ? lSmaList[i - 1] : 0; + decimal prevL2 = i >= 2 ? lSmaList[i - 2] : 0; var signal = GetCompareSignal(l - prevL1, prevL1 - prevL2); signalsList.Add(signal); @@ -9899,23 +9899,23 @@ public static StockData CalculateRSINGIndicator(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); + decimal high = highList[i]; + decimal low = lowList[i]; decimal range = high - low; - rangeList.Add(range); + rangeList.AddRounded(range); } stockData.CustomValuesList = rangeList; var stdevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal ma = maList.ElementAtOrDefault(i); - decimal stdev = stdevList.ElementAtOrDefault(i); - decimal range = rangeList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentVolume = volumeList[i]; + decimal ma = maList[i]; + decimal stdev = stdevList[i]; + decimal range = rangeList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal vwr = ma != 0 ? currentVolume / ma : 0; decimal blr = stdev != 0 ? range / stdev : 0; bool isUp = currentValue > prevValue; @@ -9924,23 +9924,23 @@ public static StockData CalculateRSINGIndicator(this StockData stockData, Moving decimal prevUpCount = upList.LastOrDefault(); decimal upCount = isEq ? 0 : isUp ? (prevUpCount <= 0 ? 1 : prevUpCount + 1) : (prevUpCount >= 0 ? -1 : prevUpCount - 1); - upList.Add(upCount); + upList.AddRounded(upCount); decimal prevDnCount = dnList.LastOrDefault(); decimal dnCount = isEq ? 0 : isDn ? (prevDnCount <= 0 ? 1 : prevDnCount + 1) : (prevDnCount >= 0 ? -1 : prevDnCount - 1); - dnList.Add(dnCount); + dnList.AddRounded(dnCount); decimal pmo = currentValue - prevValue; decimal rsing = vwr * blr * pmo; - rsingList.Add(rsing); + rsingList.AddRounded(rsing); } var rsingMaList = GetMovingAverageList(stockData, maType, length, rsingList); for (int i = 0; i < stockData.Count; i++) { - decimal rsing = rsingMaList.ElementAtOrDefault(i); - decimal prevRsing1 = i >= 1 ? rsingMaList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsing2 = i >= 2 ? rsingMaList.ElementAtOrDefault(i - 2) : 0; + decimal rsing = rsingMaList[i]; + decimal prevRsing1 = i >= 1 ? rsingMaList[i - 1] : 0; + decimal prevRsing2 = i >= 2 ? rsingMaList[i - 2] : 0; var signal = GetCompareSignal(rsing - prevRsing1, prevRsing1 - prevRsing2); signalsList.Add(signal); @@ -9981,25 +9981,25 @@ public static StockData CalculateRSMKIndicator(this StockData stockData, StockDa { for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal spValue = spInputList.ElementAtOrDefault(i); - decimal prevLogRatio = i >= length ? logRatioList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal spValue = spInputList[i]; + decimal prevLogRatio = i >= length ? logRatioList[i - length] : 0; decimal logRatio = spValue != 0 ? currentValue / spValue : 0; - logRatioList.Add(logRatio); + logRatioList.AddRounded(logRatio); decimal logDiff = logRatio - prevLogRatio; - logDiffList.Add(logDiff); + logDiffList.AddRounded(logDiff); } var logDiffEmaList = GetMovingAverageList(stockData, maType, smoothLength, logDiffList); for (int i = 0; i < stockData.Count; i++) { - decimal logDiffEma = logDiffEmaList.ElementAtOrDefault(i); + decimal logDiffEma = logDiffEmaList[i]; decimal prevRsmk = rsmkList.LastOrDefault(); decimal rsmk = logDiffEma * 100; - rsmkList.Add(rsmk); + rsmkList.AddRounded(rsmk); var signal = GetCompareSignal(rsmk, prevRsmk); signalsList.Add(signal); @@ -10036,20 +10036,20 @@ public static StockData CalculateRunningEquity(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = smaList[i]; decimal prevX = xList.LastOrDefault(); decimal x = Math.Sign(currentValue - sma); - xList.Add(x); + xList.AddRounded(x); decimal chgX = (currentValue - prevValue) * prevX; - chgXList.Add(chgX); + chgXList.AddRounded(chgX); decimal prevReq = reqList.LastOrDefault(); decimal req = chgXList.TakeLastExt(length).Sum(); - reqList.Add(req); + reqList.AddRounded(req); var signal = GetCompareSignal(req, prevReq); signalsList.Add(signal); @@ -10087,34 +10087,34 @@ public static StockData CalculateMassIndex(this StockData stockData, MovingAvgTy for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal highLow = currentHigh - currentLow; - highLowList.Add(highLow); + 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++) { - decimal firstEma = firstEmaList.ElementAtOrDefault(i); - decimal secondEma = secondEmaList.ElementAtOrDefault(i); + decimal firstEma = firstEmaList[i]; + decimal secondEma = secondEmaList[i]; decimal ratio = secondEma != 0 ? firstEma / secondEma : 0; - ratioList.Add(ratio); + ratioList.AddRounded(ratio); decimal massIndex = ratioList.TakeLastExt(length3).Sum(); - massIndexList.Add(massIndex); + massIndexList.AddRounded(massIndex); } var massIndexSignalList = GetMovingAverageList(stockData, maType, signalLength, massIndexList); for (int i = 0; i < stockData.Count; i++) { - decimal massIndex = massIndexList.ElementAtOrDefault(i); - decimal massIndexEma = massIndexSignalList.ElementAtOrDefault(i); - decimal prevMassIndex = i >= 1 ? massIndexList.ElementAtOrDefault(i - 1) : 0; - decimal prevMassIndexEma = i >= 1 ? massIndexSignalList.ElementAtOrDefault(i - 1) : 0; + decimal massIndex = massIndexList[i]; + decimal massIndexEma = massIndexSignalList[i]; + decimal prevMassIndex = i >= 1 ? massIndexList[i - 1] : 0; + decimal prevMassIndexEma = i >= 1 ? massIndexSignalList[i - 1] : 0; var signal = GetCompareSignal(massIndex - massIndexEma, prevMassIndex - prevMassIndexEma); signalsList.Add(signal); @@ -10154,45 +10154,45 @@ public static StockData CalculateMassThrustOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentVolume = volumeList[i]; decimal adv = currentValue > prevValue ? currentValue - prevValue : 0; - advList.Add(adv); + advList.AddRounded(adv); decimal dec = currentValue < prevValue ? prevValue - currentValue : 0; - decList.Add(dec); + decList.AddRounded(dec); decimal advSum = advList.TakeLastExt(length).Sum(); decimal decSum = decList.TakeLastExt(length).Sum(); decimal advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; - advVolList.Add(advVol); + advVolList.AddRounded(advVol); decimal decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; - decVolList.Add(decVol); + decVolList.AddRounded(decVol); decimal advVolSum = advVolList.TakeLastExt(length).Sum(); decimal decVolSum = decVolList.TakeLastExt(length).Sum(); decimal top = (advSum * advVolSum) - (decSum * decVolSum); - topList.Add(top); + topList.AddRounded(top); decimal bot = (advSum * advVolSum) + (decSum * decVolSum); - botList.Add(bot); + botList.AddRounded(bot); decimal mto = bot != 0 ? 100 * top / bot : 0; - mtoList.Add(mto); + mtoList.AddRounded(mto); } var mtoEmaList = GetMovingAverageList(stockData, maType, length, mtoList); for (int i = 0; i < stockData.Count; i++) { - decimal mto = mtoList.ElementAtOrDefault(i); - decimal mtoEma = mtoEmaList.ElementAtOrDefault(i); - decimal prevMto = i >= 1 ? mtoList.ElementAtOrDefault(i - 1) : 0; - decimal prevMtoEma = i >= 1 ? mtoEmaList.ElementAtOrDefault(i - 1) : 0; + decimal mto = mtoList[i]; + decimal mtoEma = mtoEmaList[i]; + decimal prevMto = i >= 1 ? mtoList[i - 1] : 0; + decimal prevMtoEma = i >= 1 ? mtoEmaList[i - 1] : 0; var signal = GetRsiSignal(mto - mtoEma, prevMto - prevMtoEma, mto, prevMto, 50, -50); signalsList.Add(signal); @@ -10228,21 +10228,21 @@ public static StockData CalculateMidpointOscillator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; decimal mo = hh - ll != 0 ? MinOrMax(100 * ((2 * currentValue) - hh - ll) / (hh - ll), 100, -100) : 0; - moList.Add(mo); + moList.AddRounded(mo); } var moEmaList = GetMovingAverageList(stockData, maType, signalLength, moList); for (int i = 0; i < stockData.Count; i++) { - decimal mo = moList.ElementAtOrDefault(i); - decimal moEma = moEmaList.ElementAtOrDefault(i); - decimal prevMo = i >= 1 ? moList.ElementAtOrDefault(i - 1) : 0; - decimal prevMoEma = i >= 1 ? moEmaList.ElementAtOrDefault(i - 1) : 0; + decimal mo = moList[i]; + decimal moEma = moEmaList[i]; + decimal prevMo = i >= 1 ? moList[i - 1] : 0; + decimal prevMoEma = i >= 1 ? moEmaList[i - 1] : 0; var signal = GetRsiSignal(mo - moEma, prevMo - prevMoEma, mo, prevMo, 70, -70); signalsList.Add(signal); @@ -10277,13 +10277,13 @@ public static StockData CalculateMorphedSineWave(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevS1 = i >= 1 ? sList.ElementAtOrDefault(i - 1) : 0; - decimal prevS2 = i >= 2 ? sList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevS1 = i >= 1 ? sList[i - 1] : 0; + decimal prevS2 = i >= 2 ? sList[i - 2] : 0; decimal c = (currentValue * power) + Sin(i / p); decimal s = c / power; - sList.Add(s); + sList.AddRounded(s); var signal = GetCompareSignal(s - prevS1, prevS1 - prevS2); signalsList.Add(signal); @@ -10314,16 +10314,16 @@ public static StockData CalculateMoveTracker(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevMt = mtList.LastOrDefault(); decimal mt = currentValue - prevValue; - mtList.Add(mt); + mtList.AddRounded(mt); decimal prevMtSignal = mtSignalList.LastOrDefault(); decimal mtSignal = mt - prevMt; - mtSignalList.Add(mtSignal); + mtSignalList.AddRounded(mtSignal); var signal = GetCompareSignal(mt - mtSignal, prevMt - prevMtSignal); signalsList.Add(signal); @@ -10356,14 +10356,14 @@ public static StockData CalculateMultiLevelIndicator(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal prevOpen = i >= length ? openList.ElementAtOrDefault(i - length) : 0; - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevZ1 = i >= 1 ? zList.ElementAtOrDefault(i - 1) : 0; - decimal prevZ2 = i >= 2 ? zList.ElementAtOrDefault(i - 2) : 0; + decimal prevOpen = i >= length ? openList[i - length] : 0; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; + decimal prevZ1 = i >= 1 ? zList[i - 1] : 0; + decimal prevZ2 = i >= 2 ? zList[i - 2] : 0; decimal z = (currentClose - currentOpen - (currentClose - prevOpen)) * factor; - zList.Add(z); + zList.AddRounded(z); var signal = GetRsiSignal(z - prevZ1, prevZ1 - prevZ2, z, prevZ1, 5, -5); signalsList.Add(signal); @@ -10401,38 +10401,38 @@ public static StockData CalculateModifiedGannHiloActivator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; decimal max = Math.Max(currentClose, currentOpen); decimal min = Math.Min(currentClose, currentOpen); decimal a = highestHigh - max; decimal b = min - lowestLow; decimal c = max + (a * mult); - cList.Add(c); + cList.AddRounded(c); decimal d = min - (b * mult); - dList.Add(d); + 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++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal f = fList.ElementAtOrDefault(i); - decimal e = eList.ElementAtOrDefault(i); + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal f = fList[i]; + decimal e = eList[i]; decimal prevG = gList.LastOrDefault(); decimal g = currentClose > e ? 1 : currentClose > f ? 0 : prevG; - gList.Add(g); + gList.AddRounded(g); decimal prevGannHilo = gannHiloList.LastOrDefault(); decimal gannHilo = (g * f) + ((1 - g) * e); - gannHiloList.Add(gannHilo); + gannHiloList.AddRounded(gannHilo); var signal = GetCompareSignal(currentClose - gannHilo, prevClose - prevGannHilo); signalsList.Add(signal); @@ -10466,20 +10466,20 @@ public static StockData CalculateMarketDirectionIndicator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal len1Sum = tempList.TakeLastExt(fastLength - 1).Sum(); decimal len2Sum = tempList.TakeLastExt(slowLength - 1).Sum(); decimal prevCp2 = cp2List.LastOrDefault(); decimal cp2 = ((fastLength * len2Sum) - (slowLength * len1Sum)) / (slowLength - fastLength); - cp2List.Add(cp2); + cp2List.AddRounded(cp2); decimal prevMdi = mdiList.LastOrDefault(); decimal mdi = currentValue + prevValue != 0 ? 100 * (prevCp2 - cp2) / ((currentValue + prevValue) / 2) : 0; - mdiList.Add(mdi); + mdiList.AddRounded(mdi); var signal = GetCompareSignal(mdi, prevMdi); signalsList.Add(signal); @@ -10515,9 +10515,9 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal hMax = highestList.ElementAtOrDefault(i); - decimal lMin = lowestList.ElementAtOrDefault(i); - decimal prevC = i >= length2 ? inputList.ElementAtOrDefault(i - length2) : 0; + decimal hMax = highestList[i]; + decimal lMin = lowestList[i]; + decimal prevC = i >= length2 ? inputList[i - length2] : 0; decimal rx = length1 != 0 ? (hMax - lMin) / length1 : 0; int imx = 1; @@ -10527,13 +10527,13 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo bu = lMin + (j * rx); bl = bu - rx; - decimal currHigh = i >= j ? highList.ElementAtOrDefault(i - j) : 0; - decimal currLow = i >= j ? lowList.ElementAtOrDefault(i - j) : 0; + decimal currHigh = i >= j ? highList[i - j] : 0; + decimal currLow = i >= j ? lowList[i - j] : 0; decimal hMax1 = currHigh, lMin1 = currLow; for (int k = 2; k < length2; k++) { - decimal high = i >= j + k ? highList.ElementAtOrDefault(i - (j + k)) : 0; - decimal low = i >= j + k ? lowList.ElementAtOrDefault(i - (j + k)) : 0; + decimal high = i >= j + k ? highList[i - (j + k)] : 0; + decimal low = i >= j + k ? lowList[i - (j + k)] : 0; hMax1 = Math.Max(high, hMax1); lMin1 = Math.Min(low, lMin1); } @@ -10545,8 +10545,8 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo pdf = 0; for (int k = 1; k <= length2; k++) { - decimal high = i >= j + k ? highList.ElementAtOrDefault(i - (j + k)) : 0; - decimal low = i >= j + k ? lowList.ElementAtOrDefault(i - (j + k)) : 0; + decimal high = i >= j + k ? highList[i - (j + k)] : 0; + decimal low = i >= j + k ? lowList[i - (j + k)] : 0; if (high <= bu1) { @@ -10591,10 +10591,10 @@ public static StockData CalculateMobilityOscillator(this StockData stockData, Mo var moSigList = GetMovingAverageList(stockData, maType, signalLength, moWmaList); for (int i = 0; i < stockData.Count; i++) { - decimal mo = moWmaList.ElementAtOrDefault(i); - decimal moSig = moSigList.ElementAtOrDefault(i); - decimal prevMo = i >= 1 ? moWmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevMoSig = i >= 1 ? moSigList.ElementAtOrDefault(i - 1) : 0; + decimal mo = moWmaList[i]; + decimal moSig = moSigList[i]; + decimal prevMo = i >= 1 ? moWmaList[i - 1] : 0; + decimal prevMoSig = i >= 1 ? moSigList[i - 1] : 0; var signal = GetCompareSignal(mo - moSig, prevMo - prevMoSig); signalsList.Add(signal); @@ -10632,37 +10632,37 @@ public static StockData CalculateMassThrustIndicator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentVolume = volumeList[i]; decimal adv = currentValue > prevValue ? currentValue - prevValue : 0; - advList.Add(adv); + advList.AddRounded(adv); decimal dec = currentValue < prevValue ? prevValue - currentValue : 0; - decList.Add(dec); + decList.AddRounded(dec); decimal advSum = advList.TakeLastExt(length).Sum(); decimal decSum = decList.TakeLastExt(length).Sum(); decimal advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; - advVolList.Add(advVol); + advVolList.AddRounded(advVol); decimal decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; - decVolList.Add(decVol); + decVolList.AddRounded(decVol); decimal advVolSum = advVolList.TakeLastExt(length).Sum(); decimal decVolSum = decVolList.TakeLastExt(length).Sum(); decimal mti = ((advSum * advVolSum) - (decSum * decVolSum)) / 1000000; - mtiList.Add(mti); + mtiList.AddRounded(mti); } var mtiEmaList = GetMovingAverageList(stockData, maType, length, mtiList); for (int i = 0; i < stockData.Count; i++) { - decimal mtiEma = mtiEmaList.ElementAtOrDefault(i); - decimal prevMtiEma = i >= 1 ? mtiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal mtiEma = mtiEmaList[i]; + decimal prevMtiEma = i >= 1 ? mtiEmaList[i - 1] : 0; var signal = GetCompareSignal(mtiEma, prevMtiEma); signalsList.Add(signal); @@ -10696,13 +10696,13 @@ public static StockData CalculateDecisionPointBreadthSwenlinTradingOscillator(th for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal advance = currentValue > prevValue ? 1 : 0; decimal decline = currentValue < prevValue ? 1 : 0; decimal iVal = advance + decline != 0 ? 1000 * (advance - decline) / (advance + decline) : 0; - iList.Add(iVal); + iList.AddRounded(iVal); } var ivalEmaList = GetMovingAverageList(stockData, maType, length, iList); @@ -10710,10 +10710,10 @@ public static StockData CalculateDecisionPointBreadthSwenlinTradingOscillator(th var stoEmaList = GetMovingAverageList(stockData, maType, length, stoList); for (int i = 0; i < stockData.Count; i++) { - decimal sto = stoList.ElementAtOrDefault(i); - decimal stoEma = stoEmaList.ElementAtOrDefault(i); - decimal prevSto = i >= 1 ? stoList.ElementAtOrDefault(i - 1) : 0; - decimal prevStoEma = i >= 1 ? stoEmaList.ElementAtOrDefault(i - 1) : 0; + decimal sto = stoList[i]; + decimal stoEma = stoEmaList[i]; + decimal prevSto = i >= 1 ? stoList[i - 1] : 0; + decimal prevStoEma = i >= 1 ? stoEmaList[i - 1] : 0; var signal = GetCompareSignal(sto - stoEma, prevSto - prevStoEma); signalsList.Add(signal); @@ -10749,22 +10749,22 @@ public static StockData CalculateDeltaMovingAverage(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevOpen = i >= length2 ? openList.ElementAtOrDefault(i - length2) : 0; + decimal currentClose = inputList[i]; + decimal prevOpen = i >= length2 ? openList[i - length2] : 0; decimal delta = currentClose - prevOpen; - deltaList.Add(delta); + deltaList.AddRounded(delta); } var deltaSmaList = GetMovingAverageList(stockData, maType, length1, deltaList); for (int i = 0; i < stockData.Count; i++) { - decimal delta = deltaList.ElementAtOrDefault(i); - decimal deltaSma = deltaSmaList.ElementAtOrDefault(i); + decimal delta = deltaList[i]; + decimal deltaSma = deltaSmaList[i]; decimal prevDeltaHistogram = deltaHistogramList.LastOrDefault(); decimal deltaHistogram = delta - deltaSma; - deltaHistogramList.Add(deltaHistogram); + deltaHistogramList.AddRounded(deltaHistogram); var signal = GetCompareSignal(deltaHistogram, prevDeltaHistogram); signalsList.Add(signal); @@ -10801,25 +10801,25 @@ public static StockData CalculateDetrendedSyntheticPrice(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal high = Math.Max(currentHigh, prevHigh); decimal low = Math.Min(currentLow, prevLow); decimal price = (high + low) / 2; - decimal prevEma1 = i >= 1 ? ema1List.ElementAtOrDefault(i - 1) : price; - decimal prevEma2 = i >= 1 ? ema2List.ElementAtOrDefault(i - 1) : price; + decimal prevEma1 = i >= 1 ? ema1List[i - 1] : price; + decimal prevEma2 = i >= 1 ? ema2List[i - 1] : price; decimal ema1 = (alpha * price) + ((1 - alpha) * prevEma1); - ema1List.Add(ema1); + ema1List.AddRounded(ema1); decimal ema2 = (alpha / 2 * price) + ((1 - (alpha / 2)) * prevEma2); - ema2List.Add(ema2); + ema2List.AddRounded(ema2); decimal prevDsp = dspList.LastOrDefault(); decimal dsp = ema1 - ema2; - dspList.Add(dsp); + dspList.AddRounded(dsp); var signal = GetCompareSignal(dsp, prevDsp); signalsList.Add(signal); @@ -10861,15 +10861,15 @@ public static StockData CalculateDerivativeOscillator(this StockData stockData, for (int i = 0; i < rsiList.Count; i++) { decimal prevS1 = s1List.LastOrDefault(); - decimal s1 = rsiEma2List.ElementAtOrDefault(i); - s1List.Add(s1); + decimal s1 = rsiEma2List[i]; + s1List.AddRounded(s1); decimal prevS1Sma = s1SmaList.LastOrDefault(); decimal s1Sma = s1List.TakeLastExt(length2).Average(); - s1SmaList.Add(s1Sma); + s1SmaList.AddRounded(s1Sma); decimal s2 = s1 - s1Sma; - s2List.Add(s2); + s2List.AddRounded(s2); var signal = GetCompareSignal(s1 - s1Sma, prevS1 - prevS1Sma); signalsList.Add(signal); @@ -10906,21 +10906,21 @@ public static StockData CalculateDemandOscillator(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal range = highest - lowest; - rangeList.Add(range); + rangeList.AddRounded(range); } var vaList = GetMovingAverageList(stockData, maType, length1, rangeList); for (int i = 0; i < stockData.Count; i++) { - decimal va = vaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal va = vaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal pctChg = prevValue != 0 ? (currentValue - prevValue) / Math.Abs(prevValue) * 100 : 0; - decimal currentVolume = stockData.Volumes.ElementAtOrDefault(i); + decimal currentVolume = stockData.Volumes[i]; decimal k = va != 0 ? (3 * currentValue) / va : 0; decimal pctK = pctChg * k; decimal volPctK = pctK != 0 ? currentVolume / pctK : 0; @@ -10928,16 +10928,16 @@ public static StockData CalculateDemandOscillator(this StockData stockData, Movi decimal sp = currentValue > prevValue ? volPctK : currentVolume; decimal dosc = bp - sp; - doList.Add(dosc); + 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++) { - decimal doSig = doSigList.ElementAtOrDefault(i); - decimal prevSig1 = i >= 1 ? doSigList.ElementAtOrDefault(i - 1) : 0; - decimal prevSig2 = i >= 2 ? doSigList.ElementAtOrDefault(i - 1) : 0; + decimal doSig = doSigList[i]; + decimal prevSig1 = i >= 1 ? doSigList[i - 1] : 0; + decimal prevSig2 = i >= 2 ? doSigList[i - 1] : 0; var signal = GetCompareSignal(doSig - prevSig1, prevSig1 - prevSig2); signalsList.Add(signal); @@ -10976,15 +10976,15 @@ public static StockData CalculateDoubleSmoothedMomenta(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal hc = highestList.ElementAtOrDefault(i); - decimal lc = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal hc = highestList[i]; + decimal lc = lowestList[i]; decimal srcLc = currentValue - lc; - srcLcList.Add(srcLc); + srcLcList.AddRounded(srcLc); decimal hcLc = hc - lc; - hcLcList.Add(hcLc); + hcLcList.AddRounded(hcLc); } var topEma1List = GetMovingAverageList(stockData, maType, length2, srcLcList); @@ -10993,20 +10993,20 @@ public static StockData CalculateDoubleSmoothedMomenta(this StockData stockData, var botEma2List = GetMovingAverageList(stockData, maType, length3, botEma1List); for (int i = 0; i < stockData.Count; i++) { - decimal top = topEma2List.ElementAtOrDefault(i); - decimal bot = botEma2List.ElementAtOrDefault(i); + decimal top = topEma2List[i]; + decimal bot = botEma2List[i]; decimal mom = bot != 0 ? MinOrMax(100 * top / bot, 100, 0) : 0; - momList.Add(mom); + momList.AddRounded(mom); } var momEmaList = GetMovingAverageList(stockData, maType, length3, momList); for (int i = 0; i < stockData.Count; i++) { - decimal mom = momList.ElementAtOrDefault(i); - decimal momEma = momEmaList.ElementAtOrDefault(i); - decimal prevMom = i >= 1 ? momList.ElementAtOrDefault(i - 1) : 0; - decimal prevMomEma = i >= 1 ? momEmaList.ElementAtOrDefault(i - 1) : 0; + decimal mom = momList[i]; + decimal momEma = momEmaList[i]; + decimal prevMom = i >= 1 ? momList[i - 1] : 0; + decimal prevMomEma = i >= 1 ? momEmaList[i - 1] : 0; var signal = GetCompareSignal(mom - momEma, prevMom - prevMomEma); signalsList.Add(signal); @@ -11047,17 +11047,17 @@ public static StockData CalculateDidiIndex(this StockData stockData, MovingAvgTy for (int i = 0; i < stockData.Count; i++) { - decimal mediumSma = mediumSmaList.ElementAtOrDefault(i); - decimal shortSma = shortSmaList.ElementAtOrDefault(i); - decimal longSma = longSmaList.ElementAtOrDefault(i); + decimal mediumSma = mediumSmaList[i]; + decimal shortSma = shortSmaList[i]; + decimal longSma = longSmaList[i]; decimal prevCurta = curtaList.LastOrDefault(); decimal curta = mediumSma != 0 ? shortSma / mediumSma : 0; - curtaList.Add(curta); + curtaList.AddRounded(curta); decimal prevLonga = longaList.LastOrDefault(); decimal longa = mediumSma != 0 ? longSma / mediumSma : 0; - longaList.Add(longa); + longaList.AddRounded(longa); var signal = GetCompareSignal(curta - longa, prevCurta - prevLonga); signalsList.Add(signal); @@ -11093,12 +11093,12 @@ public static StockData CalculateDisparityIndex(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; decimal prevDisparityIndex = disparityIndexList.LastOrDefault(); decimal disparityIndex = currentSma != 0 ? (currentValue - currentSma) / currentSma * 100 : 0; - disparityIndexList.Add(disparityIndex); + disparityIndexList.AddRounded(disparityIndex); var signal = GetCompareSignal(disparityIndex, prevDisparityIndex); signalsList.Add(signal); @@ -11135,25 +11135,25 @@ public static StockData CalculateDampingIndex(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal range = currentHigh - currentLow; - rangeList.Add(range); + rangeList.AddRounded(range); } var rangeSmaList = GetMovingAverageList(stockData, maType, length, rangeList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevSma1 = i >= 1 ? rangeSmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma6 = i >= 6 ? rangeSmaList.ElementAtOrDefault(i - 6) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; - decimal currentSma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevSma1 = i >= 1 ? rangeSmaList[i - 1] : 0; + decimal prevSma6 = i >= 6 ? rangeSmaList[i - 6] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; + decimal currentSma = smaList[i]; decimal di = prevSma6 != 0 ? prevSma1 / prevSma6 : 0; - diList.Add(di); + diList.AddRounded(di); var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, di, threshold); signalsList.Add(signal); @@ -11190,18 +11190,18 @@ public static StockData CalculateDirectionalTrendIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal hmu = currentHigh - prevHigh > 0 ? currentHigh - prevHigh : 0; decimal lmd = currentLow - prevLow < 0 ? (currentLow - prevLow) * -1 : 0; decimal diff = hmu - lmd; - diffList.Add(diff); + diffList.AddRounded(diff); decimal absDiff = Math.Abs(diff); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); } var diffEma1List = GetMovingAverageList(stockData, maType, length1, diffList); @@ -11212,13 +11212,13 @@ public static StockData CalculateDirectionalTrendIndex(this StockData stockData, var absDiffEma3List = GetMovingAverageList(stockData, maType, length3, absDiffEma2List); for (int i = 0; i < stockData.Count; i++) { - decimal diffEma3 = diffEma3List.ElementAtOrDefault(i); - decimal absDiffEma3 = absDiffEma3List.ElementAtOrDefault(i); - decimal prevDti1 = i >= 1 ? dtiList.ElementAtOrDefault(i - 1) : 0; - decimal prevDti2 = i >= 2 ? dtiList.ElementAtOrDefault(i - 2) : 0; + decimal diffEma3 = diffEma3List[i]; + decimal absDiffEma3 = absDiffEma3List[i]; + decimal prevDti1 = i >= 1 ? dtiList[i - 1] : 0; + decimal prevDti2 = i >= 2 ? dtiList[i - 2] : 0; decimal dti = absDiffEma3 != 0 ? MinOrMax(100 * diffEma3 / absDiffEma3, 100, -100) : 0; - dtiList.Add(dti); + dtiList.AddRounded(dti); var signal = GetRsiSignal(dti - prevDti1, prevDti1 - prevDti2, dti, prevDti1, 25, -25); signalsList.Add(signal); @@ -11256,15 +11256,15 @@ public static StockData CalculateDrunkardWalk(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - tempHighList.Add(currentHigh); + decimal currentHigh = highList[i]; + tempHighList.AddRounded(currentHigh); - decimal currentLow = lowList.ElementAtOrDefault(i); - tempLowList.Add(currentLow); + decimal currentLow = lowList[i]; + tempLowList.AddRounded(currentLow); decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); int maxIndex = tempHighList.LastIndexOf(highestHigh); @@ -11275,22 +11275,22 @@ public static StockData CalculateDrunkardWalk(this StockData stockData, int leng decimal prevAtrUp = upAtrList.LastOrDefault(); decimal upK = upRun != 0 ? (decimal)1 / upRun : 0; decimal atrUp = (tr * upK) + (prevAtrUp * (1 - upK)); - upAtrList.Add(atrUp); + upAtrList.AddRounded(atrUp); decimal prevAtrDn = dnAtrList.LastOrDefault(); var dnK = dnRun != 0 ? (decimal)1 / dnRun : 0; decimal atrDn = (tr * dnK) + (prevAtrDn * (1 - dnK)); - dnAtrList.Add(atrDn); + dnAtrList.AddRounded(atrDn); decimal upDen = atrUp > 0 ? atrUp : 1; decimal prevUpWalk = upwalkList.LastOrDefault(); decimal upWalk = upRun > 0 ? (currentHigh - lowestLow) / (Sqrt(upRun) * upDen) : 0; - upwalkList.Add(upWalk); + upwalkList.AddRounded(upWalk); decimal dnDen = atrDn > 0 ? atrDn : 1; decimal prevDnWalk = dnwalkList.LastOrDefault(); decimal dnWalk = dnRun > 0 ? (highestHigh - currentLow) / (Sqrt(dnRun) * dnDen) : 0; - dnwalkList.Add(dnWalk); + dnwalkList.AddRounded(dnWalk); var signal = GetCompareSignal(upWalk - dnWalk, prevUpWalk - prevDnWalk); signalsList.Add(signal); @@ -11332,20 +11332,20 @@ public static StockData CalculateDTOscillator(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal wima = wilderMovingAvgList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevSd1 = i >= 1 ? sdList.ElementAtOrDefault(i - 1) : 0; - decimal prevSd2 = i >= 2 ? sdList.ElementAtOrDefault(i - 2) : 0; + decimal wima = wilderMovingAvgList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevSd1 = i >= 1 ? sdList[i - 1] : 0; + decimal prevSd2 = i >= 2 ? sdList[i - 2] : 0; decimal stoRsi = highest - lowest != 0 ? MinOrMax(100 * (wima - lowest) / (highest - lowest), 100, 0) : 0; - stoRsiList.Add(stoRsi); + stoRsiList.AddRounded(stoRsi); decimal sk = stoRsiList.TakeLastExt(length3).Average(); - skList.Add(sk); + skList.AddRounded(sk); decimal sd = skList.TakeLastExt(length4).Average(); - sdList.Add(sd); + sdList.AddRounded(sd); var signal = GetRsiSignal(sd - prevSd1, prevSd1 - prevSd2, sd, prevSd1, 70, 30); signalsList.Add(signal); @@ -11382,28 +11382,28 @@ public static StockData CalculateSmoothedDeltaRatioOscillator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevSma = i >= length ? smaList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; + decimal sma = smaList[i]; + decimal prevSma = i >= length ? smaList[i - length] : 0; decimal absChg = Math.Abs(currentValue - prevValue); - absChgList.Add(absChg); + absChgList.AddRounded(absChg); decimal b = sma - prevSma; - bList.Add(b); + bList.AddRounded(b); } var aList = GetMovingAverageList(stockData, maType, length, absChgList); for (int i = 0; i < stockData.Count; i++) { - decimal a = aList.ElementAtOrDefault(i); - decimal b = bList.ElementAtOrDefault(i); - decimal prevC1 = i >= 1 ? cList.ElementAtOrDefault(i - 1) : 0; - decimal prevC2 = i >= 2 ? cList.ElementAtOrDefault(i - 2) : 0; + decimal a = aList[i]; + decimal b = bList[i]; + decimal prevC1 = i >= 1 ? cList[i - 1] : 0; + decimal prevC2 = i >= 2 ? cList[i - 2] : 0; decimal c = a != 0 ? MinOrMax(b / a, 1, 0) : 0; - cList.Add(c); + cList.AddRounded(c); var signal = GetRsiSignal(c - prevC1, prevC1 - prevC2, c, prevC1, 0.8m, 0.2m); signalsList.Add(signal); @@ -11433,17 +11433,17 @@ public static StockData CalculateSupportAndResistanceOscillator(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevClose); - decimal prevSro1 = i >= 1 ? sroList.ElementAtOrDefault(i - 1) : 0; - decimal prevSro2 = i >= 2 ? sroList.ElementAtOrDefault(i - 2) : 0; + decimal prevSro1 = i >= 1 ? sroList[i - 1] : 0; + decimal prevSro2 = i >= 2 ? sroList[i - 2] : 0; decimal sro = tr != 0 ? MinOrMax((currentHigh - currentOpen + (currentClose - currentLow)) / (2 * tr), 1, 0) : 0; - sroList.Add(sro); + sroList.AddRounded(sro); var signal = GetRsiSignal(sro - prevSro1, prevSro1 - prevSro2, sro, prevSro1, 0.7m, 0.3m); signalsList.Add(signal); @@ -11479,25 +11479,25 @@ public static StockData CalculateStationaryExtrapolatedLevelsOscillator(this Sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevY = i >= length ? yList.ElementAtOrDefault(i - length) : 0; - decimal prevY2 = i >= length * 2 ? yList.ElementAtOrDefault(i - (length * 2)) : 0; + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal prevY = i >= length ? yList[i - length] : 0; + decimal prevY2 = i >= length * 2 ? yList[i - (length * 2)] : 0; decimal y = currentValue - sma; - yList.Add(y); + yList.AddRounded(y); decimal ext = ((2 * prevY) - prevY2) / 2; - extList.Add(ext); + extList.AddRounded(ext); } stockData.CustomValuesList = extList; var oscList = CalculateStochasticOscillator(stockData, maType, length: length * 2).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal osc = oscList.ElementAtOrDefault(i); - decimal prevOsc1 = i >= 1 ? oscList.ElementAtOrDefault(i - 1) : 0; - decimal prevOsc2 = i >= 2 ? oscList.ElementAtOrDefault(i - 2) : 0; + decimal osc = oscList[i]; + decimal prevOsc1 = i >= 1 ? oscList[i - 1] : 0; + decimal prevOsc2 = i >= 2 ? oscList[i - 2] : 0; var signal = GetRsiSignal(osc - prevOsc1, prevOsc1 - prevOsc2, osc, prevOsc1, 80, 20); signalsList.Add(signal); @@ -11529,25 +11529,25 @@ public static StockData CalculateSellGravitationIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; decimal v1 = currentClose - currentOpen; decimal v2 = currentHigh - currentLow; decimal v3 = v2 != 0 ? v1 / v2 : 0; - v3List.Add(v3); + 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++) { - decimal sgi = sgiList.ElementAtOrDefault(i); - decimal sgiEma = sgiEmaList.ElementAtOrDefault(i); - decimal prevSgi = i >= 1 ? sgiList.ElementAtOrDefault(i - 1) : 0; - decimal prevSgiEma = i >= 1 ? sgiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal sgi = sgiList[i]; + decimal sgiEma = sgiEmaList[i]; + decimal prevSgi = i >= 1 ? sgiList[i - 1] : 0; + decimal prevSgiEma = i >= 1 ? sgiEmaList[i - 1] : 0; var signal = GetCompareSignal(sgi - sgiEma, prevSgi - prevSgiEma); signalsList.Add(signal); @@ -11584,13 +11584,13 @@ public static StockData CalculateStrengthOfMovement(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length2 - 1 ? inputList.ElementAtOrDefault(i - (length2 - 1)) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length2 - 1 ? inputList[i - (length2 - 1)] : 0; decimal moveSe = currentValue - prevValue; decimal avgMoveSe = moveSe / (length2 - 1); decimal aaSe = prevValue != 0 ? avgMoveSe / prevValue : 0; - aaSeList.Add(aaSe); + aaSeList.AddRounded(aaSe); } var bList = GetMovingAverageList(stockData, maType, length1, aaSeList); @@ -11598,17 +11598,17 @@ public static StockData CalculateStrengthOfMovement(this StockData stockData, Mo var stoList = CalculateStochasticOscillator(stockData, maType, length: length1).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal bSto = stoList.ElementAtOrDefault(i); + decimal bSto = stoList[i]; decimal sSe = (bSto * 2) - 100; - sSeList.Add(sSe); + sSeList.AddRounded(sSe); } var ssSeList = GetMovingAverageList(stockData, maType, smoothingLength, sSeList); for (int i = 0; i < stockData.Count; i++) { - decimal ssSe = ssSeList.ElementAtOrDefault(i); - decimal prevSsse = i >= 1 ? ssSeList.ElementAtOrDefault(i - 1) : 0; + decimal ssSe = ssSeList[i]; + decimal prevSsse = i >= 1 ? ssSeList[i - 1] : 0; var signal = GetCompareSignal(ssSe, prevSsse); signalsList.Add(signal); @@ -11643,24 +11643,24 @@ public static StockData CalculateSpearmanIndicator(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); var enumerableList = tempList.TakeLastExt(length).Select(x => (double)x); var orderedList = enumerableList.AsQueryExpr().OrderBy(j => j).Run(); var sc = Correlation.Spearman(enumerableList, orderedList); sc = IsValueNullOrInfinity(sc) ? 0 : sc; - coefCorrList.Add((decimal)sc * 100); + coefCorrList.AddRounded((decimal)sc * 100); } var sigList = GetMovingAverageList(stockData, maType, signalLength, coefCorrList); for (int i = 0; i < stockData.Count; i++) { - decimal sc = coefCorrList.ElementAtOrDefault(i); - decimal prevSc = i >= 1 ? coefCorrList.ElementAtOrDefault(i - 1) : 0; - decimal sig = sigList.ElementAtOrDefault(i); - decimal prevSig = i >= 1 ? sigList.ElementAtOrDefault(i - 1) : 0; + decimal sc = coefCorrList[i]; + decimal prevSc = i >= 1 ? coefCorrList[i - 1] : 0; + decimal sig = sigList[i]; + decimal prevSig = i >= 1 ? sigList[i - 1] : 0; var signal = GetCompareSignal(sc - sig, prevSc - prevSig); signalsList.Add(signal); @@ -11695,10 +11695,10 @@ public static StockData CalculateSmoothedWilliamsAccumulationDistribution(this S for (int i = 0; i < stockData.Count; i++) { - decimal wad = wadList.ElementAtOrDefault(i); - decimal wadSma = wadSignalList.ElementAtOrDefault(i); - decimal prevWad = i >= 1 ? wadList.ElementAtOrDefault(i - 1) : 0; - decimal prevWadSma = i >= 1 ? wadSignalList.ElementAtOrDefault(i - 1) : 0; + decimal wad = wadList[i]; + decimal wadSma = wadSignalList[i]; + decimal prevWad = i >= 1 ? wadList[i - 1] : 0; + decimal prevWadSma = i >= 1 ? wadSignalList[i - 1] : 0; var signal = GetCompareSignal(wad - wadSma, prevWad - prevWadSma); signalsList.Add(signal); @@ -11735,13 +11735,13 @@ public static StockData CalculateSmoothedRateOfChange(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentMa = maList.ElementAtOrDefault(i); - decimal prevMa = i >= length ? maList.ElementAtOrDefault(i - length) : 0; + decimal currentMa = maList[i]; + decimal prevMa = i >= length ? maList[i - length] : 0; decimal mom = currentMa - prevMa; decimal prevSroc = srocList.LastOrDefault(); decimal sroc = prevMa != 0 ? 100 * mom / prevMa : 100; - srocList.Add(sroc); + srocList.AddRounded(sroc); var signal = GetCompareSignal(sroc, prevSroc); signalsList.Add(signal); @@ -11777,33 +11777,33 @@ public static StockData CalculateSentimentZoneOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal r = currentValue > prevValue ? 1 : -1; - rList.Add(r); + rList.AddRounded(r); } var spList = GetMovingAverageList(stockData, maType, fastLength, rList); for (int i = 0; i < stockData.Count; i++) { - decimal sp = spList.ElementAtOrDefault(i); + decimal sp = spList[i]; decimal szo = fastLength != 0 ? 100 * sp / fastLength : 0; - szoList.Add(szo); + szoList.AddRounded(szo); } var (highestList, lowestList) = GetMaxAndMinValuesList(szoList, slowLength); for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal range = highest - lowest; decimal ob = lowest + (range * factor); decimal os = highest - (range * factor); - decimal szo = szoList.ElementAtOrDefault(i); - decimal prevSzo1 = i >= 1 ? szoList.ElementAtOrDefault(i - 1) : 0; - decimal prevSzo2 = i >= 2 ? szoList.ElementAtOrDefault(i - 2) : 0; + decimal szo = szoList[i]; + decimal prevSzo1 = i >= 1 ? szoList[i - 1] : 0; + decimal prevSzo2 = i >= 2 ? szoList[i - 2] : 0; var signal = GetRsiSignal(szo - prevSzo1, prevSzo1 - prevSzo2, szo, prevSzo1, ob, os, true); signalsList.Add(signal); @@ -11838,20 +11838,20 @@ public static StockData CalculateSimpleCycle(this StockData stockData, int lengt for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevC1 = i >= 1 ? cList.ElementAtOrDefault(i - 1) : 0; - decimal prevC2 = i >= 2 ? cList.ElementAtOrDefault(i - 2) : 0; - decimal prevSrc = i >= length ? srcList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevC1 = i >= 1 ? cList[i - 1] : 0; + decimal prevC2 = i >= 2 ? cList[i - 2] : 0; + decimal prevSrc = i >= length ? srcList[i - length] : 0; decimal src = currentValue + prevC1; - srcList.Add(src); + srcList.AddRounded(src); decimal cEma = CalculateEMA(prevC1, cEmaList.LastOrDefault(), length); - cEmaList.Add(cEma); + cEmaList.AddRounded(cEma); decimal b = prevC1 - cEma; decimal c = (a * (src - prevSrc)) + ((1 - a) * b); - cList.Add(c); + cList.AddRounded(c); var signal = GetCompareSignal(c - prevC1, prevC1 - prevC2); signalsList.Add(signal); @@ -11891,24 +11891,24 @@ public static StockData CalculateStiffnessIndicator(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal stdDev = stdDevList[i]; decimal bound = sma - (0.2m * stdDev); decimal above = currentValue > bound ? 1 : 0; - aboveList.Add(above); + aboveList.AddRounded(above); decimal aboveSum = aboveList.TakeLastExt(length2).Sum(); decimal stiffValue = length2 != 0 ? aboveSum * 100 / length2 : 0; - stiffValueList.Add(stiffValue); + stiffValueList.AddRounded(stiffValue); } var stiffnessList = GetMovingAverageList(stockData, MovingAvgType.ExponentialMovingAverage, smoothingLength, stiffValueList); for (int i = 0; i < stockData.Count; i++) { - decimal stiffness = stiffnessList.ElementAtOrDefault(i); - decimal prevStiffness = i >= 1 ? stiffnessList.ElementAtOrDefault(i - 1) : 0; + decimal stiffness = stiffnessList[i]; + decimal prevStiffness = i >= 1 ? stiffnessList[i - 1] : 0; var signal = GetCompareSignal(stiffness - threshold, prevStiffness - threshold); signalsList.Add(signal); @@ -11947,36 +11947,36 @@ public static StockData CalculateSuperTrendFilter(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevTsl1 = i >= 1 ? tslList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevTsl2 = i >= 2 ? tslList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevTsl1 = i >= 1 ? tslList[i - 1] : currentValue; + decimal prevTsl2 = i >= 2 ? tslList[i - 2] : 0; decimal d = Math.Abs(currentValue - prevTsl1); - decimal prevT = i >= 1 ? tList.ElementAtOrDefault(i - 1) : d; + decimal prevT = i >= 1 ? tList[i - 1] : d; decimal t = (a * d) + ((1 - a) * prevT); - tList.Add(t); + tList.AddRounded(t); decimal prevSrc = srcList.LastOrDefault(); decimal src = (factor * prevTsl1) + ((1 - factor) * currentValue); - srcList.Add(src); + srcList.AddRounded(src); decimal up = prevTsl1 - t; decimal dn = prevTsl1 + t; decimal prevTrendUp = trendUpList.LastOrDefault(); decimal trendUp = prevSrc > prevTrendUp ? Math.Max(up, prevTrendUp) : up; - trendUpList.Add(trendUp); + trendUpList.AddRounded(trendUp); decimal prevTrendDn = trendDnList.LastOrDefault(); decimal trendDn = prevSrc < prevTrendDn ? Math.Min(dn, prevTrendDn) : dn; - trendDnList.Add(trendDn); + trendDnList.AddRounded(trendDn); - decimal prevTrend = i >= 1 ? trendList.ElementAtOrDefault(i - 1) : 1; + decimal prevTrend = i >= 1 ? trendList[i - 1] : 1; decimal trend = src > prevTrendDn ? 1 : src < prevTrendUp ? -1 : prevTrend; - trendList.Add(trend); + trendList.AddRounded(trend); decimal tsl = trend == 1 ? trendDn : trendUp; - tslList.Add(tsl); + tslList.AddRounded(tsl); var signal = GetCompareSignal(tsl - prevTsl1, prevTsl1 - prevTsl2); signalsList.Add(signal); @@ -12013,14 +12013,14 @@ public static StockData CalculateSMIErgodicIndicator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal pc = currentValue - prevValue; - pcList.Add(pc); + pcList.AddRounded(pc); decimal absPC = Math.Abs(currentValue - prevValue); - absPCList.Add(absPC); + absPCList.AddRounded(absPC); } var pcSmooth1List = GetMovingAverageList(stockData, maType, fastLength, pcList); @@ -12029,20 +12029,20 @@ public static StockData CalculateSMIErgodicIndicator(this StockData stockData, M var absPCSmooth2List = GetMovingAverageList(stockData, maType, slowLength, absPCSmooth1List); for (int i = 0; i < stockData.Count; i++) { - decimal absSmooth2PC = absPCSmooth2List.ElementAtOrDefault(i); - decimal smooth2PC = pcSmooth2List.ElementAtOrDefault(i); + decimal absSmooth2PC = absPCSmooth2List[i]; + decimal smooth2PC = pcSmooth2List[i]; decimal smi = absSmooth2PC != 0 ? MinOrMax(100 * smooth2PC / absSmooth2PC, 100, -100) : 0; - smiList.Add(smi); + smiList.AddRounded(smi); } var smiSignalList = GetMovingAverageList(stockData, maType, signalLength, smiList); for (int i = 0; i < stockData.Count; i++) { - decimal smi = smiList.ElementAtOrDefault(i); - decimal smiSignal = smiSignalList.ElementAtOrDefault(i); - decimal prevSmi = i >= 1 ? smiList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmiSignal = i >= 1 ? smiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal smi = smiList[i]; + decimal smiSignal = smiSignalList[i]; + decimal prevSmi = i >= 1 ? smiList[i - 1] : 0; + decimal prevSmiSignal = i >= 1 ? smiSignalList[i - 1] : 0; var signal = GetRsiSignal(smi - smiSignal, prevSmi - prevSmiSignal, smi, prevSmi, 10, -10); signalsList.Add(signal); @@ -12077,14 +12077,14 @@ public static StockData CalculateSimpleLines(this StockData stockData, int lengt for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : currentValue; + decimal currentValue = inputList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; + decimal prevA2 = i >= 2 ? aList[i - 2] : currentValue; decimal x = currentValue + ((prevA - prevA2) * mult); - prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : x; + prevA = i >= 1 ? aList[i - 1] : x; decimal a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; - aList.Add(a); + aList.AddRounded(a); var signal = GetCompareSignal(a - prevA, prevA - prevA2); signalsList.Add(signal); @@ -12125,23 +12125,23 @@ public static StockData CalculateSectorRotationModel(this StockData stockData, S for (int i = 0; i < stockData.Count; i++) { - decimal bull1 = bull1List.ElementAtOrDefault(i); - decimal bull2 = bull2List.ElementAtOrDefault(i); - decimal bear1 = bear1List.ElementAtOrDefault(i); - decimal bear2 = bear2List.ElementAtOrDefault(i); + decimal bull1 = bull1List[i]; + decimal bull2 = bull2List[i]; + decimal bear1 = bear1List[i]; + decimal bear2 = bear2List[i]; decimal bull = (bull1 + bull2) / 2; decimal bear = (bear1 + bear2) / 2; decimal osc = 100 * (bull - bear); - oscList.Add(osc); + oscList.AddRounded(osc); } var oscEmaList = GetMovingAverageList(stockData, maType, length1, oscList); - for (int j = 0; j < stockData.Count; j++) + for (int i = 0; i < stockData.Count; i++) { - decimal oscEma = oscEmaList.ElementAtOrDefault(j); - decimal prevOscEma1 = j >= 1 ? oscEmaList.ElementAtOrDefault(j - 1) : 0; - decimal prevOscEma2 = j >= 2 ? oscEmaList.ElementAtOrDefault(j - 2) : 0; + decimal oscEma = oscEmaList[i]; + decimal prevOscEma1 = i >= 1 ? oscEmaList[i - 1] : 0; + decimal prevOscEma2 = i >= 2 ? oscEmaList[i - 2] : 0; var signal = GetCompareSignal(oscEma - prevOscEma1, prevOscEma1 - prevOscEma2); signalsList.Add(signal); @@ -12185,31 +12185,31 @@ public static StockData CalculateEnhancedWilliamsR(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal maxVol = highestList2.ElementAtOrDefault(i); - decimal minVol = lowestList2.ElementAtOrDefault(i); - decimal maxSrc = highestList1.ElementAtOrDefault(i); - decimal minSrc = lowestList1.ElementAtOrDefault(i); - decimal srcSma = srcSmaList.ElementAtOrDefault(i); - decimal volSma = volSmaList.ElementAtOrDefault(i); - decimal volume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal maxVol = highestList2[i]; + decimal minVol = lowestList2[i]; + decimal maxSrc = highestList1[i]; + decimal minSrc = lowestList1[i]; + decimal srcSma = srcSmaList[i]; + decimal volSma = volSmaList[i]; + decimal volume = volumeList[i]; decimal volWr = maxVol - minVol != 0 ? 2 * ((volume - volSma) / (maxVol - minVol)) : 0; decimal srcWr = maxSrc - minSrc != 0 ? 2 * ((currentValue - srcSma) / (maxSrc - minSrc)) : 0; decimal srcSwr = maxSrc - minSrc != 0 ? 2 * ((currentValue - prevValue) / (maxSrc - minSrc)) : 0; decimal 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.Add(ewr); + ewrList.AddRounded(ewr); } var ewrSignalList = GetMovingAverageList(stockData, maType, signalLength, ewrList); for (int i = 0; i < stockData.Count; i++) { - decimal ewr = ewrList.ElementAtOrDefault(i); - decimal ewrSignal = ewrSignalList.ElementAtOrDefault(i); - decimal prevEwr = i >= 1 ? ewrList.ElementAtOrDefault(i - 1) : 0; - decimal prevEwrSignal = i >= 1 ? ewrSignalList.ElementAtOrDefault(i - 1) : 0; + decimal ewr = ewrList[i]; + decimal ewrSignal = ewrSignalList[i]; + decimal prevEwr = i >= 1 ? ewrList[i - 1] : 0; + decimal prevEwrSignal = i >= 1 ? ewrSignalList[i - 1] : 0; var signal = GetRsiSignal(ewr - ewrSignal, prevEwr - prevEwrSignal, ewr, prevEwr, 100, -100); signalsList.Add(signal); @@ -12242,20 +12242,20 @@ public static StockData CalculateEarningSupportResistanceLevels(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? closeList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue2 = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; - decimal prevValue1 = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal prevClose = i >= 1 ? closeList[i - 1] : 0; + decimal prevLow = i >= 2 ? lowList[i - 2] : 0; + decimal prevValue2 = i >= 2 ? inputList[i - 2] : 0; + decimal prevValue1 = i >= 1 ? inputList[i - 1] : 0; decimal prevMode1 = mode1List.LastOrDefault(); decimal mode1 = (prevLow + currentHigh) / 2; - mode1List.Add(mode1); + mode1List.AddRounded(mode1); decimal prevMode2 = mode2List.LastOrDefault(); decimal mode2 = (prevValue2 + currentValue + prevClose) / 3; - mode2List.Add(mode2); + mode2List.AddRounded(mode2); var signal = GetBullishBearishSignal(currentValue - Math.Max(mode1, mode2), prevValue1 - Math.Max(prevMode1, prevMode2), currentValue - Math.Min(mode1, mode2), prevValue1 - Math.Min(prevMode1, prevMode2)); @@ -12290,25 +12290,25 @@ public static StockData CalculateElderMarketThermometer(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal emt = currentHigh < prevHigh && currentLow > prevLow ? 0 : currentHigh - prevHigh > prevLow - currentLow ? Math.Abs(currentHigh - prevHigh) : Math.Abs(prevLow - currentLow); - emtList.Add(emt); + emtList.AddRounded(emt); } var aemtList = GetMovingAverageList(stockData, maType, length, emtList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal emt = emtList.ElementAtOrDefault(i); - decimal emtEma = aemtList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal emt = emtList[i]; + decimal emtEma = aemtList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, emt, emtEma); signalsList.Add(signal); @@ -12347,22 +12347,22 @@ public static StockData CalculateElliottWaveOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentSma5 = smaList.ElementAtOrDefault(i); - decimal currentSma34 = sma34List.ElementAtOrDefault(i); + decimal currentSma5 = smaList[i]; + decimal currentSma34 = sma34List[i]; decimal ewo = currentSma5 - currentSma34; - ewoList.Add(ewo); + ewoList.AddRounded(ewo); } var ewoSignalLineList = GetMovingAverageList(stockData, maType, fastLength, ewoList); for (int i = 0; i < stockData.Count; i++) { - decimal ewo = ewoList.ElementAtOrDefault(i); - decimal ewoSignalLine = ewoSignalLineList.ElementAtOrDefault(i); + decimal ewo = ewoList[i]; + decimal ewoSignalLine = ewoSignalLineList[i]; decimal prevEwoHistogram = ewoHistogramList.LastOrDefault(); decimal ewoHistogram = ewo - ewoSignalLine; - ewoHistogramList.Add(ewoHistogram); + ewoHistogramList.AddRounded(ewoHistogram); var signal = GetCompareSignal(ewoHistogram, prevEwoHistogram); signalsList.Add(signal); @@ -12400,16 +12400,16 @@ public static StockData CalculateErgodicCandlestickOscillator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; decimal xco = currentClose - currentOpen; - xcoList.Add(xco); + xcoList.AddRounded(xco); decimal xhl = currentHigh - currentLow; - xhlList.Add(xhl); + xhlList.AddRounded(xhl); } var xcoEma1List = GetMovingAverageList(stockData, maType, length1, xcoList); @@ -12418,20 +12418,20 @@ public static StockData CalculateErgodicCandlestickOscillator(this StockData sto var xhlEma2List = GetMovingAverageList(stockData, maType, length2, xhlEma1List); for (int i = 0; i < stockData.Count; i++) { - decimal xhlEma2 = xhlEma2List.ElementAtOrDefault(i); - decimal xcoEma2 = xcoEma2List.ElementAtOrDefault(i); + decimal xhlEma2 = xhlEma2List[i]; + decimal xcoEma2 = xcoEma2List[i]; decimal eco = xhlEma2 != 0 ? 100 * xcoEma2 / xhlEma2 : 0; - ecoList.Add(eco); + ecoList.AddRounded(eco); } var ecoSignalList = GetMovingAverageList(stockData, maType, length2, ecoList); for (int i = 0; i < stockData.Count; i++) { - decimal eco = ecoList.ElementAtOrDefault(i); - decimal ecoEma = ecoSignalList.ElementAtOrDefault(i); - decimal prevEco = i >= 1 ? ecoList.ElementAtOrDefault(i - 1) : 0; - decimal prevEcoEma = i >= 1 ? ecoSignalList.ElementAtOrDefault(i - 1) : 0; + decimal eco = ecoList[i]; + decimal ecoEma = ecoSignalList[i]; + decimal prevEco = i >= 1 ? ecoList[i - 1] : 0; + decimal prevEcoEma = i >= 1 ? ecoSignalList[i - 1] : 0; var signal = GetCompareSignal(eco - ecoEma, prevEco - prevEcoEma); signalsList.Add(signal); @@ -12470,14 +12470,14 @@ public static StockData CalculateErgodicTrueStrengthIndexV1(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal priceDiff = currentValue - prevValue; - priceDiffList.Add(priceDiff); + priceDiffList.AddRounded(priceDiff); decimal absPriceDiff = Math.Abs(priceDiff); - absPriceDiffList.Add(absPriceDiff); + absPriceDiffList.AddRounded(absPriceDiff); } var diffEma1List = GetMovingAverageList(stockData, maType, length1, priceDiffList); @@ -12488,20 +12488,20 @@ public static StockData CalculateErgodicTrueStrengthIndexV1(this StockData stock var absDiffEma3List = GetMovingAverageList(stockData, maType, length3, absDiffEma2List); for (int i = 0; i < stockData.Count; i++) { - decimal diffEma3 = diffEma3List.ElementAtOrDefault(i); - decimal absDiffEma3 = absDiffEma3List.ElementAtOrDefault(i); + decimal diffEma3 = diffEma3List[i]; + decimal absDiffEma3 = absDiffEma3List[i]; decimal etsi = absDiffEma3 != 0 ? MinOrMax(100 * diffEma3 / absDiffEma3, 100, -100) : 0; - etsiList.Add(etsi); + etsiList.AddRounded(etsi); } var etsiSignalList = GetMovingAverageList(stockData, maType, signalLength, etsiList); - for (int k = 0; k < stockData.Count; k++) + for (int i = 0; i < stockData.Count; i++) { - decimal etsi = etsiList.ElementAtOrDefault(k); - decimal etsiSignal = etsiSignalList.ElementAtOrDefault(k); - decimal prevEtsi = k >= 1 ? etsiList.ElementAtOrDefault(k - 1) : 0; - decimal prevEtsiSignal = k >= 1 ? etsiSignalList.ElementAtOrDefault(k - 1) : 0; + decimal etsi = etsiList[i]; + decimal etsiSignal = etsiSignalList[i]; + decimal prevEtsi = i >= 1 ? etsiList[i - 1] : 0; + decimal prevEtsiSignal = i >= 1 ? etsiSignalList[i - 1] : 0; var signal = GetCompareSignal(etsi - etsiSignal, prevEtsi - prevEtsiSignal); signalsList.Add(signal); @@ -12544,14 +12544,14 @@ public static StockData CalculateErgodicTrueStrengthIndexV2(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal priceDiff = currentValue - prevValue; - priceDiffList.Add(priceDiff); + priceDiffList.AddRounded(priceDiff); decimal absPriceDiff = Math.Abs(currentValue - prevValue); - absPriceDiffList.Add(absPriceDiff); + absPriceDiffList.AddRounded(absPriceDiff); } var diffEma1List = GetMovingAverageList(stockData, maType, length1, priceDiffList); @@ -12568,25 +12568,25 @@ public static StockData CalculateErgodicTrueStrengthIndexV2(this StockData stock var absDiffEma6List = GetMovingAverageList(stockData, maType, length6, absDiffEma5List); for (int i = 0; i < stockData.Count; i++) { - decimal diffEma6 = diffEma6List.ElementAtOrDefault(i); - decimal absDiffEma6 = absDiffEma6List.ElementAtOrDefault(i); - decimal diffEma3 = diffEma3List.ElementAtOrDefault(i); - decimal absDiffEma3 = absDiffEma3List.ElementAtOrDefault(i); + decimal diffEma6 = diffEma6List[i]; + decimal absDiffEma6 = absDiffEma6List[i]; + decimal diffEma3 = diffEma3List[i]; + decimal absDiffEma3 = absDiffEma3List[i]; decimal etsi1 = absDiffEma3 != 0 ? MinOrMax(diffEma3 / absDiffEma3 * 100, 100, -100) : 0; - etsi1List.Add(etsi1); + etsi1List.AddRounded(etsi1); decimal etsi2 = absDiffEma6 != 0 ? MinOrMax(diffEma6 / absDiffEma6 * 100, 100, -100) : 0; - etsi2List.Add(etsi2); + etsi2List.AddRounded(etsi2); } var etsi2SignalList = GetMovingAverageList(stockData, maType, signalLength, etsi2List); - for (int k = 0; k < stockData.Count; k++) + for (int i = 0; i < stockData.Count; i++) { - decimal etsi2 = etsi2List.ElementAtOrDefault(k); - decimal etsi2Signal = etsi2SignalList.ElementAtOrDefault(k); - decimal prevEtsi2 = k >= 1 ? etsi2List.ElementAtOrDefault(k - 1) : 0; - decimal prevEtsi2Signal = k >= 1 ? etsi2SignalList.ElementAtOrDefault(k - 1) : 0; + decimal etsi2 = etsi2List[i]; + decimal etsi2Signal = etsi2SignalList[i]; + decimal prevEtsi2 = i >= 1 ? etsi2List[i - 1] : 0; + decimal prevEtsi2Signal = i >= 1 ? etsi2SignalList[i - 1] : 0; var signal = GetCompareSignal(etsi2 - etsi2Signal, prevEtsi2 - prevEtsi2Signal); signalsList.Add(signal); @@ -12627,26 +12627,26 @@ public static StockData CalculateErgodicCommoditySelectionIndex(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal adx = adxList.ElementAtOrDefault(i); - decimal prevAdx = i >= 1 ? adxList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = inputList[i]; + decimal adx = adxList[i]; + decimal prevAdx = i >= 1 ? adxList[i - 1] : 0; decimal adxR = (adx + prevAdx) * 0.5m; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); decimal csi = length + tr > 0 ? k * adxR * tr / length : 0; decimal ergodicCsi = currentValue > 0 ? csi / currentValue : 0; - ergodicCsiList.Add(ergodicCsi); + ergodicCsiList.AddRounded(ergodicCsi); } var ergodicCsiSmaList = GetMovingAverageList(stockData, maType, smoothLength, ergodicCsiList); for (int i = 0; i < stockData.Count; i++) { - decimal ergodicCsiSma = ergodicCsiSmaList.ElementAtOrDefault(i); - decimal prevErgodicCsiSma1 = i >= 1 ? ergodicCsiSmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevErgodicCsiSma2 = i >= 2 ? ergodicCsiSmaList.ElementAtOrDefault(i - 2) : 0; + decimal ergodicCsiSma = ergodicCsiSmaList[i]; + decimal prevErgodicCsiSma1 = i >= 1 ? ergodicCsiSmaList[i - 1] : 0; + decimal prevErgodicCsiSma2 = i >= 2 ? ergodicCsiSmaList[i - 2] : 0; var signal = GetCompareSignal(ergodicCsiSma - prevErgodicCsiSma1, prevErgodicCsiSma1 - prevErgodicCsiSma2); signalsList.Add(signal); @@ -12686,23 +12686,23 @@ public static StockData CalculateEnhancedIndex(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal dnm = highest - lowest; - decimal sma = smaList.ElementAtOrDefault(i); + decimal sma = smaList[i]; decimal closewr = dnm != 0 ? 2 * (currentValue - sma) / dnm : 0; - closewrList.Add(closewr); + closewrList.AddRounded(closewr); } var closewrSmaList = GetMovingAverageList(stockData, maType, signalLength, closewrList); for (int i = 0; i < stockData.Count; i++) { - decimal closewr = closewrList.ElementAtOrDefault(i); - decimal closewrSma = closewrSmaList.ElementAtOrDefault(i); - decimal prevCloseWr = i >= 1 ? closewrList.ElementAtOrDefault(i - 1) : 0; - decimal prevCloseWrSma = i >= 1 ? closewrSmaList.ElementAtOrDefault(i - 1) : 0; + decimal closewr = closewrList[i]; + decimal closewrSma = closewrSmaList[i]; + decimal prevCloseWr = i >= 1 ? closewrList[i - 1] : 0; + decimal prevCloseWrSma = i >= 1 ? closewrSmaList[i - 1] : 0; var signal = GetCompareSignal(closewr - closewrSma, prevCloseWr - prevCloseWrSma); signalsList.Add(signal); @@ -12743,19 +12743,19 @@ public static StockData CalculateEmaWaveIndicator(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal emaA = emaAList.ElementAtOrDefault(i); - decimal emaB = emaBList.ElementAtOrDefault(i); - decimal emaC = emaCList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal emaA = emaAList[i]; + decimal emaB = emaBList[i]; + decimal emaC = emaCList[i]; decimal emaADiff = currentValue - emaA; - emaADiffList.Add(emaADiff); + emaADiffList.AddRounded(emaADiff); decimal emaBDiff = currentValue - emaB; - emaBDiffList.Add(emaBDiff); + emaBDiffList.AddRounded(emaBDiff); decimal emaCDiff = currentValue - emaC; - emaCDiffList.Add(emaCDiff); + emaCDiffList.AddRounded(emaCDiff); } var waList = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, smoothLength, emaADiffList); @@ -12763,9 +12763,9 @@ public static StockData CalculateEmaWaveIndicator(this StockData stockData, int var wcList = GetMovingAverageList(stockData, MovingAvgType.SimpleMovingAverage, smoothLength, emaCDiffList); for (int i = 0; i < stockData.Count; i++) { - decimal wa = waList.ElementAtOrDefault(i); - decimal wb = wbList.ElementAtOrDefault(i); - decimal wc = wcList.ElementAtOrDefault(i); + decimal wa = waList[i]; + decimal wb = wbList[i]; + decimal wc = wcList[i]; var signal = GetConditionSignal(wa > 0 && wb > 0 && wc > 0, wa < 0 && wb < 0 && wc < 0); signalsList.Add(signal); @@ -12805,11 +12805,11 @@ public static StockData CalculateErgodicMeanDeviationIndicator(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; decimal ma1 = currentValue - currentEma; - ma1List.Add(ma1); + ma1List.AddRounded(ma1); } var ma1EmaList = GetMovingAverageList(stockData, maType, length2, ma1List); @@ -12817,10 +12817,10 @@ public static StockData CalculateErgodicMeanDeviationIndicator(this StockData st var emdiSignalList = GetMovingAverageList(stockData, maType, signalLength, emdiList); for (int i = 0; i < stockData.Count; i++) { - decimal emdi = emdiList.ElementAtOrDefault(i); - decimal emdiSignal = emdiSignalList.ElementAtOrDefault(i); - decimal prevEmdi = i >= 1 ? emdiList.ElementAtOrDefault(i - 1) : 0; - decimal prevEmdiSignal = i >= 1 ? emdiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal emdi = emdiList[i]; + decimal emdiSignal = emdiSignalList[i]; + decimal prevEmdi = i >= 1 ? emdiList[i - 1] : 0; + decimal prevEmdiSignal = i >= 1 ? emdiSignalList[i - 1] : 0; var signal = GetCompareSignal(emdi - emdiSignal, prevEmdi - prevEmdiSignal); signalsList.Add(signal); @@ -12855,17 +12855,17 @@ public static StockData CalculateEfficientPrice(this StockData stockData, int le for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal er = erList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal prevEp1 = i >= 1 ? epList.ElementAtOrDefault(i - 1) : 0; - decimal prevEp2 = i >= 2 ? epList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal er = erList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; + decimal prevEp1 = i >= 1 ? epList[i - 1] : 0; + decimal prevEp2 = i >= 2 ? epList[i - 2] : 0; decimal chgEr = (currentValue - prevValue) * er; - chgErList.Add(chgEr); + chgErList.AddRounded(chgEr); decimal ep = chgErList.Sum(); - epList.Add(ep); + epList.AddRounded(ep); var signal = GetCompareSignal(ep - prevEp1, prevEp1 - prevEp2); signalsList.Add(signal); @@ -12900,14 +12900,14 @@ public static StockData CalculateEfficientAutoLine(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal er = erList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal er = erList[i]; decimal dev = (er * fastAlpha) + ((1 - er) * slowAlpha); decimal prevA = aList.LastOrDefault(); decimal a = i < 9 ? currentValue : currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; - aList.Add(a); + aList.AddRounded(a); var signal = GetCompareSignal(currentValue - a, prevValue - prevA); signalsList.Add(signal); diff --git a/Calculations/PivotPoint.cs b/Calculations/PivotPoint.cs index 85cc6f9..b3ceba5 100644 --- a/Calculations/PivotPoint.cs +++ b/Calculations/PivotPoint.cs @@ -27,53 +27,53 @@ public static StockData CalculateStandardPivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevOpen = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevOpen = i >= 1 ? openList[i - 1] : 0; decimal prevPivot = pivotList.LastOrDefault(); decimal range = prevHigh - prevLow; decimal pivot = (prevHigh + prevLow + prevClose + prevOpen) / 4; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal supportLevel1 = (pivot * 2) - prevHigh; - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal resistanceLevel1 = (pivot * 2) - prevLow; - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); decimal range2 = resistanceLevel1 - supportLevel1; decimal supportLevel2 = pivot - range; - supportLevel2List.Add(supportLevel2); + supportLevel2List.AddRounded(supportLevel2); decimal resistanceLevel2 = pivot + range; - resistanceLevel2List.Add(resistanceLevel2); + resistanceLevel2List.AddRounded(resistanceLevel2); decimal supportLevel3 = pivot - range2; - supportLevel3List.Add(supportLevel3); + supportLevel3List.AddRounded(supportLevel3); decimal resistanceLevel3 = pivot + range2; - resistanceLevel3List.Add(resistanceLevel3); + resistanceLevel3List.AddRounded(resistanceLevel3); decimal midpoint1 = (supportLevel3 + supportLevel2) / 2; - midpoint1List.Add(midpoint1); + midpoint1List.AddRounded(midpoint1); decimal midpoint2 = (supportLevel2 + supportLevel1) / 2; - midpoint2List.Add(midpoint2); + midpoint2List.AddRounded(midpoint2); decimal midpoint3 = (supportLevel1 + pivot) / 2; - midpoint3List.Add(midpoint3); + midpoint3List.AddRounded(midpoint3); decimal midpoint4 = (resistanceLevel1 + pivot) / 2; - midpoint4List.Add(midpoint4); + midpoint4List.AddRounded(midpoint4); decimal midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; - midpoint5List.Add(midpoint5); + midpoint5List.AddRounded(midpoint5); decimal midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; - midpoint6List.Add(midpoint6); + midpoint6List.AddRounded(midpoint6); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); signalsList.Add(signal); @@ -127,51 +127,51 @@ public static StockData CalculateWoodiePivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal prevPivot = pivotList.LastOrDefault(); decimal range = prevHigh - prevLow; decimal pivot = (prevHigh + prevLow + (prevClose * 2)) / 4; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal supportLevel1 = (pivot * 2) - prevHigh; - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal resistanceLevel1 = (pivot * 2) - prevLow; - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); decimal supportLevel2 = pivot - range; - supportLevel2List.Add(supportLevel2); + supportLevel2List.AddRounded(supportLevel2); decimal resistanceLevel2 = pivot + range; - resistanceLevel2List.Add(resistanceLevel2); + resistanceLevel2List.AddRounded(resistanceLevel2); decimal supportLevel3 = prevLow - (2 * (prevHigh - pivot)); - supportLevel3List.Add(supportLevel3); + supportLevel3List.AddRounded(supportLevel3); decimal resistanceLevel3 = prevHigh + (2 * (pivot - prevLow)); - resistanceLevel3List.Add(resistanceLevel3); + resistanceLevel3List.AddRounded(resistanceLevel3); decimal supportLevel4 = supportLevel3 - range; - supportLevel4List.Add(supportLevel4); + supportLevel4List.AddRounded(supportLevel4); decimal resistanceLevel4 = resistanceLevel3 + range; - resistanceLevel4List.Add(resistanceLevel4); + resistanceLevel4List.AddRounded(resistanceLevel4); decimal midpoint1 = (supportLevel1 + supportLevel2) / 2; - midpoint1List.Add(midpoint1); + midpoint1List.AddRounded(midpoint1); decimal midpoint2 = (pivot + supportLevel1) / 2; - midpoint2List.Add(midpoint2); + midpoint2List.AddRounded(midpoint2); decimal midpoint3 = (resistanceLevel1 + pivot) / 2; - midpoint3List.Add(midpoint3); + midpoint3List.AddRounded(midpoint3); decimal midpoint4 = (resistanceLevel1 + resistanceLevel2) / 2; - midpoint4List.Add(midpoint4); + midpoint4List.AddRounded(midpoint4); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); signalsList.Add(signal); @@ -225,52 +225,52 @@ public static StockData CalculateFloorPivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i) : 0; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i) : 0; + decimal currentClose = inputList[i]; + decimal prevHigh = i >= 1 ? highList[i] : 0; + decimal prevLow = i >= 1 ? lowList[i] : 0; + decimal prevClose = i >= 1 ? inputList[i] : 0; decimal range = prevHigh - prevLow; decimal pivot = (prevHigh + prevLow + prevClose) / 3; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal prevSupportLevel1 = supportLevel1List.LastOrDefault(); decimal supportLevel1 = (pivot * 2) - prevHigh; - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); decimal resistanceLevel1 = (pivot * 2) - prevLow; - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); decimal supportLevel2 = pivot - range; - supportLevel2List.Add(supportLevel2); + supportLevel2List.AddRounded(supportLevel2); decimal resistanceLevel2 = pivot + range; - resistanceLevel2List.Add(resistanceLevel2); + resistanceLevel2List.AddRounded(resistanceLevel2); decimal supportLevel3 = supportLevel1 - range; - supportLevel3List.Add(supportLevel3); + supportLevel3List.AddRounded(supportLevel3); decimal resistanceLevel3 = resistanceLevel1 + range; - resistanceLevel3List.Add(resistanceLevel3); + resistanceLevel3List.AddRounded(resistanceLevel3); decimal midpoint1 = (supportLevel3 + supportLevel2) / 2; - midpoint1List.Add(midpoint1); + midpoint1List.AddRounded(midpoint1); decimal midpoint2 = (supportLevel2 + supportLevel1) / 2; - midpoint2List.Add(midpoint2); + midpoint2List.AddRounded(midpoint2); decimal midpoint3 = (supportLevel1 + pivot) / 2; - midpoint3List.Add(midpoint3); + midpoint3List.AddRounded(midpoint3); decimal midpoint4 = (resistanceLevel1 + pivot) / 2; - midpoint4List.Add(midpoint4); + midpoint4List.AddRounded(midpoint4); decimal midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; - midpoint5List.Add(midpoint5); + midpoint5List.AddRounded(midpoint5); decimal midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; - midpoint6List.Add(midpoint6); + midpoint6List.AddRounded(midpoint6); var signal = GetBullishBearishSignal(currentClose - resistanceLevel1, prevClose - prevResistanceLevel1, currentClose - supportLevel1, prevClose - prevSupportLevel1); @@ -325,51 +325,51 @@ public static StockData CalculateFibonacciPivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; decimal prevPivot = pivotList.LastOrDefault(); decimal range = prevHigh - prevLow; decimal pivot = (prevHigh + prevLow + prevClose) / 3; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal supportLevel1 = pivot - (range * 0.382m); - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal supportLevel2 = pivot - (range * 0.618m); - supportLevel2List.Add(supportLevel2); + supportLevel2List.AddRounded(supportLevel2); decimal supportLevel3 = pivot - (range * 1); - supportLevel3List.Add(supportLevel3); + supportLevel3List.AddRounded(supportLevel3); decimal resistanceLevel1 = pivot + (range * 0.382m); - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); decimal resistanceLevel2 = pivot + (range * 0.618m); - resistanceLevel2List.Add(resistanceLevel2); + resistanceLevel2List.AddRounded(resistanceLevel2); decimal resistanceLevel3 = pivot + (range * 1); - resistanceLevel3List.Add(resistanceLevel3); + resistanceLevel3List.AddRounded(resistanceLevel3); decimal midpoint1 = (supportLevel3 + supportLevel2) / 2; - midpoint1List.Add(midpoint1); + midpoint1List.AddRounded(midpoint1); decimal midpoint2 = (supportLevel2 + supportLevel1) / 2; - midpoint2List.Add(midpoint2); + midpoint2List.AddRounded(midpoint2); decimal midpoint3 = (supportLevel1 + pivot) / 2; - midpoint3List.Add(midpoint3); + midpoint3List.AddRounded(midpoint3); decimal midpoint4 = (resistanceLevel1 + pivot) / 2; - midpoint4List.Add(midpoint4); + midpoint4List.AddRounded(midpoint4); decimal midpoint5 = (resistanceLevel2 + resistanceLevel1) / 2; - midpoint5List.Add(midpoint5); + midpoint5List.AddRounded(midpoint5); decimal midpoint6 = (resistanceLevel3 + resistanceLevel2) / 2; - midpoint6List.Add(midpoint6); + midpoint6List.AddRounded(midpoint6); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); signalsList.Add(signal); @@ -427,66 +427,66 @@ public static StockData CalculateCamarillaPivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentClose = i >= 1 ? prevClose : inputList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = i >= 1 ? prevHigh : highList.ElementAtOrDefault(i); - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal currentLow = i >= 1 ? prevLow : lowList.ElementAtOrDefault(i); + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal currentClose = i >= 1 ? prevClose : inputList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal currentHigh = i >= 1 ? prevHigh : highList[i]; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal currentLow = i >= 1 ? prevLow : lowList[i]; decimal range = currentHigh - currentLow; decimal pivot = (prevHigh + prevLow + prevClose) / 3; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal prevSupportLevel1 = supportLevel1List.LastOrDefault(); decimal supportLevel1 = currentClose - (0.0916m * range); - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal supportLevel2 = currentClose - (0.183m * range); - supportLevel2List.Add(supportLevel2); + supportLevel2List.AddRounded(supportLevel2); decimal supportLevel3 = currentClose - (0.275m * range); - supportLevel3List.Add(supportLevel3); + supportLevel3List.AddRounded(supportLevel3); decimal supportLevel4 = currentClose - (0.55m * range); - supportLevel4List.Add(supportLevel4); + supportLevel4List.AddRounded(supportLevel4); decimal prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); decimal resistanceLevel1 = currentClose + (0.0916m * range); - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); decimal resistanceLevel2 = currentClose + (0.183m * range); - resistanceLevel2List.Add(resistanceLevel2); + resistanceLevel2List.AddRounded(resistanceLevel2); decimal resistanceLevel3 = currentClose + (0.275m * range); - resistanceLevel3List.Add(resistanceLevel3); + resistanceLevel3List.AddRounded(resistanceLevel3); decimal resistanceLevel4 = currentClose + (0.55m * range); - resistanceLevel4List.Add(resistanceLevel4); + resistanceLevel4List.AddRounded(resistanceLevel4); decimal resistanceLevel5 = currentLow != 0 ? currentHigh / currentLow * currentClose : 0; - resistanceLevel5List.Add(resistanceLevel5); + resistanceLevel5List.AddRounded(resistanceLevel5); decimal supportLevel5 = currentClose - (resistanceLevel5 - currentClose); - supportLevel5List.Add(supportLevel5); + supportLevel5List.AddRounded(supportLevel5); decimal midpoint1 = (supportLevel3 + supportLevel2) / 2; - midpoint1List.Add(midpoint1); + midpoint1List.AddRounded(midpoint1); decimal midpoint2 = (supportLevel2 + supportLevel1) / 2; - midpoint2List.Add(midpoint2); + midpoint2List.AddRounded(midpoint2); decimal midpoint3 = (resistanceLevel2 + resistanceLevel1) / 2; - midpoint3List.Add(midpoint3); + midpoint3List.AddRounded(midpoint3); decimal midpoint4 = (resistanceLevel3 + resistanceLevel2) / 2; - midpoint4List.Add(midpoint4); + midpoint4List.AddRounded(midpoint4); decimal midpoint5 = (resistanceLevel3 + resistanceLevel4) / 2; - midpoint5List.Add(midpoint5); + midpoint5List.AddRounded(midpoint5); decimal midpoint6 = (supportLevel4 + supportLevel3) / 2; - midpoint6List.Add(midpoint6); + midpoint6List.AddRounded(midpoint6); var signal = GetBullishBearishSignal(currentClose - resistanceLevel1, prevClose - prevResistanceLevel1, currentClose - supportLevel1, prevClose - prevSupportLevel1); @@ -537,19 +537,19 @@ public static StockData CalculatePivotPointAverage(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentOpen = openList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal pp1 = (prevHigh + prevLow + prevClose) / 3; - pp1List.Add(pp1); + pp1List.AddRounded(pp1); decimal pp2 = (prevHigh + prevLow + prevClose + currentOpen) / 4; - pp2List.Add(pp2); + pp2List.AddRounded(pp2); decimal pp3 = (prevHigh + prevLow + currentOpen) / 3; - pp3List.Add(pp3); + pp3List.AddRounded(pp3); } var ppav1List = GetMovingAverageList(stockData, maType, length, pp1List); @@ -557,10 +557,10 @@ public static StockData CalculatePivotPointAverage(this StockData stockData, Mov var ppav3List = GetMovingAverageList(stockData, maType, length, pp3List); for (int i = 0; i < stockData.Count; i++) { - decimal pp1 = pp1List.ElementAtOrDefault(i); - decimal ppav1 = ppav1List.ElementAtOrDefault(i); - decimal prevPp1 = i >= 1 ? pp1List.ElementAtOrDefault(i - 1) : 0; - decimal prevPpav1 = i >= 1 ? ppav1List.ElementAtOrDefault(i - 1) : 0; + decimal pp1 = pp1List[i]; + decimal ppav1 = ppav1List[i]; + decimal prevPp1 = i >= 1 ? pp1List[i - 1] : 0; + decimal prevPpav1 = i >= 1 ? ppav1List[i - 1] : 0; var signal = GetCompareSignal(pp1 - ppav1, prevPp1 - prevPpav1); signalsList.Add(signal); @@ -597,24 +597,24 @@ public static StockData CalculateDemarkPivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevOpen = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevOpen = i >= 1 ? openList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; decimal x = prevClose < prevOpen ? prevHigh + (2 * prevLow) + prevClose : prevClose > prevOpen ? (2 * prevHigh) + prevLow + prevClose : prevClose == prevOpen ? prevHigh + prevLow + (2 * prevClose) : prevClose; decimal prevPivot = pivotList.LastOrDefault(); decimal pivot = x / 4; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal ratio = x / 2; decimal supportLevel1 = ratio - prevHigh; - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal resistanceLevel1 = ratio - prevLow; - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); var signal = GetCompareSignal(currentClose - pivot, prevClose - prevPivot); signalsList.Add(signal); @@ -648,21 +648,21 @@ public static StockData CalculateDynamicPivotPoints(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal pivot = (prevHigh + prevLow + prevClose) / 3; - pivotList.Add(pivot); + pivotList.AddRounded(pivot); decimal prevSupportLevel1 = supportLevel1List.LastOrDefault(); decimal supportLevel1 = pivot - (prevHigh - pivot); - supportLevel1List.Add(supportLevel1); + supportLevel1List.AddRounded(supportLevel1); decimal prevResistanceLevel1 = resistanceLevel1List.LastOrDefault(); decimal resistanceLevel1 = pivot + (pivot - prevLow); - resistanceLevel1List.Add(resistanceLevel1); + resistanceLevel1List.AddRounded(resistanceLevel1); var signal = GetBullishBearishSignal(currentClose - resistanceLevel1, prevClose - prevResistanceLevel1, currentClose - supportLevel1, prevClose - prevSupportLevel1); diff --git a/Calculations/Ppo.cs b/Calculations/Ppo.cs index bbb865a..39e66d7 100644 --- a/Calculations/Ppo.cs +++ b/Calculations/Ppo.cs @@ -24,22 +24,22 @@ public static StockData CalculatePercentagePriceOscillator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal fastEma = fastEmaList.ElementAtOrDefault(i); - decimal slowEma = slowEmaList.ElementAtOrDefault(i); + decimal fastEma = fastEmaList[i]; + decimal slowEma = slowEmaList[i]; decimal ppo = slowEma != 0 ? 100 * (fastEma - slowEma) / slowEma : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); } var ppoSignalList = GetMovingAverageList(stockData, maType, signalLength, ppoList); for (int i = 0; i < stockData.Count; i++) { - decimal ppo = ppoList.ElementAtOrDefault(i); - decimal ppoSignalLine = ppoSignalList.ElementAtOrDefault(i); + decimal ppo = ppoList[i]; + decimal ppoSignalLine = ppoSignalList[i]; decimal prevPpoHistogram = ppoHistogramList.LastOrDefault(); decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); signalsList.Add(signal); @@ -80,22 +80,22 @@ public static StockData CalculatePercentageVolumeOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal fastEma = fastEmaList.ElementAtOrDefault(i); - decimal slowEma = slowEmaList.ElementAtOrDefault(i); + decimal fastEma = fastEmaList[i]; + decimal slowEma = slowEmaList[i]; decimal pvo = slowEma != 0 ? 100 * (fastEma - slowEma) / slowEma : 0; - pvoList.Add(pvo); + pvoList.AddRounded(pvo); } var pvoSignalList = GetMovingAverageList(stockData, maType, signalLength, pvoList); for (int i = 0; i < stockData.Count; i++) { - decimal pvo = pvoList.ElementAtOrDefault(i); - decimal pvoSignalLine = pvoSignalList.ElementAtOrDefault(i); + decimal pvo = pvoList[i]; + decimal pvoSignalLine = pvoSignalList[i]; decimal prevPvoHistogram = pvoHistogramList.LastOrDefault(); decimal pvoHistogram = pvo - pvoSignalLine; - pvoHistogramList.Add(pvoHistogram); + pvoHistogramList.AddRounded(pvoHistogram); var signal = GetCompareSignal(pvoHistogram, prevPvoHistogram); signalsList.Add(signal); @@ -150,28 +150,28 @@ public static StockData Calculate4PercentagePriceOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal ema5 = ema5List.ElementAtOrDefault(i); - decimal ema8 = ema8List.ElementAtOrDefault(i); - decimal ema10 = ema10List.ElementAtOrDefault(i); - decimal ema14 = ema14List.ElementAtOrDefault(i); - decimal ema16 = ema16List.ElementAtOrDefault(i); - decimal ema17 = ema17List.ElementAtOrDefault(i); + decimal ema5 = ema5List[i]; + decimal ema8 = ema8List[i]; + decimal ema10 = ema10List[i]; + decimal ema14 = ema14List[i]; + decimal ema16 = ema16List[i]; + decimal ema17 = ema17List[i]; decimal macd1 = ema17 - ema14; decimal macd2 = ema17 - ema8; decimal macd3 = ema10 - ema16; decimal macd4 = ema5 - ema10; decimal ppo1 = ema14 != 0 ? macd1 / ema14 * 100 : 0; - ppo1List.Add(ppo1); + ppo1List.AddRounded(ppo1); decimal ppo2 = ema8 != 0 ? macd2 / ema8 * 100 : 0; - ppo2List.Add(ppo2); + ppo2List.AddRounded(ppo2); decimal ppo3 = ema16 != 0 ? macd3 / ema16 * 100 : 0; - ppo3List.Add(ppo3); + ppo3List.AddRounded(ppo3); decimal ppo4 = ema10 != 0 ? macd4 / ema10 * 100 : 0; - ppo4List.Add(ppo4); + ppo4List.AddRounded(ppo4); } var ppo1SignalLineList = GetMovingAverageList(stockData, maType, length1, ppo1List); @@ -180,27 +180,27 @@ public static StockData Calculate4PercentagePriceOscillator(this StockData stock var ppo4SignalLineList = GetMovingAverageList(stockData, maType, length1, ppo4List); for (int i = 0; i < stockData.Count; i++) { - decimal ppo1 = ppo1List.ElementAtOrDefault(i); - decimal ppo1SignalLine = ppo1SignalLineList.ElementAtOrDefault(i); - decimal ppo2 = ppo2List.ElementAtOrDefault(i); - decimal ppo2SignalLine = ppo2SignalLineList.ElementAtOrDefault(i); - decimal ppo3 = ppo3List.ElementAtOrDefault(i); - decimal ppo3SignalLine = ppo3SignalLineList.ElementAtOrDefault(i); - decimal ppo4 = ppo4List.ElementAtOrDefault(i); - decimal ppo4SignalLine = ppo4SignalLineList.ElementAtOrDefault(i); + decimal ppo1 = ppo1List[i]; + decimal ppo1SignalLine = ppo1SignalLineList[i]; + decimal ppo2 = ppo2List[i]; + decimal ppo2SignalLine = ppo2SignalLineList[i]; + decimal ppo3 = ppo3List[i]; + decimal ppo3SignalLine = ppo3SignalLineList[i]; + decimal ppo4 = ppo4List[i]; + decimal ppo4SignalLine = ppo4SignalLineList[i]; decimal ppo1Histogram = ppo1 - ppo1SignalLine; decimal ppoBlue = blueMult * ppo1Histogram; decimal prevPpo2Histogram = ppo2HistogramList.LastOrDefault(); decimal ppo2Histogram = ppo2 - ppo2SignalLine; - ppo2HistogramList.Add(ppo2Histogram); + ppo2HistogramList.AddRounded(ppo2Histogram); decimal ppo3Histogram = ppo3 - ppo3SignalLine; decimal ppoYellow = yellowMult * ppo3Histogram; decimal prevPpo4Histogram = ppo4HistogramList.LastOrDefault(); decimal ppo4Histogram = ppo4 - ppo4SignalLine; - ppo4HistogramList.Add(ppo4Histogram); + ppo4HistogramList.AddRounded(ppo4Histogram); decimal maxPpo = Math.Max(ppoBlue, Math.Max(ppoYellow, Math.Max(ppo2Histogram, ppo4Histogram))); decimal minPpo = Math.Min(ppoBlue, Math.Min(ppoYellow, Math.Min(ppo2Histogram, ppo4Histogram))); @@ -251,20 +251,20 @@ public static StockData CalculateImpulsePercentagePriceOscillator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal hi = wellesWilderHighMovingAvgList.ElementAtOrDefault(i); - decimal lo = wellesWilderLowMovingAvgList.ElementAtOrDefault(i); - decimal mi = typicalPriceZeroLagEmaList.ElementAtOrDefault(i); + decimal hi = wellesWilderHighMovingAvgList[i]; + decimal lo = wellesWilderLowMovingAvgList[i]; + decimal mi = typicalPriceZeroLagEmaList[i]; decimal macd = mi > hi ? mi - hi : mi < lo ? mi - lo : 0; decimal ppo = mi > hi && hi != 0 ? macd / hi * 100 : mi < lo && lo != 0 ? macd / lo * 100 : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); decimal ppoSignalLine = ppoList.TakeLastExt(signalLength).Average(); - ppoSignalLineList.Add(ppoSignalLine); + ppoSignalLineList.AddRounded(ppoSignalLine); decimal prevPpoHistogram = ppoHistogramList.LastOrDefault(); decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); signalsList.Add(signal); @@ -305,23 +305,23 @@ public static StockData CalculatePercentagePriceOscillatorLeader(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal i1 = i1List.ElementAtOrDefault(i); - decimal i2 = i2List.ElementAtOrDefault(i); + decimal i1 = i1List[i]; + decimal i2 = i2List[i]; decimal macd = i1 - i2; decimal ppo = i2 != 0 ? macd / i2 * 100 : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, signalLength, ppoList); for (int i = 0; i < stockData.Count; i++) { - decimal ppo = ppoList.ElementAtOrDefault(i); - decimal ppoSignalLine = ppoSignalLineList.ElementAtOrDefault(i); + decimal ppo = ppoList[i]; + decimal ppoSignalLine = ppoSignalLineList[i]; decimal prevPpoHistogram = ppoHistogramList.LastOrDefault(); decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); signalsList.Add(signal); @@ -362,23 +362,23 @@ public static StockData CalculateTFSMboPercentagePriceOscillator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal mob1 = mob1List.ElementAtOrDefault(i); - decimal mob2 = mob2List.ElementAtOrDefault(i); + decimal mob1 = mob1List[i]; + decimal mob2 = mob2List[i]; decimal tfsMob = mob1 - mob2; decimal ppo = mob2 != 0 ? tfsMob / mob2 * 100 : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, signalLength, ppoList); for (int i = 0; i < stockData.Count; i++) { - decimal ppo = ppoList.ElementAtOrDefault(i); - decimal ppoSignalLine = ppoSignalLineList.ElementAtOrDefault(i); + decimal ppo = ppoList[i]; + decimal ppoSignalLine = ppoSignalLineList[i]; decimal prevPpoHistogram = ppoHistogramList.LastOrDefault(); decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); signalsList.Add(signal); @@ -420,33 +420,33 @@ public static StockData CalculateMirroredPercentagePriceOscillator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal mao = emaOpenList.ElementAtOrDefault(i); - decimal mac = emaCloseList.ElementAtOrDefault(i); + decimal mao = emaOpenList[i]; + decimal mac = emaCloseList[i]; decimal macd = mac - mao; decimal macdMirror = mao - mac; decimal ppo = mao != 0 ? macd / mao * 100 : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); decimal ppoMirror = mac != 0 ? macdMirror / mac * 100 : 0; - ppoMirrorList.Add(ppoMirror); + 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++) { - decimal ppo = ppoList.ElementAtOrDefault(i); - decimal ppoSignalLine = ppoSignalLineList.ElementAtOrDefault(i); - decimal ppoMirror = ppoMirrorList.ElementAtOrDefault(i); - decimal ppoMirrorSignalLine = ppoMirrorSignalLineList.ElementAtOrDefault(i); + decimal ppo = ppoList[i]; + decimal ppoSignalLine = ppoSignalLineList[i]; + decimal ppoMirror = ppoMirrorList[i]; + decimal ppoMirrorSignalLine = ppoMirrorSignalLineList[i]; decimal prevPpoHistogram = ppoHistogramList.LastOrDefault(); decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); decimal ppoMirrorHistogram = ppoMirror - ppoMirrorSignalLine; - ppoMirrorHistogramList.Add(ppoMirrorHistogram); + ppoMirrorHistogramList.AddRounded(ppoMirrorHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); signalsList.Add(signal); @@ -492,19 +492,19 @@ public static StockData CalculateDiNapoliPercentagePriceOscillator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal ss = ssList.ElementAtOrDefault(i); - decimal r = rList.ElementAtOrDefault(i); + decimal ss = ssList[i]; + decimal r = rList[i]; decimal ppo = ss != 0 ? 100 * r / ss : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); decimal prevS = sList.LastOrDefault(); decimal s = prevS + (spAlpha * (ppo - prevS)); - sList.Add(s); + sList.AddRounded(s); decimal prevH = hList.LastOrDefault(); decimal h = ppo - s; - hList.Add(h); + hList.AddRounded(h); var signal = GetCompareSignal(h, prevH); signalsList.Add(signal); @@ -545,23 +545,23 @@ public static StockData CalculateErgodicPercentagePriceOscillator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal ema1 = period1EmaList.ElementAtOrDefault(i); - decimal ema2 = period2EmaList.ElementAtOrDefault(i); + decimal ema1 = period1EmaList[i]; + decimal ema2 = period2EmaList[i]; decimal macd = ema1 - ema2; decimal ppo = ema2 != 0 ? macd / ema2 * 100 : 0; - ppoList.Add(ppo); + ppoList.AddRounded(ppo); } var ppoSignalLineList = GetMovingAverageList(stockData, maType, length3, ppoList); for (int i = 0; i < stockData.Count; i++) { - decimal ppo = ppoList.ElementAtOrDefault(i); - decimal ppoSignalLine = ppoSignalLineList.ElementAtOrDefault(i); + decimal ppo = ppoList[i]; + decimal ppoSignalLine = ppoSignalLineList[i]; decimal prevPpoHistogram = ppoHistogramList.LastOrDefault(); decimal ppoHistogram = ppo - ppoSignalLine; - ppoHistogramList.Add(ppoHistogram); + ppoHistogramList.AddRounded(ppoHistogram); var signal = GetCompareSignal(ppoHistogram, prevPpoHistogram); signalsList.Add(signal); diff --git a/Calculations/PriceChannel.cs b/Calculations/PriceChannel.cs index 6e07bae..2fd519f 100644 --- a/Calculations/PriceChannel.cs +++ b/Calculations/PriceChannel.cs @@ -23,19 +23,19 @@ public static StockData CalculatePriceChannel(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal upperPriceChannel = currentEma * (1 + pct); - upperPriceChannelList.Add(upperPriceChannel); + upperPriceChannelList.AddRounded(upperPriceChannel); decimal lowerPriceChannel = currentEma * (1 - pct); - lowerPriceChannelList.Add(lowerPriceChannel); + lowerPriceChannelList.AddRounded(lowerPriceChannel); decimal prevMidPriceChannel = midPriceChannelList.LastOrDefault(); decimal midPriceChannel = (upperPriceChannel + lowerPriceChannel) / 2; - midPriceChannelList.Add(midPriceChannel); + midPriceChannelList.AddRounded(midPriceChannel); var signal = GetCompareSignal(currentValue - midPriceChannel, prevValue - prevMidPriceChannel); signalsList.Add(signal); @@ -71,18 +71,18 @@ public static StockData CalculateDonchianChannels(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal upperChannel = highestList.ElementAtOrDefault(i); - upperChannelList.Add(upperChannel); + decimal upperChannel = highestList[i]; + upperChannelList.AddRounded(upperChannel); - decimal lowerChannel = lowestList.ElementAtOrDefault(i); - lowerChannelList.Add(lowerChannel); + decimal lowerChannel = lowestList[i]; + lowerChannelList.AddRounded(lowerChannel); decimal prevMiddleChannel = middleChannelList.LastOrDefault(); decimal middleChannel = (upperChannel + lowerChannel) / 2; - middleChannelList.Add(middleChannel); + middleChannelList.AddRounded(middleChannel); var signal = GetCompareSignal(currentValue - middleChannel, prevValue - prevMiddleChannel); signalsList.Add(signal); @@ -120,11 +120,11 @@ public static StockData CalculateStandardDeviationChannel(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = regressionList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentStdDev = stdDeviationList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? regressionList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = regressionList[i]; + decimal currentValue = inputList[i]; + decimal currentStdDev = stdDeviationList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? regressionList[i - 1] : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (currentStdDev * stdDevMult); @@ -172,11 +172,11 @@ public static StockData CalculateStollerAverageRangeChannels(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = smaList[i]; + decimal currentValue = inputList[i]; + decimal currentAtr = atrList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (currentAtr * atrMult); @@ -221,14 +221,14 @@ public static StockData CalculateMovingAverageChannel(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal upperChannel = highMaList.ElementAtOrDefault(i); - decimal lowerChannel = lowMaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal upperChannel = highMaList[i]; + decimal lowerChannel = lowMaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevMidChannel = midChannelList.LastOrDefault(); decimal midChannel = (upperChannel + lowerChannel) / 2; - midChannelList.Add(midChannel); + midChannelList.AddRounded(midChannel); var signal = GetCompareSignal(currentValue - midChannel, prevValue - prevMidChannel); signalsList.Add(signal); @@ -267,17 +267,17 @@ public static StockData CalculateMovingAverageEnvelope(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentSma20 = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma20 = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentSma20 = smaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma20 = i >= 1 ? smaList[i - 1] : 0; decimal factor = currentSma20 * mult; decimal upperEnvelope = currentSma20 + factor; - upperEnvelopeList.Add(upperEnvelope); + upperEnvelopeList.AddRounded(upperEnvelope); decimal lowerEnvelope = currentSma20 - factor; - lowerEnvelopeList.Add(lowerEnvelope); + lowerEnvelopeList.AddRounded(lowerEnvelope); var signal = GetCompareSignal(currentValue - currentSma20, prevValue - prevSma20); signalsList.Add(signal); @@ -311,14 +311,14 @@ public static StockData CalculateFractalChaosBands(this StockData stockData) for (int i = 0; i < stockData.Count; i++) { - decimal prevHigh1 = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh2 = i >= 2 ? highList.ElementAtOrDefault(i - 2) : 0; - decimal prevHigh3 = i >= 3 ? highList.ElementAtOrDefault(i - 3) : 0; - decimal prevLow1 = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow2 = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; - decimal prevLow3 = i >= 3 ? lowList.ElementAtOrDefault(i - 3) : 0; - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevHigh1 = i >= 1 ? highList[i - 1] : 0; + decimal prevHigh2 = i >= 2 ? highList[i - 2] : 0; + decimal prevHigh3 = i >= 3 ? highList[i - 3] : 0; + decimal prevLow1 = i >= 1 ? lowList[i - 1] : 0; + decimal prevLow2 = i >= 2 ? lowList[i - 2] : 0; + decimal prevLow3 = i >= 3 ? lowList[i - 3] : 0; + decimal currentClose = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal oklUpper = prevHigh1 < prevHigh2 ? 1 : 0; decimal okrUpper = prevHigh3 < prevHigh2 ? 1 : 0; decimal oklLower = prevLow1 > prevLow2 ? 1 : 0; @@ -326,15 +326,15 @@ public static StockData CalculateFractalChaosBands(this StockData stockData) decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = oklUpper == 1 && okrUpper == 1 ? prevHigh2 : prevUpperBand; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = oklLower == 1 && okrLower == 1 ? prevLow2 : prevLowerBand; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (upperBand + lowerBand) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentClose - middleBand, prevClose - prevMiddleBand, currentClose, prevClose, upperBand, prevUpperBand, lowerBand, prevLowerBand); signalsList.Add(signal); @@ -374,19 +374,19 @@ public static StockData CalculateAverageTrueRangeChannel(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal atr = atrList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = smaList.ElementAtOrDefault(i); - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal atr = atrList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = smaList[i]; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal prevTopInner = innerTopAtrChannelList.LastOrDefault(); decimal topInner = Math.Round(currentValue + (atr * mult)); - innerTopAtrChannelList.Add(topInner); + innerTopAtrChannelList.AddRounded(topInner); decimal prevBottomInner = innerBottomAtrChannelList.LastOrDefault(); decimal bottomInner = Math.Round(currentValue - (atr * mult)); - innerBottomAtrChannelList.Add(bottomInner); + innerBottomAtrChannelList.AddRounded(bottomInner); var signal = GetBollingerBandsSignal(currentValue - sma, prevValue - prevSma, currentValue, prevValue, topInner, prevTopInner, bottomInner, prevBottomInner); @@ -428,19 +428,19 @@ public static StockData CalculateUltimateMovingAverageBands(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevVal = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal uma = umaList.ElementAtOrDefault(i); - decimal prevUma = i >= 1 ? umaList.ElementAtOrDefault(i - 1) : 0; - decimal stdev = stdevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevVal = i >= 1 ? inputList[i - 1] : 0; + decimal uma = umaList[i]; + decimal prevUma = i >= 1 ? umaList[i - 1] : 0; + decimal stdev = stdevList[i]; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = uma + (stdDevMult * stdev); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = uma - (stdDevMult * stdev); - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - uma, prevVal - prevUma, currentValue, prevVal, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -482,18 +482,18 @@ public static StockData CalculateUniChannel(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentSma = smaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal prevUb = upperBandList.LastOrDefault(); decimal ub = type1 ? currentSma + ubFac : currentSma + (currentSma * ubFac); - upperBandList.Add(ub); + upperBandList.AddRounded(ub); decimal prevLb = lowerBandList.LastOrDefault(); decimal lb = type1 ? currentSma - lbFac : currentSma - (currentSma * lbFac); - lowerBandList.Add(lb); + lowerBandList.AddRounded(lb); var signal = GetBollingerBandsSignal(currentValue - currentSma, prevValue - prevSma, currentValue, prevValue, ub, prevUb, lb, prevLb); signalsList.Add(signal); @@ -542,19 +542,19 @@ public static StockData CalculateWilsonRelativePriceChannel(this StockData stock var rsiList = CalculateRelativeStrengthIndex(stockData, maType, length, smoothLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; decimal rsiOverbought = rsi - overbought; - rsiOverboughtList.Add(rsiOverbought); + rsiOverboughtList.AddRounded(rsiOverbought); decimal rsiOversold = rsi - oversold; - rsiOversoldList.Add(rsiOversold); + rsiOversoldList.AddRounded(rsiOversold); decimal rsiUpperNeutralZone = rsi - upperNeutralZone; - rsiUpperNeutralZoneList.Add(rsiUpperNeutralZone); + rsiUpperNeutralZoneList.AddRounded(rsiUpperNeutralZone); decimal rsiLowerNeutralZone = rsi - lowerNeutralZone; - rsiLowerNeutralZoneList.Add(rsiLowerNeutralZone); + rsiLowerNeutralZoneList.AddRounded(rsiLowerNeutralZone); } var obList = GetMovingAverageList(stockData, maType, smoothLength, rsiOverboughtList); @@ -563,28 +563,28 @@ public static StockData CalculateWilsonRelativePriceChannel(this StockData stock var nzlList = GetMovingAverageList(stockData, maType, smoothLength, rsiLowerNeutralZoneList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ob = obList.ElementAtOrDefault(i); - decimal os = osList.ElementAtOrDefault(i); - decimal nzu = nzuList.ElementAtOrDefault(i); - decimal nzl = nzlList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal ob = obList[i]; + decimal os = osList[i]; + decimal nzu = nzuList[i]; + decimal nzl = nzlList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevS1 = s1List.LastOrDefault(); decimal s1 = currentValue - (currentValue * os / 100); - s1List.Add(s1); + s1List.AddRounded(s1); decimal prevU1 = u1List.LastOrDefault(); decimal u1 = currentValue - (currentValue * ob / 100); - u1List.Add(u1); + u1List.AddRounded(u1); decimal prevU2 = u2List.LastOrDefault(); decimal u2 = currentValue - (currentValue * nzu / 100); - u2List.Add(u2); + u2List.AddRounded(u2); decimal prevS2 = s2List.LastOrDefault(); decimal s2 = currentValue - (currentValue * nzl / 100); - s2List.Add(s2); + s2List.AddRounded(s2); var signal = GetBullishBearishSignal(currentValue - Math.Min(u1, u2), prevValue - Math.Min(prevU1, prevU2), currentValue - Math.Max(s1, s2), prevValue - Math.Max(prevS1, prevS2)); @@ -624,10 +624,10 @@ public static StockData CalculateLinearChannels(this StockData stockData, int le for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; + decimal prevA2 = i >= 2 ? aList[i - 2] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal x = currentValue + ((prevA - prevA2) * mult); decimal a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; @@ -638,11 +638,11 @@ public static StockData CalculateLinearChannels(this StockData stockData, int le decimal prevUpper = upperList.LastOrDefault(); decimal upper = up == a ? prevUpper : up; - upperList.Add(upper); + upperList.AddRounded(upper); decimal prevLower = lowerList.LastOrDefault(); decimal lower = dn == a ? prevLower : dn; - lowerList.Add(lower); + lowerList.AddRounded(lower); var signal = GetBollingerBandsSignal(currentValue - a, prevValue - prevA, currentValue, prevValue, upper, prevUpper, lower, prevLower); signalsList.Add(signal); @@ -681,17 +681,17 @@ public static StockData CalculateInterquartileRangeBands(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal q1 = q1List.ElementAtOrDefault(i); - decimal q3 = q3List.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal q1 = q1List[i]; + decimal q3 = q3List[i]; decimal iqr = q3 - q1; decimal upperBand = q3 + (mult * iqr); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal lowerBand = q1 - (mult * iqr); - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (upperBand + lowerBand) / 2; @@ -760,21 +760,21 @@ public static StockData CalculateGChannels(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevA = aList.LastOrDefault(); decimal prevB = bList.LastOrDefault(); decimal factor = length != 0 ? (prevA - prevB) / length : 0; decimal a = Math.Max(currentValue, prevA) - factor; - aList.Add(a); + aList.AddRounded(a); decimal b = Math.Min(currentValue, prevB) + factor; - bList.Add(b); + bList.AddRounded(b); decimal prevMid = midList.LastOrDefault(); decimal mid = (a + b) / 2; - midList.Add(mid); + midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); signalsList.Add(signal); @@ -813,14 +813,14 @@ public static StockData CalculateHighLowMovingAverage(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal upperBand = upperBandList.ElementAtOrDefault(i); - decimal lowerBand = lowerBandList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal upperBand = upperBandList[i]; + decimal lowerBand = lowerBandList[i]; decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (upperBand + lowerBand) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetCompareSignal(currentValue - middleBand, prevValue - prevMiddleBand); signalsList.Add(signal); @@ -860,18 +860,18 @@ public static StockData CalculateHighLowBands(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal tma = tmaList2.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevTma = i >= 1 ? tmaList2.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal tma = tmaList2[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevTma = i >= 1 ? tmaList2[i - 1] : 0; decimal prevHighBand = highBandList.LastOrDefault(); decimal highBand = tma + (tma * pctShift / 100); - highBandList.Add(highBand); + highBandList.AddRounded(highBand); decimal prevLowBand = lowBandList.LastOrDefault(); decimal lowBand = tma - (tma * pctShift / 100); - lowBandList.Add(lowBand); + lowBandList.AddRounded(lowBand); var signal = GetBollingerBandsSignal(currentValue - tma, prevValue - prevTma, currentValue, prevValue, highBand, prevHighBand, lowBand, prevLowBand); @@ -927,40 +927,40 @@ public static StockData CalculateHurstCycleChannel(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sclAtr = sclAtrList.ElementAtOrDefault(i); - decimal mclAtr = mclAtrList.ElementAtOrDefault(i); - decimal prevSclRma = i >= scl_2 ? sclRmaList.ElementAtOrDefault(i - scl_2) : currentValue; - decimal prevMclRma = i >= mcl_2 ? mclRmaList.ElementAtOrDefault(i - mcl_2) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal sclAtr = sclAtrList[i]; + decimal mclAtr = mclAtrList[i]; + decimal prevSclRma = i >= scl_2 ? sclRmaList[i - scl_2] : currentValue; + decimal prevMclRma = i >= mcl_2 ? mclRmaList[i - mcl_2] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal scm_off = fastMult * sclAtr; decimal mcm_off = slowMult * mclAtr; decimal prevSct = sctList.LastOrDefault(); decimal sct = prevSclRma + scm_off; - sctList.Add(sct); + sctList.AddRounded(sct); decimal prevScb = scbList.LastOrDefault(); decimal scb = prevSclRma - scm_off; - scbList.Add(scb); + scbList.AddRounded(scb); decimal mct = prevMclRma + mcm_off; - mctList.Add(mct); + mctList.AddRounded(mct); decimal mcb = prevMclRma - mcm_off; - mcbList.Add(mcb); + mcbList.AddRounded(mcb); decimal scmm = (sct + scb) / 2; - scmmList.Add(scmm); + scmmList.AddRounded(scmm); decimal mcmm = (mct + mcb) / 2; - mcmmList.Add(mcmm); + mcmmList.AddRounded(mcmm); decimal omed = mct - mcb != 0 ? (scmm - mcb) / (mct - mcb) : 0; - omedList.Add(omed); + omedList.AddRounded(omed); decimal oshort = mct - mcb != 0 ? (currentValue - mcb) / (mct - mcb) : 0; - oshortList.Add(oshort); + oshortList.AddRounded(oshort); var signal = GetBullishBearishSignal(currentValue - sct, prevValue - prevSct, currentValue - scb, prevValue - prevScb); signalsList.Add(signal); @@ -1011,38 +1011,38 @@ public static StockData CalculateHurstBands(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevCma1 = i >= 1 ? cmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevCma2 = i >= 2 ? cmaList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevCma1 = i >= 1 ? cmaList[i - 1] : 0; + decimal prevCma2 = i >= 2 ? cmaList[i - 2] : 0; - decimal dPrice = i >= displacement ? inputList.ElementAtOrDefault(i - displacement) : 0; - dPriceList.Add(dPrice); + decimal dPrice = i >= displacement ? inputList[i - displacement] : 0; + dPriceList.AddRounded(dPrice); decimal cma = dPrice == 0 ? prevCma1 + (prevCma1 - prevCma2) : dPriceList.TakeLastExt(length).Average(); - cmaList.Add(cma); + cmaList.AddRounded(cma); decimal extremeBand = cma * extremeMult / 100; decimal outerBand = cma * outerMult / 100; decimal innerBand = cma * innerMult / 100; decimal upperExtremeBand = cma + extremeBand; - upperExtremeBandList.Add(upperExtremeBand); + upperExtremeBandList.AddRounded(upperExtremeBand); decimal lowerExtremeBand = cma - extremeBand; - lowerExtremeBandList.Add(lowerExtremeBand); + lowerExtremeBandList.AddRounded(lowerExtremeBand); decimal upperInnerBand = cma + innerBand; - upperInnerBandList.Add(upperInnerBand); + upperInnerBandList.AddRounded(upperInnerBand); decimal lowerInnerBand = cma - innerBand; - lowerInnerBandList.Add(lowerInnerBand); + lowerInnerBandList.AddRounded(lowerInnerBand); decimal upperOuterBand = cma + outerBand; - upperOuterBandList.Add(upperOuterBand); + upperOuterBandList.AddRounded(upperOuterBand); decimal lowerOuterBand = cma - outerBand; - lowerOuterBandList.Add(lowerOuterBand); + lowerOuterBandList.AddRounded(lowerOuterBand); var signal = GetCompareSignal(currentValue - cma, prevValue - prevCma1); signalsList.Add(signal); @@ -1090,14 +1090,14 @@ public static StockData CalculateHirashimaSugitaRS(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal ema = emaList[i]; decimal d1 = currentValue - ema; - d1List.Add(d1); + d1List.AddRounded(d1); decimal absD1 = Math.Abs(d1); - absD1List.Add(absD1); + absD1List.AddRounded(absD1); } var wmaList = GetMovingAverageList(stockData, maType, length, absD1List); @@ -1105,42 +1105,42 @@ public static StockData CalculateHirashimaSugitaRS(this StockData stockData, Mov var s1List = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal ema = emaList.ElementAtOrDefault(i); - decimal s1 = s1List.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal ema = emaList[i]; + decimal s1 = s1List[i]; + decimal currentValue = inputList[i]; decimal x = ema + s1; decimal d2 = currentValue - x; - d2List.Add(d2); + d2List.AddRounded(d2); } stockData.CustomValuesList = d2List; var s2List = CalculateLinearRegression(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal ema = emaList.ElementAtOrDefault(i); - decimal s1 = s1List.ElementAtOrDefault(i); - decimal s2 = s2List.ElementAtOrDefault(i); - decimal prevS2 = i >= 1 ? s2List.ElementAtOrDefault(i - 1) : 0; - decimal wma = wmaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal ema = emaList[i]; + decimal s1 = s1List[i]; + decimal s2 = s2List[i]; + decimal prevS2 = i >= 1 ? s2List[i - 1] : 0; + decimal wma = wmaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevBasis = basisList.LastOrDefault(); decimal basis = ema + s1 + (s2 - prevS2); - basisList.Add(basis); + basisList.AddRounded(basis); decimal upper1 = basis + wma; - upper1List.Add(upper1); + upper1List.AddRounded(upper1); decimal lower1 = basis - wma; - lower1List.Add(lower1); + lower1List.AddRounded(lower1); decimal upper2 = upper1 + wma; - upper2List.Add(upper2); + upper2List.AddRounded(upper2); decimal lower2 = lower1 - wma; - lower2List.Add(lower2); + lower2List.AddRounded(lower2); var signal = GetCompareSignal(currentValue - basis, prevValue - prevBasis); signalsList.Add(signal); @@ -1181,34 +1181,34 @@ public static StockData CalculateFlaggingBands(this StockData stockData, int len for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal prevA1 = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevB1 = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : currentValue; - decimal prevB2 = i >= 2 ? bList.ElementAtOrDefault(i - 2) : currentValue; - decimal prevA3 = i >= 3 ? aList.ElementAtOrDefault(i - 3) : currentValue; - decimal prevB3 = i >= 3 ? bList.ElementAtOrDefault(i - 3) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal stdDev = stdDevList[i]; + decimal prevA1 = i >= 1 ? aList[i - 1] : currentValue; + decimal prevB1 = i >= 1 ? bList[i - 1] : currentValue; + decimal prevA2 = i >= 2 ? aList[i - 2] : currentValue; + decimal prevB2 = i >= 2 ? bList[i - 2] : currentValue; + decimal prevA3 = i >= 3 ? aList[i - 3] : currentValue; + decimal prevB3 = i >= 3 ? bList[i - 3] : currentValue; decimal l = stdDev != 0 ? (decimal)1 / length * stdDev : 0; decimal a = currentValue > prevA1 ? prevA1 + (currentValue - prevA1) : prevA2 == prevA3 ? prevA2 - l : prevA2; - aList.Add(a); + aList.AddRounded(a); decimal b = currentValue < prevB1 ? prevB1 + (currentValue - prevB1) : prevB2 == prevB3 ? prevB2 + l : prevB2; - bList.Add(b); + bList.AddRounded(b); decimal prevTos = tosList.LastOrDefault(); decimal tos = currentValue > prevA2 ? 1 : currentValue < prevB2 ? 0 : prevTos; - tosList.Add(tos); + tosList.AddRounded(tos); decimal prevTavg = tavgList.LastOrDefault(); decimal avg = (a + b) / 2; decimal tavg = tos == 1 ? (a + avg) / 2 : (b + avg) / 2; - tavgList.Add(tavg); + tavgList.AddRounded(tavg); decimal ts = (tos * b) + ((1 - tos) * a); - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - tavg, prevValue - prevTavg); signalsList.Add(signal); @@ -1252,14 +1252,14 @@ public static StockData CalculateKirshenbaumBands(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - tempInputList.Add(currentValue); + decimal currentValue = inputList[i]; + tempInputList.AddRounded(currentValue); - decimal currentLinReg = linRegList.ElementAtOrDefault(i); - tempLinRegList.Add(currentLinReg); + decimal currentLinReg = linRegList[i]; + tempLinRegList.AddRounded(currentLinReg); var stdError = GoodnessOfFit.PopulationStandardError(tempLinRegList.TakeLastExt(length2).Select(x => (double)x), tempInputList.TakeLastExt(length2).Select(x => (double)x)); @@ -1268,11 +1268,11 @@ public static StockData CalculateKirshenbaumBands(this StockData stockData, Movi decimal prevTop = topList.LastOrDefault(); decimal top = currentEma + ratio; - topList.Add(top); + topList.AddRounded(top); decimal prevBottom = bottomList.LastOrDefault(); decimal bottom = currentEma - ratio; - bottomList.Add(bottom); + bottomList.AddRounded(bottom); var signal = GetBullishBearishSignal(currentValue - top, prevValue - prevTop, currentValue - bottom, prevValue - prevBottom); signalsList.Add(signal); @@ -1311,26 +1311,26 @@ public static StockData CalculateKaufmanAdaptiveBands(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal er = Pow(erList.ElementAtOrDefault(i), stdDevFactor); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal er = Pow(erList[i], stdDevFactor); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (currentValue * er) + ((1 - er) * prevMiddleBand); - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); decimal prevPowMa = powMaList.LastOrDefault(); decimal powMa = (Pow(currentValue, 2) * er) + ((1 - er) * prevPowMa); - powMaList.Add(powMa); + powMaList.AddRounded(powMa); decimal kaufmanDev = powMa - Pow(middleBand, 2) >= 0 ? Sqrt(powMa - Pow(middleBand, 2)) : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + kaufmanDev; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = middleBand - kaufmanDev; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -1373,20 +1373,20 @@ public static StockData CalculateKeltnerChannels(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentEma20Day = emaList.ElementAtOrDefault(i); - decimal currentAtr10Day = atrList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentEma20Day = emaList[i]; + decimal currentAtr10Day = atrList[i]; decimal upperChannel = currentEma20Day + (multFactor * currentAtr10Day); - upperChannelList.Add(upperChannel); + upperChannelList.AddRounded(upperChannel); decimal lowerChannel = currentEma20Day - (multFactor * currentAtr10Day); - lowerChannelList.Add(lowerChannel); + lowerChannelList.AddRounded(lowerChannel); decimal prevMidChannel = midChannelList.LastOrDefault(); decimal midChannel = (upperChannel + lowerChannel) / 2; - midChannelList.Add(midChannel); + midChannelList.AddRounded(midChannel); var signal = GetCompareSignal(currentValue - midChannel, prevValue - prevMidChannel); signalsList.Add(signal); @@ -1425,25 +1425,25 @@ public static StockData CalculateVortexBands(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal basis = basisList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal basis = basisList[i]; + decimal currentValue = inputList[i]; decimal diff = currentValue - basis; - diffList.Add(diff); + diffList.AddRounded(diff); } var diffMaList = GetMovingAverageList(stockData, maType, length, diffList); for (int i = 0; i < stockData.Count; i++) { - decimal diffMa = diffMaList.ElementAtOrDefault(i); - decimal basis = basisList.ElementAtOrDefault(i); + decimal diffMa = diffMaList[i]; + decimal basis = basisList[i]; decimal dev = 2 * diffMa; decimal upper = basis + dev; - upperList.Add(upper); + upperList.AddRounded(upper); decimal lower = basis - dev; - lowerList.Add(lower); + lowerList.AddRounded(lower); var signal = GetConditionSignal(upper > lower && upper > basis, lower > upper && lower > basis); signalsList.Add(signal); @@ -1482,31 +1482,31 @@ public static StockData CalculateVolumeAdaptiveBands(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal a = Math.Max(aList.ElementAtOrDefault(i), 1); + decimal currentValue = inputList[i]; + decimal a = Math.Max(aList[i], 1); decimal b = a * -1; - decimal prevUp = i >= 1 ? upList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevUp = i >= 1 ? upList[i - 1] : currentValue; decimal up = a != 0 ? (prevUp + (currentValue * a)) / a : 0; - upList.Add(up); + upList.AddRounded(up); - decimal prevDn = i >= 1 ? dnList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevDn = i >= 1 ? dnList[i - 1] : currentValue; decimal dn = b != 0 ? (prevDn + (currentValue * b)) / b : 0; - dnList.Add(dn); + 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++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal upperBand = upSmaList.ElementAtOrDefault(i); - decimal lowerBand = dnSmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal upperBand = upSmaList[i]; + decimal lowerBand = dnSmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (upperBand + lowerBand) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetCompareSignal(currentValue - middleBand, prevValue - prevMiddleBand); signalsList.Add(signal); @@ -1546,20 +1546,20 @@ public static StockData CalculateVariableMovingAverageBands(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal vma = maList.ElementAtOrDefault(i); - decimal prevVma = i >= 1 ? maList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentAtr = atrList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal vma = maList[i]; + decimal prevVma = i >= 1 ? maList[i - 1] : 0; decimal o = mult * currentAtr; decimal prevUband = ubandList.LastOrDefault(); decimal uband = vma + o; - ubandList.Add(uband); + ubandList.AddRounded(uband); decimal prevLband = lbandList.LastOrDefault(); decimal lband = vma - o; - lbandList.Add(lband); + lbandList.AddRounded(lband); var signal = GetBollingerBandsSignal(currentValue - vma, prevValue - prevVma, currentValue, prevValue, uband, prevUband, lband, prevLband); signalsList.Add(signal); @@ -1605,43 +1605,43 @@ public static StockData CalculateVervoortVolatilityBands(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal medianAvg = medianAvgList.ElementAtOrDefault(i); - tempList.Add(medianAvg); + decimal medianAvg = medianAvgList[i]; + tempList.AddRounded(medianAvg); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentLow = lowList[i]; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal typical = currentValue >= prevValue ? currentValue - prevLow : prevValue - currentLow; - typicalList.Add(typical); + typicalList.AddRounded(typical); decimal typicalSma = typicalList.TakeLastExt(length2).Average(); decimal deviation = devMult * typicalSma; - deviationList.Add(deviation); + deviationList.AddRounded(deviation); decimal medianAvgSma = tempList.TakeLastExt(length1).Average(); - medianAvgSmaList.Add(medianAvgSma); + medianAvgSmaList.AddRounded(medianAvgSma); } var devHighList = GetMovingAverageList(stockData, maType, length1, deviationList); for (int i = 0; i < stockData.Count; i++) { - decimal devHigh = devHighList.ElementAtOrDefault(i); - decimal midline = medianAvgSmaList.ElementAtOrDefault(i); - decimal medianAvgEma = medianAvgEmaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMidline = i >= 1 ? medianAvgSmaList.ElementAtOrDefault(i - 1) : 0; + decimal devHigh = devHighList[i]; + decimal midline = medianAvgSmaList[i]; + decimal medianAvgEma = medianAvgEmaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMidline = i >= 1 ? medianAvgSmaList[i - 1] : 0; decimal devLow = lowBandMult * devHigh; decimal prevUb = ubList.LastOrDefault(); decimal ub = medianAvgEma + devHigh; - ubList.Add(ub); + ubList.AddRounded(ub); decimal prevLb = lbList.LastOrDefault(); decimal lb = medianAvgEma - devLow; - lbList.Add(lb); + lbList.AddRounded(lb); var signal = GetBollingerBandsSignal(currentValue - midline, prevValue - prevMidline, currentValue, prevValue, ub, prevUb, lb, prevLb); signalsList.Add(signal); @@ -1680,29 +1680,29 @@ public static StockData CalculatePriceHeadleyAccelerationBands(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal mult = currentHigh + currentLow != 0 ? 4 * factor * 1000 * (currentHigh - currentLow) / (currentHigh + currentLow) : 0; decimal outerUb = currentHigh * (1 + mult); - ubList.Add(outerUb); + ubList.AddRounded(outerUb); decimal outerLb = currentLow * (1 - mult); - lbList.Add(outerLb); + 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++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal middleBand = middleBandList.ElementAtOrDefault(i); - decimal prevMiddleBand = i >= 1 ? middleBandList.ElementAtOrDefault(i - 1) : 0; - decimal outerUbSma = suList.ElementAtOrDefault(i); - decimal prevOuterUbSma = i >= 1 ? suList.ElementAtOrDefault(i - 1) : 0; - decimal outerLbSma = slList.ElementAtOrDefault(i); - decimal prevOuterLbSma = i >= 1 ? slList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal middleBand = middleBandList[i]; + decimal prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; + decimal outerUbSma = suList[i]; + decimal prevOuterUbSma = i >= 1 ? suList[i - 1] : 0; + decimal outerLbSma = slList[i]; + decimal prevOuterLbSma = i >= 1 ? slList[i - 1] : 0; var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, outerUbSma, prevOuterUbSma, outerLbSma, prevOuterLbSma); @@ -1744,43 +1744,43 @@ public static StockData CalculatePseudoPolynomialChannel(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal y = inputList.ElementAtOrDefault(i); - decimal prevK = i >= length ? kList.ElementAtOrDefault(i - length) : y; - decimal prevK2 = i >= length * 2 ? kList.ElementAtOrDefault(i - (length * 2)) : y; - decimal prevIndex = i >= length ? indexList.ElementAtOrDefault(i - length) : 0; - decimal prevIndex2 = i >= length * 2 ? indexList.ElementAtOrDefault(i - (length * 2)) : 0; + decimal y = inputList[i]; + decimal prevK = i >= length ? kList[i - length] : y; + decimal prevK2 = i >= length * 2 ? kList[i - (length * 2)] : y; + decimal prevIndex = i >= length ? indexList[i - length] : 0; + decimal prevIndex2 = i >= length * 2 ? indexList[i - (length * 2)] : 0; decimal ky = (morph * prevK) + ((1 - morph) * y); decimal ky2 = (morph * prevK2) + ((1 - morph) * y); decimal index = i; - indexList.Add(i); + indexList.AddRounded(i); decimal k = prevIndex2 - prevIndex != 0 ? ky + ((index - prevIndex) / (prevIndex2 - prevIndex) * (ky2 - ky)) : 0; - kList.Add(k); + kList.AddRounded(k); } var k1List = GetMovingAverageList(stockData, maType, length, kList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal k1 = k1List.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal k1 = k1List[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal yk1 = Math.Abs(currentValue - k1); - yK1List.Add(yk1); + yK1List.AddRounded(yk1); decimal er = i != 0 ? yK1List.Sum() / i : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = k1 + er; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = k1 - er; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (upperBand + lowerBand) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -1819,27 +1819,27 @@ public static StockData CalculateProjectedSupportAndResistance(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; decimal range = highestHigh - lowestLow; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal support1 = lowestLow - (0.25m * range); - support1List.Add(support1); + support1List.AddRounded(support1); decimal support2 = lowestLow - (0.5m * range); - support2List.Add(support2); + support2List.AddRounded(support2); decimal resistance1 = highestHigh + (0.25m * range); - resistance1List.Add(resistance1); + resistance1List.AddRounded(resistance1); decimal resistance2 = highestHigh + (0.5m * range); - resistance2List.Add(resistance2); + resistance2List.AddRounded(resistance2); decimal prevMiddle = middleList.LastOrDefault(); decimal middle = (support1 + support2 + resistance1 + resistance2) / 4; - middleList.Add(middle); + middleList.AddRounded(middle); var signal = GetCompareSignal(currentValue - middle, prevValue - prevMiddle); signalsList.Add(signal); @@ -1880,12 +1880,12 @@ public static StockData CalculatePrimeNumberBands(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal prevUpBand1 = i >= 1 ? upperBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevUpBand2 = i >= 2 ? upperBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevDnBand1 = i >= 1 ? lowerBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevDnBand2 = i >= 2 ? lowerBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal close = inputList[i]; + decimal prevUpBand1 = i >= 1 ? upperBandList[i - 1] : 0; + decimal prevUpBand2 = i >= 2 ? upperBandList[i - 1] : 0; + decimal prevDnBand1 = i >= 1 ? lowerBandList[i - 1] : 0; + decimal prevDnBand2 = i >= 2 ? lowerBandList[i - 1] : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; var signal = GetBullishBearishSignal(close - prevUpBand1, prevClose - prevUpBand2, close - prevDnBand1, prevClose - prevDnBand2); signalsList.Add(signal); @@ -1936,30 +1936,30 @@ public static StockData CalculatePeriodicChannel(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { decimal prevValue = tempList.LastOrDefault(); - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal index = i; - indexList.Add(index); + indexList.AddRounded(index); decimal indexCum = i != 0 ? indexList.Sum() / i : 0; decimal indexCumDiff = i - indexCum; decimal absIndexCumDiff = Math.Abs(i - indexCum); - absIndexCumDiffList.Add(absIndexCumDiff); + absIndexCumDiffList.AddRounded(absIndexCumDiff); decimal absIndexCum = i != 0 ? absIndexCumDiffList.Sum() / i : 0; decimal 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.Add((decimal)corr); + corrList.AddRounded((decimal)corr); decimal s = i * Math.Sign(corrList.Sum()); decimal sin = Sin(s / length1); - sinList.Add(sin); + sinList.AddRounded(sin); decimal inSin = Sin(s / length1) * -1; - inSinList.Add(inSin); + inSinList.AddRounded(inSin); decimal sinCum = i != 0 ? sinList.Sum() / i : 0; decimal inSinCum = i != 0 ? inSinList.Sum() / i : 0; @@ -1967,11 +1967,11 @@ public static StockData CalculatePeriodicChannel(this StockData stockData, int l decimal inSinCumDiff = inSin - inSinCum; decimal absSinCumDiff = Math.Abs(sin - sinCum); - absSinCumDiffList.Add(absSinCumDiff); + absSinCumDiffList.AddRounded(absSinCumDiff); decimal absSinCum = i != 0 ? absSinCumDiffList.Sum() / i : 0; decimal absInSinCumDiff = Math.Abs(inSin - inSinCum); - absInSinCumDiffList.Add(absInSinCumDiff); + absInSinCumDiffList.AddRounded(absInSinCumDiff); decimal absInSinCum = i != 0 ? absInSinCumDiffList.Sum() / i : 0; decimal zs = absSinCum != 0 ? sinCumDiff / absSinCum : 0; @@ -1979,38 +1979,38 @@ public static StockData CalculatePeriodicChannel(this StockData stockData, int l decimal cum = i != 0 ? tempList.Sum() / i : 0; decimal absDiff = Math.Abs(currentValue - cum); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal absDiffCum = i != 0 ? absDiffList.Sum() / i : 0; decimal prevK = kList.LastOrDefault(); decimal k = cum + ((z + zs) * absDiffCum); - kList.Add(k); + kList.AddRounded(k); decimal inK = cum + ((z + inZs) * absDiffCum); decimal absKDiff = Math.Abs(currentValue - k); - absKDiffList.Add(absKDiff); + absKDiffList.AddRounded(absKDiff); decimal absInKDiff = Math.Abs(currentValue - inK); decimal os = i != 0 ? absKDiffList.Sum() / i : 0; - osList.Add(os); + osList.AddRounded(os); decimal ap = k + os; - apList.Add(ap); + apList.AddRounded(ap); decimal bp = ap + os; - bpList.Add(bp); + bpList.AddRounded(bp); decimal cp = bp + os; - cpList.Add(cp); + cpList.AddRounded(cp); decimal al = k - os; - alList.Add(al); + alList.AddRounded(al); decimal bl = al - os; - blList.Add(bl); + blList.AddRounded(bl); decimal cl = bl - os; - clList.Add(cl); + clList.AddRounded(cl); var signal = GetCompareSignal(currentValue - k, prevValue - prevK); signalsList.Add(signal); @@ -2057,35 +2057,35 @@ public static StockData CalculatePriceLineChannel(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal atr = atrList.ElementAtOrDefault(i); - decimal prevA1 = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevB1 = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : 0; - decimal prevB2 = i >= 2 ? bList.ElementAtOrDefault(i - 2) : 0; - decimal prevSizeA = i >= 1 ? sizeAList.ElementAtOrDefault(i - 1) : atr / length; - decimal prevSizeB = i >= 1 ? sizeBList.ElementAtOrDefault(i - 1) : atr / length; - decimal prevSizeC = i >= 1 ? sizeCList.ElementAtOrDefault(i - 1) : atr / length; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal atr = atrList[i]; + decimal prevA1 = i >= 1 ? aList[i - 1] : currentValue; + decimal prevB1 = i >= 1 ? bList[i - 1] : currentValue; + decimal prevA2 = i >= 2 ? aList[i - 2] : 0; + decimal prevB2 = i >= 2 ? bList[i - 2] : 0; + decimal prevSizeA = i >= 1 ? sizeAList[i - 1] : atr / length; + decimal prevSizeB = i >= 1 ? sizeBList[i - 1] : atr / length; + decimal prevSizeC = i >= 1 ? sizeCList[i - 1] : atr / length; decimal sizeA = prevA1 - prevA2 > 0 ? atr : prevSizeA; - sizeAList.Add(sizeA); + sizeAList.AddRounded(sizeA); decimal sizeB = prevB1 - prevB2 < 0 ? atr : prevSizeB; - sizeBList.Add(sizeB); + sizeBList.AddRounded(sizeB); decimal sizeC = prevA1 - prevA2 > 0 || prevB1 - prevB2 < 0 ? atr : prevSizeC; - sizeCList.Add(sizeC); + sizeCList.AddRounded(sizeC); decimal a = Math.Max(currentValue, prevA1) - (sizeA / length); - aList.Add(a); + aList.AddRounded(a); decimal b = Math.Min(currentValue, prevB1) + (sizeB / length); - bList.Add(b); + bList.AddRounded(b); decimal prevMid = midList.LastOrDefault(); decimal mid = (a + b) / 2; - midList.Add(mid); + midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); signalsList.Add(signal); @@ -2127,23 +2127,23 @@ public static StockData CalculatePriceCurveChannel(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal atr = atrList.ElementAtOrDefault(i); - decimal prevA1 = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevB1 = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : 0; - decimal prevB2 = i >= 2 ? bList.ElementAtOrDefault(i - 2) : 0; - decimal prevSize = i >= 1 ? sizeList.ElementAtOrDefault(i - 1) : atr / length; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal atr = atrList[i]; + decimal prevA1 = i >= 1 ? aList[i - 1] : currentValue; + decimal prevB1 = i >= 1 ? bList[i - 1] : currentValue; + decimal prevA2 = i >= 2 ? aList[i - 2] : 0; + decimal prevB2 = i >= 2 ? bList[i - 2] : 0; + decimal prevSize = i >= 1 ? sizeList[i - 1] : atr / length; decimal size = prevA1 - prevA2 > 0 || prevB1 - prevB2 < 0 ? atr : prevSize; - sizeList.Add(size); + sizeList.AddRounded(size); decimal aChg = prevA1 > prevA2 ? 1 : 0; - aChgList.Add(aChg); + aChgList.AddRounded(aChg); decimal bChg = prevB1 < prevB2 ? 1 : 0; - bChgList.Add(bChg); + bChgList.AddRounded(bChg); int maxIndexA = aChgList.LastIndexOf(1); int maxIndexB = bChgList.LastIndexOf(1); @@ -2151,14 +2151,14 @@ public static StockData CalculatePriceCurveChannel(this StockData stockData, Mov int barsSinceB = bChgList.Count - 1 - maxIndexB; decimal a = Math.Max(currentValue, prevA1) - (size / Pow(length, 2) * (barsSinceA + 1)); - aList.Add(a); + aList.AddRounded(a); decimal b = Math.Min(currentValue, prevB1) + (size / Pow(length, 2) * (barsSinceB + 1)); - bList.Add(b); + bList.AddRounded(b); decimal prevMid = midList.LastOrDefault(); decimal mid = (a + b) / 2; - midList.Add(mid); + midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); signalsList.Add(signal); @@ -2198,31 +2198,31 @@ public static StockData CalculateProjectionBands(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevPu = i >= 1 ? puList.ElementAtOrDefault(i - 1) : 0; - decimal prevPl = i >= 1 ? plList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevPu = i >= 1 ? puList[i - 1] : 0; + decimal prevPl = i >= 1 ? plList[i - 1] : 0; decimal pu = currentHigh, pl = currentLow; - for (int j = 0; j < length; j++) + for (int j = 1; j <= length; j++) { - decimal highSlope = i >= j ? highSlopeList.ElementAtOrDefault(i - j) : 0; - decimal lowSlope = i >= j ? lowSlopeList.ElementAtOrDefault(i - j) : 0; - decimal pHigh = i >= j + 1 ? highList.ElementAtOrDefault(i - (j + 1)) : 0; - decimal pLow = i >= j + 1 ? lowList.ElementAtOrDefault(i - (j + 1)) : 0; + decimal highSlope = i >= j ? highSlopeList[i - j] : 0; + decimal lowSlope = i >= j ? lowSlopeList[i - j] : 0; + decimal pHigh = i >= j - 1 ? highList[i - (j - 1)] : 0; + decimal pLow = i >= j - 1 ? lowList[i - (j - 1)] : 0; decimal vHigh = pHigh + (highSlope * j); decimal vLow = pLow + (lowSlope * j); pu = Math.Max(pu, vHigh); pl = Math.Min(pl, vLow); } - puList.Add(pu); - plList.Add(pl); + puList.AddRounded(pu); + plList.AddRounded(pl); decimal prevMiddleBand = middleBandList.LastOrDefault(); decimal middleBand = (pu + pl) / 2; - middleBandList.Add(middleBand); + middleBandList.AddRounded(middleBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, pu, prevPu, pl, prevPl); signalsList.Add(signal); @@ -2264,33 +2264,33 @@ public static StockData CalculateTrendTraderBands(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal close = inputList.ElementAtOrDefault(i); - decimal prevHighest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowest = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal prevAtr = i >= 1 ? atrList.ElementAtOrDefault(i - 1) : 0; + decimal close = inputList[i]; + decimal prevHighest = i >= 1 ? highestList[i - 1] : 0; + decimal prevLowest = i >= 1 ? lowestList[i - 1] : 0; + decimal prevAtr = i >= 1 ? atrList[i - 1] : 0; decimal atrMult = prevAtr * mult; decimal highLimit = prevHighest - atrMult; decimal lowLimit = prevLowest + atrMult; decimal ret = close > highLimit && close > lowLimit ? highLimit : close < lowLimit && close < highLimit ? lowLimit : retList.LastOrDefault(); - retList.Add(ret); + retList.AddRounded(ret); } var retEmaList = GetMovingAverageList(stockData, maType, length, retList); for (int i = 0; i < stockData.Count; i++) { - decimal retEma = retEmaList.ElementAtOrDefault(i); - decimal close = inputList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevRetEma = i >= 1 ? retEmaList.ElementAtOrDefault(i - 1) : 0; + decimal retEma = retEmaList[i]; + decimal close = inputList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevRetEma = i >= 1 ? retEmaList[i - 1] : 0; decimal prevOuterUpperBand = outerUpperBandList.LastOrDefault(); decimal outerUpperBand = retEma + bandStep; - outerUpperBandList.Add(outerUpperBand); + outerUpperBandList.AddRounded(outerUpperBand); decimal prevOuterLowerBand = outerLowerBandList.LastOrDefault(); decimal outerLowerBand = retEma - bandStep; - outerLowerBandList.Add(outerLowerBand); + outerLowerBandList.AddRounded(outerLowerBand); var signal = GetBollingerBandsSignal(close - retEma, prevClose - prevRetEma, close, prevClose, outerUpperBand, prevOuterUpperBand, outerLowerBand, prevOuterLowerBand); @@ -2340,57 +2340,57 @@ public static StockData CalculateTimeAndMoneyChannel(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevBasis = i >= halfLength ? smaList.ElementAtOrDefault(i - halfLength) : 0; + decimal currentValue = inputList[i]; + decimal prevBasis = i >= halfLength ? smaList[i - halfLength] : 0; decimal yom = prevBasis != 0 ? 100 * (currentValue - prevBasis) / prevBasis : 0; - yomList.Add(yom); + yomList.AddRounded(yom); decimal yomSquared = Pow(yom, 2); - yomSquaredList.Add(yomSquared); + 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++) { - decimal prevVaryom = i >= halfLength ? varyomList.ElementAtOrDefault(i - halfLength) : 0; - decimal avyom = avyomList.ElementAtOrDefault(i); - decimal yomSquaredSma = yomSquaredSmaList.ElementAtOrDefault(i); + decimal prevVaryom = i >= halfLength ? varyomList[i - halfLength] : 0; + decimal avyom = avyomList[i]; + decimal yomSquaredSma = yomSquaredSmaList[i]; decimal varyom = yomSquaredSma - (avyom * avyom); - varyomList.Add(varyom); + varyomList.AddRounded(varyom); decimal som = prevVaryom >= 0 ? Sqrt(prevVaryom) : 0; - somList.Add(som); + somList.AddRounded(som); } var sigomList = GetMovingAverageList(stockData, maType, length1, somList); for (int i = 0; i < stockData.Count; i++) { - decimal som = somList.ElementAtOrDefault(i); - decimal prevSom = i >= 1 ? somList.ElementAtOrDefault(i - 1) : 0; - decimal sigom = sigomList.ElementAtOrDefault(i); - decimal prevSigom = i >= 1 ? sigomList.ElementAtOrDefault(i - 1) : 0; - decimal basis = smaList.ElementAtOrDefault(i); + decimal som = somList[i]; + decimal prevSom = i >= 1 ? somList[i - 1] : 0; + decimal sigom = sigomList[i]; + decimal prevSigom = i >= 1 ? sigomList[i - 1] : 0; + decimal basis = smaList[i]; decimal chPlus1 = basis * (1 + (0.01m * sigom)); - chPlus1List.Add(chPlus1); + chPlus1List.AddRounded(chPlus1); decimal chMinus1 = basis * (1 - (0.01m * sigom)); - chMinus1List.Add(chMinus1); + chMinus1List.AddRounded(chMinus1); decimal chPlus2 = basis * (1 + (0.02m * sigom)); - chPlus2List.Add(chPlus2); + chPlus2List.AddRounded(chPlus2); decimal chMinus2 = basis * (1 - (0.02m * sigom)); - chMinus2List.Add(chMinus2); + chMinus2List.AddRounded(chMinus2); decimal chPlus3 = basis * (1 + (0.03m * sigom)); - chPlus3List.Add(chPlus3); + chPlus3List.AddRounded(chPlus3); decimal chMinus3 = basis * (1 - (0.03m * sigom)); - chMinus3List.Add(chMinus3); + chMinus3List.AddRounded(chMinus3); var signal = GetCompareSignal(som - sigom, prevSom - prevSigom); signalsList.Add(signal); @@ -2435,35 +2435,35 @@ public static StockData CalculateTironeLevels(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal hh = highestList.ElementAtOrDefault(i); - decimal ll = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal hh = highestList[i]; + decimal ll = lowestList[i]; decimal tlh = hh - ((hh - ll) / 3); - tlhList.Add(tlh); + tlhList.AddRounded(tlh); decimal clh = ll + ((hh - ll) / 2); - clhList.Add(clh); + clhList.AddRounded(clh); decimal blh = ll + ((hh - ll) / 3); - blhList.Add(blh); + blhList.AddRounded(blh); decimal prevAm = amList.LastOrDefault(); decimal am = (hh + ll + currentValue) / 3; - amList.Add(am); + amList.AddRounded(am); decimal eh = am + (hh - ll); - ehList.Add(eh); + ehList.AddRounded(eh); decimal el = am - (hh - ll); - elList.Add(el); + elList.AddRounded(el); decimal rh = (2 * am) - ll; - rhList.Add(rh); + rhList.AddRounded(rh); decimal rl = (2 * am) - hh; - rlList.Add(rl); + rlList.AddRounded(rl); var signal = GetCompareSignal(currentValue - am, prevValue - prevAm); signalsList.Add(signal); @@ -2505,22 +2505,22 @@ public static StockData CalculateTimeSeriesForecast(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ts = tsList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevTs = i >= 1 ? tsList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal ts = tsList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevTs = i >= 1 ? tsList[i - 1] : 0; decimal absDiff = Math.Abs(currentValue - ts); - absDiffList.Add(absDiff); + absDiffList.AddRounded(absDiff); decimal e = i != 0 ? absDiffList.Sum() / i : 0; decimal prevA = aList.LastOrDefault(); decimal a = ts + e; - aList.Add(a); + aList.AddRounded(a); decimal prevB = bList.LastOrDefault(); decimal b = ts - e; - bList.Add(b); + bList.AddRounded(b); var signal = GetBollingerBandsSignal(currentValue - ts, prevValue - prevTs, currentValue, prevValue, a, prevA, b, prevB); signalsList.Add(signal); @@ -2560,21 +2560,21 @@ public static StockData CalculateRangeBands(this StockData stockData, decimal st for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = smaList[i]; + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; decimal rangeDev = highest - lowest; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (rangeDev * stdDevFactor); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = middleBand - (rangeDev * stdDevFactor); - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -2610,22 +2610,22 @@ public static StockData CalculateRangeIdentifier(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal prevUp = upList.LastOrDefault(); decimal prevDown = downList.LastOrDefault(); decimal up = currentValue < prevUp && currentValue > prevDown ? prevUp : currentHigh; - upList.Add(up); + upList.AddRounded(up); decimal down = currentValue < prevUp && currentValue > prevDown ? prevDown : currentLow; - downList.Add(down); + downList.AddRounded(down); decimal prevMid = midList.LastOrDefault(); decimal mid = (up + down) / 2; - midList.Add(mid); + midList.AddRounded(mid); var signal = GetCompareSignal(currentValue - mid, prevValue - prevMid); signalsList.Add(signal); @@ -2665,22 +2665,22 @@ public static StockData CalculateRateOfChangeBands(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal roc = rocList.ElementAtOrDefault(i); - decimal middleBand = middleBandList.ElementAtOrDefault(i); - decimal prevMiddleBand1 = i >= 1 ? middleBandList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand2 = i >= 2 ? middleBandList.ElementAtOrDefault(i - 2) : 0; + decimal roc = rocList[i]; + decimal middleBand = middleBandList[i]; + decimal prevMiddleBand1 = i >= 1 ? middleBandList[i - 1] : 0; + decimal prevMiddleBand2 = i >= 2 ? middleBandList[i - 2] : 0; decimal rocSquared = Pow(roc, 2); - rocSquaredList.Add(rocSquared); + rocSquaredList.AddRounded(rocSquared); decimal squaredAvg = rocSquaredList.TakeLastExt(length).Average(); decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = Sqrt(squaredAvg); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = -upperBand; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(middleBand - prevMiddleBand1, prevMiddleBand1 - prevMiddleBand2, middleBand, prevMiddleBand1, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -2721,30 +2721,30 @@ public static StockData CalculateRootMovingAverageSquaredErrorBands(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal sma = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal sma = smaList[i]; + decimal currentValue = inputList[i]; decimal pow = Pow(currentValue - sma, 2); - powList.Add(pow); + powList.AddRounded(pow); } var powSmaList = GetMovingAverageList(stockData, maType, length, powList); for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal powSma = powSmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = smaList[i]; + decimal currentValue = inputList[i]; + decimal powSma = powSmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; decimal rmaseDev = Sqrt(powSma); decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (rmaseDev * stdDevFactor); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = middleBand - (rmaseDev * stdDevFactor); - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -2787,23 +2787,23 @@ public static StockData CalculateMovingAverageBands(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal fastMa = fastMaList.ElementAtOrDefault(i); - decimal slowMa = slowMaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevFastMa = i >= 1 ? fastMaList.ElementAtOrDefault(i - 1) : 0; + decimal fastMa = fastMaList[i]; + decimal slowMa = slowMaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevFastMa = i >= 1 ? fastMaList[i - 1] : 0; decimal sq = Pow(slowMa - fastMa, 2); - sqList.Add(sq); + sqList.AddRounded(sq); decimal dev = Sqrt(sqList.TakeLastExt(fastLength).Average()) * mult; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = slowMa + dev; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = slowMa - dev; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - fastMa, prevValue - prevFastMa, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -2845,16 +2845,16 @@ public static StockData CalculateMovingAverageSupportResistance(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentSma = smaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal top = currentSma * supportLevel; - topList.Add(top); + topList.AddRounded(top); decimal bottom = supportLevel != 0 ? currentSma / supportLevel : 0; - bottomList.Add(bottom); + bottomList.AddRounded(bottom); var signal = GetCompareSignal(currentValue - currentSma, prevValue - prevSma); signalsList.Add(signal); @@ -2895,37 +2895,37 @@ public static StockData CalculateMotionToAttractionChannels(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevAMa = i >= 1 ? aMaList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevBMa = i >= 1 ? bMaList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevAMa = i >= 1 ? aMaList[i - 1] : currentValue; + decimal prevBMa = i >= 1 ? bMaList[i - 1] : currentValue; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; decimal a = currentValue > prevAMa ? currentValue : prevA; - aList.Add(a); + aList.AddRounded(a); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; decimal b = currentValue < prevBMa ? currentValue : prevB; - bList.Add(b); + bList.AddRounded(b); decimal prevC = cList.LastOrDefault(); decimal c = b - prevB != 0 ? prevC + alpha : a - prevA != 0 ? 0 : prevC; - cList.Add(c); + cList.AddRounded(c); decimal prevD = dList.LastOrDefault(); decimal d = a - prevA != 0 ? prevD + alpha : b - prevB != 0 ? 0 : prevD; - dList.Add(d); + dList.AddRounded(d); decimal avg = (a + b) / 2; decimal aMa = (c * avg) + ((1 - c) * a); - aMaList.Add(aMa); + aMaList.AddRounded(aMa); decimal bMa = (d * avg) + ((1 - d) * b); - bMaList.Add(bMa); + bMaList.AddRounded(bMa); decimal prevAvgMa = avgMaList.LastOrDefault(); decimal avgMa = (aMa + bMa) / 2; - avgMaList.Add(avgMa); + avgMaList.AddRounded(avgMa); var signal = GetCompareSignal(currentValue - avgMa, prevValue - prevAvgMa); signalsList.Add(signal); @@ -2965,22 +2965,22 @@ public static StockData CalculateMeanAbsoluteErrorBands(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = smaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; decimal dev = Math.Abs(currentValue - middleBand); - devList.Add(dev); + devList.AddRounded(dev); decimal maeDev = i != 0 ? devList.Sum() / i : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (maeDev * stdDevFactor); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = middleBand - (maeDev * stdDevFactor); - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -3021,19 +3021,19 @@ public static StockData CalculateMeanAbsoluteDeviationBands(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal middleBand = smaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentStdDeviation = devList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal middleBand = smaList[i]; + decimal currentValue = inputList[i]; + decimal currentStdDeviation = devList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? smaList[i - 1] : 0; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = middleBand + (currentStdDeviation * stdDevFactor); - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = middleBand - (currentStdDeviation * stdDevFactor); - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -3075,21 +3075,21 @@ public static StockData CalculateMovingAverageDisplacedEnvelope(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= length2 ? emaList.ElementAtOrDefault(i - length2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= length2 ? emaList[i - length2] : 0; decimal prevUpperEnvelope = upperEnvelopeList.LastOrDefault(); decimal upperEnvelope = prevEma * ((100 + pct) / 100); - upperEnvelopeList.Add(upperEnvelope); + upperEnvelopeList.AddRounded(upperEnvelope); decimal prevLowerEnvelope = lowerEnvelopeList.LastOrDefault(); decimal lowerEnvelope = prevEma * ((100 - pct) / 100); - lowerEnvelopeList.Add(lowerEnvelope); + lowerEnvelopeList.AddRounded(lowerEnvelope); decimal prevMiddleEnvelope = middleEnvelopeList.LastOrDefault(); decimal middleEnvelope = (upperEnvelope + lowerEnvelope) / 2; - middleEnvelopeList.Add(middleEnvelope); + middleEnvelopeList.AddRounded(middleEnvelope); var signal = GetBollingerBandsSignal(currentValue - middleEnvelope, prevValue - prevMiddleEnvelope, currentValue, prevValue, upperEnvelope, prevUpperEnvelope, lowerEnvelope, prevLowerEnvelope); @@ -3130,10 +3130,10 @@ public static StockData CalculateDema2Lines(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal dema1 = dema1List.ElementAtOrDefault(i); - decimal dema2 = dema2List.ElementAtOrDefault(i); - decimal prevDema1 = i >= 1 ? dema1List.ElementAtOrDefault(i - 1) : 0; - decimal prevDema2 = i >= 1 ? dema2List.ElementAtOrDefault(i - 1) : 0; + decimal dema1 = dema1List[i]; + decimal dema2 = dema2List[i]; + decimal prevDema1 = i >= 1 ? dema1List[i - 1] : 0; + decimal prevDema2 = i >= 1 ? dema2List[i - 1] : 0; var signal = GetCompareSignal(dema1 - dema2, prevDema1 - prevDema2); signalsList.Add(signal); @@ -3174,21 +3174,21 @@ public static StockData CalculateDynamicSupportAndResistance(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentAvgTrueRange = atrList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentAvgTrueRange = atrList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal support = highestHigh - (currentAvgTrueRange * mult); - supportList.Add(support); + supportList.AddRounded(support); decimal resistance = lowestLow + (currentAvgTrueRange * mult); - resistanceList.Add(resistance); + resistanceList.AddRounded(resistance); decimal prevMiddle = middleList.LastOrDefault(); decimal middle = (support + resistance) / 2; - middleList.Add(middle); + middleList.AddRounded(middle); var signal = GetCompareSignal(currentValue - middle, prevValue - prevMiddle); signalsList.Add(signal); @@ -3226,19 +3226,19 @@ public static StockData CalculateDailyAveragePriceDelta(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal high = highList.ElementAtOrDefault(i); - decimal low = lowList.ElementAtOrDefault(i); - decimal highSma = smaHighList.ElementAtOrDefault(i); - decimal lowSma = smaLowList.ElementAtOrDefault(i); + decimal high = highList[i]; + decimal low = lowList[i]; + decimal highSma = smaHighList[i]; + decimal lowSma = smaLowList[i]; decimal dapd = highSma - lowSma; decimal prevTop = topList.LastOrDefault(); decimal top = high + dapd; - topList.Add(top); + topList.AddRounded(top); decimal prevBottom = bottomList.LastOrDefault(); decimal bottom = low - dapd; - bottomList.Add(bottom); + bottomList.AddRounded(bottom); var signal = GetConditionSignal(high > prevTop, low < prevBottom); signalsList.Add(signal); @@ -3279,37 +3279,37 @@ public static StockData CalculateDEnvelope(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevMt = mtList.LastOrDefault(); decimal mt = (alp * currentValue) + ((1 - alp) * prevMt); - mtList.Add(mt); + mtList.AddRounded(mt); decimal prevUt = utList.LastOrDefault(); decimal ut = (alp * mt) + ((1 - alp) * prevUt); - utList.Add(ut); + utList.AddRounded(ut); decimal prevDt = dtList.LastOrDefault(); decimal dt = (2 - alp) * (mt - ut) / (1 - alp); - dtList.Add(dt); + dtList.AddRounded(dt); decimal prevMt2 = mt2List.LastOrDefault(); decimal mt2 = (alp * Math.Abs(currentValue - dt)) + ((1 - alp) * prevMt2); - mt2List.Add(mt2); + mt2List.AddRounded(mt2); decimal prevUt2 = ut2List.LastOrDefault(); decimal ut2 = (alp * mt2) + ((1 - alp) * prevUt2); - ut2List.Add(ut2); + ut2List.AddRounded(ut2); decimal dt2 = (2 - alp) * (mt2 - ut2) / (1 - alp); decimal prevBut = butList.LastOrDefault(); decimal but = dt + (devFactor * dt2); - butList.Add(but); + butList.AddRounded(but); decimal prevBlt = bltList.LastOrDefault(); decimal blt = dt - (devFactor * dt2); - bltList.Add(blt); + bltList.AddRounded(blt); var signal = GetBollingerBandsSignal(currentValue - dt, prevValue - prevDt, currentValue, prevValue, but, prevBut, blt, prevBlt); signalsList.Add(signal); @@ -3347,29 +3347,29 @@ public static StockData CalculateSmartEnvelope(this StockData stockData, int len for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; decimal prevASignal = aSignalList.LastOrDefault(); decimal prevBSignal = bSignalList.LastOrDefault(); decimal diff = Math.Abs(currentValue - prevValue); decimal a = Math.Max(currentValue, prevA) - (Math.Min(Math.Abs(currentValue - prevA), diff) / length * prevASignal); - aList.Add(a); + aList.AddRounded(a); decimal b = Math.Min(currentValue, prevB) + (Math.Min(Math.Abs(currentValue - prevB), diff) / length * prevBSignal); - bList.Add(b); + bList.AddRounded(b); decimal aSignal = b < prevB ? -factor : factor; - aSignalList.Add(aSignal); + aSignalList.AddRounded(aSignal); decimal bSignal = a > prevA ? -factor : factor; - bSignalList.Add(bSignal); + bSignalList.AddRounded(bSignal); decimal prevAvg = avgList.LastOrDefault(); decimal avg = (a + b) / 2; - avgList.Add(avg); + avgList.AddRounded(avg); var signal = GetCompareSignal(currentValue - avg, prevValue - prevAvg); signalsList.Add(signal); @@ -3407,21 +3407,21 @@ public static StockData CalculateSupportResistance(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal sma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal sma = i >= 1 ? smaList[i - 1] : 0; bool crossAbove = prevValue < sma && currentValue >= sma; bool crossBelow = prevValue > sma && currentValue <= sma; decimal prevRes = resList.LastOrDefault(); decimal res = crossBelow ? highest : i >= 1 ? prevRes : highest; - resList.Add(res); + resList.AddRounded(res); decimal prevSupp = suppList.LastOrDefault(); decimal supp = crossAbove ? lowest : i >= 1 ? prevSupp : lowest; - suppList.Add(supp); + suppList.AddRounded(supp); var signal = GetBullishBearishSignal(currentValue - res, prevValue - prevRes, currentValue - supp, prevValue - prevSupp); signalsList.Add(signal); @@ -3458,31 +3458,31 @@ public static StockData CalculateStationaryExtrapolatedLevels(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal priorY = i >= length ? yList.ElementAtOrDefault(i - length) : 0; - decimal priorY2 = i >= length * 2 ? yList.ElementAtOrDefault(i - (length * 2)) : 0; - decimal priorX = i >= length ? xList.ElementAtOrDefault(i - length) : 0; - decimal priorX2 = i >= length * 2 ? xList.ElementAtOrDefault(i - (length * 2)) : 0; + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal priorY = i >= length ? yList[i - length] : 0; + decimal priorY2 = i >= length * 2 ? yList[i - (length * 2)] : 0; + decimal priorX = i >= length ? xList[i - length] : 0; + decimal priorX2 = i >= length * 2 ? xList[i - (length * 2)] : 0; decimal x = i; - xList.Add(i); + xList.AddRounded(i); decimal y = currentValue - sma; - yList.Add(y); + yList.AddRounded(y); decimal ext = priorX2 - priorX != 0 && priorY2 - priorY != 0 ? (priorY + ((x - priorX) / (priorX2 - priorX) * (priorY2 - priorY))) / 2 : 0; - extList.Add(ext); + extList.AddRounded(ext); } var (highestList1, lowestList1) = GetMaxAndMinValuesList(extList, length); var (upperBandList, lowerBandList) = GetMaxAndMinValuesList(highestList1, lowestList1, length); for (int i = 0; i < stockData.Count; i++) { - decimal y = yList.ElementAtOrDefault(i); - decimal ext = extList.ElementAtOrDefault(i); - decimal prevY = i >= 1 ? yList.ElementAtOrDefault(i - 1) : 0; - decimal prevExt = i >= 1 ? extList.ElementAtOrDefault(i - 1) : 0; + decimal y = yList[i]; + decimal ext = extList[i]; + decimal prevY = i >= 1 ? yList[i - 1] : 0; + decimal prevExt = i >= 1 ? extList[i - 1] : 0; var signal = GetCompareSignal(y - ext, prevY - prevExt); signalsList.Add(signal); @@ -3522,14 +3522,14 @@ public static StockData CalculateScalpersChannel(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentSma = smaList[i]; + decimal currentAtr = atrList[i]; decimal prevScalper = scalperList.LastOrDefault(); decimal scalper = Pi * currentAtr > 0 ? currentSma - Log(Pi * currentAtr) : currentSma; - scalperList.Add(scalper); + scalperList.AddRounded(scalper); var signal = GetCompareSignal(currentValue - scalper, prevValue - prevScalper); signalsList.Add(signal); @@ -3574,21 +3574,21 @@ public static StockData CalculateSmoothedVolatilityBands(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal atr = atrList.ElementAtOrDefault(i); - decimal middleBand = middleBandList.ElementAtOrDefault(i); - decimal ma = maList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMiddleBand = i >= 1 ? middleBandList.ElementAtOrDefault(i - 1) : 0; + decimal atr = atrList[i]; + decimal middleBand = middleBandList[i]; + decimal ma = maList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMiddleBand = i >= 1 ? middleBandList[i - 1] : 0; decimal atrBuf = atr * deviation; decimal prevUpperBand = upperBandList.LastOrDefault(); decimal upperBand = currentValue != 0 ? ma + (ma * atrBuf / currentValue) : ma; - upperBandList.Add(upperBand); + upperBandList.AddRounded(upperBand); decimal prevLowerBand = lowerBandList.LastOrDefault(); decimal lowerBand = currentValue != 0 ? ma - (ma * atrBuf * bandAdjust / currentValue) : ma; - lowerBandList.Add(lowerBand); + lowerBandList.AddRounded(lowerBand); var signal = GetBollingerBandsSignal(currentValue - middleBand, prevValue - prevMiddleBand, currentValue, prevValue, upperBand, prevUpperBand, lowerBand, prevLowerBand); @@ -3626,20 +3626,20 @@ public static StockData CalculateExtendedRecursiveBands(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevAClassic = i >= 1 ? aClassicList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevBClassic = i >= 1 ? bClassicList.ElementAtOrDefault(i - 1) : currentValue; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevAClassic = i >= 1 ? aClassicList[i - 1] : currentValue; + decimal prevBClassic = i >= 1 ? bClassicList[i - 1] : currentValue; decimal aClassic = Math.Max(prevAClassic, currentValue) - (sc * Math.Abs(currentValue - prevAClassic)); - aClassicList.Add(aClassic); + aClassicList.AddRounded(aClassic); decimal bClassic = Math.Min(prevBClassic, currentValue) + (sc * Math.Abs(currentValue - prevBClassic)); - bClassicList.Add(bClassic); + bClassicList.AddRounded(bClassic); decimal prevCClassic = cClassicList.LastOrDefault(); decimal cClassic = (aClassic + bClassic) / 2; - cClassicList.Add(cClassic); + cClassicList.AddRounded(cClassic); var signal = GetCompareSignal(currentValue - cClassic, prevValue - prevCClassic); signalsList.Add(signal); @@ -3679,10 +3679,10 @@ public static StockData CalculateEfficientTrendStepChannel(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal val2 = currentValue * 2; - val2List.Add(val2); + val2List.AddRounded(val2); } stockData.CustomValuesList = val2List; @@ -3691,24 +3691,24 @@ public static StockData CalculateEfficientTrendStepChannel(this StockData stockD var stdDevSlowList = CalculateStandardDeviationVolatility(stockData, length: slowLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal er = erList.ElementAtOrDefault(i); - decimal fastStdDev = stdDevFastList.ElementAtOrDefault(i); - decimal slowStdDev = stdDevSlowList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal er = erList[i]; + decimal fastStdDev = stdDevFastList[i]; + decimal slowStdDev = stdDevSlowList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal dev = (er * fastStdDev) + ((1 - er) * slowStdDev); decimal a = currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; - aList.Add(a); + aList.AddRounded(a); decimal prevUpper = upperList.LastOrDefault(); decimal upper = a + dev; - upperList.Add(upper); + upperList.AddRounded(upper); decimal prevLower = lowerList.LastOrDefault(); decimal lower = a - dev; - lowerList.Add(lower); + lowerList.AddRounded(lower); var signal = GetBollingerBandsSignal(currentValue - a, prevValue - prevA, currentValue, prevValue, upper, prevUpper, lower, prevLower); signalsList.Add(signal); diff --git a/Calculations/Ratio.cs b/Calculations/Ratio.cs index f70a9e5..1c1e539 100644 --- a/Calculations/Ratio.cs +++ b/Calculations/Ratio.cs @@ -26,14 +26,14 @@ public static StockData CalculateMartinRatio(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; - benchList.Add(bench); + benchList.AddRounded(bench); decimal ret = prevValue != 0 ? (100 * (currentValue / prevValue)) - 1 - (bench * 100) : 0; - retList.Add(ret); + retList.AddRounded(ret); } var retSmaList = GetMovingAverageList(stockData, maType, length, retList); @@ -41,12 +41,12 @@ public static StockData CalculateMartinRatio(this StockData stockData, MovingAvg var ulcerIndexList = CalculateUlcerIndex(stockData, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal ulcerIndex = ulcerIndexList.ElementAtOrDefault(i); - decimal retSma = retSmaList.ElementAtOrDefault(i); + decimal ulcerIndex = ulcerIndexList[i]; + decimal retSma = retSmaList[i]; decimal prevMartin = martinList.LastOrDefault(); decimal martin = ulcerIndex != 0 ? retSma / ulcerIndex : 0; - martinList.Add(martin); + martinList.AddRounded(martin); var signal = GetCompareSignal(martin - 2, prevMartin - 2); signalsList.Add(signal); @@ -84,24 +84,24 @@ public static StockData CalculateUpsidePotentialRatio(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; - retList.Add(ret); + retList.AddRounded(ret); decimal downSide = 0, upSide = 0; for (int j = 0; j < length; j++) { - decimal iValue = i >= j ? retList.ElementAtOrDefault(i - j) : 0; + decimal iValue = i >= j ? retList[i - j] : 0; downSide += iValue < bench ? Pow(iValue - bench, 2) * ratio : 0; upSide += iValue > bench ? (iValue - bench) * ratio : 0; } decimal prevUpsidePotential = upsidePotentialList.LastOrDefault(); decimal upsidePotential = downSide >= 0 ? upSide / Sqrt(downSide) : 0; - upsidePotentialList.Add(upsidePotential); + upsidePotentialList.AddRounded(upsidePotential); var signal = GetCompareSignal(upsidePotential - 5, prevUpsidePotential - 5); signalsList.Add(signal); @@ -139,11 +139,11 @@ public static StockData CalculateInformationRatio(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; - retList.Add(ret); + retList.AddRounded(ret); } stockData.CustomValuesList = retList; @@ -151,13 +151,13 @@ public static StockData CalculateInformationRatio(this StockData stockData, Movi var retSmaList = GetMovingAverageList(stockData, maType, length, retList); for (int i = 0; i < stockData.Count; i++) { - decimal stdDeviation = stdDevList.ElementAtOrDefault(i); - decimal retSma = retSmaList.ElementAtOrDefault(i); + decimal stdDeviation = stdDevList[i]; + decimal retSma = retSmaList[i]; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; decimal prevInfo = infoList.LastOrDefault(); decimal info = stdDeviation != 0 ? (retSma - bench) / stdDeviation : 0; - infoList.Add(info); + infoList.AddRounded(info); var signal = GetCompareSignal(info - 5, prevInfo - 5); signalsList.Add(signal); @@ -194,24 +194,24 @@ public static StockData CalculateOmegaRatio(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; - retList.Add(ret); + retList.AddRounded(ret); decimal downSide = 0, upSide = 0; for (int j = 0; j < length; j++) { - decimal iValue = i >= j ? retList.ElementAtOrDefault(i - j) : 0; + decimal iValue = i >= j ? retList[i - j] : 0; downSide += iValue < bench ? bench - iValue : 0; upSide += iValue > bench ? iValue - bench : 0; } decimal prevOmega = omegaList.LastOrDefault(); decimal omega = downSide != 0 ? upSide / downSide : 0; - omegaList.Add(omega); + omegaList.AddRounded(omega); var signal = GetCompareSignal(omega - 5, prevOmega - 5); signalsList.Add(signal); @@ -248,21 +248,21 @@ public static StockData CalculateVolatilityRatio(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevHighest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowest = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal priorValue = i >= length + 1 ? inputList.ElementAtOrDefault(i - (length + 1)) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal prevHighest = i >= 1 ? highestList[i - 1] : 0; + decimal prevLowest = i >= 1 ? lowestList[i - 1] : 0; + decimal priorValue = i >= length + 1 ? inputList[i - (length + 1)] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); decimal max = priorValue != 0 ? Math.Max(prevHighest, priorValue) : prevHighest; decimal min = priorValue != 0 ? Math.Min(prevLowest, priorValue) : prevLowest; decimal vr = max - min != 0 ? tr / (max - min) : 0; - vrList.Add(vr); + vrList.AddRounded(vr); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, vr, breakoutLevel); signalsList.Add(signal); @@ -300,12 +300,12 @@ public static StockData CalculateCalmarRatio(this StockData stockData, int lengt for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; - decimal maxDn = highestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; + decimal maxDn = highestList[i]; decimal dd = maxDn != 0 ? (currentValue - maxDn) / maxDn : 0; - ddList.Add(dd); + ddList.AddRounded(dd); decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; decimal annualReturn = 1 + ret >= 0 ? Pow(1 + ret, power) - 1 : 0; @@ -313,7 +313,7 @@ public static StockData CalculateCalmarRatio(this StockData stockData, int lengt decimal prevCalmar = calmarList.LastOrDefault(); decimal calmar = maxDd != 0 ? annualReturn / Math.Abs(maxDd) : 0; - calmarList.Add(calmar); + calmarList.AddRounded(calmar); var signal = GetCompareSignal(calmar - 2, prevCalmar - 2); signalsList.Add(signal); @@ -349,17 +349,17 @@ public static StockData CalculateTreynorRatio(this StockData stockData, int leng for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; - retList.Add(ret); + retList.AddRounded(ret); decimal retSma = retList.TakeLastExt(length).Average(); decimal prevTreynor = treynorList.LastOrDefault(); decimal treynor = beta != 0 ? (retSma - bench) / beta : 0; - treynorList.Add(treynor); + treynorList.AddRounded(treynor); var signal = GetCompareSignal(treynor - 2, prevTreynor - 2); signalsList.Add(signal); @@ -397,35 +397,35 @@ public static StockData CalculateSortinoRatio(this StockData stockData, MovingAv for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 - bench : 0; - retList.Add(ret); + retList.AddRounded(ret); } var retSmaList = GetMovingAverageList(stockData, maType, length, retList); for (int i = 0; i < stockData.Count; i++) { - decimal ret = retList.ElementAtOrDefault(i); - decimal retSma = retSmaList.ElementAtOrDefault(i); + decimal ret = retList[i]; + decimal retSma = retSmaList[i]; decimal currentDeviation = Math.Min(ret - retSma, 0); decimal deviationSquared = Pow(currentDeviation, 2); - deviationSquaredList.Add(deviationSquared); + deviationSquaredList.AddRounded(deviationSquared); } var divisionOfSumList = GetMovingAverageList(stockData, maType, length, deviationSquaredList); for (int i = 0; i < stockData.Count; i++) { - decimal divisionOfSum = divisionOfSumList.ElementAtOrDefault(i); + decimal divisionOfSum = divisionOfSumList[i]; decimal stdDeviation = Sqrt(divisionOfSum); - decimal retSma = retSmaList.ElementAtOrDefault(i); + decimal retSma = retSmaList[i]; decimal prevSortino = sortinoList.LastOrDefault(); decimal sortino = stdDeviation != 0 ? retSma / stdDeviation : 0; - sortinoList.Add(sortino); + sortinoList.AddRounded(sortino); var signal = GetCompareSignal(sortino - 2, prevSortino - 2); signalsList.Add(signal); @@ -462,12 +462,12 @@ public static StockData CalculateSharpeRatio(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal bench = Pow(1 + bmk, length / barsPerYr) - 1; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 - bench : 0; - retList.Add(ret); + retList.AddRounded(ret); } var retSmaList = GetMovingAverageList(stockData, maType, length, retList); @@ -475,12 +475,12 @@ public static StockData CalculateSharpeRatio(this StockData stockData, MovingAvg var stdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal stdDeviation = stdDevList.ElementAtOrDefault(i); - decimal retSma = retSmaList.ElementAtOrDefault(i); + decimal stdDeviation = stdDevList[i]; + decimal retSma = retSmaList[i]; decimal prevSharpe = sharpeList.LastOrDefault(); decimal sharpe = stdDeviation != 0 ? retSma / stdDeviation : 0; - sharpeList.Add(sharpe); + sharpeList.AddRounded(sharpe); var signal = GetCompareSignal(sharpe - 2, prevSharpe - 2); signalsList.Add(signal); @@ -516,17 +516,17 @@ public static StockData CalculateShinoharaIntensityRatio(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal high = highList.ElementAtOrDefault(i); - tempHighList.Add(high); + decimal high = highList[i]; + tempHighList.AddRounded(high); - decimal low = lowList.ElementAtOrDefault(i); - tempLowList.Add(low); + decimal low = lowList[i]; + tempLowList.AddRounded(low); - decimal open = openList.ElementAtOrDefault(i); - tempOpenList.Add(open); + decimal open = openList[i]; + tempOpenList.AddRounded(open); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - prevCloseList.Add(prevClose); + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + prevCloseList.AddRounded(prevClose); decimal highSum = tempHighList.TakeLastExt(length).Sum(); decimal lowSum = tempLowList.TakeLastExt(length).Sum(); @@ -539,11 +539,11 @@ public static StockData CalculateShinoharaIntensityRatio(this StockData stockDat decimal prevRatioA = ratioAList.LastOrDefault(); decimal ratioA = bearA != 0 ? bullA / bearA * 100 : 0; - ratioAList.Add(ratioA); + ratioAList.AddRounded(ratioA); decimal prevRatioB = ratioBList.LastOrDefault(); decimal ratioB = bearB != 0 ? bullB / bearB * 100 : 0; - ratioBList.Add(ratioB); + ratioBList.AddRounded(ratioB); var signal = GetCompareSignal(ratioA - ratioB, prevRatioA - prevRatioB); signalsList.Add(signal); diff --git a/Calculations/Rsi.cs b/Calculations/Rsi.cs index e40cdba..d35b053 100644 --- a/Calculations/Rsi.cs +++ b/Calculations/Rsi.cs @@ -23,8 +23,8 @@ public static StockData CalculateRelativeStrengthIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal priceChg = currentValue - prevValue; decimal loss = priceChg < 0 ? Math.Abs(priceChg) : 0; @@ -38,8 +38,8 @@ public static StockData CalculateRelativeStrengthIndex(this StockData stockData, var avgLossList = GetMovingAverageList(stockData, movingAvgType, length, lossList); for (int i = 0; i < stockData.Count; i++) { - decimal avgGain = avgGainList.ElementAtOrDefault(i); - decimal avgLoss = avgLossList.ElementAtOrDefault(i); + decimal avgGain = avgGainList[i]; + decimal avgLoss = avgLossList[i]; decimal rs = avgLoss != 0 ? MinOrMax(avgGain / avgLoss, 1, 0) : 0; rsList.AddRounded(rs); @@ -51,9 +51,9 @@ public static StockData CalculateRelativeStrengthIndex(this StockData stockData, var rsiSignalList = GetMovingAverageList(stockData, movingAvgType, signalLength, rsiList); for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal rsiSignal = rsiSignalList.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; + decimal rsiSignal = rsiSignalList[i]; decimal prevRsiHistogram = rsiHistogramList.LastOrDefault(); decimal rsiHistogram = rsi - rsiSignal; @@ -100,35 +100,35 @@ public static StockData CalculateConnorsRelativeStrengthIndex(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal roc = rocList.ElementAtOrDefault(i); - tempList.Add(roc); + decimal roc = rocList[i]; + tempList.AddRounded(roc); var lookBackList = tempList.TakeLastExt(length3).Take(length3 - 1).ToList(); int count = lookBackList.Where(x => x <= roc).Count(); decimal pctRank = MinOrMax((decimal)count / length3 * 100, 100, 0); - pctRankList.Add(pctRank); + pctRankList.AddRounded(pctRank); decimal prevStreak = streakList.LastOrDefault(); decimal streak = currentValue > prevValue ? prevStreak >= 0 ? prevStreak + 1 : 1 : currentValue < prevValue ? prevStreak <= 0 ? prevStreak - 1 : -1 : 0; - streakList.Add(streak); + streakList.AddRounded(streak); } stockData.CustomValuesList = streakList; var rsiStreakList = CalculateRelativeStrengthIndex(stockData, maType, length1, length1).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentRsi = rsiList.ElementAtOrDefault(i); - decimal percentRank = pctRankList.ElementAtOrDefault(i); - decimal streakRsi = rsiStreakList.ElementAtOrDefault(i); - decimal prevConnorsRsi1 = i >= 1 ? connorsRsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevConnorsRsi2 = i >= 2 ? connorsRsiList.ElementAtOrDefault(i - 2) : 0; + decimal currentRsi = rsiList[i]; + decimal percentRank = pctRankList[i]; + decimal streakRsi = rsiStreakList[i]; + decimal prevConnorsRsi1 = i >= 1 ? connorsRsiList[i - 1] : 0; + decimal prevConnorsRsi2 = i >= 2 ? connorsRsiList[i - 2] : 0; decimal connorsRsi = MinOrMax((currentRsi + percentRank + streakRsi) / 3, 100, 0); - connorsRsiList.Add(connorsRsi); + connorsRsiList.AddRounded(connorsRsi); var signal = GetRsiSignal(connorsRsi - prevConnorsRsi1, prevConnorsRsi1 - prevConnorsRsi2, connorsRsi, prevConnorsRsi1, 70, 30); signalsList.Add(signal); @@ -165,13 +165,13 @@ public static StockData CalculateAsymmetricalRelativeStrengthIndex(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal prevArsi1 = i >= 1 ? arsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevArsi2 = i >= 2 ? arsiList.ElementAtOrDefault(i - 2) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevArsi1 = i >= 1 ? arsiList[i - 1] : 0; + decimal prevArsi2 = i >= 2 ? arsiList[i - 2] : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal roc = prevValue != 0 ? (currentValue - prevValue) / prevValue * 100 : 0; - rocList.Add(roc); + rocList.AddRounded(roc); decimal upCount = rocList.TakeLastExt(length).Where(x => x >= 0).Count(); decimal upAlpha = upCount != 0 ? 1 / upCount : 0; @@ -180,18 +180,18 @@ public static StockData CalculateAsymmetricalRelativeStrengthIndex(this StockDat decimal prevUpSum = upSumList.LastOrDefault(); decimal upSum = (upAlpha * posRoc) + ((1 - upAlpha) * prevUpSum); - upSumList.Add(upSum); + upSumList.AddRounded(upSum); decimal downCount = length - upCount; decimal downAlpha = downCount != 0 ? 1 / downCount : 0; decimal prevDownSum = downSumList.LastOrDefault(); decimal downSum = (downAlpha * negRoc) + ((1 - downAlpha) * prevDownSum); - downSumList.Add(downSum); + downSumList.AddRounded(downSum); decimal ars = downSum != 0 ? upSum / downSum : 0; decimal arsi = downSum == 0 ? 100 : upSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + ars)), 100, 0); - arsiList.Add(arsi); + arsiList.AddRounded(arsi); var signal = GetRsiSignal(arsi - prevArsi1, prevArsi1 - prevArsi2, arsi, prevArsi1, 70, 30); signalsList.Add(signal); @@ -226,14 +226,14 @@ public static StockData CalculateAdaptiveRelativeStrengthIndex(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal rsi = rsiList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal alpha = 2 * Math.Abs((rsi / 100) - 0.5m); decimal prevArsi = arsiList.LastOrDefault(); decimal arsi = (alpha * currentValue) + ((1 - alpha) * prevArsi); - arsiList.Add(arsi); + arsiList.AddRounded(arsi); var signal = GetCompareSignal(currentValue - arsi, prevValue - prevArsi); signalsList.Add(signal); @@ -267,25 +267,25 @@ public static StockData CalculateAverageAbsoluteErrorNormalization(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevY = i >= 1 ? yList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA1 = i >= 1 ? aList.ElementAtOrDefault(i - 1) : 0; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevY = i >= 1 ? yList[i - 1] : currentValue; + decimal prevA1 = i >= 1 ? aList[i - 1] : 0; + decimal prevA2 = i >= 2 ? aList[i - 2] : 0; decimal e = currentValue - prevY; - eList.Add(e); + eList.AddRounded(e); decimal eAbs = Math.Abs(e); - eAbsList.Add(eAbs); + eAbsList.AddRounded(eAbs); decimal eAbsSma = eAbsList.TakeLastExt(length).Average(); decimal eSma = eList.TakeLastExt(length).Average(); decimal a = eAbsSma != 0 ? MinOrMax(eSma / eAbsSma, 1, -1) : 0; - aList.Add(a); + aList.AddRounded(a); decimal y = currentValue + (a * eAbsSma); - yList.Add(y); + yList.AddRounded(y); var signal = GetRsiSignal(a - prevA1, prevA1 - prevA2, a, prevA1, 0.8m, -0.8m); signalsList.Add(signal); @@ -323,28 +323,28 @@ public static StockData CalculateApirineSlowRelativeStrengthIndex(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal r1 = emaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal r1 = emaList[i]; decimal r2 = currentValue > r1 ? currentValue - r1 : 0; - r2List.Add(r2); + r2List.AddRounded(r2); decimal r3 = currentValue < r1 ? r1 - currentValue : 0; - r3List.Add(r3); + 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++) { - decimal r4 = r4List.ElementAtOrDefault(i); - decimal r5 = r5List.ElementAtOrDefault(i); - decimal prevRr1 = i >= 1 ? rrList.ElementAtOrDefault(i - 1) : 0; - decimal prevRr2 = i >= 2 ? rrList.ElementAtOrDefault(i - 2) : 0; + decimal r4 = r4List[i]; + decimal r5 = r5List[i]; + decimal prevRr1 = i >= 1 ? rrList[i - 1] : 0; + decimal prevRr2 = i >= 2 ? rrList[i - 2] : 0; decimal rs = r5 != 0 ? r4 / r5 : 0; decimal rr = r5 == 0 ? 100 : r4 == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); - rrList.Add(rr); + rrList.AddRounded(rr); var signal = GetRsiSignal(rr - prevRr1, prevRr1 - prevRr2, rr, prevRr1, 70, 30); signalsList.Add(signal); @@ -382,36 +382,36 @@ public static StockData CalculateBreakoutRelativeStrengthIndex(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevBrsi1 = i >= 1 ? brsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevBrsi2 = i >= 2 ? brsiList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = closeList[i]; + decimal currentOpen = openList[i]; + decimal prevBrsi1 = i >= 1 ? brsiList[i - 1] : 0; + decimal prevBrsi2 = i >= 2 ? brsiList[i - 2] : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - tempList.Add(currentVolume); + decimal currentVolume = volumeList[i]; + tempList.AddRounded(currentVolume); decimal boVolume = tempList.TakeLastExt(lbLength).Sum(); decimal boStrength = currentHigh - currentLow != 0 ? (currentClose - currentOpen) / (currentHigh - currentLow) : 0; decimal prevBoPower = boPowerList.LastOrDefault(); decimal boPower = currentValue * boStrength * boVolume; - boPowerList.Add(boPower); + boPowerList.AddRounded(boPower); decimal posPower = boPower > prevBoPower ? Math.Abs(boPower) : 0; - posPowerList.Add(posPower); + posPowerList.AddRounded(posPower); decimal negPower = boPower < prevBoPower ? Math.Abs(boPower) : 0; - negPowerList.Add(negPower); + negPowerList.AddRounded(negPower); decimal posPowerSum = posPowerList.TakeLastExt(length).Sum(); decimal negPowerSum = negPowerList.TakeLastExt(length).Sum(); decimal boRatio = negPowerSum != 0 ? posPowerSum / negPowerSum : 0; decimal brsi = negPowerSum == 0 ? 100 : posPowerSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + boRatio)), 100, 0); - brsiList.Add(brsi); + brsiList.AddRounded(brsi); var signal = GetRsiSignal(brsi - prevBrsi1, prevBrsi1 - prevBrsi2, brsi, prevBrsi1, 80, 20); signalsList.Add(signal); @@ -446,27 +446,27 @@ public static StockData CalculateLiquidRelativeStrengthIndex(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevVolume = i >= 1 ? volumeList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentVolume = volumeList[i]; + decimal prevVolume = i >= 1 ? volumeList[i - 1] : 0; decimal a = currentValue - prevValue; decimal b = currentVolume - prevVolume; - decimal prevC1 = i >= 1 ? cList.ElementAtOrDefault(i - 1) : 0; - decimal prevC2 = i >= 2 ? cList.ElementAtOrDefault(i - 2) : 0; + decimal prevC1 = i >= 1 ? cList[i - 1] : 0; + decimal prevC2 = i >= 2 ? cList[i - 2] : 0; decimal num = Math.Max(a, 0) * Math.Max(b, 0); decimal den = Math.Abs(a) * Math.Abs(b); decimal prevNumEma = numEmaList.LastOrDefault(); decimal numEma = (num * k) + (prevNumEma * (1 - k)); - numEmaList.Add(numEma); + numEmaList.AddRounded(numEma); decimal prevDenEma = denEmaList.LastOrDefault(); decimal denEma = (den * k) + (prevDenEma * (1 - k)); - denEmaList.Add(denEma); + denEmaList.AddRounded(denEma); decimal c = denEma != 0 ? MinOrMax(100 * numEma / denEma, 100, 0) : 0; - cList.Add(c); + cList.AddRounded(c); var signal = GetRsiSignal(c - prevC1, prevC1 - prevC2, c, prevC1, 80, 20); signalsList.Add(signal); @@ -501,22 +501,22 @@ public static StockData CalculateFoldedRelativeStrengthIndex(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); + decimal rsi = rsiList[i]; decimal absRsi = 2 * Math.Abs(rsi - 50); - absRsiList.Add(absRsi); + absRsiList.AddRounded(absRsi); decimal frsi = absRsiList.TakeLastExt(length).Sum(); - frsiList.Add(frsi); + frsiList.AddRounded(frsi); } var frsiMaList = GetMovingAverageList(stockData, maType, length, frsiList); for (int i = 0; i < stockData.Count; i++) { - decimal frsi = frsiList.ElementAtOrDefault(i); - decimal frsiMa = frsiMaList.ElementAtOrDefault(i); - decimal prevFrsi = i >= 1 ? frsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevFrsiMa = i >= 1 ? frsiMaList.ElementAtOrDefault(i - 1) : 0; + decimal frsi = frsiList[i]; + decimal frsiMa = frsiMaList[i]; + decimal prevFrsi = i >= 1 ? frsiList[i - 1] : 0; + decimal prevFrsiMa = i >= 1 ? frsiMaList[i - 1] : 0; var signal = GetRsiSignal(frsi - frsiMa, prevFrsi - prevFrsiMa, frsi, prevFrsi, 50, 10); signalsList.Add(signal); @@ -553,35 +553,35 @@ public static StockData CalculateVolumeWeightedRelativeStrengthIndex(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal volume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal volume = volumeList[i]; decimal max = Math.Max((currentValue - prevValue) * volume, 0); - maxList.Add(max); + maxList.AddRounded(max); decimal min = -Math.Min((currentValue - prevValue) * volume, 0); - minList.Add(min); + 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++) { - decimal up = upList.ElementAtOrDefault(i); - decimal dn = dnList.ElementAtOrDefault(i); + decimal up = upList[i]; + decimal dn = dnList[i]; decimal rsiRaw = dn == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + (up / dn))); decimal rsiScale = (rsiRaw * 2) - 100; - rsiScaledList.Add(rsiScale); + rsiScaledList.AddRounded(rsiScale); } var rsiList = GetMovingAverageList(stockData, maType, smoothLength, rsiScaledList); for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal prevRsi1 = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsi2 = i >= 2 ? rsiList.ElementAtOrDefault(i - 2) : 0; + decimal rsi = rsiList[i]; + decimal prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; + decimal prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; var signal = GetCompareSignal(rsi - prevRsi1, prevRsi1 - prevRsi2); signalsList.Add(signal); @@ -616,30 +616,30 @@ public static StockData CalculateRapidRelativeStrengthIndex(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal chg = currentValue - prevValue; decimal upChg = chg > 0 ? chg : 0; - upChgList.Add(upChg); + upChgList.AddRounded(upChg); decimal downChg = chg < 0 ? Math.Abs(chg) : 0; - downChgList.Add(downChg); + downChgList.AddRounded(downChg); decimal upChgSum = upChgList.TakeLastExt(length).Sum(); decimal downChgSum = downChgList.TakeLastExt(length).Sum(); decimal rs = downChgSum != 0 ? upChgSum / downChgSum : 0; decimal rapidRsi = downChgSum == 0 ? 100 : upChgSum == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); - rapidRsiList.Add(rapidRsi); + rapidRsiList.AddRounded(rapidRsi); } var rrsiEmaList = GetMovingAverageList(stockData, maType, length, rapidRsiList); for (int i = 0; i < stockData.Count; i++) { - decimal rapidRsi = rrsiEmaList.ElementAtOrDefault(i); - decimal prevRapidRsi1 = i >= 1 ? rrsiEmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevRapidRsi2 = i >= 2 ? rrsiEmaList.ElementAtOrDefault(i - 2) : 0; + decimal rapidRsi = rrsiEmaList[i]; + decimal prevRapidRsi1 = i >= 1 ? rrsiEmaList[i - 1] : 0; + decimal prevRapidRsi2 = i >= 2 ? rrsiEmaList[i - 2] : 0; var signal = GetRsiSignal(rapidRsi - prevRapidRsi1, prevRapidRsi1 - prevRapidRsi2, rapidRsi, prevRapidRsi1, 70, 30); signalsList.Add(signal); @@ -678,11 +678,11 @@ public static StockData CalculateRecursiveRelativeStrengthIndex(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal chg = currentValue - prevValue; - chgList.Add(chg); + chgList.AddRounded(chg); } var srcList = GetMovingAverageList(stockData, maType, length, chgList); @@ -690,18 +690,18 @@ public static StockData CalculateRecursiveRelativeStrengthIndex(this StockData s var rsiList = CalculateRelativeStrengthIndex(stockData, length: length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal src = srcList.ElementAtOrDefault(i); - decimal prevB1 = i >= 1 ? bList.ElementAtOrDefault(i - 1) : 0; - decimal prevB2 = i >= 2 ? bList.ElementAtOrDefault(i - 2) : 0; + decimal rsi = rsiList[i]; + decimal src = srcList[i]; + decimal prevB1 = i >= 1 ? bList[i - 1] : 0; + decimal prevB2 = i >= 2 ? bList[i - 2] : 0; decimal b = 0, avg = 0, gain = 0, loss = 0, avgRsi = 0; for (int j = 1; j <= length; j++) { - decimal prevB = i >= j ? bList.ElementAtOrDefault(i - j) : src; - decimal prevAvg = i >= j ? avgList.ElementAtOrDefault(i - j) : 0; - decimal prevGain = i >= j ? gainList.ElementAtOrDefault(i - j) : 0; - decimal prevLoss = i >= j ? lossList.ElementAtOrDefault(i - j) : 0; + decimal prevB = i >= j ? bList[i - j] : src; + decimal prevAvg = i >= j ? avgList[i - j] : 0; + decimal prevGain = i >= j ? gainList[i - j] : 0; + decimal prevLoss = i >= j ? lossList[i - j] : 0; decimal k = (decimal)j / length; decimal a = rsi * (decimal)length / j; avg = (a + prevB) / 2; @@ -714,11 +714,11 @@ public static StockData CalculateRecursiveRelativeStrengthIndex(this StockData s avgRsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 1, 0); b = avgRsiList.Count >= length ? avgRsiList.TakeLastExt(length).Average() : avgRsi; } - bList.Add(b); - avgList.Add(avg); - gainList.Add(gain); - lossList.Add(loss); - avgRsiList.Add(avgRsi); + bList.AddRounded(b); + avgList.AddRounded(avg); + gainList.AddRounded(gain); + lossList.AddRounded(loss); + avgRsiList.AddRounded(avgRsi); var signal = GetRsiSignal(b - prevB1, prevB1 - prevB2, b, prevB1, 0.8m, 0.2m); signalsList.Add(signal); @@ -755,36 +755,36 @@ public static StockData CalculateMomentaRelativeStrengthIndex(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal hc = highestList.ElementAtOrDefault(i); - decimal lc = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal hc = highestList[i]; + decimal lc = lowestList[i]; decimal srcLc = currentValue - lc; - srcLcList.Add(srcLc); + srcLcList.AddRounded(srcLc); decimal hcSrc = hc - currentValue; - hcSrcList.Add(hcSrc); + 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++) { - decimal top = topList.ElementAtOrDefault(i); - decimal bot = botList.ElementAtOrDefault(i); + decimal top = topList[i]; + decimal bot = botList[i]; decimal rs = bot != 0 ? MinOrMax(top / bot, 1, 0) : 0; decimal rsi = bot == 0 ? 100 : top == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); - rsiList.Add(rsi); + rsiList.AddRounded(rsi); } var rsiEmaList = GetMovingAverageList(stockData, maType, length2, rsiList); for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal rsiEma = rsiEmaList.ElementAtOrDefault(i); - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsiEma = i >= 1 ? rsiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal rsi = rsiList[i]; + decimal rsiEma = rsiEmaList[i]; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; + decimal prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; var signal = GetRsiSignal(rsi - rsiEma, prevRsi - prevRsiEma, rsi, prevRsi, 80, 20); signalsList.Add(signal); @@ -823,15 +823,15 @@ public static StockData CalculateDoubleSmoothedRelativeStrengthIndex(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal hc = highestList.ElementAtOrDefault(i); - decimal lc = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal hc = highestList[i]; + decimal lc = lowestList[i]; decimal srcLc = currentValue - lc; - srcLcList.Add(srcLc); + srcLcList.AddRounded(srcLc); decimal hcSrc = hc - currentValue; - hcSrcList.Add(hcSrc); + hcSrcList.AddRounded(hcSrc); } var topEma1List = GetMovingAverageList(stockData, maType, length2, srcLcList); @@ -840,21 +840,21 @@ public static StockData CalculateDoubleSmoothedRelativeStrengthIndex(this StockD var botEma2List = GetMovingAverageList(stockData, maType, length3, botEma1List); for (int i = 0; i < stockData.Count; i++) { - decimal top = topEma2List.ElementAtOrDefault(i); - decimal bot = botEma2List.ElementAtOrDefault(i); + decimal top = topEma2List[i]; + decimal bot = botEma2List[i]; decimal rs = bot != 0 ? MinOrMax(top / bot, 1, 0) : 0; decimal rsi = bot == 0 ? 100 : top == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 100, 0); - rsiList.Add(rsi); + rsiList.AddRounded(rsi); } var rsiEmaList = GetMovingAverageList(stockData, maType, length3, rsiList); for (int i = 0; i < stockData.Count; i++) { - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal rsiEma = rsiEmaList.ElementAtOrDefault(i); - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsiEma = i >= 1 ? rsiEmaList.ElementAtOrDefault(i - 1) : 0; + decimal rsi = rsiList[i]; + decimal rsiEma = rsiEmaList[i]; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; + decimal prevRsiEma = i >= 1 ? rsiEmaList[i - 1] : 0; var signal = GetRsiSignal(rsi - rsiEma, prevRsi - prevRsiEma, rsi, prevRsi, 80, 20); signalsList.Add(signal); @@ -890,26 +890,26 @@ public static StockData CalculateDominantCycleTunedRelativeStrengthIndex(this St for (int i = 0; i < stockData.Count; i++) { - decimal v1 = v1List.ElementAtOrDefault(i); + decimal v1 = v1List[i]; decimal p = v1 != 0 ? 1 / v1 : 0.07m; - decimal price = inputList.ElementAtOrDefault(i); - decimal prevPrice = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal price = inputList[i]; + decimal prevPrice = i >= 1 ? inputList[i - 1] : 0; decimal aChg = price > prevPrice ? Math.Abs(price - prevPrice) : 0; decimal bChg = price < prevPrice ? Math.Abs(price - prevPrice) : 0; - decimal prevRsi1 = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; - decimal prevRsi2 = i >= 2 ? rsiList.ElementAtOrDefault(i - 2) : 0; + decimal prevRsi1 = i >= 1 ? rsiList[i - 1] : 0; + decimal prevRsi2 = i >= 2 ? rsiList[i - 2] : 0; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : aChg; + decimal prevA = i >= 1 ? aList[i - 1] : aChg; decimal a = (p * aChg) + ((1 - p) * prevA); - aList.Add(a); + aList.AddRounded(a); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : bChg; + decimal prevB = i >= 1 ? bList[i - 1] : bChg; decimal b = (p * bChg) + ((1 - p) * prevB); - bList.Add(b); + bList.AddRounded(b); decimal r = b != 0 ? a / b : 0; decimal rsi = b == 0 ? 100 : a == 0 ? 0 : MinOrMax(100 - (100 / (1 + r)), 100, 0); - rsiList.Add(rsi); + rsiList.AddRounded(rsi); var signal = GetRsiSignal(rsi - prevRsi1, prevRsi1 - prevRsi2, rsi, prevRsi1, 70, 30); signalsList.Add(signal); @@ -949,18 +949,18 @@ public static StockData CalculateSelfAdjustingRelativeStrengthIndex(this StockDa for (int i = 0; i < stockData.Count; i++) { - decimal rsiStdDev = rsiStdDevList.ElementAtOrDefault(i); - decimal rsi = rsiList.ElementAtOrDefault(i); - decimal prevRsi = i >= 1 ? rsiList.ElementAtOrDefault(i - 1) : 0; + decimal rsiStdDev = rsiStdDevList[i]; + decimal rsi = rsiList[i]; + decimal prevRsi = i >= 1 ? rsiList[i - 1] : 0; decimal adjustingStdDev = mult * rsiStdDev; - decimal rsiSma = rsiSmaList.ElementAtOrDefault(i); - decimal prevRsiSma = i >= 1 ? rsiSmaList.ElementAtOrDefault(i - 1) : 0; + decimal rsiSma = rsiSmaList[i]; + decimal prevRsiSma = i >= 1 ? rsiSmaList[i - 1] : 0; decimal obStdDev = 50 + adjustingStdDev; - obList.Add(obStdDev); + obList.AddRounded(obStdDev); decimal osStdDev = 50 - adjustingStdDev; - osList.Add(osStdDev); + osList.AddRounded(osStdDev); var signal = GetRsiSignal(rsi - rsiSma, prevRsi - prevRsiSma, rsi, prevRsi, obStdDev, osStdDev); signalsList.Add(signal); @@ -1004,10 +1004,10 @@ public static StockData CalculateStochasticConnorsRelativeStrengthIndex(this Sto for (int i = 0; i < stockData.Count; i++) { - decimal smaK = fastDList.ElementAtOrDefault(i); - decimal smaD = slowDList.ElementAtOrDefault(i); - decimal prevSmak = i >= 1 ? fastDList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmad = i >= 1 ? slowDList.ElementAtOrDefault(i - 1) : 0; + decimal smaK = fastDList[i]; + decimal smaD = slowDList[i]; + decimal prevSmak = i >= 1 ? fastDList[i - 1] : 0; + decimal prevSmad = i >= 1 ? slowDList[i - 1] : 0; var signal = GetRsiSignal(smaK - smaD, prevSmak - prevSmad, smaK, prevSmak, 70, 30); signalsList.Add(signal); @@ -1065,20 +1065,20 @@ public static StockData CalculateCCTStochRSI(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal currentRSI5 = rsi5List.ElementAtOrDefault(i); - tempRsi5List.Add(currentRSI5); + decimal currentRSI5 = rsi5List[i]; + tempRsi5List.AddRounded(currentRSI5); - decimal currentRSI8 = rsi8List.ElementAtOrDefault(i); - tempRsi8List.Add(currentRSI8); + decimal currentRSI8 = rsi8List[i]; + tempRsi8List.AddRounded(currentRSI8); - decimal currentRSI13 = rsi13List.ElementAtOrDefault(i); - tempRsi13List.Add(currentRSI13); + decimal currentRSI13 = rsi13List[i]; + tempRsi13List.AddRounded(currentRSI13); - decimal currentRSI14 = rsi14List.ElementAtOrDefault(i); - tempRsi14List.Add(currentRSI14); + decimal currentRSI14 = rsi14List[i]; + tempRsi14List.AddRounded(currentRSI14); - decimal currentRSI21 = rsi21List.ElementAtOrDefault(i); - tempRsi21List.Add(currentRSI21); + decimal currentRSI21 = rsi21List[i]; + tempRsi21List.AddRounded(currentRSI21); decimal lowestX1 = tempRsi21List.TakeLastExt(length2).Min(); decimal lowestZ1 = tempRsi21List.TakeLastExt(length3).Min(); @@ -1102,25 +1102,25 @@ public static StockData CalculateCCTStochRSI(this StockData stockData, MovingAvg decimal highestCustom = tempRsi8List.TakeLastExt(length2).Max(); decimal stochRSI1 = highestY1 - lowestZ1 != 0 ? (currentRSI21 - lowestX1) / (highestY1 - lowestZ1) * 100 : 0; - type1List.Add(stochRSI1); + type1List.AddRounded(stochRSI1); decimal stochRSI2 = highestY2 - lowestZ2 != 0 ? (currentRSI21 - lowestX2) / (highestY2 - lowestZ2) * 100 : 0; - type2List.Add(stochRSI2); + type2List.AddRounded(stochRSI2); decimal stochRSI3 = highestY3 - lowestZ3 != 0 ? (currentRSI14 - lowestX3) / (highestY3 - lowestZ3) * 100 : 0; - type3List.Add(stochRSI3); + type3List.AddRounded(stochRSI3); decimal stochRSI4 = highestY4 - lowestZ4 != 0 ? (currentRSI21 - lowestX4) / (highestY4 - lowestZ4) * 100 : 0; - type4List.Add(stochRSI4); + type4List.AddRounded(stochRSI4); decimal stochRSI5 = highestY5 - lowestZ5 != 0 ? (currentRSI5 - lowestX5) / (highestY5 - lowestZ5) * 100 : 0; - type5List.Add(stochRSI5); + type5List.AddRounded(stochRSI5); decimal stochRSI6 = highestY6 - lowestZ6 != 0 ? (currentRSI13 - lowestX6) / (highestY6 - lowestZ6) * 100 : 0; - type6List.Add(stochRSI6); + type6List.AddRounded(stochRSI6); decimal stochCustom = highestCustom - lowestCustom != 0 ? (currentRSI8 - lowestCustom) / (highestCustom - lowestCustom) * 100 : 0; - typeCustomList.Add(stochCustom); + typeCustomList.AddRounded(stochCustom); } var rsiEma4List = GetMovingAverageList(stockData, maType, smoothLength2, type4List); @@ -1130,10 +1130,10 @@ public static StockData CalculateCCTStochRSI(this StockData stockData, MovingAvg var rsiSignalList = GetMovingAverageList(stockData, maType, signalLength, type1List); for (int i = 0; i < stockData.Count; i++) { - var rsi = type1List.ElementAtOrDefault(i); - var prevRsi = i >= 1 ? type1List.ElementAtOrDefault(i - 1) : 0; - var rsiSignal = rsiSignalList.ElementAtOrDefault(i); - var prevRsiSignal = i >= 1 ? rsiSignalList.ElementAtOrDefault(i - 1) : 0; + var rsi = type1List[i]; + var prevRsi = i >= 1 ? type1List[i - 1] : 0; + var rsiSignal = rsiSignalList[i]; + var prevRsiSignal = i >= 1 ? rsiSignalList[i - 1] : 0; var signal = GetRsiSignal(rsi - rsiSignal, prevRsi - prevRsiSignal, rsi, prevRsi, 90, 10); signalsList.Add(signal); @@ -1179,10 +1179,10 @@ public static StockData CalculateStochasticRelativeStrengthIndex(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentRSI = stochRsiList.ElementAtOrDefault(i); - decimal prevStochRsi = i >= 1 ? stochRsiList.ElementAtOrDefault(i - 1) : 0; - decimal currentRsiSignal = stochRsiSignalList.ElementAtOrDefault(i); - decimal prevRsiSignal = i >= 1 ? stochRsiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal currentRSI = stochRsiList[i]; + decimal prevStochRsi = i >= 1 ? stochRsiList[i - 1] : 0; + decimal currentRsiSignal = stochRsiSignalList[i]; + decimal prevRsiSignal = i >= 1 ? stochRsiSignalList[i - 1] : 0; var signal = GetRsiSignal(currentRSI - currentRsiSignal, prevStochRsi - prevRsiSignal, currentRSI, prevStochRsi, 80, 20); signalsList.Add(signal); diff --git a/Calculations/Stochastic.cs b/Calculations/Stochastic.cs index 5b38d3a..e76fac0 100644 --- a/Calculations/Stochastic.cs +++ b/Calculations/Stochastic.cs @@ -21,22 +21,22 @@ public static StockData CalculateStochasticOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; decimal fastK = highestHigh - lowestLow != 0 ? MinOrMax((currentValue - lowestLow) / (highestHigh - lowestLow) * 100, 100, 0) : 0; - fastKList.Add(fastK); + 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++) { - decimal slowK = fastDList.ElementAtOrDefault(i); - decimal slowD = slowDList.ElementAtOrDefault(i); - decimal prevSlowk = i >= 1 ? fastDList.ElementAtOrDefault(i - 1) : 0; - decimal prevSlowd = i >= 1 ? slowDList.ElementAtOrDefault(i - 1) : 0; + decimal slowK = fastDList[i]; + decimal slowD = slowDList[i]; + decimal prevSlowk = i >= 1 ? fastDList[i - 1] : 0; + decimal prevSlowd = i >= 1 ? slowDList[i - 1] : 0; var signal = GetRsiSignal(slowK - slowD, prevSlowk - prevSlowd, slowK, prevSlowk, 80, 20); signalsList.Add(signal); @@ -75,19 +75,19 @@ public static StockData CalculateAdaptiveStochastic(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal er = erList.ElementAtOrDefault(i); - decimal src = srcList.ElementAtOrDefault(i); - decimal highest1 = highest1List.ElementAtOrDefault(i); - decimal lowest1 = lowest1List.ElementAtOrDefault(i); - decimal highest2 = highest2List.ElementAtOrDefault(i); - decimal lowest2 = lowest2List.ElementAtOrDefault(i); - decimal prevStc1 = i >= 1 ? stcList.ElementAtOrDefault(i - 1) : 0; - decimal prevStc2 = i >= 2 ? stcList.ElementAtOrDefault(i - 2) : 0; + decimal er = erList[i]; + decimal src = srcList[i]; + decimal highest1 = highest1List[i]; + decimal lowest1 = lowest1List[i]; + decimal highest2 = highest2List[i]; + decimal lowest2 = lowest2List[i]; + decimal prevStc1 = i >= 1 ? stcList[i - 1] : 0; + decimal prevStc2 = i >= 2 ? stcList[i - 2] : 0; decimal a = (er * highest1) + ((1 - er) * highest2); decimal b = (er * lowest1) + ((1 - er) * lowest2); decimal stc = a - b != 0 ? MinOrMax((src - b) / (a - b), 1, 0) : 0; - stcList.Add(stc); + stcList.AddRounded(stc); var signal = GetRsiSignal(stc - prevStc1, prevStc1 - prevStc2, stc, prevStc1, 0.8m, 0.2m); signalsList.Add(signal); @@ -127,37 +127,37 @@ public static StockData CalculateBilateralStochasticOscillator(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal range = highest - lowest; - rangeList.Add(range); + rangeList.AddRounded(range); } var rangeSmaList = GetMovingAverageList(stockData, maType, length, rangeList); for (int i = 0; i < stockData.Count; i++) { - decimal sma = smaList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal rangeSma = rangeSmaList.ElementAtOrDefault(i); + decimal sma = smaList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal rangeSma = rangeSmaList[i]; decimal bull = rangeSma != 0 ? (sma / rangeSma) - (lowest / rangeSma) : 0; - bullList.Add(bull); + bullList.AddRounded(bull); decimal bear = rangeSma != 0 ? Math.Abs((sma / rangeSma) - (highest / rangeSma)) : 0; - bearList.Add(bear); + bearList.AddRounded(bear); decimal max = Math.Max(bull, bear); - maxList.Add(max); + maxList.AddRounded(max); } var signalList = GetMovingAverageList(stockData, maType, signalLength, maxList); for (int i = 0; i < stockData.Count; i++) { - decimal bull = bullList.ElementAtOrDefault(i); - decimal bear = bearList.ElementAtOrDefault(i); - decimal sig = signalList.ElementAtOrDefault(i); + decimal bull = bullList[i]; + decimal bear = bearList[i]; + decimal sig = signalList[i]; var signal = GetConditionSignal(bull > bear || bull > sig, bear > bull || bull < sig); signalsList.Add(signal); @@ -198,9 +198,9 @@ public static StockData CalculateNaturalStochasticIndicator(this StockData stock decimal weightSum = 0, denomSum = 0; for (int j = 0; j < length; j++) { - decimal hh = i >= j ? highestList.ElementAtOrDefault(i - j) : 0; - decimal ll = i >= j ? lowestList.ElementAtOrDefault(i - j) : 0; - decimal c = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal hh = i >= j ? highestList[i - j] : 0; + decimal ll = i >= j ? lowestList[i - j] : 0; + decimal c = i >= j ? inputList[i - j] : 0; decimal range = hh - ll; decimal frac = range != 0 ? (c - ll) / range : 0; decimal ratio = 1 / Sqrt(j + 1); @@ -209,15 +209,15 @@ public static StockData CalculateNaturalStochasticIndicator(this StockData stock } decimal rawNst = denomSum != 0 ? (200 * weightSum / denomSum) - 100 : 0; - rawNstList.Add(rawNst); + rawNstList.AddRounded(rawNst); } var nstList = GetMovingAverageList(stockData, maType, smoothLength, rawNstList); for (int i = 0; i < stockData.Count; i++) { - decimal nst = nstList.ElementAtOrDefault(i); - decimal prevNst1 = i >= 1 ? nstList.ElementAtOrDefault(i - 1) : 0; - decimal prevNst2 = i >= 2 ? nstList.ElementAtOrDefault(i - 2) : 0; + decimal nst = nstList[i]; + decimal prevNst1 = i >= 1 ? nstList[i - 1] : 0; + decimal prevNst2 = i >= 2 ? nstList[i - 2] : 0; var signal = GetCompareSignal(nst - prevNst1, prevNst1 - prevNst2); signalsList.Add(signal); @@ -266,35 +266,35 @@ public static StockData CalculateFisherTransformStochasticOscillator(this StockD for (int i = 0; i < stockData.Count; i++) { - decimal wma1 = wmaList.ElementAtOrDefault(i); - decimal wma2 = wma2List.ElementAtOrDefault(i); - decimal wma3 = wma3List.ElementAtOrDefault(i); - decimal wma4 = wma4List.ElementAtOrDefault(i); - decimal wma5 = wma5List.ElementAtOrDefault(i); - decimal wma6 = wma6List.ElementAtOrDefault(i); - decimal wma7 = wma7List.ElementAtOrDefault(i); - decimal wma8 = wma8List.ElementAtOrDefault(i); - decimal wma9 = wma9List.ElementAtOrDefault(i); - decimal wma10 = wma10List.ElementAtOrDefault(i); + decimal wma1 = wmaList[i]; + decimal wma2 = wma2List[i]; + decimal wma3 = wma3List[i]; + decimal wma4 = wma4List[i]; + decimal wma5 = wma5List[i]; + decimal wma6 = wma6List[i]; + decimal wma7 = wma7List[i]; + decimal wma8 = wma8List[i]; + decimal wma9 = wma9List[i]; + decimal wma10 = wma10List[i]; decimal rbw = ((wma1 * 5) + (wma2 * 4) + (wma3 * 3) + (wma4 * 2) + wma5 + wma6 + wma7 + wma8 + wma9 + wma10) / 20; - rbwList.Add(rbw); + rbwList.AddRounded(rbw); } var (highestList, lowestList) = GetMaxAndMinValuesList(rbwList, stochLength); for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal rbw = rbwList.ElementAtOrDefault(i); - decimal prevFtso1 = i >= 1 ? ftsoList.ElementAtOrDefault(i - 1) : 0; - decimal prevFtso2 = i >= 2 ? ftsoList.ElementAtOrDefault(i - 2) : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal rbw = rbwList[i]; + decimal prevFtso1 = i >= 1 ? ftsoList[i - 1] : 0; + decimal prevFtso2 = i >= 2 ? ftsoList[i - 2] : 0; decimal num = rbw - lowest; - numList.Add(num); + numList.AddRounded(num); decimal denom = highest - lowest; - denomList.Add(denom); + denomList.AddRounded(denom); decimal numSum = numList.TakeLastExt(smoothLength).Sum(); decimal denomSum = denomList.TakeLastExt(smoothLength).Sum(); @@ -302,7 +302,7 @@ public static StockData CalculateFisherTransformStochasticOscillator(this StockD decimal x = 0.1m * (rbws - 50); decimal ftso = MinOrMax((((Exp(2 * x) - 1) / (Exp(2 * x) + 1)) + 1) * 50, 100, 0); - ftsoList.Add(ftso); + ftsoList.AddRounded(ftso); var signal = GetRsiSignal(ftso - prevFtso1, prevFtso1 - prevFtso2, ftso, prevFtso1, 70, 30); signalsList.Add(signal); @@ -342,20 +342,20 @@ public static StockData CalculateFastandSlowStochasticOscillator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal v4 = v4List.ElementAtOrDefault(i); - decimal slowK = slowKList.ElementAtOrDefault(i); + decimal v4 = v4List[i]; + decimal slowK = slowKList[i]; decimal fsst = (500 * v4) + slowK; - fsstList.Add(fsst); + fsstList.AddRounded(fsst); } var wfsstList = GetMovingAverageList(stockData, maType, length4, fsstList); for (int i = 0; i < wfsstList.Count; i++) { - decimal fsst = fsstList.ElementAtOrDefault(i); - decimal wfsst = wfsstList.ElementAtOrDefault(i); - decimal prevFsst = i >= 1 ? fsstList.ElementAtOrDefault(i - 1) : 0; - decimal prevWfsst = i >= 1 ? wfsstList.ElementAtOrDefault(i - 1) : 0; + decimal fsst = fsstList[i]; + decimal wfsst = wfsstList[i]; + decimal prevFsst = i >= 1 ? fsstList[i - 1] : 0; + decimal prevWfsst = i >= 1 ? wfsstList[i - 1] : 0; var signal = GetCompareSignal(fsst - wfsst, prevFsst - prevWfsst); signalsList.Add(signal); @@ -394,23 +394,23 @@ public static StockData CalculatePremierStochasticOscillator(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal sk = stochasticRsiList.ElementAtOrDefault(i); + decimal sk = stochasticRsiList[i]; decimal nsk = 0.1m * (sk - 50); - nskList.Add(nsk); + 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++) { - decimal ss = ssList.ElementAtOrDefault(i); - decimal prevPso1 = i >= 1 ? psoList.ElementAtOrDefault(i - 1) : 0; - decimal prevPso2 = i >= 2 ? psoList.ElementAtOrDefault(i - 2) : 0; + decimal ss = ssList[i]; + decimal prevPso1 = i >= 1 ? psoList[i - 1] : 0; + decimal prevPso2 = i >= 2 ? psoList[i - 2] : 0; decimal expss = Exp(ss); decimal pso = expss + 1 != 0 ? MinOrMax((expss - 1) / (expss + 1), 1, -1) : 0; - psoList.Add(pso); + psoList.AddRounded(pso); var signal = GetRsiSignal(pso - prevPso1, prevPso1 - prevPso2, pso, prevPso1, 0.9m, -0.9m); signalsList.Add(signal); @@ -452,10 +452,10 @@ public static StockData CalculateTurboStochasticsFast(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal tsfD = tsfDList.ElementAtOrDefault(i); - decimal tsfK = tsfKList.ElementAtOrDefault(i); - decimal prevTsfk = i >= 1 ? tsfKList.ElementAtOrDefault(i - 1) : 0; - decimal prevTsfd = i >= 1 ? tsfDList.ElementAtOrDefault(i - 1) : 0; + decimal tsfD = tsfDList[i]; + decimal tsfK = tsfKList[i]; + decimal prevTsfk = i >= 1 ? tsfKList[i - 1] : 0; + decimal prevTsfd = i >= 1 ? tsfDList[i - 1] : 0; var signal = GetRsiSignal(tsfK - tsfD, prevTsfk - prevTsfd, tsfK, prevTsfk, 70, 30); signalsList.Add(signal); @@ -501,10 +501,10 @@ public static StockData CalculateTurboStochasticsSlow(this StockData stockData, for (int i = 0; i < tssDList.Count; i++) { - decimal tssD = tssDList.ElementAtOrDefault(i); - decimal tssK = tssKList.ElementAtOrDefault(i); - decimal prevTssk = i >= 1 ? tssKList.ElementAtOrDefault(i - 1) : 0; - decimal prevTssd = i >= 1 ? tssDList.ElementAtOrDefault(i - 1) : 0; + decimal tssD = tssDList[i]; + decimal tssK = tssKList[i]; + decimal prevTssk = i >= 1 ? tssKList[i - 1] : 0; + decimal prevTssd = i >= 1 ? tssDList[i - 1] : 0; var signal = GetRsiSignal(tssK - tssD, prevTssk - prevTssd, tssK, prevTssk, 70, 30); signalsList.Add(signal); @@ -539,22 +539,22 @@ public static StockData CalculateRecursiveStochastic(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal stoch = highest - lowest != 0 ? (currentValue - lowest) / (highest - lowest) * 100 : 0; - decimal prevK1 = i >= 1 ? kList.ElementAtOrDefault(i - 1) : 0; - decimal prevK2 = i >= 2 ? kList.ElementAtOrDefault(i - 2) : 0; + decimal prevK1 = i >= 1 ? kList[i - 1] : 0; + decimal prevK2 = i >= 2 ? kList[i - 2] : 0; decimal ma = (alpha * stoch) + ((1 - alpha) * prevK1); - maList.Add(ma); + maList.AddRounded(ma); var lbList = maList.TakeLastExt(length).ToList(); decimal highestMa = lbList.Max(); decimal lowestMa = lbList.Min(); decimal k = highestMa - lowestMa != 0 ? MinOrMax((ma - lowestMa) / (highestMa - lowestMa) * 100, 100, 0) : 0; - kList.Add(k); + kList.AddRounded(k); var signal = GetRsiSignal(k - prevK1, prevK1 - prevK2, k, prevK1, 80, 20); signalsList.Add(signal); @@ -589,18 +589,18 @@ public static StockData CalculateDiNapoliPreferredStochasticOscillator(this Stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal max = highestList.ElementAtOrDefault(i); - decimal min = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal max = highestList[i]; + decimal min = lowestList[i]; decimal fast = max - min != 0 ? MinOrMax((currentValue - min) / (max - min) * 100, 100, 0) : 0; decimal prevR = rList.LastOrDefault(); decimal r = prevR + ((fast - prevR) / length2); - rList.Add(r); + rList.AddRounded(r); decimal prevS = sList.LastOrDefault(); decimal s = prevS + ((r - prevS) / length3); - sList.Add(s); + sList.AddRounded(s); var signal = GetRsiSignal(r - s, prevR - prevS, r, prevR, 70, 30); signalsList.Add(signal); @@ -640,15 +640,15 @@ public static StockData CalculateDoubleSmoothedStochastic(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; decimal num = currentValue - lowestLow; - numList.Add(num); + numList.AddRounded(num); decimal denom = highestHigh - lowestLow; - denomList.Add(denom); + denomList.AddRounded(denom); } var ssNumList = GetMovingAverageList(stockData, maType, length2, numList); @@ -657,20 +657,20 @@ public static StockData CalculateDoubleSmoothedStochastic(this StockData stockDa var dsDenomList = GetMovingAverageList(stockData, maType, length3, ssDenomList); for (int i = 0; i < stockData.Count; i++) { - decimal dsNum = dsNumList.ElementAtOrDefault(i); - decimal dsDenom = dsDenomList.ElementAtOrDefault(i); + decimal dsNum = dsNumList[i]; + decimal dsDenom = dsDenomList[i]; decimal dss = dsDenom != 0 ? MinOrMax(100 * dsNum / dsDenom, 100, 0) : 0; - dssList.Add(dss); + dssList.AddRounded(dss); } var sdssList = GetMovingAverageList(stockData, maType, length4, dssList); for (int i = 0; i < stockData.Count; i++) { - decimal dss = dssList.ElementAtOrDefault(i); - decimal sdss = sdssList.ElementAtOrDefault(i); - decimal prevDss = i >= 1 ? dssList.ElementAtOrDefault(i - 1) : 0; - decimal prevSdss = i >= 1 ? sdssList.ElementAtOrDefault(i - 1) : 0; + decimal dss = dssList[i]; + decimal sdss = sdssList[i]; + decimal prevDss = i >= 1 ? dssList[i - 1] : 0; + decimal prevSdss = i >= 1 ? sdssList[i - 1] : 0; var signal = GetRsiSignal(dss - sdss, prevDss - prevSdss, dss, prevDss, 70, 30); signalsList.Add(signal); @@ -707,22 +707,22 @@ public static StockData CalculateDoubleStochasticOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal slowK = stochasticList.ElementAtOrDefault(i); - decimal highestSlowK = highestList.ElementAtOrDefault(i); - decimal lowestSlowK = lowestList.ElementAtOrDefault(i); + decimal slowK = stochasticList[i]; + decimal highestSlowK = highestList[i]; + decimal lowestSlowK = lowestList[i]; decimal doubleK = highestSlowK - lowestSlowK != 0 ? MinOrMax((slowK - lowestSlowK) / (highestSlowK - lowestSlowK) * 100, 100, 0) : 0; - doubleKList.Add(doubleK); + 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++) { - decimal doubleSlowK = doubleSlowKList.ElementAtOrDefault(i); - decimal doubleKSignal = doubleKSignalList.ElementAtOrDefault(i); - decimal prevDoubleslowk = i >= 1 ? doubleSlowKList.ElementAtOrDefault(i - 1) : 0; - decimal prevDoubleKSignal = i >= 1 ? doubleKSignalList.ElementAtOrDefault(i - 1) : 0; + decimal doubleSlowK = doubleSlowKList[i]; + decimal doubleKSignal = doubleKSignalList[i]; + decimal prevDoubleslowk = i >= 1 ? doubleSlowKList[i - 1] : 0; + decimal prevDoubleKSignal = i >= 1 ? doubleKSignalList[i - 1] : 0; var signal = GetRsiSignal(doubleSlowK - doubleKSignal, prevDoubleslowk - prevDoubleKSignal, doubleSlowK, prevDoubleslowk, 80, 20); signalsList.Add(signal); @@ -763,31 +763,31 @@ public static StockData CalculateDMIStochastic(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal pdi = diPlusList.ElementAtOrDefault(i); - decimal ndi = diMinusList.ElementAtOrDefault(i); + decimal pdi = diPlusList[i]; + decimal ndi = diMinusList[i]; decimal dmiOscillator = ndi - pdi; - dmiOscillatorList.Add(dmiOscillator); + dmiOscillatorList.AddRounded(dmiOscillator); } var (highestList, lowestList) = GetMaxAndMinValuesList(dmiOscillatorList, length2); for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal dmiOscillator = dmiOscillatorList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal dmiOscillator = dmiOscillatorList[i]; decimal fastK = highest - lowest != 0 ? MinOrMax((dmiOscillator - lowest) / (highest - lowest) * 100, 100, 0) : 0; - fastKList.Add(fastK); + 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++) { - decimal dmiStoch = dmiStochList.ElementAtOrDefault(i); - decimal prevDmiStoch1 = i >= 1 ? dmiStochList.ElementAtOrDefault(i - 1) : 0; - decimal prevDmiStoch2 = i >= 2 ? dmiStochList.ElementAtOrDefault(i - 2) : 0; + decimal dmiStoch = dmiStochList[i]; + decimal prevDmiStoch1 = i >= 1 ? dmiStochList[i - 1] : 0; + decimal prevDmiStoch2 = i >= 2 ? dmiStochList[i - 2] : 0; var signal = GetRsiSignal(dmiStoch - prevDmiStoch1, prevDmiStoch1 - prevDmiStoch2, dmiStoch, prevDmiStoch1, 90, 10); signalsList.Add(signal); @@ -826,16 +826,16 @@ public static StockData CalculateStochasticMomentumIndex(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; decimal median = (highestHigh + lowestLow) / 2; decimal diff = currentValue - median; - dList.Add(diff); + dList.AddRounded(diff); decimal highLow = highestHigh - lowestLow; - hlList.Add(highLow); + hlList.AddRounded(highLow); } var dEmaList = GetMovingAverageList(stockData, maType, length2, dList); @@ -844,21 +844,21 @@ public static StockData CalculateStochasticMomentumIndex(this StockData stockDat var hlSmoothEmaList = GetMovingAverageList(stockData, maType, smoothLength1, hlEmaList); for (int i = 0; i < stockData.Count; i++) { - decimal hlSmoothEma = hlSmoothEmaList.ElementAtOrDefault(i); - decimal dSmoothEma = dSmoothEmaList.ElementAtOrDefault(i); + decimal hlSmoothEma = hlSmoothEmaList[i]; + decimal dSmoothEma = dSmoothEmaList[i]; decimal hl2 = hlSmoothEma / 2; decimal smi = hl2 != 0 ? MinOrMax(100 * dSmoothEma / hl2, 100, -100) : 0; - smiList.Add(smi); + smiList.AddRounded(smi); } var smiSignalList = GetMovingAverageList(stockData, maType, smoothLength2, smiList); for (int i = 0; i < stockData.Count; i++) { - decimal smi = smiList.ElementAtOrDefault(i); - decimal smiSignal = smiSignalList.ElementAtOrDefault(i); - decimal prevSmi = i >= 1 ? smiList.ElementAtOrDefault(i - 1) : 0; - decimal prevSmiSignal = i >= 1 ? smiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal smi = smiList[i]; + decimal smiSignal = smiSignalList[i]; + decimal prevSmi = i >= 1 ? smiList[i - 1] : 0; + decimal prevSmiSignal = i >= 1 ? smiSignalList[i - 1] : 0; var signal = GetCompareSignal(smi - smiSignal, prevSmi - prevSmiSignal); signalsList.Add(signal); @@ -896,10 +896,10 @@ public static StockData CalculateStochasticFastOscillator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal pkEma = pkList.ElementAtOrDefault(i); - decimal pdEma = pdList.ElementAtOrDefault(i); - decimal prevPkema = i >= 1 ? pkList.ElementAtOrDefault(i - 1) : 0; - decimal prevPdema = i >= 1 ? pdList.ElementAtOrDefault(i - 1) : 0; + decimal pkEma = pkList[i]; + decimal pdEma = pdList[i]; + decimal prevPkema = i >= 1 ? pkList[i - 1] : 0; + decimal prevPdema = i >= 1 ? pdList[i - 1] : 0; var signal = GetRsiSignal(pkEma - pdEma, prevPkema - prevPdema, pkEma, prevPkema, 80, 20); signalsList.Add(signal); @@ -938,35 +938,35 @@ public static StockData CalculateStochasticCustomOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; decimal num = currentValue - lowestLow; - numList.Add(num); + numList.AddRounded(num); decimal denom = highestHigh - lowestLow; - denomList.Add(denom); + 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++) { - decimal numSma = numSmaList.ElementAtOrDefault(i); - decimal denomSma = denomSmaList.ElementAtOrDefault(i); + decimal numSma = numSmaList[i]; + decimal denomSma = denomSmaList[i]; decimal sck = denomSma != 0 ? MinOrMax(numSma / denomSma * 100, 100, 0) : 0; - sckList.Add(sck); + sckList.AddRounded(sck); } var scdList = GetMovingAverageList(stockData, maType, length3, sckList); for (int i = 0; i < stockData.Count; i++) { - decimal sck = sckList.ElementAtOrDefault(i); - decimal scd = scdList.ElementAtOrDefault(i); - decimal prevSck = i >= 1 ? sckList.ElementAtOrDefault(i - 1) : 0; - decimal prevScd = i >= 1 ? scdList.ElementAtOrDefault(i - 1) : 0; + decimal sck = sckList[i]; + decimal scd = scdList[i]; + decimal prevSck = i >= 1 ? sckList[i - 1] : 0; + decimal prevScd = i >= 1 ? scdList[i - 1] : 0; var signal = GetRsiSignal(sck - scd, prevSck - prevScd, sck, prevSck, 70, 30); signalsList.Add(signal); @@ -1003,10 +1003,10 @@ public static StockData CalculateStochasticRegular(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal fk = fastKList.ElementAtOrDefault(i); - decimal sk = skList.ElementAtOrDefault(i); - decimal prevFk = i >= 1 ? fastKList.ElementAtOrDefault(i - 1) : 0; - decimal prevSk = i >= 1 ? skList.ElementAtOrDefault(i - 1) : 0; + decimal fk = fastKList[i]; + decimal sk = skList[i]; + decimal prevFk = i >= 1 ? fastKList[i - 1] : 0; + decimal prevSk = i >= 1 ? skList[i - 1] : 0; var signal = GetRsiSignal(fk - sk, prevFk - prevSk, fk, prevFk, 70, 30); signalsList.Add(signal); @@ -1042,22 +1042,22 @@ public static StockData CalculateSwamiStochastics(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevStoch1 = i >= 1 ? stochList.ElementAtOrDefault(i - 1) : 0; - decimal prevStoch2 = i >= 2 ? stochList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevStoch1 = i >= 1 ? stochList[i - 1] : 0; + decimal prevStoch2 = i >= 2 ? stochList[i - 2] : 0; decimal pNum = numList.LastOrDefault(); decimal num = (currentValue - lowest + pNum) / 2; - numList.Add(num); + numList.AddRounded(num); decimal pDenom = denomList.LastOrDefault(); decimal denom = (highest - lowest + pDenom) / 2; - denomList.Add(denom); + denomList.AddRounded(denom); decimal stoch = denom != 0 ? MinOrMax((0.2m * num / denom) + (0.8m * prevStoch1), 1, 0) : 0; - stochList.Add(stoch); + stochList.AddRounded(stoch); var signal = GetRsiSignal(stoch - prevStoch1, prevStoch1 - prevStoch2, stoch, prevStoch1, 0.8m, 0.2m); signalsList.Add(signal); diff --git a/Calculations/TrailingStop.cs b/Calculations/TrailingStop.cs index 0978f6e..3bb8b17 100644 --- a/Calculations/TrailingStop.cs +++ b/Calculations/TrailingStop.cs @@ -24,33 +24,33 @@ public static StockData CalculateAdaptiveTrailingStop(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal per = perList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal per = perList[i]; decimal prevA = i >= 1 ? aList.LastOrDefault() : currentValue; decimal a = Math.Max(currentValue, prevA) - (Math.Abs(currentValue - prevA) * per); - aList.Add(a); + aList.AddRounded(a); decimal prevB = i >= 1 ? bList.LastOrDefault() : currentValue; decimal b = Math.Min(currentValue, prevB) + (Math.Abs(currentValue - prevB) * per); - bList.Add(b); + bList.AddRounded(b); decimal prevUp = upList.LastOrDefault(); decimal up = a > prevA ? a : a < prevA && b < prevB ? a : prevUp; - upList.Add(up); + upList.AddRounded(up); decimal prevDn = dnList.LastOrDefault(); decimal dn = b < prevB ? b : b > prevB && a > prevA ? b : prevDn; - dnList.Add(dn); + dnList.AddRounded(dn); decimal prevOs = osList.LastOrDefault(); decimal os = up > currentValue ? 1 : dn > currentValue ? 0 : prevOs; - osList.Add(os); + osList.AddRounded(os); decimal prevTs = tsList.LastOrDefault(); decimal ts = (os * dn) + ((1 - os) * up); - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); signalsList.Add(signal); @@ -89,26 +89,26 @@ public static StockData CalculateAdaptiveAutonomousRecursiveTrailingStop(this St for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ma2 = ma2List.ElementAtOrDefault(i); - decimal d = dList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ma2 = ma2List[i]; + decimal d = dList[i]; decimal prevUpper = upperList.LastOrDefault(); decimal upper = ma2 + d; - upperList.Add(upper); + upperList.AddRounded(upper); decimal prevLower = lowerList.LastOrDefault(); decimal lower = ma2 - d; - lowerList.Add(lower); + lowerList.AddRounded(lower); decimal prevOs = osList.LastOrDefault(); decimal os = currentValue > prevUpper ? 1 : currentValue < prevLower ? 0 : prevOs; - osList.Add(os); + osList.AddRounded(os); decimal prevTs = tsList.LastOrDefault(); decimal ts = (os * lower) + ((1 - os) * upper); - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); signalsList.Add(signal); @@ -142,14 +142,14 @@ public static StockData CalculateParabolicSAR(this StockData stockData, decimal for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh1 = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow1 = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh2 = i >= 2 ? highList.ElementAtOrDefault(i - 2) : 0; - decimal prevLow2 = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh1 = i >= 1 ? highList[i - 1] : 0; + decimal prevLow1 = i >= 1 ? lowList[i - 1] : 0; + decimal prevHigh2 = i >= 2 ? highList[i - 2] : 0; + decimal prevLow2 = i >= 2 ? lowList[i - 2] : 0; bool uptrend; decimal ep, prevSAR, prevEP, SAR, af = start; @@ -215,11 +215,11 @@ public static StockData CalculateParabolicSAR(this StockData stockData, decimal { SAR = i > 1 ? Math.Max(SAR, prevHigh2) : Math.Max(SAR, prevHigh1); } - sarList.Add(SAR); + sarList.AddRounded(SAR); decimal prevNextSar = nextSarList.LastOrDefault(); decimal nextSar = SAR + (af * (ep - SAR)); - nextSarList.Add(nextSar); + nextSarList.AddRounded(nextSar); var signal = GetCompareSignal(currentHigh - nextSar, prevHigh1 - prevNextSar); signalsList.Add(signal); @@ -257,19 +257,19 @@ public static StockData CalculateChandelierExit(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentAvgTrueRange = atrList.ElementAtOrDefault(i); - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentAvgTrueRange = atrList[i]; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevExitLong = chandelierExitLongList.LastOrDefault(); decimal chandelierExitLong = highestHigh - (currentAvgTrueRange * mult); - chandelierExitLongList.Add(chandelierExitLong); + chandelierExitLongList.AddRounded(chandelierExitLong); decimal prevExitShort = chandelierExitShortList.LastOrDefault(); decimal chandelierExitShort = lowestLow + (currentAvgTrueRange * mult); - chandelierExitShortList.Add(chandelierExitShort); + chandelierExitShortList.AddRounded(chandelierExitShort); var signal = GetBullishBearishSignal(currentValue - chandelierExitLong, prevValue - prevExitLong, currentValue - chandelierExitShort, prevValue - prevExitShort); signalsList.Add(signal); @@ -308,17 +308,17 @@ public static StockData CalculateAverageTrueRangeTrailingStops(this StockData st for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentEma = emaList[i]; + decimal currentAtr = atrList[i]; decimal prevAtrts = i >= 1 ? atrtsList.LastOrDefault() : currentValue; var upTrend = currentValue > currentEma; var dnTrend = currentValue <= currentEma; decimal atrts = upTrend ? Math.Max(currentValue - (factor * currentAtr), prevAtrts) : dnTrend ? Math.Min(currentValue + (factor * currentAtr), prevAtrts) : prevAtrts; - atrtsList.Add(atrts); + atrtsList.AddRounded(atrts); var signal = GetCompareSignal(currentValue - atrts, prevValue - prevAtrts); signalsList.Add(signal); @@ -356,33 +356,33 @@ public static StockData CalculateLinearTrailingStop(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevA2 = i >= 2 ? aList.ElementAtOrDefault(i - 2) : currentValue; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; + decimal prevA2 = i >= 2 ? aList[i - 2] : currentValue; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal x = currentValue + ((prevA - prevA2) * mult); decimal a = x > prevA + s ? prevA + s : x < prevA - s ? prevA - s : prevA; - aList.Add(a); + aList.AddRounded(a); decimal up = a + (Math.Abs(a - prevA) * mult); decimal dn = a - (Math.Abs(a - prevA) * mult); decimal prevUpper = upperList.LastOrDefault(); decimal upper = up == a ? prevUpper : up; - upperList.Add(upper); + upperList.AddRounded(upper); decimal prevLower = lowerList.LastOrDefault(); decimal lower = dn == a ? prevLower : dn; - lowerList.Add(lower); + lowerList.AddRounded(lower); decimal prevOs = osList.LastOrDefault(); decimal os = currentValue > upper ? 1 : currentValue > lower ? 0 : prevOs; - osList.Add(os); + osList.AddRounded(os); decimal prevTs = tsList.LastOrDefault(); decimal ts = (os * lower) + ((1 - os) * upper); - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); signalsList.Add(signal); @@ -418,11 +418,11 @@ public static StockData CalculateNickRypockTrailingReverse(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; decimal prevTrend = trendList.LastOrDefault(); decimal prevHp = hpList.LastOrDefault(); decimal prevLp = lpList.LastOrDefault(); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevNrtr = nrtrList.LastOrDefault(); decimal nrtr, hp = 0, lp = 0, trend = 0; @@ -450,10 +450,10 @@ public static StockData CalculateNickRypockTrailingReverse(this StockData stockD nrtr = hp * (1 - pct); } } - trendList.Add(trend); - hpList.Add(hp); - lpList.Add(lp); - nrtrList.Add(nrtr); + trendList.AddRounded(trend); + hpList.AddRounded(hp); + lpList.AddRounded(lp); + nrtrList.AddRounded(nrtr); var signal = GetCompareSignal(currentValue - nrtr, prevValue - prevNrtr); signalsList.Add(signal); @@ -496,14 +496,14 @@ public static StockData CalculateHalfTrend(this StockData stockData, MovingAvgTy for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentAvgTrueRange = atrList.ElementAtOrDefault(i); - decimal high = highestList.ElementAtOrDefault(i); - decimal low = lowestList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal highMa = highMaList.ElementAtOrDefault(i); - decimal lowMa = lowMaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentAvgTrueRange = atrList[i]; + decimal high = highestList[i]; + decimal low = lowestList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal highMa = highMaList[i]; + decimal lowMa = lowMaList[i]; decimal maxLow = i >= 1 ? prevLow : low; decimal minHigh = i >= 1 ? prevHigh : high; decimal prevNextTrend = nextTrendList.LastOrDefault(); @@ -536,8 +536,8 @@ public static StockData CalculateHalfTrend(this StockData stockData, MovingAvgTy } } } - trendList.Add(trend); - nextTrendList.Add(nextTrend); + trendList.AddRounded(trend); + nextTrendList.AddRounded(nextTrend); decimal up = 0, down = 0, arrowUp = 0, arrowDown = 0; if (trend == 0) @@ -564,11 +564,11 @@ public static StockData CalculateHalfTrend(this StockData stockData, MovingAvgTy down = Math.Min(minHigh, prevDown); } } - upList.Add(up); - downList.Add(down); + upList.AddRounded(up); + downList.AddRounded(down); decimal ht = trend == 0 ? up : down; - htList.Add(ht); + htList.AddRounded(ht); var signal = GetConditionSignal(arrowUp != 0 && trend == 0 && prevTrend == 1, arrowDown != 0 && trend == 1 && prevTrend == 0); signalsList.Add(signal); @@ -613,13 +613,13 @@ public static StockData CalculateKaseDevStopV1(this StockData stockData, InputNa for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevClose = i >= 2 ? closeList.ElementAtOrDefault(i - 2) : 0; - decimal prevLow = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevClose = i >= 2 ? closeList[i - 2] : 0; + decimal prevLow = i >= 2 ? lowList[i - 2] : 0; decimal dtr = Math.Max(Math.Max(currentHigh - prevLow, Math.Abs(currentHigh - prevClose)), Math.Abs(currentLow - prevClose)); - dtrList.Add(dtr); + dtrList.AddRounded(dtr); } var dtrAvgList = GetMovingAverageList(stockData, maType, length, dtrList); @@ -629,26 +629,26 @@ public static StockData CalculateKaseDevStopV1(this StockData stockData, InputNa var dtrStdList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal maFast = smaFastList.ElementAtOrDefault(i); - decimal maSlow = smaSlowList.ElementAtOrDefault(i); - decimal dtrAvg = dtrAvgList.ElementAtOrDefault(i); - decimal dtrStd = dtrStdList.ElementAtOrDefault(i); - decimal currentTypicalPrice = inputList.ElementAtOrDefault(i); - decimal prevMaFast = i >= 1 ? smaFastList.ElementAtOrDefault(i - 1) : 0; - decimal prevMaSlow = i >= 1 ? smaSlowList.ElementAtOrDefault(i - 1) : 0; + decimal maFast = smaFastList[i]; + decimal maSlow = smaSlowList[i]; + decimal dtrAvg = dtrAvgList[i]; + decimal dtrStd = dtrStdList[i]; + decimal currentTypicalPrice = inputList[i]; + decimal prevMaFast = i >= 1 ? smaFastList[i - 1] : 0; + decimal prevMaSlow = i >= 1 ? smaSlowList[i - 1] : 0; decimal warningLine = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev1 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev1 * dtrStd); - warningLineList.Add(warningLine); + warningLineList.AddRounded(warningLine); decimal dev1 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev2 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev2 * dtrStd); - dev1List.Add(dev1); + dev1List.AddRounded(dev1); decimal dev2 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev3 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev3 * dtrStd); - dev2List.Add(dev2); + dev2List.AddRounded(dev2); decimal dev3 = maFast < maSlow ? currentTypicalPrice + dtrAvg + (stdDev4 * dtrStd) : currentTypicalPrice - dtrAvg - (stdDev4 * dtrStd); - dev3List.Add(dev3); + dev3List.AddRounded(dev3); var signal = GetCompareSignal(maFast - maSlow, prevMaFast - prevMaSlow); signalsList.Add(signal); @@ -700,25 +700,25 @@ public static StockData CalculateKaseDevStopV2(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal maFast = smaFastList.ElementAtOrDefault(i); - decimal maSlow = smaSlowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 2 ? inputList.ElementAtOrDefault(i - 2) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal maFast = smaFastList[i]; + decimal maSlow = smaSlowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 2 ? inputList[i - 2] : 0; decimal trend = maFast > maSlow ? 1 : -1; - trendList.Add(trend); + trendList.AddRounded(trend); decimal price = trend == 1 ? currentHigh : currentLow; price = trend > 0 ? Math.Max(price, currentHigh) : Math.Min(price, currentLow); - priceList.Add(price); + priceList.AddRounded(price); decimal mmax = Math.Max(Math.Max(currentHigh, prevHigh), prevClose); decimal mmin = Math.Min(Math.Min(currentLow, prevLow), prevClose); decimal rrange = mmax - mmin; - rrangeList.Add(rrange); + rrangeList.AddRounded(rrange); } var rangeAvgList = GetMovingAverageList(stockData, maType, length, rrangeList); @@ -726,24 +726,24 @@ public static StockData CalculateKaseDevStopV2(this StockData stockData, MovingA var rangeStdDevList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal price = priceList.ElementAtOrDefault(i); - decimal trend = trendList.ElementAtOrDefault(i); - decimal avg = rangeAvgList.ElementAtOrDefault(i); - decimal dev = rangeStdDevList.ElementAtOrDefault(i); - decimal prevPrice = i >= 1 ? priceList.ElementAtOrDefault(i - 1) : 0; + decimal price = priceList[i]; + decimal trend = trendList[i]; + decimal avg = rangeAvgList[i]; + decimal dev = rangeStdDevList[i]; + decimal prevPrice = i >= 1 ? priceList[i - 1] : 0; decimal val = (price + ((-1) * trend)) * (avg + (stdDev1 * dev)); - valList.Add(val); + valList.AddRounded(val); decimal val1 = (price + ((-1) * trend)) * (avg + (stdDev2 * dev)); - val1List.Add(val1); + val1List.AddRounded(val1); decimal val2 = (price + ((-1) * trend)) * (avg + (stdDev3 * dev)); - val2List.Add(val2); + val2List.AddRounded(val2); decimal prevVal3 = val3List.LastOrDefault(); decimal val3 = (price + ((-1) * trend)) * (avg + (stdDev4 * dev)); - val3List.Add(val3); + val3List.AddRounded(val3); var signal = GetCompareSignal(price - val3, prevPrice - prevVal3); signalsList.Add(signal); @@ -780,21 +780,21 @@ public static StockData CalculatePercentageTrailingStops(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevHH = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : currentClose; - decimal prevLL = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : currentClose; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevHH = i >= 1 ? highestList[i - 1] : currentClose; + decimal prevLL = i >= 1 ? lowestList[i - 1] : currentClose; decimal pSS = i >= 1 ? stopSList.LastOrDefault() : currentClose; decimal pSL = i >= 1 ? stopLList.LastOrDefault() : currentClose; decimal stopL = currentHigh > prevHH ? currentHigh - (pct * currentHigh) : pSL; - stopLList.Add(stopL); + stopLList.AddRounded(stopL); decimal stopS = currentLow < prevLL ? currentLow + (pct * currentLow) : pSS; - stopSList.Add(stopS); + stopSList.AddRounded(stopS); var signal = GetConditionSignal(prevHigh < stopS && currentHigh > stopS, prevLow > stopL && currentLow < stopL); signalsList.Add(signal); @@ -831,20 +831,20 @@ public static StockData CalculateMotionToAttractionTrailingStop(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal a = aList.ElementAtOrDefault(i); - decimal b = bList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; + decimal a = aList[i]; + decimal b = bList[i]; decimal prevOs = osList.LastOrDefault(); decimal os = currentValue > prevA ? 1 : currentValue < prevB ? 0 : prevOs; - osList.Add(os); + osList.AddRounded(os); decimal prevTs = tsList.LastOrDefault(); decimal ts = (os * b) + ((1 - os) * a); - tsList.Add(ts); + tsList.AddRounded(ts); var signal = GetCompareSignal(currentValue - ts, prevValue - prevTs); signalsList.Add(signal); @@ -888,26 +888,26 @@ public static StockData CalculateElderSafeZoneStops(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentLow = lowList[i]; + decimal currentHigh = highList[i]; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal dmMinus = prevLow > currentLow ? prevLow - currentLow : 0; - dmMinusList.Add(dmMinus); + dmMinusList.AddRounded(dmMinus); decimal dmMinusCount = prevLow > currentLow ? 1 : 0; - dmMinusCountList.Add(dmMinusCount); + dmMinusCountList.AddRounded(dmMinusCount); decimal dmPlus = currentHigh > prevHigh ? currentHigh - prevHigh : 0; - dmPlusList.Add(dmPlus); + dmPlusList.AddRounded(dmPlus); decimal dmPlusCount = currentHigh > prevHigh ? 1 : 0; - dmPlusCountList.Add(dmPlusCount); + dmPlusCountList.AddRounded(dmPlusCount); decimal countM = dmMinusCountList.TakeLastExt(length2).Sum(); decimal dmMinusSum = dmMinusList.TakeLastExt(length2).Sum(); @@ -917,17 +917,17 @@ public static StockData CalculateElderSafeZoneStops(this StockData stockData, Mo decimal dmAvgPlus = countP != 0 ? dmPlusSum / countP : 0; decimal safeZMinus = prevLow - (factor * dmAvgMinus); - safeZMinusList.Add(safeZMinus); + safeZMinusList.AddRounded(safeZMinus); decimal safeZPlus = prevHigh + (factor * dmAvgPlus); - safeZPlusList.Add(safeZPlus); + safeZPlusList.AddRounded(safeZPlus); decimal highest = safeZMinusList.TakeLastExt(length3).Max(); decimal lowest = safeZPlusList.TakeLastExt(length3).Min(); decimal prevStop = stopList.LastOrDefault(); decimal stop = currentValue >= currentEma ? highest : lowest; - stopList.Add(stop); + stopList.AddRounded(stop); var signal = GetBullishBearishSignal(currentValue - Math.Max(currentEma, stop), prevValue - Math.Max(prevEma, prevStop), currentValue - Math.Min(currentEma, stop), prevValue - Math.Min(prevEma, prevStop)); diff --git a/Calculations/Trend.cs b/Calculations/Trend.cs index e54a1fb..dcafd7a 100644 --- a/Calculations/Trend.cs +++ b/Calculations/Trend.cs @@ -17,17 +17,17 @@ public static StockData CalculateTrendTriggerFactor(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal prevHighest = i >= length ? highestList.ElementAtOrDefault(i - length) : 0; - decimal prevLowest = i >= length ? lowestList.ElementAtOrDefault(i - length) : 0; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal prevHighest = i >= length ? highestList[i - length] : 0; + decimal prevLowest = i >= length ? lowestList[i - length] : 0; decimal buyPower = highest - prevLowest; decimal sellPower = prevHighest - lowest; - decimal prevTtf1 = i >= 1 ? ttfList.ElementAtOrDefault(i - 1) : 0; - decimal prevTtf2 = i >= 2 ? ttfList.ElementAtOrDefault(i - 2) : 0; + decimal prevTtf1 = i >= 1 ? ttfList[i - 1] : 0; + decimal prevTtf2 = i >= 2 ? ttfList[i - 2] : 0; decimal ttf = buyPower + sellPower != 0 ? 200 * (buyPower - sellPower) / (buyPower + sellPower) : 0; - ttfList.Add(ttf); + ttfList.AddRounded(ttf); var signal = GetRsiSignal(ttf - prevTtf1, prevTtf1 - prevTtf2, ttf, prevTtf1, 100, -100); signalsList.Add(signal); @@ -67,30 +67,30 @@ public static StockData CalculateTrendPersistenceRate(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal prevMa1 = i >= 1 ? maList.ElementAtOrDefault(i - 1) : 0; - decimal prevMa2 = i >= 2 ? maList.ElementAtOrDefault(i - 2) : 0; + decimal prevMa1 = i >= 1 ? maList[i - 1] : 0; + decimal prevMa2 = i >= 2 ? maList[i - 2] : 0; decimal diff = (prevMa1 - prevMa2) / mult; decimal ctrP = diff > threshold ? 1 : 0; - ctrPList.Add(ctrP); + ctrPList.AddRounded(ctrP); decimal ctrM = diff < -threshold ? 1 : 0; - ctrMList.Add(ctrM); + ctrMList.AddRounded(ctrM); decimal ctrPSum = ctrPList.TakeLastExt(length).Sum(); decimal ctrMSum = ctrMList.TakeLastExt(length).Sum(); decimal tpr = length != 0 ? Math.Abs(100 * (ctrPSum - ctrMSum) / length) : 0; - tprList.Add(tpr); + tprList.AddRounded(tpr); } var tprMaList = GetMovingAverageList(stockData, maType, smoothLength, tprList); for (int i = 0; i < stockData.Count; i++) { - decimal tpr = tprList.ElementAtOrDefault(i); - decimal tprMa = tprMaList.ElementAtOrDefault(i); - decimal prevTpr = i >= 1 ? tprList.ElementAtOrDefault(i - 1) : 0; - decimal prevTprMa = i >= 1 ? tprMaList.ElementAtOrDefault(i - 1) : 0; + decimal tpr = tprList[i]; + decimal tprMa = tprMaList[i]; + decimal prevTpr = i >= 1 ? tprList[i - 1] : 0; + decimal prevTprMa = i >= 1 ? tprMaList[i - 1] : 0; var signal = GetCompareSignal(tpr - tprMa, prevTpr - prevTprMa); signalsList.Add(signal); @@ -123,13 +123,13 @@ public static StockData CalculateTrendStep(this StockData stockData, int length for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal dev = stdDevList.ElementAtOrDefault(i) * 2; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal dev = stdDevList[i] * 2; - decimal prevA = i >= 1 ? aList.ElementAtOrDefault(i - 1) : currentValue; + decimal prevA = i >= 1 ? aList[i - 1] : currentValue; decimal a = i < length ? currentValue : currentValue > prevA + dev ? currentValue : currentValue < prevA - dev ? currentValue : prevA; - aList.Add(a); + aList.AddRounded(a); var signal = GetCompareSignal(currentValue - a, prevValue - prevA); signalsList.Add(signal); @@ -169,36 +169,36 @@ public static StockData CalculateTrendExhaustionIndicator(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHighest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevHighest = i >= 1 ? highestList[i - 1] : 0; + decimal currentHigh = highList[i]; decimal a = currentValue > prevValue ? 1 : 0; - aList.Add(a); + aList.AddRounded(a); decimal h = currentHigh > prevHighest ? 1 : 0; - hList.Add(h); + hList.AddRounded(h); decimal aCount = aList.Sum(); - aCountList.Add(aCount); + aCountList.AddRounded(aCount); decimal hCount = hList.Sum(); - hCountList.Add(hCount); + hCountList.AddRounded(hCount); decimal haRatio = aCount != 0 ? hCount / aCount : 0; decimal prevTei = teiList.LastOrDefault(); decimal tei = prevTei + (sc * (haRatio - prevTei)); - teiList.Add(tei); + teiList.AddRounded(tei); } var teiSignalList = GetMovingAverageList(stockData, maType, length, teiList); for (int i = 0; i < stockData.Count; i++) { - decimal tei = teiList.ElementAtOrDefault(i); - decimal teiSignal = teiSignalList.ElementAtOrDefault(i); - decimal prevTei = i >= 1 ? teiList.ElementAtOrDefault(i - 1) : 0; - decimal prevTeiSignal = i >= 1 ? teiSignalList.ElementAtOrDefault(i - 1) : 0; + decimal tei = teiList[i]; + decimal teiSignal = teiSignalList[i]; + decimal prevTei = i >= 1 ? teiList[i - 1] : 0; + decimal prevTeiSignal = i >= 1 ? teiSignalList[i - 1] : 0; var signal = GetCompareSignal(tei - teiSignal, prevTei - prevTeiSignal); signalsList.Add(signal); @@ -234,23 +234,23 @@ public static StockData CalculateTrendImpulseFilter(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevB = i >= 1 ? bList.ElementAtOrDefault(i - 1) : currentValue; - decimal highest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal lowest = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevB = i >= 1 ? bList[i - 1] : currentValue; + decimal highest = i >= 1 ? highestList[i - 1] : 0; + decimal lowest = i >= 1 ? lowestList[i - 1] : 0; decimal a = currentValue > highest || currentValue < lowest ? 1 : 0; decimal b = (a * currentValue) + ((1 - a) * prevB); - bList.Add(b); + bList.AddRounded(b); } var bEmaList = GetMovingAverageList(stockData, maType, length2, bList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal bEma = bEmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevBEma = i >= 1 ? bEmaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal bEma = bEmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevBEma = i >= 1 ? bEmaList[i - 1] : 0; var signal = GetCompareSignal(currentValue - bEma, prevValue - prevBEma); signalsList.Add(signal); @@ -287,23 +287,23 @@ public static StockData CalculateTrendAnalysisIndex(this StockData stockData, Mo for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; decimal tai = currentValue != 0 ? (highest - lowest) * 100 / currentValue : 0; - taiList.Add(tai); + taiList.AddRounded(tai); } var taiMaList = GetMovingAverageList(stockData, maType, length2, taiList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; - decimal tai = taiList.ElementAtOrDefault(i); - decimal taiSma = taiMaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; + decimal tai = taiList[i]; + decimal taiSma = taiMaList[i]; var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, tai, taiSma); signalsList.Add(signal); @@ -343,12 +343,12 @@ public static StockData CalculateTrendAnalysisIndicator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal tai = taiList.ElementAtOrDefault(i); - decimal fastMa = fastMaList.ElementAtOrDefault(i); - decimal slowMa = slowMaList.ElementAtOrDefault(i); - decimal taiMa = taiSmaList.ElementAtOrDefault(i); - decimal prevFastMa = i >= 1 ? fastMaList.ElementAtOrDefault(i - 1) : 0; - decimal prevSlowMa = i >= 1 ? slowMaList.ElementAtOrDefault(i - 1) : 0; + decimal tai = taiList[i]; + decimal fastMa = fastMaList[i]; + decimal slowMa = slowMaList[i]; + decimal taiMa = taiSmaList[i]; + decimal prevFastMa = i >= 1 ? fastMaList[i - 1] : 0; + decimal prevSlowMa = i >= 1 ? slowMaList[i - 1] : 0; var signal = GetVolatilitySignal(fastMa - slowMa, prevFastMa - prevSlowMa, tai, taiMa); signalsList.Add(signal); @@ -391,39 +391,39 @@ public static StockData CalculateTrender(this StockData stockData, MovingAvgType for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal mpEma = emaList.ElementAtOrDefault(i); - decimal trEma = atrList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal mpEma = emaList[i]; + decimal trEma = atrList[i]; decimal ad = currentValue > prevValue ? mpEma + (trEma / 2) : currentValue < prevValue ? mpEma - (trEma / 2) : mpEma; - adList.Add(ad); + adList.AddRounded(ad); } var admList = GetMovingAverageList(stockData, maType, length, adList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal adm = admList.ElementAtOrDefault(i); - decimal prevAdm = i >= 1 ? admList.ElementAtOrDefault(i - 1) : 0; - decimal mpEma = emaList.ElementAtOrDefault(i); - decimal prevMpEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 2 ? highList.ElementAtOrDefault(i - 2) : 0; - decimal prevLow = i >= 2 ? lowList.ElementAtOrDefault(i - 2) : 0; - decimal stdDev = stdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal adm = admList[i]; + decimal prevAdm = i >= 1 ? admList[i - 1] : 0; + decimal mpEma = emaList[i]; + decimal prevMpEma = i >= 1 ? emaList[i - 1] : 0; + decimal prevHigh = i >= 2 ? highList[i - 2] : 0; + decimal prevLow = i >= 2 ? lowList[i - 2] : 0; + decimal stdDev = stdDevList[i]; decimal prevTrndDn = trndDnList.LastOrDefault(); decimal trndDn = adm < mpEma && prevAdm > prevMpEma ? prevHigh : currentValue < prevValue ? currentValue + (stdDev * atrMult) : prevTrndDn; - trndDnList.Add(trndDn); + trndDnList.AddRounded(trndDn); decimal prevTrndUp = trndUpList.LastOrDefault(); decimal trndUp = adm > mpEma && prevAdm < prevMpEma ? prevLow : currentValue > prevValue ? currentValue - (stdDev * atrMult) : prevTrndUp; - trndUpList.Add(trndUp); + trndUpList.AddRounded(trndUp); decimal prevTrndr = trndrList.LastOrDefault(); decimal trndr = adm < mpEma ? trndDn : adm > mpEma ? trndUp : prevTrndr; - trndrList.Add(trndr); + trndrList.AddRounded(trndr); var signal = GetCompareSignal(currentValue - trndr, prevValue - prevTrndr); signalsList.Add(signal); @@ -463,18 +463,18 @@ public static StockData CalculateTrendDirectionForceIndex(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i) * 1000; - srcList.Add(currentValue); + decimal 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++) { - decimal ema1 = ema1List.ElementAtOrDefault(i); - decimal ema2 = ema2List.ElementAtOrDefault(i); - decimal prevEma1 = i >= 1 ? ema1List.ElementAtOrDefault(i - 1) : 0; - decimal prevEma2 = i >= 1 ? ema2List.ElementAtOrDefault(i - 1) : 0; + decimal ema1 = ema1List[i]; + decimal ema2 = ema2List[i]; + decimal prevEma1 = i >= 1 ? ema1List[i - 1] : 0; + decimal prevEma2 = i >= 1 ? ema2List[i - 1] : 0; decimal ema1Diff = ema1 - prevEma1; decimal ema2Diff = ema2 - prevEma2; decimal emaDiffAvg = (ema1Diff + ema2Diff) / 2; @@ -490,12 +490,12 @@ public static StockData CalculateTrendDirectionForceIndex(this StockData stockDa } decimal absTdf = Math.Abs(tdf); - absTdfList.Add(absTdf); + absTdfList.AddRounded(absTdf); decimal tdfh = absTdfList.TakeLastExt(length2).Max(); decimal prevTdfi = tdfiList.LastOrDefault(); decimal tdfi = tdfh != 0 ? tdf / tdfh : 0; - tdfiList.Add(tdfi); + tdfiList.AddRounded(tdfi); var signal = GetCompareSignal(tdfi, prevTdfi); signalsList.Add(signal); @@ -533,21 +533,21 @@ public static StockData CalculateTrendIntensityIndex(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevTii1 = i >= 1 ? tiiList.ElementAtOrDefault(i - 1) : 0; - decimal prevTii2 = i >= 2 ? tiiList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; + decimal prevTii1 = i >= 1 ? tiiList[i - 1] : 0; + decimal prevTii2 = i >= 2 ? tiiList[i - 2] : 0; decimal deviationUp = currentValue > currentSma ? currentValue - currentSma : 0; - deviationUpList.Add(deviationUp); + deviationUpList.AddRounded(deviationUp); decimal deviationDown = currentValue < currentSma ? currentSma - currentValue : 0; - deviationDownList.Add(deviationDown); + deviationDownList.AddRounded(deviationDown); decimal sdPlus = deviationUpList.TakeLastExt(fastLength).Sum(); decimal sdMinus = deviationDownList.TakeLastExt(fastLength).Sum(); decimal tii = sdPlus + sdMinus != 0 ? sdPlus / (sdPlus + sdMinus) * 100 : 0; - tiiList.Add(tii); + tiiList.AddRounded(tii); var signal = GetRsiSignal(tii - prevTii1, prevTii1 - prevTii2, tii, prevTii1, 80, 20); signalsList.Add(signal); @@ -586,35 +586,35 @@ public static StockData CalculateTrendForceHistogram(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal highest = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal lowest = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal ema = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal highest = i >= 1 ? highestList[i - 1] : 0; + decimal lowest = i >= 1 ? lowestList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevA = aList.LastOrDefault(); decimal a = currentValue > highest ? 1 : 0; - aList.Add(a); + aList.AddRounded(a); decimal prevB = bList.LastOrDefault(); decimal b = currentValue < lowest ? 1 : 0; - bList.Add(b); + bList.AddRounded(b); decimal prevC = cList.LastOrDefault(); decimal c = a == 1 ? prevC + 1 : b - prevB == 1 ? 0 : prevC; - cList.Add(c); + cList.AddRounded(c); decimal prevD = dList.LastOrDefault(); decimal d = b == 1 ? prevD + 1 : a - prevA == 1 ? 0 : prevD; - dList.Add(d); + dList.AddRounded(d); decimal avg = (c + d) / 2; - avgList.Add(avg); + avgList.AddRounded(avg); decimal rmean = i != 0 ? avgList.Sum() / i : 0; decimal osc = avg - rmean; - oscList.Add(osc); + oscList.AddRounded(osc); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, osc, 0); signalsList.Add(signal); @@ -649,25 +649,25 @@ public static StockData CalculateTrendDetectionIndex(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length1 ? inputList[i - length1] : 0; decimal mom = currentValue - prevValue; - momList.Add(mom); + momList.AddRounded(mom); decimal momAbs = Math.Abs(mom); - momAbsList.Add(momAbs); + momAbsList.AddRounded(momAbs); decimal prevTdiDirection = tdiDirectionList.LastOrDefault(); decimal tdiDirection = momList.TakeLastExt(length1).Sum(); - tdiDirectionList.Add(tdiDirection); + tdiDirectionList.AddRounded(tdiDirection); decimal momAbsSum1 = momAbsList.TakeLastExt(length1).Sum(); decimal momAbsSum2 = momAbsList.TakeLastExt(length2).Sum(); decimal prevTdi = tdiList.LastOrDefault(); decimal tdi = Math.Abs(tdiDirection) - momAbsSum2 + momAbsSum1; - tdiList.Add(tdi); + tdiList.AddRounded(tdi); var signal = GetCompareSignal(tdiDirection - tdi, prevTdiDirection - prevTdi); signalsList.Add(signal); @@ -704,33 +704,33 @@ public static StockData CalculateTrendContinuationFactor(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal priceChg = currentValue - prevValue; decimal chgPlus = priceChg > 0 ? priceChg : 0; decimal chgMinus = priceChg < 0 ? Math.Abs(priceChg) : 0; decimal prevCfPlus = cfPlusList.LastOrDefault(); decimal cfPlus = chgPlus == 0 ? 0 : chgPlus + prevCfPlus; - cfPlusList.Add(cfPlus); + cfPlusList.AddRounded(cfPlus); decimal prevCfMinus = cfMinusList.LastOrDefault(); decimal cfMinus = chgMinus == 0 ? 0 : chgMinus + prevCfMinus; - cfMinusList.Add(cfMinus); + cfMinusList.AddRounded(cfMinus); decimal diffPlus = chgPlus - cfMinus; - diffPlusList.Add(diffPlus); + diffPlusList.AddRounded(diffPlus); decimal diffMinus = chgMinus - cfPlus; - diffMinusList.Add(diffMinus); + diffMinusList.AddRounded(diffMinus); decimal prevTcfPlus = tcfPlusList.LastOrDefault(); decimal tcfPlus = diffPlusList.TakeLastExt(length).Sum(); - tcfPlusList.Add(tcfPlus); + tcfPlusList.AddRounded(tcfPlus); decimal prevTcfMinus = tcfMinusList.LastOrDefault(); decimal tcfMinus = diffMinusList.TakeLastExt(length).Sum(); - tcfMinusList.Add(tcfMinus); + tcfMinusList.AddRounded(tcfMinus); var signal = GetCompareSignal(tcfPlus - tcfMinus, prevTcfPlus - prevTcfMinus); signalsList.Add(signal); @@ -770,28 +770,28 @@ public static StockData CalculateSuperTrend(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentAtr = atrList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal atrValue = atrMult * currentAtr; decimal tempLongStop = currentValue - atrValue; decimal tempShortStop = currentValue + atrValue; decimal prevLongStop = longStopList.LastOrDefault(); decimal longStop = prevValue > prevLongStop ? Math.Max(tempLongStop, prevLongStop) : tempLongStop; - longStopList.Add(longStop); + longStopList.AddRounded(longStop); decimal prevShortStop = shortStopList.LastOrDefault(); decimal shortStop = prevValue < prevShortStop ? Math.Max(tempShortStop, prevShortStop) : tempShortStop; - shortStopList.Add(shortStop); + shortStopList.AddRounded(shortStop); decimal prevDir = dirList.LastOrDefault(); decimal dir = prevDir == -1 && currentValue > prevShortStop ? 1 : prevDir == 1 && currentValue < prevLongStop ? -1 : prevDir; - dirList.Add(dir); + dirList.AddRounded(dir); decimal prevTrend = trendList.LastOrDefault(); decimal trend = dir > 0 ? longStop : shortStop; - trendList.Add(trend); + trendList.AddRounded(trend); var signal = GetCompareSignal(currentValue - trend, prevValue - prevTrend); signalsList.Add(signal); @@ -829,20 +829,20 @@ public static StockData CalculateSchaffTrendCycle(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentEma23 = ema23List.ElementAtOrDefault(i); - decimal currentEma50 = ema50List.ElementAtOrDefault(i); + decimal currentEma23 = ema23List[i]; + decimal currentEma50 = ema50List[i]; decimal macd = currentEma23 - currentEma50; - macdList.Add(macd); + macdList.AddRounded(macd); } stockData.CustomValuesList = macdList; var stcList = CalculateStochasticOscillator(stockData, maType, length: cycleLength).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal stc = stcList.ElementAtOrDefault(i); - decimal prevStc1 = i >= 1 ? stcList.ElementAtOrDefault(i - 1) : 0; - decimal prevStc2 = i >= 2 ? stcList.ElementAtOrDefault(i - 2) : 0; + decimal stc = stcList[i]; + decimal prevStc1 = i >= 1 ? stcList[i - 1] : 0; + decimal prevStc2 = i >= 2 ? stcList[i - 2] : 0; var signal = GetRsiSignal(stc - prevStc1, prevStc1 - prevStc2, stc, prevStc1, 75, 25); signalsList.Add(signal); @@ -877,26 +877,26 @@ public static StockData CalculateUberTrendIndicator(this StockData stockData, in for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevUti1 = i >= 1 ? utiList.ElementAtOrDefault(i - 1) : 0; - decimal prevUti2 = i >= 2 ? utiList.ElementAtOrDefault(i - 2) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentVolume = volumeList[i]; + decimal prevUti1 = i >= 1 ? utiList[i - 1] : 0; + decimal prevUti2 = i >= 2 ? utiList[i - 2] : 0; decimal adv = currentValue > prevValue ? currentValue - prevValue : 0; - advList.Add(adv); + advList.AddRounded(adv); decimal dec = currentValue < prevValue ? prevValue - currentValue : 0; - decList.Add(dec); + decList.AddRounded(dec); decimal advSum = advList.TakeLastExt(length).Sum(); decimal decSum = decList.TakeLastExt(length).Sum(); decimal advVol = currentValue > prevValue && advSum != 0 ? currentVolume / advSum : 0; - advVolList.Add(advVol); + advVolList.AddRounded(advVol); decimal decVol = currentValue < prevValue && decSum != 0 ? currentVolume / decSum : 0; - decVolList.Add(decVol); + decVolList.AddRounded(decVol); decimal advVolSum = advVolList.TakeLastExt(length).Sum(); decimal decVolSum = decVolList.TakeLastExt(length).Sum(); @@ -905,7 +905,7 @@ public static StockData CalculateUberTrendIndicator(this StockData stockData, in decimal ut = bot != 0 ? top / bot : 0; decimal uti = ut + 1 != 0 ? (ut - 1) / (ut + 1) : 0; - utiList.Add(uti); + utiList.AddRounded(uti); var signal = GetCompareSignal(uti - prevUti1, prevUti1 - prevUti2); signalsList.Add(signal); @@ -944,32 +944,32 @@ public static StockData CalculateWaveTrendOscillator(this StockData stockData, I for (int i = 0; i < stockData.Count; i++) { - decimal ap = inputList.ElementAtOrDefault(i); - decimal esa = emaList.ElementAtOrDefault(i); + decimal ap = inputList[i]; + decimal esa = emaList[i]; decimal absApEsa = Math.Abs(ap - esa); - absApEsaList.Add(absApEsa); + absApEsaList.AddRounded(absApEsa); } var dList = GetMovingAverageList(stockData, maType, length1, absApEsaList); for (int i = 0; i < stockData.Count; i++) { - decimal ap = inputList.ElementAtOrDefault(i); - decimal esa = emaList.ElementAtOrDefault(i); - decimal d = dList.ElementAtOrDefault(i); + decimal ap = inputList[i]; + decimal esa = emaList[i]; + decimal d = dList[i]; decimal ci = d != 0 ? (ap - esa) / (0.015m * d) : 0; - ciList.Add(ci); + 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++) { - decimal tci = tciList.ElementAtOrDefault(i); - decimal wt2 = wt2List.ElementAtOrDefault(i); - decimal prevTci = i >= 1 ? tciList.ElementAtOrDefault(i - 1) : 0; - decimal prevWt2 = i >= 1 ? wt2List.ElementAtOrDefault(i - 1) : 0; + decimal tci = tciList[i]; + decimal wt2 = wt2List[i]; + decimal prevTci = i >= 1 ? tciList[i - 1] : 0; + decimal prevWt2 = i >= 1 ? wt2List[i - 1] : 0; var signal = GetRsiSignal(tci - wt2, prevTci - prevWt2, tci, prevTci, 53, -53); signalsList.Add(signal); @@ -1008,24 +1008,24 @@ public static StockData CalculateOptimizedTrendTracker(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal ma = maList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal ma = maList[i]; decimal fark = ma * percent * 0.01m; decimal prevLongStop = longStopList.LastOrDefault(); decimal longStop = ma - fark; longStop = ma > prevLongStop ? Math.Max(longStop, prevLongStop) : longStop; - longStopList.Add(longStop); + longStopList.AddRounded(longStop); decimal prevShortStop = shortStopList.LastOrDefault(); decimal shortStop = ma + fark; - shortStopList.Add(shortStop); + shortStopList.AddRounded(shortStop); decimal prevOtt = ottList.LastOrDefault(); decimal mt = ma > prevShortStop ? longStop : ma < prevLongStop ? shortStop : 0; decimal ott = ma > mt ? mt * (200 + percent) / 200 : mt * (200 - percent) / 200; - ottList.Add(ott); + ottList.AddRounded(ott); var signal = GetCompareSignal(currentValue - ott, prevValue - prevOtt); signalsList.Add(signal); @@ -1057,16 +1057,16 @@ public static StockData CalculateGannTrendOscillator(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); - decimal prevHighest1 = i >= 1 ? highestList.ElementAtOrDefault(i - 1) : 0; - decimal prevLowest1 = i >= 1 ? lowestList.ElementAtOrDefault(i - 1) : 0; - decimal prevHighest2 = i >= 2 ? highestList.ElementAtOrDefault(i - 2) : 0; - decimal prevLowest2 = i >= 2 ? lowestList.ElementAtOrDefault(i - 2) : 0; + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; + decimal prevHighest1 = i >= 1 ? highestList[i - 1] : 0; + decimal prevLowest1 = i >= 1 ? lowestList[i - 1] : 0; + decimal prevHighest2 = i >= 2 ? highestList[i - 2] : 0; + decimal prevLowest2 = i >= 2 ? lowestList[i - 2] : 0; decimal prevGto = gannTrendOscillatorList.LastOrDefault(); decimal gto = prevHighest2 > prevHighest1 && highestHigh > prevHighest1 ? 1 : prevLowest2 < prevLowest1 && lowestLow < prevLowest1 ? -1 : prevGto; - gannTrendOscillatorList.Add(gto); + gannTrendOscillatorList.AddRounded(gto); var signal = GetCompareSignal(gto, prevGto); signalsList.Add(signal); @@ -1107,43 +1107,43 @@ public static StockData CalculateGrandTrendForecasting(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevT = i >= length ? tList.ElementAtOrDefault(i - length) : currentValue; - decimal priorT = i >= forecastLength ? tList.ElementAtOrDefault(i - forecastLength) : 0; - decimal prevFcast = i >= forecastLength ? fcastList.ElementAtOrDefault(i - forecastLength) : 0; - decimal prevChg = i >= length ? chgList.ElementAtOrDefault(i - length) : currentValue; + decimal currentValue = inputList[i]; + decimal prevT = i >= length ? tList[i - length] : currentValue; + decimal priorT = i >= forecastLength ? tList[i - forecastLength] : 0; + decimal prevFcast = i >= forecastLength ? fcastList[i - forecastLength] : 0; + decimal prevChg = i >= length ? chgList[i - length] : currentValue; decimal chg = 0.9m * prevT; - chgList.Add(chg); + chgList.AddRounded(chg); decimal t = (0.9m * prevT) + (0.1m * currentValue) + (chg - prevChg); - tList.Add(t); + tList.AddRounded(t); decimal trend = tList.TakeLastExt(length).Average(); - trendList.Add(trend); + trendList.AddRounded(trend); decimal fcast = t + (t - priorT); - fcastList.Add(fcast); + fcastList.AddRounded(fcast); decimal diff = Math.Abs(currentValue - prevFcast); - diffList.Add(diff); + diffList.AddRounded(diff); decimal diffSma = diffList.TakeLastExt(forecastLength).Average(); decimal dev = diffSma * mult; decimal upper = fcast + dev; - upperList.Add(upper); + upperList.AddRounded(upper); decimal lower = fcast - dev; - lowerList.Add(lower); + lowerList.AddRounded(lower); decimal prevBullSlope = bullSlopeList.LastOrDefault(); decimal bullSlope = currentValue - Math.Max(fcast, Math.Max(t, trend)); - bullSlopeList.Add(bullSlope); + bullSlopeList.AddRounded(bullSlope); decimal prevBearSlope = bearSlopeList.LastOrDefault(); decimal bearSlope = currentValue - Math.Min(fcast, Math.Min(t, trend)); - bearSlopeList.Add(bearSlope); + bearSlopeList.AddRounded(bearSlope); var signal = GetBullishBearishSignal(bullSlope, prevBullSlope, bearSlope, prevBearSlope); signalsList.Add(signal); @@ -1191,36 +1191,36 @@ public static StockData CalculateCoralTrendIndicator(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevI1 = i1List.LastOrDefault(); decimal i1 = (c1 * currentValue) + (c2 * prevI1); - i1List.Add(i1); + i1List.AddRounded(i1); decimal prevI2 = i2List.LastOrDefault(); decimal i2 = (c1 * i1) + (c2 * prevI2); - i2List.Add(i2); + i2List.AddRounded(i2); decimal prevI3 = i3List.LastOrDefault(); decimal i3 = (c1 * i2) + (c2 * prevI3); - i3List.Add(i3); + i3List.AddRounded(i3); decimal prevI4 = i4List.LastOrDefault(); decimal i4 = (c1 * i3) + (c2 * prevI4); - i4List.Add(i4); + i4List.AddRounded(i4); decimal prevI5 = i5List.LastOrDefault(); decimal i5 = (c1 * i4) + (c2 * prevI5); - i5List.Add(i5); + i5List.AddRounded(i5); decimal prevI6 = i6List.LastOrDefault(); decimal i6 = (c1 * i5) + (c2 * prevI6); - i6List.Add(i6); + i6List.AddRounded(i6); decimal prevBfr = bfrList.LastOrDefault(); decimal bfr = (-1 * cd * cd * cd * i6) + (c3 * i5) + (c4 * i4) + (c5 * i3); - bfrList.Add(bfr); + bfrList.AddRounded(bfr); var signal = GetCompareSignal(currentValue - bfr, prevValue - prevBfr); signalsList.Add(signal); @@ -1253,22 +1253,22 @@ public static StockData CalculatePriceVolumeTrend(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevPvt = priceVolumeTrendList.LastOrDefault(); decimal pvt = prevValue != 0 ? prevPvt + (currentVolume * ((currentValue - prevValue) / prevValue)) : prevPvt; - priceVolumeTrendList.Add(pvt); + priceVolumeTrendList.AddRounded(pvt); } var pvtEmaList = GetMovingAverageList(stockData, maType, length, priceVolumeTrendList); for (int i = 0; i < stockData.Count; i++) { - decimal pvt = priceVolumeTrendList.ElementAtOrDefault(i); - decimal pvtEma = pvtEmaList.ElementAtOrDefault(i); - decimal prevPvt = i >= 1 ? priceVolumeTrendList.ElementAtOrDefault(i - 1) : 0; - decimal prevPvtEma = i >= 1 ? pvtEmaList.ElementAtOrDefault(i - 1) : 0; + decimal pvt = priceVolumeTrendList[i]; + decimal pvtEma = pvtEmaList[i]; + decimal prevPvt = i >= 1 ? priceVolumeTrendList[i - 1] : 0; + decimal prevPvtEma = i >= 1 ? pvtEmaList[i - 1] : 0; var signal = GetCompareSignal(pvt - pvtEma, prevPvt - prevPvtEma); signalsList.Add(signal); @@ -1301,30 +1301,30 @@ public static StockData CalculatePercentageTrend(this StockData stockData, int l for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentValue = inputList[i]; int period = 0; decimal prevTrend = trendList.LastOrDefault(); decimal trend = currentValue; - for (int j = 0; j < length; j++) + for (int j = 1; j <= length; j++) { - decimal prevC = i >= j - 1 ? inputList.ElementAtOrDefault(i - (j - 1)) : 0; - decimal currC = i >= j ? inputList.ElementAtOrDefault(i - j) : 0; + decimal prevC = i >= j - 1 ? inputList[i - (j - 1)] : 0; + decimal currC = i >= j ? inputList[i - j] : 0; period = (prevC <= trend && currC > trend) || (prevC >= trend && currC < trend) ? 0 : period; decimal highest1 = currC, lowest1 = currC; - for (int k = 0; k < period; k++) + for (int k = j - period; k <= j; k++) { - decimal c = i >= j - k ? inputList.ElementAtOrDefault(i - (j - k)) : 0; + decimal c = i >= j - k ? inputList[i - (j - k)] : 0; highest1 = Math.Max(highest1, c); lowest1 = Math.Min(lowest1, c); } decimal highest2 = currC, lowest2 = currC; - for (int k = 0; k < length; k++) + for (int k = i - length; k <= j; k++) { - decimal c = i >= j - k ? inputList.ElementAtOrDefault(i - (j - k)) : 0; + decimal c = i >= j - k ? inputList[i - (j - k)] : 0; highest2 = Math.Max(highest2, c); lowest2 = Math.Min(lowest2, c); } @@ -1339,7 +1339,7 @@ public static StockData CalculatePercentageTrend(this StockData stockData, int l trend = currC > trend ? highest2 * (1 - pct) : lowest2 * (1 + pct); } } - trendList.Add(trend); + trendList.AddRounded(trend); var signal = GetCompareSignal(currentValue - trend, prevValue - prevTrend); signalsList.Add(signal); @@ -1372,23 +1372,23 @@ public static StockData CalculateModifiedPriceVolumeTrend(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentVolume = volumeList[i]; decimal rv = currentVolume / 50000; decimal prevMpvt = mpvtList.LastOrDefault(); decimal mpvt = prevValue != 0 ? prevMpvt + (rv * (currentValue - prevValue) / prevValue) : 0; - mpvtList.Add(mpvt); + mpvtList.AddRounded(mpvt); } var mpvtSignalList = GetMovingAverageList(stockData, maType, length, mpvtList); for (int i = 0; i < stockData.Count; i++) { - decimal mpvt = mpvtList.ElementAtOrDefault(i); - decimal mpvtSignal = mpvtSignalList.ElementAtOrDefault(i); - decimal prevMpvt = i >= 1 ? mpvtList.ElementAtOrDefault(i - 1) : 0; - decimal prevMpvtSignal = i >= 1 ? mpvtSignalList.ElementAtOrDefault(i - 1) : 0; + decimal mpvt = mpvtList[i]; + decimal mpvtSignal = mpvtSignalList[i]; + decimal prevMpvt = i >= 1 ? mpvtList[i - 1] : 0; + decimal prevMpvtSignal = i >= 1 ? mpvtSignalList[i - 1] : 0; var signal = GetCompareSignal(mpvt - mpvtSignal, prevMpvt - prevMpvtSignal); signalsList.Add(signal); diff --git a/Calculations/Volatility.cs b/Calculations/Volatility.cs index e403be9..26fa137 100644 --- a/Calculations/Volatility.cs +++ b/Calculations/Volatility.cs @@ -21,8 +21,8 @@ public static StockData CalculateStandardDeviationVolatility(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; decimal currentDeviation = currentValue - currentSma; decimal deviationSquared = Pow(currentDeviation, 2); @@ -32,7 +32,7 @@ public static StockData CalculateStandardDeviationVolatility(this StockData stoc var divisionOfSumList = GetMovingAverageList(stockData, maType, length, deviationSquaredList); for (int i = 0; i < stockData.Count; i++) { - decimal divisionOfSum = divisionOfSumList.ElementAtOrDefault(i); + decimal divisionOfSum = divisionOfSumList[i]; decimal stdDevVolatility = Sqrt(divisionOfSum); stdDevVolatilityList.AddRounded(stdDevVolatility); @@ -41,12 +41,12 @@ public static StockData CalculateStandardDeviationVolatility(this StockData stoc var stdDevSmaList = GetMovingAverageList(stockData, maType, length, stdDevVolatilityList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; - decimal stdDev = stdDevVolatilityList.ElementAtOrDefault(i); - decimal stdDevMa = stdDevSmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; + decimal stdDev = stdDevVolatilityList[i]; + decimal stdDevMa = stdDevSmaList[i]; Signal signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, stdDev, stdDevMa); signalsList.Add(signal); @@ -85,27 +85,27 @@ public static StockData CalculateHistoricalVolatility(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal temp = prevValue != 0 ? currentValue / prevValue : 0; decimal tempLog = temp > 0 ? Log(temp) : 0; - tempLogList.Add(tempLog); + tempLogList.AddRounded(tempLog); } stockData.CustomValuesList = tempLogList; var stdDevLogList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - var stdDevLog = stdDevLogList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + var stdDevLog = stdDevLogList[i]; + decimal currentEma = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevHv = hvList.LastOrDefault(); decimal hv = 100 * stdDevLog * annualSqrt; - hvList.Add(hv); + hvList.AddRounded(hv); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, hv, prevHv); signalsList.Add(signal); @@ -145,17 +145,17 @@ public static StockData CalculateMovingAverageBandWidth(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal mb = maList.ElementAtOrDefault(i); - decimal ub = ubList.ElementAtOrDefault(i); - decimal lb = lbList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMb = i >= 1 ? maList.ElementAtOrDefault(i - 1) : 0; - decimal prevUb = i >= 1 ? ubList.ElementAtOrDefault(i - 1) : 0; - decimal prevLb = i >= 1 ? lbList.ElementAtOrDefault(i - 1) : 0; + decimal mb = maList[i]; + decimal ub = ubList[i]; + decimal lb = lbList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevMb = i >= 1 ? maList[i - 1] : 0; + decimal prevUb = i >= 1 ? ubList[i - 1] : 0; + decimal prevLb = i >= 1 ? lbList[i - 1] : 0; decimal mabw = mb != 0 ? (ub - lb) / mb * 100 : 0; - mabwList.Add(mabw); + mabwList.AddRounded(mabw); var signal = GetBollingerBandsSignal(currentValue - mb, prevValue - prevMb, currentValue, prevValue, ub, prevUb, lb, prevLb); signalsList.Add(signal); @@ -195,31 +195,31 @@ public static StockData CalculateMovingAverageAdaptiveFilter(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevAma = i >= 1 ? amaList.ElementAtOrDefault(i - 1) : currentValue; - decimal er = erList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevAma = i >= 1 ? amaList[i - 1] : currentValue; + decimal er = erList[i]; decimal sm = Pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2); decimal ama = prevAma + (sm * (currentValue - prevAma)); - amaList.Add(ama); + amaList.AddRounded(ama); decimal amaDiff = ama - prevAma; - amaDiffList.Add(amaDiff); + amaDiffList.AddRounded(amaDiff); } stockData.CustomValuesList = amaDiffList; var stdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal stdDev = stdDevList[i]; + decimal currentValue = inputList[i]; + decimal ema = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal prevMaaf = maafList.LastOrDefault(); decimal maaf = stdDev * filter; - maafList.Add(maaf); + maafList.AddRounded(maaf); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, maaf, prevMaaf); signalsList.Add(signal); @@ -262,37 +262,37 @@ public static StockData CalculateRelativeNormalizedVolatility(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal spValue = spInputList.ElementAtOrDefault(i); - decimal prevSpValue = i >= 1 ? spInputList.ElementAtOrDefault(i - 1) : 0; - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal spStdDev = spStdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal spValue = spInputList[i]; + decimal prevSpValue = i >= 1 ? spInputList[i - 1] : 0; + decimal stdDev = stdDevList[i]; + decimal spStdDev = spStdDevList[i]; decimal d = currentValue - prevValue; decimal sp = spValue - prevSpValue; decimal zsrc = stdDev != 0 ? d / stdDev : 0; decimal zsp = spStdDev != 0 ? sp / spStdDev : 0; decimal absZsrc = Math.Abs(zsrc); - absZsrcList.Add(absZsrc); + absZsrcList.AddRounded(absZsrc); decimal absZsp = Math.Abs(zsp); - absZspList.Add(absZsp); + 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++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal absZsrcSma = absZsrcSmaList.ElementAtOrDefault(i); - decimal absZspSma = absZspSmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal absZsrcSma = absZsrcSmaList[i]; + decimal absZspSma = absZspSmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal r = absZspSma != 0 ? absZsrcSma / absZspSma : 0; - rList.Add(r); + rList.AddRounded(r); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, r, 1); signalsList.Add(signal); @@ -333,31 +333,31 @@ public static StockData CalculateReversalPoints(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal max = Math.Max(currentValue, prevValue); decimal min = Math.Min(currentValue, prevValue); decimal a = max - min; - aList.Add(a); + 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++) { - decimal aEma1 = aEma1List.ElementAtOrDefault(i); - decimal aEma2 = aEma2List.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal aEma1 = aEma1List[i]; + decimal aEma2 = aEma2List[i]; + decimal currentValue = inputList[i]; + decimal ema = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal b = aEma2 != 0 ? aEma1 / aEma2 : 0; - bList.Add(b); + bList.AddRounded(b); decimal bSum = bList.TakeLastExt(length).Sum(); - bSumList.Add(bSum); + bSumList.AddRounded(bSum); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, bSum, c); signalsList.Add(signal); @@ -393,13 +393,13 @@ public static StockData CalculateMayerMultiple(this StockData stockData, MovingA for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal mm = currentSma != 0 ? currentValue / currentSma : 0; - mmList.Add(mm); + mmList.AddRounded(mm); var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, mm, threshold); signalsList.Add(signal); @@ -434,26 +434,26 @@ public static StockData CalculateMotionSmoothnessIndex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal chg = currentValue - prevValue; - chgList.Add(chg); + chgList.AddRounded(chg); } stockData.CustomValuesList = chgList; var aChgStdDevList = CalculateStandardDeviationVolatility(stockData, length: length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal aChgStdDev = aChgStdDevList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal aChgStdDev = aChgStdDevList[i]; + decimal stdDev = stdDevList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal b = stdDev != 0 ? aChgStdDev / stdDev : 0; - bList.Add(b); + bList.AddRounded(b); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, b, 0.5m); signalsList.Add(signal); @@ -490,22 +490,22 @@ public static StockData CalculateChoppinessIndex(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal highestHigh = highestHighList.ElementAtOrDefault(i); - decimal lowestLow = lowestLowList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal highestHigh = highestHighList[i]; + decimal lowestLow = lowestLowList[i]; decimal range = highestHigh - lowestLow; decimal tr = CalculateTrueRange(currentHigh, currentLow, prevValue); - trList.Add(tr); + trList.AddRounded(tr); decimal trSum = trList.TakeLastExt(length).Sum(); decimal ci = range > 0 ? 100 * Log10(trSum / range) / Log10(length) : 0; - ciList.Add(ci); + ciList.AddRounded(ci); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, ci, 38.2m); signalsList.Add(signal); @@ -541,17 +541,17 @@ public static StockData CalculateUltimateVolatilityIndicator(this StockData stoc for (int i = 0; i < stockData.Count; i++) { - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentMa = maList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMa = i >= 1 ? maList.ElementAtOrDefault(i - 1) : 0; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; + decimal currentMa = maList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevMa = i >= 1 ? maList[i - 1] : 0; decimal abs = Math.Abs(currentClose - currentOpen); - absList.Add(abs); + absList.AddRounded(abs); decimal uvi = (decimal)1 / length * absList.TakeLastExt(length).Sum(); - uviList.Add(uvi); + uviList.AddRounded(uvi); var signal = GetVolatilitySignal(currentClose - currentMa, prevClose - prevMa, uvi, 1); signalsList.Add(signal); @@ -586,16 +586,16 @@ public static StockData CalculateQmaSmaDifference(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal qma = qmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal sma = smaList[i]; + decimal qma = qmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal prevC = cList.LastOrDefault(); decimal c = qma - sma; - cList.Add(c); + cList.AddRounded(c); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, c, prevC); signalsList.Add(signal); @@ -632,30 +632,30 @@ public static StockData CalculateGarmanKlassVolatility(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; decimal logHl = currentLow != 0 ? Log(currentHigh / currentLow) : 0; decimal logCo = currentOpen != 0 ? Log(currentClose / currentOpen) : 0; decimal log = (0.5m * Pow(logHl, 2)) - (((2 * Log(2)) - 1) * Pow(logCo, 2)); - logList.Add(log); + logList.AddRounded(log); decimal logSum = logList.TakeLastExt(length).Sum(); decimal gcv = length != 0 && logSum != 0 ? Sqrt((decimal)i / length * logSum) : 0; - gcvList.Add(gcv); + gcvList.AddRounded(gcv); } var gcvWmaList = GetMovingAverageList(stockData, maType, signalLength, gcvList); for (int i = 0; i < stockData.Count; i++) { - var currentClose = inputList.ElementAtOrDefault(i); - var wma = wmaList.ElementAtOrDefault(i); - var prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - var prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; - var gcv = gcvList.ElementAtOrDefault(i); - var gcvWma = i >= 1 ? gcvWmaList.ElementAtOrDefault(i - 1) : 0; + var currentClose = inputList[i]; + var wma = wmaList[i]; + var prevClose = i >= 1 ? inputList[i - 1] : 0; + var prevWma = i >= 1 ? wmaList[i - 1] : 0; + var gcv = gcvList[i]; + var gcvWma = i >= 1 ? gcvWmaList[i - 1] : 0; var signal = GetVolatilitySignal(currentClose - wma, prevClose - prevWma, gcv, gcvWma); signalsList.Add(signal); @@ -693,24 +693,24 @@ public static StockData CalculateGopalakrishnanRangeIndex(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal highestHigh = highestList.ElementAtOrDefault(i); - decimal lowestLow = lowestList.ElementAtOrDefault(i); + decimal highestHigh = highestList[i]; + decimal lowestLow = lowestList[i]; decimal range = highestHigh - lowestLow; decimal rangeLog = range > 0 ? Log(range) : 0; decimal gapo = rangeLog / Log(length); - gapoList.Add(gapo); + gapoList.AddRounded(gapo); } var gapoWmaList = GetMovingAverageList(stockData, maType, length, gapoList); for (int i = 0; i < stockData.Count; i++) { - var gapoWma = gapoWmaList.ElementAtOrDefault(i); - var prevGapoWma = i >= 1 ? gapoWmaList.ElementAtOrDefault(i - 1) : 0; - var currentValue = inputList.ElementAtOrDefault(i); - var prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - var currentWma = wmaList.ElementAtOrDefault(i); - var prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; + var gapoWma = gapoWmaList[i]; + var prevGapoWma = i >= 1 ? gapoWmaList[i - 1] : 0; + 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 signal = GetVolatilitySignal(currentValue - currentWma, prevValue - prevWma, gapoWma, prevGapoWma); signalsList.Add(signal); @@ -752,39 +752,39 @@ public static StockData CalculateHistoricalVolatilityPercentile(this StockData s for (int i = 0; i < stockData.Count; i++) { - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentEma = emaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal temp = prevValue != 0 ? currentValue / prevValue : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; decimal tempLog = temp > 0 ? Log(temp) : 0; - tempLogList.Add(tempLog); + tempLogList.AddRounded(tempLog); decimal avgLog = tempLogList.TakeLastExt(length).Average(); decimal devLogSq = Pow(tempLog - avgLog, 2); - devLogSqList.Add(devLogSq); + devLogSqList.AddRounded(devLogSq); decimal devLogSqAvg = devLogSqList.TakeLastExt(length).Sum() / (length - 1); decimal stdDevLog = devLogSqAvg >= 0 ? Sqrt(devLogSqAvg) : 0; decimal hv = stdDevLog * Sqrt(annualLength); - hvList.Add(hv); + hvList.AddRounded(hv); decimal count = hvList.TakeLastExt(annualLength).Where(i => i < hv).Count(); decimal hvp = count / annualLength * 100; - hvpList.Add(hvp); + hvpList.AddRounded(hvp); } var hvpEmaList = GetMovingAverageList(stockData, maType, length, hvpList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal hvp = hvpList.ElementAtOrDefault(i); - decimal hvpEma = hvpEmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentEma = emaList[i]; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal hvp = hvpList[i]; + decimal hvpEma = hvpEmaList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, hvp, hvpEma); signalsList.Add(signal); @@ -827,16 +827,16 @@ public static StockData CalculateFastZScore(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = smaStdDevList.ElementAtOrDefault(i); - decimal linreg = smaLinregList.ElementAtOrDefault(i); - decimal linreg2 = linreg2List.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal stdDev = smaStdDevList[i]; + decimal linreg = smaLinregList[i]; + decimal linreg2 = linreg2List[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; decimal gs = stdDev != 0 ? (linreg2 - linreg) / stdDev / 2 : 0; - gsList.Add(gs); + gsList.AddRounded(gs); var signal = GetVolatilitySignal(currentValue - sma, prevValue - prevSma, gs, 0); signalsList.Add(signal); @@ -869,12 +869,12 @@ public static StockData CalculateVolatilitySwitchIndicator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal rocSma = (currentValue + prevValue) / 2; decimal dr = rocSma != 0 ? (currentValue - prevValue) / rocSma : 0; - drList.Add(dr); + drList.AddRounded(dr); } stockData.CustomValuesList = drList; @@ -883,11 +883,11 @@ public static StockData CalculateVolatilitySwitchIndicator(this StockData stockD var wmaList = GetMovingAverageList(stockData, maType, length, inputList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentWma = wmaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; - decimal vswitch14 = vswitchList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentWma = wmaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevWma = i >= 1 ? wmaList[i - 1] : 0; + decimal vswitch14 = vswitchList[i]; var signal = GetVolatilitySignal(currentValue - currentWma, prevValue - prevWma, vswitch14, 0.5m); signalsList.Add(signal); @@ -925,29 +925,29 @@ public static StockData CalculateVerticalHorizontalFilter(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal highestPrice = highestList.ElementAtOrDefault(i); - decimal lowestPrice = lowestList.ElementAtOrDefault(i); + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentValue = inputList[i]; + decimal highestPrice = highestList[i]; + decimal lowestPrice = lowestList[i]; decimal numerator = Math.Abs(highestPrice - lowestPrice); decimal priceChange = Math.Abs(currentValue - prevValue); - changeList.Add(priceChange); + changeList.AddRounded(priceChange); decimal denominator = changeList.TakeLastExt(length).Sum(); decimal vhf = denominator != 0 ? numerator / denominator : 0; - vhfList.Add(vhf); + vhfList.AddRounded(vhf); } var vhfWmaList = GetMovingAverageList(stockData, maType, signalLength, vhfList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal currentWma = wmaList.ElementAtOrDefault(i); - decimal prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; - decimal vhfWma = vhfWmaList.ElementAtOrDefault(i); - decimal vhf = vhfList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal currentWma = wmaList[i]; + decimal prevWma = i >= 1 ? wmaList[i - 1] : 0; + decimal vhfWma = vhfWmaList[i]; + decimal vhf = vhfList[i]; var signal = GetVolatilitySignal(currentValue - currentWma, prevValue - prevWma, vhf, vhfWma); signalsList.Add(signal); @@ -985,16 +985,16 @@ public static StockData CalculateClosedFormDistanceVolatility(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal ema = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; - decimal currentHigh = highList.ElementAtOrDefault(i); - tempHighList.Add(currentHigh); + decimal currentHigh = highList[i]; + tempHighList.AddRounded(currentHigh); - decimal currentLow = lowList.ElementAtOrDefault(i); - tempLowList.Add(currentLow); + decimal currentLow = lowList[i]; + tempLowList.AddRounded(currentLow); decimal a = tempHighList.TakeLastExt(length).Sum(); decimal b = tempLowList.TakeLastExt(length).Sum(); @@ -1002,7 +1002,7 @@ public static StockData CalculateClosedFormDistanceVolatility(this StockData sto decimal prevHv = hvList.LastOrDefault(); decimal hv = abAvg != 0 && a != b ? Sqrt((1 - (Pow(a, 0.25m) * Pow(b, 0.25m) / Pow(abAvg, 0.5m)))) : 0; - hvList.Add(hv); + hvList.AddRounded(hv); var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, hv, prevHv); signalsList.Add(signal); @@ -1041,23 +1041,23 @@ public static StockData CalculateProjectionOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal pl = plList.ElementAtOrDefault(i); - decimal pu = puList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal pl = plList[i]; + decimal pu = puList[i]; decimal pbo = pu - pl != 0 ? 100 * (currentValue - pl) / (pu - pl) : 0; - pboList.Add(pbo); + pboList.AddRounded(pbo); } var pboSignalList = GetMovingAverageList(stockData, maType, smoothLength, pboList); for (int i = 0; i < stockData.Count; i++) { - decimal pbo = pboSignalList.ElementAtOrDefault(i); - decimal prevPbo = i >= 1 ? pboSignalList.ElementAtOrDefault(i - 1) : 0; - decimal wma = wmaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal pbo = pboSignalList[i]; + decimal prevPbo = i >= 1 ? pboSignalList[i - 1] : 0; + decimal wma = wmaList[i]; + decimal currentValue = inputList[i]; + decimal prevWma = i >= 1 ? wmaList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; var signal = GetVolatilitySignal(currentValue - wma, prevValue - prevWma, pbo, prevPbo); signalsList.Add(signal); @@ -1096,22 +1096,22 @@ public static StockData CalculateProjectionBandwidth(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal pu = puList.ElementAtOrDefault(i); - decimal pl = plList.ElementAtOrDefault(i); + decimal pu = puList[i]; + decimal pl = plList[i]; decimal pbw = pu + pl != 0 ? 200 * (pu - pl) / (pu + pl) : 0; - pbwList.Add(pbw); + pbwList.AddRounded(pbw); } var pbwSignalList = GetMovingAverageList(stockData, maType, length, pbwList); for (int i = 0; i < stockData.Count; i++) { - decimal pbw = pbwList.ElementAtOrDefault(i); - decimal pbwSignal = pbwSignalList.ElementAtOrDefault(i); - decimal wma = wmaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevWma = i >= 1 ? wmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal pbw = pbwList[i]; + decimal pbwSignal = pbwSignalList[i]; + decimal wma = wmaList[i]; + decimal currentValue = inputList[i]; + decimal prevWma = i >= 1 ? wmaList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; var signal = GetVolatilitySignal(currentValue - wma, prevValue - prevWma, pbw, pbwSignal); signalsList.Add(signal); @@ -1149,22 +1149,22 @@ public static StockData CalculateDonchianChannelWidth(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal upper = highestList.ElementAtOrDefault(i); - decimal lower = lowestList.ElementAtOrDefault(i); + decimal upper = highestList[i]; + decimal lower = lowestList[i]; decimal donchianWidth = upper - lower; - donchianWidthList.Add(donchianWidth); + donchianWidthList.AddRounded(donchianWidth); } var donchianWidthSmaList = GetMovingAverageList(stockData, maType, smoothLength, donchianWidthList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentSma = smaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevSma = i >= 1 ? smaList.ElementAtOrDefault(i - 1) : 0; - decimal donchianWidth = donchianWidthList.ElementAtOrDefault(i); - decimal donchianWidthSma = donchianWidthSmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentSma = smaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevSma = i >= 1 ? smaList[i - 1] : 0; + decimal donchianWidth = donchianWidthList[i]; + decimal donchianWidthSma = donchianWidthSmaList[i]; var signal = GetVolatilitySignal(currentValue - currentSma, prevValue - prevSma, donchianWidth, donchianWidthSma); signalsList.Add(signal); @@ -1205,26 +1205,26 @@ public static StockData CalculateStatisticalVolatility(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal maxC = highestList1.ElementAtOrDefault(i); - decimal minC = lowestList1.ElementAtOrDefault(i); - decimal maxH = highestList2.ElementAtOrDefault(i); - decimal minL = lowestList2.ElementAtOrDefault(i); + decimal maxC = highestList1[i]; + decimal minC = lowestList1[i]; + decimal maxH = highestList2[i]; + decimal minL = lowestList2[i]; decimal cLog = minC != 0 ? Log(maxC / minC) : 0; decimal hlLog = minL != 0 ? Log(maxH / minL) : 0; decimal vol = MinOrMax(((0.6m * cLog * annualSqrt) + (0.6m * hlLog * annualSqrt)) * 0.5m, 2.99m, 0); - volList.Add(vol); + volList.AddRounded(vol); } var volEmaList = GetMovingAverageList(stockData, maType, length1, volList); for (int i = 0; i < stockData.Count; i++) { - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal vol = volList.ElementAtOrDefault(i); - decimal volEma = volEmaList.ElementAtOrDefault(i); + decimal currentEma = emaList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal vol = volList[i]; + decimal volEma = volEmaList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, vol, volEma); signalsList.Add(signal); @@ -1262,37 +1262,37 @@ public static StockData CalculateStandardDevation(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); decimal sum = tempList.TakeLastExt(length).Sum(); decimal sumPow = Pow(sum, 2); - sumList.Add(sumPow); + sumList.AddRounded(sumPow); decimal pow = Pow(currentValue, 2); - powList.Add(pow); + powList.AddRounded(pow); } var powSmaList = GetMovingAverageList(stockData, maType, length, powList); for (int i = 0; i < stockData.Count; i++) { - decimal a = powSmaList.ElementAtOrDefault(i); - decimal sum = sumList.ElementAtOrDefault(i); + decimal a = powSmaList[i]; + decimal sum = sumList[i]; decimal b = sum / Pow(length, 2); decimal c = a - b >= 0 ? Sqrt(a - b) : 0; - cList.Add(c); + cList.AddRounded(c); } var cSmaList = GetMovingAverageList(stockData, maType, length, cList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal c = cList.ElementAtOrDefault(i); - decimal cSma = cSmaList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal c = cList[i]; + decimal cSma = cSmaList[i]; var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, c, cSma); signalsList.Add(signal); @@ -1329,22 +1329,22 @@ public static StockData CalculateVolatilityBasedMomentum(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; + decimal currentAtr = atrList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= length1 ? inputList[i - length1] : 0; decimal rateOfChange = currentValue - prevValue; decimal vbm = currentAtr != 0 ? rateOfChange / currentAtr : 0; - vbmList.Add(vbm); + vbmList.AddRounded(vbm); } var vbmEmaList = GetMovingAverageList(stockData, maType, length1, vbmList); for (int i = 0; i < stockData.Count; i++) { - decimal vbm = vbmList.ElementAtOrDefault(i); - decimal vbmEma = vbmEmaList.ElementAtOrDefault(i); - decimal prevVbm = i >= 1 ? vbmList.ElementAtOrDefault(i - 1) : 0; - decimal prevVbmEma = i >= 1 ? vbmEmaList.ElementAtOrDefault(i - 1) : 0; + decimal vbm = vbmList[i]; + decimal vbmEma = vbmEmaList[i]; + decimal prevVbm = i >= 1 ? vbmList[i - 1] : 0; + decimal prevVbmEma = i >= 1 ? vbmEmaList[i - 1] : 0; var signal = GetCompareSignal(vbm - vbmEma, prevVbm - prevVbmEma); signalsList.Add(signal); @@ -1381,33 +1381,33 @@ public static StockData CalculateVolatilityQualityIndex(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; + decimal currentOpen = openList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal trueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); decimal prevVqiT = vqiTList.LastOrDefault(); decimal vqiT = trueRange != 0 && currentHigh - currentLow != 0 ? (((currentClose - prevClose) / trueRange) + ((currentClose - currentOpen) / (currentHigh - currentLow))) * 0.5m : prevVqiT; - vqiTList.Add(vqiT); + vqiTList.AddRounded(vqiT); decimal vqi = Math.Abs(vqiT) * ((currentClose - prevClose + (currentClose - currentOpen)) * 0.5m); - vqiList.Add(vqi); + vqiList.AddRounded(vqi); decimal vqiSum = vqiList.Sum(); - vqiSumList.Add(vqiSum); + 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++) { - decimal vqiSum = vqiSumList.ElementAtOrDefault(i); - decimal vqiSumFastSma = vqiSumFastSmaList.ElementAtOrDefault(i); - decimal prevVqiSum = i >= 1 ? vqiSumList.ElementAtOrDefault(i - 1) : 0; - decimal prevVqiSumFastSma = i >= 1 ? vqiSumFastSmaList.ElementAtOrDefault(i - 1) : 0; + decimal vqiSum = vqiSumList[i]; + decimal vqiSumFastSma = vqiSumFastSmaList[i]; + decimal prevVqiSum = i >= 1 ? vqiSumList[i - 1] : 0; + decimal prevVqiSumFastSma = i >= 1 ? vqiSumFastSmaList[i - 1] : 0; var signal = GetCompareSignal(vqiSum - vqiSumFastSma, prevVqiSum - prevVqiSumFastSma); signalsList.Add(signal); @@ -1442,29 +1442,29 @@ public static StockData CalculateSigmaSpikes(this StockData stockData, MovingAvg for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal ret = prevValue != 0 ? (currentValue / prevValue) - 1 : 0; - retList.Add(ret); + retList.AddRounded(ret); } stockData.CustomValuesList = retList; var stdList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal prevStd = i >= 1 ? stdList.ElementAtOrDefault(i - 1) : 0; - decimal ret = retList.ElementAtOrDefault(i); + decimal prevStd = i >= 1 ? stdList[i - 1] : 0; + decimal ret = retList[i]; decimal sigma = prevStd != 0 ? ret / prevStd : 0; - sigmaList.Add(sigma); + sigmaList.AddRounded(sigma); } var ssList = GetMovingAverageList(stockData, maType, length, sigmaList); for (int i = 0; i < stockData.Count; i++) { - decimal ss = ssList.ElementAtOrDefault(i); - decimal prevSs = i >= 1 ? ssList.ElementAtOrDefault(i - 1) : 0; + decimal ss = ssList[i]; + decimal prevSs = i >= 1 ? ssList[i - 1] : 0; var signal = GetCompareSignal(ss, prevSs); signalsList.Add(signal); @@ -1503,28 +1503,28 @@ public static StockData CalculateSurfaceRoughnessEstimator(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - tempList.Add(currentValue); + decimal currentValue = inputList[i]; + tempList.AddRounded(currentValue); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - prevList.Add(prevValue); + decimal 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; decimal a = 1 - (((decimal)corr + 1) / 2); - aList.Add(a); + aList.AddRounded(a); } var aEmaList = GetMovingAverageList(stockData, maType, length, aList); for (int i = 0; i < stockData.Count; i++) { - decimal corr = corrList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal ema = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal a = aList.ElementAtOrDefault(i); - decimal aEma = aEmaList.ElementAtOrDefault(i); + decimal corr = corrList[i]; + decimal currentValue = inputList[i]; + decimal ema = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal a = aList[i]; + decimal aEma = aEmaList[i]; var signal = GetVolatilitySignal(currentValue - ema, prevValue - prevEma, a, aEma); signalsList.Add(signal); diff --git a/Calculations/Volume.cs b/Calculations/Volume.cs index 7a83e2c..a14f775 100644 --- a/Calculations/Volume.cs +++ b/Calculations/Volume.cs @@ -17,20 +17,20 @@ public static StockData CalculateForceIndex(this StockData stockData, MovingAvgT for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal rawForce = (currentValue - prevValue) * currentVolume; - rawForceList.Add(rawForce); + rawForceList.AddRounded(rawForce); } var forceList = GetMovingAverageList(stockData, maType, length, rawForceList); for (int i = 0; i < stockData.Count; i++) { - decimal force = forceList.ElementAtOrDefault(i); - decimal prevForce1 = i >= 1 ? forceList.ElementAtOrDefault(i - 1) : 0; - decimal prevForce2 = i >= 2 ? forceList.ElementAtOrDefault(i - 2) : 0; + decimal force = forceList[i]; + decimal prevForce1 = i >= 1 ? forceList[i - 1] : 0; + decimal prevForce2 = i >= 2 ? forceList[i - 2] : 0; var signal = GetCompareSignal(force - prevForce1, prevForce1 - prevForce2); signalsList.Add(signal); @@ -64,25 +64,25 @@ public static StockData CalculateMoneyFlowIndex(this StockData stockData, InputN for (int i = 0; i < stockData.Count; i++) { - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal typicalPrice = inputList.ElementAtOrDefault(i); - decimal prevTypicalPrice = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevMfi1 = i >= 1 ? mfiList.ElementAtOrDefault(i - 1) : 0; - decimal prevMfi2 = i >= 2 ? mfiList.ElementAtOrDefault(i - 2) : 0; + decimal currentVolume = volumeList[i]; + decimal typicalPrice = inputList[i]; + decimal prevTypicalPrice = i >= 1 ? inputList[i - 1] : 0; + decimal prevMfi1 = i >= 1 ? mfiList[i - 1] : 0; + decimal prevMfi2 = i >= 2 ? mfiList[i - 2] : 0; decimal rawMoneyFlow = typicalPrice * currentVolume; decimal posMoneyFlow = typicalPrice > prevTypicalPrice ? rawMoneyFlow : 0; - posMoneyFlowList.Add(posMoneyFlow); + posMoneyFlowList.AddRounded(posMoneyFlow); decimal negMoneyFlow = typicalPrice < prevTypicalPrice ? rawMoneyFlow : 0; - negMoneyFlowList.Add(negMoneyFlow); + negMoneyFlowList.AddRounded(negMoneyFlow); decimal posMoneyFlowTotal = posMoneyFlowList.TakeLastExt(length).Sum(); decimal negMoneyFlowTotal = negMoneyFlowList.TakeLastExt(length).Sum(); decimal mfiRatio = negMoneyFlowTotal != 0 ? MinOrMax(posMoneyFlowTotal / negMoneyFlowTotal, 1, 0) : 0; decimal mfi = negMoneyFlowTotal == 0 ? 100 : posMoneyFlowTotal == 0 ? 0 : MinOrMax(100 - (100 / (1 + mfiRatio)), 100, 0); - mfiList.Add(mfi); + mfiList.AddRounded(mfi); var signal = GetRsiSignal(mfi - prevMfi1, prevMfi1 - prevMfi2, mfi, prevMfi1, 80, 20); signalsList.Add(signal); @@ -122,50 +122,50 @@ public static StockData CalculateKlingerVolumeOscillator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal mom = currentValue - prevValue; decimal prevTrend = trendList.LastOrDefault(); decimal trend = mom > 0 ? 1 : mom < 0 ? -1 : prevTrend; - trendList.Add(trend); + trendList.AddRounded(trend); decimal prevDm = dmList.LastOrDefault(); decimal dm = currentHigh - currentLow; - dmList.Add(dm); + dmList.AddRounded(dm); decimal prevCm = cmList.LastOrDefault(); decimal cm = trend == prevTrend ? prevCm + dm : prevDm + dm; - cmList.Add(cm); + cmList.AddRounded(cm); decimal temp = cm != 0 ? Math.Abs((2 * (dm / cm)) - 1) : -1; decimal vf = currentVolume * temp * trend * 100; - vfList.Add(vf); + 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++) { - decimal ema34 = ema34List.ElementAtOrDefault(i); - decimal ema55 = ema55List.ElementAtOrDefault(i); + decimal ema34 = ema34List[i]; + decimal ema55 = ema55List[i]; decimal klingerOscillator = ema34 - ema55; - kvoList.Add(klingerOscillator); + kvoList.AddRounded(klingerOscillator); } var kvoSignalList = GetMovingAverageList(stockData, maType, signalLength, kvoList); - for (int k = 0; k < stockData.Count; k++) + for (int i = 0; i < stockData.Count; i++) { - decimal klingerOscillator = kvoList.ElementAtOrDefault(k); - decimal koSignalLine = kvoSignalList.ElementAtOrDefault(k); + decimal klingerOscillator = kvoList[i]; + decimal koSignalLine = kvoSignalList[i]; decimal prevKlingerOscillatorHistogram = kvoHistoList.LastOrDefault(); decimal klingerOscillatorHistogram = klingerOscillator - koSignalLine; - kvoHistoList.Add(klingerOscillatorHistogram); + kvoHistoList.AddRounded(klingerOscillatorHistogram); var signal = GetCompareSignal(klingerOscillatorHistogram, prevKlingerOscillatorHistogram); signalsList.Add(signal); @@ -199,22 +199,22 @@ public static StockData CalculateOnBalanceVolume(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevObv = obvList.LastOrDefault(); decimal obv = currentValue > prevValue ? prevObv + currentVolume : currentValue < prevValue ? prevObv - currentVolume : prevObv; - obvList.Add(obv); + obvList.AddRounded(obv); } var obvSignalList = GetMovingAverageList(stockData, maType, length, obvList); for (int i = 0; i < stockData.Count; i++) { - decimal obv = obvList.ElementAtOrDefault(i); - decimal prevObv = i >= 1 ? obvList.ElementAtOrDefault(i - 1) : 0; - decimal obvSig = obvSignalList.ElementAtOrDefault(i); - decimal prevObvSig = i >= 1 ? obvSignalList.ElementAtOrDefault(i - 1) : 0; + decimal obv = obvList[i]; + decimal prevObv = i >= 1 ? obvList[i - 1] : 0; + decimal obvSig = obvSignalList[i]; + decimal prevObvSig = i >= 1 ? obvSignalList[i - 1] : 0; var signal = GetCompareSignal(obv - obvSig, prevObv - prevObvSig); signalsList.Add(signal); @@ -247,24 +247,24 @@ public static StockData CalculateNegativeVolumeIndex(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevVolume = i >= 1 ? volumeList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevVolume = i >= 1 ? volumeList[i - 1] : 0; decimal pctChg = CalculatePercentChange(currentClose, prevClose); decimal prevNvi = nviList.LastOrDefault(); decimal nvi = currentVolume >= prevVolume ? prevNvi : prevNvi + (prevNvi * pctChg); - nviList.Add(nvi); + nviList.AddRounded(nvi); } var nviSignalList = GetMovingAverageList(stockData, maType, length, nviList); for (int i = 0; i < stockData.Count; i++) { - decimal nvi = nviList.ElementAtOrDefault(i); - decimal prevNvi = i >= 1 ? nviList.ElementAtOrDefault(i - 1) : 0; - decimal nviSignal = nviSignalList.ElementAtOrDefault(i); - decimal prevNviSignal = i >= 1 ? nviSignalList.ElementAtOrDefault(i - 1) : 0; + decimal nvi = nviList[i]; + decimal prevNvi = i >= 1 ? nviList[i - 1] : 0; + decimal nviSignal = nviSignalList[i]; + decimal prevNviSignal = i >= 1 ? nviSignalList[i - 1] : 0; var signal = GetCompareSignal(nvi - nviSignal, prevNvi - prevNviSignal); signalsList.Add(signal); @@ -297,24 +297,24 @@ public static StockData CalculatePositiveVolumeIndex(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevVolume = i >= 1 ? volumeList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevVolume = i >= 1 ? volumeList[i - 1] : 0; decimal pctChg = CalculatePercentChange(currentClose, prevClose); decimal prevPvi = pviList.LastOrDefault(); decimal pvi = currentVolume <= prevVolume ? prevPvi : prevPvi + (prevPvi * pctChg); - pviList.Add(pvi); + pviList.AddRounded(pvi); } var pviSignalList = GetMovingAverageList(stockData, maType, length, pviList); for (int i = 0; i < stockData.Count; i++) { - decimal pvi = pviList.ElementAtOrDefault(i); - decimal prevPvi = i >= 1 ? pviList.ElementAtOrDefault(i - 1) : 0; - decimal pviSignal = pviSignalList.ElementAtOrDefault(i); - decimal prevPviSignal = i >= 1 ? pviSignalList.ElementAtOrDefault(i - 1) : 0; + decimal pvi = pviList[i]; + decimal prevPvi = i >= 1 ? pviList[i - 1] : 0; + decimal pviSignal = pviSignalList[i]; + decimal prevPviSignal = i >= 1 ? pviSignalList[i - 1] : 0; var signal = GetCompareSignal(pvi - pviSignal, prevPvi - prevPviSignal); signalsList.Add(signal); @@ -348,19 +348,19 @@ public static StockData CalculateChaikinMoneyFlow(this StockData stockData, int for (int i = 0; i < stockData.Count; i++) { - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal currentLow = lowList[i]; + decimal currentHigh = highList[i]; + decimal currentClose = inputList[i]; decimal moneyFlowMultiplier = currentHigh - currentLow != 0 ? (currentClose - currentLow - (currentHigh - currentClose)) / (currentHigh - currentLow) : 0; - decimal prevCmf1 = i >= 1 ? chaikinMoneyFlowList.ElementAtOrDefault(i - 1) : 0; - decimal prevCmf2 = i >= 2 ? chaikinMoneyFlowList.ElementAtOrDefault(i - 2) : 0; + decimal prevCmf1 = i >= 1 ? chaikinMoneyFlowList[i - 1] : 0; + decimal prevCmf2 = i >= 2 ? chaikinMoneyFlowList[i - 2] : 0; - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentVolume = volumeList[i]; tempVolumeList.AddRounded(currentVolume); decimal moneyFlowVolume = moneyFlowMultiplier * currentVolume; - moneyFlowVolumeList.Add(moneyFlowVolume); + moneyFlowVolumeList.AddRounded(moneyFlowVolume); decimal volumeSum = tempVolumeList.TakeLastExt(length).Sum(); decimal mfVolumeSum = moneyFlowVolumeList.TakeLastExt(length).Sum(); @@ -399,26 +399,26 @@ public static StockData CalculateAccumulationDistributionLine(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentLow = lowList[i]; + decimal currentHigh = highList[i]; + decimal currentClose = inputList[i]; + decimal currentVolume = volumeList[i]; decimal moneyFlowMultiplier = currentHigh - currentLow != 0 ? (currentClose - currentLow - (currentHigh - currentClose)) / (currentHigh - currentLow) : 0; decimal moneyFlowVolume = moneyFlowMultiplier * currentVolume; decimal prevAdl = adlList.LastOrDefault(); decimal adl = prevAdl + moneyFlowVolume; - adlList.Add(adl); + adlList.AddRounded(adl); } var adlSignalList = GetMovingAverageList(stockData, maType, length, adlList); for (int i = 0; i < stockData.Count; i++) { - var adl = adlList.ElementAtOrDefault(i); - var prevAdl = i >= 1 ? adlList.ElementAtOrDefault(i - 1) : 0; - var adlSignal = adlSignalList.ElementAtOrDefault(i); - var prevAdlSignal = i >= 1 ? adlSignalList.ElementAtOrDefault(i - 1) : 0; + var adl = adlList[i]; + var prevAdl = i >= 1 ? adlList[i - 1] : 0; + var adlSignal = adlSignalList[i]; + var prevAdlSignal = i >= 1 ? adlSignalList[i - 1] : 0; var signal = GetCompareSignal(adl - adlSignal, prevAdl - prevAdlSignal); signalsList.Add(signal); @@ -457,21 +457,21 @@ public static StockData CalculateAverageMoneyFlowOscillator(this StockData stock for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal chg = currentValue - prevValue; - chgList.Add(chg); + chgList.AddRounded(chg); } var avgcList = GetMovingAverageList(stockData, maType, length, chgList); for (int i = 0; i < stockData.Count; i++) { - decimal avgv = avgvList.ElementAtOrDefault(i); - decimal avgc = avgcList.ElementAtOrDefault(i); + decimal avgv = avgvList[i]; + decimal avgc = avgcList[i]; decimal r = Math.Abs(avgv * avgc) > 0 ? Log(Math.Abs(avgv * avgc)) * Math.Sign(avgc) : 0; - rList.Add(r); + rList.AddRounded(r); var list = rList.TakeLastExt(length).ToList(); decimal rh = list.Max(); @@ -479,14 +479,14 @@ public static StockData CalculateAverageMoneyFlowOscillator(this StockData stock decimal rs = rh != rl ? (r - rl) / (rh - rl) * 100 : 0; decimal k = (rs * 2) - 100; - kList.Add(k); + kList.AddRounded(k); } var ksList = GetMovingAverageList(stockData, maType, smoothLength, kList); for (int i = 0; i < stockData.Count; i++) { - decimal ks = ksList.ElementAtOrDefault(i); - decimal prevKs = i >= 1 ? ksList.ElementAtOrDefault(i - 1) : 0; + decimal ks = ksList[i]; + decimal prevKs = i >= 1 ? ksList[i - 1] : 0; var signal = GetCompareSignal(ks, prevKs); signalsList.Add(signal); @@ -540,31 +540,31 @@ public static StockData CalculateBetterVolumeIndicator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentVolume = volumeList[i]; + decimal currentOpen = openList[i]; + decimal currentClose = inputList[i]; decimal highLowRange = highest - lowest; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevOpen = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevOpen = i >= 1 ? openList[i - 1] : 0; decimal range = CalculateTrueRange(currentHigh, currentLow, prevClose); decimal prevV1 = v1List.LastOrDefault(); decimal v1 = currentClose > currentOpen ? range / ((2 * range) + currentOpen - currentClose) * currentVolume : currentClose < currentOpen ? (range + currentClose - currentOpen) / ((2 * range) + currentClose - currentOpen) * currentVolume : 0.5m * currentVolume; - v1List.Add(v1); + v1List.AddRounded(v1); decimal prevV2 = v2List.LastOrDefault(); decimal v2 = currentVolume - v1; - v2List.Add(v2); + v2List.AddRounded(v2); decimal prevV3 = v3List.LastOrDefault(); decimal v3 = v1 + v2; - v3List.Add(v3); + v3List.AddRounded(v3); decimal v4 = v1 * range; v4List.AddRounded(v4); @@ -681,27 +681,27 @@ public static StockData CalculateBuffAverage(this StockData stockData, int fastL for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - tempVolumeList.Add(currentVolume); + decimal currentVolume = volumeList[i]; + tempVolumeList.AddRounded(currentVolume); decimal priceVol = currentValue * currentVolume; - priceVolList.Add(priceVol); + priceVolList.AddRounded(priceVol); decimal fastBuffNum = priceVolList.TakeLastExt(fastLength).Sum(); decimal fastBuffDenom = tempVolumeList.TakeLastExt(fastLength).Sum(); decimal prevFastBuff = fastBuffList.LastOrDefault(); decimal fastBuff = fastBuffDenom != 0 ? fastBuffNum / fastBuffDenom : 0; - fastBuffList.Add(fastBuff); + fastBuffList.AddRounded(fastBuff); decimal slowBuffNum = priceVolList.TakeLastExt(slowLength).Sum(); decimal slowBuffDenom = tempVolumeList.TakeLastExt(slowLength).Sum(); decimal prevSlowBuff = slowBuffList.LastOrDefault(); decimal slowBuff = slowBuffDenom != 0 ? slowBuffNum / slowBuffDenom : 0; - slowBuffList.Add(slowBuff); + slowBuffList.AddRounded(slowBuff); var signal = GetCompareSignal(fastBuff - slowBuff, prevFastBuff - prevSlowBuff); signalsList.Add(signal); @@ -735,22 +735,22 @@ public static StockData CalculateUpsideDownsideVolume(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal upVol = currentValue > prevValue ? currentVolume : 0; - upVolList.Add(upVol); + upVolList.AddRounded(upVol); decimal downVol = currentValue < prevValue ? currentVolume * -1 : 0; - downVolList.Add(downVol); + downVolList.AddRounded(downVol); decimal upVolSum = upVolList.TakeLastExt(length).Sum(); decimal downVolSum = downVolList.TakeLastExt(length).Sum(); decimal prevUpDownVol = upDownVolumeList.LastOrDefault(); decimal upDownVol = downVolSum != 0 ? upVolSum / downVolSum : 0; - upDownVolumeList.Add(upDownVol); + upDownVolumeList.AddRounded(upDownVol); var signal = GetCompareSignal(upDownVol, prevUpDownVol); signalsList.Add(signal); @@ -786,29 +786,29 @@ public static StockData CalculateEaseOfMovement(this StockData stockData, Moving for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentVolume = volumeList[i]; decimal prevHalfRange = halfRangeList.LastOrDefault(); decimal halfRange = (currentHigh - currentLow) * 0.5m; decimal boxRatio = currentHigh - currentLow != 0 ? currentVolume / (currentHigh - currentLow) : 0; decimal prevMidpointMove = midpointMoveList.LastOrDefault(); decimal midpointMove = halfRange - prevHalfRange; - midpointMoveList.Add(midpointMove); + midpointMoveList.AddRounded(midpointMove); decimal emv = boxRatio != 0 ? divisor * ((midpointMove - prevMidpointMove) / boxRatio) : 0; - emvList.Add(emv); + 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++) { - decimal emv = emvList.ElementAtOrDefault(i); - decimal emvSignal = emvSignalList.ElementAtOrDefault(i); - decimal prevEmv = i >= 1 ? emvList.ElementAtOrDefault(i - 1) : 0; - decimal prevEmvSignal = i >= 1 ? emvSignalList.ElementAtOrDefault(i - 1) : 0; + decimal emv = emvList[i]; + decimal emvSignal = emvSignalList[i]; + decimal prevEmv = i >= 1 ? emvList[i - 1] : 0; + decimal prevEmvSignal = i >= 1 ? emvSignalList[i - 1] : 0; var signal = GetCompareSignal(emv - emvSignal, prevEmv - prevEmvSignal); signalsList.Add(signal); @@ -844,10 +844,10 @@ public static StockData CalculateOnBalanceVolumeModified(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal obvm = obvmList.ElementAtOrDefault(i); - decimal sig = sigList.ElementAtOrDefault(i); - decimal prevObvm = i >= 1 ? obvmList.ElementAtOrDefault(i - 1) : 0; - decimal prevSig = i >= 1 ? sigList.ElementAtOrDefault(i - 1) : 0; + decimal obvm = obvmList[i]; + decimal sig = sigList[i]; + decimal prevObvm = i >= 1 ? obvmList[i - 1] : 0; + decimal prevSig = i >= 1 ? sigList[i - 1] : 0; var signal = GetCompareSignal(obvm - sig, prevObvm - prevSig); signalsList.Add(signal); @@ -882,22 +882,22 @@ public static StockData CalculateOnBalanceVolumeReflex(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= length ? inputList.ElementAtOrDefault(i - length) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= length ? inputList[i - length] : 0; decimal prevOvr = ovrList.LastOrDefault(); decimal ovr = currentValue > prevValue ? prevOvr + currentVolume : currentValue < prevValue ? prevOvr - currentVolume : prevOvr; - ovrList.Add(ovr); + ovrList.AddRounded(ovr); } var ovrSmaList = GetMovingAverageList(stockData, maType, signalLength, ovrList); for (int i = 0; i < stockData.Count; i++) { - decimal ovr = ovrList.ElementAtOrDefault(i); - decimal ovrEma = ovrSmaList.ElementAtOrDefault(i); - decimal prevOvr = i >= 1 ? ovrList.ElementAtOrDefault(i - 1) : 0; - decimal prevOvrEma = i >= 1 ? ovrSmaList.ElementAtOrDefault(i - 1) : 0; + decimal ovr = ovrList[i]; + decimal ovrEma = ovrSmaList[i]; + decimal prevOvr = i >= 1 ? ovrList[i - 1] : 0; + decimal prevOvrEma = i >= 1 ? ovrSmaList[i - 1] : 0; var signal = GetCompareSignal(ovr - ovrEma, prevOvr - prevOvrEma); signalsList.Add(signal); @@ -942,34 +942,34 @@ public static StockData CalculateOnBalanceVolumeDisparityIndicator(this StockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal obvSma = obvSmaList.ElementAtOrDefault(i); - decimal obvStdDev = obvStdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal stdDev = stdDevList[i]; + decimal obvSma = obvSmaList[i]; + decimal obvStdDev = obvStdDevList[i]; decimal aTop = currentValue - (sma - (2 * stdDev)); decimal aBot = currentValue + (2 * stdDev) - (sma - (2 * stdDev)); - decimal obv = obvList.ElementAtOrDefault(i); + decimal obv = obvList[i]; decimal a = aBot != 0 ? aTop / aBot : 0; decimal bTop = obv - (obvSma - (2 * obvStdDev)); decimal bBot = obvSma + (2 * obvStdDev) - (obvSma - (2 * obvStdDev)); decimal b = bBot != 0 ? bTop / bBot : 0; decimal obvdi = 1 + b != 0 ? (1 + a) / (1 + b) : 0; - obvdiList.Add(obvdi); + obvdiList.AddRounded(obvdi); } var obvdiEmaList = GetMovingAverageList(stockData, maType, signalLength, obvdiList); for (int i = 0; i < stockData.Count; i++) { - decimal obvdi = obvdiList.ElementAtOrDefault(i); - decimal obvdiEma = obvdiEmaList.ElementAtOrDefault(i); - decimal prevObvdi = i >= 1 ? obvdiList.ElementAtOrDefault(i - 1) : 0; + decimal obvdi = obvdiList[i]; + decimal obvdiEma = obvdiEmaList[i]; + decimal prevObvdi = i >= 1 ? obvdiList[i - 1] : 0; decimal prevBsc = bscList.LastOrDefault(); decimal bsc = (prevObvdi < bottom && obvdi > bottom) || obvdi > obvdiEma ? 1 : (prevObvdi > top && obvdi < top) || obvdi < bottom ? -1 : prevBsc; - bscList.Add(bsc); + bscList.AddRounded(bsc); var signal = GetCompareSignal(bsc, prevBsc); signalsList.Add(signal); @@ -1014,29 +1014,29 @@ public static StockData CalculateNegativeVolumeDisparityIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal sma = smaList.ElementAtOrDefault(i); - decimal stdDev = stdDevList.ElementAtOrDefault(i); - decimal nviSma = nviSmaList.ElementAtOrDefault(i); - decimal nviStdDev = nviStdDevList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal sma = smaList[i]; + decimal stdDev = stdDevList[i]; + decimal nviSma = nviSmaList[i]; + decimal nviStdDev = nviStdDevList[i]; decimal aTop = currentValue - (sma - (2 * stdDev)); decimal aBot = (currentValue + (2 * stdDev)) - (sma - (2 * stdDev)); - decimal nvi = nviList.ElementAtOrDefault(i); + decimal nvi = nviList[i]; decimal a = aBot != 0 ? aTop / aBot : 0; decimal bTop = nvi - (nviSma - (2 * nviStdDev)); decimal bBot = (nviSma + (2 * nviStdDev)) - (nviSma - (2 * nviStdDev)); decimal b = bBot != 0 ? bTop / bBot : 0; decimal nvdi = 1 + b != 0 ? (1 + a) / (1 + b) : 0; - nvdiList.Add(nvdi); + nvdiList.AddRounded(nvdi); } var nvdiEmaList = GetMovingAverageList(stockData, maType, signalLength, nvdiList); for (int i = 0; i < stockData.Count; i++) { - decimal nvdi = nvdiList.ElementAtOrDefault(i); - decimal nvdiEma = nvdiEmaList.ElementAtOrDefault(i); - decimal prevNvdi = i >= 1 ? nvdiList.ElementAtOrDefault(i - 1) : 0; + decimal nvdi = nvdiList[i]; + decimal nvdiEma = nvdiEmaList[i]; + decimal prevNvdi = i >= 1 ? nvdiList[i - 1] : 0; decimal prevBsc = bscList.LastOrDefault(); decimal bsc = (prevNvdi < bottom && nvdi > bottom) || nvdi > nvdiEma ? 1 : (prevNvdi > top && nvdi < top) || @@ -1079,28 +1079,28 @@ public static StockData CalculateHawkeyeVolumeIndicator(this StockData stockData for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentValue = closeList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentValue = closeList[i]; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - tempVolumeList.Add(currentVolume); + decimal currentVolume = volumeList[i]; + tempVolumeList.AddRounded(currentVolume); decimal range = currentHigh - currentLow; - tempRangeList.Add(range); + tempRangeList.AddRounded(range); decimal volumeSma = tempVolumeList.TakeLastExt(length).Average(); decimal rangeSma = tempRangeList.TakeLastExt(length).Average(); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevMidpoint = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevVolume = i >= 1 ? volumeList.ElementAtOrDefault(i - 1) : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevMidpoint = i >= 1 ? inputList[i - 1] : 0; + decimal prevVolume = i >= 1 ? volumeList[i - 1] : 0; decimal u1 = divisor != 0 ? prevMidpoint + ((prevHigh - prevLow) / divisor) : prevMidpoint; - u1List.Add(u1); + u1List.AddRounded(u1); decimal d1 = divisor != 0 ? prevMidpoint - ((prevHigh - prevLow) / divisor) : prevMidpoint; - d1List.Add(d1); + d1List.AddRounded(d1); bool rEnabled1 = range > rangeSma && currentValue < d1 && currentVolume > volumeSma; bool rEnabled2 = currentValue < prevMidpoint; @@ -1149,13 +1149,13 @@ public static StockData CalculateHerrickPayoffIndex(this StockData stockData, In for (int i = 0; i < stockData.Count; i++) { - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal currentOpen = openList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? closeList.ElementAtOrDefault(i - 1) : 0; - decimal prevOpen = i >= 1 ? openList.ElementAtOrDefault(i - 1) : 0; - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentClose = closeList[i]; + decimal currentOpen = openList[i]; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevClose = i >= 1 ? closeList[i - 1] : 0; + decimal prevOpen = i >= 1 ? openList[i - 1] : 0; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevK = kList.LastOrDefault(); decimal absDiff = Math.Abs(currentClose - prevClose); decimal g = Math.Min(currentOpen, prevOpen); @@ -1163,11 +1163,11 @@ public static StockData CalculateHerrickPayoffIndex(this StockData stockData, In decimal temp = g != 0 ? currentValue < prevValue ? 1 - (absDiff / 2 / g) : 1 + (absDiff / 2 / g) : 1; k *= temp; - kList.Add(k); + kList.AddRounded(k); decimal prevHpic = hpicList.LastOrDefault(); decimal hpic = prevK + (k - prevK); - hpicList.Add(hpic); + hpicList.AddRounded(hpic); var signal = GetCompareSignal(hpic, prevHpic); signalsList.Add(signal); @@ -1207,27 +1207,27 @@ public static StockData CalculateFiniteVolumeElements(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal medianPrice = medianPriceList.ElementAtOrDefault(i); - decimal typicalPrice = typicalPriceList.ElementAtOrDefault(i); - decimal prevTypicalPrice = i >= 1 ? typicalPriceList.ElementAtOrDefault(i - 1) : 0; - decimal volumeSma = volumeSmaList.ElementAtOrDefault(i); - decimal volume = volumeList.ElementAtOrDefault(i); - decimal close = inputList.ElementAtOrDefault(i); + decimal medianPrice = medianPriceList[i]; + decimal typicalPrice = typicalPriceList[i]; + decimal prevTypicalPrice = i >= 1 ? typicalPriceList[i - 1] : 0; + decimal volumeSma = volumeSmaList[i]; + decimal volume = volumeList[i]; + decimal close = inputList[i]; decimal nmf = close - medianPrice + typicalPrice - prevTypicalPrice; decimal nvlm = nmf > factor * close / 100 ? volume : nmf < -factor * close / 100 ? -volume : 0; decimal prevFve = fveList.LastOrDefault(); - decimal prevFve2 = i >= 2 ? fveList.ElementAtOrDefault(i - 2) : 0; + decimal prevFve2 = i >= 2 ? fveList[i - 2] : 0; decimal fve = volumeSma != 0 && length != 0 ? prevFve + (nvlm / volumeSma / length * 100) : prevFve; - fveList.Add(fve); + fveList.AddRounded(fve); decimal prevBullSlope = bullList.LastOrDefault(); decimal bullSlope = fve - Math.Max(prevFve, prevFve2); - bullList.Add(bullSlope); + bullList.AddRounded(bullSlope); decimal prevBearSlope = bearList.LastOrDefault(); decimal bearSlope = fve - Math.Min(prevFve, prevFve2); - bearList.Add(bearSlope); + bearList.AddRounded(bearSlope); var signal = GetBullishBearishSignal(bullSlope, prevBullSlope, bearSlope, prevBearSlope); signalsList.Add(signal); @@ -1265,18 +1265,18 @@ public static StockData CalculateRelativeVolumeIndicator(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal av = smaVolumeList.ElementAtOrDefault(i); - decimal sd = stdDevVolumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentVolume = volumeList[i]; + decimal currentValue = inputList[i]; + decimal av = smaVolumeList[i]; + decimal sd = stdDevVolumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal relVol = sd != 0 ? (currentVolume - av) / sd : 0; - relVolList.Add(relVol); + relVolList.AddRounded(relVol); decimal prevDpl = dplList.LastOrDefault(); decimal dpl = relVol >= 2 ? prevValue : i >= 1 ? prevDpl : currentValue; - dplList.Add(dpl); + dplList.AddRounded(dpl); var signal = GetCompareSignal(currentValue - dpl, prevValue - prevDpl); signalsList.Add(signal); @@ -1317,14 +1317,14 @@ public static StockData CalculateFreedomOfMovement(this StockData stockData, Mov for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; - decimal currentRelVol = relVolList.ElementAtOrDefault(i); - tempList.Add(currentRelVol); + decimal currentRelVol = relVolList[i]; + tempList.AddRounded(currentRelVol); decimal aMove = prevValue != 0 ? Math.Abs((currentValue - prevValue) / prevValue) : 0; - aMoveList.Add(aMove); + aMoveList.AddRounded(aMove); var list = aMoveList.TakeLastExt(length).ToList(); decimal aMoveMax = list.Max(); @@ -1336,28 +1336,28 @@ public static StockData CalculateFreedomOfMovement(this StockData stockData, Mov decimal theVol = relVolMax - relVolMin != 0 ? (1 + ((currentRelVol - relVolMin) * (10 - 1))) / (relVolMax - relVolMin) : 0; decimal vBym = theMove != 0 ? theVol / theMove : 0; - vBymList.Add(vBym); + vBymList.AddRounded(vBym); decimal avf = vBymList.TakeLastExt(length).Average(); - avfList.Add(avf); + avfList.AddRounded(avf); } stockData.CustomValuesList = vBymList; var sdfList = CalculateStandardDeviationVolatility(stockData, maType, length).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal vBym = vBymList.ElementAtOrDefault(i); - decimal avf = avfList.ElementAtOrDefault(i); - decimal sdf = sdfList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal vBym = vBymList[i]; + decimal avf = avfList[i]; + decimal sdf = sdfList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal theFom = sdf != 0 ? (vBym - avf) / sdf : 0; - theFomList.Add(theFom); + theFomList.AddRounded(theFom); decimal prevDpl = dplList.LastOrDefault(); decimal dpl = theFom >= 2 ? prevValue : i >= 1 ? prevDpl : currentValue; - dplList.Add(dpl); + dplList.AddRounded(dpl); var signal = GetCompareSignal(currentValue - dpl, prevValue - prevDpl); signalsList.Add(signal); @@ -1400,27 +1400,27 @@ public static StockData CalculateVolumePriceConfirmationIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal vwmaLong = vwmaLongList.ElementAtOrDefault(i); - decimal vwmaShort = vwmaShortList.ElementAtOrDefault(i); - decimal volumeSmaLong = volumeSmaLongList.ElementAtOrDefault(i); - decimal volumeSmaShort = volumeSmaShortList.ElementAtOrDefault(i); - decimal smaLong = smaLongList.ElementAtOrDefault(i); - decimal smaShort = smaShortList.ElementAtOrDefault(i); + decimal vwmaLong = vwmaLongList[i]; + decimal vwmaShort = vwmaShortList[i]; + decimal volumeSmaLong = volumeSmaLongList[i]; + decimal volumeSmaShort = volumeSmaShortList[i]; + decimal smaLong = smaLongList[i]; + decimal smaShort = smaShortList[i]; decimal vpc = vwmaLong - smaLong; decimal vpr = smaShort != 0 ? vwmaShort / smaShort : 0; decimal vm = volumeSmaLong != 0 ? volumeSmaShort / volumeSmaLong : 0; decimal vpci = vpc * vpr * vm; - vpciList.Add(vpci); + vpciList.AddRounded(vpci); } var vpciSmaList = GetMovingAverageList(stockData, maType, length, vpciList); for (int i = 0; i < stockData.Count; i++) { - decimal vpci = vpciList.ElementAtOrDefault(i); - decimal vpciSma = vpciSmaList.ElementAtOrDefault(i); - decimal prevVpci = i >= 1 ? vpciList.ElementAtOrDefault(i - 1) : 0; - decimal prevVpciSma = i >= 1 ? vpciSmaList.ElementAtOrDefault(i - 1) : 0; + decimal vpci = vpciList[i]; + decimal vpciSma = vpciSmaList[i]; + decimal prevVpci = i >= 1 ? vpciList[i - 1] : 0; + decimal prevVpciSma = i >= 1 ? vpciSmaList[i - 1] : 0; Signal signal = GetCompareSignal(vpci - vpciSma, prevVpci - prevVpciSma); signalsList.Add(signal); @@ -1462,33 +1462,33 @@ public static StockData CalculateVolumePositiveNegativeIndicator(this StockData for (int i = 0; i < stockData.Count; i++) { - decimal mav = mavList.ElementAtOrDefault(i); + decimal mav = mavList[i]; mav = mav > 0 ? mav : 1; - decimal tp = inputList.ElementAtOrDefault(i); - decimal prevTp = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal atr = atrList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal tp = inputList[i]; + decimal prevTp = i >= 1 ? inputList[i - 1] : 0; + decimal atr = atrList[i]; + decimal currentVolume = volumeList[i]; decimal mf = tp - prevTp; decimal mc = 0.1m * atr; decimal vmp = mf > mc ? currentVolume : 0; - vmpList.Add(vmp); + vmpList.AddRounded(vmp); decimal vmn = mf < -mc ? currentVolume : 0; - vmnList.Add(vmn); + vmnList.AddRounded(vmn); decimal vn = vmnList.TakeLastExt(length).Sum(); decimal vp = vmpList.TakeLastExt(length).Sum(); decimal vpn = mav != 0 && length != 0 ? (vp - vn) / mav / length * 100 : 0; - vpnList.Add(vpn); + vpnList.AddRounded(vpn); } var vpnEmaList = GetMovingAverageList(stockData, maType, smoothLength, vpnList); for (int i = 0; i < stockData.Count; i++) { - decimal vpnEma = vpnEmaList.ElementAtOrDefault(i); - decimal prevVpnEma = i >= 1 ? vpnEmaList.ElementAtOrDefault(i - 1) : 0; + decimal vpnEma = vpnEmaList[i]; + decimal prevVpnEma = i >= 1 ? vpnEmaList[i - 1] : 0; var signal = GetCompareSignal(vpnEma, prevVpnEma); signalsList.Add(signal); @@ -1521,18 +1521,18 @@ public static StockData CalculateVolumeAccumulationOscillator(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); + decimal currentValue = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentVolume = volumeList[i]; decimal medianValue = (currentHigh + currentLow) / 2; decimal vao = currentValue != medianValue ? currentVolume * (currentValue - medianValue) : currentVolume; - vaoList.Add(vao); + vaoList.AddRounded(vao); decimal prevVaoSum = vaoSumList.LastOrDefault(); decimal vaoSum = vaoList.TakeLastExt(length).Average(); - vaoSumList.Add(vaoSum); + vaoSumList.AddRounded(vaoSum); var signal = GetCompareSignal(vaoSum, prevVaoSum); signalsList.Add(signal); @@ -1565,23 +1565,23 @@ public static StockData CalculateVolumeAccumulationPercent(this StockData stockD for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentClose = inputList[i]; - decimal currentVolume = volumeList.ElementAtOrDefault(i); - tempVolumeList.Add(currentVolume); + decimal currentVolume = volumeList[i]; + tempVolumeList.AddRounded(currentVolume); decimal xt = currentHigh - currentLow != 0 ? ((2 * currentClose) - currentHigh - currentLow) / (currentHigh - currentLow) : 0; decimal tva = currentVolume * xt; - tvaList.Add(tva); + tvaList.AddRounded(tva); decimal volumeSum = tempVolumeList.TakeLastExt(length).Sum(); decimal tvaSum = tvaList.TakeLastExt(length).Sum(); decimal prevVapc = vapcList.LastOrDefault(); decimal vapc = volumeSum != 0 ? MinOrMax(100 * tvaSum / volumeSum, 100, 0) : 0; - vapcList.Add(vapc); + vapcList.AddRounded(vapc); var signal = GetCompareSignal(vapc, prevVapc); signalsList.Add(signal); @@ -1627,26 +1627,26 @@ public static StockData CalculateVolumeFlowIndicator(this StockData stockData, M for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal inter = currentValue > 0 && prevValue > 0 ? Log(currentValue) - Log(prevValue) : 0; - interList.Add(inter); + interList.AddRounded(inter); } stockData.CustomValuesList = interList; var vinterList = CalculateStandardDeviationVolatility(stockData, maType, length2).CustomValuesList; for (int i = 0; i < stockData.Count; i++) { - decimal vinter = vinterList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal currentClose = closeList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal vinter = vinterList[i]; + decimal currentVolume = volumeList[i]; + decimal currentClose = closeList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevVave = tempList.LastOrDefault(); - decimal vave = smaVolumeList.ElementAtOrDefault(i); - tempList.Add(vave); + decimal vave = smaVolumeList[i]; + tempList.AddRounded(vave); decimal cutoff = currentClose * vinter * coef; decimal vmax = prevVave * vcoef; @@ -1654,23 +1654,23 @@ public static StockData CalculateVolumeFlowIndicator(this StockData stockData, M decimal mf = currentValue - prevValue; decimal vcp = mf > cutoff ? vc : mf < cutoff * -1 ? vc * -1 : mf > 0 ? vc : mf < 0 ? vc * -1 : 0; - vcpList.Add(vcp); + vcpList.AddRounded(vcp); decimal vcpSum = vcpList.TakeLastExt(length1).Sum(); decimal vcpVaveSum = vave != 0 ? vcpSum / vave : 0; - vcpVaveSumList.Add(vcpVaveSum); + 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++) { - decimal vfi = vfiList.ElementAtOrDefault(i); - decimal vfima = vfiEmaList.ElementAtOrDefault(i); + decimal vfi = vfiList[i]; + decimal vfima = vfiEmaList[i]; decimal prevD = dList.LastOrDefault(); decimal d = vfi - vfima; - dList.Add(d); + dList.AddRounded(d); var signal = GetCompareSignal(d, prevD); signalsList.Add(signal); @@ -1709,22 +1709,22 @@ public static StockData CalculatePriceVolumeOscillator(this StockData stockData, for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= length1 ? inputList.ElementAtOrDefault(i - length1) : 0; - decimal prevVolume = i >= length2 ? volumeList.ElementAtOrDefault(i - length2) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= length1 ? inputList[i - length1] : 0; + decimal prevVolume = i >= length2 ? volumeList[i - length2] : 0; decimal a = currentValue - prevValue; - aList.Add(a); + aList.AddRounded(a); decimal b = currentVolume - prevVolume; - bList.Add(b); + bList.AddRounded(b); decimal absA = Math.Abs(a); - absAList.Add(absA); + absAList.AddRounded(absA); decimal absB = Math.Abs(b); - absBList.Add(absB); + absBList.AddRounded(absB); decimal aSum = aList.TakeLastExt(length1).Sum(); decimal bSum = bList.TakeLastExt(length2).Sum(); @@ -1732,10 +1732,10 @@ public static StockData CalculatePriceVolumeOscillator(this StockData stockData, decimal absBSum = absBList.TakeLastExt(length2).Sum(); decimal oscA = absASum != 0 ? aSum / absASum : 0; - oscAList.Add(oscA); + oscAList.AddRounded(oscA); decimal oscB = absBSum != 0 ? bSum / absBSum : 0; - oscBList.Add(oscB); + oscBList.AddRounded(oscB); var signal = GetConditionSignal(oscA > 0 && oscB > 0, oscA < 0 && oscB > 0); signalsList.Add(signal); @@ -1770,24 +1770,24 @@ public static StockData CalculatePriceVolumeRank(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevVolume = i >= 1 ? volumeList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevVolume = i >= 1 ? volumeList[i - 1] : 0; decimal pvr = currentValue > prevValue && currentVolume > prevVolume ? 1 : currentValue > prevValue && currentVolume <= prevVolume ? 2 : currentValue <= prevValue && currentVolume <= prevVolume ? 3 : 4; - pvrList.Add(pvr); + pvrList.AddRounded(pvr); } var pvrFastSmaList = GetMovingAverageList(stockData, maType, fastLength, pvrList); var pvrSlowSmaList = GetMovingAverageList(stockData, maType, slowLength, pvrList); for (int i = 0; i < stockData.Count; i++) { - decimal fastSma = pvrFastSmaList.ElementAtOrDefault(i); - decimal slowSma = pvrSlowSmaList.ElementAtOrDefault(i); - decimal prevFastSma = i >= 1 ? pvrFastSmaList.ElementAtOrDefault(i - 1) : 0; - decimal prevSlowSma = i >= 1 ? pvrSlowSmaList.ElementAtOrDefault(i - 1) : 0; + decimal fastSma = pvrFastSmaList[i]; + decimal slowSma = pvrSlowSmaList[i]; + decimal prevFastSma = i >= 1 ? pvrFastSmaList[i - 1] : 0; + decimal prevSlowSma = i >= 1 ? pvrSlowSmaList[i - 1] : 0; var signal = GetCompareSignal(fastSma - slowSma, prevFastSma - prevSlowSma); signalsList.Add(signal); @@ -1825,28 +1825,28 @@ public static StockData CalculateTwiggsMoneyFlow(this StockData stockData, Movin for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevPrice = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentPrice = inputList[i]; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentVolume = volumeList[i]; + decimal prevPrice = i >= 1 ? inputList[i - 1] : 0; decimal trh = Math.Max(currentHigh, prevPrice); decimal trl = Math.Min(currentLow, prevPrice); decimal ad = trh - trl != 0 && currentVolume != 0 ? (currentPrice - trl - (trh - currentPrice)) / (trh - trl) * currentVolume : 0; - adList.Add(ad); + adList.AddRounded(ad); } var smoothAdList = GetMovingAverageList(stockData, maType, length, adList); for (int i = 0; i < stockData.Count; i++) { - decimal currentEmaVolume = volumeEmaList.ElementAtOrDefault(i); - decimal smoothAd = smoothAdList.ElementAtOrDefault(i); - decimal prevTmf1 = i >= 1 ? tmfList.ElementAtOrDefault(i - 1) : 0; - decimal prevTmf2 = i >= 2 ? tmfList.ElementAtOrDefault(i - 2) : 0; + decimal currentEmaVolume = volumeEmaList[i]; + decimal smoothAd = smoothAdList[i]; + decimal prevTmf1 = i >= 1 ? tmfList[i - 1] : 0; + decimal prevTmf2 = i >= 2 ? tmfList[i - 2] : 0; decimal tmf = currentEmaVolume != 0 ? MinOrMax(smoothAd / currentEmaVolume, 1, -1) : 0; - tmfList.Add(tmf); + tmfList.AddRounded(tmf); var signal = GetRsiSignal(tmf - prevTmf1, prevTmf1 - prevTmf2, tmf, prevTmf1, 0.2m, -0.2m); signalsList.Add(signal); @@ -1880,24 +1880,24 @@ public static StockData CalculateTradeVolumeIndex(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentPrice = inputList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevPrice = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentPrice = inputList[i]; + decimal currentVolume = volumeList[i]; + decimal prevPrice = i >= 1 ? inputList[i - 1] : 0; decimal priceChange = currentPrice - prevPrice; decimal prevTvi = tviList.LastOrDefault(); decimal tvi = priceChange > minTickValue ? prevTvi + currentVolume : priceChange < -minTickValue ? prevTvi - currentVolume : prevTvi; - tviList.Add(tvi); + tviList.AddRounded(tvi); } var tviSignalList = GetMovingAverageList(stockData, maType, length, tviList); for (int i = 0; i < stockData.Count; i++) { - decimal tvi = tviList.ElementAtOrDefault(i); - decimal tviSignal = tviSignalList.ElementAtOrDefault(i); - decimal prevTvi = i >= 1 ? tviList.ElementAtOrDefault(i - 1) : 0; - decimal prevTviSignal = i >= 1 ? tviSignalList.ElementAtOrDefault(i - 1) : 0; + decimal tvi = tviList[i]; + decimal tviSignal = tviSignalList[i]; + decimal prevTvi = i >= 1 ? tviList[i - 1] : 0; + decimal prevTviSignal = i >= 1 ? tviSignalList[i - 1] : 0; var signal = GetCompareSignal(tvi - tviSignal, prevTvi - prevTviSignal); signalsList.Add(signal); @@ -1930,17 +1930,17 @@ public static StockData CalculateTFSVolumeOscillator(this StockData stockData, i for (int i = 0; i < stockData.Count; i++) { - decimal open = openList.ElementAtOrDefault(i); - decimal close = inputList.ElementAtOrDefault(i); - decimal volume = volumeList.ElementAtOrDefault(i); + decimal open = openList[i]; + decimal close = inputList[i]; + decimal volume = volumeList[i]; decimal totv = close > open ? volume : close < open ? -volume : 0; - totvList.Add(totv); + totvList.AddRounded(totv); decimal totvSum = totvList.TakeLastExt(length).Sum(); decimal prevTfsvo = tfsvoList.LastOrDefault(); decimal tfsvo = length != 0 ? totvSum / length : 0; - tfsvoList.Add(tfsvo); + tfsvoList.AddRounded(tfsvo); var signal = GetCompareSignal(tfsvo, prevTfsvo); signalsList.Add(signal); @@ -1970,14 +1970,14 @@ public static StockData CalculateMarketFacilitationIndex(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i); - decimal prevVolume = i >= 1 ? volumeList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal currentVolume = volumeList[i]; + decimal prevVolume = i >= 1 ? volumeList[i - 1] : 0; decimal prevMfi = mfiList.LastOrDefault(); decimal mfi = currentVolume != 0 ? (currentHigh - currentLow) / currentVolume : 0; - mfiList.Add(mfi); + mfiList.AddRounded(mfi); decimal mfiDiff = mfi - prevMfi; decimal volDiff = currentVolume - prevVolume; @@ -2013,13 +2013,13 @@ public static StockData CalculateMultiVoteOnBalanceVolume(this StockData stockDa for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentClose = inputList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal currentVolume = volumeList.ElementAtOrDefault(i) / 1000000; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentClose = inputList[i]; + decimal currentLow = lowList[i]; + decimal currentVolume = volumeList[i] / 1000000; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; decimal highVote = currentHigh > prevHigh ? 1 : currentHigh < prevHigh ? -1 : 0; decimal lowVote = currentLow > prevLow ? 1 : currentLow < prevLow ? -1 : 0; decimal closeVote = currentClose > prevClose ? 1 : currentClose < prevClose ? -1 : 0; @@ -2027,16 +2027,16 @@ public static StockData CalculateMultiVoteOnBalanceVolume(this StockData stockDa decimal prevMvo = mvoList.LastOrDefault(); decimal mvo = prevMvo + (currentVolume * totalVotes); - mvoList.Add(mvo); + mvoList.AddRounded(mvo); } var mvoEmaList = GetMovingAverageList(stockData, maType, length, mvoList); for (int i = 0; i < stockData.Count; i++) { - decimal mvo = mvoList.ElementAtOrDefault(i); - decimal mvoEma = mvoEmaList.ElementAtOrDefault(i); - decimal prevMvo = i >= 1 ? mvoList.ElementAtOrDefault(i - 1) : 0; - decimal prevMvoEma = i >= 1 ? mvoEmaList.ElementAtOrDefault(i - 1) : 0; + decimal mvo = mvoList[i]; + decimal mvoEma = mvoEmaList[i]; + decimal prevMvo = i >= 1 ? mvoList[i - 1] : 0; + decimal prevMvoEma = i >= 1 ? mvoEmaList[i - 1] : 0; var signal = GetCompareSignal(mvo - mvoEma, prevMvo - prevMvoEma); signalsList.Add(signal); diff --git a/Calculations/Wilder.cs b/Calculations/Wilder.cs index 3fe0346..e65699b 100644 --- a/Calculations/Wilder.cs +++ b/Calculations/Wilder.cs @@ -20,9 +20,9 @@ public static StockData CalculateAverageTrueRange(this StockData stockData, Movi for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal currentTrueRange = CalculateTrueRange(currentHigh, currentLow, prevClose); trList.AddRounded(currentTrueRange); @@ -31,12 +31,12 @@ public static StockData CalculateAverageTrueRange(this StockData stockData, Movi var atrList = GetMovingAverageList(stockData, maType, length, trList); for (int i = 0; i < stockData.Count; i++) { - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal atr = atrList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; - decimal prevEma = i >= 1 ? emaList.ElementAtOrDefault(i - 1) : 0; - decimal prevAtr = i >= 1 ? atrList.ElementAtOrDefault(i - 1) : 0; + decimal currentValue = inputList[i]; + decimal atr = atrList[i]; + decimal currentEma = emaList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; + decimal prevEma = i >= 1 ? emaList[i - 1] : 0; + decimal prevAtr = i >= 1 ? atrList[i - 1] : 0; decimal atrEma = CalculateEMA(atr, prevAtr, length); var signal = GetVolatilitySignal(currentValue - currentEma, prevValue - prevEma, atr, atrEma); @@ -74,11 +74,11 @@ public static StockData CalculateAverageDirectionalIndex(this StockData stockDat for (int i = 0; i < stockData.Count; i++) { - decimal currentHigh = highList.ElementAtOrDefault(i); - decimal currentLow = lowList.ElementAtOrDefault(i); - decimal prevHigh = i >= 1 ? highList.ElementAtOrDefault(i - 1) : 0; - decimal prevLow = i >= 1 ? lowList.ElementAtOrDefault(i - 1) : 0; - decimal prevClose = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentHigh = highList[i]; + decimal currentLow = lowList[i]; + decimal prevHigh = i >= 1 ? highList[i - 1] : 0; + decimal prevLow = i >= 1 ? lowList[i - 1] : 0; + decimal prevClose = i >= 1 ? inputList[i - 1] : 0; decimal highDiff = currentHigh - prevHigh; decimal lowDiff = prevLow - currentLow; @@ -97,15 +97,15 @@ public static StockData CalculateAverageDirectionalIndex(this StockData stockDat var tr14List = GetMovingAverageList(stockData, maType, length, trList); for (int i = 0; i < stockData.Count; i++) { - decimal dmPlus14 = dmPlus14List.ElementAtOrDefault(i); - decimal dmMinus14 = dmMinus14List.ElementAtOrDefault(i); - decimal trueRange14 = tr14List.ElementAtOrDefault(i); + decimal dmPlus14 = dmPlus14List[i]; + decimal dmMinus14 = dmMinus14List[i]; + decimal trueRange14 = tr14List[i]; decimal diPlus = trueRange14 != 0 ? MinOrMax(100 * dmPlus14 / trueRange14, 100, 0) : 0; - diPlusList.Add(diPlus); + diPlusList.AddRounded(diPlus); decimal diMinus = trueRange14 != 0 ? MinOrMax(100 * dmMinus14 / trueRange14, 100, 0) : 0; - diMinusList.Add(diMinus); + diMinusList.AddRounded(diMinus); decimal diDiff = Math.Abs(diPlus - diMinus); decimal diSum = diPlus + diMinus; @@ -117,10 +117,10 @@ public static StockData CalculateAverageDirectionalIndex(this StockData stockDat var adxList = GetMovingAverageList(stockData, maType, length, diList); for (int i = 0; i < stockData.Count; i++) { - decimal diPlus = diPlusList.ElementAtOrDefault(i); - decimal diMinus = diMinusList.ElementAtOrDefault(i); - decimal prevDiPlus = i >= 1 ? diPlusList.ElementAtOrDefault(i - 1) : 0; - decimal prevDiMinus = i >= 1 ? diMinusList.ElementAtOrDefault(i - 1) : 0; + decimal diPlus = diPlusList[i]; + decimal diMinus = diMinusList[i]; + decimal prevDiPlus = i >= 1 ? diPlusList[i - 1] : 0; + decimal prevDiMinus = i >= 1 ? diMinusList[i - 1] : 0; var signal = GetCompareSignal(diPlus - diMinus, prevDiPlus - prevDiMinus); signalsList.Add(signal); @@ -161,17 +161,17 @@ public static StockData CalculateWellesWilderVolatilitySystem(this StockData sto for (int i = 0; i < stockData.Count; i++) { - decimal currentAtr = atrList.ElementAtOrDefault(i); - decimal currentEma = emaList.ElementAtOrDefault(i); - decimal highest = highestList.ElementAtOrDefault(i); - decimal lowest = lowestList.ElementAtOrDefault(i); - decimal currentValue = inputList.ElementAtOrDefault(i); - decimal prevValue = i >= 1 ? inputList.ElementAtOrDefault(i - 1) : 0; + decimal currentAtr = atrList[i]; + decimal currentEma = emaList[i]; + decimal highest = highestList[i]; + decimal lowest = lowestList[i]; + decimal currentValue = inputList[i]; + decimal prevValue = i >= 1 ? inputList[i - 1] : 0; decimal prevVStop = vstopList.LastOrDefault(); decimal sic = currentValue > currentEma ? highest : lowest; decimal vstop = currentValue > currentEma ? sic - (factor * currentAtr) : sic + (factor * currentAtr); - vstopList.Add(vstop); + vstopList.AddRounded(vstop); var signal = GetCompareSignal(currentValue - vstop, prevValue - prevVStop); signalsList.Add(signal); diff --git a/Helpers/CalculationsHelper.cs b/Helpers/CalculationsHelper.cs index 4066f18..f90c113 100644 --- a/Helpers/CalculationsHelper.cs +++ b/Helpers/CalculationsHelper.cs @@ -692,16 +692,16 @@ public static (List, List) GetMaxAndMinValuesList(List, List) GetMaxAndMinValuesList(List, List) GetMaxAndMinValuesList(ListThe value. public static void AddRounded(this List list, decimal value) { - list.Add(Math.Round(value, 4)); + list.AddRounded(Math.Round(value, 4)); } /// @@ -809,7 +809,7 @@ public static decimal PercentileNearestRank(this IEnumerable sequence, var n = list.Count; int rank = n > 0 ? (int)Math.Ceiling(percentile / 100 * n) : 0; - return list.ElementAtOrDefault(Math.Max(rank - 1, 0)); + return list[Math.Max(rank - 1, 0)]; } /// diff --git a/OoplesFinance.StockIndicators.csproj b/OoplesFinance.StockIndicators.csproj index d33ee9b..d64aa7c 100644 --- a/OoplesFinance.StockIndicators.csproj +++ b/OoplesFinance.StockIndicators.csproj @@ -8,7 +8,7 @@ True en-US Largest C# stock indicator library with over 750 to choose from and easiest to use with abilities such as making an indicator out of any other indicator or using any moving average with any indicator. - 1.0.35 + 1.0.37 ooples Ooples Finance https://github.com/ooples/OoplesFinance.StockIndicators