public void ChaikinADLine() { var goodOutputsLine1 = new double[HistoriesLength]; int outBeginningIndex = 0; int outNBElement = 0; var GoodOutputsRetCode1 = Core.Ad( FakeDataBase.ManualStartingIndex, EndingIndex, PriceHighs, PriceLows, ClosingPrices, Volumes, out outBeginningIndex, out outNBElement, goodOutputsLine1); var possiblyBadOutput1 = objectToTest.ChaikinADLine( TestDataFrequency, HistoriesLength ); Assert.Equal(GoodOutputsRetCode1, possiblyBadOutput1.Outcome); Assert.Equal(outBeginningIndex, possiblyBadOutput1.AlgorithmsBeginningIndex); Assert.Equal(outNBElement, possiblyBadOutput1.NBElement); for (int i = 0; i < goodOutputsLine1.Length; i++) { Assert.Equal(goodOutputsLine1[i], possiblyBadOutput1.Series[i]); } //CustomHistory test FakeDataBase.HistoryIsCustom = true; FakeDataBase.ManualStartingIndex = 5; goodOutputsLine1 = new double[HistoriesLength]; var GoodOutputsRetCode2 = Core.Ad( FakeDataBase.ManualStartingIndex, EndingIndex, PriceHighs, PriceLows, ClosingPrices, Volumes, out outBeginningIndex, out outNBElement, goodOutputsLine1); var possiblyBadOutput2 = objectToTest.ChaikinADLine( TestDataFrequency, HistoriesLength ); Assert.Equal(GoodOutputsRetCode2, possiblyBadOutput2.Outcome); Assert.Equal(outBeginningIndex, possiblyBadOutput2.AlgorithmsBeginningIndex); Assert.Equal(outNBElement, possiblyBadOutput2.NBElement); for (int i = 0; i < goodOutputsLine1.Length; i++) { Assert.Equal(goodOutputsLine1[i], possiblyBadOutput2.Series[i]); } }
/// <summary> /// Calculation of Chaikin A/D Line indicators /// </summary> /// <param name="db">data to calculate AD</param> /// <param name="name"></param> public AD(DataBars db, string name) : base(db, name) { int begin = 0, length = 0; Core.RetCode retCode = Core.RetCode.UnknownErr; double[] output = new double[db.Count]; retCode = Core.Ad(0, db.Count - 1, db.High.Values, db.Low.Values, db.Close.Values, db.Volume.Values, out begin, out length, output); if (retCode != Core.RetCode.Success) { return; } //Assign first bar that contains indicator data if (length <= 0) { FirstValidValue = begin + output.Length + 1; } else { FirstValidValue = begin; } this.Name = name; for (int i = begin, j = 0; j < length; i++, j++) { this[i] = output[j]; } }
public ITaLibOutput <double[]> ChaikinADLine(Frequency unitType, int historiesLength) { var inputs = new IndicatorsInputs(database, historiesLength); database.FillMarketHistory(unitType, inputs.OutputArrayLength); double[] highs = database.CurrentHistory .Select(bar => bar.PriceHigh) .ToArray(); double[] lows = database.CurrentHistory .Select(bar => bar.PriceLow) .ToArray(); double[] closes = database.CurrentHistory .Select(bar => bar.ClosingPrice) .ToArray(); double[] volumes = database.CurrentHistory .Select(bar => bar.Volume) .ToArray(); var output = new TaLibOutput <double[]> { Series = new double[inputs.OutputArrayLength], HistoryWasCustom = database.HistoryIsCustom }; int outBeginningIndex = 0; int outNBElement = 0; output.Outcome = Core.Ad(startIdx: inputs.StartingIndex, endIdx: inputs.EndIndex, inHigh: highs, inLow: lows, inClose: closes, inVolume: volumes, outBegIdx: out outBeginningIndex, outNBElement: out outNBElement, outReal: output.Series); output.AlgorithmsBeginningIndex = outBeginningIndex; output.NBElement = outNBElement; return(output); }