diff --git a/Quantower/Indicators/AAA_chart.cs b/Quantower/Indicators/AAA_chart.cs index 11884745..d932408f 100644 --- a/Quantower/Indicators/AAA_chart.cs +++ b/Quantower/Indicators/AAA_chart.cs @@ -13,47 +13,45 @@ public class AAA_chart : Indicator { #endregion Parameters private TBars bars; - private TSeries series; - private JMA_Series jma; - private DWMA_Series dwma; + private JMA_Series ind_a; + private DWMA_Series ind_b; + + public override string ShortName => $"AAA ({this.Period})"; public AAA_chart() : base() { - this.SeparateWindow = true; + this.SeparateWindow = false; + this.Name = "AAA - Test indicator"; this.Description = "Test indicator"; this.AddLineSeries("JMA", Color.RoyalBlue, 3, LineStyle.Solid); this.AddLineSeries("DWMA", Color.OrangeRed, 3, LineStyle.Solid); + this.SeparateWindow = false; } protected override void OnInit() { - this.ShortName = "AAA (" + this.Period + ")"; this.bars = new(); - this.series = new(); - this.jma = new(source: bars.HLC3, period: this.Period, useNaN: false); - this.dwma = new(source: bars.HLC3, period: this.Period, useNaN: false); + this.ind_a = new(source: bars.Close, period: this.Period, useNaN: false); + this.ind_b = new(source: bars.OHLC4, period: this.Period, useNaN: false); } protected override void OnUpdate(UpdateArgs args) { - Debug.WriteLine($"{args.Reason}"); bool update = !(args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar); - this.bars.Add(this.Time(), + 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), + this.GetPrice(PriceType.Volume), update); - //this.series.Add(0.25*(this.GetPrice(PriceType.Open)+ this.GetPrice(PriceType.High)+ this.GetPrice(PriceType.Low)+ this.GetPrice(PriceType.Close)), update); - - this.SetValue(this.jma.v.Last(), 0); - this.SetValue(this.dwma.v.Last(), 1); + this.SetValue(this.ind_a.v.Last(), 0); + this.SetValue(this.ind_b.v.Last(), 1); } } diff --git a/Quantower/Indicators/ATR_chart.cs b/Quantower/Indicators/ATR_chart.cs index d13e91b9..5467c3de 100644 --- a/Quantower/Indicators/ATR_chart.cs +++ b/Quantower/Indicators/ATR_chart.cs @@ -27,7 +27,6 @@ public class ATR_chart : Indicator protected override void OnInit() { - this.ShortName = "ATR (" + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars, period: this.Period, useNaN: false); } diff --git a/Quantower/Indicators/BIAS_chart.cs b/Quantower/Indicators/BIAS_chart.cs index 33405a72..f6bb61c3 100644 --- a/Quantower/Indicators/BIAS_chart.cs +++ b/Quantower/Indicators/BIAS_chart.cs @@ -32,7 +32,6 @@ public class BIAS_chart : Indicator protected override void OnInit() { - this.ShortName = "BIAS (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period); } diff --git a/Quantower/Indicators/CCI_chart.cs b/Quantower/Indicators/CCI_chart.cs index 02a6bb57..38d5ec7e 100644 --- a/Quantower/Indicators/CCI_chart.cs +++ b/Quantower/Indicators/CCI_chart.cs @@ -28,10 +28,10 @@ public class CCI_chart : Indicator protected override void OnInit() { - this.ShortName = "CCI (" + 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 && args.Reason != UpdateReason.HistoricalBar); diff --git a/Quantower/Indicators/DEMA_chart.cs b/Quantower/Indicators/DEMA_chart.cs index 10e1aa43..2fd74588 100644 --- a/Quantower/Indicators/DEMA_chart.cs +++ b/Quantower/Indicators/DEMA_chart.cs @@ -32,8 +32,6 @@ public class DEMA_chart : Indicator protected override void OnInit() { - this.ShortName = - "DEMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); diff --git a/Quantower/Indicators/EMA_chart.cs b/Quantower/Indicators/EMA_chart.cs index 3a6eb9ce..8960e4dc 100644 --- a/Quantower/Indicators/EMA_chart.cs +++ b/Quantower/Indicators/EMA_chart.cs @@ -32,7 +32,6 @@ public class EMA_chart : Indicator protected override void OnInit() { - this.ShortName = "EMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } diff --git a/Quantower/Indicators/ENTP_chart.cs b/Quantower/Indicators/ENTP_chart.cs index 4267974e..eab3f38d 100644 --- a/Quantower/Indicators/ENTP_chart.cs +++ b/Quantower/Indicators/ENTP_chart.cs @@ -32,7 +32,6 @@ public class ENTP_chart : Indicator protected override void OnInit() { - this.ShortName = "ENTP (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/HEMA_chart.cs b/Quantower/Indicators/HEMA_chart.cs index 121aa17f..ab44699f 100644 --- a/Quantower/Indicators/HEMA_chart.cs +++ b/Quantower/Indicators/HEMA_chart.cs @@ -32,8 +32,6 @@ public class HEMA_chart : Indicator protected override void OnInit() { - this.ShortName = - "HEMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); diff --git a/Quantower/Indicators/HMA_chart.cs b/Quantower/Indicators/HMA_chart.cs index ed0e3ea8..93667ef6 100644 --- a/Quantower/Indicators/HMA_chart.cs +++ b/Quantower/Indicators/HMA_chart.cs @@ -33,8 +33,6 @@ public class HMA_chart : Indicator protected override void OnInit() { - this.ShortName = - "HMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); diff --git a/Quantower/Indicators/JMA_chart.cs b/Quantower/Indicators/JMA_chart.cs index 70c3b445..cf0e3ac8 100644 --- a/Quantower/Indicators/JMA_chart.cs +++ b/Quantower/Indicators/JMA_chart.cs @@ -1,4 +1,5 @@ using System.Drawing; +using System.Linq; using TradingPlatform.BusinessLayer; namespace QuanTAlib; @@ -32,21 +33,18 @@ public class JMA_chart : Indicator protected override void OnInit() { - this.ShortName = - "JMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); - this.indicator = new(source: bars.Select(this.DataSource), - period: this.Period, useNaN: false); + this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } protected override void OnUpdate(UpdateArgs args) { - bool update = !(args.Reason == UpdateReason.NewBar || - args.Reason == UpdateReason.HistoricalBar); + bool update = !(args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar); 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; + + double result = this.indicator.v.Last(); this.SetValue(result); } } diff --git a/Quantower/Indicators/KAMA_chart.cs b/Quantower/Indicators/KAMA_chart.cs index 109ba100..88658444 100644 --- a/Quantower/Indicators/KAMA_chart.cs +++ b/Quantower/Indicators/KAMA_chart.cs @@ -37,7 +37,6 @@ public class KAMA_chart : Indicator protected override void OnInit() { - this.ShortName = "KAMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ":" + this.Fast + ":" + this.Slow + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, fast: this.Fast, slow: this.Slow, useNaN: false); } diff --git a/Quantower/Indicators/KURT_chart.cs b/Quantower/Indicators/KURT_chart.cs index e2e74631..6081cfc0 100644 --- a/Quantower/Indicators/KURT_chart.cs +++ b/Quantower/Indicators/KURT_chart.cs @@ -32,8 +32,6 @@ public class KURT_chart : Indicator protected override void OnInit() { - this.ShortName = - "KURT (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); diff --git a/Quantower/Indicators/MAD_chart.cs b/Quantower/Indicators/MAD_chart.cs index 819189b2..1f5a68c0 100644 --- a/Quantower/Indicators/MAD_chart.cs +++ b/Quantower/Indicators/MAD_chart.cs @@ -32,8 +32,6 @@ public class MAD_chart : Indicator protected override void OnInit() { - this.ShortName = - "MAD (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); diff --git a/Quantower/Indicators/MAPE_chart.cs b/Quantower/Indicators/MAPE_chart.cs index 9b772f33..571e2a64 100644 --- a/Quantower/Indicators/MAPE_chart.cs +++ b/Quantower/Indicators/MAPE_chart.cs @@ -32,9 +32,7 @@ public class MAPE_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "MAPE (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/MAX_chart.cs b/Quantower/Indicators/MAX_chart.cs index 8f318006..cecd04c1 100644 --- a/Quantower/Indicators/MAX_chart.cs +++ b/Quantower/Indicators/MAX_chart.cs @@ -32,9 +32,7 @@ public class MAX_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "MAX (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period); } diff --git a/Quantower/Indicators/MED_chart.cs b/Quantower/Indicators/MED_chart.cs index d56fc9e0..c1130ace 100644 --- a/Quantower/Indicators/MED_chart.cs +++ b/Quantower/Indicators/MED_chart.cs @@ -32,9 +32,7 @@ public class MED_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "MED (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period); } diff --git a/Quantower/Indicators/MIN_chart.cs b/Quantower/Indicators/MIN_chart.cs index 20da1dc3..00d21563 100644 --- a/Quantower/Indicators/MIN_chart.cs +++ b/Quantower/Indicators/MIN_chart.cs @@ -33,8 +33,6 @@ public class MIN_chart : Indicator protected override void OnInit() { this.bars = new(); - this.ShortName = - "MIN (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.indicator = new(source: bars.Select(this.DataSource), period: this.Period); } diff --git a/Quantower/Indicators/MSE_chart.cs b/Quantower/Indicators/MSE_chart.cs index ef3dfe53..96645353 100644 --- a/Quantower/Indicators/MSE_chart.cs +++ b/Quantower/Indicators/MSE_chart.cs @@ -32,9 +32,7 @@ public class MSE_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "MSE (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/RMA_chart.cs b/Quantower/Indicators/RMA_chart.cs index 153f78f0..20593f6e 100644 --- a/Quantower/Indicators/RMA_chart.cs +++ b/Quantower/Indicators/RMA_chart.cs @@ -32,9 +32,7 @@ public class RMA_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "RMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } diff --git a/Quantower/Indicators/RSI_chart.cs b/Quantower/Indicators/RSI_chart.cs index d5b840e7..ebd9d80b 100644 --- a/Quantower/Indicators/RSI_chart.cs +++ b/Quantower/Indicators/RSI_chart.cs @@ -32,9 +32,7 @@ public class RSI_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "RSI (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/SDEV_chart.cs b/Quantower/Indicators/SDEV_chart.cs index a5b956fa..2e6a423d 100644 --- a/Quantower/Indicators/SDEV_chart.cs +++ b/Quantower/Indicators/SDEV_chart.cs @@ -32,9 +32,7 @@ public class SDEV_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "SDEV (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/SMAPE_chart.cs b/Quantower/Indicators/SMAPE_chart.cs index 92084b5b..4fd46315 100644 --- a/Quantower/Indicators/SMAPE_chart.cs +++ b/Quantower/Indicators/SMAPE_chart.cs @@ -32,9 +32,7 @@ public class SMAPE_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "SMAPE (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/SMA_chart.cs b/Quantower/Indicators/SMA_chart.cs index 3439c0ee..57954ab6 100644 --- a/Quantower/Indicators/SMA_chart.cs +++ b/Quantower/Indicators/SMA_chart.cs @@ -32,13 +32,11 @@ public class SMA_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "SMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); - } - + } + protected override void OnUpdate(UpdateArgs args) { bool update = !(args.Reason == UpdateReason.NewBar || diff --git a/Quantower/Indicators/SMMA_chart.cs b/Quantower/Indicators/SMMA_chart.cs index 6bea81cb..ab7187fb 100644 --- a/Quantower/Indicators/SMMA_chart.cs +++ b/Quantower/Indicators/SMMA_chart.cs @@ -32,7 +32,6 @@ public class SMMA_chart : Indicator protected override void OnInit() { - this.ShortName = "SMMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } diff --git a/Quantower/Indicators/TEMA_chart.cs b/Quantower/Indicators/TEMA_chart.cs index ef944cbc..8a0c6293 100644 --- a/Quantower/Indicators/TEMA_chart.cs +++ b/Quantower/Indicators/TEMA_chart.cs @@ -32,9 +32,7 @@ public class TEMA_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "TEMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } diff --git a/Quantower/Indicators/VAR_chart.cs b/Quantower/Indicators/VAR_chart.cs index 3a665f01..d16725e8 100644 --- a/Quantower/Indicators/VAR_chart.cs +++ b/Quantower/Indicators/VAR_chart.cs @@ -32,13 +32,11 @@ public class VAR_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "VAR (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } - + 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 8444fb2e..e607561a 100644 --- a/Quantower/Indicators/WMAPE_chart.cs +++ b/Quantower/Indicators/WMAPE_chart.cs @@ -41,8 +41,7 @@ public class WMAPE_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = "WMAPE (" + QuanTAlib.TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: this.bars.Select(this.DataSource), period: this.Period, useNaN: true); } protected override void OnUpdate(UpdateArgs args) diff --git a/Quantower/Indicators/WMA_chart.cs b/Quantower/Indicators/WMA_chart.cs index 20019b22..755d0ebc 100644 --- a/Quantower/Indicators/WMA_chart.cs +++ b/Quantower/Indicators/WMA_chart.cs @@ -32,9 +32,7 @@ public class WMA_chart : Indicator protected override void OnInit() { - this.bars = new(); - this.ShortName = - "WMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: false); } diff --git a/Quantower/Quantower.csproj b/Quantower/Quantower.csproj index 080b789a..39ec2b10 100644 --- a/Quantower/Quantower.csproj +++ b/Quantower/Quantower.csproj @@ -1,52 +1,47 @@ - - - - net48 - preview - true - AnyCPU - Indicator - Quantower_QTAlib - QuanTAlib - embedded - preview - AnyCPU - disable - False - ..\.sonarlint\mihakralj_quantalibcsharp.ruleset - - - True - 3 - True - anycpu - full - C:\Quantower\TradingPlatform\v1.128.18\..\..\Settings\Scripts\Indicators\Quantower - - - embedded - True - 3 - True - anycpu - C:\Quantower\TradingPlatform\v1.128.18\..\..\Settings\Scripts\Indicators\Quantower - - - - QuanTAlib\%(RecursiveDir)%(Filename)%(Extension) - - - - - - - - - C:\Quantower\TradingPlatform\v1.128.18\bin\TradingPlatform.BusinessLayer.dll - - + + + + C:\Quantower\TradingPlatform\v1.128.20\bin\TradingPlatform.BusinessLayer.dll + + \ No newline at end of file diff --git a/Quantower/dll/TradingPlatform.BusinessLayer.dll b/Quantower/dll/TradingPlatform.BusinessLayer.dll index a85e72dd..95e71e6e 100644 Binary files a/Quantower/dll/TradingPlatform.BusinessLayer.dll and b/Quantower/dll/TradingPlatform.BusinessLayer.dll differ diff --git a/Tests/Validations/Trends/Skender.cs b/Tests/Validations/Trends/Skender.cs index 8997d5bc..1882eae9 100644 --- a/Tests/Validations/Trends/Skender.cs +++ b/Tests/Validations/Trends/Skender.cs @@ -16,8 +16,8 @@ public class Skender { bars = new(Bars: 10000, Volatility: 0.5, Drift: 0.0, Precision: 2); period = rnd.Next(30) + 5; - digits = 2; //minimizing rounding errors in type conversions - skip = 300; + digits = 6; //minimizing rounding errors in type conversions + skip = 200; quotes = bars.Select(q => new Quote { @@ -33,15 +33,14 @@ public class Skender [Fact] public void ADL() { - // TODO: check precision of ADL() ADL_Series QL = new(bars, false); var SK = quotes.GetAdl().Select(i => i.Adl); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round(SK.ElementAt(i - 1)!, digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1)!; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); + } } [Fact] public void ALMA() @@ -50,10 +49,10 @@ public class Skender var SK = quotes.GetAlma(period).Select(i => i.Alma.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void ATR() @@ -62,10 +61,10 @@ public class Skender var SK = quotes.GetAtr(period).Select(i => i.Atr.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void ATRP() @@ -74,10 +73,10 @@ public class Skender var SK = quotes.GetAtr(period).Select(i => i.Atrp.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void BBANDS() @@ -86,25 +85,25 @@ public class Skender var SK = quotes.GetBollingerBands(period, 2.0); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL.Mid[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1).Sma!.Value, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.Upper[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).UpperBand!.Value, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.Lower[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).LowerBand!.Value, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.Bandwidth[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).Width!.Value, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.PercentB[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).PercentB!.Value, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.Zscore[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).ZScore!.Value, digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL.Mid[i - 1].v; + double SK_item = SK.ElementAt(i - 1).Sma!.Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + QL_item = QL.Upper[i - 1].v; + SK_item = SK.ElementAt(i - 1).UpperBand!.Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + QL_item = QL.Lower[i - 1].v; + SK_item = SK.ElementAt(i - 1).LowerBand!.Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + QL_item = QL.Bandwidth[i - 1].v; + SK_item = SK.ElementAt(i - 1).Width!.Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + QL_item = QL.PercentB[i - 1].v; + SK_item = SK.ElementAt(i - 1).PercentB!.Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + QL_item = QL.Zscore[i - 1].v; + SK_item = SK.ElementAt(i - 1).ZScore!.Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void CCI() @@ -113,10 +112,10 @@ public class Skender var SK = quotes.GetCci(period).Select(i => i.Cci.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void CMO() @@ -125,10 +124,10 @@ public class Skender var SK = quotes.GetCmo(period).Select(i => i.Cmo.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void CORR() @@ -137,10 +136,10 @@ public class Skender var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period).Select(i => i.Correlation.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void COVAR() @@ -149,9 +148,9 @@ public class Skender var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period).Select(i => i.Covariance.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -161,9 +160,9 @@ public class Skender var SK = quotes.GetDema(period).Select(i => i.Dema.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -173,48 +172,46 @@ public class Skender var SK = quotes.GetEma(period).Select(i => i.Ema.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } - /* [Fact] public void HL2() { TSeries QL = bars.HL2; - var SK = quotes.GetBaseQuote(CandlePart.HL2).Select(i => i.Value); + var SK = quotes.GetBaseQuote(CandlePart.HL2); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1).Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void HLC3() { TSeries QL = bars.HLC3; - var SK = quotes.GetBaseQuote(CandlePart.HLC3).Select(i => i.Value); - for (int i = QL.Length; i > skip; i--) + var SK = quotes.GetBaseQuote(CandlePart.HLC3); + for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1).Value; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } - */ - [Fact] + [Fact] public void HMA() { HMA_Series QL = new(bars.Close, period, useNaN: false); var SK = quotes.GetHma(period).Select(i => i.Hma.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); - } + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits)); + } } [Fact] public void KAMA() @@ -224,9 +221,9 @@ public class Skender var SK = quotes.GetKama(period).Select(i => i.Kama.Null2NaN()!); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + double QL_item = QL[i - 1].v; + double SK_item = SK.ElementAt(i - 1); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -236,18 +233,18 @@ public class Skender var SK = quotes.GetSlope(period); for (int i = QL.Length; i > skip; i--) { - double QL_item = Math.Round(QL[i - 1].v, digits: digits); - double SK_item = Math.Round((double)SK.ElementAt(i - 1).Slope!, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.Intercept[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).Intercept!, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.RSquared[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).RSquared!, digits: digits); - Assert.Equal(SK_item!, QL_item); - QL_item = Math.Round(QL.StdDev[i - 1].v, digits: digits); - SK_item = Math.Round((double)SK.ElementAt(i - 1).StdDev!, digits: digits); - Assert.Equal(SK_item!, QL_item); + double QL_item = QL[i - 1].v; + double SK_item = (double)SK.ElementAt(i - 1).Slope!; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); + QL_item = QL.Intercept[i - 1].v; + SK_item = (double)SK.ElementAt(i - 1).Intercept!; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); + QL_item = QL.RSquared[i - 1].v; + SK_item = (double)SK.ElementAt(i - 1).RSquared!; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); + QL_item = QL.StdDev[i - 1].v; + SK_item = (double)SK.ElementAt(i - 1).StdDev!; + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -259,10 +256,10 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1).Macd.Null2NaN()!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); QL_item = Math.Round(QL.Signal[i - 1].v, digits: digits); SK_item = Math.Round(SK.ElementAt(i - 1).Signal.Null2NaN()!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -274,7 +271,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -286,10 +283,10 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1).Mama.Null2NaN()!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); QL_item = Math.Round(QL.Fama[i - 1].v, digits: digits); SK_item = Math.Round(SK.ElementAt(i - 1).Fama.Null2NaN()!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -301,7 +298,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -313,7 +310,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -326,7 +323,7 @@ public class Skender { double QL_item = Math.Round(QL.Last().v, digits: digits); double SK_item = Math.Round(SK.Last()! + (double)quotes.First().Volume!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } /* @@ -339,7 +336,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -351,7 +348,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -363,7 +360,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } */ @@ -376,7 +373,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -388,7 +385,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -400,7 +397,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -412,7 +409,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -424,7 +421,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -436,7 +433,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -448,7 +445,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -460,7 +457,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } } [Fact] @@ -472,7 +469,7 @@ public class Skender { double QL_item = Math.Round(QL[i - 1].v, digits: digits); double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); - Assert.Equal(SK_item!, QL_item); + Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); } }