Strategy · Pine Script v5 · On the chart

Stochastic RSI MTF

by kritarth2121· code credited to Dynamictradingstrategies

This strategy computes a smoothed Stochastic RSI and compares it with a signal line taken from the four-hour timeframe.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code96
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago10 Dec 2023

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

96 lines of Pine Script v5 from STOCH RSI MULTIPLETIMEFRAME.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

STOCH RSI MULTIPLETIMEFRAME.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dynamictradingstrategies

//@version=5
strategy("STOCHASTIC RSI MTF", overlay = true, initial_capital = 300000)

Stoch_l = input.int(title = "Stoch_l", defval = 14, minval = 1,maxval = 30, step = 1 )
RSI_L = input.int(title = "RSI_L", defval = 14, minval = 1,maxval = 30, step = 1 )

EMA_L1 = input.int(title = "EMA_L1", defval = 13, minval = 1,maxval = 100, step = 1 )
EMA_L2 = input.int(title = "EMA_L2", defval = 34, minval = 1,maxval = 100, step = 1 )

EXIT_EMA = input.int(title = "EXIT_EMA", defval = 13, minval = 1,maxval = 100, step = 1 )



////// TRADING INDICATOR 

RSI = ta.rsi(close,RSI_L)

Stoch_rsi = ta.stoch(RSI,RSI,RSI,Stoch_l)
smooth_stoch = ta.sma(Stoch_rsi,3)
Signal_line = ta.sma(smooth_stoch,3)

EXITEMA = ta.ema(close,EXIT_EMA)

/// MULTIPLE TIMEFRAME STOCHASTIC RSI INDICATOR

STOCHRSI_2H    = request.security(syminfo.tickerid, "240", smooth_stoch[barstate.isrealtime ? 1 : 0])
Signal_line_2H = request.security(syminfo.tickerid, "240", Signal_line[barstate.isrealtime ? 1 : 0])

BUY = STOCHRSI_2H > Signal_line_2H and ta.crossover(smooth_stoch,30) and close > EXITEMA
SELL = STOCHRSI_2H < Signal_line_2H and ta.crossunder(smooth_stoch,70) and close < EXITEMA

BUYEXIT =  ta.crossunder(close,EXITEMA)
SELLEXIT = ta.crossover(close,EXITEMA)


////// END ////////

// STRATEGY 

if strategy.position_size <= 0
    strategy.entry("long", strategy.long, when = BUY, comment = "BUY")
    
if strategy.position_size > 0
    strategy.close("long", when = BUYEXIT, comment = "BUYEXIT")
    


if strategy.position_size >= 0
    strategy.entry("short", strategy.short, when = SELL, comment = "SELL")
    
if strategy.position_size < 0
    strategy.close("short", when = SELLEXIT, comment = "SELLEXIT")
    





plotshape(BUY,style = shape.triangleup, text = "BUY", textcolor = color.new(color.green,0), location = location.belowbar)
plotshape(SELL, style = shape.triangledown, text = "SELL", textcolor = color.new(color.red,0),location = location.abovebar)














//EMA1 = ta.ema(close,EMA_L1)
//EMA2 = ta.ema(close,EMA_L2)


//BUY = EMA1 > EMA2 and ta.crossover(smooth_stoch,Signal_line) and smooth_stoch > smooth_stoch[1] and ta.crossover(smooth_stoch,20)
//SELL = EMA1 < EMA2 and ta.crossunder(smooth_stoch,Signal_line) and smooth_stoch < smooth_stoch[1] and ta.crossunder(smooth_stoch,80)

//plotshape(BUY,style = shape.triangleup, text = "BUY", textcolor = color.new(color.green,0), location = location.belowbar)
//plotshape(SELL, style = shape.triangledown, text = "SELL", textcolor = color.new(color.red,0),location = location.abovebar)

//plot(EMA1)
//plot(EMA2, color = color.new(color.green,0))

//plot(smooth_stoch)
//plot(Signal_line, color = color.new(color.red,0))
//a = hline(80)
//b = hline(20)

//fill(a,b, color = color.new(color.green,70))

Overview

Stochastic RSI MTF goes long when the four-hour reading is above its signal, the chart reading crosses up through 30 and price is above an exit EMA. It goes short on the mirror conditions around 70. Positions close when price crosses back through the EMA. There is no stop loss or take profit, and it can reverse between long and short.

Details

Published by

kritarth2121 on GitHub

Code credit

Dynamictradingstrategies, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Stoch_lint14Stoch_l
RSI_Lint14RSI_L
EMA_L1int13EMA_L1
EMA_L2int34EMA_L2
EXIT_EMAint13EXIT_EMA
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

330 stars

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy

This strategy draws on the price chart and combines Stochastic RSI, the Money Flow Index, and an exponential moving average to open long or short trades. Longs use the lower oscillator thresholds and shorts use the upper ones, with direction limited to longs,

Strategy v5 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy
53 stars

This strategy implements Larry Connors' 2-period RSI mean-reversion algorithm overlaid on the price chart. It filters trades using a long-term Simple Moving Average (SMA), entering long positions when the price trades above the SMA and the short-term RSI drops

Strategy v6 Oscillators & momentumMean reversion
Updated 2 months ago · MPL-2.0 GitHub repository of Larry Connors 2-Period RSI Strategy

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