From 432d6bb548830640723b5976e4b96bc8da0d2223 Mon Sep 17 00:00:00 2001 From: Franklin Moormann Date: Wed, 7 Dec 2022 00:46:25 -0500 Subject: [PATCH] Changed all decimals to doubles which is a breaking change Added Market Meanness Index --- Calculations/Stochastic.cs | 2 +- Calculations/Trend.cs | 4 +- Calculations/Volatility.cs | 69 ++++++++++++++++++++++++++++ Enums/IndicatorName.cs | 2 + Enums/MovingAvgType.cs | 1 + OoplesFinance.StockIndicators.csproj | 2 +- README.md | 2 +- 7 files changed, 77 insertions(+), 5 deletions(-) diff --git a/Calculations/Stochastic.cs b/Calculations/Stochastic.cs index 46cf14e..e624089 100644 --- a/Calculations/Stochastic.cs +++ b/Calculations/Stochastic.cs @@ -309,7 +309,7 @@ public static StockData CalculateFisherTransformStochasticOscillator(this StockD double numSum = numList.TakeLastExt(smoothLength).Sum(); double denomSum = denomList.TakeLastExt(smoothLength).Sum(); double rbws = denomSum + 0.0001 != 0 ? MinOrMax(numSum / (denomSum + 0.0001) * 100, 100, 0) : 0; - double x = 0.1m * (rbws - 50); + double x = 0.1 * (rbws - 50); double ftso = MinOrMax((((Exp(2 * x) - 1) / (Exp(2 * x) + 1)) + 1) * 50, 100, 0); ftsoList.AddRounded(ftso); diff --git a/Calculations/Trend.cs b/Calculations/Trend.cs index 8cd141a..ab671a1 100644 --- a/Calculations/Trend.cs +++ b/Calculations/Trend.cs @@ -1123,10 +1123,10 @@ public static StockData CalculateGrandTrendForecasting(this StockData stockData, double prevFcast = i >= forecastLength ? fcastList[i - forecastLength] : 0; double prevChg = i >= length ? chgList[i - length] : currentValue; - double chg = 0.9m * prevT; + double chg = 0.9 * prevT; chgList.AddRounded(chg); - double t = (0.9m * prevT) + (0.1m * currentValue) + (chg - prevChg); + double t = (0.9 * prevT) + (0.1 * currentValue) + (chg - prevChg); tList.AddRounded(t); double trend = tList.TakeLastExt(length).Average(); diff --git a/Calculations/Volatility.cs b/Calculations/Volatility.cs index 094dc04..b57fb92 100644 --- a/Calculations/Volatility.cs +++ b/Calculations/Volatility.cs @@ -8,6 +8,8 @@ // so if you are going to re-use or modify my code then I just ask // that you include my copyright info and my contact info in a comment +using OoplesFinance.StockIndicators.Models; + namespace OoplesFinance.StockIndicators; public static partial class Calculations @@ -480,6 +482,73 @@ public static StockData CalculateMotionSmoothnessIndex(this StockData stockData, return stockData; } + /// + /// Calculates the Market Meanness Index + /// + /// + /// + /// + /// + public static StockData CalculateMarketMeannessIndex(this StockData stockData, MovingAvgType maType = MovingAvgType.EhlersNoiseEliminationTechnology, int length = 100) + { + List mmiList = new(); + List tempList = new(); + List signalsList = new(); + var (inputList, _, _, _, _) = GetInputValuesList(stockData); + + var maList = GetMovingAverageList(stockData, maType, length, inputList); + + for (int i = 0; i < stockData.Count; i++) + { + double currentValue = inputList[i]; + tempList.AddRounded(currentValue); + + double median = tempList.TakeLastExt(length).Median(); + int nl = 0, nh = 0; + for (int j = 1; j < length; j++) + { + var value1 = i >= j - 1 ? tempList[i - (j - 1)] : 0; + var value2 = i >= j ? tempList[i - j] : 0; + + if (value1 > median && value1 > value2) + { + nl++; + } + else if (value1 < median && value1 < value2) + { + nh++; + } + } + + double mmi = length != 1 ? 100 * (nl + nh) / (length - 1) : 0; + mmiList.AddRounded(mmi); + } + + var mmiFilterList = GetMovingAverageList(stockData, maType, length, mmiList); + for (int i = 0; i < stockData.Count; i++) + { + var mmiFilt = mmiFilterList[i]; + var prevMmiFilt1 = i >= 1 ? mmiFilterList[i - 1] : 0; + var prevMmiFilt2 = i >= 2 ? mmiFilterList[i - 2] : 0; + var currentValue = inputList[i]; + var currentMa = maList[i]; + + Signal signal = GetConditionSignal(currentValue < currentMa && ((mmiFilt > prevMmiFilt1 && prevMmiFilt1 < prevMmiFilt2) || (mmiFilt < prevMmiFilt1 && prevMmiFilt1 > prevMmiFilt2)), currentValue < currentMa && ((mmiFilt > prevMmiFilt1 && prevMmiFilt1 < prevMmiFilt2) || (mmiFilt < prevMmiFilt1 && prevMmiFilt1 > prevMmiFilt2))); + signalsList.Add(signal); + } + + stockData.OutputValues = new() + { + { "Mmi", mmiList }, + { "MmiSmoothed", mmiFilterList } + }; + stockData.SignalsList = signalsList; + stockData.CustomValuesList = mmiList; + stockData.IndicatorName = IndicatorName.MarketMeannessIndex; + + return stockData; + } + /// /// Calculates the choppiness index. /// diff --git a/Enums/IndicatorName.cs b/Enums/IndicatorName.cs index d1ea1b9..49c6c08 100644 --- a/Enums/IndicatorName.cs +++ b/Enums/IndicatorName.cs @@ -878,6 +878,8 @@ public enum IndicatorName [Category(IndicatorType.Volume)] MarketFacilitationIndex, [Category(IndicatorType.Volatility)] + MarketMeannessIndex, + [Category(IndicatorType.Volatility)] MartinRatio, [Category(IndicatorType.Momentum)] MassIndex, diff --git a/Enums/MovingAvgType.cs b/Enums/MovingAvgType.cs index c6c878f..d02539f 100644 --- a/Enums/MovingAvgType.cs +++ b/Enums/MovingAvgType.cs @@ -63,6 +63,7 @@ public enum MovingAvgType EhlersMedianAverageAdaptiveFilter, EhlersMesaAdaptiveMovingAverage, EhlersModifiedOptimumEllipticFilter, + EhlersNoiseEliminationTechnology, EhlersOptimumEllipticFilter, EhlersRecursiveMedianFilter, EhlersSuperSmootherFilter, diff --git a/OoplesFinance.StockIndicators.csproj b/OoplesFinance.StockIndicators.csproj index bcfd016..d029c50 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.47 + 1.0.48 ooples Ooples Finance https://github.com/ooples/OoplesFinance.StockIndicators diff --git a/README.md b/README.md index f9e0246..c9d5fea 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## .Net Stock Indicator Library -This is a stock indicator library that is completely open source (Apache 2.0 license) and very easy to use. Current version contains [762 stock indicators](https://ooples.github.io/OoplesFinance.StockIndicators/indicators) and I will add more as I get requests for them! +This is a stock indicator library that is completely open source (Apache 2.0 license) and very easy to use. Current version contains [763 stock indicators](https://ooples.github.io/OoplesFinance.StockIndicators/indicators) and I will add more as I get requests for them! ### How to use this library