Dynamic Gradient Filter

Mupsje Updated   

Sigmoid Functions:

History and Mathematical Basis:
  1. Sigmoid functions have a rich history in mathematics and are widely used in various fields, including statistics, machine learning, and signal processing.
  2. The term "sigmoid" originates from the Greek words "sigma" (meaning "S-shaped") and "eidos" (meaning "form" or "type").
  3. The sigmoid curve is characterized by its smooth S-shaped appearance, which allows it to map any real-valued input to a bounded output range, typically between 0 and 1.
  4. The most common form of the sigmoid function is the logistic function:

Logistic Function (σ):
  • Defined as σ(x) = 1 / (1 + e^(-x)), where:
'x' is the input value,
'e' is Euler's number (approximately 2.71828).
  • This function was first introduced by Belgian mathematician Pierre François Verhulst in the 1830s to model population growth with limiting factors.
  • It gained popularity in the early 20th century when statisticians like Ronald Fisher began using it in regression analysis.

Specific Sigmoid Functions Used in the Indicator:
  • sig(val):
The 'sig' function in this indicator is a modified version of the logistic function, clamping a value between 0 and 1 on the sigmoid curve.
  • siga(val):
The 'siga' function adjusts values between -1 and 1 on the sigmoid curve, offering a centered variation of the sigmoid effect.
  • sigmoid(val):
The 'sigmoid' function provides a standard implementation of the logistic function, calculating the sigmoid value of the input data.

Adaptive Smoothing Factor:
The 'adaptiveSmoothingFactor(gradient, k)' function computes a dynamic smoothing factor for the filter based on the gradient of the price data and the user-defined sensitivity parameter 'k'.

  • Gradient:
The gradient represents the rate of change in price, calculated as the absolute difference between the current and previous close prices.

  • Sensitivity (k):
The 'k' parameter adjusts how quickly the filter reacts to changes in the gradient. Higher values of 'k' lead to a more responsive filter, while lower values result in smoother outputs.

Usage in the Indicator:
The "close" value refers to the closing price of each period in the chart's time frame

  • The indicator calculates the gradient by measuring the absolute difference between the current "close" price and the previous "close" price.
  • This gradient represents the strength or magnitude of the price movement within the chosen time frame.
  • The "close" value plays a pivotal role in determining the dynamic behavior of the "Dynamic Gradient Filter," as it directly influences the smoothing factor.

What Makes This Special:
The "Dynamic Gradient Filter" indicator stands out due to its adaptive nature and responsiveness to changing market conditions.

Dynamic Smoothing Factor:
  • The indicator's dynamic smoothing factor adjusts in real-time based on the rate of change in price (gradient) and the user-defined sensitivity '(k)' parameter.
  • This adaptability allows the filter to respond promptly to both minor fluctuations and significant price movements.
Smoothed Price Action:
  • The final output of the filter is a smoothed representation of the price action, aiding traders in identifying trends and potential reversals.
Customizable Sensitivity:
  • Traders can adjust the 'Sensitivity' parameter '(k)' to suit their preferred trading style, making the indicator versatile for various strategies.
Visual Clarity:
  • The plotted "Dynamic Gradient Filter" line on the chart provides a clear visual guide, enhancing the understanding of market dynamics.

Traders and analysts can utilize the "Dynamic Gradient Filter" to:

  • Identify trends and reversals in price movements.
  • Filter out noise and highlight significant price changes.
  • Fine-tune trading strategies by adjusting the sensitivity parameter.
  • Enhance visual analysis with a dynamically adjusting filter line on the chart.


Release Notes:
minor adjustment to
m = input.float(1, title="Multiplier",minval=0.01, maxval=10000, step=0.01)
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?