OPEN-SOURCE SCRIPT

Smoothed Basis

45
Overview and Purpose

The script calculates a smoothed mid-range basis between the highest and lowest prices over a specified period, then applies a smoothing function (smoothed moving average) to show the trend direction or momentum in a less noisy way. The area between the basis and its smoothed value is color-filled to visually highlight when the basis is above or below the smoothed average, signaling potentially bullish or bearish momentum.

Indicator Setup

length = Period length for calculating the highest and lowest values.
signal = Smoothing period used to smooth the basis.
offset =Optional horizontal shift to the plots (default 0).

Core Calculations

lower = Finds the lowest low over the past length bars.
upper = Finds the highest high over the past length bars.
basis = Calculates the midpoint between the highest and lowest.

Smoothing Calculation (Smoothed Moving Average - SMMA)

Declares smma as 0.0 initially. If the previous smma value is not available (like on the first bar), initializes with a simple moving average of basis over signal bars. Else applies formula
which gives a smoother version of basis which reacts less to sudden changes.

Plotting and Color Fill

Plots the raw basis line and smoothed basis line .
Fills the area between the basis and smoothed basis lines:

Greenish fill if the basis is above the smoothed value (potentially bullish).
Reddish fill if the basis is below the smoothed value (potentially bearish).

Interpretation and Use
The indicator visually shows where price ranges are shifting by tracking the midpoint between recent highs and lows.
The smoothed basis serves as a trend or momentum filter by dampening noise in the basis line.

When the basis is above the smoothed line (green fill), it signals upward momentum or strength; below it (red fill) suggests downward momentum or weakness.

The length and signal parameters allow tuning for different timeframes or asset volatility.

In summary, this code creates a custom smoothed oscillator based on the midpoint range of price extremes, highlighting trend changes via color fills and smoothening price action noise with an SMMA.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.