Strategy · Pine Script v5 · On the chart

Fluffy 15M Stochastic RSI Top

by pvdochtend· code credited to pjotrtje

A strategy written for 15-minute charts that looks for pullbacks within an uptrend.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code127
Settings14inputs
LicenceGPL-3.0
Last update3 years ago5 Feb 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

127 lines of Pine Script v5 from 2EMA-StochRSI-ATR.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

2EMA-StochRSI-ATR.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pjotrtje
//
// This script is based on a strategy i found on YouTube (https://www.youtube.com/watch?v=VWySXvbVov8)
// Channel of TradePro. As an Pinescript exercise I translated it to a Pinescript so I can backtest if and perhaps use it as a deal start/end strategy.
//
//Short recap:
//Long:
//50 > 200      - isEMAUptrendSimple
//close < 50    - isCloseLowerThanFastEMA
//Stochastic RSI MAX [14] < 20 
//Stochastic RSI Cross Up higher value than previous cross (in the last 14) 
//

//@version=5
strategy("Fluffy 15M Stochastic RSI Top", shorttitle = "Fluffy 15M Stoch RSI Top" ,overlay=true)

//Get needed indicators

//EMA Uptrend
EMA_Fast_Length = input(title="EMA Fast Length", group="EMA Trend Settings", defval=50)
EMA_Slow_Length = input(title="EMA Slow Length", group="EMA Trend Settings", defval=200)
EMA_Fast = ta.ema(close,EMA_Fast_Length)
EMA_Slow = ta.ema(close,EMA_Slow_Length)

isEMAUptrendSimple = EMA_Fast > EMA_Slow

isCloseLowerThanFastEMA = close < EMA_Fast

//Stochastic RSI
ThresholdOverBought = input.int(title="Stochastic Upperlevel", group="Stochastic Settings", defval=80)
ThresholdOverSold = input.int(title="Stochastic Lowerlevel", group="Stochastic Settings", defval=20)
periodK = input.int(14, title="%K Length", group="Stochastic Settings", minval=1)
smoothK = input.int(3, title="%K Smoothing", group="Stochastic Settings", minval=1)
periodD = input.int(3, title="%D Smoothing", group="Stochastic Settings", minval=1)
rsi1 = ta.rsi(close, 14)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, periodK), smoothK)
d = ta.sma(k, periodD)

isStochasticCrossUp = ta.crossover(k,d)
isStochasticOverSold = k < ThresholdOverSold

//ATR Stoploss finder (by veryfid)
length = input.int(title="Length", group="ATR Settings", defval=14, minval=1)
smoothing = input.string(title="Smoothing", group="ATR Settings", defval="EMA", options=["RMA", "SMA", "EMA", "WMA"])
m = input(0.7, "Multiplier")
srcHigh = input(high)
srcLow = input(low)

collong = input(color.teal, "Low Line Color",inline ="1")
colshort = input(color.red, "High Line Color",inline ="2")

ma_function(source, length) =>
    if smoothing == "RMA"
        ta.rma(source, length)
    else
        if smoothing == "SMA"
            ta.sma(source, length)
        else
            if smoothing == "EMA"
                ta.ema(source, length)
            else
                ta.wma(source, length)
                
trHigh = ma_function(ta.tr(true), length) * m + srcHigh
trLow = srcLow - ma_function(ta.tr(true), length) * m

// Calculate stuff
//Check if the Value of the Stochastic Was recently oversold (parameter default: 15)
f_isStochasticRecentlyOverSold(_steps) =>
    bool _wasOverSold = false
    for i = 1 to _steps
        if isStochasticOverSold[i]
            _wasOverSold := true
    _wasOverSold

//Then this is the second (higher) crossup that should be the start signal.
f_isStochasticRecentlyLowerCrossUp(_crossvalue,_steps) =>
    bool _hasRecentLowerCrossUp = false
    for i = 1 to _steps
        if isStochasticCrossUp[i] and k[i] < _crossvalue
            _hasRecentLowerCrossUp := true
    _hasRecentLowerCrossUp

//https://www.tradingview.com/script/IHVPG6TS-Stop-loss-and-Take-Profit-in-example/
f_moneyToSLPoints(money) =>
    strategy.position_size !=0 ? (money / syminfo.pointvalue / math.abs(strategy.position_size)) / syminfo.mintick : na

