Indicator · Pine Script v5 · On the chart

MACD & RSI Overlay (Expo)

by theonetrade· code credited to Zeiierman

MACD & RSI Overlay (Expo) projects MACD, RSI, or both directly onto the main price chart rather than in a separate pane.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code100
Settings15inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

100 lines of Pine Script v5 from assets/indicator/bit-exact/macd_rsi_overlay_expo_iOi1pXOX.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

macd_rsi_overlay_expo_iOi1pXOX.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Zeiierman

//@version=5
indicator('MACD & RSI Overlay (Expo)', overlay=true)

// ~~ ToolTips {
t1 = "Select if you want to display MACD [12,26] or RSI [14] or both at the same time on your chart."
t2 = "Set the smoothing length"
t3 = "Set the signal line length"
t4 = "Increase this value if you want to factor in the underlying trend. A high value returns a long-term underlying trend and a low value returns the short-term underlying trend."
t5 = "The scale refers to how far or close the MACD and RSI lines should be relative to the price. A higher scale means that the lines should be further away from the price, while a lower scale means that the lines should be closer to the price"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Input variables {
//MACD & RSI
macd_rsi           = input.string("MACD", title="", options=["MACD","RSI 14", "Both"], group="MACD/RSI", inline="macdrsi", tooltip = t1)
macd_rsi_smooth    = input.int(1, minval=1, maxval=200, step=1, title="Smooth", group="MACD/RSI", inline="macdrsi", tooltip = t2)
signal_line_Length = input.int(14, minval=5, maxval=200, step=1, title="Signal Length", group="MACD/RSI", inline="macdrsi", tooltip = t3)
macd_col           = input.color(color.aqua, title="MACD Line", group="MACD/RSI", inline="col")
rsi_col            = input.color(color.rgb(19, 96, 238), title="RSI Line", group="MACD/RSI", inline="col")
signal_line_col    = input.color(#F8DE7E, title="Signal Line", group="MACD/RSI", inline="col")
ob                 = input.int(70, minval=0, maxval=100, title="", group="RSI OB/OS", inline="obos_col")
os                 = input.int(30, minval=0, maxval=100, title="", group="RSI OB/OS", inline="obos_col") 
ob_col             = input.color(color.lime, title="", group="RSI OB/OS", inline="obos_col")
os_col             = input.color(color.red, title="", group="RSI OB/OS", inline="obos_col")

//Scaling
trendFactor   = input.int(30, minval=1, maxval=300, step=2, title="Trend Factor", group="Trend Feature", tooltip = t4)
scalingFactor = input.float(2.5, step=0.1, maxval=10, title="Scaling Factor", group="Scaling", tooltip = t5)

//Table
showTable   = input.bool(true,title="Show Trend Table", inline="tbl", group="Trend Table")
TblSize     = input.string(size.normal,title="Size",options=[size.auto,size.tiny,size.small,size.normal,size.large,size.huge],inline="tbl")
pos         = input.string(position.top_right, title="Location",options =[position.top_right,position.top_center,
 position.top_left,position.bottom_right,position.bottom_center,position.bottom_left,position.middle_right,position.middle_left],inline="tbl")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Moving Averages {
priceMa = ta.sma(close, 2)
trendMa = ta.sma(close, trendFactor)

//Calculate Scaled Adaptive Moving Average
error    = math.abs(priceMa - trendMa)
errorSum = math.sum(error, 10)
ama      = errorSum == 0 ? close[1] : priceMa * (error / errorSum) + trendMa * (1 - error / errorSum)
pma      = scalingFactor * close + (1.0 - scalingFactor) * ama[1]

//Averages
macd   = ta.wma(ta.rma(pma, 5),macd_rsi_smooth)
rsi    = ta.wma(ta.rma(pma, 1),macd_rsi_smooth)
signal = ta.sma(pma, signal_line_Length)

//OB/OS color
rsi_ = ta.rsi(close,14)
rsi_col_ = rsi_>ob?ob_col:rsi_<os?os_col:rsi_col

//Plots
plot(macd_rsi=="MACD" or macd_rsi=="Both"?macd:na,color=color.new(macd_col, 0), title='MACD Line')
plot(macd_rsi=="RSI 14" or macd_rsi=="Both"?rsi:na,color=color.new(rsi_col_, 0), title='RSI Line')
plot(signal, color=color.new(signal_line_col, 0), title='Signal Line')
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Table {
string h1 = switch macd_rsi
    "MACD"   => "MACD: "+(macd>close?"Bullish":"Bearish")
    "RSI 14" => "RSI: "+(close<rsi?"Bullish":"Bearish")
    "Both"   => "MACD: "+(macd>close?"Bullish":"Bearish")+
     "\nRSI: "+(close<rsi?"Bullish":"Bearish")

//Plot Table
var tbl = table.new(pos, 1, 1, frame_color=chart.bg_color, frame_width=2, border_width=2, border_color=chart.bg_color)
color trend_col = str.contains(h1,"Bullish") and str.contains(h1,"Bearish")?color.orange:str.contains(h1,"Bullish")?color.lime:color.red
if barstate.islast and showTable
    table.cell(tbl, 0, 0, text=h1, text_color=color.white, bgcolor=color.new(trend_col,30), text_size=TblSize)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Alerts {
indicatorcross(indicator) =>
    over  = ta.crossover(indicator,signal)
    under = ta.crossunder(indicator,signal)
    [over,under]
srccross(src,indicator) =>
    over  = ta.crossover(src,indicator)
    under = ta.crossunder(src,indicator)
    [over,under]    

[over_macd,under_macd] = indicatorcross(macd)   
[over_rsi,under_rsi]   = indicatorcross(rsi)   

[over_macd_price,under_macd_price] = srccross(close,macd) 
[over_rsi_price,under_rsi_price]   = srccross(close,rsi) 
[over_rsi_macd,under_rsi_macd]     = srccross(rsi,macd) 

alertcondition(over_macd, title="MACD Crosses Over Signal Line", message="MACD Crosses Over Signal Line"),alertcondition(under_macd, title="MACD Crosses Under Signal Line", message="MACD Crosses Under Signal Line")
alertcondition(over_rsi, title="RSI Crosses Over Signal Line", message="RSI Crosses Over Signal Line"),alertcondition(under_rsi, title="RSI Crosses Under Signal Line", message="RSI Crosses Under Signal Line")
alertcondition(over_macd_price, title="Close Crosses Over MACD", message="Close Crosses Over MACD"),alertcondition(under_macd_price, title="Close Crosses Under MACD", message="Close Crosses Under MACD")
alertcondition(over_rsi_price, title="Close Crosses Over RSI", message="Close Crosses Over RSI"),alertcondition(under_rsi_price, title="Close Crosses Under RSI", message="Close Crosses Under RSI")
alertcondition(over_rsi_macd, title="RSI Crosses Over MACD", message="RSI Crosses Over MACD"),alertcondition(under_rsi_macd, title="RSI Crosses Under MACD", message="RSI Crosses Under MACD")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

Overview

MACD & RSI Overlay (Expo) calculates a scaled adaptive moving average based on a user-defined trend factor and scaling factor to align momentum indicator lines relative to price movement. Users can switch between MACD, RSI, or dual display, adjust smoothing and signal lengths, and set overbought/oversold color thresholds. An optional on-chart trend table dashboard provides additional market context.

Details

Published by

theonetrade on GitHub

Code credit

Zeiierman, as written in the script's header

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
macd_rsistringMACDmacd_rsi
Smoothint1macd_rsi_smooth
Signal Lengthint14signal_line_Length
MACD Linecolorcolor.aquamacd_col
RSI Linecolorcolor.rgb(19, 96, 238)rsi_col
Signal Linecolor#F8DE7Esignal_line_col
obint70ob
osint30os
ob_colcolorcolor.limeob_col
os_colcolorcolor.redos_col
Trend Factorint30trendFactor
Scaling Factorfloat2.5scalingFactor
Show all 15 settings
SettingTypeDefaultVariable
Show Trend TablebooltrueshowTable
Sizestringsize.normalTblSize
Locationstringposition.top_rightpos
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

228 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 4 months ago · None stated GitHub repository of TradersPost Trading Checklist
53 stars

This indicator analyzes historical candle direction and price range over a configurable lookback window to gauge market trend. It categorizes trend direction using candle count, price range sum, or both. Signals are filtered using a Simple Moving Average to en

Indicator v6 TrendOscillators & momentum
Updated 3 months ago · MPL-2.0 GitHub repository of Candle Counter + MA + RSI + Mode

Trend Hub

by Matswm86
29 stars

Trend Hub is a multi-timeframe contextual HUD panel that displays trend direction, strength, and momentum states across three timeframes directly on the price chart. Built around L.A. Little's qualified-trend model, it calculates market trends using swing poin

Indicator v6 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Trend Hub

Pocket Scout - SPY/QQQ

by chris-c-thomas
13 stars

Pocket Scout - SPY/QQQ is a mobile-optimized intraday bias indicator designed for major US equity ETFs and indices. It overlays a 9/21/50 EMA ribbon, session VWAP, prior day high/low/close levels, and intraday high/low lines directly on the main price chart. T

Indicator v6 TrendOscillators & momentum Repaints
Updated 7 months ago · MIT GitHub repository of Pocket Scout - SPY/QQQ

Portfolio Backtester

by f-cksociety
11 stars

The script is a Pine Script v5 indicator that emulates strategy backtesting directly on the price chart. It evaluates modular entry strategies, trade directions, entry stop-loss types such as ATR multiples or fixed percentages, and a wide variety of trade filt

Indicator v5 TrendOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of Portfolio Backtester

Vein: Pullback identifies temporary counter-trend retracements and signals when they end versus when structure breaks. It calculates a multi-layer confluence score from 0 to 10 based on trend quality, move weakness, structure preservation, and Fibonacci retrac

Indicator v6 TrendOscillators & momentum
Updated 4 weeks ago · MIT GitHub repository of Vein: Pullback [WavesUnchained]

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers