Strategy · Pine Script v5 · On the chart

3hr Stoch

by benso87

3hr Stoch is a short-only trading strategy based on a smoothed Stochastic Oscillator.

View on GitHub

GitHub stars24on the repository
Pine versionv5runs as is
Lines of code42
Settings8inputs
LicenceMPL-2.0
Last update4 years ago5 Oct 2022

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

42 lines of Pine Script v5 from 3hr Stoch Shorts Strategy.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

3hr Stoch Shorts Strategy.pine
//@version=5
//
// Author: benso87
// benso87.com
//
//
strategy("3hr Stoch", overlay=true, initial_capital=1000, default_qty_value=10, default_qty_type=strategy.percent_of_equity,process_orders_on_close=true)

///////////////////////////////////////////////////////////////////////////////
// Inputs

// Dates
startDate    = input.time    (timestamp('1 Jan 2022 00:00'), title='Start', group='Dates')
endDate        = input.time    (timestamp('1 Jan 2100 00:00'), title='End', group='Dates')

// Stoch
src = input(close, title='Source', group='Stochastic')
periodK = input.int(14, title='K', minval=1, group='Stochastic')
periodD = input.int(3, title='D', minval=1, group='Stochastic')
smoothK = input.int(6, title='Smooth K', minval=1, group='Stochastic')
obLevel = input(80, title='Overbought Level', group='Stochastic')
osLevel = input(20, title='Oversold Level', group='Stochastic')


///////////////////////////////////////////////////////////////////////////////
// Calculations
k = ta.sma(ta.stoch(src, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

crossUp = ta.crossover(k,d)

///////////////////////////////////////////////////////////////////////////////
// Strategy

// Short when K falls below D and below the overbought zone
shortSignal = k < obLevel and k < d and k[1] >= obLevel and time >= startDate and time <= endDate

// Exit when K falls below oversold or stoch crosses up
shortExit = crossUp or k <= osLevel

strategy.entry("SHORT", strategy.short, when=shortSignal)
strategy.close("SHORT", when=shortExit)

Overview

3hr Stoch calculates the %K and %D lines using configurable period and smoothing settings. The strategy enters a short position when the %K line crosses below the %D line while dropping beneath the designated overbought threshold within a configured date range. It exits the short position when %K crosses back above %D or reaches the oversold level. Displayed on the main price chart, the strategy relies entirely on indicator logic with no defined stop loss or take profit orders.

Details

Published by

benso87 on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Mean reversion

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
Starttimetimestamp('1 Jan 2022 00:00')startDate
Endtimetimestamp('1 Jan 2100 00:00')endDate
Sourcesourceclosesrc
Kint14periodK
Dint3periodD
Smooth Kint6smoothK
Overbought Levelint80obLevel
Oversold Levelint20osLevel
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 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