Indicator · Pine Script v6 · On the chart

MA/EMA + RSI Trend & Pullback

by PlasmaZero

The MA/EMA + RSI Trend & Pullback indicator combines moving averages with the RSI oscillator to determine trend direction and identify pullback opportunities for entries and exits.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code158
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update11 months ago12 Nov 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

158 lines of Pine Script v6 from ma_ema_rsi_trend_pullback.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

ma_ema_rsi_trend_pullback.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PlasmaZero

//@version=6
indicator("MA/EMA + RSI Trend & Pullback", overlay=true, max_labels_count=500)

// INPUTS //
src      = input.source(close, "Source")
maType   = input.string("EMA", "MA Type", options = ["EMA", "SMA"])
fastLen  = input.int(21, "Fast MA Length", minval = 1)
slowLen  = input.int(50, "Slow MA Length", minval = 1)
rsiLen   = input.int(14, "RSI Length", minval = 1)
rsiOB    = input.float(65.0, "RSI Overbought Level", minval = 50, maxval = 100)
rsiOS    = input.float(35.0, "RSI Oversold Level", minval = 0, maxval = 50)
rsiMid   = input.float(50.0, "RSI Midpoint", minval = 30, maxval = 70)

// Entry Mode Selection //
// Lets user pick how entries are generated:
// Only RSI crossovers, RSI + MA pullbacks, or a combination of several signal types.
// Default: "Multiple Signals".
entryMode = input.string("Multiple Signals", "Entry Mode", 
     options = ["RSI Crossover Only", "RSI Zone + MA", "Multiple Signals"])

// Moving Averages //
ma(src, length) =>
    maType == "EMA" ? ta.ema(src, length) : ta.sma(src, length)

fastMA = ma(src, fastLen)
slowMA = ma(src, slowLen)

// Trend Definition //
upTrend   = fastMA > slowMA //true when fast MA is above slow MA.
downTrend = fastMA < slowMA //true when fast MA is below slow MA.
trendJustChanged = (upTrend and not upTrend[1]) or (downTrend and not downTrend[1]) //Checks if we just flipped trend on the given bar 
// meaning did we enter an uptrend/downtrend where trend saw a flip from previous bar.

// RSI //
rsi = ta.rsi(src, rsiLen)
rsiInOversold  = rsi < rsiOS //true when RSI is below oversold level
rsiInOverbought = rsi > rsiOB //true when RSI is above overbought level.
rsiRising = rsi > rsi[1]//RSI is higher than previous bar indicates upward momentum.
rsiFalling = rsi < rsi[1]//RSI is lower than previous bar indicates downward momentum.

// Entry Signals //
// Type 1: RSI Crossover (the most strict condition (least number of signals)
longCross  = ta.crossover(rsi, rsiOS)//RSI crosses up through oversold level (coming out of oversold).
shortCross = ta.crossunder(rsi, rsiOB)//RSI crosses down through overbought level (coming down from overbought)

// Type 2: RSI in zone + price pullback to MA
pricePullbackLong  = upTrend and close < fastMA and close > slowMA and rsi < rsiMid //Only in upTrend, price pulled back below fastMA, but still above slowMA, RSI below mid
pricePullbackShort = downTrend and close > fastMA and close < slowMA and rsi > rsiMid //Only in downTrend, price pulled back above fastMA, but still below slowMA, RSI above mid

// Type 3: New trend + favorable RSI
newUpTrend   = upTrend and not upTrend[1] and rsi > rsiMid //trend flipped to uptrend with RSI being bullish
newDownTrend = downTrend and not downTrend[1] and rsi < rsiMid //trend flipped to downtrend with RSI being bearish

// Type 4: RSI momentum shift in trend
rsiMomentumLong  = upTrend and rsiRising and rsi[1] < rsiMid and rsi > rsiMid //uptrend with rising RSI with a cross from below midpoint to above midpoint -> bullish shift
rsiMomentumShort = downTrend and rsiFalling and rsi[1] > rsiMid and rsi < rsiMid //downtrend with falling RSI with a cross from above midpoint to below -> bearish shift

// Combine based on selected mode
longSignal = switch entryMode
    "RSI Crossover Only" => upTrend and longCross
    "RSI Zone + MA"      => upTrend and (longCross or pricePullbackLong)
    "Multiple Signals"   => upTrend and (longCross or pricePullbackLong or newUpTrend or rsiMomentumLong)
    => false

shortSignal = switch entryMode
    "RSI Crossover Only" => downTrend and shortCross
    "RSI Zone + MA"      => downTrend and (shortCross or pricePullbackShort)
    "Multiple Signals"   => downTrend and (shortCross or pricePullbackShort or newDownTrend or rsiMomentumShort)
    => false

// POSITION TRACKING //
var int position = 0  // 0 = flat, 1 = long, -1 = short
//flat means no position as it indicates a consolidation period. Good for iron condors via options

// Exit conditions - calculate crossovers first for consistency
rsiCrossUnderOB = ta.crossunder(rsi, rsiOB)
rsiCrossOverOS = ta.crossover(rsi, rsiOS)

