/// <summary> /// Linear regression is used to calculate a best fit line for the price data. In addition an upper and lower band is added by calculating the standard deviation of prices from the regression line. /// </summary> /// <returns></returns> public RegressionChannel RegressionChannel(Data.IDataSeries input, int period, double width) { if (cacheRegressionChannel != null) { for (int idx = 0; idx < cacheRegressionChannel.Length; idx++) { if (cacheRegressionChannel[idx].Period == period && Math.Abs(cacheRegressionChannel[idx].Width - width) <= double.Epsilon && cacheRegressionChannel[idx].EqualsInput(input)) { return(cacheRegressionChannel[idx]); } } } lock (checkRegressionChannel) { checkRegressionChannel.Period = period; period = checkRegressionChannel.Period; checkRegressionChannel.Width = width; width = checkRegressionChannel.Width; if (cacheRegressionChannel != null) { for (int idx = 0; idx < cacheRegressionChannel.Length; idx++) { if (cacheRegressionChannel[idx].Period == period && Math.Abs(cacheRegressionChannel[idx].Width - width) <= double.Epsilon && cacheRegressionChannel[idx].EqualsInput(input)) { return(cacheRegressionChannel[idx]); } } } RegressionChannel indicator = new RegressionChannel(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; indicator.Width = width; Indicators.Add(indicator); indicator.SetUp(); RegressionChannel[] tmp = new RegressionChannel[cacheRegressionChannel == null ? 1 : cacheRegressionChannel.Length + 1]; if (cacheRegressionChannel != null) { cacheRegressionChannel.CopyTo(tmp, 0); } tmp[tmp.Length - 1] = indicator; cacheRegressionChannel = tmp; return(indicator); } }
/// <summary> /// Linear regression is used to calculate a best fit line for the price data. In addition an upper and lower band is added by calculating the standard deviation of prices from the regression line. /// </summary> /// <returns></returns> public RegressionChannel RegressionChannel(Data.IDataSeries input, int period, double width) { if (cacheRegressionChannel != null) for (int idx = 0; idx < cacheRegressionChannel.Length; idx++) if (cacheRegressionChannel[idx].Period == period && Math.Abs(cacheRegressionChannel[idx].Width - width) <= double.Epsilon && cacheRegressionChannel[idx].EqualsInput(input)) return cacheRegressionChannel[idx]; lock (checkRegressionChannel) { checkRegressionChannel.Period = period; period = checkRegressionChannel.Period; checkRegressionChannel.Width = width; width = checkRegressionChannel.Width; if (cacheRegressionChannel != null) for (int idx = 0; idx < cacheRegressionChannel.Length; idx++) if (cacheRegressionChannel[idx].Period == period && Math.Abs(cacheRegressionChannel[idx].Width - width) <= double.Epsilon && cacheRegressionChannel[idx].EqualsInput(input)) return cacheRegressionChannel[idx]; RegressionChannel indicator = new RegressionChannel(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; indicator.Width = width; Indicators.Add(indicator); indicator.SetUp(); RegressionChannel[] tmp = new RegressionChannel[cacheRegressionChannel == null ? 1 : cacheRegressionChannel.Length + 1]; if (cacheRegressionChannel != null) cacheRegressionChannel.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheRegressionChannel = tmp; return indicator; } }