OPEN-SOURCE SCRIPT

LR Angle | julzALGO

2 579
LR Angle | julzALGO is a trend-angle visualization tool built around Linear Regression slope measurement.

Instead of judging trend strength only by how steep a line appears on the screen, the indicator calculates the slope mathematically, normalizes it with ATR, and converts it into a degree reading.

This provides a standardized way to evaluate trend direction and relative slope strength across different symbols, price levels, and volatility conditions.

The indicator is designed to answer one simple question:

Is the Linear Regression slope rising, falling, or becoming balanced?

Overview

LR Angle measures the angle of a Linear Regression line using market data rather than chart pixels.

The script compares the current Linear Regression value with its value a selected number of bars ago. It calculates the slope per bar, normalizes that slope using ATR, and converts the result into degrees using `math.atan()`.

This creates a digital-protractor-style angle reading:

Positive angle = rising Linear Regression slope
Negative angle = falling Linear Regression slope
Near zero = flatter or more balanced slope

The visual tools are designed to make this measurement easier to interpret directly on the chart.

Main Features

Linear Regression Angle Line

ảnh chụp nhanh

The indicator plots a Linear Regression line directly on the main chart.

The line color changes according to the calculated angle:

Green = rising slope
Red = falling slope
Neutral = flat or calculation not yet available

This provides a direct visual representation of the current trend-angle condition.

Default Linear Regression Length: 50

Visual Protractor

ảnh chụp nhanh

LR Angle includes an on-chart digital protractor-style display.

The protractor shows:

* Curved degree guide
* Tick marks
* Degree labels
* Directional needle
* Positive-angle orientation when the slope is rising
* Negative-angle orientation when the slope is falling

When the calculated angle is positive, the protractor represents the rising slope.

When the calculated angle is negative, the protractor flips downward to represent the falling slope.

The protractor is a visual representation only. The actual degree value is calculated mathematically from the ATR-normalized Linear Regression slope.

B / S Flip Labels

ảnh chụp nhanh

The script can display small B and S labels when the calculated angle state changes.

B : appears when the angle enters a rising condition
S : appears when the angle enters a falling condition

The optional B / S Angle Threshold allows users to require a minimum angle before a new state is recognized.

Example:

Threshold = 0° → any positive or negative state change can trigger
Threshold = 5°→ B requires an angle above +5°, while S requires an angle below −5°

These labels are directional angle-state markers. They are not automatic trade entries and can be combined with market structure, price action, volume analysis, and risk management.

Multi-Length Angle Matrix

ảnh chụp nhanh

The Angle Matrix compares multiple Linear Regression angle readings simultaneously.

Default rows:

LR 50
LR 100
LR 150
LR 200

Each row displays:

* Linear Regression length
* Calculated angle
* Direction state
* Strength blocks

Matrix states:

UP = angle is above the Balance Zone
DOWN = angle is below the negative Balance Zone
BALANCE = angle is inside the selected neutral range

The strength blocks fill according to the absolute angle relative to the selected Full Strength Angle

For example, if Full Strength Angle is set to 30°, readings approaching ±30° progressively fill more blocks. At or beyond the configured Full Strength Angle, the meter reaches full strength.

This makes it easier to compare weaker, balanced, and stronger directional slopes at a glance.

How the Angle Is Calculated

The calculation can be represented as:

Angle = atan(((LR − LR[N]) / N) / ATR) × 180 / π

Where:

LR = current Linear Regression value
LR[N] = Linear Regression value N bars ago
N = Slope Lookback
ATR = Average True Range used for normalization
atan = arctangent function
180 / π = conversion from radians to degrees

Step-by-Step Calculation

1. Calculate the current Linear Regression value.
2. Compare it with the Linear Regression value from N bars ago.
3. Divide the change by N to calculate slope per bar.
4. Divide the slope per bar by ATR to normalize it.
5. Apply `atan()` to the normalized slope.
6. Convert the result from radians into degrees.

Why ATR Normalization Is Used

Raw slope values are difficult to compare across markets.

For example, a 10-point movement in gold, BTC, forex, or a stock does not represent the same relative market movement.

ATR normalization scales the Linear Regression slope relative to the instrument's recent trading range.

This helps make the angle measurement more comparable across:

* Different symbols
* Different price levels
* Different volatility conditions
* Different chart environments

The result should still be interpreted in the context of the selected timeframe and settings.

Important Note About the Angle

The angle displayed by this indicator is **not the physical screen angle** of the plotted Linear Regression line.

Chart zoom, chart height, price scale, and screen dimensions can make any plotted line appear steeper or flatter.