// Check for exit signals
longExitSignal  = position == 1 and (rsiCrossUnderOB or downTrend)//RSI crosses down through overbought level.
shortExitSignal = position == -1 and (rsiCrossOverOS or upTrend)//RSI crosses up through oversold level.

// Check for entry signals after considering exits
longEntrySignal  = longSignal and position <= 0  //Enter if flat or in short
shortEntrySignal = shortSignal and position >= 0  //Enter if flat or in long

// Exits take priority as we must first exit a position to enter a new one 
bool longEntry = false
bool shortEntry = false
bool longExit = false
bool shortExit = false

// Handle position changes with exit priority
if longExitSignal
    longExit := true
    position := 0
else if shortExitSignal
    shortExit := true
    position := 0
else if longEntrySignal and position != 1
    longEntry := true
    position := 1
else if shortEntrySignal and position != -1
    shortEntry := true
    position := -1
//Exit first then look to enter a new long/short position

// PLOTS //
// MAs on chart
plot(fastMA, title="Fast MA", color=color.new(color.green, 0), linewidth=2)
plot(slowMA, title="Slow MA", color=color.new(color.blue, 0), linewidth=2)

// Trend shading
// bgcolor(upTrend ? color.new(color.lime, 90) : na, title="Uptrend Background") //optional if you want to see trend as a background
// bgcolor(downTrend ? color.new(color.red, 90) : na, title="Downtrend Background")

// RSI ON CHART //
// Plot RSI as overlay on price chart
// You can also add RSI as a separate indicator if preferred
// plot(rsi, title="RSI", color=color.new(color.blue, 0), linewidth=1)
// hline(rsiOB, "RSI Overbought", color=color.new(color.red, 50))
// hline(rsiOS, "RSI Oversold",   color=color.new(color.lime, 50))
// hline(rsiMid, "RSI Midpoint",  color=color.new(color.gray, 70), linestyle=hline.style_dotted)

// SIGNAL MARKERS //
plotshape(longEntry,  title="Long Entry",  location=location.belowbar,
     style=shape.triangleup,   size=size.small, color=color.new(color.lime, 0), text="LONG")
plotshape(longExit,   title="Long Exit",   location=location.abovebar,
     style=shape.xcross,       size=size.small, color=color.new(color.orange, 0), text="EXIT")
plotshape(shortEntry, title="Short Entry", location=location.abovebar,
     style=shape.triangledown, size=size.small, color=color.new(color.red, 0), text="SHORT")
plotshape(shortExit,  title="Short Exit",  location=location.belowbar,
     style=shape.xcross,       size=size.small, color=color.new(color.orange, 0), text="EXIT")

// LABELS //
// Show current position status
var label posLabel = na
label.delete(posLabel)
posText = position == 1 ? "LONG" : position == -1 ? "SHORT" : "FLAT"
posColor = position == 1 ? color.lime : position == -1 ? color.red : color.gray
posLabel := label.new(bar_index, high, posText, 
     color=color.new(posColor, 70), 
     textcolor=color.white, 
     style=label.style_label_down,
     size=size.small)

//ALERTS //
alertcondition(longEntry,  title="Long Entry",  
     message="LONG ENTRY")
alertcondition(longExit,   title="Long Exit",           
     message="LONG EXIT")
alertcondition(shortEntry, title="Short Entry", 
     message="SHORT ENTRY")
alertcondition(shortExit,  title="Short Exit",          
     message="SHORT EXIT")

Overview

MA/EMA + RSI Trend & Pullback plots fast and slow MAs on the price chart along with the RSI, and applies background shading to show uptrends, downtrends, and current long or short positions. The script offers three entry modes—RSI crossover only, RSI zone plus MA, and multiple signals—allowing users to adjust signal strictness. Main settings include the source, MA type (EMA or SMA), lengths for fast and slow MAs, RSI length and levels, and entry mode selection. It draws signals directly on the chart with labels for long, short, and exit.

Details

Published by

PlasmaZero on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages

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
Sourcesourceclosesrc
MA TypestringEMAmaType
Fast MA Lengthint21fastLen
Slow MA Lengthint50slowLen
RSI Lengthint14rsiLen
RSI Overbought Levelfloat65.0rsiOB
RSI Oversold Levelfloat35.0rsiOS
RSI Midpointfloat50.0rsiMid
Entry ModestringMultiple SignalsentryMode
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

948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average
218 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 3 months ago · None stated GitHub repository of TradersPost Trading Checklist

Daily Trend Filter

by agutinbaigo28
147 stars

Calculates market regime conditions by combining RSI, MACD, and ADX/DMI indicators. It evaluates whether the market is in a strong bullish, strong bearish, neutral, or non-trending regime. The script plots a colored line overlaying the close price to reflect t

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Daily Trend Filter

AAPP

by capissimo
114 stars

This indicator plots an adaptive moving average or scaled RSI divergence line directly on the price chart. It calculates dual RSI series to measure momentum divergence, scales the values to the chart's price range, and constructs an adaptive average filtered b

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of AAPP

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Signal Strategy 15m
56 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision

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