Indicator · Pine Script v6 · On the chart

RSI Multi-Layer Entry Indicator

by Ahmed-GoCode· code credited to Ahmed - Quant-Edge Indicators

This overlay indicator calculates the 14-period Relative Strength Index to identify overbought and oversold market conditions.

View on GitHub

GitHub stars53on the repository
Pine versionv6current
Lines of code109
Settings0inputs
LicenceMPL-2.0
Last update2 months ago17 Aug 2026

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

109 lines of Pine Script v6 from Quant-Edge-Indicators/RSI & Momentum/RSI Multilayer Entry.pinescript, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

RSI Multilayer Entry.pinescript
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ahmed - Quant-Edge Indicators
//@version=6
indicator(title="RSI Multi-Layer Entry Indicator (With Position Tracking)", overlay=true)

// --- RSI Settings ---
rsiPeriod = 14
rsiOverbought = 70
rsiOversold = 30

// --- Trade Settings ---
SL = 3 //(USD , for Gold)
TP1 = 3
TP2 = 10
entryUnits = 5 // 5 usd for gold chart. when we have a buy piosition for examole, and price goes down more than 5, then it is used to open a second layer buy position.

// --- Variables ---
rsi = ta.rsi(close, rsiPeriod)
entryPrice = 0.0
entryDirection = 0 // 1 for buy, -1 for sell
positionSize = 0 // Tracks the size of the current position
entryBar = 0 // Bar index of the entry
positionType = "" // Tracks the type of the current position (e.g., "Long", "Short")

// --- Entry Logic ---
if (rsi > rsiOverbought and entryDirection == 0)
    entryPrice := close
    entryDirection := -1
    positionSize := 1 // Initial position size (the first position in a row, the first layer.)
    entryBar := bar_index
    positionType := "Short"
    label.new(bar_index, high, "Short Entry", color=color.red, style=label.style_label_down)

if (rsi < rsiOversold and entryDirection == 0)
    entryPrice := close
    entryDirection := 1
    positionSize := 1 // Initial position size (the first position in a row, the first layer.)
    entryBar := bar_index
    positionType := "Long"
    label.new(bar_index, low, "Long Entry", color=color.green, style=label.style_label_up)

// --- Multi-Layer Entry ---
if (entryDirection != 0)
    if (entryDirection == 1 and close < entryPrice - entryUnits and positionSize < 2) // Long entry, price moved down
        positionSize := positionSize + 1
        label.new(bar_index, low, "Long Entry (Layer 2)", color=color.green, style=label.style_label_up)
    if (entryDirection == -1 and close > entryPrice + entryUnits and positionSize < 2) // Short entry, price moved up
        positionSize := positionSize + 1
        label.new(bar_index, high, "Short Entry (Layer 2)", color=color.red, style=label.style_label_down)

// --- Exit Logic ---
if (positionType == "Long" and close >= entryPrice + TP1)
    positionSize := 0 // Reset position size
    label.new(bar_index, high, "TP1 Long Hit", color=color.red, style=label.style_label_up)
    entryDirection := 0 // Reset entry direction

if (positionType == "Long" and close >= entryPrice + TP2)
    positionSize := 0 // Reset position size
    label.new(bar_index, high, "TP2 Long Hit", color=color.red, style=label.style_label_up)
    entryDirection := 0 // Reset entry direction

if (positionType == "Long" and close <= entryPrice - SL)
    positionSize := 0 // Reset position size
    label.new(bar_index, low, "SL Long Hit", color=color.red, style=label.style_label_up)
    entryDirection := 0 // Reset entry direction

if (positionType == "Short" and close <= entryPrice - TP1)
    positionSize := 0 // Reset position size
    label.new(bar_index, low, "TP1 Short Hit", color=color.green, style=label.style_label_down)
    entryDirection := 0 // Reset entry direction

if (positionType == "Short" and close <= entryPrice - TP2)
    positionSize := 0 // Reset position size
    label.new(bar_index, low, "TP2 Short Hit", color=color.green, style=label.style_label_down)
    entryDirection := 0 // Reset entry direction

if (positionType == "Short" and close >= entryPrice + SL)
    positionSize := 0 // Reset position size
    label.new(bar_index, high, "SL Short Hit", color=color.green, style=label.style_label_down)
    entryDirection := 0 // Reset entry direction

