OPEN-SOURCE SCRIPT
Phase Regression Oscillator [LuxAlgo]

The Phase Regression Oscillator indicator is a cycle analysis tool that uses an analytical linear least squares fit to extract the instantaneous phase of a specified frequency relative to price action. By solving a system of normal equations on every bar, the script determines the "best fit" sine wave for a rolling window, providing a high-resolution view of the market's cyclical state.
🔶 USAGE
The indicator is designed to identify the current stage of a market cycle by fitting a theoretical sine wave to the most recent price data. Unlike traditional oscillators that rely on simple averages or price extremes, this tool uses regression to find the mathematical phase of the trend.
🔹 Interpreting the Components
🔶 DETAILS
The script employs a Linear Least Squares approach to model price as:
y = a·sin(ωx) + b·cos(ωx) + c
Instead of using a computationally expensive "grid search" to guess the phase, the indicator uses a 3x3 matrix solver (Cramer's Rule) to analytically find the coefficients a, b, and c that minimize the squared error. The phase (φ) is then extracted using the arctangent of the coefficients.
By defining the period as a percentage of the window size, the tool ensures that the regression always looks for a cycle length that is proportional to the observed lookback, making it adaptable across different timeframes and asset classes.
🔶 SETTINGS
🔹 Main Settings
🔹 Levels
🔹 Style
🔶 USAGE
The indicator is designed to identify the current stage of a market cycle by fitting a theoretical sine wave to the most recent price data. Unlike traditional oscillators that rely on simple averages or price extremes, this tool uses regression to find the mathematical phase of the trend.
🔹 Interpreting the Components
- Sine Oscillator (Solid Line): This is the primary signal. When the line is positive and green, the cycle is in its ascending or peaking phase. When negative and red, the cycle is in its descending or troughing phase.
- Cosine Component (Dotted Line): This represents the "quadrature" or in-phase component. In cycle analysis, the lead/lag relationship between the sine and cosine lines can help traders identify when a cycle is losing momentum or reaching a turning point.
- Overbought/Oversold Levels: Dashed horizontal lines indicate levels where the cycle fit has reached extreme mathematical synchronization, often preceding a phase shift or reversal.
🔶 DETAILS
The script employs a Linear Least Squares approach to model price as:
y = a·sin(ωx) + b·cos(ωx) + c
Instead of using a computationally expensive "grid search" to guess the phase, the indicator uses a 3x3 matrix solver (Cramer's Rule) to analytically find the coefficients a, b, and c that minimize the squared error. The phase (φ) is then extracted using the arctangent of the coefficients.
By defining the period as a percentage of the window size, the tool ensures that the regression always looks for a cycle length that is proportional to the observed lookback, making it adaptable across different timeframes and asset classes.
🔶 SETTINGS
🔹 Main Settings
- Window Size (N): The rolling lookback period (in bars) used to calculate the regression fit.
- Period % of Window: Defines the fixed period (P) of the sine wave as a percentage of the Window Size. A value of 100% means the regression looks for a cycle equal to the window length.
🔹 Levels
- Overbought Level: The upper threshold used to identify cycle peaks.
- Oversold Level: The lower threshold used to identify cycle troughs.
🔹 Style
- Bullish Color: Color for the oscillator when positive, the oversold level, and the upward gradient fill.
- Bearish Color: Color for the oscillator when negative, the overbought level, and the downward gradient fill.
- Cosine Color: The color of the dotted quadrature reference line.
- Zero Line Color: The color of the center baseline.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.