public PBandLower(Bars bars, int period, string description) : base(bars, description) { this.FirstValidValue = period; if (FirstValidValue > bars.Count || FirstValidValue < 0) { FirstValidValue = bars.Count; } if (bars.Count < period) { return; } DataSeries PBbot_slope = LinearRegSlope.Series(bars.Low, period); DataSeries Result = new DataSeries(bars, "temporary_lower"); for (int bar = period - 1; bar < bars.Count; bar++) { Result[bar] = bars.Low[bar]; for (int L_back = 0; L_back <= period - 1; L_back++) { Result[bar] = Math.Min(Result[bar], bars.Low[bar - L_back] + (PBbot_slope[bar] * (L_back))); } base[bar] = Result[bar]; } }
/// <summary> /// Initializes a new instance of the <see cref="LinearRegression"/>. /// </summary> /// <param name="linearReg">Linear regression.</param> /// <param name="rSquared">Regression R-squared.</param> /// <param name="regSlope">Coefficient with independent variable, slope of a straight line.</param> /// <param name="standardError">Standard error.</param> public LinearRegression(LinearReg linearReg, RSquared rSquared, LinearRegSlope regSlope, StandardError standardError) : base(linearReg, rSquared, regSlope, standardError) { LinearReg = linearReg; RSquared = rSquared; LinearRegSlope = regSlope; StandardError = standardError; Mode = ComplexIndicatorModes.Parallel; }
public TSF(DataSeries ds, int period, int ProjectionBar, string description) : base(ds, description) { base.FirstValidValue = period; if (ds.Count < period) { return; } //DataSeries sumY = Sum.Series(ds, period); //double sumBars = period * (period - 1) * 0.5; //int sumSqrBars = period * (period - 1) * (2 * period - 1) / 6; //double sum1 = 0; double sum2 = 0; double num1 = 0; double num2 = 0; //double m = 0; double b = 0; //for (int bar = base.FirstValidValue; bar < ds.Count; bar++) //{ // sum1 = 0.0; // for (int counter = (period - 1); counter > -1; counter--) // sum1 += counter * ds[bar - counter]; // sum2 = sumBars * sumY[bar]; // num1 = period * sum1 - sum2; // num2 = sumBars * sumBars - period * sumSqrBars; // if (num2 != 0) // m = num1 / num2; // else // m = 0; // b = (sumY[bar] - m * sumBars) / period; // base[bar] = m * (period - 1 - ProjectionBar) + b; //} // Or simply use this one-liner by Giorgio Beltrame :-) for (int bar = base.FirstValidValue; bar < ds.Count; bar++) { base[bar] = LinearReg.Series(ds, period)[bar] + (LinearRegSlope.Series(ds, period)[bar] * ProjectionBar); } }