Indicator · Pine Script v4 · On the chart

Combined Stochastic & RSI & MACD Signal

by Crypto-Adhyeta

This indicator combines the Stochastic oscillator, Relative Strength Index (RSI), and MACD to detect aligned momentum signals.

View on GitHub

GitHub stars6on the repository
Pine versionv4older, still runs
Lines of code89
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update5 years ago6 Jun 2021

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

89 lines of Pine Script v4 from Combined Stoch_RSI_MACD Long_Short.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Combined Stoch_RSI_MACD Long_Short.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Crypto_Adhyeta
//script inspiration by DataTrader video https://www.youtube.com/watch?v=hh3BKTFE1dc

//@version=4
study(title="Combined Stochastic & RSI & MACD signal", shorttitle="Signal Stoch+RSI+MACD", format=format.price, precision=2, overlay=true)      //1st option: Displays marks when Long/Short alert is fired in the chart
//study(title="Combined Stochastic & RSI & MACD signal", shorttitle="Signal Stoch+RSI+MACD", format=format.price, precision=2, overlay=false)   //2nd option: Displays curves of each indicator and the combined signal
                                                                                                                                                //curve under the chart

//inputs
//***Stochastic
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
//***MACD
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
srcMACD = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Oscillator: 1 - SMA / 0 - EMA", type=input.bool, defval=false)
sma_signal = input(title="Signal Line:  1 - SMA / 0 - EMA", type=input.bool, defval=false)

//variables
stateStoch = 0
stateRSI = 0
stateMACD =  0
stateCOMBINED = 0

//Built-In Stochastic
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
if (crossover(k, 20))
    stateStoch := 1
else
    if stateStoch[1] == 1 and k > 20 and k < 80 
        stateStoch := 1
    else
        stateStoch := 0
if stateStoch == 0 and crossunder(k, 80)
    stateStoch := -1
else
    if stateStoch[1] == -1 and k < 80 and k > 20
        stateStoch := -1

//Built-In RSI
myRSI=rsi(close, periodK)
if myRSI > 50
    stateRSI := 1
else
    if myRSI < 50
        stateRSI := -1
    else
        stateRSI := 0

//Built-In MACD
fast_ma = sma_source ? sma(srcMACD, fast_length) : ema(srcMACD, fast_length)
slow_ma = sma_source ? sma(srcMACD, slow_length) : ema(srcMACD, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
if macd > signal
    stateMACD := 1
else
    if macd < signal
        stateMACD := -1
    else
        stateMACD := 0


//Indicators combination logic and alert generation
if stateRSI == 1 and stateMACD == 1 and stateStoch == 1
    stateCOMBINED := 2
else
    if (stateRSI == -1 and stateMACD == -1 and stateStoch == -1)
        stateCOMBINED := -2
    else 
        stateCOMBINED := 0
alertcondition(stateCOMBINED == 2, title='Long entry', message='Uptrend!')
alertcondition(stateCOMBINED == -2, title='Short entry', message='Downtrend!')

//Plots
//plot(stateStoch, color=color.red)         //uncomment for display and verification; uncomment the 2nd option "overlay=false" on the top of the script
//plot(stateRSI, color=color.blue)          //uncomment for display and verification; uncomment the 2nd option "overlay=false" on the top of the script
//plot(stateMACD, color=color.green)        //uncomment for display and verification; uncomment the 2nd option "overlay=false" on the top of the script
//plot(stateCOMBINED, color=color.yellow)   //uncomment for display and verification; uncomment the 2nd option "overlay=false" on the top of the script
plotshape(crossover(stateCOMBINED, 1), text='Long', style=shape.triangledown, location=location.abovebar, color=color.green, size=size.small)   //1st option: displays Long alert only once
                                                                                                                                                //at the beginning of the signal
plotshape(crossunder(stateCOMBINED, -1), text='Short', style=shape.triangleup, location=location.belowbar, color=color.red, size=size.small)    //1st option: displays Short alert only once
                                                                                                                                                //at the beginning of the signal

Overview

A bullish state occurs when Stochastic rises above 20 and stays below 80, RSI is above 50, and the MACD line is above its signal line. A bearish state triggers when Stochastic drops below 80, RSI falls below 50, and MACD drops below its signal line. Settings allow adjusting Stochastic parameters and MACD periods. It operates on the main chart with built-in alert conditions, though visual plots are commented out in the code.

Details

Published by

Crypto-Adhyeta on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum, Trend

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
Kint14periodK
Dint3periodD
Smoothint3smoothK
Fast Lengthint12fast_length
Slow Lengthint26slow_length
SourcesourceclosesrcMACD
Signal Smoothingint9signal_length
Oscillator: 1 - SMA / 0 - EMAboolfalsesma_source
Signal Line: 1 - SMA / 0 - EMAboolfalsesma_signal
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

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
257 stars

This indicator uses a Lorentzian distance k-nearest neighbors classification algorithm to predict market direction based on up to five technical features, such as RSI, WaveTrend, CCI, and ADX. It compares current feature values against historical bar patterns

Indicator v5 AI / machine learningOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of Donald - Machine Learning Options
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

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