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()); } } }
/// <param name="series"> a time series </param> /// <returns> a global extrema strategy </returns> public static Strategy BuildStrategy(TimeSeries series) { if (series == null) { throw new ArgumentException("Series cannot be null"); } var closePrices = new ClosePriceIndicator(series); // Getting the max price over the past week var maxPrices = new MaxPriceIndicator(series); var weekMaxPrice = new HighestValueIndicator(maxPrices, NB_TICKS_PER_WEEK); // Getting the min price over the past week var minPrices = new MinPriceIndicator(series); var weekMinPrice = new LowestValueIndicator(minPrices, NB_TICKS_PER_WEEK); // Going long if the close price goes below the min price var downWeek = new MultiplierIndicator(weekMinPrice, Decimal.ValueOf("1.004")); var buyingRule = new UnderIndicatorRule(closePrices, downWeek); // Going short if the close price goes above the max price var upWeek = new MultiplierIndicator(weekMaxPrice, Decimal.ValueOf("0.996")); var sellingRule = new OverIndicatorRule(closePrices, upWeek); return(new Strategy(buyingRule, sellingRule)); }
/** * Constructor. * @param series the time series * @param timeFrame the time frame (usually 22) * @param k the K multiplier for ATR (usually 3.0) */ public ChandelierExitShortIndicator(ITimeSeries series, int timeFrame, decimal k) : base(series) { _low = new LowestValueIndicator(new MinPriceIndicator(series), timeFrame); _atr = new ATRIndicator(series, timeFrame); _k = k; }
/** * Constructor. * @param rsi the rsi indicator * @param timeFrame the time frame */ public StochasticRSIIndicator(RSIIndicator rsi, int timeFrame) : base(rsi) { _rsi = rsi; _minRsi = new LowestValueIndicator(rsi, timeFrame); _maxRsi = new HighestValueIndicator(rsi, timeFrame); }
/** * Constructor. * <p> * @param series the time series * @param MinValueIndicator the indicator for the Maximum price ( {@link MaxPriceIndicator}) * @param timeFrame the time frame */ public AroonDownIndicator(ITimeSeries series, IIndicator <decimal> MinValueIndicator, int timeFrame) : base(series) { _timeFrame = timeFrame; _minValueIndicator = MinValueIndicator; // + 1 needed for last possible iteration in loop _lowestMinPriceIndicator = new LowestValueIndicator(MinValueIndicator, timeFrame + 1); }
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 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 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 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()); } }
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 AroonDownIndicator(TimeSeries series, int timeFrame) : base(series) { _timeFrame = timeFrame; _closePriceIndicator = new ClosePriceIndicator(series); _lowestClosePriceIndicator = new LowestValueIndicator(_closePriceIndicator, timeFrame); }
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"); }