public void naNValuesInIntervall() { List <IBar> bars = new List <IBar>(); for (long i = 0; i <= 10; i++) { // (NaN, 1, NaN, 2, NaN, 3, NaN, 4, ...) decimal closePrice = i % 2 == 0 ? i : Decimals.NaN; IBar bar = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN); bars.Add(bar); } BaseTimeSeries series = new BaseTimeSeries("NaN test", bars); LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 2); for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++) { if (i % 2 != 0) { Assert.AreEqual(series.GetBar(i - 1).ClosePrice.ToString(), lowestValue.GetValue(i).ToString()); } else { Assert.AreEqual(series.GetBar(Math.Max(0, i - 1)).ClosePrice.ToString(), lowestValue.GetValue(i).ToString()); } } }
protected override decimal Calculate(int index) { decimal MinRsiValue = _minRsi.GetValue(index); return(_rsi.GetValue(index).Minus(MinRsiValue) .DividedBy(_maxRsi.GetValue(index).Minus(MinRsiValue))); }
public void LowestValueIndicatorUsingTimeFrame5UsingClosePrice() { var lowestValue = new LowestValueIndicator(new ClosePriceIndicator(_data), 5); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(4), "1"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(5), "2"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(6), "3"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(7), "3"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(8), "3"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(9), "3"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(10), "2"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(11), "2"); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(12), "2"); }
public override bool IsSatisfied(int index, ITradingRecord tradingRecord) { LowestValueIndicator lowest = new LowestValueIndicator(_indicator, _timeFrame); decimal lowestVal = lowest.GetValue(index); decimal refVal = _indicator.GetValue(index); bool satisfied = !refVal.IsNaN() && !lowestVal.IsNaN() && refVal.Equals(lowestVal); traceIsSatisfied(index, satisfied); return(satisfied); }
protected override decimal Calculate(int index) { HighestValueIndicator highestHigh = new HighestValueIndicator(_maxPriceIndicator, _timeFrame); LowestValueIndicator lowestMin = new LowestValueIndicator(_minPriceIndicator, _timeFrame); decimal highestHighPrice = highestHigh.GetValue(index); decimal lowestLowPrice = lowestMin.GetValue(index); return(_indicator.GetValue(index).Minus(lowestLowPrice) .DividedBy(highestHighPrice.Minus(lowestLowPrice)) .MultipliedBy(Decimals.HUNDRED)); }
public void onlyNaNValues() { List <IBar> bars = new List <IBar>(); for (long i = 0; i <= 10000; i++) { IBar bar = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN); bars.Add(bar); } BaseTimeSeries series = new BaseTimeSeries("NaN test", bars); LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 5); for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++) { Assert.AreEqual(Decimals.NaN.ToString(), lowestValue.GetValue(i).ToString()); } }
protected override Decimal Calculate(int index) { var realTimeFrame = Math.Min(_timeFrame, index + 1); // Getting the number of ticks since the lowest close price var endIndex = index - realTimeFrame; var nbTicks = 0; for (var i = index; i > endIndex; i--) { if (_closePriceIndicator.GetValue(i).IsEqual(_lowestClosePriceIndicator.GetValue(index))) { break; } nbTicks++; } return(Decimal.ValueOf(realTimeFrame - nbTicks).DividedBy(Decimal.ValueOf(realTimeFrame)).MultipliedBy(Decimal.Hundred)); }
protected override decimal Calculate(int index) { if (TimeSeries.GetBar(index).MinPrice.IsNaN()) { return(Decimals.NaN); } // Getting the number of bars since the lowest close price int endIndex = Math.Max(0, index - _timeFrame); int nbBars = 0; for (int i = index; i > endIndex; i--) { if (_minValueIndicator.GetValue(i).Equals(_lowestMinPriceIndicator.GetValue(index))) { break; } nbBars++; } return(((decimal)(_timeFrame - nbBars)).DividedBy(_timeFrame).MultipliedBy(Decimals.HUNDRED)); }
public void lowestValueIndicatorWhenTimeFrameIsGreaterThanIndex() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 500); Assert.AreEqual(lowestValue.GetValue(12), 1); }
public void lowestValueIndicatorValueShouldBeEqualsToFirstDataValue() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); Assert.AreEqual(lowestValue.GetValue(0), 1); }
public void lowestValueIndicatorUsingTimeFrame5UsingClosePrice() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); Assert.AreEqual(lowestValue.GetValue(1), 1M); Assert.AreEqual(lowestValue.GetValue(2), 1M); Assert.AreEqual(lowestValue.GetValue(3), 1M); Assert.AreEqual(lowestValue.GetValue(4), 1M); Assert.AreEqual(lowestValue.GetValue(5), 2M); Assert.AreEqual(lowestValue.GetValue(6), 3M); Assert.AreEqual(lowestValue.GetValue(7), 3M); Assert.AreEqual(lowestValue.GetValue(8), 3M); Assert.AreEqual(lowestValue.GetValue(9), 3M); Assert.AreEqual(lowestValue.GetValue(10), 2M); Assert.AreEqual(lowestValue.GetValue(11), 2M); Assert.AreEqual(lowestValue.GetValue(12), 2M); }
public void LowestValueIndicatorWhenTimeFrameIsGreaterThanIndex() { var lowestValue = new LowestValueIndicator(new ClosePriceIndicator(_data), 500); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(12), "1"); }
public void LowestValueIndicatorValueShouldBeEqualsToFirstDataValue() { var lowestValue = new LowestValueIndicator(new ClosePriceIndicator(_data), 5); TaTestsUtils.AssertDecimalEquals(lowestValue.GetValue(0), "1"); }
protected override decimal Calculate(int index) { return(_low.GetValue(index).Plus(_atr.GetValue(index).MultipliedBy(_k))); }