Skip to content
All library documents

Pine Script Matrix Library for Regression and Linear Algebra

Article TradingView scripts

Summary

This Pine Script document presents a reusable matrix and math library, with multiple linear regression as its main applied example. The library code covers array-based vector operations, matrix handling, common nonlinear functions, and approximations for normal, F, and Student t cumulative distributions. The regression routine estimates a dependent series from multiple explanatory series, optionally includes a constant, and can report coefficients and related statistics.

The example applies the model to a selected market series and two other symbols, then displays the estimate, standard error, R-squared measures, p-value, and coefficient statistics. It also plots the estimate with a band based on the estimate's standard error. This is an implementation example rather than a trading strategy or empirical study: the document reports no predictive performance, validation method, or trading results. Users should assess the statistical assumptions, approximation accuracy, and time-series behavior before treating regression output as evidence for a trade.

Key ideas

  • The library implements matrix and vector operations in Pine Script using arrays.
  • It includes approximations for several probability distributions and common activation functions.
  • The example regresses one market series on two explanatory series and can include a constant.
  • Reported outputs include coefficient estimates, standard errors, fit statistics, and a p-value.
  • The plotted estimate and standard-error band do not establish predictive power or trading value.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.