Indicator · Pine Script v5 · On the chart

ENVELOPE - RSI - Buy Sell Signals

by saleh-ato· code credited to Saleh_Toodarvari

This indicator plots envelope bands based on a moving average or exponential moving average of a chosen price source.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code65
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago16 Jun 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

65 lines of Pine Script v5 from ENVELOPE RSI - Buy Sell Signals/Envelope-RSI.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Envelope-RSI.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Saleh_Toodarvari

//@version=5
indicator(title="ENVELOPE - RSI - Buy Sell Signals", shorttitle="ENVELOPE - RSI", overlay=true)
//_________________Envelope_________________
len = input.int(8, title="Envelope Length", minval=1, group="Envelope Settings")
percent = input(0.22,title="Envelope Percent", group="Envelope Settings")
src = input(hl2, title="Envelope Source", group="Envelope Settings")
exponential = input(false)
basis = exponential ? ta.ema(src, len) : ta.sma(src, len)
k = percent/100.0
upper = basis * (1 + k)
lower = basis * (1 - k)
plot(basis, "Basis", color=#ED7300)
u = plot(upper, "Upper", color=#FF2424)
l = plot(lower, "Lower", color=#24FF24)
fill(u, l, color=color.rgb(33, 150, 243, 95), title="Background")
cross_buy=ta.crossover(close,lower)
cross_sell=ta.crossunder(close,upper) 
// _________________RSI_________________
rsiLengthInput = input.int(8, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(hl2, "RSI Source", group="RSI Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
Overbought_RSI = input.price(title="RSI OverBought Limit(Recommended: 70-85)", defval=80, group="RSI Settings")
Oversold_RSI = input.price(title="RSI OverSold Limit(Recommended: 20-30)", defval=25, group="RSI Settings")
condition_buy= rsi<Oversold_RSI and (ta.cross(low,lower) or ta.cross(close,lower) or ta.cross(high,lower) or ta.cross(open,lower))
condition_sell= rsi>Overbought_RSI and (ta.cross(low,upper) or ta.cross(close,upper) or ta.cross(high,upper) or ta.cross(open,upper))
plotshape(cross_sell ? condition_sell:na, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white)
sell_sig=plot(cross_sell ? high:na,color=color.new(#000000,100))
plotshape(cross_buy ? condition_buy:na, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white)
buy_sig=plot(cross_buy ? ohlc4:na,color=color.new(#000000,100))
tpColor = if(cross_sell[1] or cross_sell[2] or cross_buy[1] or cross_buy[2])
    color.new(#1DBC60, 30)
else
    color.new(#000000,100)
slColor = if(cross_sell[1] or cross_sell[2] or cross_buy[1] or cross_buy[2])
    color.new(#F74A58, 30)
else
    color.new(#000000,100)
//_________________TP&SL_________________
TP_Percent = input.float(0.15, "TP %")
SL_Percent = input.float(0.15, "SL %")
tp= if condition_sell
    ohlc4-ohlc4*(TP_Percent/100)
else if condition_buy
    ohlc4+ohlc4*(TP_Percent/100)
sl= if condition_sell
    ohlc4+ohlc4*(SL_Percent/100)
else if condition_buy
    ohlc4-ohlc4*(SL_Percent/100)
tp_sig=plot(tp,color=color.new(#000000,100),title="tp")
sl_sig=plot(sl,color=color.new(#000000,100),title="tp")
lower_plot=plot(lower,color=color.new(#000000,100))
fill(sell_sig,tp_sig, color=tpColor)
fill(buy_sig,tp_sig, color=tpColor)
fill(buy_sig,sl_sig, color=slColor)
fill(sell_sig,sl_sig, color=slColor)
//_________________alerts_________________
alertConditionBuy=cross_buy and condition_buy
alertConditionSell=cross_sell and condition_sell
alertcondition(alertConditionBuy, title='Envelope RSI Buy signal!', message='Buy signal')
alertcondition(alertConditionSell, title='Envelope RSI Sell signal!', message='Sell signal')

Overview

ENVELOPE - RSI - Buy Sell Signals computes RSI with user-set length and source. Signals trigger on crossovers: buy when price crosses the lower envelope band while RSI falls below the oversold limit, sell when price crosses the upper envelope band while RSI exceeds the overbought limit. The script draws buy and sell labels on the price chart, plus TP and SL levels for each signal with color-coded fills. Main settings control envelope length, percent deviation, RSI length and levels, and TP and SL percentages. It draws everything directly on the price chart.

Details

Published by

saleh-ato on GitHub

Code credit

Saleh_Toodarvari, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Moving averages, Volatility & bands, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptindicatorpinescript-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Envelope Lengthint8len
Envelope Percentfloat0.22percent
Envelope Sourcesourcehl2src
exponentialboolfalseexponential
RSI Lengthint8rsiLengthInput
RSI Sourcesourcehl2rsiSourceInput
RSI OverBought Limit(Recommended: 70-85)price80Overbought_RSI
RSI OverSold Limit(Recommended: 20-30)price25Oversold_RSI
TP %float0.15TP_Percent
SL %float0.15SL_Percent
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Datsana V.1

by g-moe
3 stars

This indicator plots RSI divergence lines at resistance and support levels based on 14-period RSI crossing above 70 or below 30 within a search window of 141 bars. It displays dual EMA trend fill between periods 199 and 299, VWAP filter, TKPS tick pattern diam

Indicator v5 Oscillators & momentumMoving averages
Updated 5 months ago · None stated GitHub repository of Datsana V.1

Super Algo Setup [Aura]

by IAMATOMIC001
3 stars

This overlay indicator combines SuperTrend, RSI, MACD, and an EMA to mark labeled tops and bottoms on the price chart. Optional filters hide repeating signals and keep only relevant exits, and a Krypton fear-and-greed filter can limit bottoms and tops to overs

Indicator v5 Oscillators & momentumMoving averages
Updated 12 months ago · None stated GitHub repository of Super Algo Setup [Aura]
1 stars

US Momentum Swing Screener is a daily chart overlay indicator for US equities and ETFs. It plots a composite score based on an EMA ribbon (9/21/50/200), RSI and StochRSI momentum, MACD confluence, volume surge detection, ADX trend strength, Bollinger Band posi

Indicator v5 Oscillators & momentumMoving averages
Updated 4 months ago · None stated GitHub repository of US Momentum Swing Screener

Composite Market Bias

by mrme000m
1 stars

Composite Market Bias is a separate-pane indicator that scores bullish and bearish conditions from RSI, fast versus slow EMA, MACD histogram, Bollinger Band position, and price versus a 50-period EMA. It plots the resulting bias score with RSI, EMA trend, MACD

Indicator v5 Oscillators & momentumMoving averages
Updated 6 weeks ago · None stated GitHub repository of Composite Market Bias

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers