/// <summary> /// Computes the next value in the transform. /// value1 is a function used to normalize price withing the last _period day range. /// value1 is centered on its midpoint and then doubled so that value1 wil swing between -1 and +1. /// value1 is also smoothed with an exponential moving average whose alpha is 0.33. /// /// Since the smoothing may allow value1 to exceed the _period day price range, limits are introduced to /// preclude the transform from blowing up by having an input larger than unity. /// </summary> /// <param name="input">IndicatorDataPoint - the time and value of the next price</param> /// <returns></returns> protected override decimal ComputeNextValue(TradeBar input) { var x = 0.0; var y = 0.0; var price = (input.Low + input.High) / 2m; _medianMin.Update(input.Time, price); _medianMax.Update(input.Time, price); if (!IsReady) { return(0); } var minL = _medianMin.Current.Value; var maxH = _medianMax.Current.Value; if (minL != maxH) { x = _alpha * 2 * ((double)((price - minL) / (maxH - minL)) - .5) + (1 - _alpha) * _previous; y = FisherTransformFunction(x); } _previous = x; return(Convert.ToDecimal(y) + .5m * Current.Value); }
protected override decimal ComputeNextValue(IReadOnlyWindow <TradeBar> window, TradeBar input) { _wfvMaximum.Update(new IndicatorDataPoint(input.EndTime, input.Close)); Current = new IndicatorDataPoint(input.EndTime, (_wfvMaximum.Current.Value - input.Low) / _wfvMaximum.Current.Value * 100m); return(Current.Value); }
/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> protected override decimal ComputeNextValue(TradeBar input) { Maximum.Update(input.Time, input.High); Mininum.Update(input.Time, input.Low); FastStoch.Update(input); StochK.Update(input); StochD.Update(input); return(StochK * 100); }
/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(IBaseDataBar input) { _maximum.Update(new IndicatorDataPoint { Value = input.High }); _minimum.Update(new IndicatorDataPoint { Value = input.Low }); return((_maximum + _minimum) / 2); }
/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="input">The input given to the indicator</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(IBaseDataBar input) { Minimum.Update(input.Time, input.Low); Maximum.Update(input.Time, input.High); if (!this.IsReady) { return(0); } var range = (Maximum.Current.Value - Minimum.Current.Value); return(range == 0 ? 0 : -100m * (Maximum.Current.Value - input.Close) / range); }
protected override decimal ComputeNextValue(TradeBar input) { _highest.Update(new IndicatorDataPoint(input.EndTime, input.Close)); if (_highest.IsReady) { Current = new IndicatorDataPoint(input.EndTime, ((_highest.Current.Value - input.Close) / _highest.Current.Value) * 100); } else { Current = new IndicatorDataPoint(input.EndTime, _highest.Current.Value); //Current = new IndicatorDataPoint(input.EndTime,((_highest.Current.Value - input.Close) / _highest.Current.Value) * 100); } return(Current.Value); }
/// <summary> /// Computes the next value in the transform. /// value1 is a function used to normalize price withing the last _period day range. /// value1 is centered on its midpoint and then doubled so that value1 wil swing between -1 and +1. /// value1 is also smoothed with an exponential moving average whose alpha is 0.33. /// /// Since the smoothing may allow value1 to exceed the _period day price range, limits are introduced to /// preclude the transform from blowing up by having an input larger than unity. /// </summary> /// <param name="window">The IReadOnlyWindow of Indicator Data Points for the history of this indicator</param> /// <param name="input">IndicatorDataPoint - the time and value of the next price</param> /// <returns></returns> protected override decimal ComputeNextValue(IReadOnlyWindow <IndicatorDataPoint> window, IndicatorDataPoint input) { _maxHigh.Update(input); _minLow.Update(input); decimal fishx = 0; if (IsReady) { // get some local variables var price = input.Value; var minL = _minLow.Current.Value; var maxH = _maxHigh.Current.Value; if (price == 0) { Current = new IndicatorDataPoint(input.EndTime, 0); } else { // get the value1 from the last time this function was called var v1 = value1[0].Value; try { // compute the EMA of the price and the last value1 value1.Add(new IndicatorDataPoint(input.Time, .33m * 2m * ((price - minL) / (maxH - minL) - .5m) + .67m * v1)); } catch (Exception ex) { throw new Exception(ex.Message + ex.StackTrace); } try { // limit the new value1 so that it falls within positive or negative unity if (value1[0].Value > .9999m) { value1[0].Value = .9999m; } if (value1[0].Value < -.9999m) { value1[0].Value = -.9999m; } var current = Current; // calcuate the Fisher transform according the the formula above and from Ehlers // Math.Log takes and produces doubles, so the result is converted back to Decimal // The calculation uses the Current.Value from the last time the function was called, // so an intermediate variable is introduced so that it can be used in the // calculation before the result is assigned to the Current.Value after the calculation is made. fishx = Convert.ToDecimal(.5 * Math.Log((1.0 + (double)value1[0].Value) / (1.0 - (double)value1[0].Value))); } catch (Exception ex) { throw new Exception(ex.Message + ex.StackTrace); } } } return(fishx); }
/// <summary> /// AroonUp = 100 * (period - {periods since max})/period /// </summary> /// <param name="upPeriod">The AroonUp period</param> /// <param name="max">A Maximum indicator used to compute periods since max</param> /// <param name="input">The next input data</param> /// <returns>The AroonUp value</returns> private static decimal ComputeAroonUp(int upPeriod, Maximum max, IndicatorDataPoint input) { max.Update(input); return(100m * (upPeriod - max.PeriodsSinceMaximum) / upPeriod); }