Coeff |
A var[8] array for storing the calculated polynomial coefficients
a_{n}, or 0 for storing the coefficients internally. |

Data |
Data series to be approximated by the polynomial. |

Length |
Number of elements in the Data series to be approximated by the polynomial. |

Order |
Order of the polynomial (1..7). Use 1 for linear regression, 2 for parabolic
(quadratic) regression, and higher numbers for th-order regression. n |

Weight |
Ratio of the weight of the last data value to the weight of the first value, for "fading-memory" polynomials. Use 1 for equal weights. |

Coeff |
A var[8] array that contains the polynomial coefficients
a_{n}, or 0 for using the last coefficients generated by polyfit. |

Offs |
The offset into the polyfit Data series of the
returned polynomial value. Use negative offsets for extending the series
into the future. |

- Polynomials of order
**1**(straight line),**2**(parabola), or**3**are useful for price change predictions. Higher order polynomials are unlikely to give good predictions. - The weight ratio can be used for giving recent data more weight; however the best predictions are usually generated with
**weight**at**1**. - For better accuracy in price prediction, don't fit the polynomial to a price series, but to a series of price differences. Price differences vary more than prices and thus give more accurate correlation coefficients.
- As data series are stored in reverse order, a rising data series generates a polynomial with a falling slope, and vice versa.
- For predicting curve events with polynomial regression, such as crossovers, peaks, or valleys, use the predict function.
- For logistic linear regression with multiple variables, use the advise(PERCEPTRON,...) function.

// least square moving average indicatorvar LSMA(vars Data,int Period,int Offset) { polyfit(0,Data,Period,1,0); return polynom(0,Offset); }// quadratic least square moving average indicatorvar QLSMA(vars Data,int Period,int Offset) { polyfit(0,Data,Period,2,0); return polynom(0,Offset); }// predict price change by parabolic regressionfunction run()

{

vars Diff = series(price(0)-price(1)); var Correlation = polyfit(0,Diff,15,2,1);// sum up the differences for predicting the price change over the next 3 bars

var Change3 = polynom(0,-1)+polynom(0,-2)+polynom(0,-3);

plot("Prediction",price(0)+Change3,MAIN,BLUE);

plot("Correlation",Correlation,NEW,GREEN);

}