/// <summary> /// Initializes a new instance of the average class /// </summary> /// <param name="name">The name of the indicator instance</param> /// <param name="n">The window period (must be even). Example value: 16</param> /// <param name="longPeriod">The average period. Example value: 198</param> public FractalAdaptiveMovingAverage(string name, int n, int longPeriod) : base(name) { if (n % 2 > 0) { throw new ArgumentException($"{name}: N must be even, N = {n}"); } _n = n; _w = Math.Log(2d / (1 + longPeriod)); _high = new RollingWindow <double>(n); _low = new RollingWindow <double>(n); }
/// <summary> /// Initializes a new instance of the average class /// </summary> /// <param name="name">The name of the indicator instance</param> /// <param name="n">The window period (must be even). Example value: 16</param> /// <param name="longPeriod">The average period. Example value: 198</param> public FractalAdaptiveMovingAverage(string name, int n, int longPeriod) : base(name) { if (n % 2 > 0) { throw new ArgumentException("N must be even."); } _n = n; _w = CalculateW(longPeriod); _high = new RollingWindow <double>(n); _low = new RollingWindow <double>(n); }
public EmpiricalModeDecomposition(string name, int period, decimal fraction, decimal delta) : base(name) { _period = period; _fraction = fraction; _delta = delta; _bars = new RollingWindow <IBaseDataBar>(3); _bps = new RollingWindow <double>(3); _peak = new Identity(name + "_Peak"); _valley = new Identity(name + "_Valley"); _bpMA = new SimpleMovingAverage(2 * _period); _peakMA = new SimpleMovingAverage(50); _valleyMA = new SimpleMovingAverage(50); }
/// <summary> /// Initializes a new instance of the <see cref="AutocorrelogramPeriodogram"/> class. /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="shortPeriod">The period of the low pass filter cut off frequency.</param> /// <param name="longPeriod">The period of the high pass filter cut off frequency.</param> /// <param name="correlationWidth">Number of pair observations used to estimate the autocorrelation coefficients.</param> public AutocorrelogramPeriodogram(string name, int shortPeriod, int longPeriod, int correlationWidth) : base(name, correlationWidth) { _shortPeriod = shortPeriod; _longPeriod = longPeriod; _bandwidth = longPeriod - shortPeriod; _correlationWidth = correlationWidth; _decayFactor = EstimateDecayFactor(_shortPeriod, _longPeriod); hpf = new HighPassFilter(longPeriod); sSmoother = new SuperSmoother(shortPeriod); sSmootherWindow = new RollingWindow <double>(longPeriod + _correlationWidth); R = Vector <double> .Build.Dense(_bandwidth + 1, 1d); }
/// <summary> /// Creates a new MarkProfile indicator with the specified period /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of this indicator</param> /// <param name="valueAreaVolumePercentage">The percentage of volume contained in the value area</param> /// <param name="priceRangeRoundOff">How many digits you want to round and the precision. /// i.e 0.01 round to two digits exactly. 0.05 by default.</param> protected MarketProfile(string name, int period, decimal valueAreaVolumePercentage = 0.70m, decimal priceRangeRoundOff = 0.05m) : base(name) { // Check roundoff is positive if (priceRangeRoundOff <= 0) { throw new ArgumentException("Must be strictly bigger than zero.", nameof(priceRangeRoundOff)); } _valueAreaVolumePercentage = valueAreaVolumePercentage; _oldDataPoints = new RollingWindow <Tuple <decimal, decimal> >(period); _volumePerPrice = new SortedList <decimal, decimal>(); _totalVolume = new Sum(name + "_Sum", period); _priceRangeRoundOff = 1 / priceRangeRoundOff; }
// The length of the smoothed window // square root of period rounded to the nearest whole number /// <summary> /// A Hull Moving Average /// </summary> /// <param name="name">string - a name for the indicator</param> /// <param name="period">int - the number of periods over which to calculate the HMA - the length of the longWMA</param> public HullMovingAverage(string name, int period) : base(name, period) { // Creates the long LWMA for the number of periods specified in the constuctor _longWma = new LinearWeightedMovingAverage("Long", period); // Creates the short LWMA for half the period rounded to the nearest whole number _shortWma = new LinearWeightedMovingAverage("Short", period / 2); // Creates the smoother data set to which the resulting wma is applied _smooth = new RollingWindow <IndicatorDataPoint>(period); // number of historical periods to look at in the resulting WMA int k = System.Convert.ToInt32(Math.Sqrt(period)); // Creates the LWMA for the output. This step probably could have been skipped _result = new LinearWeightedMovingAverage("Result", k); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="period"></param> public CyclePeriod(string name, int period = 3) : base(name, period) { // Initialize the differents window needed _smooth = new RollingWindow <decimal>(3); _cycle = new RollingWindow <decimal>(6); _quadrature = new RollingWindow <decimal>(2); _deltaPhase = new RollingWindow <decimal>(5); // Initialize the EMA needed _instPeriod = new ExponentialMovingAverage(2, new decimal(0.33)); _period = new ExponentialMovingAverage(10, new decimal(0.15)); // weight = 80% _A = (decimal)Math.Pow(1 - (double)_alpha / 2, 2); _B = 1 - _alpha; _quadCoeffA = new decimal(0.0962); _quadCoeffB = new decimal(0.5769); }
/// <summary> /// Creates a new Beta indicator with the specified name, period, target and /// reference values /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of this indicator</param> /// <param name="targetSymbol">The target symbol of this indicator</param> /// <param name="referenceSymbol">The reference symbol of this indicator</param> public Beta(string name, int period, Symbol targetSymbol, Symbol referenceSymbol) : base(name) { // Assert the period is greater than two, otherwise the beta can not be computed if (period < 2) { throw new Exception($"Period parameter for Beta indicator must be greater than 2 but was {period}"); } WarmUpPeriod = period + 1; _referenceSymbol = referenceSymbol; _targetSymbol = targetSymbol; _targetDataPoints = new RollingWindow <decimal>(2); _referenceDataPoints = new RollingWindow <decimal>(2); _targetReturns = new RollingWindow <double>(period); _referenceReturns = new RollingWindow <double>(period); _beta = 0; }
private decimal Median(RollingWindow <decimal> deltaPhase) { int k; decimal median; int obs = deltaPhase.Count; bool even = obs % 2 == 0; decimal[] array = deltaPhase.OrderBy(x => x).ToArray(); if (even) { k = obs / 2; median = (array[k] + array[k + 1]) / 2; } else { k = (obs + 1) / 2; median = array[k]; } return(median); }
/// <summary> /// Looks for the next low pivot point. /// </summary> /// <param name="windowLows">rolling window that tracks the lows</param> /// <param name="midPointIndexOrSurroundingBarsCount">The midpoint index or surrounding bars count for lows</param> /// <returns>pivot point if found else null</returns> protected virtual PivotPoint FindNextLowPivotPoint(RollingWindow <IBaseDataBar> windowLows, int midPointIndexOrSurroundingBarsCount) { var isLow = true; var middlePoint = windowLows[midPointIndexOrSurroundingBarsCount]; for (var k = 0; k < windowLows.Size && isLow; k++) { if (k == midPointIndexOrSurroundingBarsCount) { continue; } isLow = windowLows[k].Low > middlePoint.Low; } PivotPoint low = null; if (isLow) { low = new PivotPoint(PivotPointType.Low, middlePoint.Low, middlePoint.EndTime); } return(low); }
public FractalChannel(string name, int fractalLength = 5) : base(name) { _fractal = new RollingWindow <TradeBar>(fractalLength); _fractalMidIndex = fractalLength / 2 - (fractalLength % 2 == 0 ? 1 : 0); }
/// <summary> /// Initializes a new instance of the WindowIndicator class /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The number of data points to hold in the window</param> protected WindowIndicator(string name, int period) : base(name) { _window = new RollingWindow <T>(period); }
/// <summary> /// Swiss Army Knife indicator by John Ehlers /// </summary> /// <param name="name"></param> /// <param name="period"></param> /// <param name="delta"></param> /// <param name="tool"></param> public SwissArmyKnife(string name, int period, double delta, SwissArmyKnifeTool tool) : base(name) { _period = period; _tool = tool; _delta = delta; _filt = new RollingWindow <double>(2) { 0.0, 0.0 }; _price = new RollingWindow <double>(3); double alpha; double beta; double gamma; if (_tool == SwissArmyKnifeTool.Gauss) { beta = 2.415 * (1 - Math.Cos(2 * Math.PI / _period)); alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta); _c0 = alpha * alpha; _a1 = 2d * (1 - alpha); _a2 = -(1 - alpha) * (1 - alpha); } if (_tool == SwissArmyKnifeTool.Butter) { beta = 2.415 * (1 - Math.Cos(2 * Math.PI / _period)); alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta); _c0 = alpha * alpha / 4d; _b1 = 2; _b2 = 1; _a1 = 2d * (1 - alpha); _a2 = -(1 - alpha) * (1 - alpha); } if (_tool == SwissArmyKnifeTool.HighPass) { alpha = (Math.Cos(2 * Math.PI / _period) + Math.Sin(2 * Math.PI / _period) - 1) / Math.Cos(2 * Math.PI / _period); _c0 = (1 + alpha) / 2; _b1 = -1; _a1 = 1 - alpha; } if (_tool == SwissArmyKnifeTool.TwoPoleHighPass) { beta = 2.415 * (1 - Math.Cos(2 * Math.PI / _period)); alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta); _c0 = (1 + alpha) * (1 + alpha) / 4; _b1 = -2; _b2 = 1; _a1 = 2d * (1 - alpha); _a2 = -(1 - alpha) * (1 - alpha); } if (_tool == SwissArmyKnifeTool.BandPass) { beta = Math.Cos(2 * Math.PI / _period); gamma = (1 / Math.Cos(4 * Math.PI * _delta / _period)); alpha = gamma - Math.Sqrt(Math.Pow(gamma, 2) - 1); _c0 = (1 - alpha) / 2d; _b0 = 1; _b2 = -1; _a1 = -beta * (1 - alpha); _a2 = alpha; } }
/// <summary> /// Computes the returns with the new given data point and the last given data point /// </summary> /// <param name="rollingWindow">The collection of data points from which we want /// to compute the return</param> /// <returns>The returns with the new given data point</returns> private static double GetNewReturn(RollingWindow <decimal> rollingWindow) { return((double)((rollingWindow[0] / rollingWindow[1]) - 1)); }
private decimal Detrend(RollingWindow <decimal> sourceWindow) { return((_quadCoeffA * sourceWindow[0] + _quadCoeffB * sourceWindow[2] - _quadCoeffB * sourceWindow[4] - _quadCoeffA * sourceWindow.MostRecentlyRemoved) * (decimal)(.075 * _Period[1] + .54)); }