OPEN-SOURCE SCRIPT

(Mustang Algo) Stochastic RSI + Triple EMA

607
Stochastic RSI + Triple EMA (StochTEMA)

Overview
The Stochastic RSI + Triple EMA indicator combines the Stochastic RSI oscillator with a Triple Exponential Moving Average (TEMA) overlay to generate clear buy and sell signals on the price chart. By measuring RSI overbought/oversold conditions and confirming trend direction with TEMA, this tool helps traders identify high-probability entries and exits while filtering out noise in choppy markets.

Key Features
Stochastic RSI Calculation

Computes a standard RSI over a user-defined period (default 50).

Applies a Stochastic oscillator to the RSI values over a second user-defined period (default 50).

Smooths the %K line by taking an SMA over a third input (default 3), and %D is an SMA of %K over another input (default 3).

Defines oversold when both %K and %D are below 20, and overbought when both are above 80.

Triple EMA (TEMA)

Calculates three successive EMAs on the closing price with the same length (default 9).

Combines them using TEMA = 3×(EMA1 – EMA2) + EMA3, producing a fast-reacting trend line.

Bullish trend is identified when price > TEMA and TEMA is rising; bearish trend when price < TEMA and TEMA is falling; neutral/flat when TEMA change is minimal.

Signal Logic

Strong Buy: Previous bar’s Stoch RSI was oversold (both %K and %D < 20), %K crosses above %D, and TEMA is in a bullish trend.

Medium Buy: %K crosses above %D (without requiring oversold), TEMA is bullish, and previous %K < 50.

Weak Buy: Previous bar’s %K and %D were oversold, %K crosses above %D, TEMA is flat or bullish (not bearish).

Strong Sell: Previous bar’s Stoch RSI was overbought (both %K and %D > 80), %K crosses below %D, and TEMA is bearish.

Medium Sell: %K crosses below %D (without requiring overbought), TEMA is bearish, and previous %K > 50.

Weak Sell: Previous bar’s %K and %D were overbought, %K crosses below %D, TEMA is flat or bearish (not bullish).

Visual Elements on Chart

TEMA Line: Plotted in cyan (#00BCD4) with a medium-thick line for clear trend visualization.

Buy/Sell Markers:

BUY STRONG: Lime label below the candle

BUY MEDIUM: Green triangle below the candle

BUY WEAK: Semi-transparent green circle below the candle

SELL STRONG: Red label above the candle

SELL MEDIUM: Orange triangle above the candle

SELL WEAK: Semi-transparent orange circle above the candle

Candle & Background Coloring: When a strong buy or sell signal occurs, the candle body is tinted (semi-transparent lime/red) and the chart background briefly flashes light green (buy) or light red (sell).

Dynamic Support/Resistance:

On a strong buy signal, a green dot is plotted under that bar’s low as a temporary support marker.

On a strong sell signal, a red dot is plotted above that bar’s high as a temporary resistance marker.

Alerts

Strong Buy Alert: Triggered when Stoch RSI is oversold, %K crosses above %D, and TEMA is bullish.

Strong Sell Alert: Triggered when Stoch RSI is overbought, %K crosses below %D, and TEMA is bearish.

General Buy Alert: Triggered on any bullish crossover (%K > %D) when TEMA is not bearish.

General Sell Alert: Triggered on any bearish crossover (%K < %D) when TEMA is not bullish.

Inputs
Stochastic RSI Settings (group “Stochastic RSI”):

K (smoothK): Period length for smoothing the %K line (default 3, minimum 1)

D (smoothD): Period length for smoothing the %D line (default 3, minimum 1)

RSI Length (lengthRSI): Number of bars used for the RSI calculation (default 50, minimum 1)

Stochastic Length (lengthStoch): Number of bars for the Stochastic oscillator applied to RSI (default 50, minimum 1)

RSI Source (src): Price source for the RSI (default = close)

TEMA Settings (group “Triple EMA”):

TEMA Length (lengthTEMA): Number of bars used for each of the three EMAs (default 9, minimum 1)

How to Use
Add the Script

Copy and paste the indicator code into TradingView’s Pine Editor (version 6).

Save the script and add it to your chart as “Stochastic RSI + Triple EMA (StochTEMA).”

Adjust Inputs

Choose shorter lengths for lower timeframes (e.g., intraday scalping) and longer lengths for higher timeframes (e.g., swing trading).

Fine-tune the Stochastic RSI parameters (K, D, RSI Length, Stochastic Length) to suit the volatility of the instrument.

Modify TEMA Length if you prefer a faster or slower moving average response.

Interpret Signals

Primary Entries/Exits: Focus on “BUY STRONG” and “SELL STRONG” signals, as they require both oversold/overbought conditions and a confirming TEMA trend.

Confirmation Signals: Use “BUY MEDIUM”/“BUY WEAK” to confirm or add to an existing position when the market is trending. Similarly, “SELL MEDIUM”/“SELL WEAK” can be used to scale out or confirm bearish momentum.

Support/Resistance Dots: These help identify recent swing lows (green dots) and swing highs (red dots) that were tagged by strong signals—useful to place stop-loss or profit-target orders.

Set Alerts

Open the Alerts menu (bell icon) in TradingView, choose this script, and select the desired alert condition (e.g., “BUY Signal Strong”).

Configure notifications (popup, email, webhook) according to your trading workflow.

Notes & Best Practices
Filtering False Signals: By combining Stoch RSI crossovers with TEMA trend confirmation, most false breakouts during choppy price action are filtered out.

Timeframe Selection: This indicator works on all timeframes, but shorter timeframes may generate frequent signals—consider higher-timeframe confirmation when trading lower timeframes.

Risk Management: Always use proper position sizing and stop-loss placement. An “oversold” or “overbought” reading can remain extended for some time in strong trends.

Backtesting/Optimization: Before live trading, backtest different parameter combinations on historical data to find the optimal balance between sensitivity and reliability for your chosen instrument.

No Guarantee of Profits: As with any technical indicator, past performance does not guarantee future results. Use in conjunction with other forms of analysis (volume, price patterns, fundamentals).

Author: Your Name or Username
Version: 1.0 (Pine Script v6)
Published: June 2025

Feel free to customize input values and visual preferences. If you find bugs or have suggestions for improvements, open an issue or leave a comment below. Trade responsibly!

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.