Indicator · Pine Script v5 · Own pane

RSI Swing Signal

by Web3Degenerate· code credited to ZenAndTheArtOfTrading / www.PineScriptMastery.com

This indicator plots an RSI oscillator in a separate pane and marks long and short setups when RSI is oversold or overbought and a swing low or swing high fractal forms with a reversing candle.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code80
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago13 Sep 2024

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

80 lines of Pine Script v5 from advanced-pine-script/15.Pine-Script-Updates/14.April-2024-Split-Plots-force_overlay.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

14.April-2024-Split-Plots-force_overlay.pine
// This  demonstrates how to use the new force_overlay parameter added in April, which allows us to force certain plot functions to draw directly over the chart even if they're called from a separate window (like an oscillator for example).

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ZenAndTheArtOfTrading / www.PineScriptMastery.com
// @version=5
indicator(title="RSI Swing Signal", shorttitle="RSI+", overlay=false)

// Stops & target settings
stopLossInput   = input.float(title="Stop Loss Size (x ATR)", defval=1.0, group="Trade Settings")
riskToRewardBE  = input.float(title="Reward To Risk Ratio (B/E)", defval=0.8, group="Trade Settings")
riskToReward    = input.float(title="Reward:Risk Ratio", defval=1.0, group="Trade Settings")
showBE          = input.bool(title="Show B/E Point", defval=false, group="Trade Settings")

// Indicator settings
lookback        = input(title="Lookback:", defval=7, group="Indicator Settings")
rsiOB           = input(title="RSI Overbought Level:", defval=80, group="Indicator Settings")
rsiOS           = input(title="RSI Oversold Level:", defval=20, group="Indicator Settings")
rsiLen          = input(title="RSI Length:", defval=7, group="Indicator Settings")
rsiSrc          = input(title="RSI Source:", defval=close, group="Indicator Settings")
drawRT          = input.bool(title="Draw Signals On Real-Time Bars", defval=true, group="Indicator Settings")

// Get RSI value
rsi = ta.rsi(rsiSrc, rsiLen)
rsisell = rsi > rsiOB
rsibuy = rsi < rsiOS

// Calculate non-EAP stop loss size
currentATR = ta.atr(14)
stopSize = currentATR * stopLossInput

// Determine buy/sell signals
buysignal1 = (rsibuy or rsibuy[1]) and close[1] < open[1] and close > open[1] and low > low[1] and low[1] < low[2] and low[1] == ta.lowest(low, lookback) and open <= close[1]
buysignal2 = (rsibuy or rsibuy[1]) and close[1] < open[1] and close > open[1] and low < low[1] and low == ta.lowest(low, lookback) and open <= close[1]
sellsignal2 = (rsisell or rsisell[1]) and close[1] > open[1] and close < open[1] and high > high[1] and high == ta.highest(high, lookback) and open >= close[1]
sellsignal1 = (rsisell or rsisell[1]) and close[1] > open[1] and close < open[1] and high < high[1] and high[1] > high[2] and high[1] == ta.highest(high, lookback) and open >= close[1]

// Calculate stop loss distance in pips
longEntrySize = close - ta.lowest(low, 3) + stopSize
shortEntrySize = ta.highest(high, 3) - close + stopSize

// Prepare stop and target values
var tradeStopPrice = 0.0
var tradeTargetPrice = 0.0
var tradeBreakEvenPrice = 0.0
validLong = buysignal1 or buysignal2
validShort = sellsignal1 or sellsignal2

// Store long position info
if validLong
    tradeStopPrice := close - longEntrySize
    tradeTargetPrice := close + longEntrySize * riskToReward
    tradeBreakEvenPrice := close + longEntrySize * riskToRewardBE
// Store short position info
if validShort
    tradeStopPrice := close + shortEntrySize
    tradeTargetPrice := close - shortEntrySize * riskToReward
    tradeBreakEvenPrice := close - shortEntrySize * riskToRewardBE

