From a1b15682cef19294158b544dbb47de9ad43dfc26 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 29 Jan 2025 11:12:37 -0500 Subject: [PATCH] Fix issue in exponential moving average generator. Although I found where the generator was being used....the context of the usage has no impact on the issue with the generator because the usage was only using the first index in the exponential moving average which always amounts to just the value of the simple moving average. (i.e.) smoothing does not occur on the first index, only subsequent indices are smoothed. --- .../Generator/MovingAverageGenerator.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MarketDataLib/Generator/MovingAverageGenerator.cs b/MarketDataLib/Generator/MovingAverageGenerator.cs index a5ce86c..be4b61e 100644 --- a/MarketDataLib/Generator/MovingAverageGenerator.cs +++ b/MarketDataLib/Generator/MovingAverageGenerator.cs @@ -114,20 +114,30 @@ namespace MarketData.Generator return null; } } + + /// + /// The EMA coverage shoudld be the same as the simple moving average. If you have 10 elements in the SMA then you should have 10 elements in the EMA + /// The EMA smooths the line by applying a smoothing (Beta) where Beta=1/(dayCount+1). Foe example if you are wanting to calculate the + /// 20 day exponential moving average over a series then Beta=2/(20+1)=.095 + /// The formula: EMA=prevEMA.AVGPrice+beta*(smaPrice.CurrentPrice - prevEMA.AVGPrice) + /// Tom Basso uses a 9 day(Fast) and 41 day(Slow) exponential moving average crossover to determine change in trend direction. + /// + /// + /// + /// public static DMAPrices GenerateExponentialMovingAverage(Prices prices,int dayCount) { try { if(null==prices||prices.CountGenerates a dayCount moving average given prices. public static DMAPrices GenerateMovingAverage(Prices prices, int dayCount) {