OPEN-SOURCE SCRIPT
TEWMA Supertrend - [JTCAPITAL]

TEWMA Supertrend - [JTCAPITAL] is a modified way to use Triple Exponential Weighted Moving Average (TEWMA) combined with ATR-based Supertrend logic for Trend-Following.
The idea behind this indicator is to merge the smoothness and responsiveness of TEWMA with the robustness of ATR-based Supertrend volatility filtering. This results in a tool that not only reacts quickly to price changes but also adapts to market volatility, providing reliable trend detection with reduced noise.
The indicator works by calculating in the following steps:
Buy and Sell Conditions:
-Buy Signal: Triggered when price closes above the Supertrend line, confirming a bullish shift.
-Sell Signal: Triggered when price closes below the Supertrend line, confirming a bearish shift.
Features and Parameters:
-TEWMA Source – Select the input price (Close, Open, High, Low, etc.).
-TEWMA Length – Defines the lookback for the Weighted MA and subsequent TEMA smoothing.
-Supertrend Length – Defines the ATR period used for volatility measurement.
-Multiplier – Determines how far the Supertrend bands are placed from the TEWMA. Higher values mean wider bands and fewer trend flips, while lower values mean tighter bands and more frequent signals.
Specifications:
Weighted Moving Average (WMA)
The WMA gives more importance to recent price points while still considering past values. This makes it more responsive to recent moves than a Simple Moving Average (SMA).
Triple Exponential Moving Average (TEMA)
TEMA reduces lag by combining multiple layers of EMA calculations. Unlike a simple EMA, which can be slow to react, TEMA anticipates changes faster, while still maintaining smoothness to avoid false signals.
TEWMA (TEMA of WMA)
By applying TEMA on top of WMA, we create a hybrid smoothing technique. This retains the responsiveness of WMA but reduces its lag via TEMA’s structure. The result is a highly adaptive moving average, ideal for fast trend detection.
Average True Range (ATR)
ATR measures the degree of volatility by looking at the full trading range of each candle. It ensures that the Supertrend bands expand in volatile markets and contract in calm markets, keeping signals relevant to current conditions.
Supertrend Bands
The upper and lower envelopes built around TEWMA act as dynamic support and resistance. Their adaptive nature reduces false trend shifts during choppy sideways markets.
Band Adjustment Logic
Instead of recalculating bands every candle, the script uses a memory mechanism (previous values) to prevent unnecessary trend switches. This stabilizes the indicator and avoids excessive noise.
Trend Line
The final output is a line that follows price in trending phases while holding steady during consolidations. Its placement above or below price clearly signals bullish or bearish market structure.
Color Coding and Visuals
The use of shaded fills and line coloring enhances readability. Traders can quickly distinguish trend direction and momentum without deep numerical analysis.
Enjoy!
The idea behind this indicator is to merge the smoothness and responsiveness of TEWMA with the robustness of ATR-based Supertrend volatility filtering. This results in a tool that not only reacts quickly to price changes but also adapts to market volatility, providing reliable trend detection with reduced noise.
The indicator works by calculating in the following steps:
- Source Selection
The user can select the price source (default is Close). This price series is the foundation of all calculations, and changing the source allows the indicator to adapt to different analytical perspectives, such as Open, High, Low, or HL2. - TEWMA Calculation
The script calculates a Weighted Moving Average (WMA) of the selected source, and then applies a Triple Exponential Moving Average (TEMA) smoothing on top of it. The result is what we call TEWMA. This hybrid method achieves two goals simultaneously:
-WMA adds sensitivity by giving more weight to recent data.
-TEMA reduces lag by combining multiple EMA calculations while keeping smoothness. - ATR Volatility Measurement
In parallel, the Average True Range (ATR) is calculated over the user-defined Supertrend length. ATR measures volatility and dynamically scales the upper and lower bands to adjust to different market conditions. - Upper and Lower Band Construction
The indicator builds two envelopes around the TEWMA:
-Upper Band = TEWMA + (Multiplier × ATR)
-Lower Band = TEWMA – (Multiplier × ATR)
These bands expand and contract depending on volatility, creating a dynamic channel. - Band Adjustment Logic
To prevent false flips, the current upper/lower band values are compared to their previous values. If price has not broken above or below the prior band, the bands “stick” to their previous values, thereby filtering noise and avoiding unnecessary trend changes. - Trend Detection
-If price closes above the adjusted upper band, the direction is bullish.
-If price closes below the adjusted lower band, the direction is bearish.
-Otherwise, the trend direction continues from its prior state.
The Trend line is then set to either the upper band (bearish) or lower band (bullish). - Visual Representation
-The TEWMA line itself is plotted and color-coded (blue for bullish, purple for bearish).
-The active Supertrend line is plotted depending on trend direction.
-Shaded regions are added around the lines for enhanced clarity, visually separating bullish and bearish phases.
Buy and Sell Conditions:
-Buy Signal: Triggered when price closes above the Supertrend line, confirming a bullish shift.
-Sell Signal: Triggered when price closes below the Supertrend line, confirming a bearish shift.
Features and Parameters:
-TEWMA Source – Select the input price (Close, Open, High, Low, etc.).
-TEWMA Length – Defines the lookback for the Weighted MA and subsequent TEMA smoothing.
-Supertrend Length – Defines the ATR period used for volatility measurement.
-Multiplier – Determines how far the Supertrend bands are placed from the TEWMA. Higher values mean wider bands and fewer trend flips, while lower values mean tighter bands and more frequent signals.
Specifications:
Weighted Moving Average (WMA)
The WMA gives more importance to recent price points while still considering past values. This makes it more responsive to recent moves than a Simple Moving Average (SMA).
Triple Exponential Moving Average (TEMA)
TEMA reduces lag by combining multiple layers of EMA calculations. Unlike a simple EMA, which can be slow to react, TEMA anticipates changes faster, while still maintaining smoothness to avoid false signals.
TEWMA (TEMA of WMA)
By applying TEMA on top of WMA, we create a hybrid smoothing technique. This retains the responsiveness of WMA but reduces its lag via TEMA’s structure. The result is a highly adaptive moving average, ideal for fast trend detection.
Average True Range (ATR)
ATR measures the degree of volatility by looking at the full trading range of each candle. It ensures that the Supertrend bands expand in volatile markets and contract in calm markets, keeping signals relevant to current conditions.
Supertrend Bands
The upper and lower envelopes built around TEWMA act as dynamic support and resistance. Their adaptive nature reduces false trend shifts during choppy sideways markets.
Band Adjustment Logic
Instead of recalculating bands every candle, the script uses a memory mechanism (previous values) to prevent unnecessary trend switches. This stabilizes the indicator and avoids excessive noise.
Trend Line
The final output is a line that follows price in trending phases while holding steady during consolidations. Its placement above or below price clearly signals bullish or bearish market structure.
Color Coding and Visuals
The use of shaded fills and line coloring enhances readability. Traders can quickly distinguish trend direction and momentum without deep numerical analysis.
Enjoy!
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.