quotes; - - public Skender_Stock() - { - this.bars = new(Bars: 5000, Volatility:0.7, Drift:0.0); - this.period = this.rnd.Next(28) + 3; - this.quotes = this.bars.Select( - q => new Quote - { - Date = q.t, - Open = (decimal)q.o, - High = (decimal)q.h, - Low = (decimal)q.l, - Close = (decimal)q.c, - Volume = (decimal)q.v - }); - } - - [Fact] - public void SMA() - { - SMA_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetSma(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void EMA() - { - EMA_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetEma(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Ema!, 6), Math.Round(QL.Last().v, 6)); - } - [Fact] - public void WMA() - { - WMA_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetWma(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Wma!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void DEMA() - { - DEMA_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetDema(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Dema!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void TEMA() - { - TEMA_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetTema(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Tema!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void MAD() - { - MAD_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetSmaAnalysis(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Mad!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void MAPE() - { - MAPE_Series QL = new(this.bars.Close, this.period, false); - var SK = this.quotes.GetSmaAnalysis(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Mape!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void ATR() - { - ATR_Series QL = new(this.bars, this.period, false); - var SK = this.quotes.GetAtr(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Atr!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void OBV() - { - OBV_Series QL = new(this.bars, this.period, false); - var SK = this.quotes.GetObv(this.period); - - // adding volume[0] to OBV to pass the test and keep compatibility with TA-LIB - Assert.Equal(Math.Round((double)SK.Last().Obv!, 6) + Math.Round((double)this.quotes.First().Volume!, 6), - Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void ADL() - { - ADL_Series QL = new(this.bars, false); - var SK = this.quotes.GetAdl(); - - Assert.Equal(Math.Round((double)SK.Last().Adl!, 5), Math.Round(QL.Last().v, 5)); - } - - [Fact] - public void CCI() - { - CCI_Series QL = new(this.bars, this.period, false); - var SK = this.quotes.GetCci(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Cci!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void ATRP() - { - ATRP_Series QL = new(this.bars, this.period, false); - var SK = this.quotes.GetAtr(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Atrp!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void KAMA() - { - KAMA_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetKama(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Kama!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void HMA() - { - HMA_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetHma(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Hma!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void SMMA() - { - SMMA_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetSmma(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Smma!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void MACD() - { - MACD_Series QL = new(this.bars.Close, 26,12,9, useNaN: false); - var SK = this.quotes.GetMacd(12,26,9); - - Assert.Equal(Math.Round((double)SK.Last().Macd!, 6), Math.Round(QL.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().Signal!, 6), Math.Round(QL.Signal.Last().v, 6)); - } - - [Fact] - public void BBANDS() - { - BBANDS_Series QL = new(this.bars.Close, this.period, 2.0, useNaN: false); - var SK = this.quotes.GetBollingerBands(this.period, 2.0); - - Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Mid.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().UpperBand!, 6), Math.Round(QL.Upper.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().LowerBand!, 6), Math.Round(QL.Lower.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().Width!, 6), Math.Round(QL.Bandwidth.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().PercentB!, 6), Math.Round(QL.PercentB.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().ZScore!, 6), Math.Round(QL.Zscore.Last().v, 6)); - } - - [Fact] - public void RSI() - { - RSI_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetRsi(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Rsi!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void ALMA() - { - ALMA_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetAlma(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Alma!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void SDEV() - { - SDEV_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetStdDev(this.period); - - Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void LINREG() - { - LINREG_Series QL = new(this.bars.Close, this.period, useNaN: false); - var SK = this.quotes.GetSlope(this.period); - - Assert.Equal(Math.Round((double)SK.Last().Slope!, 6), Math.Round(QL.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().Intercept!, 6), Math.Round(QL.Intercept.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().RSquared!, 6), Math.Round(QL.RSquared.Last().v, 6)); - Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.StdDev.Last().v, 6)); - } - - [Fact] - public void TR() - { - TR_Series QL = new(this.bars, useNaN: false); - var SK = this.quotes.GetTr(); - - Assert.Equal(Math.Round((double)SK.Last().Tr!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void HL2() - { - TSeries QL = this.bars.HL2; - var SK = this.quotes.GetBaseQuote(CandlePart.HL2); - - Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void OC2() - { - TSeries QL = this.bars.OC2; - var SK = this.quotes.GetBaseQuote(CandlePart.OC2); - - Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void HLC3() - { - TSeries QL = this.bars.HLC3; - var SK = this.quotes.GetBaseQuote(CandlePart.HLC3); - - Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void OHL3() - { - TSeries QL = this.bars.OHL3; - var SK = this.quotes.GetBaseQuote(CandlePart.OHL3); - - Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); - } - - [Fact] - public void OHLC4() - { - TSeries QL = this.bars.OHLC4; - var SK = this.quotes.GetBaseQuote(CandlePart.OHLC4); - - Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); - } -} +using System; +using QuanTAlib; +using Skender.Stock.Indicators; +using Xunit; + +namespace Validation; +public class Skender_Stock +{ + private readonly GBM_Feed bars; + private readonly Random rnd = new(); + private readonly int period; + private readonly IEnumerablequotes; + + public Skender_Stock() + { + this.bars = new(Bars: 5000, Volatility:0.7, Drift:0.0); + this.period = this.rnd.Next(28) + 3; + this.quotes = this.bars.Select( + q => new Quote + { + Date = q.t, + Open = (decimal)q.o, + High = (decimal)q.h, + Low = (decimal)q.l, + Close = (decimal)q.c, + Volume = (decimal)q.v + }); + } + + [Fact] + public void SMA() + { + SMA_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetSma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void EMA() + { + EMA_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetEma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Ema!, 6), Math.Round(QL.Last().v, 6)); + } + [Fact] + public void WMA() + { + WMA_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetWma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Wma!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void DEMA() + { + DEMA_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetDema(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Dema!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void TEMA() + { + TEMA_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetTema(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Tema!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void MAD() + { + MAD_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetSmaAnalysis(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Mad!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void MAPE() + { + MAPE_Series QL = new(this.bars.Close, this.period, false); + var SK = this.quotes.GetSmaAnalysis(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Mape!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void ATR() + { + ATR_Series QL = new(this.bars, this.period, false); + var SK = this.quotes.GetAtr(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Atr!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void OBV() + { + OBV_Series QL = new(this.bars, this.period, false); + var SK = this.quotes.GetObv(this.period); + + // adding volume[0] to OBV to pass the test and keep compatibility with TA-LIB + Assert.Equal(Math.Round(SK.Last().Obv! + (double)this.quotes.First().Volume!, 5), + Math.Round(QL.Last().v, 5)); + } + + [Fact] + public void ADL() + { + ADL_Series QL = new(this.bars, false); + var SK = this.quotes.GetAdl(); + + Assert.Equal(Math.Round((double)SK.Last().Adl!, 5), Math.Round(QL.Last().v, 5)); + } + + [Fact] + public void CCI() + { + CCI_Series QL = new(this.bars, this.period, false); + var SK = this.quotes.GetCci(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Cci!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void ATRP() + { + ATRP_Series QL = new(this.bars, this.period, false); + var SK = this.quotes.GetAtr(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Atrp!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void KAMA() + { + KAMA_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetKama(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Kama!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void HMA() + { + HMA_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetHma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Hma!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void SMMA() + { + SMMA_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetSmma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Smma!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void MACD() + { + MACD_Series QL = new(this.bars.Close, 26,12,9, useNaN: false); + var SK = this.quotes.GetMacd(12,26,9); + + Assert.Equal(Math.Round((double)SK.Last().Macd!, 6), Math.Round(QL.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().Signal!, 6), Math.Round(QL.Signal.Last().v, 6)); + } + + [Fact] + public void BBANDS() + { + BBANDS_Series QL = new(this.bars.Close, this.period, 2.0, useNaN: false); + var SK = this.quotes.GetBollingerBands(this.period, 2.0); + + Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Mid.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().UpperBand!, 6), Math.Round(QL.Upper.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().LowerBand!, 6), Math.Round(QL.Lower.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().Width!, 6), Math.Round(QL.Bandwidth.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().PercentB!, 6), Math.Round(QL.PercentB.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().ZScore!, 6), Math.Round(QL.Zscore.Last().v, 6)); + } + + [Fact] + public void RSI() + { + RSI_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetRsi(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Rsi!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void ALMA() + { + ALMA_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetAlma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Alma!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void SDEV() + { + SDEV_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetStdDev(this.period); + + Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void LINREG() + { + LINREG_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetSlope(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Slope!, 6), Math.Round(QL.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().Intercept!, 6), Math.Round(QL.Intercept.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().RSquared!, 6), Math.Round(QL.RSquared.Last().v, 6)); + Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.StdDev.Last().v, 6)); + } + + [Fact] + public void TR() + { + TR_Series QL = new(this.bars, useNaN: false); + var SK = this.quotes.GetTr(); + + Assert.Equal(Math.Round((double)SK.Last().Tr!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void HL2() + { + TSeries QL = this.bars.HL2; + var SK = this.quotes.GetBaseQuote(CandlePart.HL2); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void OC2() + { + TSeries QL = this.bars.OC2; + var SK = this.quotes.GetBaseQuote(CandlePart.OC2); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void HLC3() + { + TSeries QL = this.bars.HLC3; + var SK = this.quotes.GetBaseQuote(CandlePart.HLC3); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void OHL3() + { + TSeries QL = this.bars.OHL3; + var SK = this.quotes.GetBaseQuote(CandlePart.OHL3); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); + } + + [Fact] + public void OHLC4() + { + TSeries QL = this.bars.OHLC4; + var SK = this.quotes.GetBaseQuote(CandlePart.OHLC4); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6)); + } +} diff --git a/Tests/Validations/TA_LIB.cs b/Tests/Validations/TA_LIB.cs index 4680de66..b8f2f7ce 100644 --- a/Tests/Validations/TA_LIB.cs +++ b/Tests/Validations/TA_LIB.cs @@ -1,272 +1,272 @@ -using Xunit; -using System; -using TALib; -using QuanTAlib; - -namespace Validation; -public class TA_LIB -{ - private readonly GBM_Feed bars; - private readonly Random rnd = new(); - private readonly int period; - private readonly double[] TALIB; - private readonly double[] inopen; - private readonly double[] inhigh; - private readonly double[] inlow; - private readonly double[] inclose; - private readonly double[] involume; - - public TA_LIB() - { - this.bars = new(5000); - this.period = this.rnd.Next(28) + 3; - this.TALIB = new double[this.bars.Count]; - this.inopen = this.bars.Open.v.ToArray(); - this.inhigh = this.bars.High.v.ToArray(); - this.inlow = this.bars.Low.v.ToArray(); - this.inclose = this.bars.Close.v.ToArray(); - this.involume = this.bars.Volume.v.ToArray(); - } - - ///////////////////////////////////////// - - [Fact] - public void ADD() - { - ADD_Series QL = new(this.bars.Open, this.bars.Close); - Core.Add(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void SUB() - { - SUB_Series QL = new(this.bars.Open, this.bars.Close); - Core.Sub(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void MUL() - { - MUL_Series QL = new(this.bars.Open, this.bars.Close); - Core.Mult(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void DIV() - { - DIV_Series QL = new(this.bars.Open, this.bars.Close); - Core.Div(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void SDEV() - { - SDEV_Series QL = new(this.bars.Close, this.period, false); - Core.StdDev(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void SMA() - { - SMA_Series QL = new(this.bars.Close, this.period, false); - Core.Sma(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void TRIMA() - { - TRIMA_Series QL = new(this.bars.Close, this.period, false); - Core.Trima(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void EMA() - { - EMA_Series QL = new(this.bars.Close, this.period, false); - Core.Ema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void WMA() - { - WMA_Series QL = new(this.bars.Close, this.period, false); - Core.Wma(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void DEMA() - { - DEMA_Series QL = new(this.bars.Close, this.period, false); - Core.Dema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void TEMA() - { - TEMA_Series QL = new(this.bars.Close, this.period, false); - Core.Tema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void MAX() - { - MAX_Series QL = new(this.bars.Close, this.period, false); - Core.Max(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void MIN() - { - MIN_Series QL = new(this.bars.Close, this.period, false); - Core.Min(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void ADL() - { - ADL_Series QL = new(this.bars, false); - Core.Ad(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void OBV() - { - OBV_Series QL = new(this.bars, this.period, false); - Core.Obv(this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void ADOSC() - { - ADOSC_Series QL = new(this.bars, false); - Core.AdOsc(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void ATR() - { - ATR_Series QL = new(this.bars, this.period, false); - Core.Atr(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void CCI() - { - CCI_Series QL = new(this.bars, this.period, false); - Core.Cci(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void RSI() - { - RSI_Series QL = new(this.bars.Close, this.period, false); - Core.Rsi(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void TR() - { - TR_Series QL = new(this.bars, false); - Core.TRange(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void MACD() - { - double[] macdSignal = new double[this.bars.Count]; - double[] macdHist = new double[this.bars.Count]; - MACD_Series QL = new(this.bars.Close, slow: 26, fast: 12, signal: 9, false); - Core.Macd(this.inclose, 0, this.bars.Count - 1, outMacd: this.TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _); - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - Assert.Equal(Math.Round(macdSignal[macdSignal.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Signal.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void BBANDS() - { - double[] outMiddle = new double[this.bars.Count]; - double[] outUpper = new double[this.bars.Count]; - double[] outLower = new double[this.bars.Count]; - BBANDS_Series QL = new(this.bars.Close, period:26, multiplier:2.0, false); - Core.Bbands(this.inclose, 0, this.bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod:26, optInNbDevUp:2.0, optInNbDevDn:2.0); - Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Upper.Last().v, 6, MidpointRounding.AwayFromZero)); - Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Mid.Last().v, 6, MidpointRounding.AwayFromZero)); - Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Lower.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void HL2() - { - TSeries QL = this.bars.HL2; - Core.MedPrice(this.inhigh, this.inlow, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void HLC3() - { - TSeries QL = this.bars.HLC3; - Core.TypPrice(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void OHLC4() - { - TSeries QL = this.bars.OHLC4; - Core.AvgPrice(this.inopen, this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } - - [Fact] - public void HLCC4() - { - TSeries QL = this.bars.HLCC4; - Core.WclPrice( this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); - } -} +using Xunit; +using System; +using TALib; +using QuanTAlib; + +namespace Validation; +public class TA_LIB +{ + private readonly GBM_Feed bars; + private readonly Random rnd = new(); + private readonly int period; + private readonly double[] TALIB; + private readonly double[] inopen; + private readonly double[] inhigh; + private readonly double[] inlow; + private readonly double[] inclose; + private readonly double[] involume; + + public TA_LIB() + { + this.bars = new(5000); + this.period = this.rnd.Next(28) + 3; + this.TALIB = new double[this.bars.Count]; + this.inopen = this.bars.Open.v.ToArray(); + this.inhigh = this.bars.High.v.ToArray(); + this.inlow = this.bars.Low.v.ToArray(); + this.inclose = this.bars.Close.v.ToArray(); + this.involume = this.bars.Volume.v.ToArray(); + } + + ///////////////////////////////////////// + + [Fact] + public void ADD() + { + ADD_Series QL = new(this.bars.Open, this.bars.Close); + Core.Add(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void SUB() + { + SUB_Series QL = new(this.bars.Open, this.bars.Close); + Core.Sub(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void MUL() + { + MUL_Series QL = new(this.bars.Open, this.bars.Close); + Core.Mult(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void DIV() + { + DIV_Series QL = new(this.bars.Open, this.bars.Close); + Core.Div(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void SDEV() + { + SDEV_Series QL = new(this.bars.Close, this.period, false); + Core.StdDev(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void SMA() + { + SMA_Series QL = new(this.bars.Close, this.period, false); + Core.Sma(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void TRIMA() + { + TRIMA_Series QL = new(this.bars.Close, this.period, false); + Core.Trima(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void EMA() + { + EMA_Series QL = new(this.bars.Close, this.period, false); + Core.Ema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void WMA() + { + WMA_Series QL = new(this.bars.Close, this.period, false); + Core.Wma(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void DEMA() + { + DEMA_Series QL = new(this.bars.Close, this.period, false); + Core.Dema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void TEMA() + { + TEMA_Series QL = new(this.bars.Close, this.period, false); + Core.Tema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void MAX() + { + MAX_Series QL = new(this.bars.Close, this.period, false); + Core.Max(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void MIN() + { + MIN_Series QL = new(this.bars.Close, this.period, false); + Core.Min(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void ADL() + { + ADL_Series QL = new(this.bars, false); + Core.Ad(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void OBV() + { + OBV_Series QL = new(this.bars, this.period, false); + Core.Obv(this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void ADOSC() + { + ADOSC_Series QL = new(this.bars, false); + Core.AdOsc(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void ATR() + { + ATR_Series QL = new(this.bars, this.period, false); + Core.Atr(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void CCI() + { + CCI_Series QL = new(this.bars, this.period, false); + Core.Cci(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void RSI() + { + RSI_Series QL = new(this.bars.Close, this.period, false); + Core.Rsi(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void TR() + { + TR_Series QL = new(this.bars, false); + Core.TRange(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void MACD() + { + double[] macdSignal = new double[this.bars.Count]; + double[] macdHist = new double[this.bars.Count]; + MACD_Series QL = new(this.bars.Close, slow: 26, fast: 12, signal: 9, false); + Core.Macd(this.inclose, 0, this.bars.Count - 1, outMacd: this.TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _); + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + Assert.Equal(Math.Round(macdSignal[macdSignal.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Signal.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void BBANDS() + { + double[] outMiddle = new double[this.bars.Count]; + double[] outUpper = new double[this.bars.Count]; + double[] outLower = new double[this.bars.Count]; + BBANDS_Series QL = new(this.bars.Close, period:26, multiplier:2.0, false); + Core.Bbands(this.inclose, 0, this.bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod:26, optInNbDevUp:2.0, optInNbDevDn:2.0); + Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Upper.Last().v, 6, MidpointRounding.AwayFromZero)); + Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Mid.Last().v, 6, MidpointRounding.AwayFromZero)); + Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Lower.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void HL2() + { + TSeries QL = this.bars.HL2; + Core.MedPrice(this.inhigh, this.inlow, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void HLC3() + { + TSeries QL = this.bars.HLC3; + Core.TypPrice(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void OHLC4() + { + TSeries QL = this.bars.OHLC4; + Core.AvgPrice(this.inopen, this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } + + [Fact] + public void HLCC4() + { + TSeries QL = this.bars.HLCC4; + Core.WclPrice( this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero)); + } +} diff --git a/docs/crossovers.ipynb b/docs/crossovers.ipynb index 304d3013..62f4583d 100644 --- a/docs/crossovers.ipynb +++ b/docs/crossovers.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 35, + "execution_count": 11, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 12, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -45,7 +45,8 @@ }, "outputs": [], "source": [ - "Yahoo_Feed data = new(Symbol: \"MSFT\", Period: 200);\n", + "String Sym = \"IBM\";\n", + "Alphavantage_Feed data = new(Symbol: Sym);\n", "ZLEMA_Series calc1 = new(data.OHLC4,20);\n", "HMA_Series calc2 = new(data.OHLC4,20);\n", "HEMA_Series calc3 = new(data.OHLC4,20);" @@ -53,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 17, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -68,29 +69,29 @@ "text/html": [ "\n", "\n", - " \r\n", + " \r\n", "\r\n", "\n", @@ -112,16 +113,16 @@ " GridColor:Color.fromString(\"#252525\")); \n", "\n", "var candles = Chart2D.Chart.Candlestick(data.Open.v, data.High.v, data.Low.v, data.Close.v, data.Open.t, \"\");\n", - "var line1 = Chart2D.Chart.Line (calc1.t, calc1.v,false,\"\").WithLineStyle(Width: 2, Color: Color.fromString(\"yellow\"));\n", - "var line2 = Chart2D.Chart.Line (calc2.t, calc2.v, false,\"\").WithLineStyle(Width: 3, Color: Color.fromString(\"red\"));\n", - "var line3 = Chart2D.Chart.Line (calc3.t, calc3.v, false,\"\").WithLineStyle(Width: 2, Color: Color.fromString(\"blue\"));\n", + "var line1 = Chart2D.Chart.Line (calc1.t, calc1.v, false, calc1.GetType().Name).WithLineStyle(Width: 2, Color: Color.fromString(\"yellow\"));\n", + "var line2 = Chart2D.Chart.Line (calc2.t, calc2.v, false, calc2.GetType().Name).WithLineStyle(Width: 3, Color: Color.fromString(\"red\"));\n", + "var line3 = Chart2D.Chart.Line (calc3.t, calc3.v, false, calc3.GetType().Name).WithLineStyle(Width: 2, Color: Color.fromString(\"blue\"));\n", "var chart = Chart.Combine(new []{candles, line1, line2, line3})\n", " .WithSize(1200,600)\n", " .WithMargin(Margin.init (30,10,40,30,1,false))\n", " .WithXAxisRangeSlider(RangeSlider.init(Visible:false))\n", " .WithYAxis(yAxis)\n", " .WithXAxis(yAxis)\n", - " .WithTitle(\"MSFT\")\n", + " .WithTitle(Sym)\n", " .WithLayout(layout);\n", "\n", "chart" diff --git a/docs/readme.md b/docs/readme.md index ce7c2fcf..e455846a 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -181,7 +181,7 @@ See [Getting Started](https://github.com/mihakralj/QuanTAlib/blob/main/Docs/gett | ⛔ AOBV - Archer On-Balance Volume |||| | ⛔ CMF - Chaikin Money Flow |||| | ⛔ EOM - Ease of Movement |||| -| ⭐ OBV - On-Balance Volume | `OBV_Series` | OBV | GetObv | +| ⭐ OBV - On-Balance Volume | ` OBV_Series` | OBV | GetObv | | ⛔ PRS - Price Relative Strength ||| | ⛔ PVOL - Price-Volume |||| | ⛔ PVO - Percentage Volume Oscillator ||||