0bps

Strategy vault / Breakout

Stochastic Oscillator Band Breakout Strategy

The Stochastic Oscillator band breakout strategy generates trades based on the fast line of the Stochastic Oscillator breaking through upper and lower bands. The logic is: 1. Calculate the fast and slow Stochastic…

Author
ChaoZhang
Complexity
Starter · 43 lines
Parameters
5
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

Strategy Logic

The Stochastic Oscillator band breakout strategy generates trades based on the fast line of the Stochastic Oscillator breaking through upper and lower bands.

The logic is:

  1. Calculate the fast and slow Stochastic Oscillator lines over a lookback period (e.g. 7 days)

  2. Set upper and lower bands for the fast line (e.g. 80 and 20)

  3. Go long when the fast line breaks above the upper band

  4. Go short when the fast line breaks below the lower band

  5. Optionally reverse the signals (longs become shorts, shorts become longs)

Breakouts of the bands with the slow Stochastic line as support/resistance can effectively filter false breaks. Parameters can also be tuned to suit different cycles.

Advantages

  • Simple and intuitive rules

  • Stochastics effective for overbought/oversold

  • Bands + slow line filter false breaks

Risks

  • Lagging stochastics may miss opportunities

  • Requires parameter optimization for market adaption

  • Band settings need caution to avoid over-trading

Summary

The Stochastic breakout strategy capitalizes on trend opportunities using fast/slow line band breaks. With well-tuned parameters, it can effectively capture market rhythm but lag is a key risk to note. Combining with other confirming indicators can improve strategy robustness.

Parameters

NameDefaultWhat it controls
v_input_17Length
v_input_23DLength
v_input_320UpBand
v_input_480DownBand
v_input_5falseTrade reverse

Source Pine Script

/*backtest
start: 2023-09-06 00:00:00
end: 2023-09-13 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 05/10/2017
// This back testing strategy generates a long trade at the Open of the following 
// bar when the %K line crosses up UpBand line.
// It generates a short trade at the Open of the following bar when the %K line 
// crosses down DownBand line.
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Strategy Stochastic", shorttitle="Strategy Stochastic")
Length = input(7, minval=1)
DLength = input(3, minval=1)
UpBand = input(20, minval=1)
DownBand = input(80, minval=1)
reverse = input(false, title="Trade reverse")
hline(50, color=black, linestyle=hline.style_dashed)
hline(UpBand, color=red, linestyle=hline.style_solid)
hline(DownBand, color=green, linestyle=hline.style_solid)
vFast = stoch(close, high, low, Length)
vSlow = sma(vFast, DLength)
pos = iff(vFast > UpBand, 1,
	   iff(vFast < DownBand, -1, nz(pos[1], 0))) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1, 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	   	    
barcolor(possig == -1 ? red: possig == 1 ? green : blue )  
plot(vSlow, color=blue, title="D")
plot(vFast, color=red, title="K")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Stochastic-Oscillator-Band-Breakout-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open