Strategy · Pine Script v4 · Own pane

Oversold

by kat3samsin

The oversold strategy identifies oversold conditions using the relative strength index with a 14 period.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code38
Settings6inputs
LicenceMIT
Last update5 years ago17 Mar 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 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

38 lines of Pine Script v4 from scripts/oversold.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

oversold.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kat3samsin

//@version=4
strategy("Oversold", overlay=false, process_orders_on_close=true)

//rsi
_rsi = rsi(close, 14)

//sma
_sma20 = sma(close, 20)
_sma50 = sma(close, 50)
_sma200 = sma(close, 200)

//ALMA
windowsize = input(title="Window Size", type=input.integer, defval=15)
ALMAoffset = input(title="ALMAOffset", type=input.float, defval=0.85)
sigma = input(title="Sigma", type=input.float, defval=6)
ALMA15 = alma(close, windowsize, ALMAoffset, sigma)

//stochastics
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

//only execute on downtrend
closeWithinFifteenPercentOfSMA20 = close >= (_sma20 * .85) and close < _sma20
OSEntry = _rsi <= 30 and closeWithinFifteenPercentOfSMA20 and k > d
OSExit = crossunder(k, d)

strategy.entry(id="OS", long=true, qty=strategy.equity/close, when=OSEntry)
strategy.close(id="OS", when = OSExit)

plot(_rsi, color=color.green, linewidth=1)
plot(k, color=color.blue)
plot(d, color=color.orange)

Overview

Oversold applies an arithmetic linear moving average with a 20 period for trend filtering and requires the price to stay within 15 percent of this average. Stochastic oscillator with periods 14 for K and 3 for D provides confirmation via the K line crossing above D to trigger long entries. Positions exit on the K line crossing below D. The strategy plots the RSI, K, and D in a separate pane. It has no stop loss by default and uses no pyramiding.

Details

Published by

kat3samsin on GitHub

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Mean reversion, Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

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
Window Sizeint15windowsize
ALMAOffsetfloat0.85ALMAoffset
Sigmafloat6sigma
Kint14periodK
Dint3periodD
Smoothint3smoothK
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

106 stars

Buy The Dips - MA200 Optimised is a mean-reversion strategy that measures short-term percentage price changes alongside a simple moving average trend filter. It opens long positions when price experiences a steep drop exceeding three percent while remaining ab

Strategy v4 Oscillators & momentumTrend
Updated 2 years ago · GPL-3.0 GitHub repository of Buy The Dips - MA200 Optimised

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy combines Bollinger Bands, Bollinger Band Width, and the Relative Strength Index (RSI) for mean-reversion trades. It enters long when price crosses below the lower band with oversold RSI, or when band width contracts under low volatility. Short en

Strategy v4 Mean reversionOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy
2 stars

This strategy plots in a separate pane and tests a selected oscillator with one of six entry logics: moving average, moving-average crossover, zero cross, extremes, mean reversion, or take profit. Users scale and time-adjust one of three oscillators and can li

Strategy v4 Oscillators & momentumMoving averages
Updated 8 months ago · None stated GitHub repository of Oscillator Evaluator (Analysis tool)

WaveTrend with Crosses [LazyBear]

by avatar-lavventura
2 stars

This strategy calculates the WaveTrend oscillator using exponential moving averages of typical price and plots two signal lines alongside overbought and oversold thresholds in a separate pane. It enters long positions when the primary line crosses above the si

Strategy v4 Oscillators & momentumMoving averages
Updated 7 months ago · None stated GitHub repository of WaveTrend with Crosses [LazyBear]
1 stars

The script calculates the yield spread between long-term and short-term US Treasury yields (T10Y2Y or manual US10Y minus US02Y) and plots the spread line on a separate pane. It signals long entries on steepening beyond a user threshold in reversion mode or SMA

Strategy v6 Mean reversionSupport & resistance
Updated 2 months ago · None stated GitHub repository of TN Yield Spread Sovereign v6
330 stars

This mean-reversion strategy combines multi-timeframe exponential moving averages, Bollinger Bands, and the Relative Strength Index. It generates long and optional short trade signals when price interacts with the Bollinger Bands alongside RSI threshold confir

Strategy v5 Mean reversionMoving averages
Updated 2 months ago · None stated GitHub repository of MEMA + BB + RSI [Alorse]

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