From fc474f19eefe9344ca86e9d51f8318df682b948d Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Tue, 3 Jan 2023 18:13:55 -0800 Subject: [PATCH] codacy quality cleanup --- Source/Trends/SMA_Series.cs | 50 ++------------------------------ Source/Volatility/ATRP_Series.cs | 3 +- Source/Volatility/ATR_Series.cs | 3 +- 3 files changed, 5 insertions(+), 51 deletions(-) diff --git a/Source/Trends/SMA_Series.cs b/Source/Trends/SMA_Series.cs index a263532c..a00083dc 100644 --- a/Source/Trends/SMA_Series.cs +++ b/Source/Trends/SMA_Series.cs @@ -29,8 +29,9 @@ public class SMA_Series : Single_TSeries_Indicator { if (update) { _sum = _oldsum; } else { _oldsum = _sum; _len++; } _sum += TValue.v; - if (_period != 0 && _len > _period) - _sum -= (_data[base.Count - _period - (update ? 1 : 0)].v); + if (_period != 0 && _len > _period) { + _sum -= (_data[base.Count - _period - (update ? 1 : 0)].v); + } double _div = (_period == 0) ? _len : Math.Min(_len, _period); base.Add((TValue.t, _sum / _div), update, _NaN); } @@ -39,48 +40,3 @@ public class SMA_Series : Single_TSeries_Indicator { _len = _oldlen = 0; } } -/* -public class SMA_Series : Single_TSeries_Indicator -{ - private readonly System.Collections.Generic.List _buffer = new(); - private double _sma, _oldsma; - private double _topv, _oldtopv; - public SMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) - { - if (base._data.Count > 0) - { base.Add(base._data); } - } - public override void Add((System.DateTime t, double v) TValue, bool update) - { - _topv = Add_Replace_Trim(_buffer, TValue.v, _p, update); - - // rolling back if update, storing data for potential future update - if (update) - { - _sma = _oldsma; - _topv = _oldtopv; - } - else - { - _oldsma = _sma; - _oldtopv = _topv; - } - - // main additive calculation of SMA - for data points that are larger than _p period - // this.Count > _p - if (this.Count > _p) - { - _sma += (TValue.v - _topv) / _p; - } - else - { - // calculate SMA the traditional way (sum all, divide with _p) for data points within _p period - _sma = 0; - for (int i = 0; i < _buffer.Count; i++) - { _sma += _buffer[i]; } - _sma /= _buffer.Count; - } - - base.Add((TValue.t, _sma), update, _NaN); - } -}*/ diff --git a/Source/Volatility/ATRP_Series.cs b/Source/Volatility/ATRP_Series.cs index 5bfedfc0..72fdcd48 100644 --- a/Source/Volatility/ATRP_Series.cs +++ b/Source/Volatility/ATRP_Series.cs @@ -28,8 +28,7 @@ public class ATRP_Series : Single_TBars_Indicator { if (update) { _lastatr = _lastlastatr; _cm1 = _lastcm1; _sum = _oldsum; } else { _lastlastatr = _lastatr; _lastcm1 = _cm1; _oldsum = _sum; } - if (this.Count == 0) - _cm1 = TBar.c; + if (this.Count == 0) { _cm1 = TBar.c; } double d1 = Math.Abs(TBar.h - TBar.l); double d2 = Math.Abs(_cm1 - TBar.h); double d3 = Math.Abs(_cm1 - TBar.l); diff --git a/Source/Volatility/ATR_Series.cs b/Source/Volatility/ATR_Series.cs index 5e4d4bab..cd99885f 100644 --- a/Source/Volatility/ATR_Series.cs +++ b/Source/Volatility/ATR_Series.cs @@ -30,8 +30,7 @@ public class ATR_Series : Single_TBars_Indicator { if (update) { _lastatr = _lastlastatr; _cm1 = _lastcm1; _sum = _oldsum; } else { _lastlastatr = _lastatr; _lastcm1 = _cm1; _oldsum = _sum; } - if (this.Count == 0) - _cm1 = TBar.c; + if (this.Count == 0) { _cm1 = TBar.c; } double d1 = Math.Abs(TBar.h - TBar.l); double d2 = Math.Abs(_cm1 - TBar.h); double d3 = Math.Abs(_cm1 - TBar.l);