Strategy · Pine Script v6 · Own pane

Slow Stochastic Cross

by pineforge-4pass· code credited to PineForge contributors 2026

A strategy based on the slow stochastic oscillator.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code60
Settings3inputs
LicenceApache-2.0
Last update6 days ago23 Oct 2026

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

60 lines of Pine Script v6 from validation/ta-stoch-slow-k-d-cross-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 103 — slow stochastic %K/%D crossover
// Clean-room: written from validation goal, not from source.
//
// Purpose: exercises `ta.stoch(close, high, low, length)` (which
// returns the raw fast %K) plus the standard slow-stochastic
// smoothing chain: `slowK = ta.sma(rawK, smooth)` and then
// `slowD = ta.sma(slowK, dLen)` (D is an SMA of the slow K, not of
// the raw K — otherwise slowK and D would be the same series and
// never cross). Trade trigger uses `ta.crossover` / `ta.crossunder`
// of slowK against slowD, with a band gate to avoid entries at
// extreme overbought/oversold. The engine surface under test is the
// stacked-SMA recurrence and `ta.crossover`/`ta.crossunder` ordering
// against TradingView's reference.
//
// Validation goal: bit-exact trade list against TradingView's broker
// emulator on the reference 15m feed. Pass = every long/short entry
// fires on the same bar TradingView places it.
//
// TV setup: 15m chart, ETH-USDT-USDT (Binance USDT-M Perpetual). Full
// window matching corpus/data/ohlcv_ETH-USDT-USDT_15m.csv. Strategy
// properties: leave defaults from script header. Export "List of
// trades" → tv_trades.csv.
//@version=6
strategy("PF probe 103 - stoch slow cross", shorttitle="PF_p103_STO",
     overlay=false, initial_capital=1000000,
     commission_type=strategy.commission.percent, commission_value=0,
     slippage=0, default_qty_type=strategy.fixed, default_qty_value=1,
     pyramiding=1, process_orders_on_close=false)

// ---- inputs --------------------------------------------------------
int i_k_len   = input.int(14, "Stoch %K length",     minval=1, maxval=100)
int i_smooth  = input.int(3,  "Slow %K smoothing",   minval=1, maxval=20)
int i_d_len   = input.int(3,  "%D smoothing",        minval=1, maxval=20)

// ---- raw %K from ta.stoch, then slow-smoothed --------------------
// ta.stoch in v6 returns the raw fast %K. Slow-stochastic recipe:
//   slowK = SMA(rawK, smooth)         (3 by default)
//   slowD = SMA(slowK, dLen)          (3 by default)
// D is computed from slowK, NOT from rawK, so the two series can
// actually cross.
float raw_k  = ta.stoch(close, high, low, i_k_len)
float slow_k = ta.sma(raw_k,  i_smooth)
float slow_d = ta.sma(slow_k, i_d_len)

// ---- crossover entries with band gate ------------------------------
// Band gate prevents entries at extreme readings (long while already
// at overbought ≥ 80, short while at oversold ≤ 20). Entries flip
// position so longs and shorts can alternate.
bool bull_cross = ta.crossover(slow_k,  slow_d) and slow_k < 80
bool bear_cross = ta.crossunder(slow_k, slow_d) and slow_k > 20

if bull_cross
    strategy.entry("L", strategy.long, comment="slowK cross above D")

if bear_cross
    strategy.entry("S", strategy.short, comment="slowK cross below D")

Overview

Raw %K is smoothed into slow %K and then averaged into %D, with adjustable lengths. It enters long when slow %K crosses above %D while below 80, and short when it crosses below %D while above 20, reversing the position. There is no stop loss or take profit. The script itself does not plot the oscillator lines, so only the strategy output appears in a separate pane.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
Stoch %K lengthint14i_k_len
Slow %K smoothingint3i_smooth
%D smoothingint3i_d_len
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]

Q-Trend + KVO Strategy

by TradersPost
218 stars

This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und

Strategy v6 TrendVolume
Updated 3 months ago · None stated GitHub repository of Q-Trend + KVO Strategy

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 yesterday · Apache-2.0 GitHub repository of MACD Crossover (tutorial)
114 stars

This strategy estimates price behavior using ordinary least squares regression between higher-timeframe data and a generated dataset, smoothed by a Karobein oscillator. It enters long positions when the oscillator turns upward and short positions when it turns

Strategy v4 Oscillators & momentumAI / machine learning Repaints

2xTP, SL to Entry

by hasnocool
106 stars

This strategy executes mean-reversion trades based on Bollinger Bands and the Stochastic Oscillator. Long orders trigger when price dips below the lower band alongside a bullish Stochastic crossover, with an optional oversold threshold. Short orders execute on

Strategy v5 Mean reversionOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 2xTP, SL to Entry
65 stars

This strategy calculates a 20-period Relative Strength Index (RSI) and generates entry orders based on crossovers and crossunders of the 50 level. When RSI crosses above 50, it places a long stop entry at the current high price with a custom alert message. Whe

Strategy v4 Oscillators & momentum
Updated 5 days ago · GPL-3.0 GitHub repository of Strategy Using Alert Message

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