LR Angle does not measure pixels or chart geometry.

Instead, it calculates a mathematical angle from the ATR-normalized Linear Regression slope, so the displayed degree reading is based on market data rather than the visual geometry of the chart.

Settings

Angle Calculation

Linear Regression Length

Controls the main Linear Regression period used for the angle calculation.

Default: 50

Slope Lookback

Controls how many bars back the current Linear Regression value is compared against.

Default: 10

ATR Length

Controls the ATR period used to normalize the slope.

Default: 14

Angle Settings

B / S Angle Threshold

Controls the minimum absolute angle required before a B or S state can trigger.

Default: 0°

Display

Show Linear Regression Line

Shows or hides the main Linear Regression angle line.

Show B / S Flip Labels

Shows or hides the B and S directional flip labels.

Line Width

Adjusts the thickness of the Linear Regression line.

Angle Matrix

Show Angle Matrix

Shows or hides the multi-length Angle Matrix.

Matrix Position

Controls where the matrix appears on the chart.

Matrix Text Size

Adjusts the size of the matrix text.

Matrix LR 1 / 2 / 3 / 4

Controls the four Linear Regression lengths used by the matrix.

Defaults:

* Matrix LR 1: 50
* Matrix LR 2: 100
* Matrix LR 3: 150
* Matrix LR 4: 200

Balance Zone Angle

Defines the ± neutral range where the matrix state is classified as BALANCE.

Default: 5°

Full Strength Angle

Defines the absolute angle required to completely fill the strength meter.

Default: 30°

Strength Blocks

Controls the number of blocks used in the matrix strength meter.

Default: 18

Visual Protractor

Show Visual Protractor

Shows or hides the digital protractor.

Center Bars Back

Controls how far behind the latest bar the center of the protractor is positioned.

Horizontal Radius

Controls the horizontal width of the protractor.

Vertical Radius ATR

Controls the vertical size of the protractor relative to ATR.

Show Tick Marks

Shows or hides the protractor tick marks.

Show Degree Labels

Shows or hides the degree numbers.

Style

Users can customize:

* Rising color
* Falling color
* Protractor color
* Needle color

How to Use

Rising Condition

ảnh chụp nhanh

When the Linear Regression line is green and the angle is positive, the calculated Linear Regression slope is rising.

If several Angle Matrix rows also display UP, multiple configured Linear Regression lengths are showing positive slopes.

Falling Condition

ảnh chụp nhanh

When the Linear Regression line is red and the angle is negative, the calculated Linear Regression slope is falling.

If several Angle Matrix rows also display DOWN, multiple configured Linear Regression lengths are showing negative slopes.

Balanced Conditions

ảnh chụp nhanh

When the angle is near zero, the measured slope is flatter.

The Balance Zone Angle determines how much positive or negative angle is classified as BALANCE in the matrix.

For example, with the Balance Zone set to 5°:

+3° = BALANCE
0° = BALANCE
−3° = BALANCE

Balanced readings indicate that the normalized Linear Regression slope is currently within the configured neutral range.

Reading the Matrix

The matrix helps compare shorter- and longer-length Linear Regression slopes.

Example of directional alignment:

LR 50 = UP
LR 100 = UP
LR 150 = UP
LR 200 = UP

This indicates positive slope readings across all four configured Linear Regression lengths.

Example of mixed conditions:

LR 50 = UP
LR 100 = BALANCE
LR 150 = DOWN
LR 200 = DOWN

This indicates disagreement between the shorter- and longer-length slope measurements.

Practical Uses

LR Angle can be used for:

* Trend-direction confirmation
* Relative slope-strength analysis
* Identifying flat or low-slope conditions
* Comparing shorter- and longer-length trend slopes
* Confirming pullback or continuation setups
* Filtering signals from another strategy
* Supporting discretionary market-structure analysis

It can also be combined with other forms of analysis such as price action, market structure, volume, support and resistance, VWAP, or order blocks.

Repainting / Real-Time Behavior

LR Angle does not intentionally reference future bars.

Values on historical bars are calculated from data available to those bars. On the current open candle, however, price, ATR, Linear Regression, angle readings, matrix values, and directional states can change as new price data arrives.

For traders who require confirmed readings, evaluate the indicator after the candle has closed.

Disclaimer

This indicator is intended for technical analysis and educational purposes only. It does not provide financial advice or guarantee future market direction or trading performance.

The B and S labels identify changes in the calculated angle state and should not be interpreted as guaranteed buy or sell signals.

Always use appropriate risk management and confirm trading decisions with your own analysis.

© julzALGO

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.