// --- TP/SL Levels ---
if (entryDirection != 0)
    if (entryDirection == 1) // Long
        var TP1Line = line.new(bar_index, entryPrice + TP1, bar_index, entryPrice + TP1, color=color.green, width=2, style = line.style_dashed) //title="TP1 Long"
        var TP2Line = line.new(bar_index, entryPrice + TP2, bar_index, entryPrice + TP2, color=color.green, width=2, style = line.style_dashed) //title="TP2 Long"
        var SLLine = line.new(bar_index, entryPrice - SL, bar_index, entryPrice - SL, color=color.green, width=2, style = line.style_dashed) //title="SL Long"
    else // Short
        var TP1Line = line.new(bar_index, entryPrice - TP1, bar_index, entryPrice - TP1, color=color.red, width=2, style=line.style_dashed) //title="TP1 Short"
        var TP2Line = line.new(bar_index, entryPrice - TP2, bar_index, entryPrice - TP2, color=color.red, width=2, style=line.style_dashed) //title="TP2 Short"
        var SLLine = line.new(bar_index, entryPrice + TP1, bar_index, entryPrice + TP1, color=color.red, width=2, style=line.style_dashed) //title="SL Short"

// --- Plot RSI ---
plot(rsi, color=color.blue, linewidth=2, title="RSI")
hline(rsiOverbought, color=color.red, linestyle=hline.style_dashed)
hline(rsiOversold, color=color.red, linestyle=hline.style_dashed)


//**Explanation of Changes:**

//- **`positionSize`:** Added a variable to track the size of the current position.
//- **`entryBar`:** Added a variable to store the bar index of the entry.
//- **`positionType`:** Added a variable to store the type of the current position (e.g., "Long", "Short").
//- **Tracking Position Size:** 
//    - `positionSize` is initialized to 1 when a new position is opened.
//    - It's increased by 1 when a multi-layer entry is triggered.
//    - It's reset to 0 when the position is closed (TP or SL hit).
//- **Exit Logic:** The `if` conditions now check for TP1/TP2/SL hits based on the `positionType` and `positionSize` to determine whether the position should be closed.
//- **Label Updates:** The label text now includes information about the TP/SL hit and the position size.

Overview

When RSI crosses key thresholds, it plots initial long or short entry labels directly on the price chart. If price continues moving against the position by a defined distance, the script triggers a second entry layer. It internally tracks open position status and marks take-profit and stop-loss exits with visual chart labels.

Details

Published by

Ahmed-GoCode on GitHub

Code credit

Ahmed - Quant-Edge Indicators, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Oscillators & momentum, Mean reversion

Markets

Gold

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

fair-value-gapfibonaccimarket-structurepine-scriptrsi-strategysmart-money-conceptstechnical-analysistradingviewalgorithmic-tradingcrypto-trading

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

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]
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study
147 stars

This indicator combines Bollinger Bands, RSI, Stochastic RSI, and volume spike detection to identify mean-reversion conditions during range-bound market regimes. It calculates Bollinger Band width to identify low-volatility states and triggers buy or sell sign

Indicator v5 Oscillators & momentumVolatility & bands
Updated 6 weeks ago · MIT GitHub repository of BTC Dec 2025 — Range + Gamma Flush

RSI Technique - V

by Tikam02
20 stars

RSI Technique - V identifies rapid reversal pivot points based on the Relative Strength Index. It monitors an RSI oscillator, configurable via the lookback setting, looking for sharp V-shaped spikes around extreme zones. A bullish signal appears when the indic

Indicator v5 Oscillators & momentumMean reversion
Updated 2 years ago · Apache-2.0 GitHub repository of RSI Technique - V

Commodity Heat Reversal plots score-based mean-reversion reversal markers on the price chart for commodity futures, aimed at the four-hour timeframe. It builds separate long and short heat scores from ATR distance to a mean moving average, ATR expansion, RSI e

Indicator v6 Mean reversionVolatility & bands
Updated yesterday · MIT GitHub repository of Commodity Heat Reversal [WavesUnchained]
8 stars

This indicator detects contrarian inflection points and potential market reversals by combining sentiment, volume, and price action metrics directly on the price chart. It evaluates overbought and oversold conditions with the RSI and Stochastic oscillators, hi

Indicator v5 Oscillators & momentumVolatility & bands
Updated 7 weeks ago · None stated GitHub repository of GCR Inflection Point Scanner

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