// debug plots for visualize SL & TP levels
f_pointsToPrice(pp) =>
    na(pp) ? na : strategy.position_avg_price + pp * math.sign(strategy.position_size) * syminfo.mintick

long_sl_amount = int(close-trLow)
l = f_moneyToSLPoints(long_sl_amount)
p = f_moneyToSLPoints(2*long_sl_amount)

pp = plot(f_pointsToPrice(p), style = plot.style_linebr )
lp = plot(f_pointsToPrice(-l), style = plot.style_linebr )
avg = plot( strategy.position_avg_price, style = plot.style_linebr )
fill(pp, avg, color = color.green)
fill(avg, lp, color = color.red)

// Plot stuff
pEMAFast = plot(EMA_Fast, title="EMA Fast", color=color.yellow, style=plot.style_line)
pEMASlow = plot(EMA_Slow, title="EMA Slow", color=color.red, style=plot.style_line)
EMAResistanceZoneColor = if (EMA_Fast > EMA_Slow) 
    color.rgb(0, 140, 0, 70)
else
    color.rgb(140, 0, 0, 90)

fill(pEMAFast, pEMASlow, color=EMAResistanceZoneColor, title="EMA Resistance zone")

p1 = plot(trHigh, title = "ATR Short Stop Loss", color= colshort, trackprice = true)
p2 = plot(trLow, title = "ATR Long Stop Loss", color= collong, trackprice = true)

// Create signals
longStartCondition = isEMAUptrendSimple and isCloseLowerThanFastEMA and isStochasticCrossUp and f_isStochasticRecentlyOverSold(7) and f_isStochasticRecentlyLowerCrossUp(k,7)

if (longStartCondition and strategy.position_size == 0)
    strategy.entry("Buy", strategy.long)
    alert('', alert.freq_once_per_bar_close)

strategy.exit("x", from_entry = "Buy", profit = p, loss = l)

// Backtest Range
//startDate = input(timestamp("2022-08-15T00:00:00")) 
//finishDate = input(timestamp("2022-09-31T00:00:00"))

Overview

Fluffy 15M Stochastic RSI Top requires the 50 EMA above the 200 EMA, the close below the 50 EMA, a recent oversold reading on a smoothed Stochastic RSI, and a stochastic cross up that is higher than an earlier cross in the lookback. A volatility stop is built from smoothed true range with a multiplier, and helper code converts money amounts to stop points. Settings cover the EMAs, stochastic lengths and levels and the ATR smoothing.

Details

Published by

pvdochtend on GitHub

Code credit

pjotrtje, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Mean reversion, Trend

Markets

Crypto

Timeframes

M15-H1

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
EMA Fast Lengthint50EMA_Fast_Length
EMA Slow Lengthint200EMA_Slow_Length
Stochastic Upperlevelint80ThresholdOverBought
Stochastic Lowerlevelint20ThresholdOverSold
%K Lengthint14periodK
%K Smoothingint3smoothK
%D Smoothingint3periodD
Lengthint14length
SmoothingstringEMAsmoothing
Multiplierfloat0.7m
srcHighsourcehighsrcHigh
srcLowsourcelowsrcLow
Show all 14 settings
SettingTypeDefaultVariable
Low Line Colorcolorcolor.tealcollong
High Line Colorcolorcolor.redcolshort
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 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

ADX + RSI Strat

by hasnocool
106 stars

This strategy combines a 7-period RSI with an ADX filter to trade market regimes on the price chart. When the ADX indicates ranging conditions below a set threshold, it triggers entries on RSI overbought or oversold extremes. By default, the entry logic is inv

Strategy v4 Oscillators & momentumTrend
Updated 2 years ago · GPL-3.0 GitHub repository of ADX + RSI Strat

ADX Trend Filter

by latentwill
4 stars

This strategy enters long when a series labeled ADX is above a threshold and RSI is below 40, and enters short when that series is above the threshold and RSI is above 60. Both series are calculated with the RSI function, so the trend filter is not a true ADX.

Strategy v5 TrendOscillators & momentum
Updated 7 days ago · None stated GitHub repository of ADX Trend Filter
4 stars

This strategy trades pullbacks in the direction of a moving-average trend and draws on the price chart. An uptrend requires the 50-period EMA above the 200-period EMA with price above the slower average, and a downtrend is the reverse. It enters long or short

Strategy v6 TrendOscillators & momentum
Updated yesterday · None stated GitHub repository of AG Trend-Pullback Optimized

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers