Strategy · Pine Script v5 · Own pane

Filtered Stoch

by hasnocool· code credited to SnarkyPuppy

Filtered Stoch is a long-only strategy that combines a Stochastic RSI oscillator with a trend filter based on the highest EMA of price highs.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code34
Settings8inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

34 lines of Pine Script v5 from Bull Trend Filtered StochRSI (BTFS).pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bull Trend Filtered StochRSI (BTFS).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SnarkyPuppy
//@version=5
strategy("Filtered Stoch", overlay=false, default_qty_value = 100, default_qty_type=strategy.percent_of_equity)
/////high filter...upper donchian channel of ema... or highest ema for a given amount of candles
filter_ema_len= input(6)
ema_donchian_len = input(30)
ema=ta.highest(ta.ema(high,filter_ema_len),ema_donchian_len)
////////////////////////basic stoch rsi with max val 100 and min val 0.. entry above lowerband preset 35
smoothK = input.int(7, "K", minval=1)
smoothD = input.int(4, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = math.min(100, math.max(0,ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)))
d = math.max(math.min(ta.sma(k, smoothD),80),35)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
lowerband=input(35)
h11 = hline(lowerband, "Lower Band", color=#787B86)
fill(h0, h11, color=color.rgb(33, 150, 243, 90), title="Background")
ematrend= close>ema ? 1 : 0
bgcolor(ematrend==1?color.rgb(76, 175, 79, 80):na)
longCondition = k>lowerband and ematrend==1
if (longCondition)
    strategy.entry("Up", strategy.long)
shortCondition =  ta.crossunder(k,lowerband)
if (shortCondition)
    strategy.close("Up", shortCondition)
    
Expand (44 lines)

Overview

A bullish trend state is identified when close prices trade above the EMA filter level. The strategy enters a long position when the Stochastic RSI K line exceeds the defined lower band during a bullish trend filter. Positions are exited when the K line crosses under the lower band threshold. The strategy features customizable band and moving average inputs and operates without a default stop loss.

Details

Published by

hasnocool on GitHub

Code credit

SnarkyPuppy, as written in the script's header

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend, Moving averages

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
filter_ema_lenint6filter_ema_len
ema_donchian_lenint30ema_donchian_len
Kint7smoothK
Dint4smoothD
RSI Lengthint14lengthRSI
Stochastic Lengthint14lengthStoch
RSI Sourcesourceclosesrc
lowerbandint35lowerband
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

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated today · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

EMA Ribbon MACD

by iamrichardD
57 stars

This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta

Strategy v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon MACD

This strategy evaluates the dynamic relationship between price and a chosen moving average across six diagnostic dimensions: trend, respect, extension, compression, acceleration, and exhaustion. It plots a normalized relationship oscillator bounded between -10

Strategy v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Market–Average Relationship Engine [WavesUnchained]
7 stars

This strategy combines the Moving Average Convergence Divergence oscillator with an Exponential Moving Average trend filter. It enters long positions when the MACD histogram crosses above zero while price stays above the long-term EMA filter. Long trades close

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · MPL-2.0 GitHub repository of MACD EMA Filter Strategy

MACD Signal Cross

by latentwill
4 stars

This strategy evaluates EMA momentum crossovers filtered by an RSI oscillator. It enters a long position when a fast EMA crosses above a slow EMA while RSI remains above 40. Conversely, it enters a short position when the fast EMA crosses below the slow EMA wh

Strategy v5 Moving averagesOscillators & momentum
Updated 6 days ago · None stated GitHub repository of MACD Signal Cross

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