//! PAINT OSCILLATOR
bgcolor(buysignal1 ? color.lime : sellsignal1 ? color.red : na, title="123 Fractal")
bgcolor(buysignal2 ? color.lime : sellsignal2 ? color.red : na, title="Swing Fractal")
plot(rsi, title="RSI", color=rsisell ? color.red : rsibuy ? color.lime : #4985e7, linewidth=2)
plot(rsiOB, title="RSI Overbought", color=color.new(color.red, 0))
plot(rsiOS, title="RSI Oversold", color=color.new(color.green, 0))

//! PAINT OVERLAY
// Plot candlestick pattern signals  
plotshape(validLong and (barstate.ishistory or drawRT), title="Bullish Engulfing", location=location.belowbar, color=color.green, style=shape.triangleup, text="", force_overlay=true)
plotshape(validShort and (barstate.ishistory or drawRT), title="Bearish Engulfing", location=location.abovebar, color=color.red, style=shape.triangledown, text="", force_overlay=true)

// Draw stops & targets
plot(validLong or validLong[1] ? tradeStopPrice : na, title="Long Stop Price", color=color.red, style=plot.style_linebr, force_overlay=true)
plot(validShort or validShort[1] ? tradeStopPrice : na, title="Short Stop Price", color=color.red, style=plot.style_linebr, force_overlay=true)
plot(validLong or validLong[1] ? tradeTargetPrice : na, title="Long Target Price", color=color.green, style=plot.style_linebr, force_overlay=true)
plot(validShort or validShort[1] ? tradeTargetPrice : na, title="Short Target Price", color=color.green, style=plot.style_linebr, force_overlay=true)
plot((validLong or validLong[1]) and showBE ? tradeBreakEvenPrice : na, title="Long Break-Even Price", color=color.blue, style=plot.style_linebr, force_overlay=true)
plot((validShort or validShort[1]) and showBE ? tradeBreakEvenPrice : na, title="Short Break-Even Price", color=color.blue, style=plot.style_linebr, force_overlay=true)

// Send out an alert if this candle meets our conditions
alertcondition(sellsignal1 or sellsignal2 or buysignal1 or buysignal2, title="RSI SIGNAL", message="RSI Exhaustion signal for {{ticker}}")

Overview

RSI Swing Signal sizes a stop from the recent extreme plus an ATR multiple, then stores a target and optional break-even price from the reward-to-risk inputs. Lookback, RSI length, source, and extreme levels change the signal. It is an indicator, so it does not place trades.

Details

Published by

Web3Degenerate on GitHub

Code credit

ZenAndTheArtOfTrading / www.PineScriptMastery.com, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Candlestick patterns, Mean reversion

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.

Settings

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

SettingTypeDefaultVariable
Stop Loss Size (x ATR)float1.0stopLossInput
Reward To Risk Ratio (B/E)float0.8riskToRewardBE
Reward:Risk Ratiofloat1.0riskToReward
Show B/E PointboolfalseshowBE
Lookback:int7lookback
RSI Overbought Level:int80rsiOB
RSI Oversold Level:int20rsiOS
RSI Length:int7rsiLen
RSI Source:sourceclosersiSrc
Draw Signals On Real-Time BarsbooltruedrawRT
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

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
261 stars

This indicator calculates standardized z-scores of price data across four different lookback periods (6, 14, 26, and 100). Standardizing data subtracts the moving average from the price and divides by the standard deviation. It applies a Double Exponential Mov

Indicator v5 Mean reversionVolatility & bands

Commitment Gauge

by harryguiacorn
219 stars

This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete

Indicator v4 VolumeCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Commitment Gauge
114 stars

This indicator calculates normalized percentage bounds around price highs and lows to anticipate local trend reversals. It oscillates within a fixed -1 to 1 channel and plots two boundary tracking curves alongside a background Karobein oscillator histogram for

Indicator v4 Mean reversionOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Mean Reversion Indicator
99 stars

This indicator calculates the statistical autocorrelation coefficient of an input series over a user-defined lookback window at a specified lag. It tracks values using an internal circular buffer, computes sample mean, variance, and autocovariance, and normali

Indicator v6 TrendMean reversion
Updated 4 weeks ago · Apache-2.0 GitHub repository of Autocorrelation Function (ACF)

Pretty Good Oscillator

by mihakralj
47 stars

The Pretty Good Oscillator calculates the distance between the selected price source and its simple moving average, normalized by the Average True Range over a specified period. It renders as an oscillator line in a separate pane alongside a zero line and thre

Indicator v6 Oscillators & momentumMean reversion
Updated 8 months ago · MIT GitHub repository of Pretty Good Oscillator

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