diff --git a/Quantower/Indicators/ATR_chart.cs b/Quantower/Indicators/ATR_chart.cs index ae9795a3..d13e91b9 100644 --- a/Quantower/Indicators/ATR_chart.cs +++ b/Quantower/Indicators/ATR_chart.cs @@ -30,8 +30,8 @@ public class ATR_chart : Indicator this.ShortName = "ATR (" + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars, period: this.Period, useNaN: false); - } - + } + protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || diff --git a/Quantower/Indicators/WMAPE_chart.cs b/Quantower/Indicators/WMAPE_chart.cs index f75dbecd..54fb4256 100644 --- a/Quantower/Indicators/WMAPE_chart.cs +++ b/Quantower/Indicators/WMAPE_chart.cs @@ -51,11 +51,6 @@ public class WMAPE_chart : Indicator this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update); double result = this.indicator[this.indicator.Count - 1].v; - this.SetValue(result, 0); - - - - } } diff --git a/Source/Basics/Abstracts.cs b/Source/Basics/Abstracts.cs index d20be702..434f3e7a 100644 --- a/Source/Basics/Abstracts.cs +++ b/Source/Basics/Abstracts.cs @@ -32,23 +32,14 @@ public abstract class Single_TSeries_Indicator : TSeries public new virtual void Add((System.DateTime t, double v) TValue, bool update) => base.Add(TValue, update); // potentially overridable Add() method for the whole series (could be replaced with faster bulk algo) - public virtual void Add(TSeries data) - { - for (int i = 0; i < data.Count; i++) { this.Add(TValue: data[i], update: false); } - } + public virtual void Add(TSeries data) { for (int i = 0; i < data.Count; i++) { this.Add(TValue: data[i], update: false); }} - public new void Add((System.DateTime t, double v) TValue) - => this.Add(TValue: TValue, update: false); - public void Add(bool update) - => this.Add(TValue: this._data[this._data.Count - 1], update: update); - public void Add() - => this.Add(TValue: this._data[this._data.Count - 1], update: false); - public new void Sub(object source, TSeriesEventArgs e) - => this.Add(TValue: this._data[this._data.Count - 1], update: e.update); + public new void Add((System.DateTime t, double v) TValue) => this.Add(TValue: TValue, update: false); + public void Add(bool update) => this.Add(TValue: this._data[this._data.Count - 1], update: update); + public void Add() => this.Add(TValue: this._data[this._data.Count - 1], update: false); + public new void Sub(object source, TSeriesEventArgs e) => this.Add(TValue: this._data[this._data.Count - 1], update: e.update); } - - public abstract class Pair_TSeries_Indicator : TSeries { protected readonly TSeries _d1; @@ -83,24 +74,14 @@ public abstract class Pair_TSeries_Indicator : TSeries } // overridable Add(Tvalue, Tvalue) method to add/update a single value at the end of the list - public virtual void Add((System.DateTime t, double v)TValue1, (System.DateTime t, double v)TValue2, bool update) - => base.Add(TValue: (TValue1.t, 0), update: update); // default inserts zeros - + public virtual void Add((System.DateTime t, double v)TValue1, (System.DateTime t, double v)TValue2, bool update) => base.Add(TValue: (TValue1.t, 0), update: update); // default inserts zeros // potentially overridable Add() bulk variations (could be replaced with faster bulk algos) - public virtual void Add(TSeries d1, TSeries d2) { - for (int i = 0; i < d1.Count; i++) { this.Add(d1[i], d2[i], update: false); } - } - public virtual void Add(TSeries d1, double dd2) { - for (int i = 0; i < d1.Count; i++) { this.Add(d1[i], (d1[i].t, dd2), update: false); } - } - public virtual void Add(double dd1, TSeries d2) { - for (int i = 0; i < d2.Count; i++) { this.Add((d2[i].t, dd1), d2[i], update: false); } - } + public virtual void Add(TSeries d1, TSeries d2) { for (int i = 0; i < d1.Count; i++) { this.Add(d1[i], d2[i], update: false); }} + public virtual void Add(TSeries d1, double dd2) { for (int i = 0; i < d1.Count; i++) { this.Add(d1[i], (d1[i].t, dd2), update: false); }} + public virtual void Add(double dd1, TSeries d2) { for (int i = 0; i < d2.Count; i++) { this.Add((d2[i].t, dd1), d2[i], update: false); }} - - public void Add((System.DateTime t, double v)TValue1, (System.DateTime t, double v)TValue2) - => this.Add(TValue1, TValue2, update: false); + public void Add((System.DateTime t, double v)TValue1, (System.DateTime t, double v)TValue2) => this.Add(TValue1, TValue2, update: false); public void Add(bool update) { @@ -123,12 +104,9 @@ public abstract class Pair_TSeries_Indicator : TSeries } public void Add() => this.Add(update: false); - - public new void Sub(object source, TSeriesEventArgs e) - => this.Add(e.update); + public new void Sub(object source, TSeriesEventArgs e) => this.Add(e.update); } - public abstract class Single_TBars_Indicator : TSeries { protected readonly int _p; @@ -148,22 +126,10 @@ public abstract class Single_TBars_Indicator : TSeries public virtual void Add((System.DateTime t, double o, double h, double l, double c, double v) TBar, bool update) => base.Add((TBar.t, 0.0), update); // potentially overridable Add() method for the whole bars or series (could be replaced with faster bulk algo) - public virtual void Add(TBars bars) - { - for (int i = 0; i < bars.Count; i++) { this.Add(TBar: bars[i], update: false); } - } - - public virtual void Add(TSeries data) - { - for (int i = 0; i < data.Count; i++) { base.Add(TValue: data[i], update: false); } - } - -public void Add((System.DateTime t, double o, double h, double l, double c, double v) TBar) - => this.Add(TBar: TBar, update: false); - public void Add(bool update) - => this.Add(TBar: this._bars[this._bars.Count - 1], update: update); - public void Add() - => this.Add(TBar: this._bars[this._bars.Count - 1], update: false); - public new void Sub(object source, TSeriesEventArgs e) - => this.Add(TBar: this._bars[this._bars.Count - 1], update: e.update); + public virtual void Add(TBars bars) { for (int i = 0; i < bars.Count; i++) { this.Add(TBar: bars[i], update: false); }} + public virtual void Add(TSeries data) { for (int i = 0; i < data.Count; i++) { base.Add(TValue: data[i], update: false); }} + public void Add((System.DateTime t, double o, double h, double l, double c, double v) TBar) => this.Add(TBar: TBar, update: false); + public void Add(bool update) => this.Add(TBar: this._bars[this._bars.Count - 1], update: update); + public void Add() => this.Add(TBar: this._bars[this._bars.Count - 1], update: false); + public new void Sub(object source, TSeriesEventArgs e) => this.Add(TBar: this._bars[this._bars.Count - 1], update: e.update); } diff --git a/Source/Basics/TBars.cs b/Source/Basics/TBars.cs index 849ca182..31954ef4 100644 --- a/Source/Basics/TBars.cs +++ b/Source/Basics/TBars.cs @@ -75,7 +75,6 @@ public class TBars : System.Collections.Generic.List<(DateTime t, double o, doub }; } - public void Add((DateTime t, double o, double h, double l, double c, double v) i, bool update = false) => Add(i.t, i.o, i.h, i.l, i.c, i.v, update); @@ -130,6 +129,4 @@ public class TBars : System.Collections.Generic.List<(DateTime t, double o, doub Pub(this, new TSeriesEventArgs { update = update }); } } - - } diff --git a/Source/Feeds/Alphavantage_Feed.cs b/Source/Feeds/Alphavantage_Feed.cs index 721d2f2d..ab485dfb 100644 --- a/Source/Feeds/Alphavantage_Feed.cs +++ b/Source/Feeds/Alphavantage_Feed.cs @@ -55,4 +55,3 @@ public class Alphavantage_Feed : TBars return (date, o, h, l, c, v); } } - diff --git a/Source/Feeds/GBM_Feed.cs b/Source/Feeds/GBM_Feed.cs index dbc9559e..0adcde1d 100644 --- a/Source/Feeds/GBM_Feed.cs +++ b/Source/Feeds/GBM_Feed.cs @@ -38,11 +38,11 @@ public class GBM_Feed : TBars double OCMax = Math.Max(Open,Close); double High = (GBM_value(seed, volatility*0.5, 0)); - High = (HighOCMin)? 2*OCMin-Low : Low; + Low = (Low>OCMin)? (2 * OCMin) - Low : Low; double Volume = GBM_value(seed*10, volatility*2, Drift:0); @@ -55,6 +55,6 @@ public class GBM_Feed : TBars double U1 = 1.0-rnd.NextDouble(); double U2 = 1.0-rnd.NextDouble(); double Z = Math.Sqrt(-2.0 * Math.Log(U1)) * Math.Sin(2.0 * Math.PI * U2); - return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + Volatility * Z); + return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + (Volatility * Z)); } } \ No newline at end of file diff --git a/Source/Indicators/ALMA_Series.cs b/Source/Indicators/ALMA_Series.cs index f91267e6..82072d68 100644 --- a/Source/Indicators/ALMA_Series.cs +++ b/Source/Indicators/ALMA_Series.cs @@ -62,7 +62,4 @@ public class ALMA_Series : Single_TSeries_Indicator _norm += _wt; } } - } - - diff --git a/Source/Indicators/ATRP_Series.cs b/Source/Indicators/ATRP_Series.cs index a50916e6..2bb6f1b1 100644 --- a/Source/Indicators/ATRP_Series.cs +++ b/Source/Indicators/ATRP_Series.cs @@ -50,7 +50,7 @@ public class ATRP_Series : Single_TBars_Indicator for (int i = 0; i < _buffer.Count; i++) { _ema += _buffer[i]; } _ema /= this._buffer.Count; } - else { _ema = d.v * _k + _lastema * _k1m; } + else { _ema = (d.v * _k) + (_lastema * _k1m); } this._lastlastema = this._lastema; this._lastema = _ema; diff --git a/Source/Indicators/ATR_Series.cs b/Source/Indicators/ATR_Series.cs index 70ec3c90..75740a1c 100644 --- a/Source/Indicators/ATR_Series.cs +++ b/Source/Indicators/ATR_Series.cs @@ -13,7 +13,6 @@ Sources: */ - public class ATR_Series : Single_TBars_Indicator { private readonly System.Collections.Generic.List _buffer = new(); @@ -53,7 +52,7 @@ public class ATR_Series : Single_TBars_Indicator for (int i = 0; i < _buffer.Count; i++) { _ema += _buffer[i]; } _ema /= this._buffer.Count; } - else { _ema = d.v * _k + _lastema * _k1m; } + else { _ema = (d.v * _k) + (_lastema * _k1m); } this._lastlastema = this._lastema; this._lastema = _ema; diff --git a/Source/Indicators/DEMA_Series.cs b/Source/Indicators/DEMA_Series.cs index 706196f0..016962e9 100644 --- a/Source/Indicators/DEMA_Series.cs +++ b/Source/Indicators/DEMA_Series.cs @@ -31,7 +31,6 @@ public class DEMA_Series : Single_TSeries_Indicator public override void Add((DateTime t, double v) TValue, bool update) { - if (update) { this._lastema1 = this._lastlastema1; @@ -53,12 +52,11 @@ public class DEMA_Series : Single_TSeries_Indicator for (int i = 0; i < _buffer.Count; i++) { _sma += _buffer[i]; } _sma /= this._buffer.Count; _ema1 = _ema2 = _sma; - } else { - _ema1 = TValue.v * this._k + this._lastema1 * this._k1m; - _ema2 = _ema1 * this._k + this._lastema2 * this._k1m; + _ema1 = (TValue.v * this._k) + (this._lastema1 * this._k1m); + _ema2 = (_ema1 * this._k) + (this._lastema2 * this._k1m); } double _dema = 2 * _ema1 - _ema2; diff --git a/Source/Indicators/TEMA_Series.cs b/Source/Indicators/TEMA_Series.cs index 6dfcbbb0..90aacfe2 100644 --- a/Source/Indicators/TEMA_Series.cs +++ b/Source/Indicators/TEMA_Series.cs @@ -33,7 +33,6 @@ public class TEMA_Series : Single_TSeries_Indicator public override void Add((DateTime t, double v) TValue, bool update) { - if (update) { this._lastema1 = this._lastlastema1; @@ -59,12 +58,12 @@ public class TEMA_Series : Single_TSeries_Indicator } else { - _ema1 = TValue.v * this._k + this._lastema1 * this._k1m; - _ema2 = _ema1 * this._k + this._lastema2 * this._k1m; - _ema3 = _ema2 * this._k + this._lastema3 * this._k1m; + _ema1 = (TValue.v * this._k) + (this._lastema1 * this._k1m); + _ema2 = (_ema1 * this._k) + (this._lastema2 * this._k1m); + _ema3 = (_ema2 * this._k) + (this._lastema3 * this._k1m); } - double _tema = 3 * (_ema1 - _ema2) + _ema3; + double _tema = (3 * (_ema1 - _ema2)) + _ema3; this._lastlastema1 = this._lastema1; this._lastlastema2 = this._lastema2; diff --git a/Source/Indicators/ZLEMA_Series.cs b/Source/Indicators/ZLEMA_Series.cs index 657bfbc7..ae4fef30 100644 --- a/Source/Indicators/ZLEMA_Series.cs +++ b/Source/Indicators/ZLEMA_Series.cs @@ -60,7 +60,7 @@ public class ZLEMA_Series : Single_TSeries_Indicator } else { - _ema = _zl * this._k + this._lastema * this._k1m; + _ema = (_zl * this._k) + (this._lastema * this._k1m); } this._lastlastema = this._lastema; diff --git a/Tests/Basics/TBars_Test.cs b/Tests/Basics/TBars_Test.cs index 67b0f121..c5f869a0 100644 --- a/Tests/Basics/TBars_Test.cs +++ b/Tests/Basics/TBars_Test.cs @@ -108,6 +108,5 @@ public class TBars_Test s.Add(DateTime.Today, 0.1, 1.1, 2.1, 3.1, 4.1, false); Assert.Equal(s.Close.v, t.v); Assert.Equal(s.Close.Count, t.Count); - } } diff --git a/Tests/MovingAvg/JMA_Test.cs b/Tests/MovingAvg/JMA_Test.cs index c0df4051..27115e00 100644 --- a/Tests/MovingAvg/JMA_Test.cs +++ b/Tests/MovingAvg/JMA_Test.cs @@ -27,7 +27,5 @@ public class JMA_Test Assert.Equal(a.Count, c.Count); a.Add(double.PositiveInfinity); Assert.Equal(a.Count, c.Count); - } - } diff --git a/Tests/Statistics/PSDEV_Test.cs b/Tests/Statistics/PSDEV_Test.cs index 503f9a6d..ce85da27 100644 --- a/Tests/Statistics/PSDEV_Test.cs +++ b/Tests/Statistics/PSDEV_Test.cs @@ -27,7 +27,5 @@ public class PSDEV_Test Assert.Equal(a.Count, c.Count); a.Add(double.PositiveInfinity); Assert.Equal(a.Count, c.Count); - } - } diff --git a/Tests/Statistics/SDEV_Test .cs b/Tests/Statistics/SDEV_Test .cs index 9b50f719..40c45af0 100644 --- a/Tests/Statistics/SDEV_Test .cs +++ b/Tests/Statistics/SDEV_Test .cs @@ -27,7 +27,5 @@ public class SDEV_Test Assert.Equal(a.Count, c.Count); a.Add(double.PositiveInfinity); Assert.Equal(a.Count, c.Count); - } - } diff --git a/Tests/Validations/Pandas_TA.cs b/Tests/Validations/Pandas_TA.cs index 38bffb2d..ce804d6a 100644 --- a/Tests/Validations/Pandas_TA.cs +++ b/Tests/Validations/Pandas_TA.cs @@ -120,5 +120,4 @@ public class PandasTA Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); } */ - } \ No newline at end of file diff --git a/Tests/Validations/Skender_Stock.cs b/Tests/Validations/Skender_Stock.cs index 2ee8329d..736c76cd 100644 --- a/Tests/Validations/Skender_Stock.cs +++ b/Tests/Validations/Skender_Stock.cs @@ -3,7 +3,6 @@ using QuanTAlib; using Skender.Stock.Indicators; using Xunit; - namespace Validation; public class Skender_Stock { @@ -177,7 +176,6 @@ public class Skender_Stock Assert.Equal(Math.Round((double)SK.Last().ZScore!, 8), Math.Round(QL.Zscore.Last().v, 8)); } - [Fact] public void RSI() { diff --git a/Tests/Validations/TA_LIB.cs b/Tests/Validations/TA_LIB.cs index 076a17d0..79195010 100644 --- a/Tests/Validations/TA_LIB.cs +++ b/Tests/Validations/TA_LIB.cs @@ -75,7 +75,6 @@ public class TA_LIB Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); } - [Fact] public void SMA() { @@ -215,11 +214,8 @@ public class TA_LIB Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], 7), Math.Round(QL.Upper.Last().v, 7)); Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], 7), Math.Round(QL.Mid.Last().v, 7)); Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], 7), Math.Round(QL.Lower.Last().v, 7)); - } - - [Fact] public void HL2() {