Skip to content

Commit

Permalink
Changed all decimals to doubles which is a breaking change
Browse files Browse the repository at this point in the history
Added Market Meanness Index
  • Loading branch information
ooples committed Dec 7, 2022
1 parent a8a2beb commit 432d6bb
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Calculations/Stochastic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Calculations/Trend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
69 changes: 69 additions & 0 deletions Calculations/Volatility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -480,6 +482,73 @@ public static StockData CalculateMotionSmoothnessIndex(this StockData stockData,
return stockData;
}

/// <summary>
/// Calculates the Market Meanness Index
/// </summary>
/// <param name="stockData"></param>
/// <param name="maType"></param>
/// <param name="length"></param>
/// <returns></returns>
public static StockData CalculateMarketMeannessIndex(this StockData stockData, MovingAvgType maType = MovingAvgType.EhlersNoiseEliminationTechnology, int length = 100)
{
List<double> mmiList = new();
List<double> tempList = new();
List<Signal> 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;
}

/// <summary>
/// Calculates the choppiness index.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Enums/IndicatorName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,8 @@ public enum IndicatorName
[Category(IndicatorType.Volume)]
MarketFacilitationIndex,
[Category(IndicatorType.Volatility)]
MarketMeannessIndex,
[Category(IndicatorType.Volatility)]
MartinRatio,
[Category(IndicatorType.Momentum)]
MassIndex,
Expand Down
1 change: 1 addition & 0 deletions Enums/MovingAvgType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum MovingAvgType
EhlersMedianAverageAdaptiveFilter,
EhlersMesaAdaptiveMovingAverage,
EhlersModifiedOptimumEllipticFilter,
EhlersNoiseEliminationTechnology,
EhlersOptimumEllipticFilter,
EhlersRecursiveMedianFilter,
EhlersSuperSmootherFilter,
Expand Down
2 changes: 1 addition & 1 deletion OoplesFinance.StockIndicators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<NeutralLanguage>en-US</NeutralLanguage>
<Description>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. </Description>
<Version>1.0.47</Version>
<Version>1.0.48</Version>
<Authors>ooples</Authors>
<Company>Ooples Finance</Company>
<RepositoryUrl>https://github.com/ooples/OoplesFinance.StockIndicators</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 432d6bb

Please sign in to comment.